diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-05-10 14:11:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-10 14:11:20 +0200 |
commit | 176301371a9f22d298b54c9b785f42a1c5badb56 (patch) | |
tree | 2a491ac9720ae15bca185e7046b3d2c8e0fa748d | |
parent | 5610dcf2d591d2b7da16b2765507fd29eb8e7643 (diff) | |
download | FlightCore-176301371a9f22d298b54c9b785f42a1c5badb56.tar.gz FlightCore-176301371a9f22d298b54c9b785f42a1c5badb56.zip |
refactor: Move `get_enabled_mods` to different source file (#311)
Move `get_enabled_mods` into the mod management module.
-rw-r--r-- | src-tauri/src/main.rs | 25 | ||||
-rw-r--r-- | src-tauri/src/mod_management/mod.rs | 26 | ||||
-rw-r--r-- | src-tauri/src/repair_and_verify/mod.rs | 3 |
3 files changed, 26 insertions, 28 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 95914898..9f268956 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -534,28 +534,3 @@ async fn get_available_northstar_versions() -> Result<Vec<NorthstarThunderstoreR Ok(releases) } - -/// Returns a serde json object of the parsed `enabledmods.json` file -pub fn get_enabled_mods(game_install: &GameInstall) -> Result<serde_json::value::Value, String> { - let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path); - - // Check for JSON file - if !std::path::Path::new(&enabledmods_json_path).exists() { - return Err("enabledmods.json not found".to_string()); - } - - // Read file - let data = match std::fs::read_to_string(enabledmods_json_path) { - Ok(data) => data, - Err(err) => return Err(err.to_string()), - }; - - // Parse JSON - let res: serde_json::Value = match serde_json::from_str(&data) { - Ok(result) => result, - Err(err) => return Err(format!("Failed to read JSON due to: {}", err)), - }; - - // Return parsed data - Ok(res) -} diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index 08b1e965..1c648ca4 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -8,7 +8,6 @@ use app::NorthstarMod; use serde::{Deserialize, Serialize}; use std::{fs, io::Read, path::PathBuf}; -use crate::get_enabled_mods; use app::GameInstall; #[derive(Debug, Clone)] @@ -83,6 +82,31 @@ impl std::ops::Deref for TempFile { } } +/// Returns a serde json object of the parsed `enabledmods.json` file +pub fn get_enabled_mods(game_install: &GameInstall) -> Result<serde_json::value::Value, String> { + let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path); + + // Check for JSON file + if !std::path::Path::new(&enabledmods_json_path).exists() { + return Err("enabledmods.json not found".to_string()); + } + + // Read file + let data = match std::fs::read_to_string(enabledmods_json_path) { + Ok(data) => data, + Err(err) => return Err(err.to_string()), + }; + + // Parse JSON + let res: serde_json::Value = match serde_json::from_str(&data) { + Ok(result) => result, + Err(err) => return Err(format!("Failed to read JSON due to: {}", err)), + }; + + // Return parsed data + Ok(res) +} + /// Gets all currently installed and enabled/disabled mods to rebuild `enabledmods.json` pub fn rebuild_enabled_mods_json(game_install: &GameInstall) -> Result<(), String> { let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path); diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 09c59289..fd6c0e83 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -1,5 +1,4 @@ -use crate::get_enabled_mods; -use crate::mod_management::{rebuild_enabled_mods_json, set_mod_enabled_status}; +use crate::mod_management::{get_enabled_mods, rebuild_enabled_mods_json, set_mod_enabled_status}; use anyhow::anyhow; /// Contains various functions to repair common issues and verifying installation use app::{constants::CORE_MODS, GameInstall}; |