From 695858088486a1a9d5fe9a74f79f1cad95a20b14 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Wed, 19 Jul 2023 01:09:17 +0200 Subject: feat: Delete packages installed in legacy mode on upgrade --- src-tauri/src/mod_management/legacy.rs | 36 ++++++++++++++++++++++++++++++++++ src-tauri/src/mod_management/mod.rs | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/src-tauri/src/mod_management/legacy.rs b/src-tauri/src/mod_management/legacy.rs index 568aadfc..4e1d81ff 100644 --- a/src-tauri/src/mod_management/legacy.rs +++ b/src-tauri/src/mod_management/legacy.rs @@ -126,6 +126,42 @@ pub fn parse_installed_mods( Ok(mods) } +/// Deletes all legacy packages that match in author and mod name +/// regardless of version +pub fn delete_legacy_package_install( + thunderstore_mod_string: &str, + game_install: &GameInstall, +) -> Result<(), String> { + let thunderstore_mod_string: ParsedThunderstoreModString = + thunderstore_mod_string.parse().unwrap(); + let found_installed_legacy_mods = match parse_installed_mods(&game_install) { + Ok(res) => res, + Err(err) => return Err(err.to_string()), + }; + + for legacy_mod in found_installed_legacy_mods { + if legacy_mod.thunderstore_mod_string.is_none() { + continue; // Not a thunderstore mod + } + + let current_mod_ts_string: ParsedThunderstoreModString = legacy_mod + .clone() + .thunderstore_mod_string + .unwrap() + .parse() + .unwrap(); + + if thunderstore_mod_string.author_name == current_mod_ts_string.author_name + && thunderstore_mod_string.mod_name == current_mod_ts_string.mod_name + { + // They match, delete + delete_mod_folder(&legacy_mod.directory)?; + } + } + + Ok(()) +} + /// Deletes all NorthstarMods related to a Thunderstore mod pub fn delete_thunderstore_mod( game_install: GameInstall, diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index a1a8cdf0..e1939e08 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -556,6 +556,14 @@ pub async fn fc_download_mod_and_install( }; // Successful package install + match legacy::delete_legacy_package_install(thunderstore_mod_string, game_install) { + Ok(()) => (), + Err(err) => { + log::warn!("Failed deleting legacy versions due to: {}", err); + todo!(); // should we do something on error or ignore? + } + }; + match delete_older_versions(thunderstore_mod_string, game_install) { Ok(()) => (), Err(err) => { -- cgit v1.2.3