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

Service for managing Wine prefix snapshots. More...

#include <prefix_snapshot_service.h>

Classes

struct  Impl

Public Types

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

Public Member Functions

 PrefixSnapshotService ()
 ~PrefixSnapshotService ()
void cancelOperation ()
 Cancel ongoing operation.
int cleanupOldAutoSnapshots (int maxAgeDays=30)
 Clean up auto-snapshots older than specified days.
int cleanupOldSnapshots (int keepCount=5)
 Clean up old snapshots, keeping newest N per prefix.
PrefixDiff compareSnapshots (const std::string &snapshotId1, const std::string &snapshotId2) const
 Compare two snapshots.
PrefixDiff compareWithCurrent (const std::filesystem::path &prefixPath, const std::string &snapshotId) const
 Compare current prefix state with a snapshot.
std::optional< PrefixSnapshot > createAutoSnapshot (const std::filesystem::path &prefixPath, const std::string &gameId, const std::string &gameName, const std::string &reason)
 Create automatic snapshot for a game.
std::optional< PrefixSnapshot > createIncrementalSnapshot (const std::filesystem::path &prefixPath, const std::string &parentSnapshotId, const std::string &name, const ProgressCallback &progressCallback=nullptr)
 Create an incremental snapshot (only changes since parent).
std::optional< PrefixSnapshot > createSnapshot (const std::filesystem::path &prefixPath, const std::string &name, const std::string &description="", const ProgressCallback &progressCallback=nullptr)
 Create a full snapshot of a prefix.
std::future< std::optional< PrefixSnapshot > > createSnapshotAsync (const std::filesystem::path &prefixPath, const std::string &name, const std::string &description="", const ProgressCallback &progressCallback=nullptr)
 Create a snapshot asynchronously.
bool deleteSnapshot (const std::string &snapshotId)
 Delete a snapshot.
int deleteSnapshotsForPrefix (const std::filesystem::path &prefixPath)
 Delete all snapshots for a prefix.
bool exportSnapshot (const std::string &snapshotId, const std::filesystem::path &outputPath, const ProgressCallback &progressCallback=nullptr)
 Export a snapshot to a portable archive.
std::vector< PrefixSnapshot > getAllSnapshots () const
 Get all snapshots.
std::optional< PrefixSnapshot > getSnapshot (const std::string &snapshotId) const
 Get a specific snapshot by ID.
std::filesystem::path getSnapshotDirectory () const
 Get current snapshot directory.
std::vector< PrefixSnapshot > getSnapshotsForGame (const std::string &gameId) const
 Get snapshots for a specific game.
std::vector< PrefixSnapshot > getSnapshotsForPrefix (const std::filesystem::path &prefixPath) const
 Get snapshots for a specific prefix.
int64_t getTotalSnapshotSize () const
 Get total space used by all snapshots.
std::optional< PrefixSnapshot > importSnapshot (const std::filesystem::path &archivePath, const ProgressCallback &progressCallback=nullptr)
 Import a snapshot from archive.
std::vector< std::filesystem::path > listSnapshotFiles (const std::string &snapshotId) const
 List files in a snapshot.
bool renameSnapshot (const std::string &snapshotId, const std::string &newName)
 Rename a snapshot.
bool restoreFiles (const std::string &snapshotId, const std::vector< std::filesystem::path > &files)
 Restore specific files from a snapshot.
bool restoreSnapshot (const std::string &snapshotId, const ProgressCallback &progressCallback=nullptr)
 Restore a prefix from snapshot.
std::future< bool > restoreSnapshotAsync (const std::string &snapshotId, const ProgressCallback &progressCallback=nullptr)
 Restore a snapshot asynchronously.
void setCompressionEnabled (bool enabled)
 Enable/disable compression for snapshots.
void setMaxStorageSize (int64_t maxBytes)
 Set maximum total snapshot storage size.
void setSnapshotDirectory (const std::filesystem::path &path)
 Set snapshot storage directory.
bool updateDescription (const std::string &snapshotId, const std::string &description)
 Update snapshot description.

Detailed Description

Service for managing Wine prefix snapshots.

Provides methods for creating, restoring, and managing prefix snapshots for Wine and Proton game prefixes.

Usage Example

