Skip to content

Commit

Permalink
Qt: Add auto updater UI
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed May 12, 2022
1 parent a289723 commit 41f1ec4
Show file tree
Hide file tree
Showing 11 changed files with 846 additions and 9 deletions.
542 changes: 542 additions & 0 deletions pcsx2-qt/AutoUpdaterDialog.cpp

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions pcsx2-qt/AutoUpdaterDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2022 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include "ui_AutoUpdaterDialog.h"
#include <string>
#include <QtCore/QDateTime>
#include <QtCore/QStringList>
#include <QtWidgets/QDialog>

class QNetworkAccessManager;
class QNetworkReply;

class AutoUpdaterDialog final : public QDialog
{
Q_OBJECT

public:
explicit AutoUpdaterDialog(QWidget* parent = nullptr);
~AutoUpdaterDialog();

static bool isSupported();
static QStringList getTagList();
static std::string getDefaultTag();
static QString getCurrentVersion();
static QString getCurrentVersionDate();

Q_SIGNALS:
void updateCheckCompleted();

public Q_SLOTS:
void queueUpdateCheck(bool display_message);

private Q_SLOTS:
void getLatestReleaseComplete(QNetworkReply* reply);

void queueGetChanges();
void getChangesComplete(QNetworkReply* reply);

void downloadUpdateClicked();
void skipThisUpdateClicked();
void remindMeLaterClicked();

private:
void reportError(const char* msg, ...);
void checkIfUpdateNeeded();
QString getCurrentUpdateTag() const;

#ifdef _WIN32
bool processUpdate(const QByteArray& update_data);
bool doUpdate(const QString& zip_path, const QString& updater_path, const QString& destination_path);
#else
bool processUpdate(const QByteArray& update_data);
#endif

Ui::AutoUpdaterDialog m_ui;

QNetworkAccessManager* m_network_access_mgr = nullptr;
QString m_latest_version;
QDateTime m_latest_version_timestamp;
QString m_download_url;
int m_download_size = 0;

bool m_display_messages = false;
bool m_update_will_break_save_states = false;
};
132 changes: 132 additions & 0 deletions pcsx2-qt/AutoUpdaterDialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AutoUpdaterDialog</class>
<widget class="QDialog" name="AutoUpdaterDialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>651</width>
<height>474</height>
</rect>
</property>
<property name="windowTitle">
<string>Automatic Updater</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources/resources.qrc">:/icons/update.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>16</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Update Available</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="currentVersion">
<property name="text">
<string>Current Version: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="newVersion">
<property name="text">
<string>New Version: </string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="updateNotes"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="downloadAndInstall">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Download and Install...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="skipThisUpdate">
<property name="text">
<string>Skip This Update</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="remindMeLater">
<property name="text">
<string>Remind Me Later</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="resources/resources.qrc"/>
</resources>
<connections/>
</ui>
2 changes: 2 additions & 0 deletions pcsx2-qt/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ int main(int argc, char* argv[])

if (autoboot)
g_emu_thread->startVM(std::move(autoboot));
else
main_window->startupUpdateCheck();

const int result = app.exec();

Expand Down
62 changes: 61 additions & 1 deletion pcsx2-qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "pcsx2/PerformanceMetrics.h"

#include "AboutDialog.h"
#include "AutoUpdaterDialog.h"
#include "DisplayWidget.h"
#include "EmuThread.h"
#include "GameList/GameListRefreshThread.h"
Expand Down Expand Up @@ -1065,7 +1066,66 @@ void MainWindow::onAboutActionTriggered()
about.exec();
}

void MainWindow::onCheckForUpdatesActionTriggered() {}
void MainWindow::onCheckForUpdatesActionTriggered()
{
// Wipe out the last version, that way it displays the update if we've previously skipped it.
QtHost::RemoveBaseSettingValue("AutoUpdater", "LastVersion");
checkForUpdates(true);
}

void MainWindow::checkForUpdates(bool display_message)
{
if (!AutoUpdaterDialog::isSupported())
{
if (display_message)
{
QMessageBox mbox(this);
mbox.setWindowTitle(tr("Updater Error"));
mbox.setTextFormat(Qt::RichText);

QString message;
#ifdef _WIN32
message =
tr("<p>Sorry, you are trying to update a PCSX2 version which is not an official GitHub release. To "
"prevent incompatibilities, the auto-updater is only enabled on official builds.</p>"
"<p>To obtain an official build, please download from the link below:</p>"
"<p><a href=\"https://pcsx2.net/downloads/\">https://pcsx2.net/downloads/</a></p>");
#else
message = tr("Automatic updating is not supported on the current platform.");
#endif

mbox.setText(message);
mbox.setIcon(QMessageBox::Critical);
mbox.exec();
}

return;
}

if (m_auto_updater_dialog)
return;

m_auto_updater_dialog = new AutoUpdaterDialog(this);
connect(m_auto_updater_dialog, &AutoUpdaterDialog::updateCheckCompleted, this, &MainWindow::onUpdateCheckComplete);
m_auto_updater_dialog->queueUpdateCheck(display_message);
}

