aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/lib.rs71
-rw-r--r--src-tauri/src/main.rs2
-rw-r--r--src-tauri/src/northstar/mod.rs68
3 files changed, 69 insertions, 72 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index e570efdf..e22801c5 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -2,8 +2,6 @@ use std::{cell::RefCell, env, fs, path::Path, time::Duration, time::Instant};
use anyhow::{anyhow, Context, Result};
-mod northstar;
-
pub mod constants;
mod platform_specific;
#[cfg(target_os = "windows")]
@@ -18,8 +16,6 @@ use tokio::time::sleep;
use ts_rs::TS;
use zip::ZipArchive;
-use northstar::get_northstar_version_number;
-
use crate::constants::TITANFALL2_STEAM_ID;
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -325,73 +321,6 @@ pub fn get_host_os() -> String {
env::consts::OS.to_string()
}
-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()
- ))
-}
-
/// Prepare Northstar and Launch through Steam using the Browser Protocol
pub fn launch_northstar_steam(
game_install: &GameInstall,
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 459e47e5..d3b58b67 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -368,7 +368,7 @@ async fn launch_northstar_caller(
game_install: GameInstall,
bypass_checks: Option<bool>,
) -> Result<String, String> {
- launch_northstar(&game_install, bypass_checks)
+ northstar::launch_northstar(&game_install, bypass_checks)
}
/// Launches Northstar
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()
+ ))
+}