33 return std::filesystem::exists(path, ec);
39 std::filesystem::create_directories(path, ec);
46 auto size = std::filesystem::file_size(path, ec);
47 return ec ? 0 :
static_cast<int64_t
>(size);
50std::chrono::system_clock::time_point
getFileModTime(
const std::filesystem::path& path)
53 auto ftime = std::filesystem::last_write_time(path, ec);
56 return std::chrono::system_clock::now();
59 auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
60 ftime - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now());
66 const char* units[] = {
"B",
"KB",
"MB",
"GB"};
68 double size =
static_cast<double>(bytes);
70 while (size >= 1024 && unitIndex < 3)
77 snprintf(buffer,
sizeof(buffer),
"%.1f %s", size, units[unitIndex]);
81std::string
formatTime(std::chrono::system_clock::time_point tp)
83 auto time = std::chrono::system_clock::to_time_t(tp);
86 localtime_r(&time, &tm_buf);
87 std::strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", &tm_buf);
93 std::random_device rd;
94 std::mt19937 gen(rd());
95 std::uniform_int_distribution<> dis(0, 15);
96 std::uniform_int_distribution<> dis2(8, 11);
101 for (
int i = 0; i < 8; i++)
104 for (
int i = 0; i < 4; i++)
107 for (
int i = 0; i < 3; i++)
111 for (
int i = 0; i < 3; i++)
114 for (
int i = 0; i < 12; i++)
122 const char* home = std::getenv(
"HOME");
125 return std::filesystem::path(home) /
".local" /
"share" /
"gamelauncher";
130std::vector<std::filesystem::path>
globFiles(
const std::filesystem::path& root,
131 const std::string& pattern)
133 std::vector<std::filesystem::path> result;
142 bool recursive = pattern.find(
"**") != std::string::npos;
147 auto canonicalRoot = std::filesystem::canonical(root, ec);
153 for (
const auto& entry : std::filesystem::recursive_directory_iterator(root, ec))
155 if (entry.is_regular_file())
157 std::error_code ecPath;
158 auto canonicalPath = std::filesystem::canonical(entry.path(), ecPath);
159 auto canonicalStr = canonicalPath.string();
160 auto rootStr = canonicalRoot.string();
164 !ecPath && canonicalStr.size() >= rootStr.size() &&
165 canonicalStr.compare(0, rootStr.size(), rootStr) == 0 &&
166 (canonicalStr.size() == rootStr.size() || canonicalStr[rootStr.size()] ==
'/');
169 result.push_back(entry.path());
176 for (
const auto& entry : std::filesystem::directory_iterator(root, ec))
178 if (entry.is_regular_file())
181 std::string filename = entry.path().filename().string();
182 if (pattern ==
"*" || pattern.empty())
184 result.push_back(entry.path());
186 else if (pattern.front() ==
'*')
188 std::string ext = pattern.substr(1);
189 if (filename.size() >= ext.size() &&
190 filename.substr(filename.size() - ext.size()) == ext)
192 result.push_back(entry.path());
210 return formatBytes(
size);
249 return "Downloading";
251 return "Resolving conflicts";
274 return "Steam Cloud";
293 return "Bidirectional";
308 std::map<std::string, std::vector<SaveSnapshot>>
snapshots;
316 backupDir = getDataDirectory() /
"save_backups";
335 std::lock_guard<std::mutex> lock(impl_->mutex);
338 for (
const auto& loc : impl_->saveLocations)
340 if (loc.gameId == location.
gameId)
346 impl_->saveLocations.push_back(location);
353 std::lock_guard<std::mutex> lock(impl_->mutex);
355 for (
auto& loc : impl_->saveLocations)
357 if (loc.gameId == location.
gameId)
369 std::lock_guard<std::mutex> lock(impl_->mutex);
371 auto it = std::remove_if(impl_->saveLocations.begin(), impl_->saveLocations.end(),
372 [&gameId](
const SaveLocation& loc) { return loc.gameId == gameId; });
374 if (it != impl_->saveLocations.end())
376 impl_->saveLocations.erase(it, impl_->saveLocations.end());
385 std::lock_guard<std::mutex> lock(impl_->mutex);
386 return impl_->saveLocations;
391 std::lock_guard<std::mutex> lock(impl_->mutex);
393 for (
const auto& loc : impl_->saveLocations)
395 if (loc.gameId == gameId)
403std::vector<SaveLocation>
405 const std::filesystem::path& prefixPath)
const
407 std::vector<SaveLocation> detected;
410 std::vector<std::filesystem::path> searchPaths;
411 const char* home = std::getenv(
"HOME");
414 std::filesystem::path homePath(home);
417 searchPaths.push_back(homePath /
".local" /
"share");
418 searchPaths.push_back(homePath /
".config");
419 searchPaths.push_back(homePath /
"Games");
420 searchPaths.push_back(homePath /
".steam" /
"steam" /
"steamapps" /
"compatdata");
423 const char* xdgData = std::getenv(
"XDG_DATA_HOME");
426 searchPaths.push_back(std::filesystem::path(xdgData));
430 if (!prefixPath.empty())
432 searchPaths.push_back(prefixPath /
"drive_c" /
"users" /
"steamuser" /
"Saved Games");
433 searchPaths.push_back(prefixPath /
"drive_c" /
"users" /
"steamuser" /
"Documents");
434 searchPaths.push_back(prefixPath /
"drive_c" /
"users" /
"steamuser" /
"AppData" /
436 searchPaths.push_back(prefixPath /
"drive_c" /
"users" /
"steamuser" /
"AppData" /
442 std::string lowerName = gameName;
443 std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
444 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
447 std::vector<std::string> suffixes = {
" game of the year",
" goty",
" edition",
" remaster",
449 for (
const auto& suffix : suffixes)
451 if (lowerName.size() > suffix.size())
453 if (lowerName.substr(lowerName.size() - suffix.size()) == suffix)
455 lowerName = lowerName.substr(0, lowerName.size() - suffix.size());
460 for (
const auto& searchPath : searchPaths)
462 if (!fileExists(searchPath))
466 for (
const auto& entry : std::filesystem::directory_iterator(searchPath, ec))
468 if (!entry.is_directory())
471 std::string dirName = entry.path().filename().string();
472 std::string lowerDir = dirName;
473 std::transform(lowerDir.begin(), lowerDir.end(), lowerDir.begin(),
474 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
477 if (lowerDir.find(lowerName) != std::string::npos)
486 detected.push_back(loc);
499 const std::string& description)
508 auto files = scanSaveFiles(*location);
516 snapshot.
id = generateSnapshotId();
518 snapshot.
gameName = location->gameName;
519 snapshot.
timestamp = std::chrono::system_clock::now();
524 std::filesystem::path snapshotDir = impl_->backupDir / gameId / snapshot.
id;
525 if (!createDirectories(snapshotDir))
531 int64_t totalSize = 0;
532 for (
const auto& file : files)
534 std::filesystem::path destPath = snapshotDir / file.relativePath;
535 createDirectories(destPath.parent_path());
538 std::filesystem::copy_file(file.path, destPath,
539 std::filesystem::copy_options::overwrite_existing, ec);
544 snapshotFile.
path = destPath;
545 snapshot.
files.push_back(snapshotFile);
546 totalSize += file.size;
550 Logger::warn(
"[CloudSave] Snapshot {}: failed to copy {}: {}", snapshot.
id,
551 file.relativePath, ec.message());
559 std::lock_guard<std::mutex> lock(impl_->mutex);
560 impl_->snapshots[gameId].push_back(snapshot);
564 while (impl_->maxSnapshotsPerGame > 0 &&
565 static_cast<int>(impl_->snapshots[gameId].size()) > impl_->maxSnapshotsPerGame)
567 impl_->snapshots[gameId].erase(impl_->snapshots[gameId].begin());
574std::future<std::optional<std::string>>
577 return std::async(std::launch::async, [
this, gameId, description]()
583 std::lock_guard<std::mutex> lock(impl_->mutex);
585 auto it = impl_->snapshots.find(gameId);
586 if (it != impl_->snapshots.end())
589 std::vector<SaveSnapshot> result = it->second;
590 std::reverse(result.begin(), result.end());
598 std::lock_guard<std::mutex> lock(impl_->mutex);
600 for (
const auto& [gameId, snapshots] : impl_->snapshots)
602 for (
const auto& snapshot : snapshots)
604 if (snapshot.id == snapshotId)
634 std::filesystem::path snapshotDir = impl_->backupDir / snapshot->gameId / snapshotId;
637 std::error_code canonEc1, canonEc2;
638 std::filesystem::path canonDestBase =
639 std::filesystem::weakly_canonical(location->localPath, canonEc2);
642 Logger::error(
"[CloudSave] Cannot canonicalize save location, aborting restore");
646 for (
const auto& file : snapshot->files)
649 std::filesystem::path relPath(file.relativePath);
650 for (
const auto& component : relPath)
652 if (component ==
"..")
654 Logger::error(
"[CloudSave] Rejected snapshot path with traversal: {}",
660 std::filesystem::path srcPath = snapshotDir / relPath;
661 std::filesystem::path destPath = location->localPath / relPath;
665 if (std::filesystem::is_symlink(srcPath, ec))
667 Logger::error(
"[CloudSave] Rejected symlink in snapshot: {}", srcPath.string());
674 std::filesystem::path canonDest = std::filesystem::weakly_canonical(destPath, ec);
677 Logger::error(
"[CloudSave] Could not canonicalize snapshot dest, rejecting: {}",
681 std::filesystem::path rel = std::filesystem::relative(canonDest, canonDestBase, ec);
682 if (ec || rel.empty() || *rel.begin() ==
"..")
684 Logger::error(
"[CloudSave] Rejected snapshot path outside save dir: {}",
689 createDirectories(destPath.parent_path());
691 std::filesystem::copy_file(srcPath, destPath,
692 std::filesystem::copy_options::overwrite_existing, ec);
705 std::lock_guard<std::mutex> lock(impl_->mutex);
707 for (
auto& [gameId, snapshots] : impl_->snapshots)
709 auto it = std::find_if(snapshots.begin(), snapshots.end(),
710 [&snapshotId](
const SaveSnapshot& s) { return s.id == snapshotId; });
712 if (it != snapshots.end())
715 std::filesystem::path snapshotDir = impl_->backupDir / gameId / snapshotId;
717 std::filesystem::remove_all(snapshotDir, ec);
728 std::lock_guard<std::mutex> lock(impl_->mutex);
730 auto it = impl_->snapshots.find(gameId);
731 if (it == impl_->snapshots.end())
736 auto& snapshots = it->second;
737 if (
static_cast<int>(snapshots.size()) <= keepCount)
742 int safeKeepCount = std::max(0, keepCount);
743 int deleteCount =
static_cast<int>(snapshots.size()) - safeKeepCount;
744 if (deleteCount <= 0)
749 { return a.timestamp < b.timestamp; });
752 for (
size_t i = 0; i < static_cast<size_t>(deleteCount) && i < snapshots.size(); ++i)
754 std::filesystem::path snapshotDir = impl_->backupDir / gameId / snapshots[i].id;
756 std::filesystem::remove_all(snapshotDir, ec);
759 snapshots.erase(snapshots.begin(), snapshots.begin() + deleteCount);
771 impl_->cancelRequested =
false;
776 if (progressCallback)
781 progressCallback(status);
787 if (impl_->customSyncDir.empty())
789 if (progressCallback)
793 status.
errorMessage =
"No cloud sync directory configured";
794 progressCallback(status);
801 if (progressCallback)
802 progressCallback(status);
805 auto localFiles = scanSaveFiles(*location);
808 if (progressCallback)
809 progressCallback(status);
812 std::filesystem::path remotePath = impl_->customSyncDir / gameId;
813 createDirectories(remotePath);
817 auto remoteFiles = scanSaveFiles(remoteLocation);
820 std::map<std::string, SaveFile> localMap;
821 std::map<std::string, SaveFile> remoteMap;
823 for (
const auto& f : localFiles)
824 localMap[f.relativePath] = f;
825 for (
const auto& f : remoteFiles)
826 remoteMap[f.relativePath] = f;
829 std::vector<SaveFile> toUpload;
830 std::vector<SaveFile> toDownload;
831 std::vector<SyncConflict> conflicts;
833 for (
const auto& [path, localFile] : localMap)
835 auto remoteIt = remoteMap.find(path);
836 if (remoteIt == remoteMap.end())
841 toUpload.push_back(localFile);
847 const auto& remoteFile = remoteIt->second;
848 if (localFile.checksum != remoteFile.checksum)
856 if (conflictCallback)
858 resolution = conflictCallback(conflict);
864 toUpload.push_back(localFile);
867 toDownload.push_back(remoteFile);
870 if (localFile.modifiedTime > remoteFile.modifiedTime)
871 toUpload.push_back(localFile);
873 toDownload.push_back(remoteFile);
876 toUpload.push_back(localFile);
879 std::filesystem::path backupPath = localFile.path;
880 backupPath +=
".conflict";
881 std::error_code backupEc;
882 std::filesystem::copy_file(
883 remoteFile.path, backupPath,
884 std::filesystem::copy_options::overwrite_existing, backupEc);
888 "[CloudSave] KeepBoth: failed to save remote backup for {}: {}",
889 remoteFile.relativePath, backupEc.message());
893 Logger::info(
"[CloudSave] KeepBoth: saved remote version to {}",
894 backupPath.string());
899 conflicts.push_back(conflict);
907 for (
const auto& [path, remoteFile] : remoteMap)
909 if (localMap.find(path) == localMap.end())
913 toDownload.push_back(remoteFile);
919 status.
filesTotal =
static_cast<int>(toUpload.size() + toDownload.size());
925 for (
const auto& file : toUpload)
927 if (impl_->cancelRequested)
930 if (progressCallback)
931 progressCallback(status);
935 std::filesystem::path destPath = remotePath / file.relativePath;
936 createDirectories(destPath.parent_path());
939 std::filesystem::copy_file(file.path, destPath,
940 std::filesystem::copy_options::overwrite_existing, ec);
947 ?
static_cast<int>(
static_cast<int64_t
>(status.
filesProcessed) * 100 /
950 if (progressCallback)
951 progressCallback(status);
959 for (
const auto& file : toDownload)
961 if (impl_->cancelRequested)
964 if (progressCallback)
965 progressCallback(status);
969 std::filesystem::path destPath = location->localPath / file.relativePath;
970 createDirectories(destPath.parent_path());
973 std::filesystem::copy_file(file.path, destPath,
974 std::filesystem::copy_options::overwrite_existing, ec);
981 ?
static_cast<int>(
static_cast<int64_t
>(status.
filesProcessed) * 100 /
984 if (progressCallback)
985 progressCallback(status);
991 if (progressCallback)
992 progressCallback(status);
994 return conflicts.empty();
1002 return std::async(std::launch::async,
1003 [
this, gameId, direction, progressCallback, conflictCallback]()
1004 {
return syncSaves(gameId, direction, progressCallback, conflictCallback); });
1010 if (!location || impl_->customSyncDir.empty())
1015 auto localFiles = scanSaveFiles(*location);
1018 remoteLocation.
localPath = impl_->customSyncDir / gameId;
1019 auto remoteFiles = scanSaveFiles(remoteLocation);
1022 if (localFiles.size() != remoteFiles.size())
1027 std::map<std::string, std::string> localChecksums;
1028 for (
const auto& f : localFiles)
1030 localChecksums[f.relativePath] = f.checksum;
1033 for (
const auto& f : remoteFiles)
1035 auto it = localChecksums.find(f.relativePath);
1036 if (it == localChecksums.end() || it->second != f.checksum)
1052 const std::string& ,
1065 std::lock_guard<std::mutex> lock(impl_->mutex);
1067 for (
auto& loc : impl_->saveLocations)
1069 if (loc.gameId == gameId)
1071 loc.autoSync = enabled;
1072 saveSaveLocations();
1081 if (location && location->autoSync)
1090 if (location && location->autoSync)
1104 std::lock_guard<std::mutex> lock(impl_->mutex);
1105 impl_->backupDir = path;
1106 createDirectories(path);
1111 return impl_->backupDir;
1116 std::lock_guard<std::mutex> lock(impl_->mutex);
1117 impl_->customSyncDir = path;
1127 std::lock_guard<std::mutex> lock(impl_->mutex);
1128 impl_->defaultResolution = resolution;
1135 std::lock_guard<std::mutex> lock(impl_->mutex);
1136 impl_->maxSnapshotsPerGame = count;
1141 impl_->cancelRequested =
true;
1150 std::lock_guard<std::mutex> lock(impl_->mutex);
1152 auto it = impl_->snapshots.find(gameId);
1153 if (it == impl_->snapshots.end())
1159 for (
const auto& snapshot : it->second)
1161 total += snapshot.totalSize;
1168 std::lock_guard<std::mutex> lock(impl_->mutex);
1171 for (
const auto& [gameId, snapshots] : impl_->snapshots)
1173 for (
const auto& snapshot : snapshots)
1175 total += snapshot.totalSize;
1183 std::lock_guard<std::mutex> lock(impl_->mutex);
1185 auto it = impl_->snapshots.find(gameId);
1186 if (it != impl_->snapshots.end())
1188 return static_cast<int>(it->second.size());
1197std::vector<SaveFile> CloudSaveService::scanSaveFiles(
const SaveLocation& location)
const
1199 std::vector<SaveFile> files;
1208 for (
const auto& path : paths)
1215 file.
checksum = calculateChecksum(path);
1218 bool excluded =
false;
1221 if (file.
relativePath.find(exclude) != std::string::npos)
1230 files.push_back(file);
1237std::string CloudSaveService::calculateChecksum(
const std::filesystem::path& path)
const
1240 std::ifstream file(path, std::ios::binary);
1244 constexpr uint64_t fnvOffsetBasis = 14695981039346656037ULL;
1245 constexpr uint64_t fnvPrime = 1099511628211ULL;
1246 uint64_t hash = fnvOffsetBasis;
1249 while (file.read(buf,
sizeof(buf)) || file.gcount() > 0)
1251 for (std::streamsize i = 0; i < file.gcount(); ++i)
1253 hash ^=
static_cast<uint8_t
>(buf[i]);
1259 snprintf(result,
sizeof(result),
"%016llx",
static_cast<unsigned long long>(hash));
1263bool CloudSaveService::copyFiles(
const std::vector<SaveFile>& files,
1264 const std::filesystem::path& destDir,
1265 const ProgressCallback& callback)
1268 status.
filesTotal =
static_cast<int>(files.size());
1270 for (
const auto& file : files)
1272 if (impl_->cancelRequested)
1277 std::filesystem::path destPath = destDir / file.
relativePath;
1281 std::filesystem::copy_file(file.
path, destPath,
1282 std::filesystem::copy_options::overwrite_existing, ec);
1303std::string CloudSaveService::generateSnapshotId()
const
1308void CloudSaveService::loadSaveLocations()
1310 std::filesystem::path configPath =
getDataDirectory() /
"save_locations.conf";
1316 std::ifstream file(configPath);
1318 SaveLocation current;
1320 while (std::getline(file, line))
1322 if (line.empty() || line[0] ==
'#')
1328 if (!current.
gameId.empty())
1330 impl_->saveLocations.push_back(current);
1332 current = SaveLocation();
1333 current.
gameId = line.substr(1, line.size() - 2);
1337 auto eqPos = line.find(
'=');
1338 if (eqPos != std::string::npos)
1340 std::string key = line.substr(0, eqPos);
1341 std::string value = line.substr(eqPos + 1);
1345 else if (key ==
"path")
1347 else if (key ==
"pattern")
1349 else if (key ==
"autoSync")
1350 current.
autoSync = (value ==
"true");
1351 else if (key ==
"isWinePrefix")
1353 else if (key ==
"prefixPath")
1359 if (!current.
gameId.empty())
1361 impl_->saveLocations.push_back(current);
1365void CloudSaveService::saveSaveLocations()
const
1367 std::filesystem::path configPath =
getDataDirectory() /
"save_locations.conf";
1368 std::filesystem::path tmpPath = std::filesystem::path(configPath.string() +
".tmp");
1371 std::ofstream file(tmpPath);
1374 Logger::error(
"[CloudSave] Failed to open tmp config for write: {}", tmpPath.string());
1378 for (
const auto& loc : impl_->saveLocations)
1380 file <<
"[" << loc.gameId <<
"]\n";
1381 file <<
"name=" << loc.gameName <<
"\n";
1382 file <<
"path=" << loc.localPath.string() <<
"\n";
1383 file <<
"pattern=" << loc.pattern <<
"\n";
1384 file <<
"autoSync=" << (loc.autoSync ?
"true" :
"false") <<
"\n";
1385 file <<
"isWinePrefix=" << (loc.isWinePrefix ?
"true" :
"false") <<
"\n";
1386 if (!loc.prefixPath.empty())
1388 file <<
"prefixPath=" << loc.prefixPath.string() <<
"\n";
1395 std::filesystem::rename(tmpPath, configPath, ec);
1398 Logger::error(
"[CloudSave] Failed to atomically replace config: {}", ec.message());
1399 std::filesystem::remove(tmpPath, ec);
1403void CloudSaveService::loadSnapshots()
1411 for (
const auto& gameDir : std::filesystem::directory_iterator(impl_->backupDir, ec))
1413 if (!gameDir.is_directory())
1416 std::string gameId = gameDir.path().filename().string();
1418 for (
const auto& snapshotDir : std::filesystem::directory_iterator(gameDir.path(), ec))
1420 if (!snapshotDir.is_directory())
1423 SaveSnapshot snapshot;
1424 snapshot.
id = snapshotDir.path().filename().string();
1425 snapshot.
gameId = gameId;
1429 for (
const auto& entry :
1430 std::filesystem::recursive_directory_iterator(snapshotDir.path(), ec))
1432 if (entry.is_regular_file())
1435 file.
path = entry.path();
1437 std::filesystem::relative(entry.path(), snapshotDir.path()).string();
1440 snapshot.
files.push_back(file);
1445 impl_->snapshots[gameId].push_back(snapshot);
1449 auto& snapshots = impl_->snapshots[gameId];
1450 std::sort(snapshots.begin(), snapshots.end(),
1451 [](
const SaveSnapshot& a,
const SaveSnapshot& b)
1452 { return a.timestamp < b.timestamp; });
void setCustomSyncDirectory(const std::filesystem::path &path)
Set custom sync directory.
bool needsSync(const std::string &gameId) const
Check if sync is needed.
void setBackupDirectory(const std::filesystem::path &path)
Set the local backup directory.
std::function< void(const SyncStatus &)> ProgressCallback
bool resolveConflict(const std::string &gameId, const std::string &filePath, ConflictResolution resolution)
Resolve a conflict.
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.
void setAutoSync(const std::string &gameId, bool enabled)
Enable auto-sync for a game.
void setMaxSnapshotsPerGame(int count)
Set maximum snapshots per game.
bool restoreSnapshot(const std::string &snapshotId, bool backupCurrent=true)
Restore saves from a snapshot.
int getSnapshotCount(const std::string &gameId) const
Get snapshot count for a game.
void onGameLaunch(const std::string &gameId)
Called when a game is about to launch.
void onGameExit(const std::string &gameId)
Called when a game exits.
bool updateSaveLocation(const SaveLocation &location)
Update an existing save location.
int64_t getTotalBackupSize() const
Get total backup size for all games.
std::vector< SyncConflict > getPendingConflicts(const std::string &gameId) const
Get pending conflicts.
bool deleteSnapshot(const std::string &snapshotId)
Delete a snapshot.
bool registerSaveLocation(const SaveLocation &location)
Register a game's save location.
void setDefaultConflictResolution(ConflictResolution resolution)
Set default conflict resolution.
std::future< bool > syncSavesAsync(const std::string &gameId, SyncDirection direction=SyncDirection::Bidirectional, const ProgressCallback &progressCallback=nullptr, const ConflictCallback &conflictCallback=nullptr)
Sync asynchronously.
std::vector< SaveLocation > getSaveLocations() const
Get all registered save locations.
void cancelOperation()
Cancel ongoing operation.
std::optional< SaveLocation > getSaveLocation(const std::string &gameId) const
Get save location for a specific game.
std::function< ConflictResolution(const SyncConflict &)> ConflictCallback
std::future< std::optional< std::string > > createSnapshotAsync(const std::string &gameId, const std::string &description="")
Create snapshot asynchronously.
std::optional< SaveSnapshot > getSnapshot(const std::string &snapshotId) const
Get a specific snapshot.
std::vector< SaveLocation > detectSaveLocation(const std::string &gameName, const std::filesystem::path &prefixPath={}) const
Detect save location for a game.
bool removeSaveLocation(const std::string &gameId)
Remove a save location registration.
bool syncSaves(const std::string &gameId, SyncDirection direction=SyncDirection::Bidirectional, const ProgressCallback &progressCallback=nullptr, const ConflictCallback &conflictCallback=nullptr)
Sync saves with cloud storage.
int pruneSnapshots(const std::string &gameId, int keepCount=10)
Delete old snapshots.
std::filesystem::path getBackupDirectory() const
Get the backup directory.
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void error(const std::string &message, Args &&... args)
Log error message (recoverable failure).
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
std::string syncDirectionName(SyncDirection direction)
Get human-readable sync direction name.
std::string cloudBackendName(CloudBackend backend)
Get human-readable backend name.
SyncDirection
Direction of sync operation.
@ Download
Cloud -> Local.
@ Bidirectional
Two-way sync.
ConflictResolution
How to resolve sync conflicts.
@ AskUser
Prompt user to choose.
@ UseRemote
Keep remote version.
@ UseNewest
Use whichever is newer.
@ KeepBoth
Keep both versions (create backup).
@ UseLocal
Keep local version.
CloudBackend
Supported cloud storage backends.
@ Custom
Custom sync location (e.g., Syncthing, Nextcloud).
std::chrono::system_clock::time_point getFileModTime(const std::filesystem::path &path)
int64_t getFileSize(const std::filesystem::path &path)
std::filesystem::path getDataDirectory()
std::vector< std::filesystem::path > globFiles(const std::filesystem::path &root, const std::string &pattern)
std::string formatTime(std::chrono::system_clock::time_point tp)
std::string formatBytes(int64_t bytes)
std::string generateUUID()
bool createDirectories(const std::filesystem::path &path)
bool fileExists(const std::filesystem::path &path)
bool fileExists(const std::filesystem::path &path)
std::map< std::string, std::vector< SaveSnapshot > > snapshots
std::vector< SaveLocation > saveLocations
std::filesystem::path backupDir
std::atomic< bool > cancelRequested
ConflictResolution defaultResolution
std::filesystem::path customSyncDir
Information about a specific save file.
std::string getFormattedSize() const
std::string getFormattedTime() const
std::chrono::system_clock::time_point modifiedTime
std::string relativePath
Path relative to save root.
int64_t size
File size in bytes.
std::string checksum
SHA-256 hash for comparison.
std::filesystem::path path
Full path to file.
Information about a game's save location.
bool autoSync
Auto-sync on launch/exit.
std::filesystem::path localPath
Local save directory.
std::filesystem::path prefixPath
Wine prefix path if applicable.
std::string gameName
Display name.
std::string pattern
File pattern (e.g., "*.sav", "**/*").
std::string gameId
Internal game ID.
std::vector< std::string > excludePatterns
Patterns to exclude.
bool isWinePrefix
Save is in a Wine prefix.
A complete snapshot of a game's saves at a point in time.
std::vector< SaveFile > files
Files in this snapshot.
std::string gameName
Game display name.
int64_t totalSize
Total size of all files.
std::string getFormattedTime() const
std::chrono::system_clock::time_point timestamp
std::string id
Unique snapshot ID.
std::string gameId
Game this belongs to.
std::string getFormattedSize() const
bool isAutomatic
True if auto-created.
std::string description
User-provided description.
Details about a sync conflict.
Status of sync operation.
std::string getStateStr() const