From 255ce14f3c36f5e1f2bf5e8242070d0129f15ac1 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:21:12 +0200 Subject: feat: Add button to delete profile (#603) This adds a button and corresponding logic to delete an existing profile Spliced out from #444 Co-authored-by: Jan --- src-tauri/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 66bb98d2..47cfee6a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -160,6 +160,7 @@ fn main() { get_available_northstar_versions, northstar::profile::fetch_profiles, northstar::profile::validate_profile, + northstar::profile::delete_profile, ]) .run(tauri::generate_context!()) { -- cgit v1.2.3 From c3c1aab86e7254f8f1724f3e13a4f17a9974f422 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:49:50 +0200 Subject: refactor: Use fully qualified path for vars and funcs (#614) * refactor: Use fully qualified path for variable Instead of importing it directly * refactor: Use fully-qualified path for Linux specific function --- src-tauri/src/main.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 47cfee6a..e37f118e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,8 +9,7 @@ use std::{ time::Duration, }; -use crate::constants::REFRESH_DELAY; - +mod constants; mod development; mod github; mod mod_management; @@ -103,7 +102,7 @@ fn main() { let app_handle = app.app_handle(); tauri::async_runtime::spawn(async move { loop { - sleep(REFRESH_DELAY).await; + sleep(constants::REFRESH_DELAY).await; app_handle .emit_all( "northstar-statistics", @@ -453,13 +452,8 @@ async fn get_available_northstar_versions() -> Result Result<(), String> { // check `ldd --version` to see if glibc is up to date for northstar proton let min_required_ldd_version = 2.33; - let lddv = linux::check_glibc_v(); + let lddv = platform_specific::linux::check_glibc_v(); if lddv < min_required_ldd_version { return Err(format!( "GLIBC is not version {} or greater", @@ -532,7 +526,7 @@ fn get_host_os() -> String { #[tauri::command] async fn install_northstar_proton_wrapper() -> Result<(), String> { #[cfg(target_os = "linux")] - return linux::install_ns_proton().map_err(|err| err.to_string()); + return platform_specific::linux::install_ns_proton().map_err(|err| err.to_string()); #[cfg(target_os = "windows")] Err("Not supported on Windows".to_string()) @@ -541,7 +535,7 @@ async fn install_northstar_proton_wrapper() -> Result<(), String> { #[tauri::command] async fn uninstall_northstar_proton_wrapper() -> Result<(), String> { #[cfg(target_os = "linux")] - return linux::uninstall_ns_proton(); + return platform_specific::linux::uninstall_ns_proton(); #[cfg(target_os = "windows")] Err("Not supported on Windows".to_string()) @@ -550,7 +544,7 @@ async fn uninstall_northstar_proton_wrapper() -> Result<(), String> { #[tauri::command] async fn get_local_northstar_proton_wrapper_version() -> Result { #[cfg(target_os = "linux")] - return linux::get_local_ns_proton_version(); + return platform_specific::linux::get_local_ns_proton_version(); #[cfg(target_os = "windows")] Err("Not supported on Windows".to_string()) -- cgit v1.2.3 From f515a3b702f781c0da438840071def1b37d2e1bc Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 02:27:29 +0200 Subject: refactor: Move platform specific logic to proper mod (#616) in an effort to clean up `main.rs` * refactor: Move Proton related wrapper functions to root of platform_specific module * refactor: Move Linux checks to Linux mod for platform specific stuff * refactor: Move Linux checks wrapper to mod for platform specific stuff --- src-tauri/src/main.rs | 78 ++------------------------------ src-tauri/src/platform_specific/linux.rs | 21 +++++++++ src-tauri/src/platform_specific/mod.rs | 46 +++++++++++++++++++ 3 files changed, 72 insertions(+), 73 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e37f118e..6bb65a2c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -14,6 +14,7 @@ mod development; mod github; mod mod_management; mod northstar; +mod platform_specific; mod repair_and_verify; mod thunderstore; mod util; @@ -134,7 +135,7 @@ fn main() { repair_and_verify::disable_all_but_core, util::is_debug_mode, github::release_notes::get_northstar_release_notes, - linux_checks, + platform_specific::linux_checks, mod_management::get_installed_mods_and_properties, install_mod_caller, clean_up_download_folder_caller, @@ -143,9 +144,9 @@ fn main() { util::get_server_player_count, util::kill_northstar, mod_management::delete_thunderstore_mod, - install_northstar_proton_wrapper, - uninstall_northstar_proton_wrapper, - get_local_northstar_proton_wrapper_version, + platform_specific::install_northstar_proton_wrapper, + platform_specific::uninstall_northstar_proton_wrapper, + platform_specific::get_local_northstar_proton_wrapper_version, open_repair_window, thunderstore::query_thunderstore_packages_api, github::get_list_of_tags, @@ -193,23 +194,6 @@ fn main() { }; } -/// Returns true if linux compatible -#[tauri::command] -async fn linux_checks() -> Result<(), String> { - // Different behaviour depending on OS - // MacOS is missing as it is not a target - // in turn this means this application will not build on MacOS. - #[cfg(target_os = "windows")] - { - Err("Not available on Windows".to_string()) - } - - #[cfg(target_os = "linux")] - { - linux_checks_librs() - } -} - /// Returns the current version number as a string #[tauri::command] async fn get_flightcore_version_number() -> String { @@ -452,7 +436,6 @@ async fn get_available_northstar_versions() -> Result Result<(), String> { - // Perform various checks in terms of Linux compatibility - // Return early with error message if a check fails - - // check `ldd --version` to see if glibc is up to date for northstar proton - let min_required_ldd_version = 2.33; - let lddv = platform_specific::linux::check_glibc_v(); - if lddv < min_required_ldd_version { - return Err(format!( - "GLIBC is not version {} or greater", - min_required_ldd_version - )); - }; - - // All checks passed - Ok(()) -} - /// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { let path_to_titanfall2_exe = format!("{game_install_path}/Titanfall2.exe"); @@ -520,32 +481,3 @@ pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { fn get_host_os() -> String { env::consts::OS.to_string() } - -/// On Linux attempts to install NorthstarProton -/// On Windows simply returns an error message -#[tauri::command] -async fn install_northstar_proton_wrapper() -> Result<(), String> { - #[cfg(target_os = "linux")] - return platform_specific::linux::install_ns_proton().map_err(|err| err.to_string()); - - #[cfg(target_os = "windows")] - Err("Not supported on Windows".to_string()) -} - -#[tauri::command] -async fn uninstall_northstar_proton_wrapper() -> Result<(), String> { - #[cfg(target_os = "linux")] - return platform_specific::linux::uninstall_ns_proton(); - - #[cfg(target_os = "windows")] - Err("Not supported on Windows".to_string()) -} - -#[tauri::command] -async fn get_local_northstar_proton_wrapper_version() -> Result { - #[cfg(target_os = "linux")] - return platform_specific::linux::get_local_ns_proton_version(); - - #[cfg(target_os = "windows")] - Err("Not supported on Windows".to_string()) -} diff --git a/src-tauri/src/platform_specific/linux.rs b/src-tauri/src/platform_specific/linux.rs index 674f384b..706a4d22 100644 --- a/src-tauri/src/platform_specific/linux.rs +++ b/src-tauri/src/platform_specific/linux.rs @@ -3,6 +3,27 @@ use regex::Regex; use std::process::Command; +// I intend to add more linux related stuff to check here, so making a func +// for now tho it only checks `ldd --version` +// - salmon +pub fn linux_checks_librs() -> Result<(), String> { + // Perform various checks in terms of Linux compatibility + // Return early with error message if a check fails + + // check `ldd --version` to see if glibc is up to date for northstar proton + let min_required_ldd_version = 2.33; + let lddv = check_glibc_v(); + if lddv < min_required_ldd_version { + return Err(format!( + "GLIBC is not version {} or greater", + min_required_ldd_version + )); + }; + + // All checks passed + Ok(()) +} + fn get_proton_dir() -> Option { let steam_dir = steamlocate::SteamDir::locate()?; let compat_dir = format!("{}/compatibilitytools.d/", steam_dir.path.display()); diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs index 84bd478a..d5acfde8 100644 --- a/src-tauri/src/platform_specific/mod.rs +++ b/src-tauri/src/platform_specific/mod.rs @@ -3,3 +3,49 @@ pub mod windows; #[cfg(target_os = "linux")] pub mod linux; + +/// On Linux attempts to install NorthstarProton +/// On Windows simply returns an error message +#[tauri::command] +pub async fn install_northstar_proton_wrapper() -> Result<(), String> { + #[cfg(target_os = "linux")] + return linux::install_ns_proton().map_err(|err| err.to_string()); + + #[cfg(target_os = "windows")] + Err("Not supported on Windows".to_string()) +} + +#[tauri::command] +pub async fn uninstall_northstar_proton_wrapper() -> Result<(), String> { + #[cfg(target_os = "linux")] + return linux::uninstall_ns_proton(); + + #[cfg(target_os = "windows")] + Err("Not supported on Windows".to_string()) +} + +#[tauri::command] +pub async fn get_local_northstar_proton_wrapper_version() -> Result { + #[cfg(target_os = "linux")] + return linux::get_local_ns_proton_version(); + + #[cfg(target_os = "windows")] + Err("Not supported on Windows".to_string()) +} + +/// Returns true if linux compatible +#[tauri::command] +pub async fn linux_checks() -> Result<(), String> { + // Different behaviour depending on OS + // MacOS is missing as it is not a target + // in turn this means this application will not build on MacOS. + #[cfg(target_os = "windows")] + { + Err("Not available on Windows".to_string()) + } + + #[cfg(target_os = "linux")] + { + linux::linux_checks_librs() + } +} -- cgit v1.2.3 From 475ddbbede706624f6b332c06a035f2319a88f8e Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 02:49:43 +0200 Subject: refactor: Move `get_host_os` to module (#618) In an effort to clean up `main.rs` --- src-tauri/src/main.rs | 8 +------- src-tauri/src/northstar/mod.rs | 3 ++- src-tauri/src/platform_specific/mod.rs | 6 ++++++ 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6bb65a2c..3ad7a1ea 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -123,7 +123,7 @@ fn main() { northstar::get_northstar_version_number, check_is_northstar_outdated, verify_install_location, - get_host_os, + platform_specific::get_host_os, install_northstar_caller, update_northstar, northstar::launch_northstar, @@ -475,9 +475,3 @@ pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { } Ok(()) } - -/// Returns identifier of host OS FlightCore is running on -#[tauri::command] -fn get_host_os() -> String { - env::consts::OS.to_string() -} diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index 284eac41..a6b895db 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -6,7 +6,8 @@ pub mod profile; use crate::util::check_ea_app_or_origin_running; use crate::{ constants::{CORE_MODS, TITANFALL2_STEAM_ID}, - get_host_os, GameInstall, InstallType, + platform_specific::get_host_os, + GameInstall, InstallType, }; use anyhow::anyhow; diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs index d5acfde8..8dca9424 100644 --- a/src-tauri/src/platform_specific/mod.rs +++ b/src-tauri/src/platform_specific/mod.rs @@ -4,6 +4,12 @@ pub mod windows; #[cfg(target_os = "linux")] pub mod linux; +/// Returns identifier of host OS FlightCore is running on +#[tauri::command] +pub fn get_host_os() -> String { + std::env::consts::OS.to_string() +} + /// On Linux attempts to install NorthstarProton /// On Windows simply returns an error message #[tauri::command] -- cgit v1.2.3 From 1740f79673b4aad700fbd131e83bb7beab3b7a4e Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 13 Oct 2023 02:52:43 +0200 Subject: refactor: Rename all occurences of `_caller` to `_wrapper` To prepare for moving those functions to modules --- src-tauri/src/main.rs | 14 +++++++------- src-vue/src/components/ThunderstoreModCard.vue | 2 +- src-vue/src/plugins/store.ts | 4 ++-- src-vue/src/views/DeveloperView.vue | 4 ++-- src-vue/src/views/RepairView.vue | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3ad7a1ea..32804192 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -124,7 +124,7 @@ fn main() { check_is_northstar_outdated, verify_install_location, platform_specific::get_host_os, - install_northstar_caller, + install_northstar_wrapper, update_northstar, northstar::launch_northstar, northstar::launch_northstar_steam, @@ -137,8 +137,8 @@ fn main() { github::release_notes::get_northstar_release_notes, platform_specific::linux_checks, mod_management::get_installed_mods_and_properties, - install_mod_caller, - clean_up_download_folder_caller, + install_mod_wrapper, + clean_up_download_folder_wrapper, github::release_notes::get_newest_flightcore_version, mod_management::delete_northstar_mod, util::get_server_player_count, @@ -280,7 +280,7 @@ async fn verify_install_location(game_path: String) -> bool { /// Installs Northstar to the given path #[tauri::command] -async fn install_northstar_caller( +async fn install_northstar_wrapper( window: tauri::Window, game_install: GameInstall, northstar_package_name: Option, @@ -325,12 +325,12 @@ async fn update_northstar( log::info!("Updating Northstar"); // Simply re-run install with up-to-date version for upate - install_northstar_caller(window, game_install, northstar_package_name, None).await + install_northstar_wrapper(window, game_install, northstar_package_name, None).await } /// Installs the specified mod #[tauri::command] -async fn install_mod_caller( +async fn install_mod_wrapper( game_install: GameInstall, thunderstore_mod_string: String, ) -> Result<(), String> { @@ -355,7 +355,7 @@ async fn install_mod_caller( /// Installs the specified mod #[tauri::command] -async fn clean_up_download_folder_caller( +async fn clean_up_download_folder_wrapper( game_install: GameInstall, force: bool, ) -> Result<(), String> { diff --git a/src-vue/src/components/ThunderstoreModCard.vue b/src-vue/src/components/ThunderstoreModCard.vue index 54241e85..11be7545 100644 --- a/src-vue/src/components/ThunderstoreModCard.vue +++ b/src-vue/src/components/ThunderstoreModCard.vue @@ -243,7 +243,7 @@ export default defineComponent({ // Capture translation method in a context, so it can be used outside Vue component context. // (see https://github.com/R2NorthstarTools/FlightCore/issues/384) (async (translate: Function) => { - await invoke("install_mod_caller", { gameInstall: this.$store.state.game_install, thunderstoreModString: this.latestVersion.full_name }).then((message) => { + await invoke("install_mod_wrapper", { gameInstall: this.$store.state.game_install, thunderstoreModString: this.latestVersion.full_name }).then((message) => { showNotification(translate('mods.card.install_success', { modName: mod.name }), message); }) .catch((error) => { diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index f0e86613..854cd19e 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -189,7 +189,7 @@ export const store = createStore({ switch (state.northstar_state) { // Install northstar if it wasn't detected. case NorthstarState.INSTALL: - let install_northstar_result = invoke("install_northstar_caller", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal }); + let install_northstar_result = invoke("install_northstar_wrapper", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal }); state.northstar_state = NorthstarState.INSTALLING; await install_northstar_result.then((message) => { @@ -206,7 +206,7 @@ export const store = createStore({ // Update northstar if it is outdated. case NorthstarState.MUST_UPDATE: // Updating is the same as installing, simply overwrites the existing files - let reinstall_northstar_result = invoke("install_northstar_caller", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal }); + let reinstall_northstar_result = invoke("install_northstar_wrapper", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal }); state.northstar_state = NorthstarState.UPDATING; await reinstall_northstar_result.then((message) => { diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index c87e4236..aa586e6e 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -226,7 +226,7 @@ export default defineComponent({ }, async installMod() { let mod_to_install = this.mod_to_install_field_string; - await invoke("install_mod_caller", { gameInstall: this.$store.state.game_install, thunderstoreModString: mod_to_install }).then((message) => { + await invoke("install_mod_wrapper", { gameInstall: this.$store.state.game_install, thunderstoreModString: mod_to_install }).then((message) => { // Show user notification if mod install completed. showNotification(`Installed ${mod_to_install}`, message); }) @@ -294,7 +294,7 @@ export default defineComponent({ 0 ); - let install_northstar_result = invoke("install_northstar_caller", { gameInstall: this.$store.state.game_install, northstarPackageName: this.selected_ns_version.value.package, versionNumber: this.selected_ns_version.value.version }); + let install_northstar_result = invoke("install_northstar_wrapper", { gameInstall: this.$store.state.game_install, northstarPackageName: this.selected_ns_version.value.package, versionNumber: this.selected_ns_version.value.version }); await install_northstar_result .then((message) => { diff --git a/src-vue/src/views/RepairView.vue b/src-vue/src/views/RepairView.vue index ce7e154d..341dff2d 100644 --- a/src-vue/src/views/RepairView.vue +++ b/src-vue/src/views/RepairView.vue @@ -75,7 +75,7 @@ export default defineComponent({ 0 ); - let install_northstar_result = invoke("install_northstar_caller", { gameInstall: this.$store.state.game_install, northstarPackageName: ReleaseCanal.RELEASE }); + let install_northstar_result = invoke("install_northstar_wrapper", { gameInstall: this.$store.state.game_install, northstarPackageName: ReleaseCanal.RELEASE }); appWindow.listen( 'northstar-install-download-progress', @@ -102,7 +102,7 @@ export default defineComponent({ }); }, async cleanUpDownloadFolder() { - await invoke("clean_up_download_folder_caller", { gameInstall: this.$store.state.game_install, force: true }).then((message) => { + await invoke("clean_up_download_folder_wrapper", { gameInstall: this.$store.state.game_install, force: true }).then((message) => { // Show user notification if task completed. showNotification(this.$t('generic.done'), this.$t('generic.done')); }) -- cgit v1.2.3 From 6003069ebbbfeacae7b9d5adfb88c6ef41821de8 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 03:21:46 +0200 Subject: refactor: Move NS installation logic to module (#619) Move Northstar installation logic to module in order to clean up `main.rs` --- src-tauri/src/main.rs | 54 ++------------------------------------ src-tauri/src/northstar/install.rs | 43 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 52 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 32804192..6b0425cd 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -124,8 +124,8 @@ fn main() { check_is_northstar_outdated, verify_install_location, platform_specific::get_host_os, - install_northstar_wrapper, - update_northstar, + northstar::install::install_northstar_wrapper, + northstar::install::update_northstar, northstar::launch_northstar, northstar::launch_northstar_steam, github::release_notes::check_is_flightcore_outdated, @@ -278,56 +278,6 @@ async fn verify_install_location(game_path: String) -> bool { } } -/// Installs Northstar to the given path -#[tauri::command] -async fn install_northstar_wrapper( - window: tauri::Window, - game_install: GameInstall, - northstar_package_name: Option, - version_number: Option, -) -> Result { - log::info!("Running Northstar install"); - - // Get Northstar package name (`Northstar` vs `NorthstarReleaseCandidate`) - let northstar_package_name = northstar_package_name - .map(|name| { - if name.len() <= 1 { - "Northstar".to_string() - } else { - name - } - }) - .unwrap_or("Northstar".to_string()); - - match northstar::install::install_northstar( - window, - game_install, - northstar_package_name, - version_number, - ) - .await - { - Ok(_) => Ok(true), - Err(err) => { - log::error!("{}", err); - Err(err) - } - } -} - -/// Update Northstar install in the given path -#[tauri::command] -async fn update_northstar( - window: tauri::Window, - game_install: GameInstall, - northstar_package_name: Option, -) -> Result { - log::info!("Updating Northstar"); - - // Simply re-run install with up-to-date version for upate - install_northstar_wrapper(window, game_install, northstar_package_name, None).await -} - /// Installs the specified mod #[tauri::command] async fn install_mod_wrapper( diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 757f6c68..693d7af2 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -29,6 +29,49 @@ struct InstallProgress { state: InstallState, } +/// Installs Northstar to the given path +#[tauri::command] +pub async fn install_northstar_wrapper( + window: tauri::Window, + game_install: GameInstall, + northstar_package_name: Option, + version_number: Option, +) -> Result { + log::info!("Running Northstar install"); + + // Get Northstar package name (`Northstar` vs `NorthstarReleaseCandidate`) + let northstar_package_name = northstar_package_name + .map(|name| { + if name.len() <= 1 { + "Northstar".to_string() + } else { + name + } + }) + .unwrap_or("Northstar".to_string()); + + match install_northstar(window, game_install, northstar_package_name, version_number).await { + Ok(_) => Ok(true), + Err(err) => { + log::error!("{}", err); + Err(err) + } + } +} + +/// Update Northstar install in the given path +#[tauri::command] +pub async fn update_northstar( + window: tauri::Window, + game_install: GameInstall, + northstar_package_name: Option, +) -> Result { + log::info!("Updating Northstar"); + + // Simply re-run install with up-to-date version for upate + install_northstar_wrapper(window, game_install, northstar_package_name, None).await +} + /// Copied from `papa` source code and modified ///Install N* from the provided mod /// -- cgit v1.2.3 From f49ab2e39ea479af886ecd3c325d16bc4df4046f Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 03:26:15 +0200 Subject: docs: Add doc comments to some structs (#621) --- src-tauri/src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6b0425cd..1d20bf74 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -387,6 +387,7 @@ async fn get_available_northstar_versions() -> Result Date: Fri, 13 Oct 2023 12:42:50 +0200 Subject: refactor: Move repair/verify related funcs to mod (#622) Moves functions related to game install path verification checks to dedicated module in an effort to clean up `main.rs` --- src-tauri/src/github/pull_requests.rs | 2 +- src-tauri/src/main.rs | 27 +-------------------------- src-tauri/src/platform_specific/windows.rs | 2 +- src-tauri/src/repair_and_verify/mod.rs | 25 +++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index ccb45dff..91d8a5da 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -1,7 +1,7 @@ use crate::github::release_notes::fetch_github_releases_api; -use crate::check_is_valid_game_path; use crate::constants::{APP_USER_AGENT, PULLS_API_ENDPOINT_LAUNCHER, PULLS_API_ENDPOINT_MODS}; +use crate::repair_and_verify::check_is_valid_game_path; use crate::GameInstall; use anyhow::anyhow; use serde::{Deserialize, Serialize}; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 1d20bf74..93f67a33 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -122,7 +122,7 @@ fn main() { get_flightcore_version_number, northstar::get_northstar_version_number, check_is_northstar_outdated, - verify_install_location, + repair_and_verify::verify_install_location, platform_specific::get_host_os, northstar::install::install_northstar_wrapper, northstar::install::update_northstar, @@ -266,18 +266,6 @@ async fn check_is_northstar_outdated( } } -/// Checks if is valid Titanfall2 install based on certain conditions -#[tauri::command] -async fn verify_install_location(game_path: String) -> bool { - match check_is_valid_game_path(&game_path) { - Ok(()) => true, - Err(err) => { - log::warn!("{}", err); - false - } - } -} - /// Installs the specified mod #[tauri::command] async fn install_mod_wrapper( @@ -418,16 +406,3 @@ pub struct NorthstarMod { pub enabled: bool, pub directory: String, } - -/// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria -pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { - let path_to_titanfall2_exe = format!("{game_install_path}/Titanfall2.exe"); - let is_correct_game_path = std::path::Path::new(&path_to_titanfall2_exe).exists(); - log::info!("Titanfall2.exe exists in path? {}", is_correct_game_path); - - // Exit early if wrong game path - if !is_correct_game_path { - return Err(format!("Incorrect game path \"{game_install_path}\"")); // Return error cause wrong game path - } - Ok(()) -} diff --git a/src-tauri/src/platform_specific/windows.rs b/src-tauri/src/platform_specific/windows.rs index 899ab2cd..678e5be5 100644 --- a/src-tauri/src/platform_specific/windows.rs +++ b/src-tauri/src/platform_specific/windows.rs @@ -4,7 +4,7 @@ use anyhow::{anyhow, Result}; #[cfg(target_os = "windows")] use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey}; -use crate::check_is_valid_game_path; +use crate::repair_and_verify::check_is_valid_game_path; /// Gets Titanfall2 install location on Origin pub fn origin_install_location_detection() -> Result { diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 70abc127..11dbee0e 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -2,6 +2,31 @@ use crate::mod_management::{get_enabled_mods, rebuild_enabled_mods_json, set_mod /// Contains various functions to repair common issues and verifying installation use crate::{constants::CORE_MODS, GameInstall}; +/// Checks if is valid Titanfall2 install based on certain conditions +#[tauri::command] +pub async fn verify_install_location(game_path: String) -> bool { + match check_is_valid_game_path(&game_path) { + Ok(()) => true, + Err(err) => { + log::warn!("{}", err); + false + } + } +} + +/// Checks whether the provided path is a valid Titanfall2 gamepath by checking against a certain set of criteria +pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { + let path_to_titanfall2_exe = format!("{game_install_path}/Titanfall2.exe"); + let is_correct_game_path = std::path::Path::new(&path_to_titanfall2_exe).exists(); + log::info!("Titanfall2.exe exists in path? {}", is_correct_game_path); + + // Exit early if wrong game path + if !is_correct_game_path { + return Err(format!("Incorrect game path \"{game_install_path}\"")); // Return error cause wrong game path + } + Ok(()) +} + /// Verifies Titanfall2 game files #[tauri::command] pub fn verify_game_files(game_install: GameInstall) -> Result { -- cgit v1.2.3 From b3b558dbab5ac41a64f36d36aac81f0b996101b0 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 13:21:06 +0200 Subject: refactor: Move relevant functions to util module (#623) * refactor: Move to `get_flightcore_version_number` to util module * refactor: Move to `open_repair_window` to util mod * refactor: Move to `close_application` to util mod --- src-tauri/src/main.rs | 51 ++++----------------------------------------------- src-tauri/src/util.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 93f67a33..8d6ea769 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize}; use tauri::api::dialog::blocking::MessageDialogBuilder; #[cfg(target_os = "windows")] use tauri::api::dialog::{MessageDialogButtons, MessageDialogKind}; -use tauri::{Manager, Runtime}; +use tauri::Manager; use tokio::time::sleep; use ts_rs::TS; @@ -119,7 +119,7 @@ fn main() { .invoke_handler(tauri::generate_handler![ util::force_panic, northstar::install::find_game_install_location, - get_flightcore_version_number, + util::get_flightcore_version_number, northstar::get_northstar_version_number, check_is_northstar_outdated, repair_and_verify::verify_install_location, @@ -147,7 +147,7 @@ fn main() { platform_specific::install_northstar_proton_wrapper, platform_specific::uninstall_northstar_proton_wrapper, platform_specific::get_local_northstar_proton_wrapper_version, - open_repair_window, + util::open_repair_window, thunderstore::query_thunderstore_packages_api, github::get_list_of_tags, github::compare_tags, @@ -155,7 +155,7 @@ fn main() { github::pull_requests::apply_launcher_pr, github::pull_requests::apply_mods_pr, github::pull_requests::get_launcher_download_link, - close_application, + util::close_application, development::install_git_main, get_available_northstar_versions, northstar::profile::fetch_profiles, @@ -194,19 +194,6 @@ fn main() { }; } -/// Returns the current version number as a string -#[tauri::command] -async fn get_flightcore_version_number() -> String { - let version = env!("CARGO_PKG_VERSION"); - if cfg!(debug_assertions) { - // Debugging enabled - format!("v{} (debug mode)", version) - } else { - // Debugging disabled - format!("v{}", version) - } -} - /// Helps with converting release candidate numbers which are different on Thunderstore /// due to restrictions imposed by the platform pub fn convert_release_candidate_number(version_number: String) -> String { @@ -303,36 +290,6 @@ async fn clean_up_download_folder_wrapper( } } -/// Spawns repair window -#[tauri::command] -async fn open_repair_window(handle: tauri::AppHandle) -> Result<(), String> { - // Spawn new window - let repair_window = match tauri::WindowBuilder::new( - &handle, - "RepairWindow", - tauri::WindowUrl::App("/#/repair".into()), - ) - .build() - { - Ok(res) => res, - Err(err) => return Err(err.to_string()), - }; - - // Set window title - match repair_window.set_title("FlightCore Repair Window") { - Ok(()) => (), - Err(err) => return Err(err.to_string()), - }; - Ok(()) -} - -/// Closes all windows and exits application -#[tauri::command] -async fn close_application(app: tauri::AppHandle) -> Result<(), String> { - app.exit(0); // Close application - Ok(()) -} - /// Gets list of available Northstar versions from Thunderstore #[tauri::command] async fn get_available_northstar_versions() -> Result, ()> diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index b21b2208..274cf488 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -26,6 +26,49 @@ pub async fn is_debug_mode() -> bool { cfg!(debug_assertions) } +/// Returns the current version number as a string +#[tauri::command] +pub async fn get_flightcore_version_number() -> String { + let version = env!("CARGO_PKG_VERSION"); + if cfg!(debug_assertions) { + // Debugging enabled + format!("v{} (debug mode)", version) + } else { + // Debugging disabled + format!("v{}", version) + } +} + +/// Spawns repair window +#[tauri::command] +pub async fn open_repair_window(handle: tauri::AppHandle) -> Result<(), String> { + // Spawn new window + let repair_window = match tauri::WindowBuilder::new( + &handle, + "RepairWindow", + tauri::WindowUrl::App("/#/repair".into()), + ) + .build() + { + Ok(res) => res, + Err(err) => return Err(err.to_string()), + }; + + // Set window title + match repair_window.set_title("FlightCore Repair Window") { + Ok(()) => (), + Err(err) => return Err(err.to_string()), + }; + Ok(()) +} + +/// Closes all windows and exits application +#[tauri::command] +pub async fn close_application(app: tauri::AppHandle) -> Result<(), String> { + app.exit(0); // Close application + Ok(()) +} + /// Fetches `/client/servers` endpoint from master server async fn fetch_server_list() -> Result { let url = format!("{MASTER_SERVER_URL}{SERVER_BROWSER_ENDPOINT}"); -- cgit v1.2.3 From b58d8d138919ec911369b644d7a49c94215c77a9 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 13:43:51 +0200 Subject: refactor: Move relevant functions to northstar module (#626) * refactor: Move `get_available_northstar_versions` to northstar module * refactor: Move `check_is_northstar_outdated` to northstar module --- src-tauri/src/main.rs | 97 ++---------------------------------------- src-tauri/src/northstar/mod.rs | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 94 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8d6ea769..207a148a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -19,7 +19,6 @@ mod repair_and_verify; mod thunderstore; mod util; -use semver::Version; use serde::{Deserialize, Serialize}; #[cfg(target_os = "windows")] use tauri::api::dialog::blocking::MessageDialogBuilder; @@ -38,7 +37,7 @@ struct NorthstarThunderstoreRelease { #[derive(Serialize, Deserialize, Debug, Clone, TS)] #[ts(export)] -struct NorthstarThunderstoreReleaseWrapper { +pub struct NorthstarThunderstoreReleaseWrapper { label: String, value: NorthstarThunderstoreRelease, } @@ -121,7 +120,7 @@ fn main() { northstar::install::find_game_install_location, util::get_flightcore_version_number, northstar::get_northstar_version_number, - check_is_northstar_outdated, + northstar::check_is_northstar_outdated, repair_and_verify::verify_install_location, platform_specific::get_host_os, northstar::install::install_northstar_wrapper, @@ -157,7 +156,7 @@ fn main() { github::pull_requests::get_launcher_download_link, util::close_application, development::install_git_main, - get_available_northstar_versions, + northstar::get_available_northstar_versions, northstar::profile::fetch_profiles, northstar::profile::validate_profile, northstar::profile::delete_profile, @@ -203,56 +202,6 @@ pub fn convert_release_candidate_number(version_number: String) -> String { version_number.replace("-rc", "0").replace("00", "") } -/// Checks if installed Northstar version is up-to-date -/// false -> Northstar install is up-to-date -/// true -> Northstar install is outdated -#[tauri::command] -async fn check_is_northstar_outdated( - game_install: GameInstall, - northstar_package_name: Option, -) -> Result { - let northstar_package_name = match northstar_package_name { - Some(northstar_package_name) => { - if northstar_package_name.len() <= 1 { - "Northstar".to_string() - } else { - northstar_package_name - } - } - None => "Northstar".to_string(), - }; - - let index = match thermite::api::get_package_index() { - Ok(res) => res.to_vec(), - Err(err) => return Err(format!("Couldn't check if Northstar up-to-date: {err}")), - }; - let nmod = index - .iter() - .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase()) - .expect("Couldn't find Northstar on thunderstore???"); - // .ok_or_else(|| anyhow!("Couldn't find Northstar on thunderstore???"))?; - - let version_number = match northstar::get_northstar_version_number(game_install) { - Ok(version_number) => version_number, - Err(err) => { - log::warn!("{}", err); - // If we fail to get new version just assume we are up-to-date - return Err(err); - } - }; - - // Release candidate version numbers are different between `mods.json` and Thunderstore - let version_number = convert_release_candidate_number(version_number); - - if version_number != nmod.latest { - log::info!("Installed Northstar version outdated"); - Ok(true) - } else { - log::info!("Installed Northstar version up-to-date"); - Ok(false) - } -} - /// Installs the specified mod #[tauri::command] async fn install_mod_wrapper( @@ -290,46 +239,6 @@ async fn clean_up_download_folder_wrapper( } } -/// Gets list of available Northstar versions from Thunderstore -#[tauri::command] -async fn get_available_northstar_versions() -> Result, ()> -{ - let northstar_package_name = "Northstar"; - let index = thermite::api::get_package_index().unwrap().to_vec(); - let nsmod = index - .iter() - .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase()) - .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???")) - .unwrap(); - - let mut releases: Vec = vec![]; - for (_version_string, nsmod_version_obj) in nsmod.versions.iter() { - let current_elem = NorthstarThunderstoreRelease { - package: nsmod_version_obj.name.clone(), - version: nsmod_version_obj.version.clone(), - }; - let current_elem_wrapped = NorthstarThunderstoreReleaseWrapper { - label: format!( - "{} v{}", - nsmod_version_obj.name.clone(), - nsmod_version_obj.version.clone() - ), - value: current_elem, - }; - - releases.push(current_elem_wrapped); - } - - releases.sort_by(|a, b| { - // Parse version number - let a_ver = Version::parse(&a.value.version).unwrap(); - let b_ver = Version::parse(&b.value.version).unwrap(); - b_ver.partial_cmp(&a_ver).unwrap() // Sort newest first - }); - - Ok(releases) -} - use anyhow::Result; /// Defines how Titanfall2 was installed (Steam, Origin, ...) diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index a6b895db..1c2023b6 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -9,8 +9,99 @@ use crate::{ platform_specific::get_host_os, GameInstall, InstallType, }; +use crate::{NorthstarThunderstoreRelease, NorthstarThunderstoreReleaseWrapper}; use anyhow::anyhow; +/// Gets list of available Northstar versions from Thunderstore +#[tauri::command] +pub async fn get_available_northstar_versions( +) -> Result, ()> { + let northstar_package_name = "Northstar"; + let index = thermite::api::get_package_index().unwrap().to_vec(); + let nsmod = index + .iter() + .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase()) + .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???")) + .unwrap(); + + let mut releases: Vec = vec![]; + for (_version_string, nsmod_version_obj) in nsmod.versions.iter() { + let current_elem = NorthstarThunderstoreRelease { + package: nsmod_version_obj.name.clone(), + version: nsmod_version_obj.version.clone(), + }; + let current_elem_wrapped = NorthstarThunderstoreReleaseWrapper { + label: format!( + "{} v{}", + nsmod_version_obj.name.clone(), + nsmod_version_obj.version.clone() + ), + value: current_elem, + }; + + releases.push(current_elem_wrapped); + } + + releases.sort_by(|a, b| { + // Parse version number + let a_ver = semver::Version::parse(&a.value.version).unwrap(); + let b_ver = semver::Version::parse(&b.value.version).unwrap(); + b_ver.partial_cmp(&a_ver).unwrap() // Sort newest first + }); + + Ok(releases) +} + +/// Checks if installed Northstar version is up-to-date +/// false -> Northstar install is up-to-date +/// true -> Northstar install is outdated +#[tauri::command] +pub async fn check_is_northstar_outdated( + game_install: GameInstall, + northstar_package_name: Option, +) -> Result { + let northstar_package_name = match northstar_package_name { + Some(northstar_package_name) => { + if northstar_package_name.len() <= 1 { + "Northstar".to_string() + } else { + northstar_package_name + } + } + None => "Northstar".to_string(), + }; + + let index = match thermite::api::get_package_index() { + Ok(res) => res.to_vec(), + Err(err) => return Err(format!("Couldn't check if Northstar up-to-date: {err}")), + }; + let nmod = index + .iter() + .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase()) + .expect("Couldn't find Northstar on thunderstore???"); + // .ok_or_else(|| anyhow!("Couldn't find Northstar on thunderstore???"))?; + + let version_number = match get_northstar_version_number(game_install) { + Ok(version_number) => version_number, + Err(err) => { + log::warn!("{}", err); + // If we fail to get new version just assume we are up-to-date + return Err(err); + } + }; + + // Release candidate version numbers are different between `mods.json` and Thunderstore + let version_number = crate::convert_release_candidate_number(version_number); + + if version_number != nmod.latest { + log::info!("Installed Northstar version outdated"); + Ok(true) + } else { + log::info!("Installed Northstar version up-to-date"); + Ok(false) + } +} + /// Check version number of a mod pub fn check_mod_version_number(path_to_mod_folder: &str) -> Result { let data = std::fs::read_to_string(format!("{path_to_mod_folder}/mod.json"))?; -- cgit v1.2.3 From fbaa5d7ad4d3674f991ae73c672190cdd6ddac01 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:07:43 +0200 Subject: refactor: Move `install_mod_wrapper` (#627) Move `install_mod_wrapper` to `mod_management` module to clean up `main.rs`. --- src-tauri/src/main.rs | 27 +-------------------------- src-tauri/src/mod_management/mod.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 26 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 207a148a..3290912d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -136,7 +136,7 @@ fn main() { github::release_notes::get_northstar_release_notes, platform_specific::linux_checks, mod_management::get_installed_mods_and_properties, - install_mod_wrapper, + mod_management::install_mod_wrapper, clean_up_download_folder_wrapper, github::release_notes::get_newest_flightcore_version, mod_management::delete_northstar_mod, @@ -202,31 +202,6 @@ pub fn convert_release_candidate_number(version_number: String) -> String { version_number.replace("-rc", "0").replace("00", "") } -/// Installs the specified mod -#[tauri::command] -async fn install_mod_wrapper( - game_install: GameInstall, - thunderstore_mod_string: String, -) -> Result<(), String> { - match mod_management::fc_download_mod_and_install(&game_install, &thunderstore_mod_string).await - { - Ok(()) => (), - Err(err) => { - log::warn!("{err}"); - return Err(err); - } - }; - match repair_and_verify::clean_up_download_folder(&game_install, false) { - Ok(()) => Ok(()), - Err(err) => { - log::info!("Failed to delete download folder due to {}", err); - // Failure to delete download folder is not an error in mod install - // As such ignore. User can still force delete if need be - Ok(()) - } - } -} - /// Installs the specified mod #[tauri::command] async fn clean_up_download_folder_wrapper( diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index a9826522..ab639b11 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -89,6 +89,30 @@ impl std::ops::Deref for TempFile { } } +/// Installs the specified mod +#[tauri::command] +pub async fn install_mod_wrapper( + game_install: GameInstall, + thunderstore_mod_string: String, +) -> Result<(), String> { + match fc_download_mod_and_install(&game_install, &thunderstore_mod_string).await { + Ok(()) => (), + Err(err) => { + log::warn!("{err}"); + return Err(err); + } + }; + match crate::repair_and_verify::clean_up_download_folder(&game_install, false) { + Ok(()) => Ok(()), + Err(err) => { + log::info!("Failed to delete download folder due to {}", err); + // Failure to delete download folder is not an error in mod install + // As such ignore. User can still force delete if need be + Ok(()) + } + } +} + /// Returns a serde json object of the parsed `enabledmods.json` file pub fn get_enabled_mods(game_install: &GameInstall) -> Result { let enabledmods_json_path = format!( -- cgit v1.2.3 From 1b656b824b12c1d70b9ad5f2d01ad63db1667a3e Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:35:24 +0200 Subject: refactor: Move `clean_up_download_folder_wrapper` (#628) to `repair_and_verify` module --- src-tauri/src/main.rs | 16 +--------------- src-tauri/src/repair_and_verify/mod.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3290912d..6553db99 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -137,7 +137,7 @@ fn main() { platform_specific::linux_checks, mod_management::get_installed_mods_and_properties, mod_management::install_mod_wrapper, - clean_up_download_folder_wrapper, + repair_and_verify::clean_up_download_folder_wrapper, github::release_notes::get_newest_flightcore_version, mod_management::delete_northstar_mod, util::get_server_player_count, @@ -202,20 +202,6 @@ pub fn convert_release_candidate_number(version_number: String) -> String { version_number.replace("-rc", "0").replace("00", "") } -/// Installs the specified mod -#[tauri::command] -async fn clean_up_download_folder_wrapper( - game_install: GameInstall, - force: bool, -) -> Result<(), String> { - match repair_and_verify::clean_up_download_folder(&game_install, force) { - Ok(()) => Ok(()), - Err(err) => Err(err.to_string()), - } -} - -use anyhow::Result; - /// Defines how Titanfall2 was installed (Steam, Origin, ...) #[derive(Serialize, Deserialize, Debug, Clone, TS)] #[ts(export)] diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 11dbee0e..c752a3ab 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -57,6 +57,18 @@ pub fn disable_all_but_core(game_install: GameInstall) -> Result<(), String> { Ok(()) } +/// Installs the specified mod +#[tauri::command] +pub async fn clean_up_download_folder_wrapper( + game_install: GameInstall, + force: bool, +) -> Result<(), String> { + match clean_up_download_folder(&game_install, force) { + Ok(()) => Ok(()), + Err(err) => Err(err.to_string()), + } +} + /// Deletes download folder /// If `force` is FALSE, bails on non-empty folder /// If `force` is TRUE, deletes folder even if non-empty -- cgit v1.2.3 From 1f3c3f070ac2cdbbad9a9c3a1614eecab14c0506 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:51:50 +0200 Subject: refactor: Move `convert_release_candidate_number` (#629) to `util` module --- src-tauri/src/main.rs | 9 --------- src-tauri/src/northstar/mod.rs | 2 +- src-tauri/src/util.rs | 9 +++++++++ 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6553db99..09242680 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -193,15 +193,6 @@ fn main() { }; } -/// Helps with converting release candidate numbers which are different on Thunderstore -/// due to restrictions imposed by the platform -pub fn convert_release_candidate_number(version_number: String) -> String { - // This simply converts `-rc` to `0` - // Works as intended for RCs < 10, e.g. `v1.9.2-rc1` -> `v1.9.201` - // Doesn't work for larger numbers, e.g. `v1.9.2-rc11` -> `v1.9.2011` (should be `v1.9.211`) - version_number.replace("-rc", "0").replace("00", "") -} - /// Defines how Titanfall2 was installed (Steam, Origin, ...) #[derive(Serialize, Deserialize, Debug, Clone, TS)] #[ts(export)] diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index 1c2023b6..e707849e 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -91,7 +91,7 @@ pub async fn check_is_northstar_outdated( }; // Release candidate version numbers are different between `mods.json` and Thunderstore - let version_number = crate::convert_release_candidate_number(version_number); + let version_number = crate::util::convert_release_candidate_number(version_number); if version_number != nmod.latest { log::info!("Installed Northstar version outdated"); diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index 274cf488..75555f3e 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -225,3 +225,12 @@ pub fn move_dir_all( } Ok(()) } + +/// Helps with converting release candidate numbers which are different on Thunderstore +/// due to restrictions imposed by the platform +pub fn convert_release_candidate_number(version_number: String) -> String { + // This simply converts `-rc` to `0` + // Works as intended for RCs < 10, e.g. `v1.9.2-rc1` -> `v1.9.201` + // Doesn't work for larger numbers, e.g. `v1.9.2-rc11` -> `v1.9.2011` (should be `v1.9.211`) + version_number.replace("-rc", "0").replace("00", "") +} -- cgit v1.2.3