From 2b1dc178a473540f54fe4b8aa8eab63665c6d7c6 Mon Sep 17 00:00:00 2001 From: ConfiG Date: Mon, 7 Aug 2023 21:13:40 +0300 Subject: [PATCH] add any (`*`) to ComparableVersionInfo --- loader/include/Geode/utils/VersionInfo.hpp | 9 +++++++-- loader/src/utils/VersionInfo.cpp | 14 ++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/loader/include/Geode/utils/VersionInfo.hpp b/loader/include/Geode/utils/VersionInfo.hpp index 4ceea8d8..da690a0f 100644 --- a/loader/include/Geode/utils/VersionInfo.hpp +++ b/loader/include/Geode/utils/VersionInfo.hpp @@ -13,6 +13,7 @@ namespace geode { MoreEq, Less, More, + Any }; /** @@ -185,7 +186,7 @@ namespace geode { protected: VersionInfo m_version; VersionCompare m_compare = VersionCompare::Exact; - + public: constexpr ComparableVersionInfo() = default; constexpr ComparableVersionInfo( @@ -196,12 +197,16 @@ namespace geode { static Result parse(std::string const& string); constexpr bool compare(VersionInfo const& version) const { + if (m_compare == VersionCompare::Any) { + return true; + } + // opposing major versions never match if (m_version.getMajor() != version.getMajor()) { return false; } - // the comparison works invertedly as a version like "v1.2.0" + // the comparison works invertedly as a version like "v1.2.0" // should return true for "<=v1.3.0" switch (m_compare) { case VersionCompare::LessEq: diff --git a/loader/src/utils/VersionInfo.cpp b/loader/src/utils/VersionInfo.cpp index 5cb514c7..be379c3a 100644 --- a/loader/src/utils/VersionInfo.cpp +++ b/loader/src/utils/VersionInfo.cpp @@ -133,6 +133,11 @@ std::ostream& geode::operator<<(std::ostream& stream, VersionInfo const& version Result ComparableVersionInfo::parse(std::string const& rawStr) { VersionCompare compare; auto string = rawStr; + + if (string == "*") { + return Ok(ComparableVersionInfo({0, 0, 0}, VersionCompare::Any)); + } + if (string.starts_with("<=")) { compare = VersionCompare::LessEq; string.erase(0, 2); @@ -162,13 +167,14 @@ Result ComparableVersionInfo::parse(std::string const& ra } std::string ComparableVersionInfo::toString() const { - std::string prefix = ""; + std::string prefix; switch (m_compare) { - case VersionCompare::Exact: prefix = "="; break; + case VersionCompare::Exact: prefix = "="; break; case VersionCompare::LessEq: prefix = "<="; break; case VersionCompare::MoreEq: prefix = ">="; break; - case VersionCompare::Less: prefix = "<"; break; - case VersionCompare::More: prefix = ">"; break; + case VersionCompare::Less: prefix = "<"; break; + case VersionCompare::More: prefix = ">"; break; + case VersionCompare::Any: return "*"; } return prefix + m_version.toString(); }