From 1ae49de2b49a0be84b4a842e5a6a2938bcf1889c Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Mon, 7 Nov 2022 20:24:14 +0100 Subject: refactor: Move functions to dedicated file (#41) Only a single function for now as a sort of proof-of-concept. --- src-tauri/src/lib.rs | 29 ----------------------------- src-tauri/src/main.rs | 5 ++++- src-tauri/src/mod_management/mod.rs | 33 +++++++++++++++++++++++++++++++++ src-tauri/src/repair_and_verify/mod.rs | 3 ++- 4 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 src-tauri/src/mod_management/mod.rs diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 53230f38..e4f67108 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -449,35 +449,6 @@ pub fn get_enabled_mods(game_install: GameInstall) -> Result 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(()) -} - /// Gets list of installed mods and their properties /// - name /// - is enabled? diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e0f6f8ed..c3172ee8 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -13,12 +13,15 @@ use app::{ check_is_flightcore_outdated, check_is_valid_game_path, check_northstar_running, check_origin_running, convert_release_candidate_number, find_game_install_location, get_enabled_mods, get_host_os, get_installed_mods_and_properties, get_log_list, get_northstar_version_number, - install_northstar, launch_northstar, linux_checks_librs, set_mod_enabled_status, GameInstall, NorthstarMod, + install_northstar, launch_northstar, linux_checks_librs, GameInstall, NorthstarMod, }; mod repair_and_verify; use repair_and_verify::{verify_game_files, disable_all_but_core}; +mod mod_management; +use mod_management::set_mod_enabled_status; + use tauri::Manager; use tauri_plugin_store::PluginBuilder; use tokio::time::sleep; 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(()) +} diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 39df916c..8f8fe633 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -1,6 +1,7 @@ /// Contains various functions to repair common issues and verifying installation -use app::{get_enabled_mods, set_mod_enabled_status, GameInstall}; +use app::{get_enabled_mods, GameInstall}; +use crate::mod_management::set_mod_enabled_status; /// Verifies Titanfall2 game files pub fn verify_game_files(game_install: GameInstall) -> Result { -- cgit v1.2.3