From 202aed560b616042df5cd3e0838f43ef95b31f93 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 22 Jul 2021 23:38:26 +0200 Subject: [PATCH] Qt: add option to auto install updates --- rpcs3/rpcs3qt/gui_settings.h | 7 ++++++- rpcs3/rpcs3qt/main_window.cpp | 9 +++++---- rpcs3/rpcs3qt/settings_dialog.cpp | 11 ++++------- rpcs3/rpcs3qt/tooltips.h | 2 +- rpcs3/rpcs3qt/update_manager.cpp | 27 +++++++++++++++------------ rpcs3/rpcs3qt/update_manager.h | 8 ++++---- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index 5bcd4fbc17..160eca22bd 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -111,6 +111,11 @@ namespace gui const QString patches = "Patches"; const QString localization = "Localization"; const QString pad_settings = "PadSettings"; + + const QString update_on = "true"; + const QString update_off = "false"; + const QString update_auto = "auto"; + const QString update_bkg = "background"; const QColor gl_icon_color = QColor(240, 240, 240, 255); @@ -197,7 +202,7 @@ namespace gui const gui_save m_enableUIColors = gui_save(meta, "enableUIColors", false); const gui_save m_richPresence = gui_save(meta, "useRichPresence", true); const gui_save m_discordState = gui_save(meta, "discordState", ""); - const gui_save m_check_upd_start = gui_save(meta, "checkUpdateStart", true); + const gui_save m_check_upd_start = gui_save(meta, "checkUpdateStart", update_on); const gui_save gs_disableMouse = gui_save(gs_frame, "disableMouse", false); const gui_save gs_disableKbHotkeys = gui_save(gs_frame, "disableKbHotkeys", false); diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 2407a9729a..216390476c 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -196,7 +196,7 @@ bool main_window::Init(bool with_cli_boot) QAction *download_action = new QAction(tr("Download Update"), download_menu); connect(download_action, &QAction::triggered, this, [this] { - m_updater.update(); + m_updater.update(false); }); download_menu->addAction(download_action); @@ -229,10 +229,11 @@ bool main_window::Init(bool with_cli_boot) }); #if defined(_WIN32) || defined(__linux__) - if (const auto update_value = m_gui_settings->GetValue(gui::m_check_upd_start).toString(); update_value != "false") + if (const auto update_value = m_gui_settings->GetValue(gui::m_check_upd_start).toString(); update_value != gui::update_off) { - const bool in_background = with_cli_boot || update_value != "true"; - m_updater.check_for_updates(true, in_background, this); + const bool in_background = with_cli_boot || update_value == gui::update_bkg; + const bool auto_accept = !in_background && update_value == gui::update_auto; + m_updater.check_for_updates(true, in_background, auto_accept, this); } #endif diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index b8f40c76c8..78ad5859a8 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -1595,13 +1595,10 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std ui->cb_show_pup_install->setChecked(m_gui_settings->GetValue(gui::ib_pup_success).toBool()); ui->cb_show_obsolete_cfg_dialog->setChecked(m_gui_settings->GetValue(gui::ib_obsolete_cfg).toBool()); - const QString updates_yes = tr("Yes", "Updates"); - const QString updates_background = tr("Background", "Updates"); - const QString updates_no = tr("No", "Updates"); - - ui->combo_updates->addItem(updates_yes, "true"); - ui->combo_updates->addItem(updates_background, "background"); - ui->combo_updates->addItem(updates_no, "false"); + ui->combo_updates->addItem(tr("Yes", "Updates"), gui::update_on); + ui->combo_updates->addItem(tr("Background", "Updates"), gui::update_bkg); + ui->combo_updates->addItem(tr("Automatic", "Updates"), gui::update_auto); + ui->combo_updates->addItem(tr("No", "Updates"), gui::update_off); ui->combo_updates->setCurrentIndex(ui->combo_updates->findData(m_gui_settings->GetValue(gui::m_check_upd_start).toString())); connect(ui->combo_updates, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) { diff --git a/rpcs3/rpcs3qt/tooltips.h b/rpcs3/rpcs3qt/tooltips.h index ff851b87f7..de3b129f6e 100644 --- a/rpcs3/rpcs3qt/tooltips.h +++ b/rpcs3/rpcs3qt/tooltips.h @@ -178,7 +178,7 @@ public: const QString show_pkg_install = tr("Shows a dialog when packages were installed successfully."); const QString show_pup_install = tr("Shows a dialog when firmware was installed successfully."); const QString show_obsolete_cfg = tr("Shows a dialog when obsolete settings were found."); - const QString check_update_start = tr("Checks if an update is available on startup and asks if you want to update.\nIf \"Background\" is selected, the check is done silently in the background and a new download option is shown in the top right corner of the menu if a new version was found."); + const QString check_update_start = tr("Checks if an update is available on startup and asks if you want to update.\nIf \"Automatic\" is selected, the update will run automatically without user confirmation.\nIf \"Background\" is selected, the check is done silently in the background and a new download option is shown in the top right corner of the menu if a new version was found."); const QString use_rich_presence = tr("Enables use of Discord Rich Presence to show what game you are playing on Discord.\nRequires a restart of RPCS3 to completely close the connection."); const QString discord_state = tr("Tell your friends what you are doing."); const QString custom_colors = tr("Prioritize custom user interface colors over properties set in stylesheet."); diff --git a/rpcs3/rpcs3qt/update_manager.cpp b/rpcs3/rpcs3qt/update_manager.cpp index 1202489172..69c5bcc7e1 100644 --- a/rpcs3/rpcs3qt/update_manager.cpp +++ b/rpcs3/rpcs3qt/update_manager.cpp @@ -36,7 +36,7 @@ LOG_CHANNEL(update_log, "UPDATER"); -void update_manager::check_for_updates(bool automatic, bool check_only, QWidget* parent) +void update_manager::check_for_updates(bool automatic, bool check_only, bool auto_accept, QWidget* parent) { m_update_message.clear(); @@ -59,9 +59,9 @@ void update_manager::check_for_updates(bool automatic, bool check_only, QWidget* } }); - connect(m_downloader, &downloader::signal_download_finished, this, [this, automatic, check_only](const QByteArray& data) + connect(m_downloader, &downloader::signal_download_finished, this, [this, automatic, check_only, auto_accept](const QByteArray& data) { - const bool result_json = handle_json(automatic, check_only, data); + const bool result_json = handle_json(automatic, check_only, auto_accept, data); if (!result_json) { @@ -81,7 +81,7 @@ void update_manager::check_for_updates(bool automatic, bool check_only, QWidget* m_downloader->start(url, true, !automatic, tr("Checking For Updates"), true); } -bool update_manager::handle_json(bool automatic, bool check_only, const QByteArray& data) +bool update_manager::handle_json(bool automatic, bool check_only, bool auto_accept, const QByteArray& data) { const QJsonObject json_data = QJsonDocument::fromJson(data).object(); const int return_code = json_data["return_code"].toInt(-255); @@ -218,16 +218,16 @@ bool update_manager::handle_json(bool automatic, bool check_only, const QByteArr return true; } - update(); + update(auto_accept); return true; } -void update_manager::update() +void update_manager::update(bool auto_accept) { ensure(m_downloader); - if (m_update_message.isEmpty() || - QMessageBox::question(m_downloader->get_progress_dialog() ? m_downloader->get_progress_dialog() : m_parent, tr("Update Available"), m_update_message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) + if (!auto_accept && (m_update_message.isEmpty() || + QMessageBox::question(m_downloader->get_progress_dialog() ? m_downloader->get_progress_dialog() : m_parent, tr("Update Available"), m_update_message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) { m_downloader->close_progress_dialog(); return; @@ -247,9 +247,9 @@ void update_manager::update() QMessageBox::warning(m_parent, tr("Auto-updater"), tr("An error occurred during the auto-updating process.\nCheck the log for more information.")); }); - connect(m_downloader, &downloader::signal_download_finished, this, [this](const QByteArray& data) + connect(m_downloader, &downloader::signal_download_finished, this, [this, auto_accept](const QByteArray& data) { - const bool result_json = handle_rpcs3(data); + const bool result_json = handle_rpcs3(data, auto_accept); if (!result_json) { @@ -265,7 +265,7 @@ void update_manager::update() m_downloader->start(m_request_url, true, true, tr("Downloading Update"), true, m_expected_size); } -bool update_manager::handle_rpcs3(const QByteArray& data) +bool update_manager::handle_rpcs3(const QByteArray& data, bool auto_accept) { m_downloader->update_progress_dialog(tr("Updating RPCS3")); @@ -545,7 +545,10 @@ bool update_manager::handle_rpcs3(const QByteArray& data) m_downloader->close_progress_dialog(); - QMessageBox::information(m_parent, tr("Auto-updater"), tr("Update successful!\nRPCS3 will now restart.")); + if (!auto_accept) + { + QMessageBox::information(m_parent, tr("Auto-updater"), tr("Update successful!\nRPCS3 will now restart.")); + } Emu.SetForceBoot(true); Emu.Stop(); diff --git a/rpcs3/rpcs3qt/update_manager.h b/rpcs3/rpcs3qt/update_manager.h index 5e8b2a7bbd..146c470d20 100644 --- a/rpcs3/rpcs3qt/update_manager.h +++ b/rpcs3/rpcs3qt/update_manager.h @@ -23,13 +23,13 @@ private: std::string m_expected_hash; u64 m_expected_size = 0; - bool handle_json(bool automatic, bool check_only, const QByteArray& data); - bool handle_rpcs3(const QByteArray& data); + bool handle_json(bool automatic, bool check_only, bool auto_accept, const QByteArray& data); + bool handle_rpcs3(const QByteArray& data, bool auto_accept); public: update_manager() = default; - void check_for_updates(bool automatic, bool check_only, QWidget* parent = nullptr); - void update(); + void check_for_updates(bool automatic, bool check_only, bool auto_accept, QWidget* parent = nullptr); + void update(bool auto_accept); Q_SIGNALS: void signal_update_available(bool update_available);