diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-12-28 02:13:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-28 02:13:07 +0100 |
commit | 0829ae900a3c7917fcedb05ab386d7a2a8722faf (patch) | |
tree | d3d6784e6062807775ee30c332643fe0cf9076eb /src-tauri/src/northstar | |
parent | e5998b70ee83a7af667c8494cb0496efa715e150 (diff) | |
download | FlightCore-0829ae900a3c7917fcedb05ab386d7a2a8722faf.tar.gz FlightCore-0829ae900a3c7917fcedb05ab386d7a2a8722faf.zip |
feat: Delete previous core mod files (#659)
* feat: Delete previous mod files
* feat: Print folder name that failed to get removed
* fix: Remove print visual guard
* fix: Remove unnecessary print
Diffstat (limited to 'src-tauri/src/northstar')
-rw-r--r-- | src-tauri/src/northstar/install.rs | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 693d7af2..a89de018 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -4,7 +4,7 @@ use std::time::Duration; use std::{cell::RefCell, time::Instant}; use ts_rs::TS; -use crate::constants::{NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL, TITANFALL2_STEAM_ID}; +use crate::constants::{CORE_MODS, NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL, TITANFALL2_STEAM_ID}; use crate::{ util::{extract, move_dir_all}, GameInstall, InstallType, @@ -162,6 +162,52 @@ async fn do_install( log::info!("Installing Northstar..."); + // Delete previous version here + for core_mod in CORE_MODS { + let path_to_delete_string = format!( + "{}/{}/mods/{}/", + game_install.game_path, game_install.profile, core_mod + ); + log::info!("Preparing to remove {}", path_to_delete_string); + + // Check if folder exists + let path_to_delete = std::path::Path::new(&path_to_delete_string); + + // Check if path even exists before we attempt to remove + if !path_to_delete.exists() { + log::info!("{} does not exist. Skipping", path_to_delete_string); + continue; + } + + if !path_to_delete.is_dir() { + log::error!( + "{} exists but is a file? This should never happen", + path_to_delete_string + ); + continue; + } + + // Safety check for mod.json + // Just so that we won't ever have a https://github.com/ValveSoftware/steam-for-linux/issues/3671 moment + let mod_json_path = format!("{}/mod.json", path_to_delete_string); + let mod_json_path = std::path::Path::new(&mod_json_path); + + if !mod_json_path.exists() { + log::error!("Missing mod.json for {path_to_delete_string} this shouldn't happen"); + continue; + } + + // Finally delete file + match std::fs::remove_dir_all(path_to_delete) { + Ok(()) => { + log::info!("Succesfully removed") + } + Err(err) => { + log::error!("Failed removing {} due to {}", path_to_delete_string, err) + } + }; + } + for entry in std::fs::read_dir(extract_directory).unwrap() { let entry = entry.unwrap(); let destination = format!( |