game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
CloudSaveService Class Reference

Service for managing and syncing game saves. More...

#include <cloud_save_service.h>

Classes

struct  Impl

Public Types

using ConflictCallback = std::function<ConflictResolution(const SyncConflict&)>
using ProgressCallback = std::function<void(const SyncStatus&)>

Public Member Functions

 CloudSaveService ()
 ~CloudSaveService ()
void cancelOperation ()
 Cancel ongoing operation.
std::optional< std::string > createSnapshot (const std::string &gameId, const std::string &description="")
 Create a snapshot of current saves.
std::future< std::optional< std::string > > createSnapshotAsync (const std::string &gameId, const std::string &description="")
 Create snapshot asynchronously.
bool deleteSnapshot (const std::string &snapshotId)
 Delete a snapshot.
std::vector< SaveLocation > detectSaveLocation (const std::string &gameName, const std::filesystem::path &prefixPath={}) const
 Detect save location for a game.
std::filesystem::path getBackupDirectory () const
 Get the backup directory.
std::vector< SyncConflict > getPendingConflicts (const std::string &gameId) const
 Get pending conflicts.
std::optional< SaveLocation > getSaveLocation (const std::string &gameId) const
 Get save location for a specific game.
std::vector< SaveLocation > getSaveLocations () const
 Get all registered save locations.
std::optional< SaveSnapshot > getSnapshot (const std::string &snapshotId) const
 Get a specific snapshot.
int getSnapshotCount (const std::string &gameId) const
 Get snapshot count for a game.
std::vector< SaveSnapshot > getSnapshots (const std::string &gameId) const
 List all snapshots for a game.
int64_t getTotalBackupSize () const
 Get total backup size for all games.
int64_t getTotalBackupSize (const std::string &gameId) const
 Get total backup size for a game.
bool needsSync (const std::string &gameId) const
 Check if sync is needed.
void onGameExit (const std::string &gameId)
 Called when a game exits.
void onGameLaunch (const std::string &gameId)
 Called when a game is about to launch.
int pruneSnapshots (const std::string &gameId, int keepCount=10)
 Delete old snapshots.
bool registerSaveLocation (const SaveLocation &location)
 Register a game's save location.
bool removeSaveLocation (const std::string &gameId)
 Remove a save location registration.
bool resolveConflict (const std::string &gameId, const std::string &filePath, ConflictResolution resolution)
 Resolve a conflict.
bool restoreSnapshot (const std::string &snapshotId, bool backupCurrent=true)
 Restore saves from a snapshot.
void setAutoSync (const std::string &gameId, bool enabled)
 Enable auto-sync for a game.
void setBackupDirectory (const std::filesystem::path &path)
 Set the local backup directory.
void setCustomSyncDirectory (const std::filesystem::path &path)
 Set custom sync directory.
void setDefaultConflictResolution (ConflictResolution resolution)
 Set default conflict resolution.
void setMaxSnapshotsPerGame (int count)
 Set maximum snapshots per game.
bool syncSaves (const std::string &gameId, SyncDirection direction=SyncDirection::Bidirectional, const ProgressCallback &progressCallback=nullptr, const ConflictCallback &conflictCallback=nullptr)
 Sync saves with cloud storage.
std::future< bool > syncSavesAsync (const std::string &gameId, SyncDirection direction=SyncDirection::Bidirectional, const ProgressCallback &progressCallback=nullptr, const ConflictCallback &conflictCallback=nullptr)
 Sync asynchronously.
bool updateSaveLocation (const SaveLocation &location)
 Update an existing save location.

Detailed Description

Service for managing and syncing game saves.

Provides methods for backing up, restoring, and syncing game saves across local and cloud storage.

Usage Example

// Register a game's save location
loc.gameId = "doom-eternal";
loc.gameName = "DOOM Eternal";
loc.localPath = "/home/user/.local/share/DOOM Eternal";
loc.pattern = "all-files"; // use glob pattern for all files
service.registerSaveLocation(loc);
// Create a backup
service.createSnapshot("doom-eternal", "Before mods");
// Restore from snapshot
auto snapshots = service.getSnapshots("doom-eternal");
service.restoreSnapshot(snapshots[0].id);
std::optional< std::string > createSnapshot(const std::string &gameId, const std::string &description="")
Create a snapshot of current saves.
std::vector< SaveSnapshot > getSnapshots(const std::string &gameId) const
List all snapshots for a game.
bool restoreSnapshot(const std::string &snapshotId, bool backupCurrent=true)
Restore saves from a snapshot.
bool registerSaveLocation(const SaveLocation &location)
Register a game's save location.
Information about a game's save location.
std::filesystem::path localPath
Local save directory.
std::string gameName
Display name.
std::string pattern
File pattern (e.g., "*.sav", "**‍/*").
std::string gameId
Internal game ID.

Definition at line 203 of file cloud_save_service.h.

Member Typedef Documentation

◆ ConflictCallback

Definition at line 207 of file cloud_save_service.h.

