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/install.rs31
-rw-r--r--src-tauri/src/northstar/mod.rs60
2 files changed, 53 insertions, 38 deletions
diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs
index a89de018..0953fa38 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::{CORE_MODS, NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL, TITANFALL2_STEAM_ID};
+use crate::constants::{CORE_MODS, NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL};
use crate::{
util::{extract, move_dir_all},
GameInstall, InstallType,
@@ -293,7 +293,7 @@ pub async fn install_northstar(
pub fn find_game_install_location() -> Result<GameInstall, String> {
// Attempt parsing Steam library directly
match steamlocate::SteamDir::locate() {
- Some(mut steamdir) => {
+ Ok(steamdir) => {
#[cfg(target_os = "linux")]
{
let snap_dir = match std::env::var("SNAP_USER_DATA") {
@@ -305,26 +305,37 @@ pub fn find_game_install_location() -> Result<GameInstall, String> {
.join("snap"),
};
- if steamdir.path.starts_with(snap_dir) {
+ 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) => {
- // println!("{:#?}", app);
+ match steamdir.find_app(thermite::TITANFALL2_STEAM_ID) {
+ Ok(Some((app, library))) => {
+ let app_path = library
+ .path()
+ .join("steamapps")
+ .join("common")
+ .join(app.install_dir)
+ .into_os_string()
+ .into_string()
+ .unwrap();
+
let game_install = GameInstall {
- game_path: app.path.to_str().unwrap().to_string(),
+ game_path: app_path,
profile: "R2Northstar".to_string(),
install_type: InstallType::STEAM,
};
return Ok(game_install);
}
- None => log::info!("Couldn't locate Titanfall2 Steam install"),
+ Ok(None) => log::info!("Couldn't locate your Titanfall 2 Steam install."),
+ Err(err) => log::info!(
+ "Something went wrong while trying to find Titanfall 2 {}",
+ err
+ ),
}
}
- None => log::info!("Couldn't locate Steam on this computer!"),
+ Err(err) => log::info!("Couldn't locate Steam on this computer! {}", err),
}
// (On Windows only) try parsing Windows registry for Origin install path
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs
index ea4f4cde..4b16f701 100644
--- a/src-tauri/src/northstar/mod.rs
+++ b/src-tauri/src/northstar/mod.rs
@@ -4,13 +4,18 @@ pub mod install;
pub mod profile;
use crate::util::check_ea_app_or_origin_running;
-use crate::{
- constants::{CORE_MODS, TITANFALL2_STEAM_ID},
- platform_specific::get_host_os,
- GameInstall, InstallType,
-};
+use crate::{constants::CORE_MODS, platform_specific::get_host_os, GameInstall, InstallType};
use crate::{NorthstarThunderstoreRelease, NorthstarThunderstoreReleaseWrapper};
use anyhow::anyhow;
+use serde::{Deserialize, Serialize};
+use ts_rs::TS;
+
+#[derive(Serialize, Deserialize, Debug, Clone, TS)]
+#[ts(export)]
+pub struct NorthstarLaunchOptions {
+ launch_via_steam: bool,
+ bypass_checks: bool,
+}
/// Gets list of available Northstar versions from Thunderstore
#[tauri::command]
@@ -154,14 +159,12 @@ pub fn get_northstar_version_number(game_install: GameInstall) -> Result<String,
#[tauri::command]
pub fn launch_northstar(
game_install: GameInstall,
- launch_via_steam: Option<bool>,
- bypass_checks: Option<bool>,
+ launch_options: NorthstarLaunchOptions,
) -> Result<String, String> {
dbg!(game_install.clone());
- let launch_via_steam = launch_via_steam.unwrap_or(false);
- if launch_via_steam {
- return launch_northstar_steam(game_install, bypass_checks);
+ if launch_options.launch_via_steam {
+ return launch_northstar_steam(game_install);
}
let host_os = get_host_os();
@@ -176,13 +179,11 @@ pub fn launch_northstar(
));
}
- return launch_northstar_steam(game_install, bypass_checks);
+ return launch_northstar_steam(game_install);
}
- let bypass_checks = bypass_checks.unwrap_or(false);
-
// Only check guards if bypassing checks is not enabled
- if !bypass_checks {
+ if !launch_options.bypass_checks {
// Some safety checks before, should have more in the future
if get_northstar_version_number(game_install.clone()).is_err() {
return Err(anyhow!("Not all checks were met").to_string());
@@ -228,29 +229,31 @@ pub fn launch_northstar(
}
/// Prepare Northstar and Launch through Steam using the Browser Protocol
-pub fn launch_northstar_steam(
- game_install: GameInstall,
- _bypass_checks: Option<bool>,
-) -> Result<String, String> {
+pub fn launch_northstar_steam(game_install: GameInstall) -> 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) => {
+ Ok(steamdir) => {
if get_host_os() != "windows" {
- let titanfall2_steamid: u32 = TITANFALL2_STEAM_ID.parse().unwrap();
- match steamdir.compat_tool(&titanfall2_steamid) {
- Some(_) => {}
- None => {
- return Err(
- "Titanfall2 was not configured to use a compatibility tool".to_string()
- );
+ match steamdir.compat_tool_mapping() {
+ Ok(map) => match map.get(&thermite::TITANFALL2_STEAM_ID) {
+ Some(_) => {}
+ None => {
+ return Err(
+ "Titanfall2 was not configured to use a compatibility tool"
+ .to_string(),
+ );
+ }
+ },
+ Err(_) => {
+ return Err("Could not get compatibility tool mapping".to_string());
}
}
}
}
- None => {
+ Err(_) => {
return Err("Couldn't access Titanfall2 directory".to_string());
}
}
@@ -263,7 +266,8 @@ pub fn launch_northstar_steam(
match open::that(format!(
"steam://run/{}//-profile={} --northstar/",
- TITANFALL2_STEAM_ID, game_install.profile
+ thermite::TITANFALL2_STEAM_ID,
+ game_install.profile
)) {
Ok(()) => Ok("Started game".to_string()),
Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()),