void MainWindow::onUpdateCheckComplete()
{
if (!m_auto_updater_dialog)
return;

m_auto_updater_dialog->deleteLater();
m_auto_updater_dialog = nullptr;
}

void MainWindow::startupUpdateCheck()
{
if (!QtHost::GetBaseBoolSettingValue("AutoUpdater", "CheckAtStartup", true))
return;

checkForUpdates(false);
}

void MainWindow::onToolsOpenDataDirectoryTriggered()
{
Expand Down
6 changes: 6 additions & 0 deletions pcsx2-qt/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

class QProgressBar;

class AutoUpdaterDialog;
class DisplayWidget;
class DisplayContainer;
class GameListWidget;
Expand Down Expand Up @@ -78,11 +79,13 @@ class MainWindow final : public QMainWindow

void initialize();
void connectVMThreadSignals(EmuThread* thread);
void startupUpdateCheck();

/// Locks the VM by pausing it, while a popup dialog is displayed.
VMLock pauseAndLockVM();

public Q_SLOTS:
void checkForUpdates(bool display_message);
void refreshGameList(bool invalidate_cache);
void invalidateSaveStateCache();
void reportError(const QString& title, const QString& message);
Expand All @@ -91,6 +94,8 @@ public Q_SLOTS:
void requestExit();

private Q_SLOTS:
void onUpdateCheckComplete();

DisplayWidget* createDisplay(bool fullscreen, bool render_to_main);
DisplayWidget* updateDisplay(bool fullscreen, bool render_to_main, bool surfaceless);
void displayResizeRequested(qint32 width, qint32 height);
Expand Down Expand Up @@ -203,6 +208,7 @@ private Q_SLOTS:

SettingsDialog* m_settings_dialog = nullptr;
ControllerSettingsDialog* m_controller_settings_dialog = nullptr;
AutoUpdaterDialog* m_auto_updater_dialog = nullptr;

QProgressBar* m_status_progress_widget = nullptr;
QLabel* m_status_gs_widget = nullptr;
Expand Down
14 changes: 7 additions & 7 deletions pcsx2-qt/Settings/InterfaceSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "PrecompiledHeader.h"

#include "InterfaceSettingsWidget.h"
#include "AutoUpdaterDialog.h"
#include "MainWindow.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"
Expand Down Expand Up @@ -62,20 +63,19 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsDialog* dialog, QWidget

dialog->registerWidgetHelp(m_ui.discordPresence, tr("Enable Discord Presence"), tr("Unchecked"),
tr("Shows the game you are currently playing as part of your profile in Discord."));
if (true)
if (AutoUpdaterDialog::isSupported())
{
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.autoUpdateEnabled, "AutoUpdater", "CheckAtStartup", true);
dialog->registerWidgetHelp(m_ui.autoUpdateEnabled, tr("Enable Automatic Update Check"), tr("Checked"),
tr("Automatically checks for updates to the program on startup. Updates can be deferred "
"until later or skipped entirely."));

// m_ui.autoUpdateTag->addItems(AutoUpdaterDialog::getTagList());
// SettingWidgetBinder::BindWidgetToStringSetting(m_ui.autoUpdateTag, "AutoUpdater", "UpdateTag",
// AutoUpdaterDialog::getDefaultTag());
m_ui.autoUpdateTag->addItems(AutoUpdaterDialog::getTagList());
SettingWidgetBinder::BindWidgetToStringSetting(sif, m_ui.autoUpdateTag, "AutoUpdater", "UpdateTag",
AutoUpdaterDialog::getDefaultTag());

// m_ui.autoUpdateCurrentVersion->setText(tr("%1 (%2)").arg(g_scm_tag_str).arg(g_scm_date_str));
// connect(m_ui.checkForUpdates, &QPushButton::clicked, [this]() {
// m_host_interface->getMainWindow()->checkForUpdates(true); });
m_ui.autoUpdateCurrentVersion->setText(tr("%1 (%2)").arg(AutoUpdaterDialog::getCurrentVersion()).arg(AutoUpdaterDialog::getCurrentVersionDate()));
connect(m_ui.checkForUpdates, &QPushButton::clicked, this, []() { g_main_window->checkForUpdates(true); });
}
else
{
Expand Down
Loading

0 comments on commit 41f1ec4

Please sign in to comment.