45 std::vector<const Game*> filteredCopy;
49 std::lock_guard<std::mutex> lock(
mutex_);
53 auto allGames =
library_->getAllGames();
56 for (
const Game* game : allGames)
74 callbackCopy(filteredCopy);
86 std::string nameLower = game->
name;
88 std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(),
89 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
90 std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(),
91 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
93 if (nameLower.find(queryLower) == std::string::npos)
129 if (std::find(collections.begin(), collections.end(),
171 auto comparator = [
this](
const Game* a,
const Game* b) ->
bool
178 cmp = a->
name.compare(b->name);
197 cmp =
static_cast<int>(a->
status) -
static_cast<int>(b->status);
232 std::lock_guard<std::mutex> lock(impl_->mutex_);
233 impl_->library_->loadFromDisk();
234 event.gameCount = impl_->library_->getAllGames().size();
235 callbackCopy = impl_->onLibraryLoaded_;
241 impl_->refreshFilteredList();
251 std::lock_guard<std::mutex> lock(impl_->mutex_);
252 impl_->library_->saveToDisk();
257 std::lock_guard<std::mutex> lock(impl_->mutex_);
258 return impl_->library_->getAllGames().size();
268 std::lock_guard<std::mutex> lock(impl_->mutex_);
269 auto result = impl_->library_->getGame(gameId);
270 return result.has_value() ? *result :
nullptr;
276 std::lock_guard<std::mutex> lock(impl_->mutex_);
277 auto result = impl_->library_->getGame(gameId);
278 return result.has_value() ? *result :
nullptr;
282 const std::function<
void(
Game&)>& updater)
284 std::lock_guard<std::mutex> lock(impl_->mutex_);
285 auto result = impl_->library_->getGame(gameId);
286 if (result.has_value())
298 std::string gameName = game.
name;
301 std::lock_guard<std::mutex> lock(impl_->mutex_);
302 gameId = impl_->library_->addGame(game);
303 callbackCopy = impl_->onGameAdded_;
308 impl_->refreshFilteredList();
314 event.gameName = gameName;
328 std::lock_guard<std::mutex> lock(impl_->mutex_);
329 success = impl_->library_->updateGame(gameId, updatedGame);
330 callbackCopy = impl_->onGameUpdated_;
335 impl_->refreshFilteredList();
352 std::string gameName;
357 std::lock_guard<std::mutex> lock(impl_->mutex_);
359 auto result = impl_->library_->getGame(gameId);
360 if (result.has_value())
362 gameName = (*result)->name;
364 success = impl_->library_->removeGame(gameId);
365 callbackCopy = impl_->onGameRemoved_;
370 impl_->refreshFilteredList();
376 event.gameName = gameName;
387 const std::string& newName)
391 std::lock_guard<std::mutex> lock(impl_->mutex_);
392 auto result = impl_->library_->getGame(sourceGameId);
393 if (!result.has_value())
399 newGame.
name = newName;
412 std::lock_guard<std::mutex> lock(impl_->mutex_);
413 impl_->filterOptions_ = options;
415 impl_->refreshFilteredList();
420 std::lock_guard<std::mutex> lock(impl_->mutex_);
421 return impl_->filterOptions_;
427 std::lock_guard<std::mutex> lock(impl_->mutex_);
428 impl_->sortOptions_ = options;
430 impl_->refreshFilteredList();
435 std::lock_guard<std::mutex> lock(impl_->mutex_);
436 return impl_->sortOptions_;
441 std::lock_guard<std::mutex> lock(impl_->mutex_);
442 return impl_->filteredGames_;
447 impl_->refreshFilteredList();
456 std::lock_guard<std::mutex> lock(impl_->mutex_);
457 return impl_->library_->getCollectionNames();
462 std::lock_guard<std::mutex> lock(impl_->mutex_);
463 impl_->library_->createCollection(name);
469 std::lock_guard<std::mutex> lock(impl_->mutex_);
470 impl_->library_->deleteCollection(name);
483 const std::string& collection)
489 std::lock_guard<std::mutex> lock(impl_->mutex_);
490 auto result = impl_->library_->getGame(gameId);
491 if (result.has_value())
493 Game* game = *result;
495 if (std::find(collections.begin(), collections.end(), collection) == collections.end())
497 impl_->library_->addGameToCollection(gameId, collection);
499 callbackCopy = impl_->onGameUpdated_;
507 impl_->refreshFilteredList();
513 event.fieldChanged =
"collections";
522 const std::string& collection)
525 bool removed =
false;
528 std::lock_guard<std::mutex> lock(impl_->mutex_);
529 auto result = impl_->library_->getGame(gameId);
530 if (result.has_value())
532 Game* game = *result;
534 auto it = std::find(collections.begin(), collections.end(), collection);
535 if (it != collections.end())
537 impl_->library_->removeGameFromCollection(gameId, collection);
539 callbackCopy = impl_->onGameUpdated_;
547 impl_->refreshFilteredList();
553 event.fieldChanged =
"collections";
571 std::lock_guard<std::mutex> lock(impl_->mutex_);
572 auto result = impl_->library_->getGame(gameId);
573 if (result.has_value())
575 Game* game = *result;
578 impl_->library_->updateGame(game->
id, *game);
580 callbackCopy = impl_->onGameUpdated_;
586 impl_->refreshFilteredList();
592 event.fieldChanged =
"isFavorite";
600 std::lock_guard<std::mutex> lock(impl_->mutex_);
601 auto result = impl_->library_->getGame(gameId);
602 if (result.has_value())
604 return (*result)->isFavorite;
615 std::lock_guard<std::mutex> lock(impl_->mutex_);
616 return impl_->library_->getAllGames();
621 std::lock_guard<std::mutex> lock(impl_->mutex_);
622 auto games = impl_->library_->getRecentlyPlayed(count);
623 std::vector<const Game*> result;
624 result.reserve(games.size());
625 for (
const Game* game : games)
627 result.push_back(game);
635 std::lock_guard<std::mutex> lock(impl_->mutex_);
636 return impl_->library_->getRecentSessions(gameId, limit);
641 std::lock_guard<std::mutex> lock(impl_->mutex_);
642 auto games = impl_->library_->getGamesByPlatform(
platform);
643 std::vector<const Game*> result;
644 result.reserve(games.size());
645 for (
const Game* game : games)
647 result.push_back(game);
654 std::lock_guard<std::mutex> lock(impl_->mutex_);
655 std::vector<const Game*> result;
656 for (
const Game* game : impl_->library_->getAllGames())
658 if (game->runner == runner)
660 result.push_back(game);
668 std::lock_guard<std::mutex> lock(impl_->mutex_);
669 auto games = impl_->library_->searchGames(query);
670 std::vector<const Game*> result;
671 result.reserve(games.size());
672 for (
const Game* game : games)
674 result.push_back(game);
688 return impl_->library_->discoverMissingImages();
693 return impl_->library_->discoverImagesForGame(gameId);
698 return impl_->library_->refreshStaleImages();
707 std::lock_guard<std::mutex> lock(impl_->mutex_);
708 impl_->onGameAdded_ = std::move(callback);
713 std::lock_guard<std::mutex> lock(impl_->mutex_);
714 impl_->onGameRemoved_ = std::move(callback);
719 std::lock_guard<std::mutex> lock(impl_->mutex_);
720 impl_->onGameUpdated_ = std::move(callback);
725 std::lock_guard<std::mutex> lock(impl_->mutex_);
726 impl_->onLibraryLoaded_ = std::move(callback);
731 std::lock_guard<std::mutex> lock(impl_->mutex_);
732 impl_->onFilteredListChanged_ = std::move(callback);
Central database for managing all games in the launcher.
Complete representation of a game in the library.
GameMetadata metadata
Descriptive information and media.
std::vector< std::string > collections
Collections this game belongs to.
bool isFavorite
Is this marked as a favorite game?
std::string name
Display name shown in UI.
std::string id
Unique identifier (auto-generated or user-specified).
GameStatistics statistics
Play statistics and usage tracking.
GameRunner runner
Runner/compatibility layer to use (Native, Proton, Wine, etc.).
GameStatus status
Current installation and execution status.
GameSource source
Where the game was acquired from (Steam, GOG, Local, etc.).
OnGameRemoved onGameRemoved_
FilterOptions filterOptions_
bool passesFilter(const Game *game) const
std::vector< const Game * > filteredGames_
void refreshFilteredList()
OnFilteredListChanged onFilteredListChanged_
std::unique_ptr< GameLibrary > library_
OnLibraryLoaded onLibraryLoaded_
OnGameUpdated onGameUpdated_
void setOnGameRemoved(OnGameRemoved callback)
bool updateGame(const std::string &gameId, const Game &updatedGame)
Update an existing game Returns true on success.
std::vector< PlaySession > getRecentSessions(const std::string &gameId, int limit=20) const
Get recent play sessions for a game from the database.
void setOnFilteredListChanged(OnFilteredListChanged callback)
std::string addGame(const Game &game)
Add a new game to the library Returns the assigned game ID, or empty string on failure.
std::vector< const Game * > getGamesByRunner(GameRunner runner) const
Get games by runner.
std::string duplicateGame(const std::string &sourceGameId, const std::string &newName)
Duplicate a game with a new name Returns the new game's ID, or empty string on failure.
std::vector< std::string > getCollections() const
Get all collection names.
int discoverMissingImages()
Discover and update image paths for games that are missing cover art This should be called in a backg...
bool removeGame(const std::string &gameId)
Remove a game from the library Returns true on success.
bool discoverImagesForGame(const std::string &gameId)
Discover images for a specific game (by Steam App ID) Returns true if images were found and updated.
FilterOptions getFilter() const
Get current filter options (returns copy for thread safety).
void refreshFilteredList()
Force refresh of filtered list (e.g., after external game state change).
const Game * getGame(const std::string &gameId) const
Get a game by ID (returns nullptr if not found).
void loadLibrary()
Load library from disk.
Game * getGameForEdit(const std::string &gameId)
Get mutable game for editing (returns nullptr if not found).
bool removeGameFromCollection(const std::string &gameId, const std::string &collection)
Remove a game from a collection.
std::vector< const Game * > searchGames(const std::string &query) const
Search games by name (substring match).
bool addCollection(const std::string &name)
Add a new collection.
void setSort(const SortOptions &options)
Set sort options and refresh filtered list.
void toggleFavorite(const std::string &gameId)
Toggle favorite status.
std::function< void(const GameRemovedEvent &)> OnGameRemoved
void setOnGameAdded(OnGameAdded callback)
void setFilter(const FilterOptions &options)
Set filter options and refresh filtered list.
bool renameCollection(const std::string &oldName, const std::string &newName)
Rename a collection.
std::vector< const Game * > getFilteredGames() const
Get the currently filtered and sorted game list (returns copy for thread safety).
std::function< void(const GameUpdatedEvent &)> OnGameUpdated
void executeWithGame(const std::string &gameId, const std::function< void(Game &)> &updater)
Execute an update function on a game while holding the library's internal lock.
void saveLibrary()
Save library to disk.
std::vector< Game * > getAllGames()
Get all games (non-const for process tracking).
std::function< void(const GameAddedEvent &)> OnGameAdded
size_t getGameCount() const
Get total game count.
std::vector< const Game * > getRecentlyPlayed(int count=10) const
Get recently played games.
bool removeCollection(const std::string &name)
Remove a collection.
std::function< void(const LibraryLoadedEvent &)> OnLibraryLoaded
std::function< void(const std::vector< const Game * > &)> OnFilteredListChanged
void setOnLibraryLoaded(OnLibraryLoaded callback)
int refreshStaleImages()
Refresh images for games with stale/missing image files Checks if stored paths still exist and re-dis...
SortOptions getSort() const
Get current sort options (returns copy for thread safety).
bool addGameToCollection(const std::string &gameId, const std::string &collection)
Add a game to a collection.
void setOnGameUpdated(OnGameUpdated callback)
std::vector< const Game * > getGamesByPlatform(GamePlatform platform) const
Get games by platform.
bool isFavorite(const std::string &gameId) const
Check if a game is favorited.
GamePlatform
Platform/runner type for executing the game.
@ Running
Game is currently running.
@ Installed
Game is installed and ready to play.
GameRunner
Runner/compatibility layer for executing the game.
Play statistics and usage tracking for a game.
double totalPlayTimeSeconds
Total play time in seconds (for all sessions).
time_t lastPlayed
Unix timestamp of last play session.
time_t dateAdded
Unix timestamp when added to library.