aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/constants.rs36
-rw-r--r--src-tauri/src/github/mod.rs1
-rw-r--r--src-tauri/src/main.rs5
-rw-r--r--src-tauri/src/mod_management/mod.rs2
-rw-r--r--src-tauri/src/northstar/install.rs25
-rw-r--r--src-tauri/src/northstar/mod.rs13
-rw-r--r--src-tauri/src/northstar/profile.rs76
-rw-r--r--src-tauri/src/repair_and_verify/mod.rs5
8 files changed, 137 insertions, 26 deletions
diff --git a/src-tauri/src/constants.rs b/src-tauri/src/constants.rs
index 9917a8c8..33aefac8 100644
--- a/src-tauri/src/constants.rs
+++ b/src-tauri/src/constants.rs
@@ -2,53 +2,63 @@
use const_format::concatcp;
use std::time::Duration;
-// FlightCore user agent for web requests
+/// FlightCore user agent for web requests
pub const APP_USER_AGENT: &str = concatcp!("FlightCore/", env!("CARGO_PKG_VERSION"));
-// URL of the Northstar masterserver
+/// URL of the Northstar masterserver
pub const MASTER_SERVER_URL: &str = "https://northstar.tf";
-// server list endpoint
+/// server list endpoint
pub const SERVER_BROWSER_ENDPOINT: &str = "/client/servers";
-// List of core Northstar mods
+/// List of core Northstar mods
pub const CORE_MODS: [&str; 3] = [
"Northstar.Client",
"Northstar.Custom",
"Northstar.CustomServers",
];
-// List of Thunderstoremods that shouldn't be installable
-// as they behave different than common Squirrel mods
+/// List of Thunderstoremods that shouldn't be installable
+/// as they behave different than common Squirrel mods
pub const BLACKLISTED_MODS: [&str; 3] = [
"northstar-Northstar",
"northstar-NorthstarReleaseCandidate",
"ebkr-r2modman",
];
-// Titanfall2 Steam App ID
+/// Titanfall2 Steam App ID
pub const TITANFALL2_STEAM_ID: &str = "1237970";
-// Order in which the sections for release notes should be displayed
+/// Order in which the sections for release notes should be displayed
pub const SECTION_ORDER: [&str; 10] = [
"feat", "fix", "docs", "style", "refactor", "build", "test", "i18n", "chore", "other",
];
-// GitHub API endpoints for launcher/mods PRs
+/// GitHub API endpoints for launcher/mods PRs
pub const PULLS_API_ENDPOINT_LAUNCHER: &str =
"https://api.github.com/repos/R2Northstar/NorthstarLauncher/pulls";
pub const PULLS_API_ENDPOINT_MODS: &str =
"https://api.github.com/repos/R2Northstar/NorthstarMods/pulls";
-// Statistics (players and servers counts) refresh delay
+/// Statistics (players and servers counts) refresh delay
pub const REFRESH_DELAY: Duration = Duration::from_secs(5 * 60);
-// Flightcore repo name and org name on GitHub
+/// Flightcore repo name and org name on GitHub
pub const FLIGHTCORE_REPO_NAME: &str = "R2NorthstarTools/FlightCore";
-// Northstar release repo name and org name on GitHub
+/// Northstar release repo name and org name on GitHub
pub const NORTHSTAR_RELEASE_REPO_NAME: &str = "R2Northstar/Northstar";
-// URL to launcher commits API URL
+/// URL to launcher commits API URL
pub const NS_LAUNCHER_COMMITS_API_URL: &str =
"https://api.github.com/repos/R2Northstar/NorthstarLauncher/commits";
+
+/// Filename of DLL that Northstar uses
+pub const NORTHSTAR_DLL: &str = "Northstar.dll";
+
+/// Profile that Northstar defaults to and ships with
+pub const NORTHSTAR_DEFAULT_PROFILE: &str = "R2Northstar";
+
+/// List of valid compatibility tools that Northstar can be launched with
+pub const VALID_NORTHSTAR_PROTON_BUILDS: [&str; 3] =
+ ["NorthstarProton-8.1-1", "GE-Proton8-13", "GE-Proton8-11"];
diff --git a/src-tauri/src/github/mod.rs b/src-tauri/src/github/mod.rs
index bc1ccfe8..f35b64a1 100644
--- a/src-tauri/src/github/mod.rs
+++ b/src-tauri/src/github/mod.rs
@@ -180,6 +180,7 @@ fn generate_flightcore_release_notes(commits: Vec<String>) -> String {
}
}
+ let release_notes = release_notes.trim_end_matches('\n').to_string();
release_notes
}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 9e812683..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!())
{
@@ -457,7 +459,8 @@ mod platform_specific;
#[cfg(target_os = "linux")]
use platform_specific::linux;
-#[derive(Serialize, Deserialize, Debug, Clone)]
+#[derive(Serialize, Deserialize, Debug, Clone, TS)]
+#[ts(export)]
pub enum InstallType {
STEAM,
ORIGIN,
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index ff3a09ed..a9826522 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -26,7 +26,7 @@ impl std::str::FromStr for ParsedThunderstoreModString {
type Err = &'static str; // todo use an better error management
fn from_str(s: &str) -> Result<Self, Self::Err> {
- // Check whether Thunderstore string passse reges
+ // Check whether Thunderstore string passes regex
let re = regex::Regex::new(r"^[a-zA-Z0-9_]+-[a-zA-Z0-9_]+-\d+\.\d+\.\d++$").unwrap();
if !re.is_match(s) {
return Err("Incorrect format");
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs
index 80425c56..757f6c68 100644
--- a/src-tauri/src/northstar/install.rs
+++ b/src-tauri/src/northstar/install.rs
@@ -4,7 +4,7 @@ use std::time::Duration;
use std::{cell::RefCell, time::Instant};
use ts_rs::TS;
-use crate::constants::TITANFALL2_STEAM_ID;
+use crate::constants::{NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL, TITANFALL2_STEAM_ID};
use crate::{
util::{extract, move_dir_all},
GameInstall, InstallType,
@@ -96,6 +96,27 @@ async fn do_install(
log::info!("Extracting Northstar...");
extract(nfile, std::path::Path::new(&extract_directory))?;
+ // Prepare Northstar for Installation
+ log::info!("Preparing Northstar...");
+ if game_install.profile != NORTHSTAR_DEFAULT_PROFILE {
+ // We are using a non standard Profile, we must:
+ // - move the DLL
+ // - rename the Profile
+
+ // Move DLL into the default R2Northstar Profile
+ let old_dll_path = format!("{}/{}", extract_directory, NORTHSTAR_DLL);
+ let new_dll_path = format!(
+ "{}/{}/{}",
+ extract_directory, NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL
+ );
+ std::fs::rename(old_dll_path, new_dll_path)?;
+
+ // rename default R2Northstar Profile to the profile we want to use
+ let old_profile_path = format!("{}/{}/", extract_directory, NORTHSTAR_DEFAULT_PROFILE);
+ let new_profile_path = format!("{}/{}/", extract_directory, game_install.profile);
+ std::fs::rename(old_profile_path, new_profile_path)?;
+ }
+
log::info!("Installing Northstar...");
for entry in std::fs::read_dir(extract_directory).unwrap() {
@@ -163,7 +184,7 @@ pub async fn install_northstar(
Err(err) => {
if game_path
.to_lowercase()
- .contains(&r#"C:\Program Files\"#.to_lowercase())
+ .contains(&r"C:\Program Files\".to_lowercase())
// default is `C:\Program Files\EA Games\Titanfall2`
{
return Err(
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs
index e79123fd..4ee9ba82 100644
--- a/src-tauri/src/northstar/mod.rs
+++ b/src-tauri/src/northstar/mod.rs
@@ -1,10 +1,11 @@
//! 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::{
- constants::{CORE_MODS, TITANFALL2_STEAM_ID},
+ constants::{CORE_MODS, TITANFALL2_STEAM_ID, VALID_NORTHSTAR_PROTON_BUILDS},
get_host_os, GameInstall, InstallType,
};
use anyhow::anyhow;
@@ -158,15 +159,11 @@ pub fn launch_northstar_steam(
let titanfall2_steamid: u32 = TITANFALL2_STEAM_ID.parse().unwrap();
match steamdir.compat_tool(&titanfall2_steamid) {
Some(compat) => {
- if !compat
- .name
- .clone()
- .unwrap()
- .to_ascii_lowercase()
- .contains("northstarproton")
+ if !VALID_NORTHSTAR_PROTON_BUILDS
+ .contains(&compat.clone().name.unwrap().as_str())
{
return Err(
- "Titanfall2 was not configured to use NorthstarProton".to_string()
+ "Titanfall2 was not configured to use a valid version of NorthstarProton or GE-Proton".to_string(),
);
}
}
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()
+}
diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs
index 8b68ce59..70abc127 100644
--- a/src-tauri/src/repair_and_verify/mod.rs
+++ b/src-tauri/src/repair_and_verify/mod.rs
@@ -51,7 +51,10 @@ pub fn clean_up_download_folder(
let download_directory = format!("{}/{}/", game_install.game_path, directory);
// Check if files in folder
- let download_dir_contents = std::fs::read_dir(download_directory.clone())?;
+ let download_dir_contents = match std::fs::read_dir(download_directory.clone()) {
+ Ok(contents) => contents,
+ Err(_) => continue,
+ };
// dbg!(download_dir_contents);
let mut count = 0;