From 0fdae2adb8067594ee182c2d944fd07a9e7426ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 4 Jul 2017 17:38:25 +0200 Subject: UI: Refactor Wii update code This moves the progress dialog logic and the result dialog to separate functions that can easily be reused for disc updates. --- Source/Core/DolphinWX/FrameTools.cpp | 86 ++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 32 deletions(-) (limited to 'Source/Core/DolphinWX/FrameTools.cpp') diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 787f5ae1c1..870cb6f28b 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -1320,39 +1320,9 @@ static std::string GetUpdateRegionFromIdm(int idm) } } -void CFrame::OnPerformOnlineWiiUpdate(wxCommandEvent& event) +static void ShowUpdateResult(WiiUtils::UpdateResult result) { - int confirm = wxMessageBox(_("Connect to the Internet and perform an online system update?"), - _("System Update"), wxYES_NO, this); - if (confirm != wxYES) - return; - - wxProgressDialog dialog(_("Updating"), _("Preparing to update...\nThis can take a while."), 1, - this, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_SMOOTH | wxPD_CAN_ABORT); - - const std::string region = GetUpdateRegionFromIdm(event.GetId()); - std::future result = std::async(std::launch::async, [&] { - const WiiUtils::UpdateResult res = WiiUtils::DoOnlineUpdate( - [&](size_t processed, size_t total, u64 title_id) { - Core::QueueHostJob( - [&dialog, processed, total, title_id] { - dialog.SetRange(total); - dialog.Update(processed, wxString::Format(_("Updating title %016" PRIx64 "...\n" - "This can take a while."), - title_id)); - dialog.Fit(); - }, - true); - return !dialog.WasCancelled(); - }, - region); - Core::QueueHostJob([&dialog] { dialog.EndModal(0); }, true); - return res; - }); - - dialog.ShowModal(); - - switch (result.get()) + switch (result) { case WiiUtils::UpdateResult::Succeeded: wxMessageBox(_("The emulated Wii console has been updated."), _("Update completed"), @@ -1384,8 +1354,60 @@ void CFrame::OnPerformOnlineWiiUpdate(wxCommandEvent& event) "finish it in order to avoid inconsistent system software versions."), _("Update cancelled"), wxOK | wxICON_WARNING); break; + case WiiUtils::UpdateResult::RegionMismatch: + wxMessageBox(_("The game's region does not match your console's. " + "To avoid issues with the system menu, it is not possible to update " + "the emulated console using this disc."), + _("Update failed"), wxOK | wxICON_ERROR); + break; + case WiiUtils::UpdateResult::MissingUpdatePartition: + case WiiUtils::UpdateResult::DiscReadFailed: + wxMessageBox(_("The game disc does not contain any usable update information."), + _("Update failed"), wxOK | wxICON_ERROR); + break; } +} + +template +static WiiUtils::UpdateResult ShowUpdateProgress(CFrame* frame, Callable function, Args&&... args) +{ + wxProgressDialog dialog(_("Updating"), _("Preparing to update...\nThis can take a while."), 1, + frame, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_SMOOTH | wxPD_CAN_ABORT); + + std::future result = std::async(std::launch::async, [&] { + const WiiUtils::UpdateResult res = function( + [&](size_t processed, size_t total, u64 title_id) { + Core::QueueHostJob( + [&dialog, processed, total, title_id] { + dialog.SetRange(total); + dialog.Update(processed, wxString::Format(_("Updating title %016" PRIx64 "...\n" + "This can take a while."), + title_id)); + dialog.Fit(); + }, + true); + return !dialog.WasCancelled(); + }, + std::forward(args)...); + Core::QueueHostJob([&dialog] { dialog.EndModal(0); }, true); + return res; + }); + + dialog.ShowModal(); + return result.get(); +} + +void CFrame::OnPerformOnlineWiiUpdate(wxCommandEvent& event) +{ + int confirm = wxMessageBox(_("Connect to the Internet and perform an online system update?"), + _("System Update"), wxYES_NO, this); + if (confirm != wxYES) + return; + + const std::string region = GetUpdateRegionFromIdm(event.GetId()); + const WiiUtils::UpdateResult result = ShowUpdateProgress(this, WiiUtils::DoOnlineUpdate, region); + ShowUpdateResult(result); UpdateLoadWiiMenuItem(); } -- cgit v1.2.3 From 0e71c0760e1a95c495bb9ecc004eb9e50596abfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 4 Jul 2017 18:23:25 +0200 Subject: WX: Add menu item to perform system update from disc --- Source/Core/DolphinWX/FrameTools.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Source/Core/DolphinWX/FrameTools.cpp') diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 870cb6f28b..b2d8622ac9 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -1411,6 +1411,19 @@ void CFrame::OnPerformOnlineWiiUpdate(wxCommandEvent& event) UpdateLoadWiiMenuItem(); } +void CFrame::OnPerformDiscWiiUpdate(wxCommandEvent&) +{ + const GameListItem* iso = m_game_list_ctrl->GetSelectedISO(); + if (!iso) + return; + + const std::string file_name = iso->GetFileName(); + + const WiiUtils::UpdateResult result = ShowUpdateProgress(this, WiiUtils::DoDiscUpdate, file_name); + ShowUpdateResult(result); + UpdateLoadWiiMenuItem(); +} + void CFrame::UpdateLoadWiiMenuItem() const { GetMenuBar()->Refresh(true, nullptr); -- cgit v1.2.3