diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d8f6051..b5d971d1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ add_executable(Bloom # Helpers & other src/Logger/Logger.cpp src/Helpers/Paths.cpp + src/VersionNumber.cpp src/Generated/resources.cpp # Project & application configuration diff --git a/src/Application.cpp b/src/Application.cpp index 5895382b..6d249bf1 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -207,7 +207,7 @@ int Application::presentHelpText() { throw Exception("Failed to open help file - please report this issue at https://bloom.oscillate.io/report-issue"); } - std::cout << "Bloom v" << Application::VERSION_STR << "\n"; + std::cout << "Bloom v" << Application::VERSION.toString() << "\n"; std::cout << QTextStream(&helpFile).readAll().toUtf8().constData() << "\n"; return EXIT_SUCCESS; } @@ -215,7 +215,7 @@ int Application::presentHelpText() { int Application::presentVersionText() { Logger::silence(); - std::cout << "Bloom v" << Application::VERSION_STR << "\n"; + std::cout << "Bloom v" << Application::VERSION.toString() << "\n"; #ifdef BLOOM_DEBUG_BUILD std::cout << "DEBUG BUILD - Compilation timestamp: " << __DATE__ << " " << __TIME__ << "\n"; diff --git a/src/Application.hpp b/src/Application.hpp index 0dfdae95..4c35e415 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -7,14 +7,17 @@ #include #include +#include "src/Helpers/Thread.hpp" + #include "src/SignalHandler/SignalHandler.hpp" #include "src/TargetController/TargetController.hpp" #include "src/DebugServers/GdbRsp/AvrGdbRsp/AvrGdbRsp.hpp" #include "src/Insight/Insight.hpp" -#include "src/Helpers/Thread.hpp" + #include "src/Logger/Logger.hpp" #include "src/ApplicationConfig.hpp" -#include "src/Exceptions/Exception.hpp" +#include "src/VersionNumber.hpp" + #include "src/EventManager/EventListener.hpp" #include "src/EventManager/Events/Events.hpp" @@ -29,7 +32,7 @@ namespace Bloom class Application: public Thread { public: - static const inline std::string VERSION_STR = "0.4.2"; + static const inline VersionNumber VERSION = VersionNumber(0, 4, 2); explicit Application() = default; diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index 6fa9d421..df6dbde5 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -11,6 +11,7 @@ #include "src/Application.hpp" #include "InsightWorker/Tasks/QueryLatestVersionNumber.hpp" +#include "src/VersionNumber.hpp" using namespace Bloom; using namespace Bloom::Exceptions; @@ -160,20 +161,20 @@ void Insight::shutdown() { } void Insight::checkBloomVersion() { - auto currentVersionNumber = QString::fromStdString(Application::VERSION_STR); + auto currentVersionNumber = Application::VERSION; auto versionQueryTask = new QueryLatestVersionNumber( - QString::fromStdString(Application::VERSION_STR) + currentVersionNumber ); this->connect( versionQueryTask, &QueryLatestVersionNumber::latestVersionNumberRetrieved, this, - [this, currentVersionNumber] (const QString& latestVersionNumber) { - if (latestVersionNumber != currentVersionNumber) { + [this, currentVersionNumber] (const VersionNumber& latestVersionNumber) { + if (latestVersionNumber > currentVersionNumber) { Logger::warning( - "Bloom v" + latestVersionNumber.toStdString() + "Bloom v" + latestVersionNumber.toString() + " is available to download - upgrade via https://bloom.oscillate.io" ); } diff --git a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp b/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp index e294c164..7701deb6 100644 --- a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp +++ b/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp @@ -13,7 +13,7 @@ void QueryLatestVersionNumber::run(TargetControllerConsole& targetControllerCons auto networkAccessManager = new QNetworkAccessManager(this); auto queryVersionEndpointUrl = QUrl("http://bloom.local/latest-version"); queryVersionEndpointUrl.setQuery(QUrlQuery({ - {"currentVersionNumber", this->currentVersionNumber} + {"currentVersionNumber", QString::fromStdString(this->currentVersionNumber.toString())} })); auto response = networkAccessManager->get(QNetworkRequest(queryVersionEndpointUrl)); @@ -22,7 +22,9 @@ void QueryLatestVersionNumber::run(TargetControllerConsole& targetControllerCons if (jsonResponseObject.contains("latestVersionNumber")) { emit this->latestVersionNumberRetrieved( - jsonResponseObject.value("latestVersionNumber").toString() + VersionNumber( + jsonResponseObject.value("latestVersionNumber").toString().toStdString() + ) ); } }); diff --git a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp b/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp index 1e96f900..8972b217 100644 --- a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp +++ b/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp @@ -2,6 +2,8 @@ #include "InsightWorkerTask.hpp" +#include "src/VersionNumber.hpp" + namespace Bloom { class QueryLatestVersionNumber: public InsightWorkerTask @@ -9,16 +11,16 @@ namespace Bloom Q_OBJECT public: - QueryLatestVersionNumber(const QString& currentVersionNumber): + QueryLatestVersionNumber(const VersionNumber& currentVersionNumber): InsightWorkerTask(), currentVersionNumber(currentVersionNumber) {} signals: - void latestVersionNumberRetrieved(const QString& latestVersionNumber); + void latestVersionNumberRetrieved(const VersionNumber& latestVersionNumber); protected: void run(TargetControllerConsole& targetControllerConsole) override; private: - QString currentVersionNumber; + VersionNumber currentVersionNumber; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp index 51465ab7..204c6a5d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp @@ -37,6 +37,6 @@ AboutWindow::AboutWindow(QWidget* parent): QObject(parent) { auto versionLabel = this->windowWidget->findChild("version-label"); if (versionLabel != nullptr) { - versionLabel->setText("Bloom v" + QString::fromStdString(Application::VERSION_STR)); + versionLabel->setText("Bloom v" + QString::fromStdString(Application::VERSION.toString())); } } diff --git a/src/VersionNumber.cpp b/src/VersionNumber.cpp new file mode 100644 index 00000000..e0ac9290 --- /dev/null +++ b/src/VersionNumber.cpp @@ -0,0 +1,28 @@ +#include "VersionNumber.hpp" + +#include +#include + +using namespace Bloom; + +VersionNumber::VersionNumber(std::uint16_t major, std::uint16_t minor, std::uint16_t patch) +: major(major), minor(minor), patch(patch) { + this->combined = static_cast( + std::stoul(std::to_string(this->major) + std::to_string(this->minor) + std::to_string(this->patch)) + ); +} + +VersionNumber::VersionNumber(const std::string& versionNumber) { + auto versionNumberQStr = QString::fromStdString(versionNumber); + const auto explodedString = versionNumberQStr.split('.'); + + this->major = explodedString.value(0, "0").toUShort(); + this->minor = explodedString.value(1, "0").toUShort(); + this->patch = explodedString.value(2, "0").toUShort(); + + this->combined = versionNumberQStr.remove('.').toUInt(); +} + +std::string VersionNumber::toString() const { + return std::to_string(this->major) + "." + std::to_string(this->minor) + "." + std::to_string(this->patch); +} diff --git a/src/VersionNumber.hpp b/src/VersionNumber.hpp new file mode 100644 index 00000000..6de03405 --- /dev/null +++ b/src/VersionNumber.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include +#include + +namespace Bloom +{ + class VersionNumber + { + public: + VersionNumber(std::uint16_t major, std::uint16_t minor, std::uint16_t patch); + VersionNumber(const std::string& versionNumber); + + std::string toString() const; + + [[nodiscard]] std::uint16_t getMajor() const { + return this->major; + } + + [[nodiscard]] std::uint16_t getMinor() const { + return this->minor; + } + + [[nodiscard]] std::uint16_t getPatch() const { + return this->patch; + } + + bool operator == (const VersionNumber& other) const { + return this->combined == other.combined; + } + + bool operator != (const VersionNumber& other) const { + return !(*this == other); + } + + bool operator < (const VersionNumber& rhs) const { + return this->combined < rhs.combined; + } + + bool operator > (const VersionNumber& rhs) const { + return rhs < *this; + } + + bool operator <= (const VersionNumber& rhs) const { + return !(rhs < *this); + } + + bool operator >= (const VersionNumber& rhs) const { + return !(*this < rhs); + } + + private: + std::uint16_t major = 0; + std::uint16_t minor = 0; + std::uint16_t patch = 0; + + /** + * Integer of the three version segments concatenated (e.g for version 1.5.6, the combined value + * would be 156). + */ + std::uint32_t combined = 0; + }; +}