diff --git a/Cargo.lock b/Cargo.lock index 9c1a9f3..baa2863 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2600,9 +2600,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" +checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c" dependencies = [ "bytes", "futures-core", diff --git a/src/steam/instaled_games.rs b/src/steam/instaled_games.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/steam/instaled_games.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/steam/installed_games.rs b/src/steam/installed_games.rs index eefa364..4477aa8 100644 --- a/src/steam/installed_games.rs +++ b/src/steam/installed_games.rs @@ -1,4 +1,4 @@ -use std::{ffi::OsStr, path::Path}; +use std::{ffi::OsStr, path::{Path, PathBuf}}; use super::{get_steam_path, SteamSettings}; @@ -9,11 +9,10 @@ pub struct SteamGameInfo { } pub fn get_installed_games(settings: &SteamSettings) -> Vec { - let path = get_steam_path(settings); - if let Ok(path) = path { - let apps_path = Path::new(&path).join("steamapps"); - if let Ok(files) = std::fs::read_dir(apps_path) { - let mut games = vec![]; + let install_folders = get_install_folders(settings); + let mut games = vec![]; + for apps_path in install_folders { + if let Ok(files) = std::fs::read_dir(apps_path) { for file in files { if let Ok(file) = file { if let Some(game_info) = parse_manifest_file(&file.path()) { @@ -21,10 +20,33 @@ pub fn get_installed_games(settings: &SteamSettings) -> Vec { } } } - return games; } } - vec![] + games.sort_by_key(|g| g.name.clone()); + return games; +} + +fn get_install_folders(settings: &SteamSettings) -> Vec { + let mut result = vec![]; + if let Ok(path) = get_steam_path(settings) { + let path = Path::new(&path); + + let vdf_path = path.join("steamapps").join("libraryfolders.vdf"); + if !vdf_path.exists() { + result.push(path.join("steamapps").to_path_buf()); + return result; + } + if let Ok(vdf_file) = std::fs::read_to_string(vdf_path) { + for line in vdf_file.lines() { + if line.contains("\"path\"") { + let path_string = &line[11..line.len() - 1]; + result.push(Path::new(&path_string).join("steamapps").to_path_buf()); + } + } + } + } + + return result; } fn parse_manifest_file(path: &Path) -> Option {