2020-08-06 12:08:22 +00:00
|
|
|
#include "autoupdaterdialog.h"
|
|
|
|
#include "common/file_system.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/minizip_helpers.h"
|
|
|
|
#include "common/string_util.h"
|
2022-07-11 13:03:29 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "qthost.h"
|
2020-08-06 12:08:22 +00:00
|
|
|
#include "qtutils.h"
|
|
|
|
#include "scmversion/scmversion.h"
|
|
|
|
#include "unzip.h"
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QtCore/QFile>
|
|
|
|
#include <QtCore/QJsonArray>
|
|
|
|
#include <QtCore/QJsonDocument>
|
|
|
|
#include <QtCore/QJsonObject>
|
|
|
|
#include <QtCore/QJsonValue>
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtNetwork/QNetworkAccessManager>
|
|
|
|
#include <QtNetwork/QNetworkReply>
|
|
|
|
#include <QtNetwork/QNetworkRequest>
|
|
|
|
#include <QtWidgets/QDialog>
|
|
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
#include <QtWidgets/QProgressDialog>
|
|
|
|
Log_SetChannel(AutoUpdaterDialog);
|
|
|
|
|
|
|
|
// Logic to detect whether we can use the auto updater.
|
|
|
|
// Currently Windows-only, and requires that the channel be defined by the buildbot.
|
2021-06-28 10:16:48 +00:00
|
|
|
#ifdef _WIN32
|
2020-08-06 12:08:22 +00:00
|
|
|
#if defined(__has_include) && __has_include("scmversion/tag.h")
|
|
|
|
#include "scmversion/tag.h"
|
2020-12-21 16:47:48 +00:00
|
|
|
#ifdef SCM_RELEASE_TAGS
|
2020-08-06 12:08:22 +00:00
|
|
|
#define AUTO_UPDATER_SUPPORTED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
|
|
|
|
2021-07-10 12:13:13 +00:00
|
|
|
static const char* LATEST_TAG_URL = "https://api.github.com/repos/stenzek/duckstation/tags";
|
|
|
|
static const char* LATEST_RELEASE_URL = "https://api.github.com/repos/stenzek/duckstation/releases/tags/%s";
|
|
|
|
static const char* CHANGES_URL = "https://api.github.com/repos/stenzek/duckstation/compare/%s...%s";
|
|
|
|
static const char* UPDATE_ASSET_FILENAME = SCM_RELEASE_ASSET;
|
|
|
|
static const char* UPDATE_TAGS[] = SCM_RELEASE_TAGS;
|
|
|
|
static const char* THIS_RELEASE_TAG = SCM_RELEASE_TAG;
|
2020-08-06 12:08:22 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
AutoUpdaterDialog::AutoUpdaterDialog(EmuThread* host_interface, QWidget* parent /* = nullptr */)
|
2020-08-06 12:08:22 +00:00
|
|
|
: QDialog(parent), m_host_interface(host_interface)
|
|
|
|
{
|
|
|
|
m_network_access_mgr = new QNetworkAccessManager(this);
|
|
|
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
connect(m_ui.downloadAndInstall, &QPushButton::clicked, this, &AutoUpdaterDialog::downloadUpdateClicked);
|
|
|
|
connect(m_ui.skipThisUpdate, &QPushButton::clicked, this, &AutoUpdaterDialog::skipThisUpdateClicked);
|
|
|
|
connect(m_ui.remindMeLater, &QPushButton::clicked, this, &AutoUpdaterDialog::remindMeLaterClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoUpdaterDialog::~AutoUpdaterDialog() = default;
|
|
|
|
|
|
|
|
bool AutoUpdaterDialog::isSupported()
|
|
|
|
{
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:47:48 +00:00
|
|
|
QStringList AutoUpdaterDialog::getTagList()
|
|
|
|
{
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
|
|
|
return QStringList(std::begin(UPDATE_TAGS), std::end(UPDATE_TAGS));
|
|
|
|
#else
|
|
|
|
return QStringList();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AutoUpdaterDialog::getDefaultTag()
|
|
|
|
{
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
|
|
|
return THIS_RELEASE_TAG;
|
|
|
|
#else
|
|
|
|
return {};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AutoUpdaterDialog::getCurrentUpdateTag() const
|
|
|
|
{
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
2022-07-22 11:51:00 +00:00
|
|
|
return Host::GetBaseStringSettingValue("AutoUpdater", "UpdateTag", THIS_RELEASE_TAG);
|
2020-12-21 16:47:48 +00:00
|
|
|
#else
|
|
|
|
return {};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:08:22 +00:00
|
|
|
void AutoUpdaterDialog::reportError(const char* msg, ...)
|
|
|
|
{
|
|
|
|
std::va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
std::string full_msg = StringUtil::StdStringFromFormatV(msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
QMessageBox::critical(this, tr("Updater Error"), QString::fromStdString(full_msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::queueUpdateCheck(bool display_message)
|
|
|
|
{
|
2020-08-06 12:22:35 +00:00
|
|
|
m_display_messages = display_message;
|
|
|
|
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
2020-08-06 12:08:22 +00:00
|
|
|
connect(m_network_access_mgr, &QNetworkAccessManager::finished, this, &AutoUpdaterDialog::getLatestTagComplete);
|
|
|
|
|
2020-12-21 16:47:48 +00:00
|
|
|
QUrl url(QUrl::fromEncoded(QByteArray(LATEST_TAG_URL)));
|
2020-08-06 12:08:22 +00:00
|
|
|
QNetworkRequest request(url);
|
2021-05-20 05:21:15 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2020-08-06 12:08:22 +00:00
|
|
|
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
2021-05-20 05:21:15 +00:00
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
m_network_access_mgr->get(request);
|
2020-08-06 12:22:35 +00:00
|
|
|
#else
|
|
|
|
emit updateCheckCompleted();
|
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::queueGetLatestRelease()
|
|
|
|
{
|
2020-08-06 12:22:35 +00:00
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
2020-08-06 12:08:22 +00:00
|
|
|
connect(m_network_access_mgr, &QNetworkAccessManager::finished, this, &AutoUpdaterDialog::getLatestReleaseComplete);
|
|
|
|
|
2020-12-21 16:47:48 +00:00
|
|
|
SmallString url_string;
|
|
|
|
url_string.Format(LATEST_RELEASE_URL, getCurrentUpdateTag().c_str());
|
|
|
|
|
|
|
|
QUrl url(QUrl::fromEncoded(QByteArray(url_string)));
|
2020-08-06 12:08:22 +00:00
|
|
|
QNetworkRequest request(url);
|
2021-05-20 05:21:15 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2020-08-06 12:08:22 +00:00
|
|
|
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
2021-05-20 05:21:15 +00:00
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
m_network_access_mgr->get(request);
|
2020-08-06 12:22:35 +00:00
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::getLatestTagComplete(QNetworkReply* reply)
|
|
|
|
{
|
2020-08-06 12:22:35 +00:00
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
2020-12-21 16:47:48 +00:00
|
|
|
const std::string selected_tag(getCurrentUpdateTag());
|
|
|
|
const QString selected_tag_qstr = QString::fromStdString(selected_tag);
|
|
|
|
|
2020-08-06 12:08:22 +00:00
|
|
|
// this might fail due to a lack of internet connection - in which case, don't spam the user with messages every time.
|
|
|
|
m_network_access_mgr->disconnect(this);
|
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
if (reply->error() == QNetworkReply::NoError)
|
|
|
|
{
|
|
|
|
const QByteArray reply_json(reply->readAll());
|
|
|
|
QJsonParseError parse_error;
|
|
|
|
QJsonDocument doc(QJsonDocument::fromJson(reply_json, &parse_error));
|
|
|
|
if (doc.isArray())
|
|
|
|
{
|
|
|
|
const QJsonArray doc_array(doc.array());
|
|
|
|
for (const QJsonValue& val : doc_array)
|
|
|
|
{
|
|
|
|
if (!val.isObject())
|
|
|
|
continue;
|
|
|
|
|
2020-12-21 16:47:48 +00:00
|
|
|
if (val["name"].toString() != selected_tag_qstr)
|
2020-08-06 12:08:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
m_latest_sha = val["commit"].toObject()["sha"].toString();
|
|
|
|
if (m_latest_sha.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (updateNeeded())
|
|
|
|
{
|
|
|
|
queueGetLatestRelease();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_display_messages)
|
|
|
|
QMessageBox::information(this, tr("Automatic Updater"),
|
|
|
|
tr("No updates are currently available. Please try again later."));
|
|
|
|
emit updateCheckCompleted();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_display_messages)
|
2020-12-21 16:47:48 +00:00
|
|
|
reportError("%s release not found in JSON", selected_tag.c_str());
|
2020-08-06 12:08:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_display_messages)
|
|
|
|
reportError("JSON is not an array");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_display_messages)
|
|
|
|
reportError("Failed to download latest tag info: %d", static_cast<int>(reply->error()));
|
|
|
|
}
|
|
|
|
|
|
|
|
emit updateCheckCompleted();
|
2020-08-06 12:22:35 +00:00
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::getLatestReleaseComplete(QNetworkReply* reply)
|
|
|
|
{
|
2020-08-06 12:22:35 +00:00
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
2020-08-06 12:08:22 +00:00
|
|
|
m_network_access_mgr->disconnect(this);
|
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
if (reply->error() == QNetworkReply::NoError)
|
|
|
|
{
|
|
|
|
const QByteArray reply_json(reply->readAll());
|
|
|
|
QJsonParseError parse_error;
|
|
|
|
QJsonDocument doc(QJsonDocument::fromJson(reply_json, &parse_error));
|
|
|
|
if (doc.isObject())
|
|
|
|
{
|
|
|
|
const QJsonObject doc_object(doc.object());
|
|
|
|
|
|
|
|
// search for the correct file
|
|
|
|
const QJsonArray assets(doc_object["assets"].toArray());
|
|
|
|
const QString asset_filename(UPDATE_ASSET_FILENAME);
|
|
|
|
for (const QJsonValue& asset : assets)
|
|
|
|
{
|
|
|
|
const QJsonObject asset_obj(asset.toObject());
|
|
|
|
if (asset_obj["name"] == asset_filename)
|
|
|
|
{
|
|
|
|
m_download_url = asset_obj["browser_download_url"].toString();
|
|
|
|
if (!m_download_url.isEmpty())
|
|
|
|
{
|
2020-09-29 15:10:13 +00:00
|
|
|
m_download_size = asset_obj["size"].toInt();
|
2020-08-19 14:43:23 +00:00
|
|
|
m_ui.currentVersion->setText(tr("Current Version: %1 (%2)").arg(g_scm_hash_str).arg(g_scm_date_str));
|
2020-08-06 12:08:22 +00:00
|
|
|
m_ui.newVersion->setText(
|
|
|
|
tr("New Version: %1 (%2)").arg(m_latest_sha).arg(doc_object["published_at"].toString()));
|
2020-08-19 14:20:34 +00:00
|
|
|
m_ui.updateNotes->setText(tr("Loading..."));
|
|
|
|
queueGetChanges();
|
2020-08-06 12:08:22 +00:00
|
|
|
exec();
|
|
|
|
emit updateCheckCompleted();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reportError("Asset/asset download not found");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reportError("JSON is not an object");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reportError("Failed to download latest release info: %d", static_cast<int>(reply->error()));
|
|
|
|
}
|
2020-08-06 12:22:35 +00:00
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 14:20:34 +00:00
|
|
|
void AutoUpdaterDialog::queueGetChanges()
|
|
|
|
{
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
|
|
|
connect(m_network_access_mgr, &QNetworkAccessManager::finished, this, &AutoUpdaterDialog::getChangesComplete);
|
|
|
|
|
2020-12-21 16:47:48 +00:00
|
|
|
const std::string url_string(
|
|
|
|
StringUtil::StdStringFromFormat(CHANGES_URL, g_scm_hash_str, getCurrentUpdateTag().c_str()));
|
2020-08-19 14:20:34 +00:00
|
|
|
QUrl url(QUrl::fromEncoded(QByteArray(url_string.c_str(), static_cast<int>(url_string.size()))));
|
|
|
|
QNetworkRequest request(url);
|
2021-05-20 05:21:15 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2020-08-19 14:20:34 +00:00
|
|
|
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
2021-05-20 05:21:15 +00:00
|
|
|
#endif
|
2020-08-19 14:20:34 +00:00
|
|
|
m_network_access_mgr->get(request);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::getChangesComplete(QNetworkReply* reply)
|
|
|
|
{
|
|
|
|
#ifdef AUTO_UPDATER_SUPPORTED
|
|
|
|
m_network_access_mgr->disconnect(this);
|
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
if (reply->error() == QNetworkReply::NoError)
|
|
|
|
{
|
|
|
|
const QByteArray reply_json(reply->readAll());
|
|
|
|
QJsonParseError parse_error;
|
|
|
|
QJsonDocument doc(QJsonDocument::fromJson(reply_json, &parse_error));
|
|
|
|
if (doc.isObject())
|
|
|
|
{
|
|
|
|
const QJsonObject doc_object(doc.object());
|
|
|
|
|
2020-09-29 13:12:43 +00:00
|
|
|
QString changes_html = tr("<h2>Changes:</h2>");
|
|
|
|
changes_html += QStringLiteral("<ul>");
|
2020-08-19 14:20:34 +00:00
|
|
|
|
|
|
|
const QJsonArray commits(doc_object["commits"].toArray());
|
2020-09-29 13:12:43 +00:00
|
|
|
bool update_will_break_save_states = false;
|
2020-10-07 14:59:39 +00:00
|
|
|
bool update_increases_settings_version = false;
|
2020-09-29 13:12:43 +00:00
|
|
|
|
2020-08-19 14:20:34 +00:00
|
|
|
for (const QJsonValue& commit : commits)
|
|
|
|
{
|
|
|
|
const QJsonObject commit_obj(commit["commit"].toObject());
|
|
|
|
|
|
|
|
QString message = commit_obj["message"].toString();
|
|
|
|
QString author = commit_obj["author"].toObject()["name"].toString();
|
|
|
|
const int first_line_terminator = message.indexOf('\n');
|
|
|
|
if (first_line_terminator >= 0)
|
|
|
|
message.remove(first_line_terminator, message.size() - first_line_terminator);
|
|
|
|
if (!message.isEmpty())
|
2020-09-29 15:10:13 +00:00
|
|
|
{
|
2020-08-19 14:43:23 +00:00
|
|
|
changes_html +=
|
|
|
|
QStringLiteral("<li>%1 <i>(%2)</i></li>").arg(message.toHtmlEscaped()).arg(author.toHtmlEscaped());
|
2020-09-29 15:10:13 +00:00
|
|
|
}
|
2020-09-29 13:12:43 +00:00
|
|
|
|
|
|
|
if (message.contains(QStringLiteral("[SAVEVERSION+]")))
|
|
|
|
update_will_break_save_states = true;
|
2020-12-21 16:47:48 +00:00
|
|
|
|
2020-10-07 14:59:39 +00:00
|
|
|
if (message.contains(QStringLiteral("[SETTINGSVERSION+]")))
|
|
|
|
update_increases_settings_version = true;
|
2020-08-19 14:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
changes_html += "</ul>";
|
2020-09-29 13:12:43 +00:00
|
|
|
|
|
|
|
if (update_will_break_save_states)
|
|
|
|
{
|
|
|
|
changes_html.prepend(tr("<h2>Save State Warning</h2><p>Installing this update will make your save states "
|
|
|
|
"<b>incompatible</b>. Please ensure you have saved your games to memory card "
|
|
|
|
"before installing this update or you will lose progress.</p>"));
|
|
|
|
}
|
|
|
|
|
2020-10-07 14:59:39 +00:00
|
|
|
if (update_increases_settings_version)
|
|
|
|
{
|
|
|
|
changes_html.prepend(
|
|
|
|
tr("<h2>Settings Warning</h2><p>Installing this update will reset your program configuration. Please note "
|
|
|
|
"that you will have to reconfigure your settings after this update.</p>"));
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:10:13 +00:00
|
|
|
changes_html += tr("<h4>Installing this update will download %1 MB through your internet connection.</h4>")
|
|
|
|
.arg(static_cast<double>(m_download_size) / 1000000.0, 0, 'f', 2);
|
|
|
|
|
2020-08-19 14:20:34 +00:00
|
|
|
m_ui.updateNotes->setText(changes_html);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reportError("Change list JSON is not an object");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reportError("Failed to download change list: %d", static_cast<int>(reply->error()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_ui.downloadAndInstall->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:08:22 +00:00
|
|
|
void AutoUpdaterDialog::downloadUpdateClicked()
|
|
|
|
{
|
|
|
|
QUrl url(m_download_url);
|
|
|
|
QNetworkRequest request(url);
|
2021-05-20 04:03:55 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2020-08-06 12:08:22 +00:00
|
|
|
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
2021-05-20 04:03:55 +00:00
|
|
|
#endif
|
2020-08-06 12:08:22 +00:00
|
|
|
QNetworkReply* reply = m_network_access_mgr->get(request);
|
|
|
|
|
|
|
|
QProgressDialog progress(tr("Downloading %1...").arg(m_download_url), tr("Cancel"), 0, 1);
|
|
|
|
progress.setWindowTitle(tr("Automatic Updater"));
|
|
|
|
progress.setWindowIcon(windowIcon());
|
|
|
|
progress.setAutoClose(false);
|
|
|
|
|
|
|
|
connect(reply, &QNetworkReply::downloadProgress, [&progress](quint64 received, quint64 total) {
|
|
|
|
progress.setRange(0, static_cast<int>(total));
|
|
|
|
progress.setValue(static_cast<int>(received));
|
|
|
|
});
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
connect(m_network_access_mgr, &QNetworkAccessManager::finished, this, [this, &progress](QNetworkReply* reply) {
|
2020-08-06 12:08:22 +00:00
|
|
|
m_network_access_mgr->disconnect();
|
|
|
|
|
|
|
|
if (reply->error() != QNetworkReply::NoError)
|
|
|
|
{
|
|
|
|
reportError("Download failed: %s", reply->errorString().toUtf8().constData());
|
|
|
|
progress.done(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QByteArray data = reply->readAll();
|
|
|
|
if (data.isEmpty())
|
|
|
|
{
|
|
|
|
reportError("Download failed: Update is empty");
|
|
|
|
progress.done(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (processUpdate(data))
|
|
|
|
progress.done(1);
|
|
|
|
else
|
|
|
|
progress.done(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
const int result = progress.exec();
|
|
|
|
if (result == 0)
|
|
|
|
{
|
|
|
|
// cancelled
|
|
|
|
reply->abort();
|
|
|
|
}
|
|
|
|
else if (result == 1)
|
|
|
|
{
|
|
|
|
// updater started
|
2022-07-11 13:03:29 +00:00
|
|
|
g_main_window->requestExit();
|
2020-08-06 12:08:22 +00:00
|
|
|
done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutoUpdaterDialog::updateNeeded() const
|
|
|
|
{
|
2022-07-11 13:03:29 +00:00
|
|
|
QString last_checked_sha = QString::fromStdString(Host::GetBaseStringSettingValue("AutoUpdater", "LastVersion"));
|
2020-08-06 12:08:22 +00:00
|
|
|
|
|
|
|
Log_InfoPrintf("Current SHA: %s", g_scm_hash_str);
|
|
|
|
Log_InfoPrintf("Latest SHA: %s", m_latest_sha.toUtf8().constData());
|
|
|
|
Log_InfoPrintf("Last Checked SHA: %s", last_checked_sha.toUtf8().constData());
|
|
|
|
if (m_latest_sha == g_scm_hash_str || m_latest_sha == last_checked_sha)
|
|
|
|
{
|
|
|
|
Log_InfoPrintf("No update needed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log_InfoPrintf("Update needed.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::skipThisUpdateClicked()
|
|
|
|
{
|
2022-07-11 13:03:29 +00:00
|
|
|
Host::SetBaseStringSettingValue("AutoUpdater", "LastVersion", m_latest_sha.toUtf8().constData());
|
2022-09-17 05:51:05 +00:00
|
|
|
Host::CommitBaseSettingChanges();
|
2020-08-06 12:08:22 +00:00
|
|
|
done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoUpdaterDialog::remindMeLaterClicked()
|
|
|
|
{
|
|
|
|
done(0);
|
|
|
|
}
|
|
|
|
|
2021-06-28 10:16:48 +00:00
|
|
|
#ifdef _WIN32
|
2020-08-06 12:08:22 +00:00
|
|
|
|
|
|
|
bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data)
|
|
|
|
{
|
|
|
|
const QString update_directory = QCoreApplication::applicationDirPath();
|
|
|
|
const QString update_zip_path = update_directory + QStringLiteral("\\update.zip");
|
|
|
|
const QString updater_path = update_directory + QStringLiteral("\\updater.exe");
|
|
|
|
|
|
|
|
Q_ASSERT(!update_zip_path.isEmpty() && !updater_path.isEmpty() && !update_directory.isEmpty());
|
|
|
|
if ((QFile::exists(update_zip_path) && !QFile::remove(update_zip_path)) ||
|
|
|
|
(QFile::exists(updater_path) && !QFile::remove(updater_path)))
|
|
|
|
{
|
|
|
|
reportError("Removing existing update zip/updater failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QFile update_zip_file(update_zip_path);
|
|
|
|
if (!update_zip_file.open(QIODevice::WriteOnly) || update_zip_file.write(update_data) != update_data.size())
|
|
|
|
{
|
|
|
|
reportError("Writing update zip to '%s' failed", update_zip_path.toUtf8().constData());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
update_zip_file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extractUpdater(update_zip_path, updater_path))
|
|
|
|
{
|
|
|
|
reportError("Extracting updater failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!doUpdate(update_zip_path, updater_path, update_directory))
|
|
|
|
{
|
|
|
|
reportError("Launching updater failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutoUpdaterDialog::extractUpdater(const QString& zip_path, const QString& destination_path)
|
|
|
|
{
|
|
|
|
unzFile zf = MinizipHelpers::OpenUnzFile(zip_path.toUtf8().constData());
|
|
|
|
if (!zf)
|
|
|
|
{
|
|
|
|
reportError("Failed to open update zip");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unzLocateFile(zf, "updater.exe", 0) != UNZ_OK || unzOpenCurrentFile(zf) != UNZ_OK)
|
|
|
|
{
|
|
|
|
reportError("Failed to locate updater.exe");
|
|
|
|
unzClose(zf);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile updater_exe(destination_path);
|
|
|
|
if (!updater_exe.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
reportError("Failed to open updater.exe for writing");
|
|
|
|
unzClose(zf);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr size_t CHUNK_SIZE = 4096;
|
|
|
|
char chunk[CHUNK_SIZE];
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int size = unzReadCurrentFile(zf, chunk, CHUNK_SIZE);
|
|
|
|
if (size < 0)
|
|
|
|
{
|
|
|
|
reportError("Failed to decompress updater exe");
|
|
|
|
unzClose(zf);
|
|
|
|
updater_exe.close();
|
|
|
|
updater_exe.remove();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (size == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updater_exe.write(chunk, size) != size)
|
|
|
|
{
|
|
|
|
reportError("Failed to write updater exe");
|
|
|
|
unzClose(zf);
|
|
|
|
updater_exe.close();
|
|
|
|
updater_exe.remove();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unzClose(zf);
|
|
|
|
updater_exe.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutoUpdaterDialog::doUpdate(const QString& zip_path, const QString& updater_path, const QString& destination_path)
|
|
|
|
{
|
|
|
|
const QString program_path = QCoreApplication::applicationFilePath();
|
|
|
|
if (program_path.isEmpty())
|
|
|
|
{
|
|
|
|
reportError("Failed to get current application path");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList arguments;
|
2021-03-02 22:33:03 +00:00
|
|
|
arguments << QString::number(QCoreApplication::applicationPid());
|
2020-08-06 12:08:22 +00:00
|
|
|
arguments << destination_path;
|
|
|
|
arguments << zip_path;
|
|
|
|
arguments << program_path;
|
|
|
|
|
|
|
|
// this will leak, but not sure how else to handle it...
|
|
|
|
QProcess* updater_process = new QProcess();
|
|
|
|
updater_process->setProgram(updater_path);
|
|
|
|
updater_process->setArguments(arguments);
|
|
|
|
updater_process->start(QIODevice::NotOpen);
|
|
|
|
if (!updater_process->waitForStarted())
|
|
|
|
{
|
|
|
|
reportError("Failed to start updater");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|