diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-08-27 13:38:05 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-08-27 13:38:05 +0200 |
commit | 4134c55bbe641445fb47dff2ec3ed23c9cbdc970 (patch) | |
tree | 84a216622e8104deed5bfa5f0d68022ec49982be /src-tauri/src/main.rs | |
parent | 2b2d636177af18a1cd0bdee48cacd4e60d5eb37d (diff) | |
download | FlightCore-4134c55bbe641445fb47dff2ec3ed23c9cbdc970.tar.gz FlightCore-4134c55bbe641445fb47dff2ec3ed23c9cbdc970.zip |
Find Titanfall2 steam install location
and propagate it to front-end
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r-- | src-tauri/src/main.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 41776ac4..301dcb4e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -36,6 +36,20 @@ fn main() { } }); + let app_handle = app.app_handle(); + tauri::async_runtime::spawn(async move { + // Checking install location inside a timed loop is a bad idea + // If the user has the game on a harddrive for example, it will prevent the harddrive from ever spinning down + // Instead, install location checks should be event based. + loop { + sleep(Duration::from_millis(5000)).await; + println!("sending install location"); + app_handle + .emit_all("install-location-result", find_game_install_location()) + .unwrap(); + } + }); + Ok(()) }) .manage(Counter(Default::default())) @@ -48,6 +62,24 @@ fn main() { .expect("error while running tauri application"); } +fn find_game_install_location() -> String { + // Attempt parsing Steam library directly + match steamlocate::SteamDir::locate() { + Some(mut steamdir) => { + let titanfall2_steamid = 1237970; + match steamdir.app(&titanfall2_steamid) { + Some(app) => { + println!("{:#?}", app); + return app.path.to_str().unwrap().to_string(); + } + None => println!("Couldn't locate Titanfall2"), + } + } + None => println!("Couldn't locate Steam on this computer!"), + } + "NOT FOUND".to_string() +} + #[tauri::command] fn hello_world() -> String { "Hello World!!!".to_string() |