From 0829ae900a3c7917fcedb05ab386d7a2a8722faf Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Thu, 28 Dec 2023 02:13:07 +0100 Subject: 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 --- src-tauri/src/northstar/install.rs | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'src-tauri') 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!( -- cgit v1.2.3