CommonHostInterface: Move save state on exit logic to base class

This commit is contained in:
Connor McLaughlin 2021-03-03 01:14:05 +10:00
parent 7645ca3836
commit c58227752d
9 changed files with 25 additions and 35 deletions

View file

@ -374,11 +374,7 @@ void AndroidHostInterface::EmulationThreadEntryPoint(JNIEnv* env, jobject emulat
{
// System is ready to go.
EmulationThreadLoop(env);
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem();
PowerOffSystem(ShouldSaveResumeState());
}
// Drain any callbacks so we don't leave things in a screwed-up state for next boot.

View file

@ -142,11 +142,6 @@ void HostInterface::ResetSystem()
AddOSDMessage(TranslateStdString("OSDMessage", "System reset."));
}
void HostInterface::PowerOffSystem()
{
DestroySystem();
}
void HostInterface::PauseSystem(bool paused)
{
if (paused == System::IsPaused() || System::IsShutdown())

View file

@ -52,7 +52,6 @@ public:
virtual void Shutdown();
virtual bool BootSystem(const SystemBootParameters& parameters);
virtual void PowerOffSystem();
virtual void PauseSystem(bool paused);
virtual void ResetSystem();
virtual void DestroySystem();

View file

@ -238,11 +238,7 @@ void NoGUIHostInterface::Run()
// Save state on exit so it can be resumed
if (!System::IsShutdown())
{
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
DestroySystem();
}
PowerOffSystem(ShouldSaveResumeState());
}
void NoGUIHostInterface::ReportMessage(const char* message)

View file

@ -812,10 +812,7 @@ void QtHostInterface::powerOffSystem()
return;
}
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem();
PowerOffSystem(ShouldSaveResumeState());
}
void QtHostInterface::powerOffSystemWithoutSaving()
@ -827,7 +824,7 @@ void QtHostInterface::powerOffSystemWithoutSaving()
return;
}
PowerOffSystem();
PowerOffSystem(false);
}
void QtHostInterface::synchronousPowerOffSystem()

View file

@ -199,12 +199,15 @@ void CommonHostInterface::DestroySystem()
HostInterface::DestroySystem();
}
void CommonHostInterface::PowerOffSystem()
void CommonHostInterface::PowerOffSystem(bool save_resume_state)
{
if (System::IsShutdown())
return;
HostInterface::PowerOffSystem();
if (save_resume_state)
SaveResumeSaveState();
DestroySystem();
if (InBatchMode())
RequestExit();
@ -753,6 +756,11 @@ bool CommonHostInterface::ResumeSystemFromMostRecentState()
return LoadState(path.c_str());
}
bool CommonHostInterface::ShouldSaveResumeState() const
{
return g_settings.save_state_on_exit;
}
bool CommonHostInterface::IsRunningAtNonStandardSpeed() const
{
if (!System::IsValid())
@ -1810,7 +1818,7 @@ void CommonHostInterface::RegisterGeneralHotkeys()
{
SmallString confirmation_message(
TranslateString("CommonHostInterface", "Are you sure you want to stop emulation?"));
if (g_settings.save_state_on_exit)
if (ShouldSaveResumeState())
{
confirmation_message.AppendString("\n\n");
confirmation_message.AppendString(
@ -1824,10 +1832,7 @@ void CommonHostInterface::RegisterGeneralHotkeys()
}
}
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem();
PowerOffSystem(ShouldSaveResumeState());
}
});
#else

View file

@ -125,7 +125,6 @@ public:
virtual void Shutdown() override;
virtual bool BootSystem(const SystemBootParameters& parameters) override;
virtual void PowerOffSystem() override;
virtual void ResetSystem() override;
virtual void DestroySystem() override;
@ -169,6 +168,9 @@ public:
/// Saves the current input configuration to the specified profile name.
bool SaveInputProfile(const char* profile_path);
/// Powers off the system, optionally saving the resume state.
void PowerOffSystem(bool save_resume_state);
/// Loads state from the specified filename.
bool LoadState(const char* filename);
@ -184,8 +186,7 @@ public:
/// Loads the most recent resume save state. This may be global or per-game.
bool ResumeSystemFromMostRecentState();
/// Saves the resume save state, call when shutting down. Not called automatically on DestroySystem() since that can
/// be called as a result of an error.
/// Saves the resume save state, call when shutting down.
bool SaveResumeSaveState();
/// Returns a list of save states for the specified game code.
@ -268,6 +269,9 @@ public:
/// Converts a fullscreen mode to a string.
static std::string GetFullscreenModeString(u32 width, u32 height, float refresh_rate);
/// Returns true if the state should be saved on shutdown.
bool ShouldSaveResumeState() const;
/// Returns true if fast forwarding or slow motion is currently active.
bool IsRunningAtNonStandardSpeed() const;

View file

@ -550,9 +550,7 @@ static void DoPowerOff()
if (!System::IsValid())
return;
if (g_settings.save_state_on_exit)
s_host_interface->SaveResumeSaveState();
s_host_interface->PowerOffSystem();
s_host_interface->PowerOffSystem(s_host_interface->ShouldSaveResumeState());
ReturnToMainWindow();
});

View file

@ -45,7 +45,7 @@ bool HTTPDownloaderWinHttp::Initialize()
if (WinHttpSetStatusCallback(m_hSession, HTTPStatusCallback, notification_flags, NULL) ==
WINHTTP_INVALID_STATUS_CALLBACK)
{
Log_ErrorPrint("WinHttpSetStatusCallback() failed: %u", GetLastError());
Log_ErrorPrintf("WinHttpSetStatusCallback() failed: %u", GetLastError());
return false;
}