diff --git a/android/app/src/cpp/android_host_interface.cpp b/android/app/src/cpp/android_host_interface.cpp index e8b6684b8..8bad12d5c 100644 --- a/android/app/src/cpp/android_host_interface.cpp +++ b/android/app/src/cpp/android_host_interface.cpp @@ -412,17 +412,12 @@ void AndroidHostInterface::EmulationThreadEntryPoint(JNIEnv* env, jobject emulat // Boot system. bool boot_result = false; - if (resume_state) - { - if (boot_params.filename.empty()) - boot_result = ResumeSystemFromMostRecentState(); - else - boot_result = ResumeSystemFromState(boot_params.filename.c_str(), true); - } + if (resume_state && boot_params.filename.empty()) + boot_result = ResumeSystemFromMostRecentState(); + else if (resume_state && CanResumeSystemFromFile(boot_params.filename.c_str())) + boot_result = ResumeSystemFromState(boot_params.filename.c_str(), true); else - { boot_result = BootSystem(boot_params); - } if (boot_result) { @@ -784,8 +779,8 @@ void AndroidHostInterface::SetControllerVibration(u32 controller_index, float sm DebugAssert(env); env->CallVoidMethod(m_emulation_activity_object, s_EmulationActivity_method_setInputDeviceVibration, - static_cast(controller_index), static_cast(small_motor), - static_cast(large_motor)); + static_cast(controller_index), static_cast(small_motor), + static_cast(large_motor)); } void AndroidHostInterface::SetFastForwardEnabled(bool enabled) @@ -1193,10 +1188,11 @@ DEFINE_JNI_ARGS_METHOD(jobjectArray, AndroidHostInterface_getControllerAxisNames return name_array; } -DEFINE_JNI_ARGS_METHOD(jint, AndroidHostInterface_getControllerVibrationMotorCount, jobject unused, jstring controller_type) +DEFINE_JNI_ARGS_METHOD(jint, AndroidHostInterface_getControllerVibrationMotorCount, jobject unused, + jstring controller_type) { std::optional type = - Settings::ParseControllerTypeName(AndroidHelpers::JStringToString(env, controller_type).c_str()); + Settings::ParseControllerTypeName(AndroidHelpers::JStringToString(env, controller_type).c_str()); if (!type) return 0; diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index cb6d3cdeb..c6927c654 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -939,20 +939,10 @@ void MainWindow::startGameOrChangeDiscs(const std::string& path) // if we're not running, boot the system, otherwise swap discs if (!m_emulation_running) { - if (m_host_interface->GetBoolSettingValue("Main", "SaveStateOnExit", true) && - !m_host_interface->IsCheevosChallengeModeActive()) - { - const GameListEntry* entry = m_host_interface->getGameList()->GetEntryForPath(path.c_str()); - if ((entry && !entry->code.empty()) || !System::GetGameCodeForPath(path.c_str(), true).empty()) - { - m_host_interface->resumeSystemFromState(QString::fromStdString(path), true); - return; - } - } + if (m_host_interface->CanResumeSystemFromFile(path.c_str())) + m_host_interface->resumeSystemFromState(QString::fromStdString(path), true); else - { m_host_interface->bootSystem(std::make_shared(path)); - } } else { diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 36c53fcba..c35e574d0 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -706,6 +706,20 @@ bool CommonHostInterface::SaveState(bool global, s32 slot) return true; } +bool CommonHostInterface::CanResumeSystemFromFile(const char* filename) +{ + if (GetBoolSettingValue("Main", "SaveStateOnExit", true) && !IsCheevosChallengeModeActive()) + { + const GameListEntry* entry = m_game_list->GetEntryForPath(filename); + if (entry) + return !entry->code.empty(); + else + return !System::GetGameCodeForPath(filename, true).empty(); + } + + return false; +} + bool CommonHostInterface::ResumeSystemFromState(const char* filename, bool boot_on_failure) { SystemBootParameters boot_params; diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index b61ea5974..e340f8c14 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -180,6 +180,9 @@ public: /// Saves the current emulation state to a file. Specifying a slot of -1 saves the "resume" save state. bool SaveState(bool global, s32 slot); + /// Returns true if the specified file/disc image is resumable. + bool CanResumeSystemFromFile(const char* filename); + /// Loads the resume save state for the given game. Optionally boots the game anyway if loading fails. bool ResumeSystemFromState(const char* filename, bool boot_on_failure);