5#include <QtCore/QApplicationStatic>
6#include <QtCore/QCoreApplication>
8#include <QtCore/QRegularExpression>
9#include <QtCore/QTextStream>
10#include <QtCore/QVersionNumber>
26std::optional<QVersionNumber> _parseVersion(
const QString& versionString)
28 static const QRegularExpression regExp(QStringLiteral(
"^v(\\d+)\\.(\\d+)\\.(\\d+)"));
29 const QRegularExpressionMatch match = regExp.match(versionString.trimmed());
30 if (!match.hasMatch()) {
34 return QVersionNumber(match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt());
45 return _qgcVersionCheckInstance();
50 const std::optional<QVersionNumber> current = _parseVersion(currentVersion);
51 const std::optional<QVersionNumber> latest = _parseVersion(latestVersion);
52 return current && latest && (*latest > *current);
57 const std::optional<QVersionNumber> latest = _parseVersion(latestVersion);
62 const std::optional<QVersionNumber> lastNotified = _parseVersion(lastNotifiedVersion);
63 return !lastNotified || (*latest > *lastNotified);
68 if (!_parseVersion(QCoreApplication::applicationVersion())) {
73 if (versionCheckFile.isEmpty()) {
79 [
this, download](
bool success,
const QString& localFile,
const QString& errorMsg) {
80 download->deleteLater();
81 _downloadComplete(success, localFile, errorMsg);
83 if (!download->
start(versionCheckFile)) {
84 qCDebug(QGCVersionCheckLog) <<
"Download QGC stable version failed to start" << download->
errorString();
85 download->deleteLater();
89void QGCVersionCheck::_downloadComplete(
bool success,
const QString& localFile,
const QString& errorMsg)
92 if (!errorMsg.isEmpty()) {
93 qCDebug(QGCVersionCheckLog) <<
"Download QGC stable version failed" << errorMsg;
98 QFile versionFile(localFile);
99 if (!versionFile.open(QIODevice::ReadOnly)) {
103 QTextStream textStream(&versionFile);
104 const QString version = textStream.readLine();
105 qCDebug(QGCVersionCheckLog) << version;
107 if (!
isNewerVersion(QCoreApplication::applicationVersion(), version)) {
111 _newStableVersion = version;
119 tr(
"There is a newer version of %1 available. You can download it from <a href=\"%2\">%2</a>.")
120 .arg(QCoreApplication::applicationName(), url),
121 tr(
"New Version Available"));
Unified file download utility with decompression, verification, and QML support.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Q_APPLICATION_STATIC(QGCVersionCheck, _qgcVersionCheckInstance)
A Fact is used to hold a single value within the system.
void setRawValue(const QVariant &value)
QVariant rawValue() const
virtual QString stableDownloadUrl() const
virtual QString stableVersionCheckFileUrl() const
static QGCCorePlugin * instance()
File download with progress, decompression, and hash verification.
void finished(bool success, const QString &localPath, const QString &errorMessage)
bool start(const QString &remoteUrl)
QString errorString() const
static bool isNewerVersion(const QString ¤tVersion, const QString &latestVersion)
QGCVersionCheck(QObject *parent=nullptr)
static bool shouldNotify(const QString &latestVersion, const QString &lastNotifiedVersion)
static QGCVersionCheck * instance()
void newStableVersionChanged()
void start()
Starts the asynchronous download of the stable version file.
static SettingsManager * instance()
AppSettings * appSettings() const