Qt: add changelog to updater (#10844)

This commit is contained in:
Megamouse 2021-09-16 05:34:06 +02:00 committed by GitHub
parent e3eaf5f29e
commit 56e982375e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 5 deletions

View File

@ -12,6 +12,8 @@
#include <QApplication> #include <QApplication>
#include <QDateTime> #include <QDateTime>
#include <QMessageBox> #include <QMessageBox>
#include <QLabel>
#include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonDocument> #include <QJsonDocument>
#include <QThread> #include <QThread>
@ -39,6 +41,7 @@ LOG_CHANNEL(update_log, "UPDATER");
void update_manager::check_for_updates(bool automatic, bool check_only, bool auto_accept, QWidget* parent) void update_manager::check_for_updates(bool automatic, bool check_only, bool auto_accept, QWidget* parent)
{ {
m_update_message.clear(); m_update_message.clear();
m_changelog.clear();
#ifdef __linux__ #ifdef __linux__
if (automatic && !::getenv("APPIMAGE")) if (automatic && !::getenv("APPIMAGE"))
@ -77,7 +80,7 @@ void update_manager::check_for_updates(bool automatic, bool check_only, bool aut
Q_EMIT signal_update_available(result_json && !m_update_message.isEmpty()); Q_EMIT signal_update_available(result_json && !m_update_message.isEmpty());
}); });
const std::string url = "https://update.rpcs3.net/?api=v1&c=" + rpcs3::get_commit_and_hash().second; const std::string url = "https://update.rpcs3.net/?api=v2&c=" + rpcs3::get_commit_and_hash().second;
m_downloader->start(url, true, !automatic, tr("Checking For Updates"), true); m_downloader->start(url, true, !automatic, tr("Checking For Updates"), true);
} }
@ -218,6 +221,56 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
return true; return true;
} }
if (!auto_accept)
{
const auto& changelog = json_data["changelog"];
if (changelog.isArray())
{
for (const QJsonValue& changelog_entry : changelog.toArray())
{
if (changelog_entry.isObject())
{
changelog_data entry;
if (QJsonValue version = changelog_entry["version"]; version.isString())
{
entry.version = version.toString();
}
else
{
entry.version = tr("N/A");
update_log.notice("JSON changelog entry does not contain a version string.");
}
if (QJsonValue title = changelog_entry["title"]; title.isString())
{
entry.title = title.toString();
}
else
{
entry.title = tr("N/A");
update_log.notice("JSON changelog entry does not contain a title string.");
}
m_changelog.push_back(entry);
}
else
{
update_log.error("JSON changelog entry is not an object.");
}
}
}
else if (changelog.isObject())
{
update_log.error("JSON changelog is not an array.");
}
else
{
update_log.notice("JSON does not contain a changelog section.");
}
}
update(auto_accept); update(auto_accept);
return true; return true;
} }
@ -226,11 +279,44 @@ void update_manager::update(bool auto_accept)
{ {
ensure(m_downloader); ensure(m_downloader);
if (!auto_accept && (m_update_message.isEmpty() || if (!auto_accept)
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(); if (m_update_message.isEmpty())
return; {
m_downloader->close_progress_dialog();
return;
}
QString changelog_content;
for (const changelog_data& entry : m_changelog)
{
if (!changelog_content.isEmpty())
changelog_content.append('\n');
changelog_content.append(tr("• %0: %1").arg(entry.version, entry.title));
}
QMessageBox mb(QMessageBox::Icon::Question, tr("Update Available"), m_update_message, QMessageBox::Yes | QMessageBox::No,m_downloader->get_progress_dialog() ? m_downloader->get_progress_dialog() : m_parent);
if (!changelog_content.isEmpty())
{
mb.setInformativeText(tr("To see the changelog, please click \"Show Details\"."));
mb.setDetailedText(tr("Changelog:\n\n%0").arg(changelog_content));
// Smartass hack to make the unresizeable message box wide enough for the changelog
const int changelog_width = QLabel(changelog_content).sizeHint().width();
while (QLabel(m_update_message).sizeHint().width() < changelog_width)
{
m_update_message += " ";
}
mb.setText(m_update_message);
}
if (mb.exec() == QMessageBox::No)
{
m_downloader->close_progress_dialog();
return;
}
} }
if (!Emu.IsStopped()) if (!Emu.IsStopped())

View File

@ -19,6 +19,13 @@ private:
// This message is empty if there is no download available // This message is empty if there is no download available
QString m_update_message; QString m_update_message;
struct changelog_data
{
QString version;
QString title;
};
std::vector<changelog_data> m_changelog;
std::string m_request_url; std::string m_request_url;
std::string m_expected_hash; std::string m_expected_hash;
u64 m_expected_size = 0; u64 m_expected_size = 0;