mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Read install folders (#130)
This commit is contained in:
@@ -1 +0,0 @@
|
||||
|
||||
@@ -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<SteamGameInfo> {
|
||||
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<SteamGameInfo> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return games;
|
||||
}
|
||||
}
|
||||
vec![]
|
||||
games.sort_by_key(|g| g.name.clone());
|
||||
return games;
|
||||
}
|
||||
|
||||
fn get_install_folders(settings: &SteamSettings) -> Vec<PathBuf> {
|
||||
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<SteamGameInfo> {
|
||||
|
||||
Reference in New Issue
Block a user