From 0a38800e44e7b9f3dd61416103fa7ded8d4814ed Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi Date: Tue, 11 Oct 2022 17:02:25 +0300 Subject: [PATCH] Savestates: fix endless renaming of used savestates (#12780) --- rpcs3/Emu/System.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 541465f5c3..f4ae9109fd 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -679,11 +679,17 @@ game_boot_result Emulator::BootGame(const std::string& path, const std::string& if (g_cfg.savestate.suspend_emu && m_ar) { std::string old_path = path.substr(0, path.find_last_not_of(fs::delim)); - old_path.insert(old_path.find_last_of(fs::delim) + 1, "old-"sv); + const usz insert_pos = old_path.find_last_of(fs::delim) + 1; + const auto prefix = "used_"sv; - if (fs::rename(path, old_path, true)) + if (old_path.compare(insert_pos, prefix.size(), prefix) != 0) { - sys_log.notice("Savestate has been moved to path='%s'", old_path); + old_path.insert(insert_pos, prefix); + + if (fs::rename(path, old_path, true)) + { + sys_log.notice("Savestate has been moved to path='%s'", old_path); + } } } @@ -2340,11 +2346,6 @@ std::shared_ptr Emulator::Kill(bool allow_autoexit, bool savestat } } - if (auto rsx = g_fxo->try_get()) - { - *static_cast(rsx) = thread_state::finished; - } - // Save it first for maximum timing accuracy const u64 timestamp = get_timebased_time(); @@ -2530,13 +2531,22 @@ std::shared_ptr Emulator::Kill(bool allow_autoexit, bool savestat else { std::string old_path = path.substr(0, path.find_last_not_of(fs::delim)); - old_path.insert(old_path.find_last_of(fs::delim) + 1, "old-"sv); + std::string old_path2 = old_path; + + old_path2.insert(old_path.find_last_of(fs::delim) + 1, "old-"sv); + old_path.insert(old_path.find_last_of(fs::delim) + 1, "used_"sv); if (fs::remove_file(old_path)) { sys_log.success("Old savestate has been removed: path='%s'", old_path); } + // For backwards compatibility - avoid having loose files + if (fs::remove_file(old_path2)) + { + sys_log.success("Old savestate has been removed: path='%s'", old_path2); + } + sys_log.success("Saved savestate! path='%s'", path); if (!g_cfg.savestate.suspend_emu)