aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/mod_management/mod.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-01-04 23:42:05 +0100
committerGitHub <noreply@github.com>2023-01-04 23:42:05 +0100
commit4951a7e9048b6538a72294184639f6590f78384e (patch)
tree4490516fabc1c6097fcd23d9e5fa7f35f0966d0f /src-tauri/src/mod_management/mod.rs
parent4a63e92ea30fc65cf945b163d2757f17dd3c68cd (diff)
downloadFlightCore-4951a7e9048b6538a72294184639f6590f78384e.tar.gz
FlightCore-4951a7e9048b6538a72294184639f6590f78384e.zip
feat: Add button to delete Northstar mod (#110)
* feat: Expose installed NS mod directory This allows other functions to get a mod directory directly which is useful for e.g. deleting a mod. * feat: Add button to delete Northstar mod * refactor: Return vector of NorthstarMod instead of unnamed Tuples * refactor: Remove leftover print statement * chore: Remove leftover todo comment * feat: Show confirm warning before deleting mod * refactor: Call func directly instead of proxy Removes the `func_caller` pattern * fix: Call reloading mods after attempted delete
Diffstat (limited to 'src-tauri/src/mod_management/mod.rs')
-rw-r--r--src-tauri/src/mod_management/mod.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index 4fe1b517..f6897b90 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -10,6 +10,8 @@ use app::GameInstall;
use json5;
+use crate::northstar::CORE_MODS;
+
pub const BLACKLISTED_MODS: [&str; 3] = [
"northstar-Northstar",
"northstar-NorthstarReleaseCandidate",
@@ -385,3 +387,46 @@ pub async fn fc_download_mod_and_install(
Ok(())
}
+
+/// Deletes a given Northstar mod folder
+fn delete_mod_folder(ns_mod_directory: String) -> Result<(), String> {
+ let ns_mod_dir_path = std::path::Path::new(&ns_mod_directory);
+
+ // Safety check: Check whether `mod.json` exists and exit early if not
+ // If it does not exist, we might not be dealing with a Northstar mod
+ let mod_json_path = ns_mod_dir_path.join("mod.json");
+ if !mod_json_path.exists() {
+ // If it doesn't exist, return an error
+ return Err(format!("mod.json does not exist in {}", ns_mod_directory));
+ }
+
+ match std::fs::remove_dir_all(&ns_mod_directory) {
+ Ok(()) => Ok(()),
+ Err(err) => Err(format!("Failed deleting mod: {err}")),
+ }
+}
+
+/// Deletes a Northstar mod based on its name
+#[tauri::command]
+pub fn delete_northstar_mod(game_install: GameInstall, nsmod_name: String) -> Result<(), String> {
+ // Prevent deleting core mod
+ for core_mod in CORE_MODS {
+ if nsmod_name == core_mod {
+ return Err(format!("Cannot remove core mod {nsmod_name}"));
+ }
+ }
+
+ // Get installed mods
+ let installed_ns_mods = get_installed_mods_and_properties(game_install)?;
+
+ // Get folder name based on northstarmods
+ for installed_ns_mod in installed_ns_mods {
+ // Installed mod matches specified mod
+ if installed_ns_mod.name == nsmod_name {
+ // Delete folder
+ return delete_mod_folder(installed_ns_mod.directory);
+ }
+ }
+
+ Err(format!("Mod {nsmod_name} not found to be installed"))
+}