From e9d990d0498d95f050a8c6bb9b3403336e852fe6 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sat, 10 Sep 2022 20:36:24 +0200 Subject: Add initial back-end code for launching Northstar --- src-tauri/src/lib.rs | 2 +- src-tauri/src/main.rs | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d0377917..da1ba9b8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -14,7 +14,7 @@ pub enum InstallType { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct GameInstall { - game_path: String, + pub game_path: String, pub install_type: InstallType, } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 097774d4..4244e364 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,9 +9,10 @@ use std::{ time::Duration, }; +use anyhow::anyhow; use app::{ check_is_valid_game_path, find_game_install_location, get_northstar_version_number, - install_northstar, GameInstall, + install_northstar, GameInstall, InstallType, }; use tauri::{Manager, State}; use tokio::time::sleep; @@ -193,5 +194,33 @@ async fn update_northstar_caller(game_path: String) -> Result { /// Launches Northstar fn launch_northstar(game_install: GameInstall) -> Result { dbg!(game_install.clone()); + + // Some safety checks before, should have more in the future + if get_northstar_version_number(game_install.game_path.clone()).is_err() { + return Err(anyhow!("Not all checks were met").to_string()); + } + + let host_os = get_host_os(); + + // 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)) + { + let _output = + std::process::Command::new(format!("{}/NorthstarLauncher.exe", game_install.game_path)) + // .args(&["a", "b"]) + .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())) } -- cgit v1.2.3