VersionNumber parsing
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
#include <QtCore/QtCore>
|
||||
#include <thread>
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ AboutWindow::AboutWindow(QWidget* parent): QObject(parent) {
|
||||
auto versionLabel = this->windowWidget->findChild<QLabel*>("version-label");
|
||||
|
||||
if (versionLabel != nullptr) {
|
||||
versionLabel->setText("Bloom v" + QString::fromStdString(Application::VERSION_STR));
|
||||
versionLabel->setText("Bloom v" + QString::fromStdString(Application::VERSION.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
28
src/VersionNumber.cpp
Normal file
28
src/VersionNumber.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "VersionNumber.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
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::uint32_t>(
|
||||
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);
|
||||
}
|
||||
63
src/VersionNumber.hpp
Normal file
63
src/VersionNumber.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user