◆ ProgressCallback

using CloudSaveService::ProgressCallback = std::function<void(const SyncStatus&)>

Definition at line 206 of file cloud_save_service.h.

Constructor & Destructor Documentation

◆ CloudSaveService()

CloudSaveService::CloudSaveService ( )

Definition at line 321 of file cloud_save_service.cpp.

◆ ~CloudSaveService()

CloudSaveService::~CloudSaveService ( )
default

Member Function Documentation

◆ cancelOperation()

void CloudSaveService::cancelOperation ( )

Cancel ongoing operation.

Definition at line 1139 of file cloud_save_service.cpp.

◆ createSnapshot()

std::optional< std::string > CloudSaveService::createSnapshot ( const std::string & gameId,
const std::string & description = "" )

Create a snapshot of current saves.

Parameters
gameIdGame ID
descriptionOptional description
Returns
Snapshot ID on success

Definition at line 498 of file cloud_save_service.cpp.

References SaveSnapshot::description, SaveSnapshot::files, SaveSnapshot::gameId, SaveSnapshot::gameName, getSaveLocation(), SaveSnapshot::id, SaveSnapshot::isAutomatic, SaveFile::path, SaveSnapshot::timestamp, SaveSnapshot::totalSize, and Logger::warn().

Referenced by createSnapshotAsync(), onGameExit(), and restoreSnapshot().

◆ createSnapshotAsync()

std::future< std::optional< std::string > > CloudSaveService::createSnapshotAsync ( const std::string & gameId,
const std::string & description = "" )

Create snapshot asynchronously.

Definition at line 575 of file cloud_save_service.cpp.

References createSnapshot().

◆ deleteSnapshot()

bool CloudSaveService::deleteSnapshot ( const std::string & snapshotId)

Delete a snapshot.

Parameters
snapshotIdSnapshot to delete
Returns
True on success

Definition at line 703 of file cloud_save_service.cpp.

◆ detectSaveLocation()

std::vector< SaveLocation > CloudSaveService::detectSaveLocation ( const std::string & gameName,
const std::filesystem::path & prefixPath = {} ) const

Detect save location for a game.

Parameters
gameNameGame name to search for
prefixPathOptional Wine prefix path
Returns
Detected save locations (may be multiple)

Definition at line 404 of file cloud_save_service.cpp.

References SaveLocation::gameId, SaveLocation::gameName, SaveLocation::isWinePrefix, SaveLocation::localPath, SaveLocation::pattern, and SaveLocation::prefixPath.

◆ getBackupDirectory()

std::filesystem::path CloudSaveService::getBackupDirectory ( ) const

Get the backup directory.

Definition at line 1109 of file cloud_save_service.cpp.

◆ getPendingConflicts()

std::vector< SyncConflict > CloudSaveService::getPendingConflicts ( const std::string & gameId) const

Get pending conflicts.

Parameters
gameIdGame ID
Returns
Vector of unresolved conflicts

Definition at line 1045 of file cloud_save_service.cpp.

◆ getSaveLocation()

std::optional< SaveLocation > CloudSaveService::getSaveLocation ( const std::string & gameId) const

Get save location for a specific game.

Parameters
gameIdGame ID
Returns
Save location if found

Definition at line 389 of file cloud_save_service.cpp.

Referenced by createSnapshot(), needsSync(), onGameExit(), onGameLaunch(), restoreSnapshot(), and syncSaves().

◆ getSaveLocations()

std::vector< SaveLocation > CloudSaveService::getSaveLocations ( ) const

Get all registered save locations.

Returns
Vector of save locations

Definition at line 383 of file cloud_save_service.cpp.

◆ getSnapshot()

std::optional< SaveSnapshot > CloudSaveService::getSnapshot ( const std::string & snapshotId) const

Get a specific snapshot.

Parameters
snapshotIdSnapshot ID
Returns
Snapshot info if found

Definition at line 596 of file cloud_save_service.cpp.

Referenced by restoreSnapshot().

◆ getSnapshotCount()

int CloudSaveService::getSnapshotCount ( const std::string & gameId) const

Get snapshot count for a game.

Parameters
gameIdGame ID
Returns
Number of snapshots

Definition at line 1181 of file cloud_save_service.cpp.

◆ getSnapshots()

std::vector< SaveSnapshot > CloudSaveService::getSnapshots ( const std::string & gameId) const

List all snapshots for a game.

Parameters
gameIdGame ID
Returns
Vector of snapshots, newest first

Definition at line 581 of file cloud_save_service.cpp.

◆ getTotalBackupSize() [1/2]

int64_t CloudSaveService::getTotalBackupSize ( ) const

Get total backup size for all games.

Returns
Total size in bytes

Definition at line 1166 of file cloud_save_service.cpp.

◆ getTotalBackupSize() [2/2]

int64_t CloudSaveService::getTotalBackupSize ( const std::string & gameId) const

Get total backup size for a game.

Parameters
gameIdGame ID
Returns
Total size in bytes

