Partially revert "Revert "Audit uses of IsRunning and GetState""

This reverts the revert commit bc67fc97c3,
except for the changes in BaseConfigLoader.cpp, which caused the bug
that made us revert 72cf2bdb87. PR 12917
contains an improved change to BaseConfigLoader.cpp, which can be merged
(or rejected) independently.

A few changes have also been made based on review comments.
This commit is contained in:
JosJuice
2024-07-02 17:27:04 +02:00
parent 2da3e49b1e
commit 6ca2da53e8
33 changed files with 143 additions and 114 deletions

View File

@ -138,9 +138,11 @@ void MenuBar::OnEmulationStateChanged(Core::State state)
m_recording_stop->setEnabled(false);
m_recording_export->setEnabled(false);
}
m_recording_play->setEnabled(m_game_selected && !running);
m_recording_play->setEnabled(m_game_selected && !running && !hardcore);
m_recording_start->setEnabled((m_game_selected || running) &&
const bool can_start_from_boot = m_game_selected && state == Core::State::Uninitialized;
const bool can_start_from_savestate =
state == Core::State::Running || state == Core::State::Paused;
m_recording_play->setEnabled(can_start_from_boot && !hardcore);
m_recording_start->setEnabled((can_start_from_boot || can_start_from_savestate) &&
!Core::System::GetInstance().GetMovie().IsPlayingInput());
// JIT
@ -159,7 +161,7 @@ void MenuBar::OnEmulationStateChanged(Core::State state)
m_symbols->setEnabled(running);
UpdateStateSlotMenu();
UpdateToolsMenu(running);
UpdateToolsMenu(state);
OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled());
}
@ -297,7 +299,8 @@ void MenuBar::AddToolsMenu()
m_boot_sysmenu->setEnabled(false);
connect(&Settings::Instance(), &Settings::NANDRefresh, this, [this] { UpdateToolsMenu(false); });
connect(&Settings::Instance(), &Settings::NANDRefresh, this,
[this] { UpdateToolsMenu(Core::State::Uninitialized); });
m_perform_online_update_menu = tools_menu->addMenu(tr("Perform Online System Update"));
m_perform_online_update_for_current_region = m_perform_online_update_menu->addAction(
@ -1051,20 +1054,23 @@ void MenuBar::AddSymbolsMenu()
m_symbols->addAction(tr("&Patch HLE Functions"), this, &MenuBar::PatchHLEFunctions);
}
void MenuBar::UpdateToolsMenu(bool emulation_started)
void MenuBar::UpdateToolsMenu(const Core::State state)
{
m_boot_sysmenu->setEnabled(!emulation_started);
m_perform_online_update_menu->setEnabled(!emulation_started);
m_ntscj_ipl->setEnabled(!emulation_started && File::Exists(Config::GetBootROMPath(JAP_DIR)));
m_ntscu_ipl->setEnabled(!emulation_started && File::Exists(Config::GetBootROMPath(USA_DIR)));
m_pal_ipl->setEnabled(!emulation_started && File::Exists(Config::GetBootROMPath(EUR_DIR)));
m_wad_install_action->setEnabled(!emulation_started);
m_import_backup->setEnabled(!emulation_started);
m_check_nand->setEnabled(!emulation_started);
m_import_wii_save->setEnabled(!emulation_started);
m_export_wii_saves->setEnabled(!emulation_started);
const bool is_uninitialized = state == Core::State::Uninitialized;
const bool is_running = state == Core::State::Running || state == Core::State::Paused;
if (!emulation_started)
m_boot_sysmenu->setEnabled(is_uninitialized);
m_perform_online_update_menu->setEnabled(is_uninitialized);
m_ntscj_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(JAP_DIR)));
m_ntscu_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(USA_DIR)));
m_pal_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(EUR_DIR)));
m_wad_install_action->setEnabled(is_uninitialized);
m_import_backup->setEnabled(is_uninitialized);
m_check_nand->setEnabled(is_uninitialized);
m_import_wii_save->setEnabled(is_uninitialized);
m_export_wii_saves->setEnabled(is_uninitialized);
if (is_uninitialized)
{
IOS::HLE::Kernel ios;
const auto tmd = ios.GetESCore().FindInstalledTMD(Titles::SYSTEM_MENU);
@ -1087,7 +1093,7 @@ void MenuBar::UpdateToolsMenu(bool emulation_started)
}
const auto bt = WiiUtils::GetBluetoothEmuDevice();
const bool enable_wiimotes = emulation_started && bt != nullptr;
const bool enable_wiimotes = is_running && bt != nullptr;
for (std::size_t i = 0; i < m_wii_remotes.size(); i++)
{
@ -1258,16 +1264,20 @@ void MenuBar::OnSelectionChanged(std::shared_ptr<const UICommon::GameFile> game_
m_game_selected = !!game_file;
auto& system = Core::System::GetInstance();
const bool core_is_running = Core::IsRunning(system);
m_recording_play->setEnabled(m_game_selected && !core_is_running);
m_recording_start->setEnabled((m_game_selected || core_is_running) &&
const bool can_start_from_boot = m_game_selected && Core::IsUninitialized(system);
const bool can_start_from_savestate = Core::IsRunning(system);
m_recording_play->setEnabled(can_start_from_boot);
m_recording_start->setEnabled((can_start_from_boot || can_start_from_savestate) &&
!system.GetMovie().IsPlayingInput());
}
void MenuBar::OnRecordingStatusChanged(bool recording)
{
auto& system = Core::System::GetInstance();
m_recording_start->setEnabled(!recording && (m_game_selected || Core::IsRunning(system)));
const bool can_start_from_boot = m_game_selected && Core::IsUninitialized(system);
const bool can_start_from_savestate = Core::IsRunning(system);
m_recording_start->setEnabled(!recording && (can_start_from_boot || can_start_from_savestate));
m_recording_stop->setEnabled(recording);
m_recording_export->setEnabled(recording);
}