Skip to content

Commit

Permalink
feat: Delete previous core mod files (#659)
Browse files Browse the repository at this point in the history
* feat: Delete previous mod files

* feat: Print folder name that failed to get removed

* fix: Remove print visual guard

* fix: Remove unnecessary print
  • Loading branch information
GeckoEidechse authored Dec 28, 2023
1 parent e5998b7 commit 0829ae9
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src-tauri/src/northstar/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit 0829ae9

Please sign in to comment.