From a0f8e9e8861506e6b843977c489fb6ed5d2aaf7d Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Wed, 28 Sep 2022 15:48:11 +0200 Subject: Auto-format --- src-tauri/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 025b6863..7c54e630 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -20,8 +20,8 @@ mod repair_and_verify; use repair_and_verify::verify_game_files; use tauri::Manager; -use tokio::time::sleep; use tauri_plugin_store::PluginBuilder; +use tokio::time::sleep; #[derive(Default)] struct Counter(Arc>); @@ -254,5 +254,5 @@ fn get_log_list_caller(game_install: GameInstall) -> Result Result { - verify_game_files(game_install) + verify_game_files(game_install) } -- cgit v1.2.3 From 52e0ff843dbd3cb0616bc37cee11594b64363636 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Wed, 28 Sep 2022 16:41:06 +0200 Subject: Add backend logic to parse `enabledmods.json` --- src-tauri/src/lib.rs | 28 ++++++++++++++++++++++++++++ src-tauri/src/main.rs | 12 +++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d0bc9be2..688d33f6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -387,3 +387,31 @@ pub fn get_log_list(game_install: GameInstall) -> Result Err("No logs found".to_string()) } } + +/// Returns a serde json object of the parsed `enabledmods.json` file +pub fn get_enabled_mods(game_install: GameInstall) -> Result { + let enabledmods_json_path = format!( + "{}/R2Northstar/mods/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.to_string())), + }; + + // Return parsed data + Ok(res) +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7c54e630..f75f78c7 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -12,8 +12,8 @@ use std::{ 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_host_os, get_log_list, get_northstar_version_number, install_northstar, launch_northstar, - GameInstall, + get_enabled_mods, get_host_os, get_log_list, get_northstar_version_number, install_northstar, + launch_northstar, GameInstall, }; mod repair_and_verify; @@ -83,7 +83,8 @@ fn main() { launch_northstar_caller, check_is_flightcore_outdated_caller, get_log_list_caller, - verify_game_files_caller + verify_game_files_caller, + get_enabled_mods_caller ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -256,3 +257,8 @@ fn get_log_list_caller(game_install: GameInstall) -> Result Result { verify_game_files(game_install) } + +#[tauri::command] +fn get_enabled_mods_caller(game_install: GameInstall) -> Result { + get_enabled_mods(game_install) +} -- cgit v1.2.3 From 4e53e84c9dab6da2289d1a82009ed06a8a4c697b Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Wed, 28 Sep 2022 23:44:20 +0200 Subject: Fix path checked for enabledmods.json --- src-tauri/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-tauri') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 688d33f6..fd01f0a4 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -391,7 +391,7 @@ pub fn get_log_list(game_install: GameInstall) -> Result /// Returns a serde json object of the parsed `enabledmods.json` file pub fn get_enabled_mods(game_install: GameInstall) -> Result { let enabledmods_json_path = format!( - "{}/R2Northstar/mods/enabledmods.json", + "{}/R2Northstar/enabledmods.json", game_install.game_path ); -- cgit v1.2.3 From 93cec9e9cf8d1f67c38e4194b6c912aff06a3f22 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Thu, 29 Sep 2022 00:32:23 +0200 Subject: Add ability to enable/disable mods --- src-tauri/src/lib.rs | 29 +++++++++++++++++++++++++++++ src-tauri/src/main.rs | 14 ++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'src-tauri') 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 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/main.rs b/src-tauri/src/main.rs index f75f78c7..4089d72b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -13,7 +13,7 @@ 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_log_list, get_northstar_version_number, install_northstar, - launch_northstar, GameInstall, + launch_northstar, set_mod_enabled_status, GameInstall, }; mod repair_and_verify; @@ -84,7 +84,8 @@ fn main() { check_is_flightcore_outdated_caller, get_log_list_caller, verify_game_files_caller, - get_enabled_mods_caller + get_enabled_mods_caller, + set_mod_enabled_status_caller ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -262,3 +263,12 @@ fn verify_game_files_caller(game_install: GameInstall) -> Result fn get_enabled_mods_caller(game_install: GameInstall) -> Result { get_enabled_mods(game_install) } + +#[tauri::command] +fn set_mod_enabled_status_caller( + game_install: GameInstall, + mod_name: String, + is_enabled: bool, +) -> Result<(), String> { + set_mod_enabled_status(game_install, mod_name, is_enabled) +} -- cgit v1.2.3 From 7f0ee9be80988f13f1d234136725a03db0335ec5 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Thu, 29 Sep 2022 01:15:42 +0200 Subject: Add backend function to disable all mods but core Should help with fixing a Northstar install in the case of conflicting mods. --- src-tauri/src/main.rs | 10 ++++++++-- src-tauri/src/repair_and_verify/mod.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4089d72b..a2866cb4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -17,7 +17,7 @@ use app::{ }; mod repair_and_verify; -use repair_and_verify::verify_game_files; +use repair_and_verify::{verify_game_files, disable_all_but_core}; use tauri::Manager; use tauri_plugin_store::PluginBuilder; @@ -85,7 +85,8 @@ fn main() { get_log_list_caller, verify_game_files_caller, get_enabled_mods_caller, - set_mod_enabled_status_caller + set_mod_enabled_status_caller, + disable_all_but_core_caller ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -272,3 +273,8 @@ fn set_mod_enabled_status_caller( ) -> Result<(), String> { set_mod_enabled_status(game_install, mod_name, is_enabled) } + +#[tauri::command] +fn disable_all_but_core_caller(game_install: GameInstall) -> Result<(), String> { + disable_all_but_core(game_install) +} diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index e99dcbfc..39df916c 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -1,9 +1,35 @@ /// Contains various functions to repair common issues and verifying installation -use app::GameInstall; +use app::{get_enabled_mods, set_mod_enabled_status, GameInstall}; /// Verifies Titanfall2 game files pub fn verify_game_files(game_install: GameInstall) -> Result { dbg!(game_install); Err("TODO, not yet implemented".to_string()) } + +/// Disables all mods except core ones +/// Enables core mods if disabled +pub fn disable_all_but_core(game_install: GameInstall) -> Result<(), String> { + let current_mods = get_enabled_mods(game_install.clone())?; + + // These are the mods we do not want to disable + let core_mods = [ + "Northstar.Client", + "Northstar.Custom", + "Northstar.CustomServers", + ]; + // let sub_values: Vec> = serde_json::from_str(&json)?; + + for (key, _value) in current_mods.as_object().unwrap() { + if core_mods.contains(&key.as_str()) { + // This is a core mod + set_mod_enabled_status(game_install.clone(), key.to_string(), true)?; + } else { + // Not a core mod + set_mod_enabled_status(game_install.clone(), key.to_string(), false)?; + } + } + + Ok(()) +} -- cgit v1.2.3