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