Skip to content

Commit

Permalink
copy saves to backup folder every 5 mins
Browse files Browse the repository at this point in the history
  • Loading branch information
rainmakerv3 committed Dec 28, 2024
1 parent 122fe22 commit 5a67a10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Core {

void StartAutosave(std::string game_serial);

using HLEInitDef = void (*)(Core::Loader::SymbolsResolver* sym);

struct SysModules {
Expand All @@ -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;
Expand Down

0 comments on commit 5a67a10

Please sign in to comment.