From 9b903f64e4826244b4edbe5d1a872ae2d5c11d45 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 23 Nov 2022 15:31:48 +0000 Subject: [PATCH] [Changelog]: Re-order urls --- src/Components/Modules/Changelog.cpp | 30 ++++++++++++++-------------- src/Utils/Cache.cpp | 22 ++++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Components/Modules/Changelog.cpp b/src/Components/Modules/Changelog.cpp index 93b5974d..cafb5ebc 100644 --- a/src/Components/Modules/Changelog.cpp +++ b/src/Components/Modules/Changelog.cpp @@ -7,44 +7,44 @@ namespace Components void Changelog::LoadChangelog() { - //if (!Changelog::Lines.empty()) - // return; + std::lock_guard _(Mutex); + Lines.clear(); - std::lock_guard _(Changelog::Mutex); - Changelog::Lines.clear(); - std::string data = Utils::Cache::GetFile("/develop/CHANGELOG.md"); + const auto data = Utils::Cache::GetFile("/develop/CHANGELOG.md"); if (data.empty()) { - data = "^1Unable to get changelog."; + Lines.emplace_back("^1Unable to get changelog."); + return; } - Changelog::Lines = Utils::String::Split(data, '\n'); - - for (auto& line : Changelog::Lines) + auto buffer = Utils::String::Split(data, '\n'); + for (auto& line : buffer) { Utils::String::Replace(line, "\r", ""); } + + Lines = buffer; } unsigned int Changelog::GetChangelogCount() { - return Changelog::Lines.size(); + return Lines.size(); } // Omit column here - const char* Changelog::GetChangelogText(unsigned int item, int /*column*/) + const char* Changelog::GetChangelogText(unsigned int item, [[maybe_unused]] int column) { - std::lock_guard _(Changelog::Mutex); - if (item < Changelog::Lines.size()) + std::lock_guard _(Mutex); + if (item < Lines.size()) { - return Utils::String::VA("%s", Changelog::Lines[item].data()); + return Utils::String::VA("%s", Lines[item].data()); } return ""; } - void Changelog::SelectChangelog(unsigned int /*index*/) + void Changelog::SelectChangelog([[maybe_unused]] unsigned int index) { // Don't do anything in here } diff --git a/src/Utils/Cache.cpp b/src/Utils/Cache.cpp index 17390b83..4a654cab 100644 --- a/src/Utils/Cache.cpp +++ b/src/Utils/Cache.cpp @@ -4,8 +4,8 @@ namespace Utils { const char* Cache::Urls[] = { + "https://raw.githubusercontent.com/XLabsProject/iw4x-client", "https://xlabs.dev", - "https://raw.githubusercontent.com/XLabsProject/iw4x-client" }; std::string Cache::ValidUrl; @@ -13,7 +13,7 @@ namespace Utils std::string Cache::GetStaticUrl(const std::string& path) { - return Cache::Urls[0] + path; + return Urls[0] + path; } std::string Cache::GetUrl(const std::string& url, const std::string& path) @@ -23,29 +23,27 @@ namespace Utils std::string Cache::GetFile(const std::string& path, int timeout, const std::string& useragent) { - std::lock_guard _(Cache::CacheMutex); + std::lock_guard _(CacheMutex); - if (Cache::ValidUrl.empty()) + if (ValidUrl.empty()) { InternetSetCookieA("https://onion.casa", "disclaimer_accepted", "1"); InternetSetCookieA("https://hiddenservice.net", "disclaimer_accepted", "1"); - for (int i = 0; i < ARRAYSIZE(Cache::Urls); ++i) + for (std::size_t i = 0; i < ARRAYSIZE(Urls); ++i) { - std::string result = Utils::WebIO(useragent, Cache::GetUrl(Cache::Urls[i], path)).setTimeout(timeout)->get(); + std::string result = WebIO(useragent, GetUrl(Urls[i], path)).setTimeout(timeout)->get(); if (!result.empty()) { - Cache::ValidUrl = Cache::Urls[i]; + ValidUrl = Urls[i]; return result; } } - return ""; - } - else - { - return Utils::WebIO(useragent, Cache::GetUrl(Cache::ValidUrl, path)).setTimeout(timeout)->get(); + return {}; } + + return WebIO(useragent, GetUrl(ValidUrl, path)).setTimeout(timeout)->get(); } }