Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Savestates: fix endless renaming of used savestates #12780

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down