diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-07-23 23:53:53 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-07-23 23:53:53 +0200 |
commit | f2d5d62366b80ad596824853bdcf72e1dc296243 (patch) | |
tree | 0c63957a63f67a524a8c6ba53a1585a5c077e1a6 /src-tauri/src/northstar | |
parent | baa1c52126eae7980f49f39631e2c5931d5b478f (diff) | |
parent | 031ced476c38d08f7bec5312c16d1343a24e2469 (diff) | |
download | FlightCore-f2d5d62366b80ad596824853bdcf72e1dc296243.tar.gz FlightCore-f2d5d62366b80ad596824853bdcf72e1dc296243.zip |
Merge branch 'main' into feat/launch-parameters
Diffstat (limited to 'src-tauri/src/northstar')
-rw-r--r-- | src-tauri/src/northstar/install.rs | 16 | ||||
-rw-r--r-- | src-tauri/src/northstar/mod.rs | 78 |
2 files changed, 83 insertions, 11 deletions
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 71da515d..28366738 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -168,6 +168,22 @@ pub fn find_game_install_location() -> Result<GameInstall, String> { // Attempt parsing Steam library directly match steamlocate::SteamDir::locate() { Some(mut steamdir) => { + #[cfg(target_os = "linux")] + { + let snap_dir = match std::env::var("SNAP_USER_DATA") { + Ok(snap_dir) => std::path::PathBuf::from(snap_dir), + Err(_) => match dirs::home_dir() { + Some(path) => path, + None => std::path::PathBuf::new(), + } + .join("snap"), + }; + + if steamdir.path.starts_with(snap_dir) { + log::warn!("Found Steam installed via Snap, you may encounter issues"); + } + } + let titanfall2_steamid = TITANFALL2_STEAM_ID.parse().unwrap(); match steamdir.app(&titanfall2_steamid) { Some(app) => { diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index 2630ff1f..6d0e26d2 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -3,7 +3,10 @@ pub mod install; use crate::util::check_ea_app_or_origin_running; -use crate::{constants::CORE_MODS, get_host_os, GameInstall, InstallType}; +use crate::{ + constants::{CORE_MODS, TITANFALL2_STEAM_ID}, + get_host_os, GameInstall, InstallType, +}; use anyhow::anyhow; /// Check version number of a mod @@ -65,16 +68,16 @@ pub fn launch_northstar( let host_os = get_host_os(); // Explicitly fail early certain (currently) unsupported install setups - if host_os != "windows" - || !(matches!(game_install.install_type, InstallType::STEAM) - || matches!(game_install.install_type, InstallType::ORIGIN) - || matches!(game_install.install_type, InstallType::UNKNOWN)) - { - return Err(format!( - "Not yet implemented for \"{}\" with Titanfall2 installed via \"{:?}\"", - get_host_os(), - game_install.install_type - )); + if host_os != "windows" { + if !matches!(game_install.install_type, InstallType::STEAM) { + return Err(format!( + "Not yet implemented for \"{}\" with Titanfall2 installed via \"{:?}\"", + get_host_os(), + game_install.install_type + )); + } + + return launch_northstar_steam(game_install, bypass_checks); } let bypass_checks = bypass_checks.unwrap_or(false); @@ -128,3 +131,56 @@ pub fn launch_northstar( get_host_os() )) } + +/// Prepare Northstar and Launch through Steam using the Browser Protocol +#[tauri::command] +pub fn launch_northstar_steam( + game_install: GameInstall, + _bypass_checks: Option<bool>, +) -> Result<String, String> { + if !matches!(game_install.install_type, InstallType::STEAM) { + return Err("Titanfall2 was not installed via Steam".to_string()); + } + + match steamlocate::SteamDir::locate() { + Some(mut steamdir) => { + if get_host_os() != "windows" { + 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") + { + return Err( + "Titanfall2 was not configured to use NorthstarProton".to_string() + ); + } + } + None => { + return Err( + "Titanfall2 was not configured to use a compatibility tool".to_string() + ); + } + } + } + } + None => { + return Err("Couldn't access Titanfall2 directory".to_string()); + } + } + + // Switch to Titanfall2 directory to set everything up + if std::env::set_current_dir(game_install.game_path).is_err() { + // We failed to get to Titanfall2 directory + return Err("Couldn't access Titanfall2 directory".to_string()); + } + + match open::that(format!("steam://run/{}//--northstar {}/", TITANFALL2_STEAM_ID, game_install.launch_parameters)) { + Ok(()) => Ok("Started game".to_string()), + Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()), + } +} |