From baa4d8b07b4cad0f56ad9719aaefc7ee8a615ff4 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Mon, 12 Dec 2022 20:39:47 +0100 Subject: feat: Expose installed NS mod directory (#109) * feat: Expose installed NS mod directory This allows other functions to get a mod directory directly which is useful for e.g. deleting a mod. * refactor: Return vector of NorthstarMod instead of unnamed Tuples --- src-tauri/src/lib.rs | 1 + src-tauri/src/mod_management/mod.rs | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ba89cc0a..675a06ef 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -35,6 +35,7 @@ pub struct NorthstarMod { pub name: String, pub thunderstore_mod_string: Option, pub enabled: bool, + pub directory: String, } /// Check version number of a mod diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index b17e98a6..4fa52127 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -126,15 +126,13 @@ fn parse_mod_json_for_thunderstore_mod_string( } /// Parse `mods` folder for installed mods. -fn parse_installed_mods( - game_install: GameInstall, -) -> Result)>, String> { +fn parse_installed_mods(game_install: GameInstall) -> Result, String> { let ns_mods_folder = format!("{}/R2Northstar/mods/", game_install.game_path); let paths = std::fs::read_dir(ns_mods_folder).unwrap(); let mut directories: Vec = Vec::new(); - let mut mods: Vec<(String, Option)> = Vec::new(); + let mut mods: Vec = Vec::new(); // Get list of folders in `mods` directory for path in paths { @@ -167,8 +165,17 @@ fn parse_installed_mods( Ok(thunderstore_mod_string) => Some(thunderstore_mod_string), Err(_err) => None, }; + // Get directory path + let mod_directory = directory.to_str().unwrap().to_string(); + + let ns_mod = NorthstarMod { + name: mod_name, + thunderstore_mod_string: thunderstore_mod_string, + enabled: false, // Placeholder + directory: mod_directory, + }; - mods.push((mod_name, thunderstore_mod_string)); + mods.push(ns_mod); } // Return found mod names @@ -194,16 +201,12 @@ pub fn get_installed_mods_and_properties( let mapping = enabled_mods.as_object().unwrap(); // Use list of installed mods and set enabled based on `enabledmods.json` - for (name, thunderstore_mod_string) in found_installed_mods { - let current_mod_enabled = match mapping.get(&name) { + for mut current_mod in found_installed_mods { + let current_mod_enabled = match mapping.get(¤t_mod.name) { Some(enabled) => enabled.as_bool().unwrap(), None => true, // Northstar considers mods not in mapping as enabled. }; - let current_mod: NorthstarMod = NorthstarMod { - name: name, - thunderstore_mod_string: thunderstore_mod_string, - enabled: current_mod_enabled, - }; + current_mod.enabled = current_mod_enabled; installed_mods.push(current_mod); } -- cgit v1.2.3