// Create snapshot before risky operation
auto snapshot = service.createSnapshot(prefixPath, "Before patch 1.5");
// ... something goes wrong ...
// Restore to working state
service.restoreSnapshot(snapshot.id);
bool restoreSnapshot(const std::string &snapshotId, const ProgressCallback &progressCallback=nullptr)
Restore a prefix from snapshot.
std::optional< PrefixSnapshot > createSnapshot(const std::filesystem::path &prefixPath, const std::string &name, const std::string &description="", const ProgressCallback &progressCallback=nullptr)
Create a full snapshot of a prefix.

Definition at line 142 of file prefix_snapshot_service.h.

Member Typedef Documentation

◆ ProgressCallback

using PrefixSnapshotService::ProgressCallback = std::function<void(const SnapshotProgress&)>

Definition at line 145 of file prefix_snapshot_service.h.

Constructor & Destructor Documentation

◆ PrefixSnapshotService()

PrefixSnapshotService::PrefixSnapshotService ( )

Definition at line 110 of file prefix_snapshot_service.cpp.

◆ ~PrefixSnapshotService()

PrefixSnapshotService::~PrefixSnapshotService ( )

Definition at line 128 of file prefix_snapshot_service.cpp.

References cancelOperation().

Member Function Documentation

◆ cancelOperation()

void PrefixSnapshotService::cancelOperation ( )

Cancel ongoing operation.

Definition at line 1432 of file prefix_snapshot_service.cpp.

Referenced by ~PrefixSnapshotService().

◆ cleanupOldAutoSnapshots()

int PrefixSnapshotService::cleanupOldAutoSnapshots ( int maxAgeDays = 30)

Clean up auto-snapshots older than specified days.

Parameters
maxAgeDaysMaximum age in days
Returns
Number of snapshots deleted

Definition at line 1159 of file prefix_snapshot_service.cpp.

References PrefixSnapshot::created, deleteSnapshot(), PrefixSnapshot::gameId, getAllSnapshots(), PrefixSnapshot::id, and Logger::info().

◆ cleanupOldSnapshots()

int PrefixSnapshotService::cleanupOldSnapshots ( int keepCount = 5)

Clean up old snapshots, keeping newest N per prefix.

Parameters
keepCountNumber of snapshots to keep per prefix
Returns
Number of snapshots deleted

Definition at line 1126 of file prefix_snapshot_service.cpp.

References Logger::info(), and PrefixSnapshot::prefixPath.

◆ compareSnapshots()

PrefixDiff PrefixSnapshotService::compareSnapshots ( const std::string & snapshotId1,
const std::string & snapshotId2 ) const

Compare two snapshots.

Parameters
snapshotId1First snapshot ID
snapshotId2Second snapshot ID
Returns
Differences between snapshots

Definition at line 942 of file prefix_snapshot_service.cpp.

References PrefixDiff::addedFiles, Logger::error(), getSnapshot(), PrefixDiff::modifiedFiles, and PrefixDiff::removedFiles.

◆ compareWithCurrent()

PrefixDiff PrefixSnapshotService::compareWithCurrent ( const std::filesystem::path & prefixPath,
const std::string & snapshotId ) const

Compare current prefix state with a snapshot.

Parameters
prefixPathCurrent prefix path
snapshotIdSnapshot to compare against
Returns
Differences from snapshot

Definition at line 1014 of file prefix_snapshot_service.cpp.

References PrefixDiff::addedFiles, Logger::error(), getSnapshot(), PrefixDiff::modifiedFiles, PrefixDiff::removedFiles, and PrefixSnapshot::snapshotPath.

◆ createAutoSnapshot()

std::optional< PrefixSnapshot > PrefixSnapshotService::createAutoSnapshot ( const std::filesystem::path & prefixPath,
const std::string & gameId,
const std::string & gameName,
const std::string & reason )

Create automatic snapshot for a game.

Parameters
prefixPathPath to Wine prefix
gameIdGame ID
gameNameGame name
reasonReason for snapshot (e.g., "pre-launch", "post-install")
Returns
Created snapshot info

Definition at line 599 of file prefix_snapshot_service.cpp.

References createSnapshot().

◆ createIncrementalSnapshot()

std::optional< PrefixSnapshot > PrefixSnapshotService::createIncrementalSnapshot ( const std::filesystem::path & prefixPath,
const std::string & parentSnapshotId,
const std::string & name,
const ProgressCallback & progressCallback = nullptr )

