game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
legendary_integration.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// legendary_integration.h
4// ==============================================================================
5// Integration with Legendary CLI for Epic Games Store
6// ==============================================================================
7// Provides functionality for managing Epic Games through the Legendary CLI:
8// - Game library synchronization
9// - Game installation and updates
10// - DLC management
11// - Save game sync
12// - Authentication management
13//
14// ## About Legendary
15// Legendary is an open-source Epic Games Store CLI replacement that provides
16// similar functionality to the Epic Launcher without requiring it.
17// https://github.com/legendary-gl/legendary
18// (formerly derrod/legendary; project moved to the legendary-gl org in 2026)
19//
20// ## Thread Safety
21// All public methods are thread-safe.
22// ==============================================================================
23
24#pragma once
25
26#include "game.h"
27
28#include <sys/types.h> // pid_t
29
30#include <chrono>
31#include <filesystem>
32#include <functional>
33#include <future>
34#include <memory>
35#include <optional>
36#include <string>
37#include <vector>
38
39// ==============================================================================
40// Data Structures
41// ==============================================================================
42
43/**
44 * @struct EpicGameInfo
45 * @brief Information about an Epic Games Store game
46 */
48{
49 std::string appName; ///< Internal app identifier
50 std::string appTitle; ///< Display title
51 std::string version; ///< Installed/available version
52 std::string developer; ///< Developer name
53 std::string publisher; ///< Publisher name
54
55 // Installation info
56 bool isInstalled = false;
57 std::filesystem::path installPath;
58 int64_t installSize = 0; ///< Installed size in bytes
59 int64_t downloadSize = 0; ///< Download size in bytes
60
61 // Platform info
62 std::vector<std::string> platforms; ///< Available platforms (Windows, Mac)
63 bool supportsCloudSaves = false;
64
65 // DLC info
66 bool isDLC = false;
67 std::string baseGameAppName; ///< Parent game if this is DLC
68 std::vector<std::string> dlcAppNames; ///< DLC for this game
69
70 // Cover art
71 std::string coverUrl; ///< Cover image URL
72 std::string thumbnailUrl; ///< Thumbnail URL
73
74 std::string getFormattedInstallSize() const;
75 std::string getFormattedDownloadSize() const;
76};
77
78/**
79 * @struct EpicAuthStatus
80 * @brief Epic Games authentication status
81 */
83{
84 bool isAuthenticated = false;
85 std::string accountId;
86 std::string displayName;
87 std::chrono::system_clock::time_point tokenExpiry;
88
89 bool isTokenExpired() const;
90};
91
92/**
93 * @struct LegendaryProgress
94 * @brief Progress information for Legendary operations
95 */
97{
109
111 std::string currentFile;
112 int64_t bytesDownloaded = 0;
113 int64_t bytesTotal = 0;
115 float downloadSpeed = 0.0f; ///< MB/s
116 int estimatedTimeRemaining = 0; ///< Seconds
117 std::string errorMessage;
118
119 std::string getStateStr() const;
120};
121
122/**
123 * @struct EpicCloudSaveInfo
124 * @brief Information about cloud saves for an Epic game
125 */
127{
128 std::string appName;
129 std::filesystem::path localPath;
130 std::chrono::system_clock::time_point localModified;
131 std::chrono::system_clock::time_point cloudModified;
132 bool needsUpload = false;
133 bool needsDownload = false;
134 int64_t localSize = 0;
135 int64_t cloudSize = 0;
136};
137
138// ==============================================================================
139// LegendaryIntegration Class
140// ==============================================================================
141
142/**
143 * @class LegendaryIntegration
144 * @brief Service for integrating with Epic Games through Legendary CLI
145 *
146 * Provides methods for managing Epic Games library, installation, and
147 * cloud saves through the Legendary CLI tool.
148 *
149 * ## Prerequisites
150 * - Legendary CLI must be installed (https://github.com/legendary-gl/legendary)
151 * - User must be authenticated with `legendary auth`
152 *
153 * ## Usage Example
154 * @code
155 * LegendaryIntegration epic;
156 *
157 * if (!epic.isAuthenticated()) {
158 * epic.authenticate(); // Opens browser for login
159 * }
160 *
161 * auto games = epic.getInstalledGames();
162 * for (const auto& game : games) {
163 * std::cout << game.appTitle << std::endl;
164 * }
165 * @endcode
166 */
168{
169 public:
170 using ProgressCallback = std::function<void(const LegendaryProgress&)>;
171 using AuthCallback = std::function<void(bool success, const std::string& message)>;
172
175
176 // ==========================================================================
177 // Availability Check
178 // ==========================================================================
179
180 /**
181 * @brief Check if Legendary CLI is installed
182 * @return True if legendary command is available
183 */
184 static bool isAvailable();
185
186 /**
187 * @brief Get Legendary version
188 * @return Version string or empty if not available
189 */
190 static std::string getVersion();
191
192 /**
193 * @brief Get path to Legendary executable
194 * @return Path or empty if not found
195 */
196 static std::filesystem::path getLegendaryPath();
197
198 // ==========================================================================
199 // Authentication
200 // ==========================================================================
201
202 /**
203 * @brief Check authentication status
204 * @return Authentication status
205 */
207
208 /**
209 * @brief Check if user is authenticated
210 * @return True if authenticated with valid token
211 */
212 bool isAuthenticated() const;
213
214 /**
215 * @brief Start authentication flow
216 * @param callback Callback when auth completes
217 *
218 * Opens browser for Epic Games login. The callback is called when
219 * authentication completes (success or failure).
220 */
221 void authenticate(const AuthCallback& callback = nullptr);
222
223 /**
224 * @brief Start authentication with authorization code
225 * @param authCode Authorization code from Epic login
226 * @param callback Callback when auth completes
227 */
228 void authenticateWithCode(const std::string& authCode, const AuthCallback& callback = nullptr);
229
230 /**
231 * @brief Log out and clear credentials
232 */
233 void logout();
234
235 // ==========================================================================
236 // Library Management
237 // ==========================================================================
238
239 /**
240 * @brief Get all games in Epic library
241 * @param forceRefresh Force refresh from Epic servers
242 * @return Vector of game info
243 */
244 std::vector<EpicGameInfo> getLibrary(bool forceRefresh = false);
245
246 /**
247 * @brief Get all installed games
248 * @return Vector of installed game info
249 */
250 std::vector<EpicGameInfo> getInstalledGames() const;
251
252 /**
253 * @brief Get info for a specific game
254 * @param appName App name/ID
255 * @return Game info if found
256 */
257 std::optional<EpicGameInfo> getGameInfo(const std::string& appName) const;
258
259 /**
260 * @brief Convert Epic game to generic Game object
261 * @param epicGame Epic game info
262 * @return Game object for use with game library
263 */
264 Game toGame(const EpicGameInfo& epicGame) const;
265
266 /**
267 * @brief Sync Epic library with game database
268 * @return Number of games synced
269 */
270 int syncLibrary();
271
272 // ==========================================================================
273 // Installation
274 // ==========================================================================
275
276 /**
277 * @brief Install a game
278 * @param appName App name/ID
279 * @param installPath Installation path (empty = default)
280 * @param progressCallback Progress updates
281 * @return True on success
282 */
283 bool installGame(const std::string& appName, const std::filesystem::path& installPath = {},
284 const ProgressCallback& progressCallback = nullptr);
285
286 /**
287 * @brief Install a game asynchronously
288 */
289 std::future<bool> installGameAsync(const std::string& appName,
290 const std::filesystem::path& installPath = {},
291 const ProgressCallback& progressCallback = nullptr);
292
293 /**
294 * @brief Update a game
295 * @param appName App name/ID
296 * @param progressCallback Progress updates
297 * @return True on success
298 */
299 bool updateGame(const std::string& appName, const ProgressCallback& progressCallback = nullptr);
300
301 /**
302 * @brief Uninstall a game
303 * @param appName App name/ID
304 * @param keepFiles Keep game files (just unregister)
305 * @return True on success
306 */
307 bool uninstallGame(const std::string& appName, bool keepFiles = false);
308
309 /**
310 * @brief Verify game files
311 * @param appName App name/ID
312 * @param progressCallback Progress updates
313 * @return True if all files valid
314 */
315 bool verifyGame(const std::string& appName, const ProgressCallback& progressCallback = nullptr);
316
317 /**
318 * @brief Repair game (verify and redownload corrupt files)
319 * @param appName App name/ID
320 * @param progressCallback Progress updates
321 * @return True on success
322 */
323 bool repairGame(const std::string& appName, const ProgressCallback& progressCallback = nullptr);
324
325 /**
326 * @brief Move game to different location
327 * @param appName App name/ID
328 * @param newPath New installation path
329 * @param progressCallback Progress updates
330 * @return True on success
331 */
332 bool moveGame(const std::string& appName, const std::filesystem::path& newPath,
333 const ProgressCallback& progressCallback = nullptr);
334
335 /**
336 * @brief Import an existing game installation
337 * @param appName App name/ID
338 * @param existingPath Path to existing installation
339 * @return True on success
340 */
341 bool importGame(const std::string& appName, const std::filesystem::path& existingPath);
342
343 // ==========================================================================
344 // DLC Management
345 // ==========================================================================
346
347 /**
348 * @brief Get available DLC for a game
349 * @param appName Base game app name
350 * @return Vector of DLC info
351 */
352 std::vector<EpicGameInfo> getAvailableDLC(const std::string& appName);
353
354 /**
355 * @brief Install DLC for a game
356 * @param dlcAppName DLC app name
357 * @param progressCallback Progress updates
358 * @return True on success
359 */
360 bool installDLC(const std::string& dlcAppName,
361 const ProgressCallback& progressCallback = nullptr);
362
363 // ==========================================================================
364 // Cloud Saves
365 // ==========================================================================
366
367 /**
368 * @brief Get cloud save status for a game
369 * @param appName App name/ID
370 * @return Cloud save info
371 */
372 EpicCloudSaveInfo getCloudSaveStatus(const std::string& appName) const;
373
374 /**
375 * @brief Download cloud saves for a game
376 * @param appName App name/ID
377 * @param force Force overwrite local saves
378 * @return True on success
379 */
380 bool downloadCloudSaves(const std::string& appName, bool force = false);
381
382 /**
383 * @brief Upload local saves to cloud
384 * @param appName App name/ID
385 * @param force Force overwrite cloud saves
386 * @return True on success
387 */
388 bool uploadCloudSaves(const std::string& appName, bool force = false);
389
390 /**
391 * @brief Sync saves (download if newer, upload if local is newer)
392 * @param appName App name/ID
393 * @return True on success
394 */
395 bool syncCloudSaves(const std::string& appName);
396
397 // ==========================================================================
398 // Launch
399 // ==========================================================================
400
401 /**
402 * @brief Launch a game
403 * @param appName App name/ID
404 * @param additionalArgs Additional command line arguments
405 * @param offline Launch in offline mode
406 * @param outPid Optional — receives PID of the spawned legendary process
407 * (which itself runs the game via Wine/Proton); use this
408 * to waitpid / kill the Epic launch from the caller.
409 * Pass nullptr to ignore.
410 * @return True if launch initiated (legendary was spawned successfully)
411 *
412 * Forks + execvp of the legendary binary directly — no shell. Caller is
413 * responsible for reaping the child if they want the exit status; a
414 * non-reaping caller just leaks the zombie until process exit, which is
415 * fine for a launcher.
416 */
417 bool launchGame(const std::string& appName, const std::vector<std::string>& additionalArgs = {},
418 bool offline = false, pid_t* outPid = nullptr);
419
420 /**
421 * @brief Get launch command for a game
422 * @param appName App name/ID
423 * @param additionalArgs Additional arguments
424 * @param offline Offline mode
425 * @return Launch command string
426 */
427 std::string getLaunchCommand(const std::string& appName,
428 const std::vector<std::string>& additionalArgs = {},
429 bool offline = false) const;
430
431 // ==========================================================================
432 // Configuration
433 // ==========================================================================
434
435 /**
436 * @brief Set default installation directory
437 * @param path Default install path
438 */
439 void setDefaultInstallPath(const std::filesystem::path& path);
440
441 /**
442 * @brief Get default installation directory
443 */
444 std::filesystem::path getDefaultInstallPath() const;
445
446 /**
447 * @brief Set maximum download workers
448 * @param workers Number of parallel downloads
449 */
450 void setMaxWorkers(int workers);
451
452 /**
453 * @brief Enable/disable automatic cloud save sync
454 * @param enabled Whether to auto-sync
455 */
456 void setAutoSyncSaves(bool enabled);
457
458 /**
459 * @brief Cancel ongoing operation
460 */
461 void cancelOperation();
462
463 private:
464 struct Impl;
465 std::shared_ptr<Impl> impl_;
466
467 // Internal helpers
468 std::string runLegendary(const std::vector<std::string>& args, int timeoutSec = 30) const;
469 bool runLegendaryInteractive(const std::vector<std::string>& args,
470 const ProgressCallback& callback, std::atomic<bool>& cancelled);
471 void parseLibraryOutput(const std::string& output);
472 void parseInstalledOutput(const std::string& output);
473 EpicGameInfo parseGameJson(const std::string& jsonStr) const;
474};
Complete representation of a game in the library.
Definition game.h:767
std::vector< EpicGameInfo > getInstalledGames() const
Get all installed games.
bool syncCloudSaves(const std::string &appName)
Sync saves (download if newer, upload if local is newer).
std::filesystem::path getDefaultInstallPath() const
Get default installation directory.
std::vector< EpicGameInfo > getLibrary(bool forceRefresh=false)
Get all games in Epic library.
bool installGame(const std::string &appName, const std::filesystem::path &installPath={}, const ProgressCallback &progressCallback=nullptr)
Install a game.
bool moveGame(const std::string &appName, const std::filesystem::path &newPath, const ProgressCallback &progressCallback=nullptr)
Move game to different location.
void authenticate(const AuthCallback &callback=nullptr)
Start authentication flow.
std::optional< EpicGameInfo > getGameInfo(const std::string &appName) const
Get info for a specific game.
std::function< void(bool success, const std::string &message)> AuthCallback
std::vector< EpicGameInfo > getAvailableDLC(const std::string &appName)
Get available DLC for a game.
static bool isAvailable()
Check if Legendary CLI is installed.
void cancelOperation()
Cancel ongoing operation.
bool launchGame(const std::string &appName, const std::vector< std::string > &additionalArgs={}, bool offline=false, pid_t *outPid=nullptr)
Launch a game.
std::future< bool > installGameAsync(const std::string &appName, const std::filesystem::path &installPath={}, const ProgressCallback &progressCallback=nullptr)
Install a game asynchronously.
bool installDLC(const std::string &dlcAppName, const ProgressCallback &progressCallback=nullptr)
Install DLC for a game.
bool uploadCloudSaves(const std::string &appName, bool force=false)
Upload local saves to cloud.
EpicAuthStatus getAuthStatus() const
Check authentication status.
void setAutoSyncSaves(bool enabled)
Enable/disable automatic cloud save sync.
EpicCloudSaveInfo getCloudSaveStatus(const std::string &appName) const
Get cloud save status for a game.
bool repairGame(const std::string &appName, const ProgressCallback &progressCallback=nullptr)
Repair game (verify and redownload corrupt files).
bool updateGame(const std::string &appName, const ProgressCallback &progressCallback=nullptr)
Update a game.
bool importGame(const std::string &appName, const std::filesystem::path &existingPath)
Import an existing game installation.
bool uninstallGame(const std::string &appName, bool keepFiles=false)
Uninstall a game.
std::function< void(const LegendaryProgress &)> ProgressCallback
std::string getLaunchCommand(const std::string &appName, const std::vector< std::string > &additionalArgs={}, bool offline=false) const
Get launch command for a game.
void setDefaultInstallPath(const std::filesystem::path &path)
Set default installation directory.
bool downloadCloudSaves(const std::string &appName, bool force=false)
Download cloud saves for a game.
static std::string getVersion()
Get Legendary version.
bool isAuthenticated() const
Check if user is authenticated.
bool verifyGame(const std::string &appName, const ProgressCallback &progressCallback=nullptr)
Verify game files.
Game toGame(const EpicGameInfo &epicGame) const
Convert Epic game to generic Game object.
static std::filesystem::path getLegendaryPath()
Get path to Legendary executable.
int syncLibrary()
Sync Epic library with game database.
void logout()
Log out and clear credentials.
void authenticateWithCode(const std::string &authCode, const AuthCallback &callback=nullptr)
Start authentication with authorization code.
void setMaxWorkers(int workers)
Set maximum download workers.
int progressCallback(void *userp, curl_off_t dltotal, curl_off_t, curl_off_t, curl_off_t)
Epic Games authentication status.
std::chrono::system_clock::time_point tokenExpiry
Information about cloud saves for an Epic game.
std::filesystem::path localPath
std::chrono::system_clock::time_point localModified
std::chrono::system_clock::time_point cloudModified
Information about an Epic Games Store game.
std::string appName
Internal app identifier.
std::string publisher
Publisher name.
std::string developer
Developer name.
int64_t installSize
Installed size in bytes.
std::string appTitle
Display title.
std::string getFormattedDownloadSize() const
std::string baseGameAppName
Parent game if this is DLC.
std::string thumbnailUrl
Thumbnail URL.
std::vector< std::string > platforms
Available platforms (Windows, Mac).
std::string coverUrl
Cover image URL.
std::vector< std::string > dlcAppNames
DLC for this game.
std::string getFormattedInstallSize() const
std::filesystem::path installPath
std::string version
Installed/available version.
int64_t downloadSize
Download size in bytes.
Progress information for Legendary operations.
std::string getStateStr() const