diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2022-10-21 13:48:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 13:48:10 +0200 |
commit | 7595b5f25a200a6a0f9f8742f11cc326dc1bd498 (patch) | |
tree | e970600b27eab0aa1fd23f6d53a8eb3caae2973a /src-tauri | |
parent | 5cc82fb80f5f91ed9d4a32a71e090a9a805ff2a9 (diff) | |
download | FlightCore-7595b5f25a200a6a0f9f8742f11cc326dc1bd498.tar.gz FlightCore-7595b5f25a200a6a0f9f8742f11cc326dc1bd498.zip |
feat: Add initial skeleton for ModsView (#27)
* feat: Backend code to get list of installed mods
For now simply parses `enabledmods.json`.
Note that this file will not be up-to-date if the user just installed a
mod but hasn't launched Northstar yet.
* feat: Empty skeleton page for ModsView
Will be populated later with list of installed mods
* chore: Remove leftover print statement
Diffstat (limited to 'src-tauri')
-rw-r--r-- | src-tauri/src/lib.rs | 39 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 12 |
2 files changed, 48 insertions, 3 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8a97a108..84920727 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -26,6 +26,12 @@ pub struct GameInstall { pub install_type: InstallType, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct NorthstarMod { + pub name: String, + pub enabled: bool, +} + /// Check version number of a mod pub fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, anyhow::Error> { // println!("{}", format!("{}/mod.json", path_to_mod_folder)); @@ -471,3 +477,36 @@ pub fn set_mod_enabled_status( Ok(()) } + +/// Gets list of installed mods and their properties +/// - name +/// - is enabled? +pub fn get_installed_mods(game_install: GameInstall) -> Result<Vec<NorthstarMod>, String> { + let enabled_mods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path); + // Open file + let data = match std::fs::read_to_string(enabled_mods_json_path) { + Ok(data) => data, + Err(err) => return Err(err.to_string()), + }; + // Check if valid JSON and parse + let res: serde_json::Value = match serde_json::from_str(&data) { + Ok(res) => res, + Err(err) => return Err(err.to_string()), + }; + + let mut installed_mods = Vec::new(); + + for (key, value) in res.as_object().unwrap() { + + let current_mod: NorthstarMod = NorthstarMod { + name: key.to_string(), + enabled: value.as_bool().unwrap(), + }; + installed_mods.push(current_mod); + } + + dbg!(&res); + dbg!(installed_mods.clone()); + + Ok(installed_mods) +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4826ef52..0cb329d2 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_enabled_mods, get_host_os, get_log_list, get_northstar_version_number, install_northstar, - launch_northstar, set_mod_enabled_status, GameInstall, linux_checks_librs + get_enabled_mods, get_host_os, get_installed_mods, get_log_list, get_northstar_version_number, + install_northstar, launch_northstar, linux_checks_librs, set_mod_enabled_status, GameInstall, NorthstarMod, }; mod repair_and_verify; @@ -88,7 +88,8 @@ fn main() { set_mod_enabled_status_caller, disable_all_but_core_caller, is_debug_mode, - linux_checks + linux_checks, + get_installed_mods_caller, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -297,3 +298,8 @@ fn set_mod_enabled_status_caller( fn disable_all_but_core_caller(game_install: GameInstall) -> Result<(), String> { disable_all_but_core(game_install) } + +#[tauri::command] +async fn get_installed_mods_caller(game_install: GameInstall) -> Result<Vec<NorthstarMod>, String> { + get_installed_mods(game_install) +} |