aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/lib.rs
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-29 00:32:23 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-29 00:32:23 +0200
commit93cec9e9cf8d1f67c38e4194b6c912aff06a3f22 (patch)
treec2f93a9904548d9ef1352830d28cef5dc7c8f64e /src-tauri/src/lib.rs
parent4e53e84c9dab6da2289d1a82009ed06a8a4c697b (diff)
downloadFlightCore-93cec9e9cf8d1f67c38e4194b6c912aff06a3f22.tar.gz
FlightCore-93cec9e9cf8d1f67c38e4194b6c912aff06a3f22.zip
Add ability to enable/disable mods
Diffstat (limited to 'src-tauri/src/lib.rs')
-rw-r--r--src-tauri/src/lib.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index fd01f0a4..d3086e2f 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -415,3 +415,32 @@ pub fn get_enabled_mods(game_install: GameInstall) -> Result<serde_json::value::
// Return parsed data
Ok(res)
}
+
+/// 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(())
+}