From 5a67a108839a0a8c3f6e0b8f313e519c5ebbb1f0 Mon Sep 17 00:00:00 2001 From: rainmakerv2 <30595646+rainmakerv3@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:13:53 +0800 Subject: [PATCH] copy saves to backup folder every 5 mins --- src/emulator.cpp | 27 +++++++++++++++++++++++++++ src/emulator.h | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index 10d17a2db4..205012ff67 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,8 +1,11 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include +#include #include #include +#include #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 diff --git a/src/emulator.h b/src/emulator.h index e973e9022b..4ffff9d6dd 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -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 @@ class Emulator { private: void LoadSystemModules(const std::filesystem::path& file, std::string game_serial); - Core::MemoryManager* memory; Input::GameController* controller; Core::Linker* linker;