Qt: Add menu item to perform online update

This commit is contained in:
Léo Lam 2017-06-14 11:58:11 +02:00
parent f06367febc
commit 1a6b5ca36a
8 changed files with 187 additions and 1 deletions

View File

@ -19,6 +19,8 @@ set(SRCS
Resources.cpp
Settings.cpp
ToolBar.cpp
WiiUpdate.cpp
WiiUpdate.h
Config/ControllersWindow.cpp
Config/FilesystemWidget.cpp
Config/InfoWidget.cpp

View File

@ -164,6 +164,7 @@
<ClCompile Include="Settings\InterfacePane.cpp" />
<ClCompile Include="Settings\PathPane.cpp" />
<ClCompile Include="ToolBar.cpp" />
<ClCompile Include="WiiUpdate.cpp" />
</ItemGroup>
<!--Put standard C/C++ headers here-->
<ItemGroup>
@ -185,6 +186,7 @@
<ClInclude Include="QtUtils\ElidedButton.h" />
<ClInclude Include="Resources.h" />
<ClInclude Include="Settings\PathPane.h" />
<ClInclude Include="WiiUpdate.h" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />

View File

@ -30,7 +30,6 @@
#include "DolphinQt2/AboutDialog.h"
#include "DolphinQt2/Config/ControllersWindow.h"
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
#include "DolphinQt2/Config/SettingsWindow.h"
#include "DolphinQt2/Host.h"
@ -39,6 +38,7 @@
#include "DolphinQt2/QtUtils/WindowActivationEventFilter.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/WiiUpdate.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
@ -165,6 +165,9 @@ void MainWindow::ConnectMenuBar()
// Options
connect(m_menu_bar, &MenuBar::ConfigureHotkeys, this, &MainWindow::ShowHotkeyDialog);
// Tools
connect(m_menu_bar, &MenuBar::PerformOnlineUpdate, this, &MainWindow::PerformOnlineUpdate);
// View
connect(m_menu_bar, &MenuBar::ShowTable, m_game_list, &GameList::SetTableView);
connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView);
@ -530,6 +533,13 @@ void MainWindow::SetStateSlot(int slot)
m_state_slot = slot;
}
void MainWindow::PerformOnlineUpdate(const std::string& region)
{
WiiUpdate::PerformOnlineUpdate(region, this);
// Since the update may have installed a newer system menu, refresh the tools menu.
m_menu_bar->UpdateToolsMenu(false);
}
bool MainWindow::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::Close && !Stop())

View File

@ -56,6 +56,8 @@ private slots:
void StateSaveOldest();
void SetStateSlot(int slot);
void PerformOnlineUpdate(const std::string& region);
void FullScreen();
void ScreenShot();

View File

