aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-18 00:40:24 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-18 00:40:24 +0200
commit58b8dce1422ac2ddd31a6bea88fad64bf2920e1c (patch)
tree1a0ba44499b6f88298330935721d45e919d3df4f /src-tauri/src
parentbabb50234988d4d17c5803c392a414b07fac30d6 (diff)
parent7b188d5fa95cb12a8e00051ecfaab14cbe1ff1e8 (diff)
downloadFlightCore-58b8dce1422ac2ddd31a6bea88fad64bf2920e1c.tar.gz
FlightCore-58b8dce1422ac2ddd31a6bea88fad64bf2920e1c.zip
Merge branch 'main' into feat/read-packages-dir
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/main.rs57
-rw-r--r--src-tauri/src/mod_management/legacy.rs61
-rw-r--r--src-tauri/src/mod_management/mod.rs51
-rw-r--r--src-tauri/src/northstar/mod.rs78
4 files changed, 130 insertions, 117 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 5d71713a..a584eea9 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -128,7 +128,7 @@ fn main() {
install_northstar_caller,
update_northstar,
northstar::launch_northstar,
- launch_northstar_steam,
+ northstar::launch_northstar_steam,
github::release_notes::check_is_flightcore_outdated,
repair_and_verify::get_log_list,
repair_and_verify::verify_game_files,
@@ -461,8 +461,6 @@ mod platform_specific;
#[cfg(target_os = "linux")]
use platform_specific::linux;
-use crate::constants::TITANFALL2_STEAM_ID;
-
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum InstallType {
STEAM,
@@ -527,56 +525,3 @@ pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> {
fn get_host_os() -> String {
env::consts::OS.to_string()
}
-
-/// Prepare Northstar and Launch through Steam using the Browser Protocol
-#[tauri::command]
-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)) {
- Ok(()) => Ok("Started game".to_string()),
- Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()),
- }
-}
diff --git a/src-tauri/src/mod_management/legacy.rs b/src-tauri/src/mod_management/legacy.rs
index 0f9074d2..f24f44b6 100644
--- a/src-tauri/src/mod_management/legacy.rs
+++ b/src-tauri/src/mod_management/legacy.rs
@@ -1,3 +1,7 @@
+use crate::constants::BLACKLISTED_MODS;
+use crate::mod_management::{
+ delete_mod_folder, get_installed_mods_and_properties, ParsedThunderstoreModString,
+};
use crate::GameInstall;
use crate::NorthstarMod;
use anyhow::{anyhow, Result};
@@ -110,3 +114,60 @@ pub fn parse_installed_mods(
// Return found mod names
Ok(mods)
}
+
+/// Deletes all NorthstarMods related to a Thunderstore mod
+pub fn delete_thunderstore_mod(
+ game_install: GameInstall,
+ thunderstore_mod_string: String,
+) -> Result<(), String> {
+ // Prevent deleting core mod
+ for core_ts_mod in BLACKLISTED_MODS {
+ if thunderstore_mod_string == core_ts_mod {
+ return Err(format!("Cannot remove core mod {thunderstore_mod_string}"));
+ }
+ }
+
+ let parsed_ts_mod_string: ParsedThunderstoreModString =
+ thunderstore_mod_string.parse().unwrap();
+
+ // Get installed mods
+ let installed_ns_mods = get_installed_mods_and_properties(game_install)?;
+
+ // List of mod folders to remove
+ let mut mod_folders_to_remove: Vec<String> = Vec::new();
+
+ // Get folder name based on Thundestore mod string
+ for installed_ns_mod in installed_ns_mods {
+ if installed_ns_mod.thunderstore_mod_string.is_none() {
+ // Not a Thunderstore mod
+ continue;
+ }
+
+ let installed_ns_mod_ts_string: ParsedThunderstoreModString = installed_ns_mod
+ .thunderstore_mod_string
+ .unwrap()
+ .parse()
+ .unwrap();
+
+ // Installed mod matches specified Thunderstore mod string
+ if parsed_ts_mod_string.author_name == installed_ns_mod_ts_string.author_name
+ && parsed_ts_mod_string.mod_name == installed_ns_mod_ts_string.mod_name
+ {
+ // Add folder to list of folder to remove
+ mod_folders_to_remove.push(installed_ns_mod.directory);
+ }
+ }
+
+ if mod_folders_to_remove.is_empty() {
+ return Err(format!(
+ "No mods removed as no Northstar mods matching {thunderstore_mod_string} were found to be installed."
+ ));
+ }
+
+ // Delete given folders
+ for mod_folder in mod_folders_to_remove {
+ delete_mod_folder(&mod_folder)?;
+ }
+
+ Ok(())
+}
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index 683b06a7..2ac26ede 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -554,54 +554,5 @@ pub fn delete_thunderstore_mod(
game_install: GameInstall,
thunderstore_mod_string: String,
) -> Result<(), String> {
- // Prevent deleting core mod
- for core_ts_mod in BLACKLISTED_MODS {
- if thunderstore_mod_string == core_ts_mod {
- return Err(format!("Cannot remove core mod {thunderstore_mod_string}"));
- }
- }
-
- let parsed_ts_mod_string: ParsedThunderstoreModString =
- thunderstore_mod_string.parse().unwrap();
-
- // Get installed mods
- let installed_ns_mods = get_installed_mods_and_properties(game_install)?;
-
- // List of mod folders to remove
- let mut mod_folders_to_remove: Vec<String> = Vec::new();
-
- // Get folder name based on Thundestore mod string
- for installed_ns_mod in installed_ns_mods {
- if installed_ns_mod.thunderstore_mod_string.is_none() {
- // Not a Thunderstore mod
- continue;
- }
-
- let installed_ns_mod_ts_string: ParsedThunderstoreModString = installed_ns_mod
- .thunderstore_mod_string
- .unwrap()
- .parse()
- .unwrap();
-
- // Installed mod matches specified Thunderstore mod string
- if parsed_ts_mod_string.author_name == installed_ns_mod_ts_string.author_name
- && parsed_ts_mod_string.mod_name == installed_ns_mod_ts_string.mod_name
- {
- // Add folder to list of folder to remove
- mod_folders_to_remove.push(installed_ns_mod.directory);
- }
- }
-
- if mod_folders_to_remove.is_empty() {
- return Err(format!(
- "No mods removed as no Northstar mods matching {thunderstore_mod_string} were found to be installed."
- ));
- }
-
- // Delete given folders
- for mod_folder in mod_folders_to_remove {
- delete_mod_folder(&mod_folder)?;
- }
-
- Ok(())
+ legacy::delete_thunderstore_mod(game_install, thunderstore_mod_string)
}
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs
index 47510dbd..bf55603b 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);
@@ -122,3 +125,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)) {
+ Ok(()) => Ok("Started game".to_string()),
+ Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()),
+ }
+}