1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
//! Steam game detection
//!
//! Detects games installed via Steam by parsing appmanifest_*.acf files.
//! Supports native, Flatpak, and Snap Steam installations.
use std::fs;
use std::path::{Path, PathBuf};
use super::known_games::{find_by_steam_id, KnownGame};
use super::vdf::{parse_library_folders, AppManifest};
use super::{Game, Launcher};
use crate::logging::log_info;
/// All possible Steam installation paths to check
const STEAM_PATHS: &[&str] = &[
".local/share/Steam",
".steam/debian-installation",
".steam/steam",
".var/app/com.valvesoftware.Steam/data/Steam",
".var/app/com.valvesoftware.Steam/.local/share/Steam",
"snap/steam/common/.local/share/Steam",
];
/// Detect all Steam games across all installations
pub fn detect_steam_games() -> Vec<Game> {
let mut games = Vec::new();
let home = match std::env::var("HOME") {
Ok(h) => h,
Err(_) => return games,
};
// Find all Steam installations
for steam_info in find_steam_installations(&home) {
let libraries = get_library_folders(&steam_info.path);
// Collect all steamapps paths so we can search across them for compatdata.
// Steam can place compatdata in a different library folder than the game.
let all_steamapps: Vec<PathBuf> = libraries
.iter()
.map(|l| l.join("steamapps"))
.filter(|s| s.exists())
.collect();
for steamapps in &all_steamapps {
// Scan for appmanifest_*.acf files
let Ok(entries) = fs::read_dir(steamapps) else {
continue;
};
for entry in entries.flatten() {
let path = entry.path();
let Some(name) = path.file_name().and_then(|n| n.to_str()) else {
continue;
};
if name.starts_with("appmanifest_") && name.ends_with(".acf") {
if let Some(game) =
parse_appmanifest(&path, steamapps, &all_steamapps, &steam_info)
{
games.push(game);
}
}
}
}
}
log_info(&format!("Steam: Found {} installed games", games.len()));
games
}
/// Information about a Steam installation
struct SteamInstallation {
path: PathBuf,
is_flatpak: bool,
is_snap: bool,
}
/// Find all Steam installations on the system
fn find_steam_installations(home: &str) -> Vec<SteamInstallation> {
let mut installations = Vec::new();
for relative_path in STEAM_PATHS {
let full_path = PathBuf::from(home).join(relative_path);
// Check if this is a valid Steam installation
if full_path.join("steamapps").exists() || full_path.join("steam.pid").exists() {
let is_flatpak = relative_path.contains(".var/app/com.valvesoftware.Steam");
let is_snap = relative_path.contains("snap/steam");
// Avoid duplicates (symlinks can cause the same installation to appear twice)
let canonical = full_path.canonicalize().unwrap_or(full_path.clone());
if !installations.iter().any(|i: &SteamInstallation| {
i.path.canonicalize().unwrap_or(i.path.clone()) == canonical
}) {
log_info(&format!(
"Found Steam installation: {} (flatpak={}, snap={})",
full_path.display(),
is_flatpak,
is_snap
));
installations.push(SteamInstallation {
path: full_path,
is_flatpak,
is_snap,
});
}
}
}
installations
}
/// Get all library folders for a Steam installation
fn get_library_folders(steam_path: &Path) -> Vec<PathBuf> {
let mut folders = Vec::new();
// The Steam installation directory itself is always a library
folders.push(steam_path.to_path_buf());
// Parse libraryfolders.vdf for additional libraries
let vdf_path = steam_path.join("steamapps/libraryfolders.vdf");
if let Ok(content) = fs::read_to_string(&vdf_path) {
for path_str in parse_library_folders(&content) {
let path = PathBuf::from(&path_str);
if path.exists() && !folders.contains(&path) {
folders.push(path);
}
}
}
// Also check the older config/libraryfolders.vdf location
let old_vdf_path = steam_path.join("config/libraryfolders.vdf");
if old_vdf_path != vdf_path {
if let Ok(content) = fs::read_to_string(&old_vdf_path) {
for path_str in parse_library_folders(&content) {
let path = PathBuf::from(&path_str);
if path.exists() && !folders.contains(&path) {
folders.push(path);
}
}
}
}
folders
}
/// Parse an appmanifest_*.acf file and create a Game struct
fn parse_appmanifest(
manifest_path: &Path,
steamapps_path: &Path,
all_steamapps: &[PathBuf],
steam_info: &SteamInstallation,
) -> Option<Game> {
let content = fs::read_to_string(manifest_path).ok()?;
let manifest = AppManifest::from_vdf(&content)?;
// Only consider fully installed games
if !manifest.is_installed() {
return None;
}
// Build the install path
let install_path = steamapps_path.join("common").join(&manifest.install_dir);
if !install_path.exists() {
return None;
}
// Search ALL library folders for the compatdata — Steam can place it in a
// different library than the game itself (e.g. game on SD card, compatdata
// on internal storage or vice-versa).
let prefix_path = all_steamapps
.iter()
.map(|sa| sa.join("compatdata").join(&manifest.app_id).join("pfx"))
.find(|p| p.exists());
// Look up known game info
let known_game = find_by_steam_id(&manifest.app_id);
Some(Game {
name: manifest.name,
app_id: manifest.app_id,
install_path,
prefix_path,
launcher: Launcher::Steam {
is_flatpak: steam_info.is_flatpak,
is_snap: steam_info.is_snap,
},
my_games_folder: known_game.and_then(|g| g.my_games_folder.map(String::from)),
appdata_local_folder: known_game.and_then(|g| g.appdata_local_folder.map(String::from)),
appdata_roaming_folder: known_game.and_then(|g| g.appdata_roaming_folder.map(String::from)),
registry_path: known_game.map(|g| g.registry_path.to_string()),
registry_value: known_game.map(|g| g.registry_value.to_string()),
})
}
/// Find the installation path for a specific Steam game by App ID
pub fn find_game_install_path(app_id: &str) -> Option<PathBuf> {
let home = std::env::var("HOME").ok()?;
for steam_info in find_steam_installations(&home) {
let libraries = get_library_folders(&steam_info.path);
for library_path in libraries {
let manifest_path = library_path
.join("steamapps")
.join(format!("appmanifest_{}.acf", app_id));
if manifest_path.exists() {
let content = fs::read_to_string(&manifest_path).ok()?;
let manifest = AppManifest::from_vdf(&content)?;
if manifest.is_installed() {
let install_path = library_path
.join("steamapps/common")
.join(&manifest.install_dir);
if install_path.exists() {
return Some(install_path);
}
}
}
}
}
None
}
/// Find the Wine prefix for a specific Steam game by App ID
pub fn find_game_prefix_path(app_id: &str) -> Option<PathBuf> {
let home = std::env::var("HOME").ok()?;
for steam_info in find_steam_installations(&home) {
let libraries = get_library_folders(&steam_info.path);
for library_path in libraries {
let prefix_path = library_path
.join("steamapps/compatdata")
.join(app_id)
.join("pfx");
if prefix_path.exists() {
return Some(prefix_path);
}
}
}
None
}
/// Get the known game configuration for a Steam App ID
pub fn get_known_game(app_id: &str) -> Option<&'static KnownGame> {
find_by_steam_id(app_id)
}
|