mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 18:53:32 +00:00
fix: Auto Updater
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -109,21 +110,20 @@ void UpdaterService::ConfigureSSLForRequest(QNetworkRequest& request) {
|
|||||||
request.setSslConfiguration(sslConfig);
|
request.setSslConfiguration(sslConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdaterService::DownloadAndInstallUpdate(const UpdateInfo& update_info) {
|
void UpdaterService::DownloadAndInstallUpdate(const std::string& download_url) {
|
||||||
if (update_in_progress.load()) {
|
if (update_in_progress.load()) {
|
||||||
emit UpdateError(QStringLiteral("Update operation already in progress"));
|
emit UpdateError(QStringLiteral("Update operation already in progress"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (update_info.download_url.empty()) {
|
if (download_url.empty()) {
|
||||||
emit UpdateError(QStringLiteral("Invalid download URL."));
|
emit UpdateError(QStringLiteral("Invalid download URL."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_in_progress.store(true);
|
update_in_progress.store(true);
|
||||||
cancel_requested.store(false);
|
cancel_requested.store(false);
|
||||||
current_update_info = update_info;
|
|
||||||
|
|
||||||
LOG_INFO(Frontend, "Starting update download from {}", update_info.download_url);
|
LOG_INFO(Frontend, "Starting update download from {}", download_url);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (!CreateBackup()) {
|
if (!CreateBackup()) {
|
||||||
@@ -133,7 +133,7 @@ void UpdaterService::DownloadAndInstallUpdate(const UpdateInfo& update_info) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QUrl url(QString::fromStdString(update_info.download_url));
|
QUrl url(QString::fromStdString(download_url));
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||||
current_reply = network_manager->get(request);
|
current_reply = network_manager->get(request);
|
||||||
@@ -313,19 +313,33 @@ void UpdaterService::ParseUpdateResponse(const QByteArray& response) {
|
|||||||
QString asset_name = asset_obj.value(QStringLiteral("name")).toString();
|
QString asset_name = asset_obj.value(QStringLiteral("name")).toString();
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (asset_name.endsWith(QStringLiteral(".zip"))) {
|
if (asset_name.endsWith(QStringLiteral(".zip"))) {
|
||||||
update_info.download_url = asset_obj.value(QStringLiteral("browser_download_url")).toString().toStdString();
|
DownloadOption option;
|
||||||
|
option.name = asset_name.toStdString();
|
||||||
|
option.url = asset_obj.value(QStringLiteral("browser_download_url")).toString().toStdString();
|
||||||
|
update_info.download_options.push_back(option);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
if (asset_name.endsWith(QStringLiteral(".AppImage"))) {
|
if (asset_name.endsWith(QStringLiteral(".AppImage"))) {
|
||||||
update_info.download_url = asset_obj.value(QStringLiteral("browser_download_url")).toString().toStdString();
|
DownloadOption option;
|
||||||
break;
|
QString friendly_name = asset_name;
|
||||||
|
|
||||||
|
friendly_name.remove(QRegularExpression(QStringLiteral(R"(^citron-linux-\d*-x86_64-?)"), QRegularExpression::CaseInsensitiveOption));
|
||||||
|
friendly_name.remove(QStringLiteral(".AppImage"));
|
||||||
|
if (friendly_name.isEmpty()) {
|
||||||
|
option.name = "AppImage";
|
||||||
|
} else {
|
||||||
|
option.name = friendly_name.toUpper().toStdString();
|
||||||
|
}
|
||||||
|
option.url = asset_obj.value(QStringLiteral("browser_download_url")).toString().toStdString();
|
||||||
|
update_info.download_options.push_back(option);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!update_info.download_url.empty()) {
|
if (!update_info.download_options.empty()) {
|
||||||
update_info.is_newer_version = CompareVersions(GetCurrentVersion(), update_info.version);
|
update_info.is_newer_version = CompareVersions(GetCurrentVersion(), update_info.version);
|
||||||
|
current_update_info = update_info;
|
||||||
emit UpdateCheckCompleted(update_info.is_newer_version, update_info);
|
emit UpdateCheckCompleted(update_info.is_newer_version, update_info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user