@ -9,6 +9,9 @@
#include <QMessageBox>
#include <QUrl>
#include "Core/CommonTitles.h"
#include "Core/IOS/ES/ES.h"
#include "Core/IOS/IOS.h"
#include "Core/State.h"
#include "DolphinQt2/AboutDialog.h"
#include "DolphinQt2/GameList/GameFile.h"
@ -43,6 +46,7 @@ void MenuBar::EmulationStarted()
m_state_load_menu->setEnabled(true);
m_state_save_menu->setEnabled(true);
UpdateStateSlotMenu();
UpdateToolsMenu(true);
}
void MenuBar::EmulationPaused()
{
@ -66,6 +70,7 @@ void MenuBar::EmulationStopped()
m_state_load_menu->setEnabled(false);
m_state_save_menu->setEnabled(false);
UpdateStateSlotMenu();
UpdateToolsMenu(false);
}
void MenuBar::AddFileMenu()
@ -79,6 +84,17 @@ void MenuBar::AddToolsMenu()
{
QMenu* tools_menu = addMenu(tr("Tools"));
m_wad_install_action = tools_menu->addAction(tr("Install WAD..."), this, SLOT(InstallWAD()));
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(
tr("Current Region"), [this] { emit PerformOnlineUpdate(""); });
m_perform_online_update_menu->addSeparator();
m_perform_online_update_menu->addAction(tr("Europe"),
[this] { emit PerformOnlineUpdate("EUR"); });
m_perform_online_update_menu->addAction(tr("Japan"), [this] { emit PerformOnlineUpdate("JPN"); });
m_perform_online_update_menu->addAction(tr("Korea"), [this] { emit PerformOnlineUpdate("KOR"); });
m_perform_online_update_menu->addAction(tr("United States"),
[this] { emit PerformOnlineUpdate("USA"); });
}
void MenuBar::AddEmulationMenu()
@ -248,6 +264,20 @@ void MenuBar::AddTableColumnsMenu(QMenu* view_menu)
}
}
void MenuBar::UpdateToolsMenu(bool emulation_started)
{
const bool enable_wii_tools = !emulation_started || !Settings::Instance().IsWiiGameRunning();
m_perform_online_update_menu->setEnabled(enable_wii_tools);
if (enable_wii_tools)
{
IOS::HLE::Kernel ios;
const auto tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
for (QAction* action : m_perform_online_update_menu->actions())
action->setEnabled(!tmd.IsValid());
m_perform_online_update_for_current_region->setEnabled(tmd.IsValid());
}
}
void MenuBar::InstallWAD()
{
QString wad_file = QFileDialog::getOpenFileName(this, tr("Select a title to install to NAND"),

View File

@ -4,6 +4,8 @@
#pragma once
#include <string>
#include <QMenu>
#include <QMenuBar>
@ -38,6 +40,8 @@ signals:
void StateSaveOldest();
void SetStateSlot(int slot);
void PerformOnlineUpdate(const std::string& region);
// Options
void ConfigureHotkeys();
@ -53,6 +57,7 @@ public slots:
void EmulationPaused();
void EmulationStopped();
void UpdateStateSlotMenu();
void UpdateToolsMenu(bool emulation_started);
// Tools
void InstallWAD();
@ -79,6 +84,8 @@ private:
// Tools
QAction* m_wad_install_action;
QMenu* m_perform_online_update_menu;
QAction* m_perform_online_update_for_current_region;
// Emulation
QAction* m_play_action;

View File

@ -0,0 +1,119 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt2/WiiUpdate.h"
#include <cinttypes>
#include <future>
#include <QCloseEvent>
#include <QMessageBox>
#include <QObject>
#include <QProgressDialog>
#include <QPushButton>
#include "Common/FileUtil.h"
#include "Common/Flag.h"
#include "Core/Core.h"
#include "Core/WiiUtils.h"
#include "DiscIO/NANDImporter.h"
namespace WiiUpdate
{
void PerformOnlineUpdate(const std::string& region, QWidget* parent)
{
const int confirm = QMessageBox::question(
parent, QObject::tr("Confirm"),
QObject::tr("Connect to the Internet and perform an online system update?"));
if (confirm != QMessageBox::Yes)
return;
// Do not allow the user to close the dialog. Instead, wait until the update is finished
// or cancelled.
class UpdateProgressDialog final : public QProgressDialog
{
public:
using QProgressDialog::QProgressDialog;
protected:
void reject() override {}
};
UpdateProgressDialog dialog{parent};
dialog.setLabelText(QObject::tr("Preparing to update...\nThis can take a while."));
dialog.setWindowTitle(QObject::tr("Updating"));
// QProgressDialog doesn't set its minimum size correctly.
dialog.setMinimumSize(360, 150);
// QProgressDialog doesn't allow us to disable the cancel button when it's pressed,
// so we have to pass it our own push button. Note: the dialog takes ownership of it.
auto* cancel_button = new QPushButton(QObject::tr("&Cancel"), parent);
dialog.setCancelButton(cancel_button);
Common::Flag was_cancelled;
QObject::disconnect(&dialog, &QProgressDialog::canceled, &dialog, &QProgressDialog::cancel);
QObject::connect(&dialog, &QProgressDialog::canceled, [&] {
dialog.setLabelText(QObject::tr("Finishing the update...\nThis can take a while."));
cancel_button->setEnabled(false);
was_cancelled.Set();
});
std::future<WiiUtils::UpdateResult> result = std::async(std::launch::async, [&] {
const WiiUtils::UpdateResult res = WiiUtils::DoOnlineUpdate(
[&](size_t processed, size_t total, u64 title_id) {
Core::QueueHostJob(
[&dialog, &was_cancelled, processed, total, title_id]() {
if (was_cancelled.IsSet())
return;
dialog.setRange(0, static_cast<int>(total));
dialog.setValue(static_cast<int>(processed));
dialog.setLabelText(QObject::tr("Updating title %1...\nThis can take a while.")
.arg(title_id, 16, 16, QLatin1Char('0')));
},
true);
return !was_cancelled.IsSet();
},
region);
Core::QueueHostJob([&dialog] { dialog.close(); }, true);
return res;
});
dialog.exec();
switch (result.get())
{
case WiiUtils::UpdateResult::Succeeded:
QMessageBox::information(parent, QObject::tr("Update completed"),
QObject::tr("The emulated Wii console has been updated."));
DiscIO::NANDImporter().ExtractCertificates(File::GetUserPath(D_WIIROOT_IDX));
break;
case WiiUtils::UpdateResult::AlreadyUpToDate:
QMessageBox::information(parent, QObject::tr("Update completed"),
QObject::tr("The emulated Wii console is already up-to-date."));
DiscIO::NANDImporter().ExtractCertificates(File::GetUserPath(D_WIIROOT_IDX));
break;
case WiiUtils::UpdateResult::ServerFailed:
QMessageBox::critical(parent, QObject::tr("Update failed"),
QObject::tr("Could not download update information from Nintendo. "
"Please check your Internet connection and try again."));
break;
case WiiUtils::UpdateResult::DownloadFailed:
QMessageBox::critical(parent, QObject::tr("Update failed"),
QObject::tr("Could not download update files from Nintendo. "
"Please check your Internet connection and try again."));
break;
case WiiUtils::UpdateResult::ImportFailed:
QMessageBox::critical(parent, QObject::tr("Update failed"),
QObject::tr("Could not install an update to the Wii system memory. "
"Please refer to logs for more information."));
break;
case WiiUtils::UpdateResult::Cancelled:
QMessageBox::warning(
parent, QObject::tr("Update cancelled"),
QObject::tr("The update has been cancelled. It is strongly recommended to "
"finish it in order to avoid inconsistent system software versions."));
break;
}
}
}; // namespace WiiUpdate

View File

@ -0,0 +1,14 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
class QWidget;
namespace WiiUpdate
{
void PerformOnlineUpdate(const std::string& region, QWidget* parent = nullptr);
}; // namespace WiiUpdate