From d376ad3feb0293e0786306034b874d3e9343acc2 Mon Sep 17 00:00:00 2001 From: Jamie Newbon Date: Thu, 22 Aug 2019 14:02:40 +0100 Subject: [PATCH] #6535 Version URL and added stage check to version check --- src/gui/src/VersionChecker.cpp | 68 ++++++++++++++++++++++++++-------- src/gui/src/VersionChecker.h | 9 ++++- src/lib/common/Version.cpp | 4 +- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/gui/src/VersionChecker.cpp b/src/gui/src/VersionChecker.cpp index 214f2ec5..f46968d1 100644 --- a/src/gui/src/VersionChecker.cpp +++ b/src/gui/src/VersionChecker.cpp @@ -24,8 +24,11 @@ #include #include -#define VERSION_REGEX "(\\d+\\.\\d+\\.\\d+)" -#define VERSION_URL "http://symless.com/version/" +#define VERSION_REGEX "(\\d+\\.\\d+\\.\\d+-[a-z1-9]*)" +#define VERSION_REGEX_SECTIONED "(\\d+)\\.(\\d+)\\.(\\d+)-([a-z1-9]*)" +#define VERSION_SEGMENT_COUNT 4 +#define VERSION_URL "http://version.symless.com/synergy" + VersionChecker::VersionChecker() { @@ -58,31 +61,64 @@ void VersionChecker::replyFinished(QNetworkReply* reply) } } +int VersionChecker::getStageVersion(QString stage) +{ + const int valueStable = INT_MAX; //Stable will always be considered the highest value + const int valueRC = 2; + const int valueSnapshot = 1; + const int valueOther = 0; + + //Stable should always be considered highest, followed by rc[0-9] then snapshots with everything else at the end + //HACK There is probably a much better way of doing this + if (stage == "stable") + { + return valueStable; + } + else if (stage.startsWith("rc") || stage.startsWith("RC")) + { + QRegExp rx("\\d*", Qt::CaseInsensitive); + if (rx.indexIn(stage) != -1) + { + //Return the RC value plus the RC version as in int + return valueRC + rx.cap(1).toInt(); + } + } + else if (stage == "snapshot") + { + return valueSnapshot; + } + + return valueOther; +} + int VersionChecker::compareVersions(const QString& left, const QString& right) { if (left.compare(right) == 0) return 0; // versions are same. - QStringList leftSplit = left.split(QRegExp("\\.")); - if (leftSplit.size() != 3) + QStringList leftSplit = left.split(QRegExp("[\\.-]")); + if (leftSplit.size() != VERSION_SEGMENT_COUNT) return 1; // assume right wins. - QStringList rightSplit = right.split(QRegExp("\\.")); - if (rightSplit.size() != 3) + QStringList rightSplit = right.split(QRegExp("[\\.-]")); + if (rightSplit.size() != VERSION_SEGMENT_COUNT) return -1; // assume left wins. - int leftMajor = leftSplit.at(0).toInt(); - int leftMinor = leftSplit.at(1).toInt(); - int leftRev = leftSplit.at(2).toInt(); + const int leftMajor = leftSplit.at(0).toInt(); + const int leftMinor = leftSplit.at(1).toInt(); + const int leftRev = leftSplit.at(2).toInt(); + const int leftStage = getStageVersion(leftSplit.at(3)); - int rightMajor = rightSplit.at(0).toInt(); - int rightMinor = rightSplit.at(1).toInt(); - int rightRev = rightSplit.at(2).toInt(); + const int rightMajor = rightSplit.at(0).toInt(); + const int rightMinor = rightSplit.at(1).toInt(); + const int rightRev = rightSplit.at(2).toInt(); + const int rightStage = getStageVersion(rightSplit.at(3)); - bool rightWins = - (rightMajor > leftMajor) || + const bool rightWins = + ( rightMajor > leftMajor) || ((rightMajor >= leftMajor) && (rightMinor > leftMinor)) || - ((rightMajor >= leftMajor) && (rightMinor >= leftMinor) && (rightRev > leftRev)); + ((rightMajor >= leftMajor) && (rightMinor >= leftMinor) && (rightRev > leftRev)) || + ((rightMajor >= leftMajor) && (rightMinor >= leftMinor) && (rightRev >= leftRev) && (rightStage > leftStage)); return rightWins ? 1 : -1; } @@ -95,7 +131,7 @@ QString VersionChecker::getVersion() process.setReadChannel(QProcess::StandardOutput); if (process.waitForStarted() && process.waitForFinished()) { - QRegExp rx(VERSION_REGEX); + QRegExp rx(VERSION_REGEX,Qt::CaseInsensitive); QString text = process.readLine(); if (rx.indexIn(text) != -1) { diff --git a/src/gui/src/VersionChecker.h b/src/gui/src/VersionChecker.h index 9f49cc37..2048d3d8 100644 --- a/src/gui/src/VersionChecker.h +++ b/src/gui/src/VersionChecker.h @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012-2019 Symless Ltd. * Copyright (C) 2012 Nick Bolton * * This package is free software; you can redistribute it and/or @@ -41,4 +41,11 @@ signals: private: QNetworkAccessManager* m_manager; QString m_app; + + /** + * \brief Converts a string stage to a integer value + * \param stage The string containing the stage version + * \return An integer representation of the stage, the higher the number the more recent the version + */ + int getStageVersion(QString stage); }; diff --git a/src/lib/common/Version.cpp b/src/lib/common/Version.cpp index d6449067..442c05b8 100644 --- a/src/lib/common/Version.cpp +++ b/src/lib/common/Version.cpp @@ -19,10 +19,10 @@ #include "common/Version.h" const char* kApplication = "Synergy"; -const char* kCopyright = "Copyright (C) 2012-2016 Symless Ltd.\n" +const char* kCopyright = "Copyright (C) 2012-2019 Symless Ltd.\n" "Copyright (C) 2008-2014 Nick Bolton\n" "Copyright (C) 2002-2014 Chris Schoeneman"; const char* kContact = "Email: engineering@symless.com"; const char* kWebsite = "https://symless.com/"; -const char* kVersion = SYNERGY_VERSION; +const char* kVersion = SYNERGY_VERSION_STRING; const char* kAppVersion = "Synergy " SYNERGY_VERSION;