Savestates/System.cpp: Realized fix for suspend mode (#12883)

This commit is contained in:
Elad Ashkenazi 2022-10-28 10:51:46 +03:00 committed by GitHub
parent 61a371b106
commit c8620070b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -666,34 +666,7 @@ game_boot_result Emulator::BootGame(const std::string& path, const std::string&
{
m_path = path;
auto error = Load(title_id, add_only);
if (g_cfg.savestate.suspend_emu && error == game_boot_result::no_errors)
{
for (std::string old_path : std::initializer_list<std::string>{m_ar ? path : "", m_title_id.empty() ? "" : get_savestate_path(m_title_id, path)})
{
if (old_path.empty())
{
continue;
}
std::string new_path = old_path.substr(0, old_path.find_last_not_of(fs::delim) + 1);
const usz insert_pos = new_path.find_last_of(fs::delim) + 1;
const auto prefix = "used_"sv;
if (new_path.compare(insert_pos, prefix.size(), prefix) != 0)
{
new_path.insert(insert_pos, prefix);
if (fs::rename(old_path, new_path, true))
{
sys_log.notice("Savestate has been moved to path='%s'", new_path);
}
}
}
}
return error;
return Load(title_id, add_only);
}
game_boot_result result = game_boot_result::nothing_to_boot;
@ -945,6 +918,8 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
m_cat.clear();
}
m_path_old = m_path;
if (argv[0].starts_with("/dev_hdd0"sv))
{
m_path = rpcs3::utils::get_hdd0_dir();
@ -1984,6 +1959,32 @@ void Emulator::FixGuestTime()
CallFromMainThread([this]
{
// Mark a known savestate location and the one we try to boot (in case we boot a moved/copied savestate)
if (g_cfg.savestate.suspend_emu)
{
for (std::string old_path : std::initializer_list<std::string>{m_ar ? m_path_old : "", m_title_id.empty() ? "" : get_savestate_path(m_title_id, m_path_old)})
{
if (old_path.empty())
{
continue;
}
std::string new_path = old_path.substr(0, old_path.find_last_not_of(fs::delim) + 1);
const usz insert_pos = new_path.find_last_of(fs::delim) + 1;
const auto prefix = "used_"sv;
if (new_path.compare(insert_pos, prefix.size(), prefix) != 0)
{
new_path.insert(insert_pos, prefix);
if (fs::rename(old_path, new_path, true))
{
sys_log.success("Savestate has been moved (hidden) to path='%s'", new_path);
}
}
}
}
m_ar.reset();
g_tls_log_prefix = []()
@ -1997,6 +1998,7 @@ void Emulator::FixGuestTime()
initialize_timebased_time(0);
}
}
void Emulator::FinalizeRunRequest()
{
auto on_select = [](u32, spu_thread& spu)