copy saves to backup folder every 5 mins

This commit is contained in:
rainmakerv2 2024-12-28 16:13:53 +08:00
parent 122fe22a32
commit 5a67a10883
2 changed files with 29 additions and 1 deletions

View File

@ -1,8 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <chrono>
#include <filesystem>
#include <set>
#include <fmt/core.h>
#include <pthread.h>
#include "common/config.h"
#include "common/debug.h"
@ -330,6 +333,11 @@ void Emulator::LoadSystemModules(const std::filesystem::path& file, std::string
linker->LoadModule(entry.path());
}
}
if (!game_serial.empty()) {
std::thread savethread(StartAutosave, game_serial);
savethread.detach();
}
}
#ifdef ENABLE_QT_GUI
@ -402,4 +410,23 @@ void Emulator::UpdatePlayTime(const std::string& serial) {
}
#endif
void StartAutosave(std::string game_serial) {
while (true) {
std::this_thread::sleep_for(std::chrono::minutes(5));
const auto backup_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) /
"savedata" / "1" / game_serial / "BACKUPSAVES";
const auto save_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "savedata" /
"1" / game_serial / "SPRJ0005";
try {
std::filesystem::copy(save_dir, backup_dir,
std::filesystem::copy_options::overwrite_existing |
std::filesystem::copy_options::recursive);
LOG_INFO(Config, "Backup saves created");
} catch (std::exception& ex) {
fmt::print("Error creating backup saves. Exception: {}\n", ex.what());
}
}
}
} // namespace Core

View File

@ -13,6 +13,8 @@
namespace Core {
void StartAutosave(std::string game_serial);
using HLEInitDef = void (*)(Core::Loader::SymbolsResolver* sym);
struct SysModules {
@ -30,7 +32,6 @@ public:
private:
void LoadSystemModules(const std::filesystem::path& file, std::string game_serial);
Core::MemoryManager* memory;
Input::GameController* controller;
Core::Linker* linker;