Skip to content

Commit

Permalink
System: Prevent memcard blocking resume state save
Browse files Browse the repository at this point in the history
Because otherwise you end up with a stale/old resume state, which is
arguably worse.
  • Loading branch information
stenzek committed Dec 9, 2024
1 parent 9b0a906 commit 31d953d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/core/imgui_overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand Down
6 changes: 3 additions & 3 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/duckstation-qt/qthost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}

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

0 comments on commit 31d953d

Please sign in to comment.