|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
Central database for managing all games in the launcher. More...
#include <game_library.h>
Public Member Functions | |
| GameLibrary () | |
| Constructor - initializes library path. | |
| ~GameLibrary () | |
| Destructor - cleanup. | |
| std::string | addGame (const Game &game) |
| Add a new game to the library. | |
| void | addGameToCollection (const std::string &gameId, const std::string &collection) |
| Add a game to a collection. | |
| void | createCollection (const std::string &name) |
| Create a new empty collection. | |
| void | deleteCollection (const std::string &name) |
| Delete a collection. | |
| bool | discoverImagesForGame (const std::string &gameId) |
| Discover images for a specific game. | |
| int | discoverMissingImages () |
| Discover and update images for games missing cover art. | |
| std::vector< Game * > | getAllGames () |
| Get all games in the library. | |
| std::vector< const Game * > | getAllGames () const |
| Get all games in the library (const version). | |
| std::vector< std::string > | getCollectionNames () const |
| Get list of all collection names. | |
| std::vector< Game * > | getFavorites () |
| Get all favorite games. | |
| std::vector< const Game * > | getFavorites () const |
| Get all favorite games (const version). | |
| std::optional< Game * > | getGame (const std::string &gameId) |
| Get a game by ID. | |
| std::optional< const Game * > | getGame (const std::string &gameId) const |
| Get a game by ID (const version). | |
| std::vector< Game * > | getGamesByPlatform (GamePlatform platform) |
| Get games filtered by platform. | |
| std::vector< const Game * > | getGamesByPlatform (GamePlatform platform) const |
| Get games filtered by platform (const version). | |
| std::vector< Game * > | getGamesInCollection (const std::string &collectionName) |
| Get games in a specific collection. | |
| std::vector< const Game * > | getGamesInCollection (const std::string &collectionName) const |
| Get games in a specific collection (const version). | |
| int | getInstalledGameCount () const |
| Get number of installed games. | |
| std::vector< Game * > | getInstalledGames () |
| Get all installed games. | |
| std::vector< const Game * > | getInstalledGames () const |
| Get all installed games (const version). | |
| std::vector< Game * > | getRecentlyPlayed (int count=10) |
| Get recently played games. | |
| std::vector< const Game * > | getRecentlyPlayed (int count=10) const |
| Get recently played games (const version). | |
| std::vector< PlaySession > | getRecentSessions (const std::string &gameId, int limit=20) const |
| Get recent play sessions for a game from the database. | |
| int | getTotalGameCount () const |
| Get total number of games in library. | |
| double | getTotalPlayTime () const |
| Get total play time across all games. | |
| void | loadFromDisk () |
| Load library from disk. | |
| int | refreshStaleImages () |
| Refresh images for games with stale/missing image files. | |
| bool | removeGame (const std::string &gameId) |
| Remove a game from the library. | |
| void | removeGameFromCollection (const std::string &gameId, const std::string &collection) |
| Remove a game from a collection. | |
| void | saveToDisk () |
| Save library to disk. | |
| std::vector< Game * > | searchGames (std::string_view query) |
| Search games by name (case-insensitive substring match). | |
| std::vector< const Game * > | searchGames (std::string_view query) const |
| Search games by name (const version). | |
| bool | updateGame (const std::string &gameId, const Game &updatedGame) |
| Update an existing game. | |
Central database for managing all games in the launcher.
The GameLibrary is responsible for persistent storage and retrieval of all game data. It provides methods for CRUD operations on games, as well as powerful query capabilities for filtering and sorting.
This class is NOT thread-safe. External synchronization is required if accessed from multiple threads.
Definition at line 57 of file game_library.h.
| GameLibrary::GameLibrary | ( | ) |
Constructor - initializes library path.
Determines the platform-specific library storage location:
Definition at line 27 of file game_library.cpp.
References Logger::error().
|
default |
Destructor - cleanup.
Note: The destructor does NOT automatically save to disk. Call saveToDisk() explicitly before destruction if needed.
| std::string GameLibrary::addGame | ( | const Game & | game | ) |
Add a new game to the library.
| game | Game object to add (ID will be generated if empty) |
If the game doesn't have an ID, a unique one will be generated. The game is added to the in-memory library but NOT saved to disk until saveToDisk() is called.
Definition at line 120 of file game_library.cpp.
References GameStatistics::dateAdded, Logger::error(), GameRunnerConfig::executablePath, Game::id, Logger::info(), Game::metadata, Game::name, Game::runnerConfig, Game::source, Game::statistics, GameMetadata::steamAppId, and Logger::warn().
| void GameLibrary::addGameToCollection | ( | const std::string & | gameId, |
| const std::string & | collection ) |
Add a game to a collection.
| gameId | ID of game to add |
| collection | Name of collection |
If the game is already in the collection, this is a no-op. If the game doesn't exist, prints an error to stderr.
Definition at line 931 of file game_library.cpp.
References Game::collections, Logger::error(), getGame(), and Logger::info().
| void GameLibrary::createCollection | ( | const std::string & | name | ) |
Create a new empty collection.
| name | Name of collection to create |
Collections are user-defined groups for organizing games. If a collection with this name already exists, this is a no-op.
Definition at line 888 of file game_library.cpp.
References Logger::info().
| void GameLibrary::deleteCollection | ( | const std::string & | name | ) |
Delete a collection.
| name | Name of collection to delete |
Removes the collection from the list AND removes all games from this collection. The games themselves are not deleted, only the collection membership.
Definition at line 903 of file game_library.cpp.
References Logger::info().
| bool GameLibrary::discoverImagesForGame | ( | const std::string & | gameId | ) |
Discover images for a specific game.
| gameId | ID of game to discover images for |
Definition at line 735 of file game_library.cpp.
References Logger::debug(), SteamCDN::discoverImages(), Logger::error(), SteamPaths::getPrimarySteamRoot(), GameImagePaths::header, GameImagePaths::heroImage, GameMetadata::imagePaths, Game::metadata, Game::name, GameMetadata::steamAppId, and GameImagePaths::verticalCover.
| int GameLibrary::discoverMissingImages | ( | ) |
Discover and update images for games missing cover art.
Scans Steam's library cache for images and updates the database. Should be called in a background thread.
Definition at line 641 of file game_library.cpp.
References SteamPaths::getPrimarySteamRoot(), and Logger::info().
| std::vector< Game * > GameLibrary::getAllGames | ( | ) |
Get all games in the library.
The returned pointers remain valid until games are removed or the library is destroyed. No particular order is guaranteed.
Definition at line 332 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::getAllGames | ( | ) | const |
Get all games in the library (const version).
Definition at line 346 of file game_library.cpp.
| std::vector< std::string > GameLibrary::getCollectionNames | ( | ) | const |
Get list of all collection names.
Definition at line 926 of file game_library.cpp.
| std::vector< Game * > GameLibrary::getFavorites | ( | ) |
Get all favorite games.
Definition at line 386 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::getFavorites | ( | ) | const |
Get all favorite games (const version).
Definition at line 399 of file game_library.cpp.
| std::optional< Game * > GameLibrary::getGame | ( | const std::string & | gameId | ) |
Get a game by ID.
| gameId | Unique ID of game to retrieve |
Returns a pointer to the game in the library. The pointer remains valid until the game is removed or the library is destroyed.
Definition at line 306 of file game_library.cpp.
Referenced by addGameToCollection(), and removeGameFromCollection().
| std::optional< const Game * > GameLibrary::getGame | ( | const std::string & | gameId | ) | const |
Get a game by ID (const version).
| gameId | Unique ID of game to retrieve |
Definition at line 317 of file game_library.cpp.
| std::vector< Game * > GameLibrary::getGamesByPlatform | ( | GamePlatform | platform | ) |
Get games filtered by platform.
| platform | Platform to filter by |
Definition at line 360 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::getGamesByPlatform | ( | GamePlatform | platform | ) | const |
Get games filtered by platform (const version).
| platform | Platform to filter by |
Definition at line 373 of file game_library.cpp.
| std::vector< Game * > GameLibrary::getGamesInCollection | ( | const std::string & | collectionName | ) |
Get games in a specific collection.
| collectionName | Name of collection to query |
Definition at line 575 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::getGamesInCollection | ( | const std::string & | collectionName | ) | const |
Get games in a specific collection (const version).
| collectionName | Name of collection to query |
Definition at line 590 of file game_library.cpp.
| int GameLibrary::getInstalledGameCount | ( | ) | const |
Get number of installed games.
Definition at line 614 of file game_library.cpp.
| std::vector< Game * > GameLibrary::getInstalledGames | ( | ) |
Get all installed games.
Definition at line 493 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::getInstalledGames | ( | ) | const |
Get all installed games (const version).
Definition at line 506 of file game_library.cpp.
| std::vector< Game * > GameLibrary::getRecentlyPlayed | ( | int | count = 10 | ) |
Get recently played games.
| count | Maximum number of games to return (default: 10) |
Definition at line 412 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::getRecentlyPlayed | ( | int | count = 10 | ) | const |
Get recently played games (const version).
| count | Maximum number of games to return (default: 10) |
Definition at line 448 of file game_library.cpp.
| std::vector< PlaySession > GameLibrary::getRecentSessions | ( | const std::string & | gameId, |
| int | limit = 20 ) const |
Get recent play sessions for a game from the database.
| gameId | Game ID |
| limit | Maximum sessions to return |
Definition at line 484 of file game_library.cpp.
| int GameLibrary::getTotalGameCount | ( | ) | const |
Get total number of games in library.
Definition at line 609 of file game_library.cpp.
| double GameLibrary::getTotalPlayTime | ( | ) | const |
Get total play time across all games.
Definition at line 627 of file game_library.cpp.
| void GameLibrary::loadFromDisk | ( | ) |
Load library from disk.
Reads all .game files from the library directory and loads them into memory. Also loads the collections list from collections.txt. Creates the library directory if it doesn't exist.
Definition at line 49 of file game_library.cpp.
References Logger::info().
| int GameLibrary::refreshStaleImages | ( | ) |
Refresh images for games with stale/missing image files.
Checks if stored image paths still exist on disk. For any that don't, attempts to re-discover images from Steam's cache. This handles cases where Steam has updated its cache structure or cleared old images. Should be called in a background thread.
Definition at line 775 of file game_library.cpp.
References SteamCDN::discoverImages(), SteamPaths::getPrimarySteamRoot(), GameImagePaths::header, GameImagePaths::heroImage, Logger::info(), and GameImagePaths::verticalCover.
| bool GameLibrary::removeGame | ( | const std::string & | gameId | ) |
Remove a game from the library.
| gameId | Unique ID of game to remove |
Removes the game from memory AND deletes its .game file from disk.
Definition at line 245 of file game_library.cpp.
References Logger::error(), and Logger::info().
| void GameLibrary::removeGameFromCollection | ( | const std::string & | gameId, |
| const std::string & | collection ) |
Remove a game from a collection.
| gameId | ID of game to remove |
| collection | Name of collection |
If the game isn't in the collection, this is a no-op. If the game doesn't exist, prints an error to stderr.
Definition at line 955 of file game_library.cpp.
References Game::collections, Logger::error(), getGame(), and Logger::info().
| void GameLibrary::saveToDisk | ( | ) |
Save library to disk.
Writes all games to individual .game files in the library directory. Also saves the collections list to collections.txt. Creates the library directory if it doesn't exist.
Definition at line 72 of file game_library.cpp.
References Logger::error(), and Logger::info().
| std::vector< Game * > GameLibrary::searchGames | ( | std::string_view | query | ) |
Search games by name (case-insensitive substring match).
| query | Search query string |
Performance: O(n) where n is total number of games. Uses std::string_view for efficient string handling.
Definition at line 519 of file game_library.cpp.
| std::vector< const Game * > GameLibrary::searchGames | ( | std::string_view | query | ) | const |
Search games by name (const version).
| query | Search query string |
Definition at line 547 of file game_library.cpp.
| bool GameLibrary::updateGame | ( | const std::string & | gameId, |
| const Game & | updatedGame ) |
Update an existing game.
| gameId | ID of game to update |
| updatedGame | New game data (ID will be preserved) |
Updates the game in memory but does NOT save to disk until saveToDisk() is called.
Definition at line 277 of file game_library.cpp.
References Logger::error(), Game::id, and Logger::info().