From c03aa78c8f36184cae48e8fa0ac56e7c76d88d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 1 Oct 2017 18:31:19 +0200 Subject: [PATCH] [Cleanup] WX: Remove usage of NANDContentManager Also clean up the way the system menu label is updated. We don't want to access the NAND while emulation is running, and especially not that many times per second on an unpredictable timing. --- Source/Core/DolphinWX/Frame.cpp | 1 - Source/Core/DolphinWX/Frame.h | 3 -- Source/Core/DolphinWX/FrameTools.cpp | 22 +++++--------- Source/Core/DolphinWX/MainMenuBar.cpp | 41 ++++++++++++++++++--------- Source/Core/DolphinWX/MainMenuBar.h | 1 + 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index c4f9cd7dd1..6a1c3a0c53 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -501,7 +501,6 @@ void CFrame::BindEvents() Bind(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, &CFrame::OnReloadThemeBitmaps, this); Bind(DOLPHIN_EVT_REFRESH_GAMELIST, &CFrame::OnRefreshGameList, this); Bind(DOLPHIN_EVT_RESCAN_GAMELIST, &CFrame::OnRescanGameList, this); - Bind(DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM, &CFrame::OnUpdateLoadWiiMenuItem, this); Bind(DOLPHIN_EVT_BOOT_SOFTWARE, &CFrame::OnPlay, this); Bind(DOLPHIN_EVT_STOP_SOFTWARE, &CFrame::OnStop, this); } diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index 24cb56a94b..30f86ae6dc 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -275,9 +275,6 @@ private: void OnUpdateInterpreterMenuItem(wxUpdateUIEvent& event); - void OnUpdateLoadWiiMenuItem(wxCommandEvent&); - void UpdateLoadWiiMenuItem() const; - void OnOpen(wxCommandEvent& event); // File menu void OnRefresh(wxCommandEvent& event); void OnBootDrive(wxCommandEvent& event); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 7ec4cb0da1..7cd566b80e 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -652,6 +652,7 @@ void CFrame::StartGame(std::unique_ptr boot) if (m_is_game_loading) return; m_is_game_loading = true; + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); GetToolBar()->EnableTool(IDM_PLAY, false); GetMenuBar()->FindItem(IDM_PLAY)->Enable(false); @@ -925,6 +926,7 @@ void CFrame::OnStopped() m_confirm_stop = false; m_is_game_loading = false; m_tried_graceful_shutdown = false; + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); UninhibitScreensaver(); @@ -1131,11 +1133,6 @@ void CFrame::OnUpdateInterpreterMenuItem(wxUpdateUIEvent& event) event.Check(SConfig::GetInstance().iCPUCore == PowerPC::CORE_INTERPRETER); } -void CFrame::OnUpdateLoadWiiMenuItem(wxCommandEvent& WXUNUSED(event)) -{ - UpdateLoadWiiMenuItem(); -} - void CFrame::ClearStatusBar() { if (this->GetStatusBar()->IsEnabled()) @@ -1260,7 +1257,7 @@ void CFrame::OnInstallWAD(wxCommandEvent& event) wxPD_REMAINING_TIME | wxPD_SMOOTH); if (WiiUtils::InstallWAD(fileName)) - UpdateLoadWiiMenuItem(); + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); } void CFrame::OnUninstallWAD(wxCommandEvent&) @@ -1284,7 +1281,7 @@ void CFrame::OnUninstallWAD(wxCommandEvent&) } if (title_id == Titles::SYSTEM_MENU) - UpdateLoadWiiMenuItem(); + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); } void CFrame::OnImportBootMiiBackup(wxCommandEvent& WXUNUSED(event)) @@ -1306,7 +1303,7 @@ void CFrame::OnImportBootMiiBackup(wxCommandEvent& WXUNUSED(event)) wxProgressDialog dialog(_("Importing NAND backup"), _("Working..."), 100, this, wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_SMOOTH); DiscIO::NANDImporter().ImportNANDBin(file_name, [&dialog] { dialog.Pulse(); }); - UpdateLoadWiiMenuItem(); + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); } void CFrame::OnCheckNAND(wxCommandEvent&) @@ -1462,7 +1459,7 @@ void CFrame::OnPerformOnlineWiiUpdate(wxCommandEvent& event) const WiiUtils::UpdateResult result = ShowUpdateProgress(this, WiiUtils::DoOnlineUpdate, region); ShowUpdateResult(result); - UpdateLoadWiiMenuItem(); + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); } void CFrame::OnPerformDiscWiiUpdate(wxCommandEvent&) @@ -1475,12 +1472,7 @@ void CFrame::OnPerformDiscWiiUpdate(wxCommandEvent&) const WiiUtils::UpdateResult result = ShowUpdateProgress(this, WiiUtils::DoDiscUpdate, file_name); ShowUpdateResult(result); - UpdateLoadWiiMenuItem(); -} - -void CFrame::UpdateLoadWiiMenuItem() const -{ - GetMenuBar()->Refresh(true, nullptr); + wxPostEvent(GetMenuBar(), wxCommandEvent{DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM}); } void CFrame::OnFifoPlayer(wxCommandEvent& WXUNUSED(event)) diff --git a/Source/Core/DolphinWX/MainMenuBar.cpp b/Source/Core/DolphinWX/MainMenuBar.cpp index fdb6b633c6..18eb27002c 100644 --- a/Source/Core/DolphinWX/MainMenuBar.cpp +++ b/Source/Core/DolphinWX/MainMenuBar.cpp @@ -11,10 +11,12 @@ #include "Core/CommonTitles.h" #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/IOS/ES/ES.h" +#include "Core/IOS/ES/Formats.h" #include "Core/PowerPC/PowerPC.h" #include "Core/State.h" #include "DiscIO/Enums.h" -#include "DiscIO/NANDContentLoader.h" +#include "DolphinWX/Frame.h" #include "DolphinWX/Globals.h" #include "DolphinWX/WxUtils.h" @@ -30,6 +32,7 @@ MainMenuBar::MainMenuBar(MenuType type, long style) : wxMenuBar{style}, m_type{t { BindEvents(); AddMenus(); + RefreshWiiSystemMenuLabel(); } void MainMenuBar::Refresh(bool erase_background, const wxRect* rect) @@ -62,6 +65,7 @@ void MainMenuBar::AddMenus() void MainMenuBar::BindEvents() { Bind(EVT_POPULATE_PERSPECTIVES_MENU, &MainMenuBar::OnPopulatePerspectivesMenu, this); + Bind(DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM, &MainMenuBar::OnUpdateWiiMenuTool, this); } wxMenu* MainMenuBar::CreateFileMenu() const @@ -582,16 +586,11 @@ void MainMenuBar::RefreshWiiToolsLabels() const // result in the emulated software being confused, or even worse, exported saves having // inconsistent data. const bool enable_wii_tools = !Core::IsRunning() || !SConfig::GetInstance().bWii; - for (const int index : - {IDM_MENU_INSTALL_WAD, IDM_EXPORT_ALL_SAVE, IDM_IMPORT_SAVE, IDM_IMPORT_NAND, IDM_CHECK_NAND, - IDM_EXTRACT_CERTIFICATES, IDM_LOAD_WII_MENU, IDM_PERFORM_ONLINE_UPDATE_CURRENT, - IDM_PERFORM_ONLINE_UPDATE_EUR, IDM_PERFORM_ONLINE_UPDATE_JPN, IDM_PERFORM_ONLINE_UPDATE_KOR, - IDM_PERFORM_ONLINE_UPDATE_USA}) + for (const int index : {IDM_MENU_INSTALL_WAD, IDM_EXPORT_ALL_SAVE, IDM_IMPORT_SAVE, + IDM_IMPORT_NAND, IDM_CHECK_NAND, IDM_EXTRACT_CERTIFICATES}) { FindItem(index)->Enable(enable_wii_tools); } - if (enable_wii_tools) - RefreshWiiSystemMenuLabel(); } void MainMenuBar::EnableUpdateMenu(UpdateMenuMode mode) const @@ -608,12 +607,23 @@ void MainMenuBar::RefreshWiiSystemMenuLabel() const { auto* const item = FindItem(IDM_LOAD_WII_MENU); - const auto& sys_menu_loader = DiscIO::NANDContentManager::Access().GetNANDLoader( - Titles::SYSTEM_MENU, Common::FROM_CONFIGURED_ROOT); - - if (sys_menu_loader.IsValid()) + if (Core::IsRunning()) { - const u16 version_number = sys_menu_loader.GetTMD().GetTitleVersion(); + item->Enable(false); + for (const int idm : {IDM_PERFORM_ONLINE_UPDATE_CURRENT, IDM_PERFORM_ONLINE_UPDATE_EUR, + IDM_PERFORM_ONLINE_UPDATE_JPN, IDM_PERFORM_ONLINE_UPDATE_KOR, + IDM_PERFORM_ONLINE_UPDATE_USA}) + { + FindItem(idm)->Enable(false); + } + return; + } + + IOS::HLE::Kernel ios; + const IOS::ES::TMDReader sys_menu_tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU); + if (sys_menu_tmd.IsValid()) + { + const u16 version_number = sys_menu_tmd.GetTitleVersion(); const wxString version_string = StrToWxStr(DiscIO::GetSysMenuVersionString(version_number)); item->Enable(); item->SetItemLabel(wxString::Format(_("Load Wii System Menu %s"), version_string)); @@ -627,6 +637,11 @@ void MainMenuBar::RefreshWiiSystemMenuLabel() const } } +void MainMenuBar::OnUpdateWiiMenuTool(wxCommandEvent&) +{ + RefreshWiiSystemMenuLabel(); +} + void MainMenuBar::ClearSavedPerspectivesMenu() const { while (m_saved_perspectives_menu->GetMenuItemCount() != 0) diff --git a/Source/Core/DolphinWX/MainMenuBar.h b/Source/Core/DolphinWX/MainMenuBar.h index d7e3d692dc..ab786c637f 100644 --- a/Source/Core/DolphinWX/MainMenuBar.h +++ b/Source/Core/DolphinWX/MainMenuBar.h @@ -42,6 +42,7 @@ private: wxMenu* CreateHelpMenu() const; void OnPopulatePerspectivesMenu(PopulatePerspectivesEvent&); + void OnUpdateWiiMenuTool(wxCommandEvent&); void RefreshMenuLabels() const; void RefreshPlayMenuLabel() const;