aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/mod_management
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-18 16:12:23 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-18 16:12:23 +0200
commit7df3de912e50d174a8ea33a0e8c3bf397cd85a0a (patch)
treebe0dff914d290c6486b9b7fb7e178a02f5feb063 /src-tauri/src/mod_management
parent0cd98b60d77fedb5755ccb8cb827a37d4360c9dd (diff)
parent0fc68de30150746721be31728e84f86434086bc7 (diff)
downloadFlightCore-7df3de912e50d174a8ea33a0e8c3bf397cd85a0a.tar.gz
FlightCore-7df3de912e50d174a8ea33a0e8c3bf397cd85a0a.zip
Merge remote-tracking branch 'origin/feat/delete-package' into dev/packages
Diffstat (limited to 'src-tauri/src/mod_management')
-rw-r--r--src-tauri/src/mod_management/mod.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index 2ac26ede..d0ce3476 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -548,11 +548,63 @@ pub fn delete_northstar_mod(game_install: GameInstall, nsmod_name: String) -> Re
Err(format!("Mod {nsmod_name} not found to be installed"))
}
+/// Deletes a given Thunderstore package
+fn delete_package_folder(ts_package_directory: &str) -> Result<(), String> {
+ let ns_mod_dir_path = std::path::Path::new(&ts_package_directory);
+
+ // Safety check: Check whether `manifest.json` exists and exit early if not
+ // If it does not exist, we might not be dealing with a Thunderstore package
+ let mod_json_path = ns_mod_dir_path.join("manifest.json");
+ if !mod_json_path.exists() {
+ // If it doesn't exist, return an error
+ return Err(format!(
+ "manifest.json does not exist in {}",
+ ts_package_directory
+ ));
+ }
+
+ match std::fs::remove_dir_all(ts_package_directory) {
+ Ok(()) => Ok(()),
+ Err(err) => Err(format!("Failed deleting package: {err}")),
+ }
+}
+
/// Deletes all NorthstarMods related to a Thunderstore mod
#[tauri::command]
pub fn delete_thunderstore_mod(
game_install: GameInstall,
thunderstore_mod_string: String,
) -> Result<(), String> {
+ // Check packages
+ let packages_folder = format!("{}/R2Northstar/packages", game_install.game_path);
+ if std::path::Path::new(&packages_folder).exists() {
+ println!(
+ "Directory {} exists. Listing subdirectories...",
+ packages_folder
+ );
+ for entry in fs::read_dir(packages_folder).unwrap() {
+ let entry = entry.unwrap();
+
+ // Check if it's a folder and skip if otherwise
+ if !entry.file_type().unwrap().is_dir() {
+ log::warn!("Skipping \"{}\", not a file", entry.path().display());
+ continue;
+ }
+
+ let entry_path = entry.path();
+ let package_folder_ts_string = entry_path.file_name().unwrap().to_string_lossy();
+ dbg!(package_folder_ts_string.clone());
+
+ if package_folder_ts_string != thunderstore_mod_string {
+ // Not the mod folder we are looking for, try the next one\
+ continue;
+ }
+
+ // All checks passed, this is the matching mod
+ return delete_package_folder(&entry.path().display().to_string());
+ }
+ }
+
+ // Try legacy mod installs as fallback
legacy::delete_thunderstore_mod(game_install, thunderstore_mod_string)
}