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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
//! Heroic Games Launcher detection
//!
//! Detects games installed via Heroic (GOG and Epic Games).
//! Parses installed.json and GamesConfig/*.json for game and prefix info.
use std::fs;
use std::path::{Path, PathBuf};
use serde::Deserialize;
use super::known_games::{find_by_epic_id, find_by_gog_id, find_by_title};
use super::{Game, HeroicStore, Launcher};
use crate::logging::{log_info, log_warning};
/// Possible Heroic configuration paths
const HEROIC_PATHS: &[&str] = &[
".config/heroic", // Native
".var/app/com.heroicgameslauncher.hgl/config/heroic", // Flatpak
];
/// Detect all Heroic games
pub fn detect_heroic_games() -> Vec<Game> {
let mut games = Vec::new();
let home = match std::env::var("HOME") {
Ok(h) => h,
Err(_) => return games,
};
for relative_path in HEROIC_PATHS {
let heroic_path = PathBuf::from(&home).join(relative_path);
if !heroic_path.exists() {
continue;
}
log_info(&format!("Found Heroic installation: {}", heroic_path.display()));
// Detect GOG games
let gog_games = detect_gog_games(&heroic_path);
games.extend(gog_games);
// Detect Epic games
let epic_games = detect_epic_games(&heroic_path);
games.extend(epic_games);
}
log_info(&format!("Heroic: Found {} installed games", games.len()));
games
}
// ============================================================================
// GOG Detection
// ============================================================================
/// GOG installed game entry from installed.json
#[derive(Debug, Deserialize)]
struct GogInstalledGame {
#[serde(rename = "appName")]
app_name: String,
title: Option<String>,
#[serde(rename = "install_path")]
install_path: Option<String>,
platform: Option<String>,
}
/// Wrapper for Heroic's GOG installed.json format: {"installed": [...]}
#[derive(Debug, Deserialize)]
struct GogInstalledWrapper {
installed: Vec<GogInstalledGame>,
}
/// Detect GOG games from Heroic
fn detect_gog_games(heroic_path: &Path) -> Vec<Game> {
let mut games = Vec::new();
let installed_json = heroic_path.join("gog_store/installed.json");
let Ok(content) = fs::read_to_string(&installed_json) else {
return games;
};
// Heroic wraps GOG games in {"installed": [...]}, but also handle bare arrays
let installed: Vec<GogInstalledGame> =
if let Ok(wrapper) = serde_json::from_str::<GogInstalledWrapper>(&content) {
wrapper.installed
} else if let Ok(list) = serde_json::from_str::<Vec<GogInstalledGame>>(&content) {
list
} else {
log_warning("Failed to parse Heroic GOG installed.json");
return games;
};
for gog_game in installed {
// Skip non-Windows games (we only care about Wine prefixes)
if gog_game.platform.as_deref() != Some("windows") {
continue;
}
let Some(install_path_str) = gog_game.install_path else {
continue;
};
let install_path = PathBuf::from(&install_path_str);
if !install_path.exists() {
continue;
}
// Get the game config for Wine prefix info
let prefix_path = get_heroic_game_prefix(heroic_path, &gog_game.app_name);
// Look up known game info
let known_game = find_by_gog_id(&gog_game.app_name);
let name = gog_game
.title
.unwrap_or_else(|| gog_game.app_name.clone());
games.push(Game {
name,
app_id: gog_game.app_name,
install_path,
prefix_path,
launcher: Launcher::Heroic {
store: HeroicStore::GOG,
},
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()),
});
}
games
}
// ============================================================================
// Epic Detection
// ============================================================================
/// Epic installed game entry from installed.json
#[derive(Debug, Deserialize)]
struct EpicInstalledGame {
#[serde(rename = "app_name")]
app_name: String,
title: Option<String>,
install_path: Option<String>,
platform: Option<String>,
is_installed: Option<bool>,
}
/// Detect Epic games from Heroic
fn detect_epic_games(heroic_path: &Path) -> Vec<Game> {
let mut games = Vec::new();
let installed_json = heroic_path.join("store_cache/legendary_library.json");
// Also try the older location
let installed_json = if installed_json.exists() {
installed_json
} else {
heroic_path.join("legendaryConfig/legendary/installed.json")
};
let Ok(content) = fs::read_to_string(&installed_json) else {
return games;
};
// The Epic library format can vary - try parsing as an object with game keys
if let Ok(library) = serde_json::from_str::<serde_json::Value>(&content) {
if let Some(obj) = library.as_object() {
for (app_name, game_data) in obj {
let Some(game_obj) = game_data.as_object() else {
continue;
};
// Check if installed
let is_installed = game_obj
.get("is_installed")
.and_then(|v| v.as_bool())
.unwrap_or(false);
if !is_installed {
continue;
}
// Get platform
let platform = game_obj
.get("platform")
.and_then(|v| v.as_str());
if platform != Some("Windows") && platform != Some("windows") {
continue;
}
// Get install path
let Some(install_path_str) = game_obj
.get("install_path")
.and_then(|v| v.as_str())
else {
continue;
};
let install_path = PathBuf::from(install_path_str);
if !install_path.exists() {
continue;
}
// Get title
let title = game_obj
.get("title")
.and_then(|v| v.as_str())
.unwrap_or(app_name);
// Look up known game info: try Epic AppName first, then title match
let known_game = find_by_epic_id(app_name)
.or_else(|| find_by_title(title));
let name = title.to_string();
// Get Wine prefix
let prefix_path = get_heroic_game_prefix(heroic_path, app_name);
games.push(Game {
name,
app_id: app_name.clone(),
install_path,
prefix_path,
launcher: Launcher::Heroic {
store: HeroicStore::Epic,
},
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()),
});
}
}
}
games
}
// ============================================================================
// Shared Utilities
// ============================================================================
/// Game config entry for Wine settings
#[derive(Debug, Deserialize)]
struct HeroicGameConfig {
#[serde(rename = "winePrefix")]
wine_prefix: Option<String>,
#[serde(rename = "wineVersion")]
wine_version: Option<WineVersion>,
}
#[derive(Debug, Deserialize)]
struct WineVersion {
bin: Option<String>,
name: Option<String>,
#[serde(rename = "type")]
wine_type: Option<String>,
}
/// Get the Wine prefix for a Heroic game from its config file
fn get_heroic_game_prefix(heroic_path: &Path, app_name: &str) -> Option<PathBuf> {
let config_path = heroic_path.join(format!("GamesConfig/{}.json", app_name));
let content = fs::read_to_string(&config_path).ok()?;
// The config can be either a direct object or wrapped in the app_name key
let config: serde_json::Value = serde_json::from_str(&content).ok()?;
// Try to get winePrefix from the object or from a nested object
let wine_prefix = config
.get("winePrefix")
.or_else(|| config.get(app_name).and_then(|v| v.get("winePrefix")))
.and_then(|v| v.as_str())?;
let prefix_path = PathBuf::from(wine_prefix);
if prefix_path.exists() {
Some(prefix_path)
} else {
None
}
}
|