diff --git a/src/gui/updater/ocupdater.cpp b/src/gui/updater/ocupdater.cpp index 8d94b753866..9b05cb47963 100644 --- a/src/gui/updater/ocupdater.cpp +++ b/src/gui/updater/ocupdater.cpp @@ -12,11 +12,12 @@ * for more details. */ -#include "theme.h" -#include "configfile.h" -#include "common/utility.h" #include "accessmanager.h" #include "application.h" +#include "common/utility.h" +#include "common/version.h" +#include "configfile.h" +#include "theme.h" #include "updater/ocupdater.h" @@ -243,9 +244,8 @@ bool OCUpdater::updateSucceeded() const { QSettings settings(ConfigFile::configFile(), QSettings::IniFormat); - qint64 targetVersionInt = Helper::stringVersionToInt(settings.value(updateTargetVersionC).toString()); - qint64 currentVersion = Helper::currentVersionToInt(); - return currentVersion >= targetVersionInt; + const auto targetVersionInt = QVersionNumber::fromString(settings.value(updateTargetVersionC).toString()); + return Version::versionWithBuildNumber() >= targetVersionInt; } void OCUpdater::slotVersionInfoArrived() @@ -334,23 +334,22 @@ void NSISUpdater::slotDownloadFinished() void NSISUpdater::versionInfoArrived(const UpdateInfo &info) { QSettings settings(ConfigFile::configFile(), QSettings::IniFormat); - qint64 infoVersion = Helper::stringVersionToInt(info.version()); - auto seenString = settings.value(seenVersionC).toString(); - qint64 seenVersion = Helper::stringVersionToInt(seenString); - qint64 currVersion = Helper::currentVersionToInt(); + const auto infoVersion = QVersionNumber::fromString(info.version()); + const auto seenString = settings.value(seenVersionC).toString(); + const auto seenVersion = QVersionNumber::fromString(seenString); qCInfo(lcUpdater) << "Version info arrived:" - << "Your version:" << currVersion - << "Skipped version:" << seenVersion << seenString - << "Available version:" << infoVersion << info.version() - << "Available version string:" << info.versionString() - << "Web url:" << info.web() - << "Download url:" << info.downloadUrl(); + << "Your version:" << Version::versionWithBuildNumber() + << "Skipped version:" << seenVersion << seenString + << "Available version:" << infoVersion << info.version() + << "Available version string:" << info.versionString() + << "Web url:" << info.web() + << "Download url:" << info.downloadUrl(); if (info.version().isEmpty()) { qCInfo(lcUpdater) << "No version information available at the moment"; setDownloadState(UpToDate); - } else if (infoVersion <= currVersion - || infoVersion <= seenVersion) { + } else if (infoVersion <= Version::versionWithBuildNumber() + || infoVersion <= seenVersion) { qCInfo(lcUpdater) << "Client is on latest version!"; setDownloadState(UpToDate); } else { @@ -399,7 +398,7 @@ void NSISUpdater::showNoUrlDialog(const UpdateInfo &info) QString txt = tr("
A new version of the %1 Client is available.
" "%2 is available for download. The installed version is %3.
") .arg(Utility::escape(Theme::instance()->appNameGUI()), - Utility::escape(info.versionString()), Utility::escape(clientVersion())); + Utility::escape(info.versionString()), Utility::escape(Version::versionWithBuildNumber().toString())); lbl->setText(txt); lbl->setTextFormat(Qt::RichText); @@ -450,7 +449,7 @@ void NSISUpdater::showUpdateErrorDialog(const QString &targetVersion) QString txt = tr("A new version of the %1 Client is available but the updating process failed.
" "%2 has been downloaded. The installed version is %3.
") .arg(Utility::escape(Theme::instance()->appNameGUI()), - Utility::escape(targetVersion), Utility::escape(clientVersion())); + Utility::escape(targetVersion), Utility::escape(Version::versionWithBuildNumber().toString())); lbl->setText(txt); lbl->setTextFormat(Qt::RichText); @@ -501,7 +500,7 @@ bool NSISUpdater::handleStartup() if (updateSucceeded()) { // success: clean up qCInfo(lcUpdater) << "The requested update attempt has succeeded" - << Helper::currentVersionToInt(); + << Version::versionWithBuildNumber(); wipeUpdateData(); return false; } else { @@ -553,10 +552,8 @@ void PassiveUpdateNotifier::backgroundCheckForUpdate() void PassiveUpdateNotifier::versionInfoArrived(const UpdateInfo &info) { - qint64 currentVer = Helper::currentVersionToInt(); - qint64 remoteVer = Helper::stringVersionToInt(info.version()); - - if (info.version().isEmpty() || currentVer >= remoteVer) { + const auto remoteVer = QVersionNumber::fromString(info.version()); + if (info.version().isEmpty() || Version::versionWithBuildNumber() >= remoteVer) { qCInfo(lcUpdater) << "Client is on latest version!"; setDownloadState(UpToDate); } else { diff --git a/src/gui/updater/updater.cpp b/src/gui/updater/updater.cpp index 87a996bd298..8713989e9ca 100644 --- a/src/gui/updater/updater.cpp +++ b/src/gui/updater/updater.cpp @@ -85,7 +85,7 @@ QUrlQuery Updater::getQueryParams() if (!sysInfo.isEmpty()) { query.addQueryItem(QStringLiteral("client"), sysInfo); } - query.addQueryItem(QStringLiteral("version"), clientVersion()); + query.addQueryItem(QStringLiteral("version"), Version::versionWithBuildNumber().toString()); query.addQueryItem(QStringLiteral("platform"), platform); query.addQueryItem(QStringLiteral("oem"), theme->appName()); query.addQueryItem(QStringLiteral("buildArch"), QSysInfo::buildCpuArchitecture()); @@ -140,32 +140,4 @@ Updater *Updater::create() #endif } - -qint64 Updater::Helper::versionToInt(qint64 major, qint64 minor, qint64 patch, qint64 build) -{ - return major << 56 | minor << 48 | patch << 40 | build; -} - -qint64 Updater::Helper::currentVersionToInt() -{ - // TODO: directly use QVersionNumber - return versionToInt(OCC::Version::version().majorVersion(), OCC::Version::version().minorVersion(), - OCC::Version::version().microVersion(), OCC::Version::buildNumber()); -} - -qint64 Updater::Helper::stringVersionToInt(const QString &version) -{ - if (version.isEmpty()) - return 0; - QByteArray baVersion = version.toLatin1(); - int major = 0, minor = 0, patch = 0, build = 0; - sscanf(baVersion, "%d.%d.%d.%d", &major, &minor, &patch, &build); - return versionToInt(major, minor, patch, build); -} - -QString Updater::clientVersion() -{ - return Version::versionWithBuildNumber().toString(); -} - } // namespace OCC diff --git a/src/gui/updater/updater.h b/src/gui/updater/updater.h index 33ba2234113..40145030231 100644 --- a/src/gui/updater/updater.h +++ b/src/gui/updater/updater.h @@ -29,13 +29,6 @@ class Updater : public QObject { Q_OBJECT public: - struct Helper - { - static qint64 stringVersionToInt(const QString &version); - static qint64 currentVersionToInt(); - static qint64 versionToInt(qint64 major, qint64 minor, qint64 patch, qint64 build); - }; - static Updater *instance(); static QUrl updateUrl(); @@ -44,7 +37,6 @@ class Updater : public QObject virtual bool handleStartup() = 0; protected: - static QString clientVersion(); Updater() : QObject(nullptr) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d706c9d63f1..c7c4c74864c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,8 +3,6 @@ include(owncloud_add_test.cmake) add_subdirectory(testutils) owncloud_add_test(OwncloudPropagator) -owncloud_add_test(Updater) - owncloud_add_test(OwnSql) owncloud_add_test(SyncJournalDB) owncloud_add_test(SyncFileItem) diff --git a/test/testupdater.cpp b/test/testupdater.cpp deleted file mode 100644 index e8b27bf3c85..00000000000 --- a/test/testupdater.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - This software is in the public domain, furnished "as is", without technical - support, and with no warranty, express or implied, as to its usefulness for - any purpose. -*/ - -#include