Definition at line 1148 of file cloud_save_service.cpp.

◆ needsSync()

bool CloudSaveService::needsSync ( const std::string & gameId) const

Check if sync is needed.

Parameters
gameIdGame ID
Returns
True if local and remote are out of sync

Definition at line 1007 of file cloud_save_service.cpp.

References getSaveLocation(), and SaveLocation::localPath.

◆ onGameExit()

void CloudSaveService::onGameExit ( const std::string & gameId)

Called when a game exits.

Parameters
gameIdGame ID

Uploads saves to cloud if auto-sync enabled.

Definition at line 1087 of file cloud_save_service.cpp.

References createSnapshot(), getSaveLocation(), syncSaves(), and Upload.

◆ onGameLaunch()

void CloudSaveService::onGameLaunch ( const std::string & gameId)

Called when a game is about to launch.

Parameters
gameIdGame ID

Downloads latest saves from cloud if auto-sync enabled.

Definition at line 1078 of file cloud_save_service.cpp.

References Download, getSaveLocation(), and syncSaves().

◆ pruneSnapshots()

int CloudSaveService::pruneSnapshots ( const std::string & gameId,
int keepCount = 10 )

Delete old snapshots.

Parameters
gameIdGame ID
keepCountNumber of recent snapshots to keep
Returns
Number of snapshots deleted

Definition at line 726 of file cloud_save_service.cpp.

◆ registerSaveLocation()

bool CloudSaveService::registerSaveLocation ( const SaveLocation & location)

Register a game's save location.

Parameters
locationSave location info
Returns
True on success

Definition at line 333 of file cloud_save_service.cpp.

References SaveLocation::gameId.

◆ removeSaveLocation()

bool CloudSaveService::removeSaveLocation ( const std::string & gameId)

Remove a save location registration.

Parameters
gameIdGame ID to remove
Returns
True on success

Definition at line 367 of file cloud_save_service.cpp.

◆ resolveConflict()

bool CloudSaveService::resolveConflict ( const std::string & gameId,
const std::string & filePath,
ConflictResolution resolution )

Resolve a conflict.

Parameters
gameIdGame ID
filePathConflicted file path
resolutionHow to resolve
Returns
True on success

Definition at line 1051 of file cloud_save_service.cpp.

◆ restoreSnapshot()

bool CloudSaveService::restoreSnapshot ( const std::string & snapshotId,
bool backupCurrent = true )

Restore saves from a snapshot.

Parameters
snapshotIdSnapshot to restore
backupCurrentCreate backup of current saves first
Returns
True on success

Definition at line 613 of file cloud_save_service.cpp.

References createSnapshot(), Logger::error(), getSaveLocation(), and getSnapshot().

◆ setAutoSync()

void CloudSaveService::setAutoSync ( const std::string & gameId,
bool enabled )

Enable auto-sync for a game.

Parameters
gameIdGame ID
enabledEnable or disable

Definition at line 1063 of file cloud_save_service.cpp.

◆ setBackupDirectory()

void CloudSaveService::setBackupDirectory ( const std::filesystem::path & path)

Set the local backup directory.

Parameters
pathDirectory for storing snapshots

Definition at line 1102 of file cloud_save_service.cpp.

◆ setCustomSyncDirectory()

void CloudSaveService::setCustomSyncDirectory ( const std::filesystem::path & path)

Set custom sync directory.

Parameters
pathCustom cloud sync path (e.g., Syncthing folder)

Definition at line 1114 of file cloud_save_service.cpp.

◆ setDefaultConflictResolution()

void CloudSaveService::setDefaultConflictResolution ( ConflictResolution resolution)

Set default conflict resolution.

Parameters
resolutionDefault resolution for auto-sync

Definition at line 1120 of file cloud_save_service.cpp.

◆ setMaxSnapshotsPerGame()

void CloudSaveService::setMaxSnapshotsPerGame ( int count)

Set maximum snapshots per game.

Parameters
countMaximum to keep (0 = unlimited)

Definition at line 1131 of file cloud_save_service.cpp.

◆ syncSaves()

bool CloudSaveService::syncSaves ( const std::string & gameId,
SyncDirection direction = SyncDirection::Bidirectional,
const ProgressCallback & progressCallback = nullptr,
const ConflictCallback & conflictCallback = nullptr )

◆ syncSavesAsync()

std::future< bool > CloudSaveService::syncSavesAsync ( const std::string & gameId,
SyncDirection direction = SyncDirection::Bidirectional,
const ProgressCallback & progressCallback = nullptr,
const ConflictCallback & conflictCallback = nullptr )

Sync asynchronously.

Definition at line 997 of file cloud_save_service.cpp.

References syncSaves().

◆ updateSaveLocation()

bool CloudSaveService::updateSaveLocation ( const SaveLocation & location)

Update an existing save location.

Parameters
locationUpdated location info
Returns
True on success

Definition at line 351 of file cloud_save_service.cpp.

References SaveLocation::gameId.


The documentation for this class was generated from the following files: