game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
gog_integration.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// gog_integration.h
4// ==============================================================================
5// Integration with GOG Galaxy/Heroic for GOG.com games
6// ==============================================================================
7// Provides functionality for managing GOG games through multiple methods:
8// - Heroic Games Launcher (recommended, full-featured)
9// - gogdl CLI (lightweight alternative)
10// - Direct GOG Galaxy database parsing
11//
12// ## About GOG Integration
13// GOG.com games are DRM-free, making integration straightforward. This service
14// provides library sync, installation, and cloud save management for GOG games.
15//
16// ## Thread Safety
17// All public methods are thread-safe.
18// ==============================================================================
19
20#pragma once
21
22#include "game.h"
23
24#include <chrono>
25#include <filesystem>
26#include <functional>
27#include <future>
28#include <memory>
29#include <optional>
30#include <string>
31#include <vector>
32
33// ==============================================================================
34// Data Structures
35// ==============================================================================
36
37/**
38 * @struct GOGGameInfo
39 * @brief Information about a GOG.com game
40 */
42{
43 std::string gameId; ///< GOG game ID (numeric string)
44 std::string title; ///< Display title
45 std::string slug; ///< URL-friendly name
46 std::string version; ///< Installed version
47
48 // Installation info
49 bool isInstalled = false;
50 std::filesystem::path installPath;
51 int64_t installSize = 0;
52 std::string executable; ///< Main executable name
53
54 // Platform info
55 bool hasLinuxBuild = false;
56 bool hasWindowsBuild = false;
57 bool hasMacBuild = false;
58
59 // Media
60 std::string coverUrl;
61 std::string backgroundUrl;
62 std::string iconUrl;
63
64 // Metadata
65 std::string developer;
66 std::string publisher;
67 std::string releaseDate;
68 std::vector<std::string> genres;
69 std::vector<std::string> tags;
70 float rating = 0.0f;
71
72 // DLC
73 std::vector<std::string> dlcIds;
74 bool isDLC = false;
75 std::string baseGameId; ///< If DLC, the base game ID
76
77 // Cloud saves
78 bool supportsCloudSaves = false;
79
80 std::string getFormattedSize() const;
81};
82
83/**
84 * @struct GOGAuthStatus
85 * @brief GOG Galaxy authentication status
86 */
88{
89 bool isAuthenticated = false;
90 std::string userId;
91 std::string username;
92 std::string email;
93 std::chrono::system_clock::time_point tokenExpiry;
94
95 bool isTokenExpired() const;
96};
97
98/**
99 * @struct GOGProgress
100 * @brief Progress information for GOG operations
101 */
103{
114
116 std::string currentFile;
117 int64_t bytesDownloaded = 0;
118 int64_t bytesTotal = 0;
120 float downloadSpeed = 0.0f;
121 std::string errorMessage;
122
123 std::string getStateStr() const;
124};
125
126/**
127 * @enum GOGBackend
128 * @brief Backend to use for GOG operations
129 */
130enum class GOGBackend
131{
132 Heroic, ///< Heroic Games Launcher (full-featured)
133 GOGDL, ///< gogdl CLI (lightweight)
134 Direct ///< Direct GOG API (limited)
135};
136
137// ==============================================================================
138// GOGIntegration Class
139// ==============================================================================
140
141/**
142 * @class GOGIntegration
143 * @brief Service for integrating with GOG.com
144 *
145 * Provides methods for managing GOG library, installation, and cloud saves
146 * through Heroic Games Launcher or gogdl CLI.
147 *
148 * ## Prerequisites
149 * One of:
150 * - Heroic Games Launcher installed
151 * - gogdl CLI installed
152 *
153 * ## Usage Example
154 * @code
155 * GOGIntegration gog;
156 *
157 * if (gog.isAvailable()) {
158 * auto games = gog.getLibrary();
159 * for (const auto& game : games) {
160 * std::cout << game.title << std::endl;
161 * }
162 * }
163 * @endcode
164 */
166{
167 public:
168 using ProgressCallback = std::function<void(const GOGProgress&)>;
169 using AuthCallback = std::function<void(bool success, const std::string& message)>;
170
173
174 // ==========================================================================
175 // Availability Check
176 // ==========================================================================
177
178 /**
179 * @brief Check if GOG integration is available
180 * @return True if Heroic or gogdl is installed
181 */
182 bool isAvailable() const;
183
184 /**
185 * @brief Get which backend is being used
186 * @return Active backend
187 */
189
190 /**
191 * @brief Check if Heroic Games Launcher is installed
192 */
193 static bool isHeroicAvailable();
194
195 /**
196 * @brief Check if gogdl CLI is installed
197 */
198 static bool isGogdlAvailable();
199
200 /**
201 * @brief Set preferred backend
202 * @param backend Preferred backend (will fall back if unavailable)
203 */
204 void setPreferredBackend(GOGBackend backend);
205
206 // ==========================================================================
207 // Authentication
208 // ==========================================================================
209
210 /**
211 * @brief Get authentication status
212 * @return Authentication status
213 */
215
216 /**
217 * @brief Check if user is authenticated
218 */
219 bool isAuthenticated() const;
220
221 /**
222 * @brief Start authentication flow
223 * @param callback Callback when auth completes
224 */
225 void authenticate(const AuthCallback& callback = nullptr);
226
227 /**
228 * @brief Log out and clear credentials
229 */
230 void logout();
231
232 // ==========================================================================
233 // Library Management
234 // ==========================================================================
235
236 /**
237 * @brief Get all games in GOG library
238 * @param forceRefresh Force refresh from GOG servers
239 * @return Vector of game info
240 */
241 std::vector<GOGGameInfo> getLibrary(bool forceRefresh = false);
242
243 /**
244 * @brief Get all installed GOG games
245 * @return Vector of installed game info
246 */
247 std::vector<GOGGameInfo> getInstalledGames() const;
248
249 /**
250 * @brief Get info for a specific game
251 * @param gameId GOG game ID
252 * @return Game info if found
253 */
254 std::optional<GOGGameInfo> getGameInfo(const std::string& gameId) const;
255
256 /**
257 * @brief Convert GOG game to generic Game object
258 * @param gogGame GOG game info
259 * @return Game object for use with game library
260 */
261 Game toGame(const GOGGameInfo& gogGame) const;
262
263 /**
264 * @brief Sync GOG library with game database
265 * @return Number of games synced
266 */
267 int syncLibrary();
268
269 // ==========================================================================
270 // Installation
271 // ==========================================================================
272
273 /**
274 * @brief Install a game
275 * @param gameId GOG game ID
276 * @param installPath Installation path (empty = default)
277 * @param platform Platform to install (empty = auto-detect)
278 * @param progressCallback Progress updates
279 * @return True on success
280 */
281 bool installGame(const std::string& gameId, const std::filesystem::path& installPath = {},
282 const std::string& platform = "",
283 const ProgressCallback& progressCallback = nullptr);
284
285 /**
286 * @brief Install a game asynchronously
287 */
288 std::future<bool> installGameAsync(const std::string& gameId,
289 const std::filesystem::path& installPath = {},
290 const std::string& platform = "",
291 const ProgressCallback& progressCallback = nullptr);
292
293 /**
294 * @brief Uninstall a game
295 * @param gameId GOG game ID
296 * @return True on success
297 */
298 bool uninstallGame(const std::string& gameId);
299
300 /**
301 * @brief Update a game
302 * @param gameId GOG game ID
303 * @param progressCallback Progress updates
304 * @return True on success
305 */
306 bool updateGame(const std::string& gameId, const ProgressCallback& progressCallback = nullptr);
307
308 /**
309 * @brief Check if updates are available
310 * @param gameId GOG game ID
311 * @return True if update available
312 */
313 bool hasUpdate(const std::string& gameId) const;
314
315 /**
316 * @brief Verify game files
317 * @param gameId GOG game ID
318 * @param progressCallback Progress updates
319 * @return True if all files valid
320 */
321 bool verifyGame(const std::string& gameId, const ProgressCallback& progressCallback = nullptr);
322
323 /**
324 * @brief Import existing game installation
325 * @param gameId GOG game ID
326 * @param existingPath Path to existing installation
327 * @return True on success
328 */
329 bool importGame(const std::string& gameId, const std::filesystem::path& existingPath);
330
331 // ==========================================================================
332 // Cloud Saves
333 // ==========================================================================
334
335 /**
336 * @brief Download cloud saves for a game
337 * @param gameId GOG game ID
338 * @return True on success
339 */
340 bool downloadCloudSaves(const std::string& gameId);
341
342 /**
343 * @brief Upload local saves to cloud
344 * @param gameId GOG game ID
345 * @return True on success
346 */
347 bool uploadCloudSaves(const std::string& gameId);
348
349 /**
350 * @brief Sync cloud saves (bidirectional)
351 * @param gameId GOG game ID
352 * @return True on success
353 */
354 bool syncCloudSaves(const std::string& gameId);
355
356 // ==========================================================================
357 // Launch
358 // ==========================================================================
359
360 /**
361 * @brief Launch a game
362 * @param gameId GOG game ID
363 * @param useProton Use Proton for Windows games
364 * @param protonVersion Proton version to use
365 * @return True if launch initiated
366 */
367 bool launchGame(const std::string& gameId, bool useProton = false,
368 const std::string& protonVersion = "");
369
370 /**
371 * @brief Get launch command for a game
372 * @param gameId GOG game ID
373 * @return Launch command string
374 */
375 std::string getLaunchCommand(const std::string& gameId) const;
376
377 // ==========================================================================
378 // Configuration
379 // ==========================================================================
380
381 /**
382 * @brief Set default installation directory
383 * @param path Default install path
384 */
385 void setDefaultInstallPath(const std::filesystem::path& path);
386
387 /**
388 * @brief Get default installation directory
389 */
390 std::filesystem::path getDefaultInstallPath() const;
391
392 /**
393 * @brief Cancel ongoing operation
394 */
395 void cancelOperation();
396
397 private:
398 struct Impl;
399 std::unique_ptr<Impl> impl_;
400
401 // Backend-specific implementations
402 std::vector<GOGGameInfo> fetchLibraryHeroicUnlocked(); // blocking I/O, must NOT hold mutex
403 std::vector<GOGGameInfo> getLibraryHeroic(bool forceRefresh);
404 std::vector<GOGGameInfo> getLibraryGogdl(bool forceRefresh);
405 bool installGameHeroic(const std::string& gameId, const std::filesystem::path& path,
406 const ProgressCallback& cb);
407 bool installGameGogdl(const std::string& gameId, const std::filesystem::path& path,
408 const ProgressCallback& cb);
409
410 // Heroic database parsing
411 std::vector<GOGGameInfo> parseHeroicLibrary() const;
412 std::vector<GOGGameInfo> parseHeroicInstalled() const;
413 std::filesystem::path getHeroicConfigPath() const;
414};
bool launchGame(const std::string &gameId, bool useProton=false, const std::string &protonVersion="")
Launch a game.
std::optional< GOGGameInfo > getGameInfo(const std::string &gameId) const
Get info for a specific game.
std::vector< GOGGameInfo > getLibrary(bool forceRefresh=false)
Get all games in GOG library.
bool syncCloudSaves(const std::string &gameId)
Sync cloud saves (bidirectional).
static bool isHeroicAvailable()
Check if Heroic Games Launcher is installed.
void cancelOperation()
Cancel ongoing operation.
GOGBackend getActiveBackend() const
Get which backend is being used.
bool uninstallGame(const std::string &gameId)
Uninstall a game.
bool verifyGame(const std::string &gameId, const ProgressCallback &progressCallback=nullptr)
Verify game files.
bool importGame(const std::string &gameId, const std::filesystem::path &existingPath)
Import existing game installation.
std::future< bool > installGameAsync(const std::string &gameId, const std::filesystem::path &installPath={}, const std::string &platform="", const ProgressCallback &progressCallback=nullptr)
Install a game asynchronously.
void setDefaultInstallPath(const std::filesystem::path &path)
Set default installation directory.
std::string getLaunchCommand(const std::string &gameId) const
Get launch command for a game.
bool hasUpdate(const std::string &gameId) const
Check if updates are available.
static bool isGogdlAvailable()
Check if gogdl CLI is installed.
bool isAvailable() const
Check if GOG integration is available.
void authenticate(const AuthCallback &callback=nullptr)
Start authentication flow.
Game toGame(const GOGGameInfo &gogGame) const
Convert GOG game to generic Game object.
bool updateGame(const std::string &gameId, const ProgressCallback &progressCallback=nullptr)
Update a game.
std::filesystem::path getDefaultInstallPath() const
Get default installation directory.
bool uploadCloudSaves(const std::string &gameId)
Upload local saves to cloud.
bool installGame(const std::string &gameId, const std::filesystem::path &installPath={}, const std::string &platform="", const ProgressCallback &progressCallback=nullptr)
Install a game.
std::vector< GOGGameInfo > getInstalledGames() const
Get all installed GOG games.
int syncLibrary()
Sync GOG library with game database.
bool isAuthenticated() const
Check if user is authenticated.
void setPreferredBackend(GOGBackend backend)
Set preferred backend.
GOGAuthStatus getAuthStatus() const
Get authentication status.
void logout()
Log out and clear credentials.
std::function< void(bool success, const std::string &message)> AuthCallback
std::function< void(const GOGProgress &)> ProgressCallback
bool downloadCloudSaves(const std::string &gameId)
Download cloud saves for a game.
Complete representation of a game in the library.
Definition game.h:767
GOGBackend
Backend to use for GOG operations.
@ GOGDL
gogdl CLI (lightweight)
@ Heroic
Heroic Games Launcher (full-featured).
@ Direct
Direct GOG API (limited).
int progressCallback(void *userp, curl_off_t dltotal, curl_off_t, curl_off_t, curl_off_t)
GOG Galaxy authentication status.
bool isTokenExpired() const
std::string email
std::string username
std::string userId
std::chrono::system_clock::time_point tokenExpiry
Information about a GOG.com game.
std::string backgroundUrl
bool supportsCloudSaves
std::filesystem::path installPath
std::string iconUrl
std::string baseGameId
If DLC, the base game ID.
std::string executable
Main executable name.
int64_t installSize
std::string gameId
GOG game ID (numeric string).
std::string publisher
std::string releaseDate
std::vector< std::string > dlcIds
std::string developer
std::vector< std::string > tags
std::string version
Installed version.
std::string slug
URL-friendly name.
std::string getFormattedSize() const
std::string coverUrl
std::vector< std::string > genres
std::string title
Display title.
Progress information for GOG operations.
std::string errorMessage
std::string getStateStr() const
int64_t bytesDownloaded
std::string currentFile