Create an incremental snapshot (only changes since parent).

Parameters
prefixPathPath to Wine prefix
parentSnapshotIdID of parent snapshot
nameSnapshot name
progressCallbackProgress updates
Returns
Created snapshot info, or nullopt on failure

Definition at line 567 of file prefix_snapshot_service.cpp.

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

◆ createSnapshot()

std::optional< PrefixSnapshot > PrefixSnapshotService::createSnapshot ( const std::filesystem::path & prefixPath,
const std::string & name,
const std::string & description = "",
const ProgressCallback & progressCallback = nullptr )

◆ createSnapshotAsync()

std::future< std::optional< PrefixSnapshot > > PrefixSnapshotService::createSnapshotAsync ( const std::filesystem::path & prefixPath,
const std::string & name,
const std::string & description = "",
const ProgressCallback & progressCallback = nullptr )

Create a snapshot asynchronously.

Definition at line 559 of file prefix_snapshot_service.cpp.

References createSnapshot().

◆ deleteSnapshot()

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

Delete a snapshot.

Parameters
snapshotIdSnapshot ID to delete
Returns
True on success

Definition at line 874 of file prefix_snapshot_service.cpp.

Referenced by cleanupOldAutoSnapshots().

◆ deleteSnapshotsForPrefix()

int PrefixSnapshotService::deleteSnapshotsForPrefix ( const std::filesystem::path & prefixPath)

Delete all snapshots for a prefix.

Parameters
prefixPathPrefix path
Returns
Number of snapshots deleted

Definition at line 880 of file prefix_snapshot_service.cpp.

References PrefixSnapshot::prefixPath.

◆ exportSnapshot()

bool PrefixSnapshotService::exportSnapshot ( const std::string & snapshotId,
const std::filesystem::path & outputPath,
const ProgressCallback & progressCallback = nullptr )

Export a snapshot to a portable archive.

Parameters
snapshotIdSnapshot ID
outputPathOutput archive path
progressCallbackProgress updates
Returns
True on success

Definition at line 1188 of file prefix_snapshot_service.cpp.

References Logger::error(), ShellUtils::escapeArg(), getSnapshot(), Logger::info(), and PrefixSnapshot::snapshotPath.

◆ getAllSnapshots()

std::vector< PrefixSnapshot > PrefixSnapshotService::getAllSnapshots ( ) const

Get all snapshots.

Returns
Vector of all snapshots

Definition at line 777 of file prefix_snapshot_service.cpp.

Referenced by cleanupOldAutoSnapshots().

◆ getSnapshot()

std::optional< PrefixSnapshot > PrefixSnapshotService::getSnapshot ( const std::string & snapshotId) const

Get a specific snapshot by ID.

Parameters
snapshotIdSnapshot ID
Returns
Snapshot if found

Definition at line 837 of file prefix_snapshot_service.cpp.

Referenced by compareSnapshots(), compareWithCurrent(), createIncrementalSnapshot(), exportSnapshot(), listSnapshotFiles(), restoreFiles(), and restoreSnapshot().

◆ getSnapshotDirectory()

fs::path PrefixSnapshotService::getSnapshotDirectory ( ) const

Get current snapshot directory.

Definition at line 1414 of file prefix_snapshot_service.cpp.

◆ getSnapshotsForGame()

std::vector< PrefixSnapshot > PrefixSnapshotService::getSnapshotsForGame ( const std::string & gameId) const

Get snapshots for a specific game.

Parameters
gameIdGame ID
Returns
Vector of snapshots for that game

Definition at line 817 of file prefix_snapshot_service.cpp.

References PrefixSnapshot::gameId.

◆ getSnapshotsForPrefix()

std::vector< PrefixSnapshot > PrefixSnapshotService::getSnapshotsForPrefix ( const std::filesystem::path & prefixPath) const

Get snapshots for a specific prefix.

Parameters
prefixPathPrefix path
Returns
Vector of snapshots for that prefix

Definition at line 797 of file prefix_snapshot_service.cpp.

References PrefixSnapshot::prefixPath.

◆ getTotalSnapshotSize()

int64_t PrefixSnapshotService::getTotalSnapshotSize ( ) const

Get total space used by all snapshots.

