From 85908e42d5522382626182218ec5137bcabd79ce Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 4 Oct 2024 23:12:23 +0200 Subject: [PATCH] fix download code, error checking --- src/Network/Http.cpp | 26 ++++---------------------- src/Security/Login.cpp | 4 ++-- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Network/Http.cpp b/src/Network/Http.cpp index 56bf491..821fe90 100644 --- a/src/Network/Http.cpp +++ b/src/Network/Http.cpp @@ -118,35 +118,17 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) { return Ret; } -bool HTTP::ProgressBar(size_t c, size_t t) { - if (isDownload) { - static double last_progress, progress_bar_adv; - progress_bar_adv = round(c / double(t) * 25); - std::cout << "\r"; - std::cout << "Progress : [ "; - std::cout << round(c / double(t) * 100); - std::cout << "% ] ["; - int i; - for (i = 0; i <= progress_bar_adv; i++) - std::cout << "#"; - for (i = 0; i < 25 - progress_bar_adv; i++) - std::cout << "."; - std::cout << "]"; - last_progress = round(c / double(t) * 100); - } - return true; -} - bool HTTP::Download(const std::string& IP, const std::string& Path) { static std::mutex Lock; std::scoped_lock Guard(Lock); - isDownload = true; + info("Downloading an update (this may take a while)"); std::string Ret = Get(IP); - isDownload = false; - if (Ret.empty()) + if (Ret.empty()) { + error("Download failed"); return false; + } std::ofstream File(Path, std::ios::binary); if (File.is_open()) { diff --git a/src/Security/Login.cpp b/src/Security/Login.cpp index cfd6a24..750ecfe 100644 --- a/src/Security/Login.cpp +++ b/src/Security/Login.cpp @@ -58,7 +58,7 @@ std::string Login(const std::string& fields) { try { std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields); - if (Buffer == "-1") { + if (Buffer.empty()) { return GetFail("Failed to communicate with the auth system!"); } @@ -119,7 +119,7 @@ void CheckLocalKey() { nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false); - if (Buffer == "-1" || Buffer.at(0) != '{' || d.is_discarded()) { + if (Buffer.empty() || Buffer.at(0) != '{' || d.is_discarded()) { error(Buffer); info("Invalid answer from authentication servers."); UpdateKey(nullptr);