|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
SQLite-based storage for the game library. More...
#include <game_database.h>
Public Member Functions | |
| GameDatabase () | |
| GameDatabase (const GameDatabase &)=delete | |
| GameDatabase (GameDatabase &&other) noexcept | |
| ~GameDatabase () | |
| bool | addCollection (const std::string &name) |
| Add a collection. | |
| bool | addGameToCollection (const std::string &gameId, const std::string &collection) |
| Add game to collection. | |
| bool | beginTransaction () |
| Begin a transaction. | |
| void | close () |
| Close the database. | |
| bool | commitTransaction () |
| Commit current transaction. | |
| bool | deleteGame (const std::string &gameId) |
| Delete a game by ID. | |
| bool | endSession (int64_t sessionId, const std::string &exitReason="normal") |
| End a game session. | |
| bool | exportToJson (const std::string &path) const |
| Export all games to JSON. | |
| bool | gameExists (const std::string &gameId) const |
| Check if a game exists. | |
| std::vector< Game > | getAllGames () const |
| Get all games (convenience method). | |
| double | getAverageSessionDuration (const std::string &gameId) const |
| Get average session duration for a game. | |
| std::vector< std::string > | getCollections () const |
| Get all collection names. | |
| std::optional< Game > | getGame (const std::string &gameId) const |
| Get a game by ID. | |
| int | getGameCount (const DatabaseFilterOptions &filter={}) const |
| Get total game count. | |
| std::pair< int, int > | getGameCrashStats (const std::string &gameId) const |
| Get crash statistics for a game. | |
| std::vector< Game > | getGamesWithoutCoverArt (int limit=0) const |
| Get games that are missing cover art. | |
| std::vector< Game > | getMostPlayedGames (int limit=10) const |
| Get most played games. | |
| std::vector< std::pair< std::string, int64_t > > | getPlaytimeByDay (const std::string &startDate, const std::string &endDate) const |
| Get playtime by day for a date range. | |
| std::vector< std::pair< std::string, int64_t > > | getPlaytimeByGame (const std::string &startDate, const std::string &endDate, int limit=10) const |
| Get playtime by game for a date range. | |
| std::vector< Game > | getRecentlyPlayedGames (int limit=10) const |
| Get recently played games. | |
| std::vector< PlaySession > | getRecentSessions (const std::string &gameId, int limit=20) const |
| Get recent play sessions for a game. | |
| std::vector< std::pair< GameRunner, int64_t > > | getRunnerStats () const |
| Get runner usage statistics. | |
| int | getSchemaVersion () const |
| Get database schema version. | |
| std::vector< std::pair< GameSource, int > > | getSourceStats () const |
| Get source statistics (games per source). | |
| int64_t | getTotalPlaytime (const std::string &startDate, const std::string &endDate) const |
| Get total playtime for a specific date range. | |
| int | importFromJson (const std::string &path, bool overwriteExisting=false) |
| Import games from JSON. | |
| bool | insertGame (const Game &game) |
| Insert a new game. | |
| bool | isOpen () const |
| Check if database is open. | |
| std::string | lastError () const |
| Get last error message. | |
| bool | open (const std::string &path) |
| Open or create the database. | |
| GameDatabase & | operator= (const GameDatabase &)=delete |
| GameDatabase & | operator= (GameDatabase &&other) noexcept |
| std::vector< Game > | queryGames (const DatabaseFilterOptions &filter={}, const DatabaseSortOptions &sort={}, int limit=0, int offset=0) const |
| Query games with filtering and sorting. | |
| bool | recordLaunch (const std::string &gameId, bool success, GameRunner runner, const std::string &protonVersion="", const std::string &errorMessage="", int timeToLaunchMs=0) |
| Record a launch attempt (success or failure). | |
| bool | removeCollection (const std::string &name) |
| Remove a collection. | |
| bool | removeGameFromCollection (const std::string &gameId, const std::string &collection) |
| Remove game from collection. | |
| bool | rollbackTransaction () |
| Rollback current transaction. | |
| std::vector< Game > | searchGames (const std::string &query, int limit=50) const |
| Search games by name (uses FTS if available). | |
| int64_t | startSession (const std::string &gameId, GameRunner runner, const std::string &protonVersion="") |
| Record a game session start. | |
| bool | updateDailyPlaytime (const std::string &gameId, int playTimeSeconds) |
| Update daily playtime aggregation. | |
| bool | updateGame (const Game &game) |
| Update an existing game. | |
| bool | updateGameImages (const std::string &gameId, const GameImagePaths &images) |
| Update only the image paths for a game (efficient partial update). | |
| bool | vacuum () |
| Vacuum database to reclaim space. | |
| bool | withTransaction (const std::function< bool()> &func) |
| Execute a function within a transaction. | |
SQLite-based storage for the game library.
Manages all game data persistence using SQLite. Provides methods for CRUD operations, filtered queries, and data migration.
Definition at line 107 of file game_database.h.
|
default |
Referenced by GameDatabase(), GameDatabase(), operator=(), and operator=().
| GameDatabase::~GameDatabase | ( | ) |
Definition at line 455 of file game_database.cpp.
References close().
|
delete |
References GameDatabase().
|
noexcept |
Definition at line 462 of file game_database.cpp.
References GameDatabase().
| bool GameDatabase::addCollection | ( | const std::string & | name | ) |
Add a collection.
| name | Collection name |
Definition at line 1660 of file game_database.cpp.
| bool GameDatabase::addGameToCollection | ( | const std::string & | gameId, |
| const std::string & | collection ) |
Add game to collection.
| gameId | Game ID |
| collection | Collection name |
Definition at line 1702 of file game_database.cpp.
| bool GameDatabase::beginTransaction | ( | ) |
Begin a transaction.
Definition at line 2093 of file game_database.cpp.
References Game::name, and Logger::warn().
| void GameDatabase::close | ( | ) |
Close the database.
Definition at line 655 of file game_database.cpp.
References close(), and Logger::info().
Referenced by ~GameDatabase(), close(), open(), and operator=().
| bool GameDatabase::commitTransaction | ( | ) |
Commit current transaction.
Definition at line 2099 of file game_database.cpp.
| bool GameDatabase::deleteGame | ( | const std::string & | gameId | ) |
Delete a game by ID.
| gameId | ID of game to delete |
Definition at line 1122 of file game_database.cpp.
| bool GameDatabase::endSession | ( | int64_t | sessionId, |
| const std::string & | exitReason = "normal" ) |
End a game session.
| sessionId | Session ID from startSession |
| exitReason | How the session ended (normal, crash, etc.) |
Definition at line 2587 of file game_database.cpp.
References COL_CLOUD_ENABLED, COL_CLOUD_STORAGE_BYTES, COL_CLOUD_SUPPORTED, COL_CLOUD_SYNC_STATE, COL_PROTONDB_CONFIDENCE, COL_PROTONDB_LAST_UPDATED, COL_PROTONDB_SCORE, COL_PROTONDB_TIER, COL_STEAM_IS_UPDATE, and Steam.
| bool GameDatabase::exportToJson | ( | const std::string & | path | ) | const |
Export all games to JSON.
| path | Output file path |
Definition at line 1786 of file game_database.cpp.
| bool GameDatabase::gameExists | ( | const std::string & | gameId | ) | const |
Check if a game exists.
| gameId | ID to check |
Definition at line 1283 of file game_database.cpp.
| std::vector< Game > GameDatabase::getAllGames | ( | ) | const |
Get all games (convenience method).
Definition at line 1492 of file game_database.cpp.
| double GameDatabase::getAverageSessionDuration | ( | const std::string & | gameId | ) | const |
Get average session duration for a game.
| gameId | Game ID |
Definition at line 3000 of file game_database.cpp.
| std::vector< std::string > GameDatabase::getCollections | ( | ) | const |
Get all collection names.
Definition at line 1634 of file game_database.cpp.
| std::optional< Game > GameDatabase::getGame | ( | const std::string & | gameId | ) | const |
Get a game by ID.
| gameId | ID of game to retrieve |
Definition at line 1232 of file game_database.cpp.
| int GameDatabase::getGameCount | ( | const DatabaseFilterOptions & | filter = {} | ) | const |
Get total game count.
| filter | Optional filter (empty = all games) |
Definition at line 1497 of file game_database.cpp.
| std::pair< int, int > GameDatabase::getGameCrashStats | ( | const std::string & | gameId | ) | const |
Get crash statistics for a game.
| gameId | Game ID |
Definition at line 2972 of file game_database.cpp.
| std::vector< Game > GameDatabase::getGamesWithoutCoverArt | ( | int | limit = 0 | ) | const |
Get games that are missing cover art.
| limit | Maximum number to return (0 = no limit) |
Definition at line 1193 of file game_database.cpp.
| std::vector< Game > GameDatabase::getMostPlayedGames | ( | int | limit = 10 | ) | const |
Get most played games.
| limit | Max results |
Definition at line 2952 of file game_database.cpp.
| std::vector< std::pair< std::string, int64_t > > GameDatabase::getPlaytimeByDay | ( | const std::string & | startDate, |
| const std::string & | endDate ) const |
Get playtime by day for a date range.
| startDate | Start date (YYYY-MM-DD) |
| endDate | End date (YYYY-MM-DD) |
Definition at line 2868 of file game_database.cpp.
| std::vector< std::pair< std::string, int64_t > > GameDatabase::getPlaytimeByGame | ( | const std::string & | startDate, |
| const std::string & | endDate, | ||
| int | limit = 10 ) const |
Get playtime by game for a date range.
| startDate | Start date (YYYY-MM-DD) |
| endDate | End date (YYYY-MM-DD) |
| limit | Max results |
Definition at line 2835 of file game_database.cpp.
| std::vector< Game > GameDatabase::getRecentlyPlayedGames | ( | int | limit = 10 | ) | const |
Get recently played games.
| limit | Max results |
Definition at line 2962 of file game_database.cpp.
| std::vector< PlaySession > GameDatabase::getRecentSessions | ( | const std::string & | gameId, |
| int | limit = 20 ) const |
Get recent play sessions for a game.
| gameId | Game ID |
| limit | Maximum number of sessions to return |
Definition at line 2674 of file game_database.cpp.
| std::vector< std::pair< GameRunner, int64_t > > GameDatabase::getRunnerStats | ( | ) | const |
Get runner usage statistics.
Definition at line 2898 of file game_database.cpp.
| int GameDatabase::getSchemaVersion | ( | ) | const |
Get database schema version.
Definition at line 2027 of file game_database.cpp.
References GameStatistics::lastEnvironmentVars, and Game::statistics.
| std::vector< std::pair< GameSource, int > > GameDatabase::getSourceStats | ( | ) | const |
Get source statistics (games per source).
Definition at line 2925 of file game_database.cpp.
| int64_t GameDatabase::getTotalPlaytime | ( | const std::string & | startDate, |
| const std::string & | endDate ) const |
Get total playtime for a specific date range.
| startDate | Start date (YYYY-MM-DD) |
| endDate | End date (YYYY-MM-DD) |
Definition at line 2808 of file game_database.cpp.
| int GameDatabase::importFromJson | ( | const std::string & | path, |
| bool | overwriteExisting = false ) |
Import games from JSON.
| path | Input file path |
| overwriteExisting | Overwrite games with same ID |
Definition at line 1869 of file game_database.cpp.
| bool GameDatabase::insertGame | ( | const Game & | game | ) |
Insert a new game.
| game | Game to insert (id will be used as primary key) |
Definition at line 736 of file game_database.cpp.
References Game::activeTemplateName, GameImagePaths::capsule, GameMetadata::cloudSave, Game::configTemplates, GameStatistics::crashCount, GameStatistics::dateAdded, GameStatistics::dateInstalled, GameMetadata::description, GameMetadata::developer, GameMetadata::dlc, CloudSaveInfo::enabled, GameMetadata::genres, GameImagePaths::header, GameImagePaths::heroImage, GameImagePaths::icon, Game::id, GameMetadata::imagePaths, Game::installPath, Game::installSizeBytes, Game::isFavorite, jsonArrayFromStrings(), jsonFromEnvVars(), GameStatistics::lastEnvironmentVars, GameStatistics::lastExitReason, GameStatistics::lastExitTime, GameStatistics::lastLaunchCommand, GameStatistics::lastPlayed, GameStatistics::lastProtonVersion, CloudSaveInfo::lastSyncState, CloudSaveInfo::lastSyncTime, GameImagePaths::logo, Game::metadata, Game::name, GameMetadata::protondbConfidence, GameMetadata::protondbLastUpdated, GameMetadata::protondbScore, GameMetadata::protondbTier, GameMetadata::publisher, GameMetadata::releaseYear, Game::runner, Game::runnerConfig, Game::serializeRunnerConfig(), Game::source, Game::statistics, Game::status, GameMetadata::steamAppId, GameMetadata::steamBuildId, GameMetadata::steamBytesDownloaded, GameMetadata::steamBytesToDownload, GameMetadata::steamCategories, GameMetadata::steamInstalled, GameMetadata::steamIsDownloading, GameMetadata::steamIsUpdatePending, GameMetadata::steamLastExit, GameMetadata::steamLastLaunch, GameMetadata::steamLaunchOptions, GameMetadata::steamPlaytime2Weeks, GameMetadata::steamStateFlags, GameMetadata::steamType, GameMetadata::steamUserCategories, CloudSaveInfo::storageBytes, CloudSaveInfo::supported, GameMetadata::tags, GameStatistics::timesLaunched, GameStatistics::totalPlayTimeSeconds, GameMetadata::userRating, and GameImagePaths::verticalCover.
| bool GameDatabase::isOpen | ( | ) | const |
Check if database is open.
Definition at line 720 of file game_database.cpp.
| std::string GameDatabase::lastError | ( | ) | const |
Get last error message.
Definition at line 726 of file game_database.cpp.
| bool GameDatabase::open | ( | const std::string & | path | ) |
Open or create the database.
| path | Path to the database file |
Creates the database and tables if they don't exist. Runs any pending schema migrations.
Definition at line 498 of file game_database.cpp.
References close(), Logger::info(), open(), and Logger::warn().
Referenced by open().
|
delete |
References GameDatabase().
|
noexcept |
Definition at line 476 of file game_database.cpp.
References GameDatabase(), and close().
| std::vector< Game > GameDatabase::queryGames | ( | const DatabaseFilterOptions & | filter = {}, |
| const DatabaseSortOptions & | sort = {}, | ||
| int | limit = 0, | ||
| int | offset = 0 ) const |
Query games with filtering and sorting.
| filter | Filter options |
| sort | Sort options |
| limit | Maximum results (0 = no limit) |
| offset | Skip first N results |
Definition at line 1309 of file game_database.cpp.
| bool GameDatabase::recordLaunch | ( | const std::string & | gameId, |
| bool | success, | ||
| GameRunner | runner, | ||
| const std::string & | protonVersion = "", | ||
| const std::string & | errorMessage = "", | ||
| int | timeToLaunchMs = 0 ) |
Record a launch attempt (success or failure).
| gameId | Game ID |
| success | Whether launch succeeded |
| runner | Runner used |
| protonVersion | Proton version (if applicable) |
| errorMessage | Error message if failed |
| timeToLaunchMs | Time taken to launch in milliseconds |
Definition at line 2716 of file game_database.cpp.
| bool GameDatabase::removeCollection | ( | const std::string & | name | ) |
Remove a collection.
| name | Collection name |
Definition at line 1681 of file game_database.cpp.
| bool GameDatabase::removeGameFromCollection | ( | const std::string & | gameId, |
| const std::string & | collection ) |
Remove game from collection.
| gameId | Game ID |
| collection | Collection name |
Definition at line 1754 of file game_database.cpp.
| bool GameDatabase::rollbackTransaction | ( | ) |
Rollback current transaction.
Definition at line 2105 of file game_database.cpp.
| std::vector< Game > GameDatabase::searchGames | ( | const std::string & | query, |
| int | limit = 50 ) const |
Search games by name (uses FTS if available).
| query | Search query |
| limit | Maximum results |
Definition at line 1554 of file game_database.cpp.
| int64_t GameDatabase::startSession | ( | const std::string & | gameId, |
| GameRunner | runner, | ||
| const std::string & | protonVersion = "" ) |
Record a game session start.
| gameId | Game ID |
| runner | Runner used |
| protonVersion | Proton version (if applicable) |
Definition at line 2548 of file game_database.cpp.
References COL_DESCRIPTION, COL_GENRES, COL_IMG_CAPSULE, COL_IMG_HEADER, COL_IMG_HERO, COL_IMG_ICON, COL_IMG_LOGO, COL_IMG_VERTICAL, COL_RELEASE_YEAR, COL_STEAM_APP_ID, COL_STEAM_BUILD_ID, COL_STEAM_BYTES_DL, COL_STEAM_BYTES_TO_DL, COL_STEAM_CATEGORIES, COL_STEAM_INSTALLED, COL_STEAM_LAST_EXIT, COL_STEAM_LAST_LAUNCH, COL_STEAM_LAUNCH_OPTS, COL_STEAM_PLAYTIME_2W, COL_STEAM_STATE_FLAGS, COL_STEAM_TYPE, COL_STEAM_USER_TAGS, COL_TAGS, and COL_USER_RATING.
| bool GameDatabase::updateDailyPlaytime | ( | const std::string & | gameId, |
| int | playTimeSeconds ) |
Update daily playtime aggregation.
| gameId | Game ID |
| playTimeSeconds | Playtime to add |
Definition at line 2775 of file game_database.cpp.
| bool GameDatabase::updateGame | ( | const Game & | game | ) |
Update an existing game.
| game | Game with updated data (matched by id) |
Definition at line 924 of file game_database.cpp.
| bool GameDatabase::updateGameImages | ( | const std::string & | gameId, |
| const GameImagePaths & | images ) |
Update only the image paths for a game (efficient partial update).
| gameId | ID of game to update |
| images | New image paths to set |
Definition at line 1156 of file game_database.cpp.
References Game::id.
| bool GameDatabase::vacuum | ( | ) |
Vacuum database to reclaim space.
Definition at line 2021 of file game_database.cpp.
| bool GameDatabase::withTransaction | ( | const std::function< bool()> & | func | ) |
Execute a function within a transaction.
| func | Function to execute |
Automatically rolls back on exception or if func returns false.
Definition at line 2111 of file game_database.cpp.