System: Prevent memcard blocking resume state save

Because otherwise you end up with a stale/old resume state, which is
arguably worse.
This commit is contained in:
Stenzek 2024-12-08 22:59:00 +10:00
parent 9b0a906297
commit 31d953dac2
No known key found for this signature in database
6 changed files with 9 additions and 9 deletions

View File

@ -6535,7 +6535,7 @@ void FullscreenUI::DoSaveState(s32 slot, bool global)
std::string filename(global ? System::GetGlobalSaveStateFileName(slot) :
System::GetGameSaveStateFileName(System::GetGameSerial(), slot));
Error error;
if (!System::SaveState(filename.c_str(), &error, g_settings.create_save_state_backups))
if (!System::SaveState(filename.c_str(), &error, g_settings.create_save_state_backups, false))
{
ShowToast(std::string(), fmt::format(TRANSLATE_FS("System", "Failed to save state: {}"), error.GetDescription()));
}

View File

@ -111,7 +111,7 @@ static void HotkeySaveStateSlot(bool global, s32 slot)
std::string path(global ? System::GetGlobalSaveStateFileName(slot) :
System::GetGameSaveStateFileName(System::GetGameSerial(), slot));
Error error;
if (!System::SaveState(path.c_str(), &error, g_settings.create_save_state_backups))
if (!System::SaveState(path.c_str(), &error, g_settings.create_save_state_backups, false))
{
Host::AddIconOSDMessage(
"SaveState", ICON_FA_EXCLAMATION_TRIANGLE,

View File

@ -1277,7 +1277,7 @@ void SaveStateSelectorUI::SaveCurrentSlot()
if (std::string path = GetCurrentSlotPath(); !path.empty())
{
Error error;
if (!System::SaveState(path.c_str(), &error, g_settings.create_save_state_backups))
if (!System::SaveState(path.c_str(), &error, g_settings.create_save_state_backups, false))
{
Host::AddIconOSDMessage("SaveState", ICON_EMOJI_WARNING,
fmt::format(TRANSLATE_FS("OSDMessage", "Failed to save state to slot {0}:\n{1}"),

View File

@ -1664,7 +1664,7 @@ bool System::SaveResumeState(Error* error)
}
const std::string path(GetGameSaveStateFileName(s_state.running_game_serial, -1));
return SaveState(path.c_str(), error, false);
return SaveState(path.c_str(), error, false, true);
}
bool System::BootSystem(SystemBootParameters parameters, Error* error)
@ -3010,14 +3010,14 @@ bool System::ReadAndDecompressStateData(std::FILE* fp, std::span<u8> dst, u32 fi
}
}
bool System::SaveState(const char* path, Error* error, bool backup_existing_save)
bool System::SaveState(const char* path, Error* error, bool backup_existing_save, bool ignore_memcard_busy)
{
if (!IsValid() || IsReplayingGPUDump())
{
Error::SetStringView(error, TRANSLATE_SV("System", "System is not in correct state."));
return false;
}
else if (IsSavingMemoryCards())
else if (!ignore_memcard_busy && IsSavingMemoryCards())
{
Error::SetStringView(error, TRANSLATE_SV("System", "Cannot save state while memory card is being saved."));
return false;

View File

@ -256,7 +256,7 @@ void ResetSystem();
/// Loads state from the specified path.
bool LoadState(const char* path, Error* error, bool save_undo_state);
bool SaveState(const char* path, Error* error, bool backup_existing_save);
bool SaveState(const char* path, Error* error, bool backup_existing_save, bool ignore_memcard_busy);
bool SaveResumeState(Error* error);
/// Runs the VM until the CPU execution is canceled.

View File

@ -1412,7 +1412,7 @@ void EmuThread::saveState(const QString& filename, bool block_until_done /* = fa
return;
Error error;
if (!System::SaveState(filename.toUtf8().data(), &error, g_settings.create_save_state_backups))
if (!System::SaveState(filename.toUtf8().data(), &error, g_settings.create_save_state_backups, false))
emit errorReported(tr("Error"), tr("Failed to save state: %1").arg(QString::fromStdString(error.GetDescription())));
}
@ -1432,7 +1432,7 @@ void EmuThread::saveState(bool global, qint32 slot, bool block_until_done /* = f
if (!System::SaveState((global ? System::GetGlobalSaveStateFileName(slot) :
System::GetGameSaveStateFileName(System::GetGameSerial(), slot))
.c_str(),
&error, g_settings.create_save_state_backups))
&error, g_settings.create_save_state_backups, false))
{
emit errorReported(tr("Error"), tr("Failed to save state: %1").arg(QString::fromStdString(error.GetDescription())));
}