3#if defined(QT_UTILITIES_GUI_QTWIDGETS)
7#include "resources/config.h"
12#include <c++utilities/application/argumentparser.h>
16#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
17#include <c++utilities/io/ansiescapecodes.h>
18#include <c++utilities/io/archive.h>
20#include <QCoreApplication>
25#include <QFutureWatcher>
27#include <QJsonDocument>
29#include <QJsonParseError>
32#include <QNetworkAccessManager>
33#include <QNetworkReply>
35#include <QRegularExpression>
36#include <QStringBuilder>
37#include <QVersionNumber>
38#include <QtConcurrentRun>
41#if defined(QT_UTILITIES_GUI_QTWIDGETS)
48#if defined(QT_UTILITIES_GUI_QTWIDGETS)
49#include <QCoreApplication>
52#if defined(QT_UTILITIES_SETUP_TOOLS_ENABLED)
53#include "ui_updateoptionpage.h"
57class UpdateOptionPage {
59 void setupUi(QWidget *)
62 void retranslateUi(QWidget *)
71#include "resources/config.h"
73#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
74#define QT_UTILITIES_VERSION_SUFFIX QString()
76#define QT_UTILITIES_VERSION_SUFFIX QStringLiteral("-qt5")
79#if defined(Q_OS_WINDOWS)
80#define QT_UTILITIES_EXE_REGEX "\\.exe"
82#define QT_UTILITIES_EXE_REGEX ""
85#if defined(Q_OS_WIN64)
86#if defined(Q_PROCESSOR_X86_64)
87#define QT_UTILITIES_DOWNLOAD_REGEX "-.*-x86_64-w64-mingw32"
88#elif defined(Q_PROCESSOR_ARM_64)
89#define QT_UTILITIES_DOWNLOAD_REGEX "-.*-aarch64-w64-mingw32"
91#elif defined(Q_OS_WIN32)
92#define QT_UTILITIES_DOWNLOAD_REGEX "-.*-i686-w64-mingw32"
93#elif defined(__GNUC__) && defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
94#if defined(Q_PROCESSOR_X86_64)
95#define QT_UTILITIES_DOWNLOAD_REGEX "-.*-x86_64-pc-linux-gnu"
96#elif defined(Q_PROCESSOR_ARM_64)
97#define QT_UTILITIES_DOWNLOAD_REGEX "-.*-aarch64-pc-linux-gnu"
101#if defined(Q_OS_WINDOWS) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
102#include <QNtfsPermissionCheckGuard>
107#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
113#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
115 QNetworkAccessManager *nm =
nullptr;
116 CppUtilities::DateTime lastCheck;
118 QNetworkRequest::CacheLoadControl cacheLoadControl = QNetworkRequest::PreferNetwork;
119 QVersionNumber currentVersion = QVersionNumber();
120 QString currentVersionSuffix = QString();
121 QRegularExpression gitHubRegex = QRegularExpression(QStringLiteral(
".*/github.com/([^/]+)/([^/]+)(/.*)?"));
122 QRegularExpression gitHubRegex2 = QRegularExpression(QStringLiteral(
".*/([^/.]+)\\.github.io/([^/]+)(/.*)?"));
123 QRegularExpression assetRegex = QRegularExpression();
124 QString executableName;
125 QString previouslyFoundNewVersion;
127 QString latestVersion;
128 QString additionalInfo;
129 QString releaseNotes;
134 QUrl previousVersionDownloadUrl;
135 QUrl previousVersionSignatureUrl;
136 QList<std::variant<QJsonArray, QString>> previousVersionAssets;
137 bool inProgress =
false;
138 bool updateAvailable =
false;
139 bool verbose =
false;
151#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
154 m_p->verbose = qEnvironmentVariableIntValue(PROJECT_VARNAME_UPPER
"_UPDATER_VERBOSE");
156 const auto &appInfo = CppUtilities::applicationInfo;
157 const auto url = QString::fromUtf8(appInfo.url);
158 auto gitHubMatch = m_p->gitHubRegex.match(url);
159 if (!gitHubMatch.hasMatch()) {
160 gitHubMatch = m_p->gitHubRegex2.match(url);
162 const auto gitHubOrga = gitHubMatch.captured(1);
163 const auto gitHubRepo = gitHubMatch.captured(2);
164 if (gitHubOrga.isNull() || gitHubRepo.isNull()) {
167 const auto currentVersion = QString::fromUtf8(appInfo.version);
171 = QStringLiteral(
"https://api.github.com/repos/") % gitHubOrga % QChar(
'/') % gitHubRepo % QStringLiteral(
"/releases?per_page=25");
172 m_p->currentVersion = QVersionNumber::fromString(currentVersion, &suffixIndex);
173 m_p->currentVersionSuffix = suffixIndex >= 0 ? currentVersion.mid(suffixIndex) : QString();
174#ifdef QT_UTILITIES_DOWNLOAD_REGEX
175 m_p->assetRegex = QRegularExpression(m_p->executableName + QStringLiteral(QT_UTILITIES_DOWNLOAD_REGEX
"\\..+"));
178 qDebug() <<
"deduced executable name: " << m_p->executableName;
179 qDebug() <<
"assumed current version: " << m_p->currentVersion;
180 qDebug() <<
"asset regex for current platform: " << m_p->assetRegex;
186#ifdef QT_UTILITIES_FAKE_NEW_VERSION_AVAILABLE
187 QTimer::singleShot(10000, Qt::VeryCoarseTimer,
this, [
this] { emit
updateAvailable(QStringLiteral(
"foo"), QString()); });
197#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
200 return !m_p->assetRegex.pattern().isEmpty();
206#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
209 return m_p->inProgress;
215#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
218 return m_p->updateAvailable;
224#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
233#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
242#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
243 static const auto v = QString();
246 return m_p->executableName;
252#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
253 static const auto v = QString();
256 return m_p->newVersion;
262#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
263 static const auto v = QString();
266 return m_p->latestVersion;
272#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
273 static const auto v = QString();
276 return m_p->additionalInfo;
282#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
283 static const auto v = QString();
286 return m_p->releaseNotes;
297#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
298 static const auto v = QUrl();
301 return m_p->downloadUrl;
307#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
308 static const auto v = QUrl();
311 return m_p->signatureUrl;
317#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
318 static const auto v = QUrl();
321 return m_p->previousVersionDownloadUrl;
327#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
328 static const auto v = QUrl();
331 return m_p->previousVersionSignatureUrl;
337#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
338 return CppUtilities::DateTime();
340 return m_p->lastCheck;
346#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
349 settings->beginGroup(QStringLiteral(
"updating"));
350 m_p->newVersion = settings->value(
"newVersion").toString();
351 m_p->latestVersion = settings->value(
"latestVersion").toString();
352 m_p->releaseNotes = settings->value(
"releaseNotes").toString();
353 m_p->downloadUrl = settings->value(
"downloadUrl").toUrl();
354 m_p->signatureUrl = settings->value(
"signatureUrl").toUrl();
355 m_p->previousVersionDownloadUrl = settings->value(
"previousVersionDownloadUrl").toUrl();
356 m_p->previousVersionSignatureUrl = settings->value(
"previousVersionSignatureUrl").toUrl();
357 m_p->lastCheck = CppUtilities::DateTime(settings->value(
"lastCheck").toULongLong());
358 m_p->flags =
static_cast<UpdateCheckFlags>(settings->value(
"flags").toULongLong());
359 settings->endGroup();
365#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
368 settings->beginGroup(QStringLiteral(
"updating"));
369 settings->setValue(
"newVersion", m_p->newVersion);
370 settings->setValue(
"latestVersion", m_p->latestVersion);
371 settings->setValue(
"releaseNotes", m_p->releaseNotes);
372 settings->setValue(
"downloadUrl", m_p->downloadUrl);
373 settings->setValue(
"signatureUrl", m_p->signatureUrl);
374 settings->setValue(
"previousVersionDownloadUrl", m_p->previousVersionDownloadUrl);
375 settings->setValue(
"previousVersionSignatureUrl", m_p->previousVersionSignatureUrl);
376 settings->setValue(
"lastCheck",
static_cast<qulonglong
>(m_p->lastCheck.ticks()));
377 settings->setValue(
"flags",
static_cast<qulonglong
>(m_p->flags));
378 settings->endGroup();
384#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
385 if (m_p->inProgress) {
386 return tr(
"checking …");
389 if (!m_p->error.isEmpty()) {
390 return tr(
"unable to check: %1").arg(m_p->error);
392#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
393 if (!m_p->newVersion.isEmpty()) {
394 return tr(
"new version available: %1 (last checked: %2)").arg(m_p->newVersion, QString::fromStdString(m_p->lastCheck.toIsoString()));
395 }
else if (!m_p->latestVersion.isEmpty()) {
396 return tr(
"no new version available, latest release is: %1 (last checked: %2)")
397 .arg(m_p->latestVersion, QString::fromStdString(m_p->lastCheck.toIsoString()));
400 return tr(
"unknown");
405#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
412#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
413void UpdateNotifier::setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl)
415 m_p->cacheLoadControl = cacheLoadControl;
419void UpdateNotifier::setError(
const QString &context, QNetworkReply *reply)
421#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
425 m_p->error = context + reply->errorString();
431void UpdateNotifier::setError(
const QString &context,
const QJsonParseError &jsonError,
const QByteArray &response)
433#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
438 m_p->error = context % jsonError.errorString() % QChar(
' ') % QChar(
'(') % tr(
"at offset %1").arg(jsonError.offset) % QChar(
')');
439 if (!response.isEmpty()) {
440 m_p->error += QStringLiteral(
"\nResponse was: ");
441 m_p->error += QString::fromUtf8(response);
449#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
450 m_p->error = tr(
"This build of the application does not support checking for updates.");
454 if (!m_p->nm || m_p->inProgress) {
458 auto request = QNetworkRequest(m_p->releasesUrl);
459 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, m_p->cacheLoadControl);
460 auto *
const reply = m_p->nm->get(request);
461 connect(reply, &QNetworkReply::finished,
this, &UpdateNotifier::readReleases);
467#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
468 m_p->updateAvailable =
false;
469 m_p->downloadUrl.clear();
470 m_p->signatureUrl.clear();
471 m_p->latestVersion.clear();
472 m_p->newVersion.clear();
473 m_p->releaseNotes.clear();
477void UpdateNotifier::lastCheckNow()
const
479#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
480 m_p->lastCheck = CppUtilities::DateTime::now();
484#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
486static bool isVersionHigher(
const QVersionNumber &lhs,
const QString &lhsSuffix,
const QVersionNumber &rhs,
const QString &rhsSuffix)
488 const auto cmp = QVersionNumber::compare(lhs, rhs);
491 }
else if (cmp < 0) {
494 if (!lhsSuffix.isEmpty() && rhsSuffix.isEmpty()) {
497 if (lhsSuffix.isEmpty() && !rhsSuffix.isEmpty()) {
501 return lhsSuffix > rhsSuffix;
508#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
512 auto jsonError = QJsonParseError();
513 const auto replyDoc = QJsonDocument::fromJson(data, &jsonError);
514 if (jsonError.error != QJsonParseError::NoError) {
515 setError(tr(
"Unable to parse releases: "), jsonError, data);
519#if !defined(QT_JSON_READONLY)
521 qDebug().noquote() <<
"Update check: found releases: " << QString::fromUtf8(replyDoc.toJson(QJsonDocument::Indented));
525 const auto replyArray = replyDoc.array();
528 auto latestVersionFound = QVersionNumber();
529 auto latestVersionSuffix = QString();
530 auto latestVersionAssets = QJsonValue();
531 auto latestVersionAssetsUrl = QString();
532 auto latestVersionReleaseNotes = QString();
533 auto previousVersionAssets = QMap<QVersionNumber, std::variant<QJsonArray, QString>>();
534 for (
const auto &releaseInfoVal : replyArray) {
535 const auto releaseInfo = releaseInfoVal.toObject();
536 const auto tag = releaseInfo.value(QLatin1String(
"tag_name")).toString();
537 if ((skipPreReleases && releaseInfo.value(QLatin1String(
"prerelease")).toBool())
538 || (skipDrafts && releaseInfo.value(QLatin1String(
"draft")).toBool())) {
539 qDebug() <<
"Update check: skipping prerelease/draft: " << tag;
543 const auto versionStr = tag.startsWith(QChar(
'v')) ? tag.mid(1) : tag;
544 const auto version = QVersionNumber::fromString(versionStr, &suffixIndex);
545 const auto suffix = suffixIndex >= 0 ? versionStr.mid(suffixIndex) : QString();
546 const auto assets = releaseInfo.value(QLatin1String(
"assets"));
547 const auto assetsUrl = releaseInfo.value(QLatin1String(
"assets_url")).toString();
548 if (latestVersionFound.isNull() || isVersionHigher(version, suffix, latestVersionFound, latestVersionSuffix)) {
549 latestVersionFound = version;
550 latestVersionSuffix = suffix;
551 latestVersionAssets = assets;
552 latestVersionAssetsUrl = assetsUrl;
553 latestVersionReleaseNotes = releaseInfo.value(QLatin1String(
"body")).toString();
555 if (assets.isArray()) {
556 previousVersionAssets[version] = assets.toArray();
557 }
else if (!assetsUrl.isEmpty()) {
558 previousVersionAssets[version] = assetsUrl;
561 qDebug() <<
"Update check: skipping release: " << tag;
564 if (!latestVersionFound.isNull()) {
565 m_p->latestVersion = latestVersionFound.toString() + latestVersionSuffix;
566 m_p->releaseNotes = latestVersionReleaseNotes;
567 previousVersionAssets.remove(latestVersionFound);
569 m_p->previousVersionAssets = previousVersionAssets.values();
571 const auto foundUpdate
572 = !latestVersionFound.isNull() && isVersionHigher(latestVersionFound, latestVersionSuffix, m_p->currentVersion, m_p->currentVersionSuffix);
574 m_p->newVersion = latestVersionFound.toString() + latestVersionSuffix;
576 if (latestVersionAssets.isArray()) {
577 return processAssets(latestVersionAssets.toArray(), foundUpdate,
false);
578 }
else if (foundUpdate) {
579 return queryRelease(latestVersionAssetsUrl, foundUpdate,
false);
586void UpdateNotifier::readReleases()
588#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
589 auto *
const reply =
static_cast<QNetworkReply *
>(sender());
590 reply->deleteLater();
591 switch (reply->error()) {
592 case QNetworkReply::NoError: {
596 case QNetworkReply::OperationCanceledError:
600 setError(tr(
"Unable to request releases: "), reply);
605void UpdateNotifier::queryRelease(
const QUrl &releaseUrl,
bool forUpdate,
bool forPreviousVersion)
607#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
610 Q_UNUSED(forPreviousVersion)
612 auto request = QNetworkRequest(releaseUrl);
613 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, m_p->cacheLoadControl);
614 auto *
const reply = m_p->nm->get(request);
615 reply->setProperty(
"forUpdate", forUpdate);
616 reply->setProperty(
"forPreviousVersion", forPreviousVersion);
617 connect(reply, &QNetworkReply::finished,
this, &UpdateNotifier::readRelease);
621void UpdateNotifier::readRelease()
623#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
624 auto *
const reply =
static_cast<QNetworkReply *
>(sender());
625 reply->deleteLater();
626 switch (reply->error()) {
627 case QNetworkReply::NoError: {
629 auto jsonError = QJsonParseError();
630 const auto response = reply->readAll();
631 const auto replyDoc = QJsonDocument::fromJson(response, &jsonError);
632 if (jsonError.error != QJsonParseError::NoError) {
633 setError(tr(
"Unable to parse release: "), jsonError, response);
636#if !defined(QT_JSON_READONLY)
638 qDebug().noquote() <<
"Update check: found release info: " << QString::fromUtf8(replyDoc.toJson(QJsonDocument::Indented));
641 processAssets(replyDoc.object().value(QLatin1String(
"assets")).toArray(), reply->property(
"forUpdate").toBool(),
642 reply->property(
"forPreviousVersion").toBool());
645 case QNetworkReply::OperationCanceledError:
649 setError(tr(
"Unable to request release: "), reply);
654void UpdateNotifier::processAssets(
const QJsonArray &assets,
bool forUpdate,
bool forPreviousVersion)
656#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
659 Q_UNUSED(forPreviousVersion)
661 for (
const auto &assetVal : assets) {
662 if (forPreviousVersion ? !m_p->previousVersionDownloadUrl.isEmpty() && !m_p->previousVersionSignatureUrl.isEmpty()
663 : !m_p->downloadUrl.isEmpty() && !m_p->signatureUrl.isEmpty()) {
666 const auto asset = assetVal.toObject();
667 const auto assetName = asset.value(QLatin1String(
"name")).toString();
668 if (assetName.isEmpty()) {
671 if (!m_p->assetRegex.match(assetName).hasMatch()) {
673 qDebug() <<
"Update check: skipping asset: " << assetName;
677 const auto url = asset.value(QLatin1String(
"browser_download_url")).toString();
678 if (assetName.endsWith(QLatin1String(
".sig"))) {
679 (forPreviousVersion ? m_p->previousVersionSignatureUrl : m_p->signatureUrl) = url;
681 (forPreviousVersion ? m_p->previousVersionDownloadUrl : m_p->downloadUrl) = url;
685 m_p->updateAvailable = !m_p->downloadUrl.isEmpty();
687 if (m_p->downloadUrl.isEmpty() && m_p->previousVersionDownloadUrl.isEmpty() && !m_p->previousVersionAssets.isEmpty()) {
688 auto previousVersionAssets = m_p->previousVersionAssets.takeLast();
689 if (std::holds_alternative<QJsonArray>(previousVersionAssets)) {
690 return processAssets(std::get<QJsonArray>(previousVersionAssets), forUpdate,
true);
692 return queryRelease(std::get<QString>(previousVersionAssets), forUpdate,
true);
697 if (forUpdate && m_p->updateAvailable && m_p->newVersion != m_p->previouslyFoundNewVersion) {
699 m_p->previouslyFoundNewVersion = m_p->newVersion;
705#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
707 QNetworkAccessManager *nm =
nullptr;
708 QFile *fakeDownload =
nullptr;
709 QNetworkReply *currentDownload =
nullptr;
710 QNetworkReply *signatureDownload =
nullptr;
711 QNetworkRequest::CacheLoadControl cacheLoadControl = QNetworkRequest::PreferNetwork;
712 QString
error, statusMessage;
713 QByteArray signature;
714 QFutureWatcher<QPair<QString, QString>> watcher;
715 QString executableName;
716 QString signatureExtension;
717 QRegularExpression executableRegex = QRegularExpression();
728 :
Updater(executableName, QString(), parent)
732Updater::Updater(
const QString &executableName,
const QString &signatureExtension, QObject *parent)
736#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
737 Q_UNUSED(executableName)
738 Q_UNUSED(signatureExtension)
740 connect(&m_p->watcher, &QFutureWatcher<void>::finished,
this, &Updater::concludeUpdate);
741 m_p->executableName = executableName;
742 m_p->signatureExtension = signatureExtension;
743 const auto signatureRegex = signatureExtension.isEmpty()
745 : QString(QStringLiteral(
"(") % QRegularExpression::escape(signatureExtension) % QStringLiteral(
")?"));
746#ifdef QT_UTILITIES_EXE_REGEX
747 m_p->executableRegex = QRegularExpression(executableName % QStringLiteral(
QT_UTILITIES_EXE_REGEX) % signatureRegex);
758#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
759 return m_p->currentDownload !=
nullptr || m_p->signatureDownload !=
nullptr || m_p->watcher.isRunning();
767#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
768 return isInProgress() ? tr(
"Update in progress …") : (m_p->error.isEmpty() ? tr(
"Update done") : tr(
"Update failed"));
781#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
782 return m_p->statusMessage.isEmpty() ? m_p->error : m_p->statusMessage;
790#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
791 return m_p->storedPath;
793 static const auto empty = QString();
800#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
809#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
810 m_p->verifyFunction = std::move(verifyFunction);
812 Q_UNUSED(verifyFunction)
816#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
817void Updater::setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl)
819 m_p->cacheLoadControl = cacheLoadControl;
825#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
826 Q_UNUSED(downloadUrl)
827 Q_UNUSED(signatureUrl)
828 setError(tr(
"This build of the application does not support self-updating."));
834 startDownload(downloadUrl, signatureUrl);
841#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
842 if (m_p->currentDownload) {
843 m_p->currentDownload->abort();
845 if (m_p->signatureDownload) {
846 m_p->signatureDownload->abort();
848 if (m_p->watcher.isRunning()) {
849 m_p->watcher.cancel();
854void Updater::setError(
const QString &error)
856#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
857 m_p->statusMessage.clear();
865void Updater::startDownload(
const QString &downloadUrl,
const QString &signatureUrl)
867#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
868 Q_UNUSED(downloadUrl)
869 Q_UNUSED(signatureUrl)
872 m_p->storedPath.clear();
873 m_p->signature.clear();
875 if (
const auto fakeDownloadPath = qEnvironmentVariable(PROJECT_VARNAME_UPPER
"_UPDATER_FAKE_DOWNLOAD"); !fakeDownloadPath.isEmpty()) {
876 m_p->fakeDownload =
new QFile(fakeDownloadPath);
877 m_p->fakeDownload->open(QFile::ReadOnly);
883 auto request = QNetworkRequest(QUrl(downloadUrl));
884 request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, m_p->cacheLoadControl);
885 m_p->statusMessage = tr(
"Downloading %1").arg(downloadUrl);
886 m_p->currentDownload = m_p->nm->get(request);
890 connect(m_p->currentDownload, &QNetworkReply::finished,
this, &Updater::handleDownloadFinished);
892 if (!signatureUrl.isEmpty()) {
893 request.setUrl(signatureUrl);
894 m_p->signatureDownload = m_p->nm->get(request);
895 connect(m_p->signatureDownload, &QNetworkReply::finished,
this, &Updater::handleDownloadFinished);
900void Updater::handleDownloadFinished()
902#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
903 if (m_p->signatureDownload && !m_p->signatureDownload->isFinished()) {
908 if (!m_p->currentDownload->isFinished()) {
912 if (m_p->signatureDownload) {
914 m_p->signatureDownload->deleteLater();
915 m_p->signatureDownload =
nullptr;
918 if (m_p->error.isEmpty()) {
921 m_p->currentDownload->deleteLater();
923 m_p->currentDownload =
nullptr;
927void Updater::readSignature()
929#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
930 switch (m_p->signatureDownload->error()) {
931 case QNetworkReply::NoError:
932 m_p->signature = m_p->signatureDownload->readAll();
935 setError(tr(
"Unable to download signature: ") + m_p->signatureDownload->errorString());
940void Updater::storeExecutable()
942#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
943 m_p->statusMessage = tr(
"Extracting …");
946 auto *reply =
static_cast<QIODevice *
>(m_p->fakeDownload);
947 auto archiveName = QString();
948 auto hasError =
false;
950 archiveName = m_p->fakeDownload->fileName();
951 hasError = m_p->fakeDownload->error() != QFileDevice::NoError;
953 reply = m_p->currentDownload;
954 archiveName = m_p->currentDownload->request().url().fileName();
955 hasError = m_p->currentDownload->error() != QNetworkReply::NoError;
958 reply->deleteLater();
959 setError(tr(
"Unable to download update: ") + reply->errorString());
962 auto res = QtConcurrent::run([
this, reply, archiveName] {
963 const auto data = reply->readAll();
964 const auto dataView = std::string_view(data.data(),
static_cast<std::size_t
>(data.size()));
965 auto foundExecutable =
false, foundSignature =
false;
966 auto error = QString(), storePath = QString();
967 auto newExeName = std::string(), signatureName = std::string();
968 auto newExeData = std::string();
969 auto newExe = QFile();
970 reply->deleteLater();
973 const auto appDirPath = QCoreApplication::applicationDirPath();
974 const auto appFilePath = QCoreApplication::applicationFilePath();
975 if (appDirPath.isEmpty() || appFilePath.isEmpty()) {
976 error = tr(
"Unable to determine application path.");
977 return QPair<QString, QString>(
error, storePath);
981 const auto checkCancellation = [
this, &
error] {
982 if (m_p->watcher.isCanceled()) {
983 error = tr(
"Extraction was cancelled.");
989 if (checkCancellation()) {
990 return QPair<QString, QString>(
error, storePath);
994 CppUtilities::walkThroughArchiveFromBuffer(
995 dataView, archiveName.toStdString(),
996 [
this](
const char *filePath,
const char *fileName, mode_t mode) {
999 if (m_p->watcher.isCanceled()) {
1002 return m_p->executableRegex.match(QString::fromUtf8(fileName)).hasMatch();
1004 [&](std::string_view path, CppUtilities::ArchiveFile &&file) {
1006 if (checkCancellation()) {
1009 if (file.type != CppUtilities::ArchiveFileType::Regular) {
1014 const auto fileName = QString::fromUtf8(file.name.data(),
static_cast<QString::size_type
>(file.name.size()));
1015 if (!m_p->signatureExtension.isEmpty() && fileName.endsWith(m_p->signatureExtension)) {
1016 m_p->signature = QByteArray::fromStdString(file.content);
1017 foundSignature =
true;
1018 signatureName = file.name;
1019 return foundExecutable;
1023 if (fileName.endsWith(QLatin1String(
".sig"))) {
1028 foundExecutable =
true;
1029 newExeName = file.name;
1030 newExe.setFileName(appDirPath % QChar(
'/') % fileName % QStringLiteral(
".tmp"));
1031 if (!newExe.open(QFile::WriteOnly | QFile::Truncate)) {
1032 error = tr(
"Unable to create new executable under \"%1\": %2").arg(newExe.fileName(), newExe.errorString());
1035 const auto size =
static_cast<qint64
>(file.content.size());
1036 if (!(newExe.write(file.content.data(), size) == size) || !newExe.flush()) {
1037 error = tr(
"Unable to write new executable under \"%1\": %2").arg(newExe.fileName(), newExe.errorString());
1040 if (!newExe.setPermissions(
1041 newExe.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeUser | QFileDevice::ExeGroup | QFileDevice::ExeOther)) {
1042 error = tr(
"Unable to make new binary under \"%1\" executable.").arg(newExe.fileName());
1046 storePath = newExe.fileName();
1047 newExeData = std::move(file.content);
1048 return foundSignature || m_p->signatureExtension.isEmpty();
1050 }
catch (
const CppUtilities::ArchiveException &e) {
1051 error = tr(
"Unable to open downloaded archive: %1").arg(e.what());
1053 if (
error.isEmpty() && foundExecutable) {
1055 if (m_p->verifyFunction) {
1056 if (const auto verifyError = m_p->verifyFunction(Updater::Update{ .executableName = newExeName,
1057 .signatureName = signatureName,
1059 .signature = std::string_view(m_p->signature.data(), static_cast<std::size_t>(m_p->signature.size())) });
1060 !verifyError.isEmpty()) {
1061 error = tr(
"Unable to verify whether downloaded binary is valid: %1").arg(verifyError);
1062 return QPair<QString, QString>(error, storePath);
1067 auto currentExeInfo = QFileInfo(appFilePath);
1068 auto currentExe = QFile(appFilePath);
1069 const auto completeSuffix = currentExeInfo.completeSuffix();
1070 const auto suffixWithDot = completeSuffix.isEmpty() ? QString() : QChar(
'.') + completeSuffix;
1071 for (
auto i = 0; i < 100; ++i) {
1072 const auto backupNumber = i ? QString::number(i) : QString();
1073 const auto backupPath = QString(currentExeInfo.path() % QChar(
'/') % currentExeInfo.baseName() % QStringLiteral(
"-backup")
1074 % backupNumber % QChar(
'-') % QString::fromUtf8(CppUtilities::applicationInfo.version) % suffixWithDot);
1075 if (QFile::exists(backupPath)) {
1078 if (!currentExe.rename(backupPath)) {
1079 error = tr(
"Unable to move current executable to \"%1\": %2").arg(backupPath, currentExe.errorString());
1080 return QPair<QString, QString>(
error, storePath);
1086 if (!newExe.rename(appFilePath)) {
1087 error = tr(
"Unable to rename new executable \"%1\" to \"%2\": %3").arg(newExe.fileName(), appFilePath, newExe.errorString());
1088 return QPair<QString, QString>(error, storePath);
1090 storePath = newExe.fileName();
1092 if (error.isEmpty() && !foundExecutable) {
1093 error = tr(
"Unable to find executable in downloaded archive.");
1095 return QPair<QString, QString>(error, storePath);
1097 m_p->watcher.setFuture(std::move(res));
1101void Updater::concludeUpdate()
1103#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1104 auto res = m_p->watcher.result();
1105 m_p->error = res.first;
1106 m_p->storedPath = res.second;
1107 if (!m_p->error.isEmpty()) {
1108 m_p->statusMessage.clear();
1109 emit updateFailed(m_p->error);
1111 m_p->statusMessage = tr(
"Update stored under: %1").arg(m_p->storedPath);
1112 emit updateStored();
1114 emit updateStatusChanged(statusMessage());
1115 emit updatePercentageChanged(0, 0);
1116 emit inProgressChanged(
false);
1122 :
updater(executableName.isEmpty() ?
notifier.executableName() : executableName, signatureExtension)
1149 const QString &executableName,
const QString &signatureExtension, QSettings *settings, QNetworkAccessManager *nm, QObject *parent)
1153 m_p->notifier.setNetworkAccessManager(nm);
1154 m_p->updater.setNetworkAccessManager(nm);
1155 m_p->timer.setSingleShot(
true);
1156 m_p->timer.setTimerType(Qt::VeryCoarseTimer);
1157 m_p->settings = settings;
1168 return &m_p->notifier;
1173 return &m_p->updater;
1178 if (m_p->checkInterval.has_value()) {
1179 return m_p->checkInterval.value();
1181 m_p->settings->beginGroup(QStringLiteral(
"updating"));
1183 checkInterval.duration = CppUtilities::TimeSpan::fromMilliseconds(m_p->settings->value(
"checkIntervalMs", 60 * 60 * 1000).toInt());
1184 checkInterval.enabled = m_p->settings->value(
"automaticChecksEnabled",
false).toBool();
1185 m_p->settings->endGroup();
1192 m_p->settings->beginGroup(QStringLiteral(
"updating"));
1193 m_p->settings->setValue(
"checkIntervalMs",
checkInterval.duration.totalMilliseconds());
1194 m_p->settings->setValue(
"automaticChecksEnabled",
checkInterval.enabled);
1195 m_p->settings->endGroup();
1196#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1197 scheduleNextUpdateCheck();
1203 return m_p->considerSeparateSignature;
1208 m_p->considerSeparateSignature = consideringSeparateSignature;
1213 auto error = QString();
1214#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1215 static const auto appDirPath = QCoreApplication::applicationDirPath();
1216 if (appDirPath.isEmpty()) {
1217 return tr(
"Unable to determine the application directory.");
1219#if defined(Q_OS_WINDOWS) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
1220 const auto permissionGuard = QNtfsPermissionCheckGuard();
1222 const auto dirInfo = QFileInfo(appDirPath);
1223 if (!dirInfo.isWritable()) {
1224 return tr(
"The directory where the executable is stored (%1) is not writable.").arg(appDirPath);
1230#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1231void UpdateHandler::setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl)
1233 m_p->notifier.setCacheLoadControl(cacheLoadControl);
1234 m_p->updater.setCacheLoadControl(cacheLoadControl);
1240#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1241 m_p->notifier.restore(m_p->settings);
1242 scheduleNextUpdateCheck();
1248 const auto &downloadUrl = !m_p->notifier.downloadUrl().isEmpty() ? m_p->notifier.downloadUrl() : m_p->notifier.previousVersionDownloadUrl();
1249 const auto &signatureUrl = !m_p->notifier.downloadUrl().isEmpty() ? m_p->notifier.signatureUrl() : m_p->notifier.previousVersionSignatureUrl();
1250 m_p->updater.performUpdate(downloadUrl.toString(), m_p->considerSeparateSignature ? signatureUrl.toString() : QString());
1255#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1256 m_p->notifier.save(m_p->settings);
1260void UpdateHandler::handleUpdateCheckDone()
1262#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1264 scheduleNextUpdateCheck();
1268#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1269void UpdateHandler::scheduleNextUpdateCheck()
1274 if (!interval.enabled || (interval.duration.isNull() && m_p->hasCheckedOnceSinceStartup)) {
1277 const auto timeLeft = interval.duration - (CppUtilities::DateTime::now() - m_p->notifier.lastCheck());
1278 std::cerr << CppUtilities::EscapeCodes::Phrases::Info
1279 <<
"Check for updates due in: " << timeLeft.toString(CppUtilities::TimeSpanOutputFormat::WithMeasures)
1280 << CppUtilities::EscapeCodes::Phrases::End;
1281 m_p->hasCheckedOnceSinceStartup =
true;
1282 m_p->timer.start(std::max(1000,
static_cast<int>(timeLeft.totalMilliseconds())));
1288 m_restartRequested =
true;
1289#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1290 QCoreApplication::quit();
1296#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1297 if (!m_restartRequested) {
1300 auto *
const process =
new QProcess(QCoreApplication::instance());
1301 auto args = QCoreApplication::arguments();
1303 process->setProgram(QCoreApplication::applicationFilePath());
1304 process->setArguments(args);
1305 process->startDetached();
1309#ifdef QT_UTILITIES_GUI_QTWIDGETS
1310struct UpdateOptionPagePrivate {
1312 : updateHandler(updateHandler)
1315 UpdateHandler *updateHandler =
nullptr;
1316 std::function<void()> restartHandler;
1319UpdateOptionPage::UpdateOptionPage(
UpdateHandler *updateHandler, QWidget *parentWidget)
1320 : UpdateOptionPageBase(parentWidget)
1321#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1322 , m_p(std::make_unique<UpdateOptionPagePrivate>(updateHandler))
1325#ifndef QT_UTILITIES_SETUP_TOOLS_ENABLED
1326 Q_UNUSED(updateHandler)
1330UpdateOptionPage::~UpdateOptionPage()
1334void UpdateOptionPage::setRestartHandler(std::function<
void()> &&handler)
1336 m_p->restartHandler = std::move(handler);
1337#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1338 if (ui() && m_p->restartHandler) {
1339 QObject::connect(ui()->restartPushButton, &QPushButton::clicked, widget(), m_p->restartHandler);
1344bool UpdateOptionPage::apply()
1346#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1347 if (!m_p->updateHandler) {
1351 .duration = CppUtilities::TimeSpan::fromMinutes(ui()->checkIntervalSpinBox->value()), .enabled = ui()->enabledCheckBox->isChecked() });
1355 m_p->updateHandler->notifier()->setFlags(flags);
1356 m_p->updateHandler->saveNotifierState();
1361void UpdateOptionPage::reset()
1363#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1364 if (!m_p->updateHandler) {
1367 const auto &checkInterval = m_p->updateHandler->checkInterval();
1368 ui()->checkIntervalSpinBox->setValue(
static_cast<int>(checkInterval.duration.totalMinutes()));
1369 ui()->enabledCheckBox->setChecked(checkInterval.enabled);
1370 const auto flags = m_p->updateHandler->notifier()->flags();
1376#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1377static QString formatReleaseNotes(
const QString &version,
const QString &releaseNotes)
1379 auto res = QCoreApplication::translate(
"QtGui::UpdateOptionPage",
"**Release notes of version %1:**\n\n").arg(version) + releaseNotes;
1382 static const auto re = QRegularExpression(R
"(https://github\.com/[^\s)]+)");
1383 static constexpr auto replacementLengthDiff = qsizetype(2);
1384 auto offset = qsizetype();
1385 for (
auto it = re.globalMatch(res); it.hasNext(); offset += replacementLengthDiff) {
1386 const auto match = it.next();
1387 const auto replacement = QChar(
'<') % match.captured(0) % QChar(
'>');
1388 res.replace(match.capturedStart() + offset, match.capturedLength(), replacement);
1395QWidget *UpdateOptionPage::setupWidget()
1397#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1398 if (m_p->updateHandler && m_p->updateHandler->notifier()->isSupported()) {
1399 auto *
const widget = UpdateOptionPageBase::setupWidget();
1400 ui()->versionInUseValueLabel->setText(QString::fromUtf8(CppUtilities::applicationInfo.version));
1401 ui()->updateWidget->hide();
1402 ui()->releaseNotesPushButton->hide();
1403 updateLatestVersion();
1405 QObject::connect(ui()->updatePushButton, &QPushButton::clicked, widget, [
this, widget] {
1406 if (
const auto preCheckError = m_p->updateHandler->preCheck(); preCheckError.isEmpty()
1407 || QMessageBox::critical(widget, QCoreApplication::applicationName(),
1408 QCoreApplication::translate(
"QtGui::UpdateOptionPage",
"<p>%1</p><p><strong>Try the update nevertheless?</strong></p>")
1409 .arg(preCheckError),
1410 QMessageBox::Yes | QMessageBox::No)
1411 == QMessageBox::Yes) {
1412 m_p->updateHandler->performUpdate();
1415 QObject::connect(ui()->abortUpdatePushButton, &QPushButton::clicked, m_p->updateHandler->updater(), &
Updater::abortUpdate);
1416 if (m_p->restartHandler) {
1417 QObject::connect(ui()->restartPushButton, &QPushButton::clicked, widget, m_p->restartHandler);
1419 QObject::connect(ui()->releaseNotesPushButton, &QPushButton::clicked, widget, [
this, widget] {
1420 const auto *
const notifier = m_p->updateHandler->notifier();
1421 auto infobox = QMessageBox(widget);
1422 infobox.setWindowTitle(QCoreApplication::applicationName());
1423 infobox.setIcon(QMessageBox::Information);
1424 infobox.setText(formatReleaseNotes(notifier->latestVersion(), notifier->releaseNotes()));
1425#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
1426 infobox.setTextFormat(Qt::MarkdownText);
1428 infobox.setTextFormat(Qt::PlainText);
1435 const auto *const updater = m_p->updateHandler->updater();
1436 ui()->updateWidget->setVisible(true);
1437 ui()->updateInProgressLabel->setText(updater->overallStatus());
1438 ui()->updateProgressBar->setVisible(inProgress);
1439 ui()->abortUpdatePushButton->setVisible(inProgress);
1440 ui()->restartPushButton->setVisible(!inProgress && !updater->storedPath().isEmpty() && updater->error().isEmpty());
1443 [
this](
const QString &statusMessage) { ui()->updateStatusLabel->setText(statusMessage); });
1445 if (bytesTotal == 0) {
1446 ui()->updateProgressBar->setMaximum(0);
1448 ui()->updateProgressBar->setValue(static_cast<int>(bytesReceived * 100 / bytesTotal));
1449 ui()->updateProgressBar->setMaximum(100);
1456 auto *
const label =
new QLabel;
1457 label->setWindowTitle(QCoreApplication::translate(
"QtGui::UpdateOptionPage",
"Updating"));
1458 label->setAlignment(Qt::AlignCenter);
1459 label->setWordWrap(
true);
1460#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1461 label->setText(QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
"Checking for updates is not supported on this platform."));
1463 label->setText(QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
1464 "This build of %1 has automatic updates disabled. You may update the application in an automated way via your package manager, though.")
1465 .arg(CppUtilities::applicationInfo.name));
1470void UpdateOptionPage::updateLatestVersion(
bool)
1472#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1473 if (!m_p->updateHandler) {
1476 const auto ¬ifier = *m_p->updateHandler->notifier();
1477 const auto &downloadUrl = notifier.downloadUrl();
1478 const auto &previousVersionDownloadUrl = notifier.previousVersionDownloadUrl();
1479 const auto downloadUrlEscaped = downloadUrl.toString().toHtmlEscaped();
1480 const auto previousVersionDownloadUrlEscaped = previousVersionDownloadUrl.toString().toHtmlEscaped();
1481 ui()->latestVersionValueLabel->setText(notifier.status());
1482 ui()->downloadUrlLabel->setText(downloadUrl.isEmpty()
1483 ? (notifier.latestVersion().isEmpty()
1484 ? QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
"no new version available for download")
1485 : (QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
"latest version provides no build for the current platform yet")
1486 + (previousVersionDownloadUrl.isEmpty()
1488 : QString(QStringLiteral(
"<br>")
1489 % QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
"for latest build: ")
1490 % QStringLiteral(
"<a href=\"") % previousVersionDownloadUrlEscaped % QStringLiteral(
"\">")
1491 % previousVersionDownloadUrlEscaped % QStringLiteral(
"</a>")))))
1492 : (QStringLiteral(
"<a href=\"") % downloadUrlEscaped % QStringLiteral(
"\">") % downloadUrlEscaped % QStringLiteral(
"</a>")));
1493 ui()->updatePushButton->setText(!downloadUrl.isEmpty() || previousVersionDownloadUrl.isEmpty()
1494 ? QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
"Update to latest version")
1495 : QCoreApplication::translate(
"QtUtilities::UpdateOptionPage",
"Update to latest available build"));
1496 ui()->updatePushButton->setDisabled(downloadUrl.isEmpty() && previousVersionDownloadUrl.isEmpty());
1497 ui()->releaseNotesPushButton->setHidden(notifier.releaseNotes().isEmpty());
1501VerificationErrorMessageBox::VerificationErrorMessageBox()
1503#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1504 setWindowTitle(QCoreApplication::applicationName());
1505 setStandardButtons(QMessageBox::Cancel | QMessageBox::Ignore);
1506 setDefaultButton(QMessageBox::Cancel);
1507 setIcon(QMessageBox::Critical);
1511VerificationErrorMessageBox::~VerificationErrorMessageBox()
1515int VerificationErrorMessageBox::execForError(QString &errorMessage,
const QString &explanation)
1517#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1518 auto loop = QEventLoop();
1519 QObject::connect(
this, &QDialog::finished, &loop, &QEventLoop::exit);
1520 QMetaObject::invokeMethod(
this,
"openForError", Qt::QueuedConnection, Q_ARG(QString, errorMessage), Q_ARG(QString, explanation));
1521 auto res = loop.exec();
1522 if (res == QMessageBox::Ignore) {
1523 errorMessage.clear();
1527 Q_UNUSED(errorMessage)
1528 Q_UNUSED(explanation)
1533void VerificationErrorMessageBox::openForError(
const QString &errorMessage,
const QString &explanation)
1535#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
1536 setText(tr(
"<p>The signature of the downloaded executable could not be verified: %1</p>").arg(errorMessage) + explanation);
1539 Q_UNUSED(errorMessage)
1540 Q_UNUSED(explanation)
1544struct UpdateDialogPrivate {
1545 UpdateOptionPage *updateOptionPage =
nullptr;
1548UpdateDialog::UpdateDialog(QWidget *parent)
1550 , m_p(std::make_unique<UpdateDialogPrivate>())
1552 auto *
const category =
new OptionCategory;
1554 category->assignPages({ m_p->updateOptionPage });
1555 setWindowTitle(m_p->updateOptionPage->widget()->windowTitle());
1556 setTabBarAlwaysVisible(
false);
1557 setSingleCategory(category);
1560UpdateDialog::~UpdateDialog()
1564UpdateOptionPage *UpdateDialog::page()
1566 return m_p->updateOptionPage;
1569const UpdateOptionPage *UpdateDialog::page()
const
1571 return m_p->updateOptionPage;
1578#if defined(QT_UTILITIES_GUI_QTWIDGETS)
void respawnIfRestartRequested()
The SettingsDialog class provides a framework for creating settings dialogs with different categories...
The UpdateHandler class manages the non-graphical aspects of checking for new updates and performing ...
~UpdateHandler() override
bool isConsideringSeparateSignature() const
static UpdateHandler * mainInstance()
void setConsideringSeparateSignature(bool consideringSeparateSignature)
UpdateHandler(QSettings *settings, QNetworkAccessManager *nm, QObject *parent=nullptr)
Handles checking for updates and performing an update of the application if available.
const CheckInterval & checkInterval() const
UpdateNotifier * notifier
void setCheckInterval(CheckInterval checkInterval)
The UpdateNotifier class allows checking for new updates.
void setFlags(UpdateCheckFlags flags)
void setNetworkAccessManager(QNetworkAccessManager *nm)
UpdateNotifier(QObject *parent=nullptr)
void save(QSettings *settings)
bool isInProgress() const
QUrl previousVersionSignatureUrl
bool isUpdateAvailable() const
void inProgressChanged(bool inProgress)
QUrl previousVersionDownloadUrl
void supplyNewReleaseData(const QByteArray &data)
UpdateCheckFlags flags() const
const QString & latestVersion() const
void restore(QSettings *settings)
CppUtilities::DateTime lastCheck() const
~UpdateNotifier() override
The Updater class allows downloading and applying an update.
Updater(const QString &executableName, QObject *parent=nullptr)
void updatePercentageChanged(qint64 bytesReceived, qint64 bytesTotal)
void updateStatusChanged(const QString &statusMessage)
void updateFailed(const QString &error)
std::function< QString(const Update &)> VerifyFunction
bool performUpdate(const QString &downloadUrl, const QString &signatureUrl)
void setVerifier(VerifyFunction &&verifyFunction)
void inProgressChanged(bool inProgress)
void setNetworkAccessManager(QNetworkAccessManager *nm)
bool isInProgress() const
qsizetype VersionSuffixIndex
#define INSTANTIATE_UI_FILE_BASED_OPTION_PAGE(SomeClass)
Instantiates a class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE in a convenient way.
bool considerSeparateSignature
UpdateHandlerPrivate(const QString &executableName, const QString &signatureExtension)
std::optional< UpdateHandler::CheckInterval > checkInterval
bool hasCheckedOnceSinceStartup
The CheckInterval struct specifies whether automatic checks for updates are enabled and of often they...
#define QT_UTILITIES_EXE_REGEX
#define QT_UTILITIES_VERSION_SUFFIX