Store version numbers in the appropriate type

This commit is contained in:
sledgehammer999 2025-06-30 10:08:22 +03:00
parent c47b981a56
commit 9ad4a94940
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
3 changed files with 22 additions and 27 deletions

View file

@ -1662,11 +1662,11 @@ void MainWindow::handleUpdateCheckFinished(ProgramUpdater *updater, const bool i
updater->deleteLater(); updater->deleteLater();
}; };
const QString newVersion = updater->getNewVersion(); const auto newVersion = updater->getNewVersion();
if (!newVersion.isEmpty()) if (newVersion.isValid())
{ {
const QString msg {tr("A new version is available.") + u"<br/>" const QString msg {tr("A new version is available.") + u"<br/>"
+ tr("Do you want to download %1?").arg(newVersion) + u"<br/><br/>" + tr("Do you want to download %1?").arg(newVersion.toString()) + u"<br/><br/>"
+ u"<a href=\"https://www.qbittorrent.org/news\">%1</a>"_s.arg(tr("Open changelog..."))}; + u"<a href=\"https://www.qbittorrent.org/news\">%1</a>"_s.arg(tr("Open changelog..."))};
auto *msgBox = new QMessageBox {QMessageBox::Question, tr("qBittorrent Update Available"), msg auto *msgBox = new QMessageBox {QMessageBox::Question, tr("qBittorrent Update Available"), msg
, (QMessageBox::Yes | QMessageBox::No), this}; , (QMessageBox::Yes | QMessageBox::No), this};

View file

@ -49,23 +49,20 @@
namespace namespace
{ {
bool isVersionMoreRecent(const QString &remoteVersion) bool isVersionMoreRecent(const ProgramUpdater::Version &remoteVersion)
{ {
using Version = Utils::Version<4, 3>; if (!remoteVersion.isValid())
const auto newVersion = Version::fromString(remoteVersion);
if (!newVersion.isValid())
return false; return false;
const Version currentVersion {QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD}; const ProgramUpdater::Version currentVersion {QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD};
if (newVersion == currentVersion) if (remoteVersion == currentVersion)
{ {
const bool isDevVersion = QStringLiteral(QBT_VERSION_STATUS).contains( const bool isDevVersion = QStringLiteral(QBT_VERSION_STATUS).contains(
QRegularExpression(u"(alpha|beta|rc)"_s)); QRegularExpression(u"(alpha|beta|rc)"_s));
if (isDevVersion) if (isDevVersion)
return true; return true;
} }
return (newVersion > currentVersion); return (remoteVersion > currentVersion);
} }
QString buildVariant() QString buildVariant()
@ -99,7 +96,7 @@ void ProgramUpdater::checkForUpdates() const
m_hasCompletedOneReq = false; m_hasCompletedOneReq = false;
} }
QString ProgramUpdater::getNewVersion() const ProgramUpdater::Version ProgramUpdater::getNewVersion() const
{ {
return shouldUseFallback() ? m_fallbackRemoteVersion : m_remoteVersion; return shouldUseFallback() ? m_fallbackRemoteVersion : m_remoteVersion;
} }
@ -153,9 +150,10 @@ void ProgramUpdater::rssDownloadFinished(const Net::DownloadResult &result)
if (!version.isEmpty()) if (!version.isEmpty())
{ {
qDebug("Detected version is %s", qUtf8Printable(version)); qDebug("Detected version is %s", qUtf8Printable(version));
if (isVersionMoreRecent(version)) const ProgramUpdater::Version tmpVer {version};
if (isVersionMoreRecent(tmpVer))
{ {
m_remoteVersion = version; m_remoteVersion = tmpVer;
m_updateURL = updateLink; m_updateURL = updateLink;
} }
} }
@ -192,9 +190,9 @@ void ProgramUpdater::fallbackDownloadFinished(const Net::DownloadResult &result)
if (const QJsonValue verJSON = json[platformKey][u"version"_s]; verJSON.isString()) if (const QJsonValue verJSON = json[platformKey][u"version"_s]; verJSON.isString())
{ {
const auto ver = verJSON.toString(); const ProgramUpdater::Version tmpVer {verJSON.toString()};
if (isVersionMoreRecent(ver)) if (isVersionMoreRecent(tmpVer))
m_fallbackRemoteVersion = ver; m_fallbackRemoteVersion = tmpVer;
} }
handleFinishedRequest(); handleFinishedRequest();
@ -215,10 +213,5 @@ void ProgramUpdater::handleFinishedRequest()
bool ProgramUpdater::shouldUseFallback() const bool ProgramUpdater::shouldUseFallback() const
{ {
using Version = Utils::Version<4, 3>; return m_fallbackRemoteVersion > m_remoteVersion;
const auto remote = Version::fromString(m_remoteVersion);
const auto fallback = Version::fromString(m_fallbackRemoteVersion);
return fallback > remote;
} }

View file

@ -30,9 +30,10 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include <QString>
#include <QUrl> #include <QUrl>
#include "base/utils/version.h"
namespace Net namespace Net
{ {
struct DownloadResult; struct DownloadResult;
@ -45,9 +46,10 @@ class ProgramUpdater final : public QObject
public: public:
using QObject::QObject; using QObject::QObject;
using Version = Utils::Version<4, 3>;
void checkForUpdates() const; void checkForUpdates() const;
QString getNewVersion() const; Version getNewVersion() const;
bool updateProgram() const; bool updateProgram() const;
signals: signals:
@ -62,7 +64,7 @@ private:
bool shouldUseFallback() const; bool shouldUseFallback() const;
mutable bool m_hasCompletedOneReq = false; mutable bool m_hasCompletedOneReq = false;
QString m_remoteVersion; Version m_remoteVersion;
QString m_fallbackRemoteVersion; Version m_fallbackRemoteVersion;
QUrl m_updateURL; QUrl m_updateURL;
}; };