aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/lib.rs
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-10 18:36:10 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-09-10 18:36:10 +0200
commit80b8b2c318fbb04853a813c438c896a4b2f8b37d (patch)
treedeebbe224307a6d78948a6c2c2e5c8dfcf3540a9 /src-tauri/src/lib.rs
parent578516b2bcbfa2c80e02d51951d99e3083360749 (diff)
downloadFlightCore-80b8b2c318fbb04853a813c438c896a4b2f8b37d.tar.gz
FlightCore-80b8b2c318fbb04853a813c438c896a4b2f8b37d.zip
Return GameInstall object instead of tuple
The object contains the path Titanfall2 is installed in, as well as how it was installed (Steam, Origin, EA-App)
Diffstat (limited to 'src-tauri/src/lib.rs')
-rw-r--r--src-tauri/src/lib.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 5971f421..916a78ed 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1,9 +1,10 @@
use anyhow::{anyhow, Context, Result};
use powershell_script::PsScriptBuilder;
use regex::Regex;
+use serde::{Deserialize, Serialize};
use zip::ZipArchive;
-#[derive(Debug)]
+#[derive(Serialize, Deserialize, Debug)]
pub enum InstallType {
STEAM,
ORIGIN,
@@ -11,6 +12,12 @@ pub enum InstallType {
UNKNOWN,
}
+#[derive(Serialize, Deserialize, Debug)]
+pub struct GameInstall {
+ game_path: String,
+ install_type: InstallType,
+}
+
/// Check version number of a mod
pub fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, anyhow::Error> {
// println!("{}", format!("{}/mod.json", path_to_mod_folder));
@@ -61,7 +68,7 @@ fn windows_origin_install_location_detection() -> Result<String, anyhow::Error>
}
/// Attempts to find the game install location
-pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Error> {
+pub fn find_game_install_location() -> Result<GameInstall, anyhow::Error> {
// Attempt parsing Steam library directly
match steamlocate::SteamDir::locate() {
Some(mut steamdir) => {
@@ -69,7 +76,11 @@ pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Err
match steamdir.app(&titanfall2_steamid) {
Some(app) => {
// println!("{:#?}", app);
- return Ok((app.path.to_str().unwrap().to_string(), InstallType::STEAM));
+ let game_install = GameInstall {
+ game_path: app.path.to_str().unwrap().to_string(),
+ install_type: InstallType::STEAM,
+ };
+ return Ok(game_install);
}
None => println!("Couldn't locate Titanfall2"),
}
@@ -80,7 +91,13 @@ pub fn find_game_install_location() -> Result<(String, InstallType), anyhow::Err
// (On Windows only) try parsing Windows registry for Origin install path
#[cfg(target_os = "windows")]
match windows_origin_install_location_detection() {
- Ok(game_path) => return Ok((game_path, InstallType::ORIGIN)),
+ Ok(game_path) => {
+ let game_install = GameInstall {
+ game_path: game_path,
+ install_type: InstallType::ORIGIN,
+ };
+ return Ok(game_install);
+ }
Err(err) => {
println!("{}", err);
}