Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delete previous core mod files #659

Merged
merged 5 commits into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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