aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/src/main.rs2
-rw-r--r--src-tauri/src/northstar/mod.rs1
-rw-r--r--src-tauri/src/northstar/profile.rs76
3 files changed, 79 insertions, 0 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index a7827a44..66bb98d2 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -158,6 +158,8 @@ fn main() {
close_application,
development::install_git_main,
get_available_northstar_versions,
+ northstar::profile::fetch_profiles,
+ northstar::profile::validate_profile,
])
.run(tauri::generate_context!())
{
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()
+}