dont auto-update in dev mode

This commit is contained in:
Lion Kortlepel 2024-06-22 23:20:46 +02:00
parent 1f7c498bd9
commit c95178ea59
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
3 changed files with 40 additions and 38 deletions

View File

@ -19,10 +19,3 @@ void StartProxy();
void ConfigInit(); void ConfigInit();
extern bool Dev; extern bool Dev;
struct VersionParser {
explicit VersionParser(const std::string& from_string);
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
bool operator==(VersionParser const& rhs) const noexcept;
std::vector<std::string> split;
std::vector<size_t> data;
};

View File

@ -48,8 +48,8 @@ void ConfigInit() {
if (cfg.is_open()) { if (cfg.is_open()) {
cfg << cfg <<
R"({ R"({
"Port": 4444, "Port": 4444,
"Build": "Default" "Build": "Default"
})"; })";
cfg.close(); cfg.close();
} else { } else {

View File

@ -7,6 +7,7 @@
/// ///
#include "zip_file.h" #include "zip_file.h"
#include <charconv>
#include <httplib.h> #include <httplib.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
@ -31,36 +32,44 @@ int ProxyPort = 0;
namespace fs = std::filesystem; namespace fs = std::filesystem;
VersionParser::VersionParser(const std::string& from_string) { struct Version {
std::string token; uint8_t major;
std::istringstream tokenStream(from_string); uint8_t minor;
while (std::getline(tokenStream, token, '.')) { uint8_t patch;
data.emplace_back(std::stol(token)); Version(uint8_t major, uint8_t minor, uint8_t patch);
split.emplace_back(token); Version(const std::array<uint8_t, 3>& v);
};
std::array<uint8_t, 3> VersionStrToInts(const std::string& str) {
std::array<uint8_t, 3> Version;
std::stringstream ss(str);
for (uint8_t& i : Version) {
std::string Part;
std::getline(ss, Part, '.');
std::from_chars(&*Part.begin(), &*Part.begin() + Part.size(), i);
}
return Version;
}
bool IsOutdated(const Version& Current, const Version& Newest) {
if (Newest.major > Current.major) {
return true;
} else if (Newest.major == Current.major && Newest.minor > Current.minor) {
return true;
} else if (Newest.major == Current.major && Newest.minor == Current.minor && Newest.patch > Current.patch) {
return true;
} else {
return false;
} }
} }
std::strong_ordering VersionParser::operator<=>( Version::Version(uint8_t major, uint8_t minor, uint8_t patch)
const VersionParser& rhs) const noexcept { : major(major)
size_t const fields = std::min(data.size(), rhs.data.size()); , minor(minor)
for (size_t i = 0; i != fields; ++i) { , patch(patch) { }
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 VersionParser::operator==(const VersionParser& rhs) const noexcept { Version::Version(const std::array<uint8_t, 3>& v)
return std::is_eq(*this <=> rhs); : Version(v[0], v[1], v[2]) {
} }
std::string GetEN() { std::string GetEN() {
@ -75,7 +84,7 @@ std::string GetVer() {
return "2.0"; return "2.0";
} }
std::string GetPatch() { std::string GetPatch() {
return ".85"; return ".99";
} }
std::string GetEP(char* P) { std::string GetEP(char* P) {
@ -163,7 +172,7 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
system("clear"); system("clear");
#endif #endif
if (FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(GetVer() + GetPatch())) { if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion))) && !Dev) {
info("Launcher update found!"); info("Launcher update found!");
#if defined(__linux__) #if defined(__linux__)
error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches."); error("Auto update is NOT implemented for the Linux version. Please update manually ASAP as updates contain security patches.");
@ -177,7 +186,7 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
+ PublicKey + "&branch=" + Branch, + PublicKey + "&branch=" + Branch,
EP); EP);
URelaunch(argc, args); URelaunch(argc, args);
#endif #endif
} else } else
info("Launcher version is up to date"); info("Launcher version is up to date");
TraceBack++; TraceBack++;