diff --git a/source/plugin/PluginMetaInformation.cpp b/source/plugin/PluginMetaInformation.cpp index 0380624..8dbe35e 100644 --- a/source/plugin/PluginMetaInformation.cpp +++ b/source/plugin/PluginMetaInformation.cpp @@ -9,4 +9,5 @@ PluginMetaInformation::PluginMetaInformation(const PluginMetaInformation &other) this->description = other.description; this->size = other.size; this->storageId = other.storageId; + this->wupsversion = other.wupsversion; } \ No newline at end of file diff --git a/source/plugin/PluginMetaInformation.h b/source/plugin/PluginMetaInformation.h index 454b7cc..15759fb 100644 --- a/source/plugin/PluginMetaInformation.h +++ b/source/plugin/PluginMetaInformation.h @@ -17,6 +17,7 @@ #pragma once +#include "WUPSVersion.h" #include #include @@ -48,6 +49,10 @@ public: return this->description; } + [[nodiscard]] const WUPSVersion &getWUPSVersion() const { + return this->wupsversion; + } + [[nodiscard]] const std::string &getStorageId() const { return this->storageId; } @@ -83,6 +88,14 @@ private: this->description = std::move(_description); } + void setWUPSVersion(uint16_t major, uint16_t minor, uint16_t revision) { + this->wupsversion = WUPSVersion(major, minor, revision); + } + + void setWUPSVersion(WUPSVersion &_wupsversion) { + this->wupsversion = _wupsversion; + } + void setSize(size_t _size) { this->size = _size; } @@ -99,6 +112,7 @@ private: std::string description; std::string storageId; size_t size{}; + WUPSVersion wupsversion = WUPSVersion(0, 0, 0); friend class PluginMetaInformationFactory; diff --git a/source/plugin/PluginMetaInformationFactory.cpp b/source/plugin/PluginMetaInformationFactory.cpp index 1c2bda2..628e405 100644 --- a/source/plugin/PluginMetaInformationFactory.cpp +++ b/source/plugin/PluginMetaInformationFactory.cpp @@ -103,7 +103,9 @@ std::unique_ptr PluginMetaInformationFactory::loadPlugin( } else if (key == "storage_id") { pluginInfo->setStorageId(value); } else if (key == "wups") { - if (value != "0.7.1") { + if (value == "0.7.1") { + pluginInfo->setWUPSVersion(0, 7, 1); + } else { error = PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION; DEBUG_FUNCTION_LINE_ERR("Warning: Ignoring plugin - Unsupported WUPS version: %s.", value.c_str()); return nullptr; diff --git a/source/plugin/WUPSVersion.h b/source/plugin/WUPSVersion.h new file mode 100644 index 0000000..3238476 --- /dev/null +++ b/source/plugin/WUPSVersion.h @@ -0,0 +1,49 @@ +#include "utils/StringTools.h" +#include +#include + +class WUPSVersion { +public: + WUPSVersion(int major, int minor, int revision) + : mVersion((static_cast(major) << 32) | + (static_cast(minor) << 16) | + static_cast(revision)) {} + + WUPSVersion(const WUPSVersion &other) = default; + + static std::optional createFromString(const std::string &versionStr) { + char *end; + errno = 0; // Initialize errno before calling strtol + + auto major = strtol(versionStr.c_str(), &end, 10); + if (errno || *end != '.') { + return std::nullopt; + } + + + auto minor = strtol(end + 1, &end, 10); + if (errno || *end != '.') { + return std::nullopt; + } + + auto revision = strtol(end + 1, &end, 10); + if (errno || *end != '\0') { + return std::nullopt; + } + + return WUPSVersion(static_cast(major), static_cast(minor), static_cast(revision)); + } + + std::strong_ordering operator<=>(const WUPSVersion &other) const { + return mVersion <=> other.mVersion; + } + + [[nodiscard]] std::string toString() const { + return string_format("%d.%d.%d", static_cast((mVersion >> 32) & 0xFFFF), + static_cast((mVersion >> 16) & 0xFFFF), + static_cast((mVersion) &0xFFFF)); + } + +private: + uint64_t mVersion{}; +};