aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/northstar
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src/northstar')
-rw-r--r--src-tauri/src/northstar/mod.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs
index 7bd0b0a3..d26ecb64 100644
--- a/src-tauri/src/northstar/mod.rs
+++ b/src-tauri/src/northstar/mod.rs
@@ -3,6 +3,7 @@
use crate::{check_mod_version_number, constants::CORE_MODS};
use anyhow::anyhow;
+use app::{check_origin_running, get_host_os, GameInstall, InstallType};
/// Returns the current Northstar version number as a string
pub fn get_northstar_version_number(game_path: &str) -> Result<String, anyhow::Error> {
@@ -35,3 +36,70 @@ pub fn get_northstar_version_number(game_path: &str) -> Result<String, anyhow::E
Ok(initial_version_number)
}
+
+pub fn launch_northstar(
+ game_install: &GameInstall,
+ bypass_checks: Option<bool>,
+) -> Result<String, String> {
+ dbg!(game_install.clone());
+
+ 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
+ ));
+ }
+
+ let bypass_checks = bypass_checks.unwrap_or(false);
+
+ // Only check guards if bypassing checks is not enabled
+ if !bypass_checks {
+ // Some safety checks before, should have more in the future
+ if get_northstar_version_number(&game_install.game_path).is_err() {
+ return Err(anyhow!("Not all checks were met").to_string());
+ }
+
+ // Require Origin to be running to launch Northstar
+ let origin_is_running = check_origin_running();
+ if !origin_is_running {
+ return Err(
+ anyhow!("Origin not running, start Origin before launching Northstar").to_string(),
+ );
+ }
+ }
+
+ // Switch to Titanfall2 directory for launching
+ // NorthstarLauncher.exe expects to be run from that folder
+ if std::env::set_current_dir(game_install.game_path.clone()).is_err() {
+ // We failed to get to Titanfall2 directory
+ return Err(anyhow!("Couldn't access Titanfall2 directory").to_string());
+ }
+
+ // Only Windows with Steam or Origin are supported at the moment
+ 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))
+ {
+ let ns_exe_path = format!("{}/NorthstarLauncher.exe", game_install.game_path);
+ let _output = std::process::Command::new("C:\\Windows\\System32\\cmd.exe")
+ .args(["/C", "start", "", &ns_exe_path])
+ .spawn()
+ .expect("failed to execute process");
+ return Ok("Launched game".to_string());
+ }
+
+ Err(format!(
+ "Not yet implemented for {:?} on {}",
+ game_install.install_type,
+ get_host_os()
+ ))
+}