diff --git a/src/emulator.cpp b/src/emulator.cpp index 205012ff6..1c2138e25 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -274,6 +274,12 @@ void Emulator::Run(const std::filesystem::path& file) { } #endif + // TODO disable with config option + if (!game_info.game_serial.empty()) { + std::thread savethread(StartAutosave, game_info.game_serial); + savethread.detach(); + } + linker->Execute(); window->InitTimers(); @@ -333,11 +339,6 @@ 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 @@ -410,19 +411,24 @@ void Emulator::UpdatePlayTime(const std::string& serial) { } #endif -void StartAutosave(std::string game_serial) { +void Emulator::StartAutosave(std::string game_serial) { + const int SaveInterval = 0; // TODO enable setting backup intervals + + const auto backup_dir = + Common::FS::GetUserPath(Common::FS::PathType::SaveDataDir) / "1" / "BACKUPS"; + const auto save_dir = + Common::FS::GetUserPath(Common::FS::PathType::SaveDataDir) / "1" / game_serial; + if (!std ::filesystem::exists(backup_dir)) { + std::filesystem::create_directory(backup_dir); + } 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"; + std::this_thread::sleep_for(std::chrono::minutes(1)); try { - std::filesystem::copy(save_dir, backup_dir, + std::filesystem::copy(save_dir, backup_dir / game_serial, std::filesystem::copy_options::overwrite_existing | std::filesystem::copy_options::recursive); - LOG_INFO(Config, "Backup saves created"); + LOG_INFO(Frontend, "Backup saves created"); } catch (std::exception& ex) { fmt::print("Error creating backup saves. Exception: {}\n", ex.what()); } diff --git a/src/emulator.h b/src/emulator.h index 4ffff9d6d..3acd62aee 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -12,9 +12,6 @@ #include "sdl_window.h" namespace Core { - -void StartAutosave(std::string game_serial); - using HLEInitDef = void (*)(Core::Loader::SymbolsResolver* sym); struct SysModules { @@ -23,10 +20,12 @@ struct SysModules { }; class Emulator { + public: Emulator(); ~Emulator(); + int user_id{}; void Run(const std::filesystem::path& file); void UpdatePlayTime(const std::string& serial); @@ -37,6 +36,7 @@ private: Core::Linker* linker; std::unique_ptr window; std::chrono::steady_clock::time_point start_time; + static void StartAutosave(std::string game_serial); }; } // namespace Core diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index c18b70497..991cc9b47 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -67,8 +67,8 @@ 0 0 - 822 - 487 + 1028 + 649 @@ -189,6 +189,38 @@ + + + + Backup Saving + + + + + + Create backup saves + + + + + + + + 9 + false + + + + Backup Frequency (in minutes) + + + + + + + + + @@ -228,13 +260,6 @@ - - - - Is PS4 Pro - - - @@ -301,7 +326,7 @@ - -1 + 7 QLayout::SizeConstraint::SetDefaultConstraint @@ -685,8 +710,8 @@ 0 0 - 396 - 222 + 922 + 598 @@ -976,8 +1001,8 @@ 0 0 - 536 - 192 + 922 + 598 @@ -1227,8 +1252,8 @@ 0 0 - 146 - 215 + 922 + 598 @@ -1293,8 +1318,8 @@ 0 0 - 288 - 163 + 922 + 598