Savestates: fix endless renaming of used savestates (#12780)

This commit is contained in:
Elad Ashkenazi 2022-10-11 17:02:25 +03:00 committed by GitHub
parent 6be5618d22
commit 0a38800e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 9 deletions

View File

@ -679,13 +679,19 @@ 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 (old_path.compare(insert_pos, prefix.size(), prefix) != 0)
{
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);
}
}
}
return error;
}
@ -2340,11 +2346,6 @@ std::shared_ptr<utils::serial> Emulator::Kill(bool allow_autoexit, bool savestat
}
}
if (auto rsx = g_fxo->try_get<rsx::thread>())
{
*static_cast<cpu_thread*>(rsx) = thread_state::finished;
}
// Save it first for maximum timing accuracy
const u64 timestamp = get_timebased_time();
@ -2530,13 +2531,22 @@ std::shared_ptr<utils::serial> 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)