mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-08 16:56:22 +00:00
added ShutdownException and registry queries
This commit is contained in:
@@ -15,7 +15,10 @@ void UpdateKey(const char* newKey){
|
||||
if(Key.is_open()){
|
||||
Key << newKey;
|
||||
Key.close();
|
||||
}else LOG(FATAL) << "Cannot write to disk!";
|
||||
} else {
|
||||
LOG(FATAL) << "Cannot write to disk!";
|
||||
throw ShutdownException("Fatal Error");
|
||||
}
|
||||
}else if(fs::exists("key")){
|
||||
remove("key");
|
||||
}
|
||||
@@ -88,8 +91,9 @@ void Launcher::CheckKey() {
|
||||
Json::Document d;
|
||||
d.Parse(Buffer.c_str());
|
||||
if (Buffer == "-1" || Buffer.at(0) != '{' || d.HasParseError()) {
|
||||
LOG(ERROR) << Buffer;
|
||||
LOG(DEBUG) << Buffer;
|
||||
LOG(FATAL) << "Invalid answer from authentication servers, please try again later!";
|
||||
throw ShutdownException("Fatal Error");
|
||||
}
|
||||
if(d["success"].GetBool()){
|
||||
LoginAuth = true;
|
||||
|
||||
@@ -6,32 +6,30 @@
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include "Http.h"
|
||||
#include <sstream>
|
||||
struct Ver {
|
||||
std::vector<size_t> 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);
|
||||
}
|
||||
};
|
||||
|
||||
VersionParser::VersionParser(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 VersionParser::operator<=>(const VersionParser &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 VersionParser::operator==(const VersionParser &rhs) const noexcept {
|
||||
return std::is_eq(*this <=> rhs);
|
||||
}
|
||||
|
||||
void Launcher::UpdateCheck() {
|
||||
std::string link;
|
||||
@@ -42,6 +40,7 @@ void Launcher::UpdateCheck() {
|
||||
fallback = true;
|
||||
if(HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||
LOG(FATAL) << "Primary Servers Offline! sorry for the inconvenience!";
|
||||
throw ShutdownException("Fatal Error");
|
||||
}
|
||||
}
|
||||
if(fallback){
|
||||
@@ -58,7 +57,7 @@ void Launcher::UpdateCheck() {
|
||||
}
|
||||
}
|
||||
|
||||
if(Ver(RemoteVer) > Ver(FullVersion)){
|
||||
if(VersionParser(RemoteVer) > VersionParser(FullVersion)){
|
||||
system("cls");
|
||||
LOG(INFO) << "Update found! Downloading...";
|
||||
if(std::rename(EP.c_str(), Back.c_str())){
|
||||
|
||||
Reference in New Issue
Block a user