From e8d25beac09d310caa05b6b10c15461ba2d88876 Mon Sep 17 00:00:00 2001 From: Anonymous275 <36374260+Anonymous-275@users.noreply.github.com> Date: Tue, 18 Jan 2022 18:16:45 +0200 Subject: [PATCH] version checking fix and thank you windows for having min and max macros --- include/Logger.h | 3 ++- src/Network/Update.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/Logger.h b/include/Logger.h index 37a8582..c89c848 100644 --- a/include/Logger.h +++ b/include/Logger.h @@ -5,7 +5,8 @@ #pragma once #include - +#undef min +#undef max class Log { public: static void Init(); diff --git a/src/Network/Update.cpp b/src/Network/Update.cpp index 2e58259..14a9871 100644 --- a/src/Network/Update.cpp +++ b/src/Network/Update.cpp @@ -6,6 +6,31 @@ #include "Launcher.h" #include "Logger.h" #include "Http.h" +#include +struct Ver { + std::vector data; + explicit Ver(const std::string& from_string) { + std::string token; + std::istringstream tokenStream(from_string); + while (std::getline(tokenStream, token, '.')) { + data.emplace_back(std::stol(token)); + } + } + std::strong_ordering operator<=>(Ver const& rhs) const noexcept { + size_t const fields = std::min(data.size(), rhs.data.size()); + for(size_t i = 0; i != fields; ++i) { + if(data[i] == rhs.data[i]) continue; + else if(data[i] < rhs.data[i]) return std::strong_ordering::less; + else return std::strong_ordering::greater; + } + if(data.size() == rhs.data.size()) return std::strong_ordering::equal; + else if(data.size() > rhs.data.size()) return std::strong_ordering::greater; + else return std::strong_ordering::less; + } + bool operator==(Ver const& rhs) const noexcept { + return std::is_eq(*this <=> rhs); + } +}; void Launcher::UpdateCheck() { @@ -32,7 +57,8 @@ void Launcher::UpdateCheck() { RemoteVer += c; } } - if(RemoteVer > FullVersion){ + + if(Ver(RemoteVer) > Ver(FullVersion)){ system("cls"); LOG(INFO) << "Update found! Downloading..."; if(std::rename(EP.c_str(), Back.c_str())){