Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
UserDataBackup Namespace Reference

Functions

bool copyDirectoryRecursively (const QString &sourceDir, const QString &destDir)
 Recursively copies sourceDir into destDir, creating it as needed.
bool createBackupSessionDir (const QString &backupRoot, QString *sessionDirOut)
 Creates a fresh timestamped session directory under backupRoot.
bool backupAtRiskPaths (const QStringList &sourcePaths, const QString &backupRoot, QStringList *backupLocationsOut, QString *sessionDirOut=nullptr)
 Copies several at-risk paths into a single timestamped session directory.
qint64 estimateBackupSize (const QStringList &sourcePaths, qint64 capBytes=MAX_AUTO_BACKUP_BYTES)
 Estimates the total bytes that backing up sourcePaths would copy.
QString defaultBackupRoot ()
 Default backup root guaranteed to live outside the install directory.
QStringList listBackupSessions (const QString &backupRoot)
 Lists existing backup session directories under backupRoot, newest first.
QString findRecentCoveringBackupSession (const QString &backupRoot, const QStringList &sourcePaths, int maxAgeHours=24)
 Returns the newest non-empty session covering sourcePaths, regardless of completeness.
QString findRecentUsableBackupSession (const QString &backupRoot, const QStringList &sourcePaths, int maxAgeHours=24)
 Returns the newest session that is non-empty, complete and covering sourcePaths, or empty.
bool isBackupSessionComplete (const QString &sessionDir)
 Reports whether sessionDir holds a complete backup.
void pruneOldBackupSessions (const QString &backupRoot, int keepCount=5)
 Deletes oldest sessions keeping only the newest keepCount ones. Empty sessions are junk from failed attempts and are always removed, so they can never evict a good session from the kept set.
QStringList listSessionBackupLocations (const QString &sessionDir)
 Lists the backup targets inside an existing session directory.
bool sessionCoversSources (const QString &sessionDir, const QStringList &sourcePaths)
 Reports whether sessionDir was recorded as covering all of sourcePaths.

Variables

constexpr qint64 MAX_AUTO_BACKUP_BYTES = 200LL * 1024 * 1024
 Above this total, the client skips the automatic startup backup and asks for a manual copy. Kept small on purpose: the copy runs synchronously on the UI thread at startup.

Function Documentation

◆ backupAtRiskPaths()

bool UserDataBackup::backupAtRiskPaths ( const QStringList & sourcePaths,
const QString & backupRoot,
QStringList * backupLocationsOut,
QString * sessionDirOut = nullptr )

Copies several at-risk paths into a single timestamped session directory.

Parameters
sourcePathsfiles or directories holding user data; missing entries are skipped.
backupRootdirectory OUTSIDE the install tree that will hold timestamped backups.
backupLocationsOutreceives one entry per source that produced a backup target (including partial copies).
sessionDirOutoptionally receives the shared session directory; set to empty when nothing was backed up (all sources missing, or every copy failed outright).
Returns
true when every existing source was copied completely. A false return with a non-empty backupLocationsOut means a partial backup exists. When nothing at all could be salvaged the session directory is removed again, so a failed attempt never leaves an empty session behind that would block retries. Completeness is recorded with a marker file; see isBackupSessionComplete().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyDirectoryRecursively()

bool UserDataBackup::copyDirectoryRecursively ( const QString & sourceDir,
const QString & destDir )

Recursively copies sourceDir into destDir, creating it as needed.

Returns
true when every file was copied (or there was nothing to copy). Symlinks (file or directory) are copied best-effort via QFile::copy without dereferencing them; a dangling link fails that entry only.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBackupSessionDir()

bool UserDataBackup::createBackupSessionDir ( const QString & backupRoot,
QString * sessionDirOut )

Creates a fresh timestamped session directory under backupRoot.

Parameters
backupRootdirectory OUTSIDE the install tree that will hold timestamped backups.
sessionDirOutreceives the created directory on success.
Returns
true on success. Millisecond timestamps plus a numeric suffix keep rapid successive calls (e.g. one per installer phase) from sharing a directory.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ defaultBackupRoot()

QString UserDataBackup::defaultBackupRoot ( )

Default backup root guaranteed to live outside the install directory.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ estimateBackupSize()

qint64 UserDataBackup::estimateBackupSize ( const QStringList & sourcePaths,
qint64 capBytes = MAX_AUTO_BACKUP_BYTES )

Estimates the total bytes that backing up sourcePaths would copy.

Parameters
capBytesstop counting once the total exceeds this; the returned value is then at least capBytes (used to skip the scan early on huge trees). Missing entries contribute 0. Best effort only.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findRecentCoveringBackupSession()

QString UserDataBackup::findRecentCoveringBackupSession ( const QString & backupRoot,
const QStringList & sourcePaths,
int maxAgeHours = 24 )

Returns the newest non-empty session covering sourcePaths, regardless of completeness.

Used as a fallback pointer when a fresh copy fails entirely, so the dialog can still point at salvaged content. Completeness is left to the caller to report.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findRecentUsableBackupSession()

QString UserDataBackup::findRecentUsableBackupSession ( const QString & backupRoot,
const QStringList & sourcePaths,
int maxAgeHours = 24 )

Returns the newest session that is non-empty, complete and covering sourcePaths, or empty.

An incomplete newest session (partial failure) or one covering a different source set does not block reuse of an older good session.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBackupSessionComplete()

bool UserDataBackup::isBackupSessionComplete ( const QString & sessionDir)

Reports whether sessionDir holds a complete backup.

Returns
true when the session carries the complete marker, false otherwise (partial backups and empty/missing sessions).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ listBackupSessions()

QStringList UserDataBackup::listBackupSessions ( const QString & backupRoot)

Lists existing backup session directories under backupRoot, newest first.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ listSessionBackupLocations()

QStringList UserDataBackup::listSessionBackupLocations ( const QString & sessionDir)

Lists the backup targets inside an existing session directory.

Returns
absolute paths of the entries, for reuse messages without a new copy. Completeness marker and source manifest files are internal bookkeeping and are never listed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pruneOldBackupSessions()

void UserDataBackup::pruneOldBackupSessions ( const QString & backupRoot,
int keepCount )

Deletes oldest sessions keeping only the newest keepCount ones. Empty sessions are junk from failed attempts and are always removed, so they can never evict a good session from the kept set.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sessionCoversSources()

bool UserDataBackup::sessionCoversSources ( const QString & sessionDir,
const QStringList & sourcePaths )

Reports whether sessionDir was recorded as covering all of sourcePaths.

Returns
true when the session's source manifest lists every entry of sourcePaths (normalized via QDir::cleanPath, case-insensitive on Windows/macOS). Sessions without a readable manifest return false so a changed source set always triggers a fresh copy instead of reusing a backup that may not cover it.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MAX_AUTO_BACKUP_BYTES

qint64 UserDataBackup::MAX_AUTO_BACKUP_BYTES = 200LL * 1024 * 1024
constexpr

Above this total, the client skips the automatic startup backup and asks for a manual copy. Kept small on purpose: the copy runs synchronously on the UI thread at startup.