aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
diff options
context:
space:
mode:
authorRémy Raes <contact@remyraes.com>2022-10-02 22:52:39 +0200
committerGitHub <noreply@github.com>2022-10-02 22:52:39 +0200
commita4b14e2c0edbbae1d399009ad9d691e7c30d4571 (patch)
tree7585d1bc1e54319710881e2a310f6825f622d437 /src-tauri
parent96f83ec9406e330444e5f0ab135dc4c169c832ce (diff)
parent7f0ee9be80988f13f1d234136725a03db0335ec5 (diff)
downloadFlightCore-a4b14e2c0edbbae1d399009ad9d691e7c30d4571.tar.gz
FlightCore-a4b14e2c0edbbae1d399009ad9d691e7c30d4571.zip
Merge branch 'GeckoEidechse:main' into feat/new-ui
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/src/lib.rs57
-rw-r--r--src-tauri/src/main.rs34
-rw-r--r--src-tauri/src/repair_and_verify/mod.rs28
3 files changed, 112 insertions, 7 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index d0bc9be2..d3086e2f 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -387,3 +387,60 @@ pub fn get_log_list(game_install: GameInstall) -> Result<Vec<std::path::PathBuf>
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<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.to_string())),
+ };
+
+ // 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(())
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 025b6863..a2866cb4 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -12,16 +12,16 @@ 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, set_mod_enabled_status, GameInstall,
};
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 tokio::time::sleep;
use tauri_plugin_store::PluginBuilder;
+use tokio::time::sleep;
#[derive(Default)]
struct Counter(Arc<Mutex<i32>>);
@@ -83,7 +83,10 @@ 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,
+ set_mod_enabled_status_caller,
+ disable_all_but_core_caller
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
@@ -254,5 +257,24 @@ fn get_log_list_caller(game_install: GameInstall) -> Result<Vec<std::path::PathB
#[tauri::command]
fn verify_game_files_caller(game_install: GameInstall) -> Result<String, String> {
- verify_game_files(game_install)
+ verify_game_files(game_install)
+}
+
+#[tauri::command]
+fn get_enabled_mods_caller(game_install: GameInstall) -> Result<serde_json::value::Value, String> {
+ 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)
+}
+
+#[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<String, String> {
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<HashMap<String, Value>> = 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(())
+}