aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/mod_management
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-11-07 20:24:14 +0100
committerGitHub <noreply@github.com>2022-11-07 20:24:14 +0100
commit1ae49de2b49a0be84b4a842e5a6a2938bcf1889c (patch)
tree0db6e19409c52f885ccf0eb9269cbf92fa7c6037 /src-tauri/src/mod_management
parent1674b0b354faccf9160c904f049182d67253497f (diff)
downloadFlightCore-1ae49de2b49a0be84b4a842e5a6a2938bcf1889c.tar.gz
FlightCore-1ae49de2b49a0be84b4a842e5a6a2938bcf1889c.zip
refactor: Move functions to dedicated file (#41)
Only a single function for now as a sort of proof-of-concept.
Diffstat (limited to 'src-tauri/src/mod_management')
-rw-r--r--src-tauri/src/mod_management/mod.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
new file mode 100644
index 00000000..dfc05c4a
--- /dev/null
+++ b/src-tauri/src/mod_management/mod.rs
@@ -0,0 +1,33 @@
+// This file contains various mod management functions
+
+use app::GameInstall;
+use app::get_enabled_mods;
+
+/// Set the status of a passed mod to enabled/disabled
+pub fn set_mod_enabled_status(
+ game_install: GameInstall,
+ mod_name: String,
+ is_enabled: bool,
+) -> Result<(), String> {
+ let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path);
+
+ // Parse JSON
+ let mut res: serde_json::Value = get_enabled_mods(game_install)?;
+
+ // Check if key exists
+ if res.get(mod_name.clone()).is_none() {
+ return Err("Value not found in enabledmod.json".to_string());
+ }
+
+ // Update value
+ res[mod_name] = serde_json::Value::Bool(is_enabled);
+
+ // Save the JSON structure into the output file
+ std::fs::write(
+ enabledmods_json_path,
+ serde_json::to_string_pretty(&res).unwrap(),
+ )
+ .unwrap();
+
+ Ok(())
+}