Skip to content

Commit

Permalink
Use QVersionNumber with our updater
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Nov 3, 2021
1 parent 3ea52cc commit 6605635
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 98 deletions.
47 changes: 22 additions & 25 deletions src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -399,7 +398,7 @@ void NSISUpdater::showNoUrlDialog(const UpdateInfo &info)
QString txt = tr("<p>A new version of the %1 Client is available.</p>"
"<p><b>%2</b> is available for download. The installed version is %3.</p>")
.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);
Expand Down Expand Up @@ -450,7 +449,7 @@ void NSISUpdater::showUpdateErrorDialog(const QString &targetVersion)
QString txt = tr("<p>A new version of the %1 Client is available but the updating process failed.</p>"
"<p><b>%2</b> has been downloaded. The installed version is %3.</p>")
.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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
30 changes: 1 addition & 29 deletions src/gui/updater/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
8 changes: 0 additions & 8 deletions src/gui/updater/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -44,7 +37,6 @@ class Updater : public QObject
virtual bool handleStartup() = 0;

protected:
static QString clientVersion();
Updater()
: QObject(nullptr)
{
Expand Down
2 changes: 0 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 0 additions & 34 deletions test/testupdater.cpp

This file was deleted.

0 comments on commit 6605635

Please sign in to comment.