Returns
Total size in bytes

Definition at line 1114 of file prefix_snapshot_service.cpp.

References PrefixSnapshot::sizeBytes.

◆ importSnapshot()

std::optional< PrefixSnapshot > PrefixSnapshotService::importSnapshot ( const std::filesystem::path & archivePath,
const ProgressCallback & progressCallback = nullptr )

Import a snapshot from archive.

Parameters
archivePathArchive file path
progressCallbackProgress updates
Returns
Imported snapshot info, or nullopt on failure

Definition at line 1215 of file prefix_snapshot_service.cpp.

References PipeHandle::close(), PrefixSnapshot::created, Logger::error(), ShellUtils::escapeArg(), PrefixSnapshot::fileCount, PipeHandle::get(), PrefixSnapshot::id, Logger::info(), PrefixSnapshot::name, PrefixSnapshot::sizeBytes, PrefixSnapshot::snapshotPath, and Logger::warn().

◆ listSnapshotFiles()

std::vector< fs::path > PrefixSnapshotService::listSnapshotFiles ( const std::string & snapshotId) const

List files in a snapshot.

Parameters
snapshotIdSnapshot ID
Returns
List of files in snapshot

Definition at line 1084 of file prefix_snapshot_service.cpp.

References Logger::error(), getSnapshot(), and PrefixSnapshot::snapshotPath.

◆ renameSnapshot()

bool PrefixSnapshotService::renameSnapshot ( const std::string & snapshotId,
const std::string & newName )

Rename a snapshot.

Parameters
snapshotIdSnapshot ID
newNameNew name
Returns
True on success

Definition at line 906 of file prefix_snapshot_service.cpp.

◆ restoreFiles()

bool PrefixSnapshotService::restoreFiles ( const std::string & snapshotId,
const std::vector< std::filesystem::path > & files )

Restore specific files from a snapshot.

Parameters
snapshotIdSnapshot ID
filesList of files to restore (relative paths)
Returns
True on success

Definition at line 727 of file prefix_snapshot_service.cpp.

References Logger::error(), getSnapshot(), and Logger::warn().

◆ restoreSnapshot()

bool PrefixSnapshotService::restoreSnapshot ( const std::string & snapshotId,
const ProgressCallback & progressCallback = nullptr )

Restore a prefix from snapshot.

Parameters
snapshotIdSnapshot ID to restore
progressCallbackProgress updates
Returns
True on success

Creates a backup of current state before restoring.

Definition at line 629 of file prefix_snapshot_service.cpp.

References SnapshotProgress::Completed, createSnapshot(), Logger::error(), SnapshotProgress::errorMessage, SnapshotProgress::Failed, getSnapshot(), Logger::info(), SnapshotProgress::percentComplete, SnapshotProgress::state, and Logger::warn().

Referenced by restoreSnapshotAsync().

◆ restoreSnapshotAsync()

std::future< bool > PrefixSnapshotService::restoreSnapshotAsync ( const std::string & snapshotId,
const ProgressCallback & progressCallback = nullptr )

Restore a snapshot asynchronously.

Definition at line 720 of file prefix_snapshot_service.cpp.

References restoreSnapshot().

◆ setCompressionEnabled()

void PrefixSnapshotService::setCompressionEnabled ( bool enabled)

Enable/disable compression for snapshots.

Parameters
enabledWhether to compress

Definition at line 1420 of file prefix_snapshot_service.cpp.

◆ setMaxStorageSize()

void PrefixSnapshotService::setMaxStorageSize ( int64_t maxBytes)

Set maximum total snapshot storage size.

Parameters
maxBytesMaximum size in bytes (0 = unlimited)

Definition at line 1426 of file prefix_snapshot_service.cpp.

◆ setSnapshotDirectory()

void PrefixSnapshotService::setSnapshotDirectory ( const std::filesystem::path & path)

Set snapshot storage directory.

Parameters
pathDirectory path

Definition at line 1405 of file prefix_snapshot_service.cpp.

◆ updateDescription()

bool PrefixSnapshotService::updateDescription ( const std::string & snapshotId,
const std::string & description )

Update snapshot description.

Parameters
snapshotIdSnapshot ID
descriptionNew description
Returns
True on success

Definition at line 922 of file prefix_snapshot_service.cpp.


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