From 4134c55bbe641445fb47dff2ec3ed23c9cbdc970 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sat, 27 Aug 2022 13:38:05 +0200 Subject: Find Titanfall2 steam install location and propagate it to front-end --- src-tauri/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src-tauri/src/main.rs') 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() -- cgit v1.2.3