From 40520344778a98c45817e9cbc00caab6ec3ea6bf Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 30 Jul 2023 01:24:18 +0200 Subject: refactor: Add Profile to GameInstall (#453) Add Profile to GameInstall Replace hardcoded uses of R2Northstar with profile attribute --- src-tauri/src/main.rs | 1 + src-tauri/src/mod_management/legacy.rs | 2 +- src-tauri/src/mod_management/mod.rs | 35 +++++++++++++++++++++++++++------- src-tauri/src/northstar/install.rs | 2 ++ src-tauri/src/northstar/mod.rs | 9 +++++++-- src-tauri/src/repair_and_verify/mod.rs | 2 +- 6 files changed, 40 insertions(+), 11 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 1067f5d3..476ee9cf 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -467,6 +467,7 @@ pub enum InstallType { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct GameInstall { pub game_path: String, + pub profile: String, pub install_type: InstallType, } diff --git a/src-tauri/src/mod_management/legacy.rs b/src-tauri/src/mod_management/legacy.rs index 91463250..1e9f90f5 100644 --- a/src-tauri/src/mod_management/legacy.rs +++ b/src-tauri/src/mod_management/legacy.rs @@ -45,7 +45,7 @@ fn parse_for_thunderstore_mod_string(nsmod_path: &str) -> Result Result, anyhow::Error> { - let ns_mods_folder = format!("{}/R2Northstar/mods/", game_install.game_path); + let ns_mods_folder = format!("{}/{}/mods/", game_install.game_path, game_install.profile); let paths = match std::fs::read_dir(ns_mods_folder) { Ok(paths) => paths, diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index 879d3b04..a5f928bd 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -91,7 +91,10 @@ impl std::ops::Deref for TempFile { /// 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!("{}/R2Northstar/enabledmods.json", game_install.game_path); + let enabledmods_json_path = format!( + "{}/{}/enabledmods.json", + game_install.game_path, game_install.profile + ); // Check for JSON file if !std::path::Path::new(&enabledmods_json_path).exists() { @@ -116,7 +119,10 @@ pub fn get_enabled_mods(game_install: &GameInstall) -> Result Result<(), String> { - let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path); + let enabledmods_json_path = format!( + "{}/{}/enabledmods.json", + game_install.game_path, game_install.profile + ); let mods_and_properties = get_installed_mods_and_properties(game_install.clone())?; // Create new mapping @@ -147,7 +153,10 @@ pub fn set_mod_enabled_status( mod_name: String, is_enabled: bool, ) -> Result<(), String> { - let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path); + let enabledmods_json_path = format!( + "{}/{}/enabledmods.json", + game_install.game_path, game_install.profile + ); // Parse JSON let mut res: serde_json::Value = match get_enabled_mods(&game_install) { @@ -260,7 +269,10 @@ pub fn parse_installed_package_mods( ) -> Result, anyhow::Error> { let mut collected_mods: Vec = Vec::new(); - let packages_folder = format!("{}/R2Northstar/packages/", game_install.game_path); + let packages_folder = format!( + "{}/{}/packages/", + game_install.game_path, game_install.profile + ); let packages_dir = match fs::read_dir(packages_folder) { Ok(res) => res, @@ -420,7 +432,10 @@ fn delete_older_versions( "Deleting other versions of {}", thunderstore_mod_string.to_string() ); - let packages_folder = format!("{}/R2Northstar/packages", game_install.game_path); + let packages_folder = format!( + "{}/{}/packages", + game_install.game_path, game_install.profile + ); // Get folders in packages dir let paths = match std::fs::read_dir(&packages_folder) { @@ -590,7 +605,10 @@ pub async fn fc_download_mod_and_install( }; // Get directory to install to made up of packages directory and Thunderstore mod string - let install_directory = format!("{}/R2Northstar/packages/", game_install.game_path); + let install_directory = format!( + "{}/{}/packages/", + game_install.game_path, game_install.profile + ); // Extract the mod to the mods directory match thermite::core::manage::install_with_sanity( @@ -703,7 +721,10 @@ pub fn delete_thunderstore_mod( thunderstore_mod_string: String, ) -> Result<(), String> { // Check packages - let packages_folder = format!("{}/R2Northstar/packages", game_install.game_path); + let packages_folder = format!( + "{}/{}/packages", + game_install.game_path, game_install.profile + ); if std::path::Path::new(&packages_folder).exists() { for entry in fs::read_dir(packages_folder).unwrap() { let entry = entry.unwrap(); diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index c77fd538..2d96b00e 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -190,6 +190,7 @@ pub fn find_game_install_location() -> Result { // println!("{:#?}", app); let game_install = GameInstall { game_path: app.path.to_str().unwrap().to_string(), + profile: "R2Northstar".to_string(), install_type: InstallType::STEAM, }; return Ok(game_install); @@ -206,6 +207,7 @@ pub fn find_game_install_location() -> Result { Ok(game_path) => { let game_install = GameInstall { game_path, + profile: "R2Northstar".to_string(), install_type: InstallType::ORIGIN, }; return Ok(game_install); diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index bf55603b..85d792d6 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -112,8 +112,10 @@ pub fn launch_northstar( || matches!(game_install.install_type, InstallType::UNKNOWN)) { let ns_exe_path = format!("{}/NorthstarLauncher.exe", game_install.game_path); + let ns_profile_arg = format!("-profile={}", game_install.profile); + let _output = std::process::Command::new("C:\\Windows\\System32\\cmd.exe") - .args(["/C", "start", "", &ns_exe_path]) + .args(["/C", "start", "", &ns_exe_path, &ns_profile_arg]) .spawn() .expect("failed to execute process"); return Ok("Launched game".to_string()); @@ -173,7 +175,10 @@ pub fn launch_northstar_steam( return Err("Couldn't access Titanfall2 directory".to_string()); } - match open::that(format!("steam://run/{}//--northstar/", TITANFALL2_STEAM_ID)) { + match open::that(format!( + "steam://run/{}//-profile={} --northstar/", + TITANFALL2_STEAM_ID, game_install.profile + )) { Ok(()) => Ok("Started game".to_string()), Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()), } diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 92835a4e..17c71992 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -66,7 +66,7 @@ pub fn clean_up_download_folder( /// Get list of Northstar logs #[tauri::command] pub fn get_log_list(game_install: GameInstall) -> Result, String> { - let ns_log_folder = format!("{}/R2Northstar/logs", game_install.game_path); + let ns_log_folder = format!("{}/{}/logs", game_install.game_path, game_install.profile); // List files in logs folder let paths = match std::fs::read_dir(ns_log_folder) { -- cgit v1.2.3 From 14fdc631291a117b8a137b6fbbebfe3dea3a8697 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sun, 30 Jul 2023 02:11:28 +0200 Subject: refactor: Replace naive `game_path` argument with `GameInstall` (#454) We should always pass the whole object instead of just a field for easier expandability in the future Co-authored-by: Jan200101 --- src-tauri/src/main.rs | 4 ++-- src-tauri/src/northstar/mod.rs | 14 +++++++------- src-vue/src/plugins/store.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 476ee9cf..e1d99f61 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -234,7 +234,7 @@ pub fn convert_release_candidate_number(version_number: String) -> String { /// true -> Northstar install is outdated #[tauri::command] async fn check_is_northstar_outdated( - game_path: String, + game_install: GameInstall, northstar_package_name: Option, ) -> Result { let northstar_package_name = match northstar_package_name { @@ -258,7 +258,7 @@ async fn check_is_northstar_outdated( .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_path) { + let version_number = match northstar::get_northstar_version_number(game_install) { Ok(version_number) => version_number, Err(err) => { log::warn!("{}", err); diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index 85d792d6..173495c6 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -26,15 +26,14 @@ pub fn check_mod_version_number(path_to_mod_folder: &str) -> Result Result { - log::info!("{}", game_path); +pub fn get_northstar_version_number(game_install: GameInstall) -> Result { + log::info!("{}", game_install.game_path); // TODO: // Check if NorthstarLauncher.exe exists and check its version number - let profile_folder = "R2Northstar"; let initial_version_number = match check_mod_version_number(&format!( - "{game_path}/{profile_folder}/mods/{}", - CORE_MODS[0] + "{}/{}/mods/{}", + game_install.game_path, game_install.profile, CORE_MODS[0] )) { Ok(version_number) => version_number, Err(err) => return Err(err.to_string()), @@ -42,7 +41,8 @@ pub fn get_northstar_version_number(game_path: &str) -> Result { for core_mod in CORE_MODS { let current_version_number = match check_mod_version_number(&format!( - "{game_path}/{profile_folder}/mods/{core_mod}", + "{}/{}/mods/{}", + game_install.game_path, game_install.profile, core_mod )) { Ok(version_number) => version_number, Err(err) => return Err(err.to_string()), @@ -85,7 +85,7 @@ pub fn launch_northstar( // Only check guards if bypassing checks is not enabled if !bypass_checks { // Some safety checks before, should have more in the future - if get_northstar_version_number(&game_install.game_path).is_err() { + if get_northstar_version_number(game_install.clone()).is_err() { return Err(anyhow!("Not all checks were met").to_string()); } diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 2991ad1d..aee8bbce 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -465,13 +465,13 @@ function _initializeListeners(state: any) { * state, for it to be displayed in UI. */ async function _get_northstar_version_number(state: any) { - await invoke("get_northstar_version_number", { gamePath: state.game_install.game_path }) + await invoke("get_northstar_version_number", { gameInstall: state.game_install }) .then((message) => { let northstar_version_number: string = message as string; state.installed_northstar_version = northstar_version_number; state.northstar_state = NorthstarState.READY_TO_PLAY; - invoke("check_is_northstar_outdated", { gamePath: state.game_install.game_path, northstarPackageName: state.northstar_release_canal }) + invoke("check_is_northstar_outdated", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal }) .then((message) => { if (message) { state.northstar_state = NorthstarState.MUST_UPDATE; -- cgit v1.2.3 From 61e5294aef101fac02269dd7db6fddc0bcf68ca4 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 30 Jul 2023 02:32:33 +0200 Subject: feat: Add button to forcefully terminate Northstar (#451) to DevView Kills `NorthstarLauncher.exe` and `Titanfall2.exe` processes. --- src-tauri/src/main.rs | 1 + src-tauri/src/util.rs | 23 ++++++++++++++++++++++- src-vue/src/views/DeveloperView.vue | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e1d99f61..5e6f53ba 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -142,6 +142,7 @@ fn main() { github::release_notes::get_newest_flightcore_version, mod_management::delete_northstar_mod, util::get_server_player_count, + util::kill_northstar, mod_management::delete_thunderstore_mod, install_northstar_proton_wrapper, uninstall_northstar_proton_wrapper, diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index 0f32ecb5..f1ba6b8a 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use serde::{Deserialize, Serialize}; -use sysinfo::SystemExt; +use sysinfo::{ProcessExt, SystemExt}; use zip::ZipArchive; use crate::constants::{APP_USER_AGENT, MASTER_SERVER_URL, SERVER_BROWSER_ENDPOINT}; @@ -64,6 +64,27 @@ pub async fn get_server_player_count() -> Result<(i32, usize), String> { Ok((total_player_count, server_count)) } +#[tauri::command] +pub async fn kill_northstar() -> Result<(), String> { + if !check_northstar_running() { + return Err("Northstar is not running".to_string()); + } + + let s = sysinfo::System::new_all(); + + for process in s.processes_by_exact_name("Titanfall2.exe") { + log::info!("Killing Process {}", process.pid()); + process.kill(); + } + + for process in s.processes_by_exact_name("NorthstarLauncher.exe") { + log::info!("Killing Process {}", process.pid()); + process.kill(); + } + + Ok(()) +} + /// Copied from `papa` source code and modified ///Extract N* zip file to target game path // fn extract(ctx: &Ctx, zip_file: File, target: &Path) -> Result<()> { diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index e95154f1..ef878496 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -74,6 +74,10 @@ Get installed mods + + Kill Northstar + +

Testing

@@ -220,6 +224,16 @@ export default defineComponent({ showErrorNotification(error); }); }, + async killNorthstar() { + await invoke("kill_northstar") + .then((message) => { + // Just a visual indicator that it worked + showNotification('Success'); + }) + .catch((error) => { + showErrorNotification(error); + }); + }, 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) => { -- cgit v1.2.3 From 3563a0bc4748b7c14cbff2240af401fab9d4dc5d Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 31 Jul 2023 12:13:17 +0200 Subject: refactor: Migrate install related functions to `GameInstall` (#457) This allows for later extending for installing in the appropriate profile --- src-tauri/src/main.rs | 8 ++++---- src-tauri/src/northstar/install.rs | 20 +++++++++----------- src-vue/src/plugins/store.ts | 4 ++-- src-vue/src/views/DeveloperView.vue | 2 +- src-vue/src/views/RepairView.vue | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5e6f53ba..9e812683 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -296,7 +296,7 @@ async fn verify_install_location(game_path: String) -> bool { #[tauri::command] async fn install_northstar_caller( window: tauri::Window, - game_path: String, + game_install: GameInstall, northstar_package_name: Option, version_number: Option, ) -> Result { @@ -315,7 +315,7 @@ async fn install_northstar_caller( match northstar::install::install_northstar( window, - &game_path, + game_install, northstar_package_name, version_number, ) @@ -333,13 +333,13 @@ async fn install_northstar_caller( #[tauri::command] async fn update_northstar( window: tauri::Window, - game_path: String, + 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_caller(window, game_path, northstar_package_name, None).await + install_northstar_caller(window, game_install, northstar_package_name, None).await } /// Installs the specified mod diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 2d96b00e..002548c1 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -33,10 +33,13 @@ struct InstallProgress { async fn do_install( window: tauri::Window, nmod: &thermite::model::ModVersion, - game_path: &std::path::Path, + game_install: GameInstall, ) -> Result<()> { let filename = format!("northstar-{}.zip", nmod.version); - let download_directory = format!("{}/___flightcore-temp-download-dir/", game_path.display()); + let download_directory = format!( + "{}/___flightcore-temp-download-dir/", + game_install.game_path + ); log::info!( "Attempting to create temporary directory {}", @@ -91,7 +94,7 @@ async fn do_install( .unwrap(); log::info!("Extracting Northstar..."); - extract(nfile, game_path)?; + extract(nfile, std::path::Path::new(&game_install.game_path))?; // Delete old copy log::info!("Delete temp folder again"); @@ -114,7 +117,7 @@ async fn do_install( pub async fn install_northstar( window: tauri::Window, - game_path: &str, + game_install: GameInstall, northstar_package_name: String, version_number: Option, ) -> Result { @@ -134,15 +137,10 @@ pub async fn install_northstar( // Use passed version or latest if no version was passed let version = version_number.as_ref().unwrap_or(&nmod.latest); + let game_path = game_install.game_path.clone(); log::info!("Install path \"{}\"", game_path); - match do_install( - window, - nmod.versions.get(version).unwrap(), - std::path::Path::new(game_path), - ) - .await - { + match do_install(window, nmod.versions.get(version).unwrap(), game_install).await { Ok(_) => (), Err(err) => { if game_path diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index aee8bbce..9865b992 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -179,7 +179,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", { gamePath: state.game_install.game_path, northstarPackageName: state.northstar_release_canal }); + let install_northstar_result = invoke("install_northstar_caller", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal }); state.northstar_state = NorthstarState.INSTALLING; await install_northstar_result.then((message) => { @@ -196,7 +196,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", { gamePath: state.game_install.game_path, northstarPackageName: state.northstar_release_canal }); + let reinstall_northstar_result = invoke("install_northstar_caller", { 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 ef878496..f60d47b1 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -303,7 +303,7 @@ export default defineComponent({ 0 ); - let install_northstar_result = invoke("install_northstar_caller", { gamePath: this.$store.state.game_install.game_path, northstarPackageName: this.selected_ns_version.value.package, versionNumber: this.selected_ns_version.value.version }); + 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 }); await install_northstar_result .then((message) => { diff --git a/src-vue/src/views/RepairView.vue b/src-vue/src/views/RepairView.vue index 614c1e56..65c533d2 100644 --- a/src-vue/src/views/RepairView.vue +++ b/src-vue/src/views/RepairView.vue @@ -71,7 +71,7 @@ export default defineComponent({ 0 ); - let install_northstar_result = invoke("install_northstar_caller", { gamePath: this.$store.state.game_install.game_path, northstarPackageName: ReleaseCanal.RELEASE }); + let install_northstar_result = invoke("install_northstar_caller", { gameInstall: this.$store.state.game_install, northstarPackageName: ReleaseCanal.RELEASE }); appWindow.listen( 'northstar-install-download-progress', -- cgit v1.2.3 From fae4de2fba580e4a1a92b853c479b61e856a3a42 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 1 Aug 2023 12:28:20 +0200 Subject: refactor Generalise temporary directory structure (#458) The temp folder we create could be reused for a lot more things, like extracting Northstar before moving files into the correct place. As such adjust the naming and structure to accommodate this. --- src-tauri/src/development/mod.rs | 2 +- src-tauri/src/github/pull_requests.rs | 2 +- src-tauri/src/mod_management/mod.rs | 4 ++-- src-tauri/src/northstar/install.rs | 2 +- src-tauri/src/repair_and_verify/mod.rs | 34 +++++++++++++++++++--------------- 5 files changed, 24 insertions(+), 20 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/development/mod.rs b/src-tauri/src/development/mod.rs index be02966d..7184904c 100644 --- a/src-tauri/src/development/mod.rs +++ b/src-tauri/src/development/mod.rs @@ -25,7 +25,7 @@ pub async fn install_git_main(game_install_path: &str) -> Result }; let extract_directory = format!( - "{}/___flightcore-temp-download-dir/launcher-pr-{}", + "{}/___flightcore-temp/download-dir/launcher-pr-{}", game_install_path, latest_commit_sha ); match std::fs::create_dir_all(extract_directory.clone()) { diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index 44b41638..c3079cfd 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -253,7 +253,7 @@ pub async fn apply_launcher_pr( }; let extract_directory = format!( - "{}/___flightcore-temp-download-dir/launcher-pr-{}", + "{}/___flightcore-temp/download-dir/launcher-pr-{}", game_install_path, pull_request.number ); match std::fs::create_dir_all(extract_directory.clone()) { diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index a5f928bd..ff3a09ed 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -537,7 +537,7 @@ pub async fn fc_download_mod_and_install( log::info!("Attempting to install \"{thunderstore_mod_string}\" to {game_install:?}"); // Get mods and download directories let download_directory = format!( - "{}/___flightcore-temp-download-dir/", + "{}/___flightcore-temp/download-dir/", game_install.game_path ); @@ -584,7 +584,7 @@ pub async fn fc_download_mod_and_install( }; let path = format!( - "{}/___flightcore-temp-download-dir/{thunderstore_mod_string}.zip", + "{}/___flightcore-temp/download-dir/{thunderstore_mod_string}.zip", game_install.game_path ); diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 002548c1..eef6c148 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -37,7 +37,7 @@ async fn do_install( ) -> Result<()> { let filename = format!("northstar-{}.zip", nmod.version); let download_directory = format!( - "{}/___flightcore-temp-download-dir/", + "{}/___flightcore-temp/download-dir/", game_install.game_path ); diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 17c71992..29cc9613 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -40,26 +40,30 @@ pub fn clean_up_download_folder( game_install: &GameInstall, force: bool, ) -> Result<(), anyhow::Error> { - // Get download directory - let download_directory = format!( - "{}/___flightcore-temp-download-dir/", - game_install.game_path - ); + const TEMPORARY_DIRECTORIES: [&str; 3] = [ + "___flightcore-temp-download-dir", + "___flightcore-temp/download-dir", + "___flightcore-temp", + ]; - // Check if files in folder - let download_dir_contents = std::fs::read_dir(download_directory.clone())?; - // dbg!(download_dir_contents); + for directory in TEMPORARY_DIRECTORIES { + // Get download directory + let download_directory = format!("{}/{}/", game_install.game_path, directory); - let mut count = 0; - download_dir_contents.for_each(|_| count += 1); + // Check if files in folder + let download_dir_contents = std::fs::read_dir(download_directory.clone())?; + // dbg!(download_dir_contents); - if count > 0 && !force { - return Err(anyhow!("Folder not empty, not deleting")); - } + let mut count = 0; + download_dir_contents.for_each(|_| count += 1); - // Delete folder - std::fs::remove_dir_all(download_directory)?; + if count > 0 && !force { + return Err(anyhow!("Folder not empty, not deleting")); + } + // Delete folder + std::fs::remove_dir_all(download_directory)?; + } Ok(()) } -- cgit v1.2.3 From 08d066c7c6c7b99076efb5217474cc5b72df015f Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 2 Aug 2023 12:24:57 +0200 Subject: Extract Northstar into temporary location before installing (#456) This is done in order to enable future changes --- src-tauri/src/northstar/install.rs | 44 +++++++++++++++++++++++++++----------- src-tauri/src/util.rs | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 13 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index eef6c148..80425c56 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -5,7 +5,10 @@ use std::{cell::RefCell, time::Instant}; use ts_rs::TS; use crate::constants::TITANFALL2_STEAM_ID; -use crate::{util::extract, GameInstall, InstallType}; +use crate::{ + util::{extract, move_dir_all}, + GameInstall, InstallType, +}; #[cfg(target_os = "windows")] use crate::platform_specific::windows; @@ -36,16 +39,13 @@ async fn do_install( game_install: GameInstall, ) -> Result<()> { let filename = format!("northstar-{}.zip", nmod.version); - let download_directory = format!( - "{}/___flightcore-temp/download-dir/", - game_install.game_path - ); - - log::info!( - "Attempting to create temporary directory {}", - download_directory - ); + let temp_dir = format!("{}/___flightcore-temp", game_install.game_path); + let download_directory = format!("{}/download-dir", temp_dir); + let extract_directory = format!("{}/extract-dir", temp_dir); + + log::info!("Attempting to create temporary directory {}", temp_dir); std::fs::create_dir_all(download_directory.clone())?; + std::fs::create_dir_all(extract_directory.clone())?; let download_path = format!("{}/{}", download_directory, filename); log::info!("Download path: {download_path}"); @@ -94,11 +94,29 @@ async fn do_install( .unwrap(); log::info!("Extracting Northstar..."); - extract(nfile, std::path::Path::new(&game_install.game_path))?; + extract(nfile, std::path::Path::new(&extract_directory))?; + + log::info!("Installing Northstar..."); + + for entry in std::fs::read_dir(extract_directory).unwrap() { + let entry = entry.unwrap(); + let destination = format!( + "{}/{}", + game_install.game_path, + entry.path().file_name().unwrap().to_str().unwrap() + ); + + log::info!("Installing {}", entry.path().display()); + if !entry.file_type().unwrap().is_dir() { + std::fs::rename(entry.path(), destination)?; + } else { + move_dir_all(entry.path(), destination)?; + } + } // Delete old copy - log::info!("Delete temp folder again"); - std::fs::remove_dir_all(download_directory).unwrap(); + log::info!("Delete temporary directory"); + std::fs::remove_dir_all(temp_dir).unwrap(); log::info!("Done installing Northstar!"); window diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index f1ba6b8a..b21b2208 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -143,3 +143,42 @@ pub fn check_northstar_running() -> bool { || s.processes_by_name("Titanfall2.exe").next().is_some(); x } + +/// Copies a folder and all its contents to a new location +#[allow(dead_code)] +pub fn copy_dir_all( + src: impl AsRef, + dst: impl AsRef, +) -> std::io::Result<()> { + std::fs::create_dir_all(&dst)?; + for entry in std::fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; + } else { + std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + Ok(()) +} + +/// Moves a folders file structure to a new location +/// Old folders are not removed +pub fn move_dir_all( + src: impl AsRef, + dst: impl AsRef, +) -> std::io::Result<()> { + std::fs::create_dir_all(&dst)?; + for entry in std::fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + move_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; + std::fs::remove_dir(entry.path())?; + } else { + std::fs::rename(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + Ok(()) +} -- cgit v1.2.3