game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
store_integration_controller.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// store_integration_controller.cpp
4// ==============================================================================
5// Controller for multi-store integration implementation
6// ==============================================================================
7
9
14
15#include <mutex>
16
17namespace core
18{
19
20// ==============================================================================
21// Helper Functions
22// ==============================================================================
23
24std::string storeTypeName(StoreType type)
25{
26 switch (type)
27 {
29 return "Steam";
30 case StoreType::GOG:
31 return "GOG";
32 case StoreType::Epic:
33 return "Epic Games";
35 return "Lutris";
37 return "Manual";
38 default:
39 return "Unknown";
40 }
41}
42
43// ==============================================================================
44// Implementation
45// ==============================================================================
46
48{
49 public:
50 // Services
51 std::unique_ptr<GOGIntegration> gogIntegration;
52 std::unique_ptr<LegendaryIntegration> legendaryIntegration;
53 std::unique_ptr<CloudSaveService> cloudSaveService;
54 std::unique_ptr<WineDependencyManager> dependencyManager;
55
56 // Callbacks
60
61 // State
62 std::atomic<bool> cancelRequested{false};
63 mutable std::mutex mutex;
64
66 {
67 gogIntegration = std::make_unique<GOGIntegration>();
68 legendaryIntegration = std::make_unique<LegendaryIntegration>();
69 cloudSaveService = std::make_unique<CloudSaveService>();
70 dependencyManager = std::make_unique<WineDependencyManager>();
71 }
72};
73
75
77
79 default;
81StoreIntegrationController::operator=(StoreIntegrationController&&) noexcept = default;
82
83// ==============================================================================
84// Store Status
85// ==============================================================================
86
88{
89 std::vector<StoreStatus> statuses;
90
91 // GOG
92 statuses.push_back(getStoreStatus(StoreType::GOG));
93
94 // Epic
95 statuses.push_back(getStoreStatus(StoreType::Epic));
96
97 return statuses;
98}
99
101{
102 StoreStatus status;
103 status.type = store;
104
105 switch (store)
106 {
107 case StoreType::GOG:
108 {
109 status.isAvailable = impl_->gogIntegration->isAvailable();
110 if (status.isAvailable)
111 {
112 auto auth = impl_->gogIntegration->getAuthStatus();
113 status.isAuthenticated = auth.isAuthenticated;
114 status.username = auth.username;
115 if (status.isAuthenticated)
116 {
117 status.gameCount = static_cast<int>(impl_->gogIntegration->getLibrary().size());
118 }
119 }
120 break;
121 }
122 case StoreType::Epic:
123 {
124 status.isAvailable = impl_->legendaryIntegration->isAvailable();
125 if (status.isAvailable)
126 {
127 auto auth = impl_->legendaryIntegration->getAuthStatus();
128 status.isAuthenticated = auth.isAuthenticated;
129 status.username = auth.displayName;
130 if (status.isAuthenticated)
131 {
132 status.gameCount =
133 static_cast<int>(impl_->legendaryIntegration->getLibrary().size());
134 }
135 }
136 break;
137 }
138 default:
139 break;
140 }
141
142 return status;
143}
144
149
154
155// ==============================================================================
156// GOG Integration
157// ==============================================================================
158
160{
161 return impl_->gogIntegration->isAvailable();
162}
163
165{
166 return impl_->gogIntegration->getAuthStatus();
167}
168
170 const std::function<void(bool success, const std::string& message)>& callback)
171{
172 impl_->gogIntegration->authenticate(callback);
173}
174
176{
177 impl_->gogIntegration->logout();
178}
179
180std::vector<GOGGameInfo> StoreIntegrationController::getGOGLibrary(bool forceRefresh)
181{
182 return impl_->gogIntegration->getLibrary(forceRefresh);
183}
184
186{
187 return impl_->gogIntegration->getInstalledGames();
188}
189
190std::future<bool>
192 const std::string& installPath,
193 const ProgressCallback& progressCallback)
194{
195 return impl_->gogIntegration->installGameAsync(
196 gameId, installPath.empty() ? std::filesystem::path{} : std::filesystem::path(installPath),
197 "",
198 [progressCallback](const GOGProgress& p)
199 {
200 if (progressCallback)
201 {
202 progressCallback(p.percentComplete, p.getStateStr());
203 }
204 });
205}
206
207bool StoreIntegrationController::uninstallGOGGame(const std::string& gameId)
208{
209 return impl_->gogIntegration->uninstallGame(gameId);
210}
211
213{
214 int count = impl_->gogIntegration->syncLibrary();
215
217 {
218 std::lock_guard<std::mutex> lock(impl_->mutex);
219 cb = impl_->onStoreSyncComplete;
220 }
221 if (cb)
222 {
223 StoreSyncEvent event;
224 event.store = StoreType::GOG;
225 event.gamesAdded = count;
226 event.success = true;
227 cb(event);
228 }
229
230 return count;
231}
232
234{
235 // This would need integration with GameLibraryController
236 // For now, just sync the library
237 return syncGOGLibrary();
238}
239
240// ==============================================================================
241// Epic Games Integration
242// ==============================================================================
243
245{
246 return impl_->legendaryIntegration->isAvailable();
247}
248
250{
251 return impl_->legendaryIntegration->getAuthStatus();
252}
253
255 const std::function<void(bool success, const std::string& message)>& callback)
256{
257 impl_->legendaryIntegration->authenticate(callback);
258}
259
261{
262 impl_->legendaryIntegration->logout();
263}
264
265std::vector<EpicGameInfo> StoreIntegrationController::getEpicLibrary(bool forceRefresh)
266{
267 return impl_->legendaryIntegration->getLibrary(forceRefresh);
268}
269
271{
272 return impl_->legendaryIntegration->getInstalledGames();
273}
274
275std::future<bool>
277 const std::string& installPath,
278 const ProgressCallback& progressCallback)
279{
280 return impl_->legendaryIntegration->installGameAsync(
281 appName, installPath.empty() ? std::filesystem::path{} : std::filesystem::path(installPath),
282 [progressCallback](const LegendaryProgress& p)
283 {
284 if (progressCallback)
285 {
286 progressCallback(p.percentComplete, p.getStateStr());
287 }
288 });
289}
290
291bool StoreIntegrationController::uninstallEpicGame(const std::string& appName)
292{
293 return impl_->legendaryIntegration->uninstallGame(appName);
294}
295
297{
298 int count = impl_->legendaryIntegration->syncLibrary();
299
301 {
302 std::lock_guard<std::mutex> lock(impl_->mutex);
303 cb = impl_->onStoreSyncComplete;
304 }
305 if (cb)
306 {
307 StoreSyncEvent event;
308 event.store = StoreType::Epic;
309 event.gamesAdded = count;
310 event.success = true;
311 cb(event);
312 }
313
314 return count;
315}
316
321
322// ==============================================================================
323// Cloud Save Management
324// ==============================================================================
325
327{
328 return impl_->cloudSaveService->registerSaveLocation(location);
329}
330
331std::vector<SaveLocation> StoreIntegrationController::getSaveLocations() const
332{
333 return impl_->cloudSaveService->getSaveLocations();
334}
335
336std::optional<SaveLocation>
337StoreIntegrationController::getSaveLocation(const std::string& gameId) const
338{
339 return impl_->cloudSaveService->getSaveLocation(gameId);
340}
341
342std::vector<SaveLocation>
344 const std::string& prefixPath) const
345{
346 return impl_->cloudSaveService->detectSaveLocation(
347 gameName, prefixPath.empty() ? std::filesystem::path{} : std::filesystem::path(prefixPath));
348}
349
350std::optional<std::string>
352 const std::string& description)
353{
354 auto result = impl_->cloudSaveService->createSnapshot(gameId, description);
355
356 if (result)
357 {
359 {
360 std::lock_guard<std::mutex> lock(impl_->mutex);
361 cb = impl_->onCloudSaveEvent;
362 }
363 if (cb)
364 {
365 CloudSaveEvent event;
366 event.gameId = gameId;
368 event.message = "Snapshot created: " + *result;
369 cb(event);
370 }
371 }
372
373 return result;
374}
375
376std::vector<SaveSnapshot>
377StoreIntegrationController::getSaveSnapshots(const std::string& gameId) const
378{
379 return impl_->cloudSaveService->getSnapshots(gameId);
380}
381
382bool StoreIntegrationController::restoreSaveSnapshot(const std::string& snapshotId,
383 bool backupCurrent)
384{
385 return impl_->cloudSaveService->restoreSnapshot(snapshotId, backupCurrent);
386}
387
388bool StoreIntegrationController::deleteSaveSnapshot(const std::string& snapshotId)
389{
390 return impl_->cloudSaveService->deleteSnapshot(snapshotId);
391}
392
393std::future<bool> StoreIntegrationController::syncSaves(const std::string& gameId,
394 SyncDirection direction,
395 const ProgressCallback& progressCallback)
396{
397 return impl_->cloudSaveService->syncSavesAsync(
398 gameId, direction,
399 [this, gameId, progressCallback](const SyncStatus& status)
400 {
401 if (progressCallback)
402 {
403 progressCallback(status.percentComplete, status.getStateStr());
404 }
405
407 {
408 std::lock_guard<std::mutex> lock(impl_->mutex);
409 cb = impl_->onCloudSaveEvent;
410 }
411 if (cb)
412 {
413 CloudSaveEvent event;
414 event.gameId = gameId;
415
416 switch (status.state)
417 {
423 break;
426 break;
429 break;
430 default:
431 return;
432 }
433
434 event.message = status.getStateStr();
435 cb(event);
436 }
437 },
438 nullptr); // No conflict callback for now
439}
440
441bool StoreIntegrationController::needsSaveSync(const std::string& gameId) const
442{
443 return impl_->cloudSaveService->needsSync(gameId);
444}
445
446void StoreIntegrationController::setAutoSync(const std::string& gameId, bool enabled)
447{
448 impl_->cloudSaveService->setAutoSync(gameId, enabled);
449}
450
451void StoreIntegrationController::onGameLaunch(const std::string& gameId)
452{
453 impl_->cloudSaveService->onGameLaunch(gameId);
454}
455
456void StoreIntegrationController::onGameExit(const std::string& gameId)
457{
458 impl_->cloudSaveService->onGameExit(gameId);
459}
460
462{
463 impl_->cloudSaveService->setCustomSyncDirectory(std::filesystem::path(path));
464}
465
467{
468 return impl_->cloudSaveService->getTotalBackupSize();
469}
470
471// ==============================================================================
472// Wine Dependency Management
473// ==============================================================================
474
479
484
485std::vector<WineDependency> StoreIntegrationController::getAllDependencies() const
486{
487 return impl_->dependencyManager->getAllDependencies();
488}
489
490std::vector<WineDependency>
492{
493 return impl_->dependencyManager->getDependenciesByCategory(category);
494}
495
496std::vector<WineDependency>
498{
499 return impl_->dependencyManager->searchDependencies(query);
500}
501
503{
504 return impl_->dependencyManager->getRecommendedDependencies();
505}
506
508StoreIntegrationController::scanPrefixDependencies(const std::string& prefixPath) const
509{
510 return impl_->dependencyManager->scanPrefix(std::filesystem::path(prefixPath));
511}
512
513bool StoreIntegrationController::isDependencyInstalled(const std::string& prefixPath,
514 const std::string& verbId) const
515{
516 return impl_->dependencyManager->isDependencyInstalled(std::filesystem::path(prefixPath),
517 verbId);
518}
519
520std::future<bool>
522 const std::string& verbId,
523 const ProgressCallback& progressCallback)
524{
525 return impl_->dependencyManager->installDependencyAsync(
526 std::filesystem::path(prefixPath), verbId,
527 [this, prefixPath, verbId, progressCallback](const DependencyInstallProgress& p)
528 {
529 if (progressCallback)
530 {
531 progressCallback(p.percentComplete, p.getStateStr());
532 }
533
535 {
536 std::lock_guard<std::mutex> lock(impl_->mutex);
537 cb = impl_->onDependencyEvent;
538 }
539 if (cb)
540 {
541 DependencyEvent event;
542 event.prefixPath = prefixPath;
543 event.verbId = verbId;
544 event.progressPercent = p.percentComplete;
545 event.message = p.currentStep;
546
547 switch (p.state)
548 {
555 break;
558 break;
562 event.message = p.errorMessage;
563 break;
564 }
565
566 cb(event);
567 }
568 });
569}
570
571std::future<int>
573 const std::vector<std::string>& verbIds,
574 const ProgressCallback& progressCallback)
575{
576 return std::async(std::launch::async,
577 [this, prefixPath, verbIds, progressCallback]()
578 {
579 return impl_->dependencyManager->installDependencies(
580 std::filesystem::path(prefixPath), verbIds,
581 [progressCallback](const DependencyInstallProgress& p)
582 {
583 if (progressCallback)
584 {
585 progressCallback(p.percentComplete, p.currentStep);
586 }
587 });
588 });
589}
590
591std::future<bool>
593 const ProgressCallback& progressCallback)
594{
595 return std::async(std::launch::async,
596 [this, prefixPath, progressCallback]()
597 {
598 return impl_->dependencyManager->installGamingPreset(
599 std::filesystem::path(prefixPath),
600 [progressCallback](const DependencyInstallProgress& p)
601 {
602 if (progressCallback)
603 {
604 progressCallback(p.percentComplete, p.currentStep);
605 }
606 });
607 });
608}
609
610std::future<bool>
612 const std::vector<std::string>& verbIds,
613 const ProgressCallback& progressCallback)
614{
615 return std::async(std::launch::async,
616 [this, steamAppId, verbIds, progressCallback]()
617 {
618 return impl_->dependencyManager->installForSteamGame(
619 steamAppId, verbIds,
620 [progressCallback](const DependencyInstallProgress& p)
621 {
622 if (progressCallback)
623 {
624 progressCallback(p.percentComplete, p.currentStep);
625 }
626 });
627 });
628}
629
630// ==============================================================================
631// Unified Operations
632// ==============================================================================
633
635{
636 impl_->cancelRequested = false;
637
638 int step = 0;
639 int totalSteps = 2; // GOG + Epic
640
641 // Sync GOG
642 if (!impl_->cancelRequested && isGOGAvailable() && isStoreAuthenticated(StoreType::GOG))
643 {
644 if (progressCallback)
645 {
646 progressCallback((step * 100) / totalSteps, "Syncing GOG library...");
647 }
649 step++;
650 }
651
652 // Sync Epic
653 if (!impl_->cancelRequested && isEpicAvailable() && isStoreAuthenticated(StoreType::Epic))
654 {
655 if (progressCallback)
656 {
657 progressCallback((step * 100) / totalSteps, "Syncing Epic library...");
658 }
660 step++;
661 }
662
663 if (progressCallback)
664 {
665 progressCallback(100, "Sync complete");
666 }
667}
668
669std::vector<StoreIntegrationController::UnifiedGameInfo>
671{
672 std::vector<UnifiedGameInfo> games;
673
674 // Add GOG games
675 if (isGOGAvailable())
676 {
677 for (const auto& gogGame : impl_->gogIntegration->getLibrary())
678 {
679 UnifiedGameInfo info;
680 info.id = "gog_" + gogGame.gameId;
681 info.name = gogGame.title;
682 info.store = StoreType::GOG;
683 info.isInstalled = gogGame.isInstalled;
684 info.installPath = gogGame.installPath.string();
685 info.coverUrl = gogGame.coverUrl;
686 games.push_back(info);
687 }
688 }
689
690 // Add Epic games
691 if (isEpicAvailable())
692 {
693 for (const auto& epicGame : impl_->legendaryIntegration->getLibrary())
694 {
695 UnifiedGameInfo info;
696 info.id = "epic_" + epicGame.appName;
697 info.name = epicGame.appTitle;
698 info.store = StoreType::Epic;
699 info.isInstalled = epicGame.isInstalled;
700 info.installPath = epicGame.installPath.string();
701 info.coverUrl = epicGame.coverUrl;
702 games.push_back(info);
703 }
704 }
705
706 return games;
707}
708
709std::vector<StoreIntegrationController::UnifiedGameInfo>
711{
712 std::vector<UnifiedGameInfo> gamesWithUpdates;
713
714 // Check GOG updates
715 if (isGOGAvailable())
716 {
717 for (const auto& gogGame : impl_->gogIntegration->getInstalledGames())
718 {
719 if (impl_->gogIntegration->hasUpdate(gogGame.gameId))
720 {
721 UnifiedGameInfo info;
722 info.id = "gog_" + gogGame.gameId;
723 info.name = gogGame.title;
724 info.store = StoreType::GOG;
725 info.hasUpdate = true;
726 gamesWithUpdates.push_back(info);
727 }
728 }
729 }
730
731 // Check Epic updates
732 // Note: Legendary doesn't have a direct hasUpdate method
733 // Updates are detected during sync - for now just return GOG updates
734 // Epic update checking would require running "legendary list --check-updates"
735
736 return gamesWithUpdates;
737}
738
739// ==============================================================================
740// Event Subscriptions
741// ==============================================================================
742
744{
745 std::lock_guard<std::mutex> lock(impl_->mutex);
746 impl_->onStoreSyncComplete = std::move(callback);
747}
748
750{
751 std::lock_guard<std::mutex> lock(impl_->mutex);
752 impl_->onCloudSaveEvent = std::move(callback);
753}
754
756{
757 std::lock_guard<std::mutex> lock(impl_->mutex);
758 impl_->onDependencyEvent = std::move(callback);
759}
760
761// ==============================================================================
762// Cancellation
763// ==============================================================================
764
766{
767 impl_->cancelRequested = true;
768 impl_->gogIntegration->cancelOperation();
769 impl_->legendaryIntegration->cancelOperation();
770 impl_->cloudSaveService->cancelOperation();
771 impl_->dependencyManager->cancelOperation();
772}
773
774} // namespace core
static bool isProtontricksAvailable()
Check if protontricks is available.
static bool isWinetricksAvailable()
Check if winetricks is available.
std::unique_ptr< LegendaryIntegration > legendaryIntegration
std::unique_ptr< WineDependencyManager > dependencyManager
std::unique_ptr< CloudSaveService > cloudSaveService
void syncAllStores(const ProgressCallback &progressCallback=nullptr)
Sync all stores (GOG, Epic, etc.).
bool isEpicAvailable() const
Check if Epic/Legendary is available.
EpicAuthStatus getEpicAuthStatus() const
Get Epic authentication status.
GOGAuthStatus getGOGAuthStatus() const
Get GOG authentication status.
std::vector< EpicGameInfo > getEpicLibrary(bool forceRefresh=false)
Get all Epic library games.
std::vector< UnifiedGameInfo > getAllStoreGames() const
bool isDependencyInstalled(const std::string &prefixPath, const std::string &verbId) const
Check if a dependency is installed in a prefix.
void cancelOperation()
Cancel any ongoing operation.
std::future< bool > installEpicGame(const std::string &appName, const std::string &installPath="", const ProgressCallback &progressCallback=nullptr)
Install an Epic game.
int importEpicGames()
Import Epic games to main library.
std::vector< EpicGameInfo > getInstalledEpicGames() const
Get installed Epic games.
bool isWinetricksAvailable() const
Check if winetricks is available.
std::future< int > installDependencies(const std::string &prefixPath, const std::vector< std::string > &verbIds, const ProgressCallback &progressCallback=nullptr)
Install multiple dependencies.
bool restoreSaveSnapshot(const std::string &snapshotId, bool backupCurrent=true)
Restore saves from a snapshot.
PrefixDependencyStatus scanPrefixDependencies(const std::string &prefixPath) const
Scan a Wine prefix for installed dependencies.
bool isStoreAuthenticated(StoreType store) const
Check if authenticated to a store.
void setOnCloudSaveEvent(OnCloudSaveEvent callback)
std::vector< SaveLocation > getSaveLocations() const
Get all registered save locations.
void setAutoSync(const std::string &gameId, bool enabled)
Enable/disable auto-sync for a game.
std::vector< UnifiedGameInfo > checkAllUpdates() const
Check for updates across all stores.
int syncGOGLibrary()
Sync GOG library to game database.
std::future< bool > installForSteamGame(uint32_t steamAppId, const std::vector< std::string > &verbIds, const ProgressCallback &progressCallback=nullptr)
Install dependencies for a Steam/Proton game.
std::vector< GOGGameInfo > getGOGLibrary(bool forceRefresh=false)
Get all GOG library games.
std::vector< WineDependency > getAllDependencies() const
Get all available dependencies.
void setOnDependencyEvent(OnDependencyEvent callback)
void authenticateGOG(const std::function< void(bool success, const std::string &message)> &callback)
Start GOG authentication flow.
bool deleteSaveSnapshot(const std::string &snapshotId)
Delete a snapshot.
void authenticateEpic(const std::function< void(bool success, const std::string &message)> &callback)
Start Epic authentication flow.
std::function< void(const CloudSaveEvent &)> OnCloudSaveEvent
void setCloudSyncDirectory(const std::string &path)
Set custom sync directory (e.g., Syncthing folder).
bool needsSaveSync(const std::string &gameId) const
Check if sync is needed.
bool registerSaveLocation(const SaveLocation &location)
Register a game's save location.
int64_t getTotalBackupSize() const
Get total backup size.
std::vector< GOGGameInfo > getInstalledGOGGames() const
Get installed GOG games.
std::function< void(const StoreSyncEvent &)> OnStoreSyncComplete
std::function< void(int percent, const std::string &status)> ProgressCallback
void onGameExit(const std::string &gameId)
Called when game exits (for auto-sync).
std::future< bool > installDependency(const std::string &prefixPath, const std::string &verbId, const ProgressCallback &progressCallback=nullptr)
Install a dependency.
std::vector< SaveSnapshot > getSaveSnapshots(const std::string &gameId) const
Get all snapshots for a game.
std::vector< SaveLocation > detectSaveLocations(const std::string &gameName, const std::string &prefixPath="") const
Detect save locations for a game.
StoreStatus getStoreStatus(StoreType store) const
Get status of a specific store.
std::future< bool > installGamingPreset(const std::string &prefixPath, const ProgressCallback &progressCallback=nullptr)
Install gaming preset (vcrun, dxvk, fonts).
void setOnStoreSyncComplete(OnStoreSyncComplete callback)
std::vector< WineDependency > searchDependencies(const std::string &query) const
Search for dependencies.
std::vector< WineDependency > getDependenciesByCategory(DependencyCategory category) const
Get dependencies by category.
bool uninstallEpicGame(const std::string &appName)
Uninstall an Epic game.
std::optional< SaveLocation > getSaveLocation(const std::string &gameId) const
Get save location for a game.
int syncEpicLibrary()
Sync Epic library to game database.
int importGOGGames()
Import GOG games to main library.
void onGameLaunch(const std::string &gameId)
Called when game launches (for auto-sync).
std::vector< std::string > getRecommendedDependencies() const
Get recommended dependencies for gaming.
bool isGOGAvailable() const
Check if GOG integration is available (Heroic or gogdl).
std::function< void(const DependencyEvent &)> OnDependencyEvent
bool isProtontricksAvailable() const
Check if protontricks is available.
std::future< bool > syncSaves(const std::string &gameId, SyncDirection direction, const ProgressCallback &progressCallback=nullptr)
Sync saves with cloud/custom directory.
std::future< bool > installGOGGame(const std::string &gameId, const std::string &installPath="", const ProgressCallback &progressCallback=nullptr)
Install a GOG game.
bool uninstallGOGGame(const std::string &gameId)
Uninstall a GOG game.
std::vector< StoreStatus > getAllStoreStatus() const
Get status of all available stores.
std::optional< std::string > createSaveSnapshot(const std::string &gameId, const std::string &description="")
Create a save snapshot (backup).
bool isStoreAvailable(StoreType store) const
Check if a store backend is available (tools installed).
SyncDirection
Direction of sync operation.
std::string storeTypeName(StoreType type)
Get human-readable store name.
Progress information during dependency installation.
std::string currentStep
Current step description.
Epic Games authentication status.
GOG Galaxy authentication status.
Progress information for GOG operations.
Progress information for Legendary operations.
Status of dependencies in a Wine prefix.
Information about a game's save location.
Status of sync operation.
std::string getStateStr() const
DependencyCategory
Categories of Wine dependencies.