game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_scanner_service.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// game_scanner_service.h
4// ==============================================================================
5// Service for scanning and detecting installed games from various sources
6// ==============================================================================
7// Scans for games from:
8// - Lutris (~/.local/share/lutris/games/*.yml)
9// - Bottles (~/.local/share/bottles/bottles/*)
10// - Heroic Launcher (~/.config/heroic/) - Epic and GOG games
11// - Legendary (~/.config/legendary/) - Epic Games CLI
12// - Native Linux games (~/Games/, .desktop files)
13// - Generic Wine prefixes (~/.wine, etc.)
14// ==============================================================================
15
16#pragma once
17
18#include "models/game.h"
19
20#include <cstdint>
21#include <functional>
22#include <map>
23#include <mutex>
24#include <string>
25#include <vector>
26
27// ==============================================================================
28// Scanned Game (detected game before import)
29// ==============================================================================
30
32{
33 // Identification
34 std::string id; // Unique ID for deduplication (hash of path)
35 std::string name; // Game name
36 GameSource source; // Lutris, GOG, Epic, etc.
37
38 // Paths
39 std::string executablePath; // Full path to executable
40 std::string installDir; // Installation directory
41 std::string winePrefix; // Wine prefix path (if applicable)
42 std::string workingDir; // Working directory for launch
43
44 // Runner info
45 GameRunner runner; // Native, Wine, Proton
46 std::string runnerVersion; // Wine/Proton version if known
47 std::string arguments; // Launch arguments
48
49 // Metadata / Artwork
50 std::string iconPath; // Path to icon if found
51 std::string coverPath; // Path to vertical cover image if found (600x900)
52 std::string bannerPath; // Path to banner/hero image if found (landscape)
53 uint64_t sizeOnDisk; // Installation size in bytes
54 time_t lastModified; // Last modification time
55 std::string configPath; // Original config file path (for reference)
56
57 // Environment and settings
58 std::map<std::string, std::string> environmentVars;
59 std::map<std::string, std::string> dllOverrides; // Wine DLL overrides
60 std::vector<std::string> excludeProcesses; // Processes to exclude from game tracking
61
62 // Import status
63 bool alreadyImported = false; // Already in library
64 std::string existingGameId; // If already imported, the existing game ID
65
66 // Source-specific metadata
67 std::string sourceId; // ID in the source system (e.g., Lutris slug, Epic app name)
68 std::string sourceUrl; // URL in source system if applicable
69 int steamAppId = 0; // Steam App ID if known
70 int gogId = 0; // GOG ID if known
71 std::string epicAppId; // Epic App ID if known
72
73 // Generate a unique ID based on executable path
74 void generateId();
75
76 // Convert to Game for import
77 Game toGame() const;
78};
79
80// ==============================================================================
81// Scan Progress
82// ==============================================================================
83
85{
86 std::string currentSource; // "Lutris", "Bottles", etc.
87 std::string currentOperation; // Current file/operation
88 int sourcesCompleted = 0; // Number of sources scanned
89 int totalSources = 0; // Total number of sources to scan
90 int gamesFound = 0; // Games found so far
91 int overallPercent = 0; // Overall progress 0-100
92
93 // Error tracking for each source
94 std::vector<std::string> errors; // Errors encountered during scan
95 std::vector<std::string> warnings; // Non-fatal warnings
96
97 // Add error with source context
98 void addError(const std::string& source, const std::string& message)
99 {
100 errors.push_back("[" + source + "] " + message);
101 }
102
103 // Add warning with source context
104 void addWarning(const std::string& source, const std::string& message)
105 {
106 warnings.push_back("[" + source + "] " + message);
107 }
108
109 // Check if scan had any errors
110 bool hasErrors() const
111 {
112 return !errors.empty();
113 }
114
115 // Check if scan had any warnings
116 bool hasWarnings() const
117 {
118 return !warnings.empty();
119 }
120};
121
122// ==============================================================================
123// Game Scanner Service
124// ==============================================================================
125
126/**
127 * @class GameScannerService
128 * @brief Scans for installed games from various sources
129 *
130 * This service detects games installed via Lutris, Bottles, Heroic Launcher,
131 * Legendary, and other common Linux gaming platforms. It can also scan for
132 * native Linux games and generic Wine prefixes.
133 */
135{
136 public:
137 using ProgressCallback = std::function<void(const ScanProgress&)>;
138 using CompletionCallback = std::function<void(const std::vector<ScannedGame>&)>;
139
140 // =========================================================================
141 // Full Scan
142 // =========================================================================
143
144 /**
145 * @brief Scan all available sources for games
146 * @param progressCallback Optional callback for progress updates
147 * @return List of detected games
148 */
149 static std::vector<ScannedGame> scanAll(ProgressCallback progressCallback = nullptr);
150
151 /**
152 * @brief Scan all sources asynchronously
153 * @param onComplete Callback with results
154 * @param onProgress Optional progress callback
155 */
156 static void scanAllAsync(const CompletionCallback& onComplete,
157 const ProgressCallback& onProgress = nullptr);
158
159 // =========================================================================
160 // Individual Source Scanners
161 // =========================================================================
162
163 /**
164 * @brief Scan Lutris for installed games
165 * @return List of games found in Lutris
166 */
167 static std::vector<ScannedGame> scanLutris();
168
169 /**
170 * @brief Scan Bottles for installed games
171 * @return List of games found in Bottles
172 */
173 static std::vector<ScannedGame> scanBottles();
174
175 /**
176 * @brief Scan Heroic Launcher for Epic and GOG games
177 * @return List of games found in Heroic
178 */
179 static std::vector<ScannedGame> scanHeroic();
180
181 /**
182 * @brief Scan Legendary (Epic Games CLI) for installed games
183 * @return List of games found via Legendary
184 */
185 static std::vector<ScannedGame> scanLegendary();
186
187 /**
188 * @brief Scan for native Linux games
189 * @return List of native games found
190 */
191 static std::vector<ScannedGame> scanNativeGames();
192
193 /**
194 * @brief Scan generic Wine prefixes for games
195 * @return List of games found in Wine prefixes
196 */
197 static std::vector<ScannedGame> scanWinePrefixes();
198
199 // =========================================================================
200 // Utility Methods
201 // =========================================================================
202
203 /**
204 * @brief Mark games that are already in the library
205 * @param games List of scanned games to check
206 * @param library Current game library
207 */
208 static void markAlreadyImported(std::vector<ScannedGame>& games,
209 const std::vector<Game>& library);
210
211 /**
212 * @brief Remove duplicate games from the list
213 * @param games List of scanned games
214 * @return Deduplicated list
215 */
216 static std::vector<ScannedGame> removeDuplicates(std::vector<ScannedGame> games);
217
218 /**
219 * @brief Get display name for a game source
220 * @param source The game source enum
221 * @return Human-readable name
222 */
223 static std::string getSourceDisplayName(GameSource source);
224
225 /**
226 * @brief Get icon name for a game source
227 * @param source The game source enum
228 * @return Icon/emoji for the source
229 */
230 static std::string getSourceIcon(GameSource source);
231
232 // =========================================================================
233 // Source Availability Checks
234 // =========================================================================
235
236 /**
237 * @brief Check if Lutris is installed
238 */
239 static bool isLutrisInstalled();
240
241 /**
242 * @brief Check if Bottles is installed
243 */
244 static bool isBottlesInstalled();
245
246 /**
247 * @brief Check if Heroic Launcher is installed
248 */
249 static bool isHeroicInstalled();
250
251 /**
252 * @brief Check if Legendary is installed
253 */
254 static bool isLegendaryInstalled();
255
256 /**
257 * @brief Set custom scan directories for native game scanning
258 * @param dirs List of directory paths to scan in addition to hardcoded defaults
259 *
260 * Call this during app initialization (e.g., after loading settings).
261 * These directories are appended to the built-in scan list in scanNativeGames().
262 */
263 static void setCustomScanDirectories(const std::vector<std::string>& dirs);
264
265 private:
266 // Custom scan directories (set via setCustomScanDirectories)
267 static std::vector<std::string> customScanDirs_;
268 static std::mutex customScanDirsMutex_;
269 // Helper methods for parsing
270 static std::vector<ScannedGame> parseLutrisConfig(const std::string& configPath);
271 static std::vector<ScannedGame> parseBottleConfig(const std::string& bottlePath);
272 static std::vector<ScannedGame> parseHeroicInstalledJson(const std::string& jsonPath,
273 GameSource source);
274 static std::vector<ScannedGame> parseLegendaryInstalledJson(const std::string& jsonPath);
275 static std::vector<ScannedGame> parseDesktopFile(const std::string& desktopPath);
276
277 // Path helpers
278 static std::string expandPath(const std::string& path);
279 static std::string getHomeDir();
280 static uint64_t getDirectorySize(const std::string& path);
281 static time_t getLastModified(const std::string& path);
282
283 // JSON parsing helpers (simple, no external library)
284 static std::string extractJsonString(const std::string& json, const std::string& key);
285 static int extractJsonInt(const std::string& json, const std::string& key);
286 static bool extractJsonBool(const std::string& json, const std::string& key);
287};
Scans for installed games from various sources.
static bool isHeroicInstalled()
Check if Heroic Launcher is installed.
static std::vector< ScannedGame > scanLegendary()
Scan Legendary (Epic Games CLI) for installed games.
std::function< void(const std::vector< ScannedGame > &)> CompletionCallback
static bool isLegendaryInstalled()
Check if Legendary is installed.
static std::string getSourceIcon(GameSource source)
Get icon name for a game source.
static std::vector< ScannedGame > scanWinePrefixes()
Scan generic Wine prefixes for games.
static std::string getSourceDisplayName(GameSource source)
Get display name for a game source.
static std::vector< ScannedGame > scanBottles()
Scan Bottles for installed games.
static bool isLutrisInstalled()
Check if Lutris is installed.
static bool isBottlesInstalled()
Check if Bottles is installed.
static std::vector< ScannedGame > removeDuplicates(std::vector< ScannedGame > games)
Remove duplicate games from the list.
static void setCustomScanDirectories(const std::vector< std::string > &dirs)
Set custom scan directories for native game scanning.
static std::vector< ScannedGame > scanNativeGames()
Scan for native Linux games.
static std::vector< ScannedGame > scanAll(ProgressCallback progressCallback=nullptr)
Scan all available sources for games.
static void scanAllAsync(const CompletionCallback &onComplete, const ProgressCallback &onProgress=nullptr)
Scan all sources asynchronously.
static std::vector< ScannedGame > scanLutris()
Scan Lutris for installed games.
static std::vector< ScannedGame > scanHeroic()
Scan Heroic Launcher for Epic and GOG games.
static void markAlreadyImported(std::vector< ScannedGame > &games, const std::vector< Game > &library)
Mark games that are already in the library.
std::function< void(const ScanProgress &)> ProgressCallback
Complete representation of a game in the library.
Definition game.h:767
GameSource
Where the game was acquired from (store/service/local).
Definition game.h:39
GameRunner
Runner/compatibility layer for executing the game.
Definition game.h:81
nlohmann::json json
bool hasWarnings() const
void addError(const std::string &source, const std::string &message)
std::vector< std::string > warnings
void addWarning(const std::string &source, const std::string &message)
std::vector< std::string > errors
bool hasErrors() const
std::string currentOperation
std::string currentSource
std::string sourceId
std::string runnerVersion
std::string configPath
std::map< std::string, std::string > environmentVars
std::string coverPath
std::string iconPath
std::vector< std::string > excludeProcesses
std::string winePrefix
std::string workingDir
std::string existingGameId
std::string bannerPath
std::string arguments
std::string sourceUrl
std::string epicAppId
std::string executablePath
std::string installDir
std::map< std::string, std::string > dllOverrides