diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2022-12-12 20:39:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-12 20:39:47 +0100 |
commit | baa4d8b07b4cad0f56ad9719aaefc7ee8a615ff4 (patch) | |
tree | 0fb2a90f392aba9a9d5e9bdca0044df3914753db /src-tauri | |
parent | e768d9ffab874d5991336464c80eb3b9e5a28b0c (diff) | |
download | FlightCore-baa4d8b07b4cad0f56ad9719aaefc7ee8a615ff4.tar.gz FlightCore-baa4d8b07b4cad0f56ad9719aaefc7ee8a615ff4.zip |
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
Diffstat (limited to 'src-tauri')
-rw-r--r-- | src-tauri/src/lib.rs | 1 | ||||
-rw-r--r-- | src-tauri/src/mod_management/mod.rs | 27 |
2 files changed, 16 insertions, 12 deletions
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<String>, 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<Vec<(String, Option<String>)>, String> { +fn parse_installed_mods(game_install: GameInstall) -> Result<Vec<NorthstarMod>, 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<PathBuf> = Vec::new(); - let mut mods: Vec<(String, Option<String>)> = Vec::new(); + let mut mods: Vec<NorthstarMod> = 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); } |