diff options
author | Jan <sentrycraft123@gmail.com> | 2023-08-08 23:59:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-08 23:59:05 +0200 |
commit | 24fb67f88ceca9bec04b49fae5b58759b7b25ec5 (patch) | |
tree | 3f30f87435b2877302bb90bd4ac1d82238230aa4 /src-tauri/src/northstar | |
parent | 023d2310ca33c5869f57bb4d68999662c6d887a9 (diff) | |
download | FlightCore-24fb67f88ceca9bec04b49fae5b58759b7b25ec5.tar.gz FlightCore-24fb67f88ceca9bec04b49fae5b58759b7b25ec5.zip |
feat: Add dropdown menu for profiles (#494)
Adds a dropdown menu to settings that allows selecting a different profile.
Currently gated behind dev mode being active.
Diffstat (limited to 'src-tauri/src/northstar')
-rw-r--r-- | src-tauri/src/northstar/mod.rs | 1 | ||||
-rw-r--r-- | src-tauri/src/northstar/profile.rs | 76 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index 173495c6..4fecfe51 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -1,6 +1,7 @@ //! This module deals with handling things around Northstar such as //! - getting version number pub mod install; +pub mod profile; use crate::util::check_ea_app_or_origin_running; use crate::{ diff --git a/src-tauri/src/northstar/profile.rs b/src-tauri/src/northstar/profile.rs new file mode 100644 index 00000000..78e734d0 --- /dev/null +++ b/src-tauri/src/northstar/profile.rs @@ -0,0 +1,76 @@ +use crate::GameInstall; + +// These folders are part of Titanfall 2 and +// should NEVER be used as a Profile +const SKIP_PATHS: [&str; 8] = [ + "___flightcore-temp", + "__overlay", + "bin", + "Core", + "r2", + "vpk", + "platform", + "Support", +]; + +// A profile may have one of these to be detected +const MAY_CONTAIN: [&str; 10] = [ + "mods/", + "plugins/", + "packages/", + "logs/", + "runtime/", + "save_data/", + "Northstar.dll", + "enabledmods.json", + "placeholder.playerdata.pdata", + "LEGAL.txt", +]; + +/// Returns a list of Profile names +/// All the returned Profiles can be found relative to the game path +#[tauri::command] +pub fn fetch_profiles(game_install: GameInstall) -> Result<Vec<String>, String> { + let mut profiles: Vec<String> = Vec::new(); + + for content in MAY_CONTAIN { + let pattern = format!("{}/*/{}", game_install.game_path, content); + for e in glob::glob(&pattern).expect("Failed to read glob pattern") { + let path = e.unwrap(); + let mut ancestors = path.ancestors(); + + ancestors.next(); + + let profile_path = std::path::Path::new(ancestors.next().unwrap()); + let profile_name = profile_path + .file_name() + .unwrap() + .to_os_string() + .into_string() + .unwrap(); + + if !profiles.contains(&profile_name) { + profiles.push(profile_name); + } + } + } + + Ok(profiles) +} + +/// Validates if a given profile is actually a valid profile +#[tauri::command] +pub fn validate_profile(game_install: GameInstall, profile: String) -> bool { + // Game files are never a valid profile + // Prevent users with messed up installs from making it even worse + if SKIP_PATHS.contains(&profile.as_str()) { + return false; + } + + log::info!("Validating Profile {}", profile); + + let profile_path = format!("{}/{}", game_install.game_path, profile); + let profile_dir = std::path::Path::new(profile_path.as_str()); + + profile_dir.is_dir() +} |