From 2c2e5ad936d2a869e810be5fea2e57db27d62871 Mon Sep 17 00:00:00 2001 From: William JCM Date: Wed, 30 Mar 2022 15:15:54 +0200 Subject: [PATCH] SaveTool: remove the dependency on json.hpp. --- CMakeLists.txt | 3 -- src/CMakeLists.txt | 1 - src/SaveTool/SaveTool.cpp | 72 +++++++++++++++-------------- src/SaveTool/SaveTool_drawAbout.cpp | 25 ---------- src/assets.conf | 4 -- 5 files changed, 37 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e54cc44..550ede5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,4 @@ set(CPR_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(CMAKE_USE_LIBSSH2 OFF CACHE BOOL "" FORCE) # For some reason, even when HTTP_ONLY is set to ON, libcurl will try to link to libssh2. add_subdirectory(third-party/cpr EXCLUDE_FROM_ALL) -set(JSON_BuildTests OFF CACHE BOOL "" FORCE) -add_subdirectory(third-party/json) - add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 530e4ed..3f97065 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -192,6 +192,5 @@ target_link_libraries(MassBuilderSaveTool PRIVATE efsw zip cpr::cpr - nlohmann_json::nlohmann_json imm32 wtsapi32) diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index c561ce5..e4dd9e5 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -35,8 +35,6 @@ #include -#include - #include #include #include @@ -331,10 +329,6 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { return; } - using json = nlohmann::json; - - json response = json::parse(r.text); - struct Version { explicit Version(Containers::StringView str) { std::size_t start_point = 0; @@ -348,17 +342,31 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { major = std::strtol(components[0].data(), nullptr, 10); minor = std::strtol(components[1].data(), nullptr, 10); patch = std::strtol(components[2].data(), nullptr, 10); + + fullVersion = major * 10000 + minor * 100 + patch; + + if(str.hasSuffix("-pre")) { + prerelease = true; + } } - Int major; - Int minor; - Int patch; + Int fullVersion; + Int major = 0; + Int minor = 0; + Int patch = 0; + bool prerelease = false; bool operator==(const Version& other) const { - return (major == other.major) && (minor == other.minor) && (patch == other.patch); + return fullVersion == other.fullVersion; } bool operator>(const Version& other) const { - return ( major * 10000 + minor * 100 + patch) > - (other.major * 10000 + other.minor * 100 + other.patch); + if((fullVersion > other.fullVersion) || + (fullVersion == other.fullVersion && prerelease == false && other.prerelease == true)) + { + return true; + } + else { + return false; + } } operator Containers::String() const { return Utility::format("{}.{}.{}", major, minor, patch); @@ -367,29 +375,24 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { static const Version current_ver{SAVETOOL_VERSION}; - for(auto& release : response) { - if(release["prerelease"] == true) { - continue; - } + Containers::String response = r.text.c_str(); + auto components = response.split('\n'); - Version latest_ver{release["tag_name"].get().c_str()}; + Version latest_ver{components.front()}; - if(latest_ver > current_ver || (latest_ver == current_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) { - _queue.addToast(Toast::Type::Warning, "Your version is out of date.\nCheck the settings for more information."_s, - std::chrono::milliseconds{5000}); - _updateAvailable = true; - _latestVersion = latest_ver; - _releaseLink = release["html_url"].get().c_str(); - _downloadLink = release["assets"][0]["browser_download_url"].get().c_str(); - } - else if(latest_ver == current_ver || (current_ver > latest_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) { - _queue.addToast(Toast::Type::Success, "The application is already up to date."_s); - } - else if(current_ver > latest_ver) { - _queue.addToast(Toast::Type::Warning, "Your version is more recent than the latest one in the repo. How???"_s); - } - - break; + if(latest_ver > current_ver) { + _queue.addToast(Toast::Type::Warning, "Your version is out of date.\nCheck the settings for more information."_s, + std::chrono::milliseconds{5000}); + _updateAvailable = true; + _latestVersion = latest_ver; + _releaseLink = Utility::format("https://williamjcm.ovh/git/williamjcm/MassBuilderSaveTool/releases/tag/v{}", components.front()); + _downloadLink = components.back(); + } + else if(latest_ver == current_ver || (current_ver > latest_ver && current_ver.prerelease == true)) { + _queue.addToast(Toast::Type::Success, "The application is already up to date."_s); + } + else if(current_ver > latest_ver && current_ver.prerelease == false) { + _queue.addToast(Toast::Type::Warning, "Your version is more recent than the latest one in the repo. How???"_s); } } @@ -884,12 +887,11 @@ void SaveTool::checkGameState() { } void SaveTool::checkForUpdates() { - cpr::Response r = cpr::Get(cpr::Url{"https://williamjcm.ovh/git/api/v1/repos/williamjcm/MassBuilderSaveTool/releases"}, cpr::Timeout{10000}); + cpr::Response r = cpr::Get(cpr::Url{"https://williamjcm.ovh/mbst/version"}, cpr::Timeout{10000}); SDL_Event event; SDL_zero(event); event.type = _updateEventId; - event.user.code = r.status_code; event.user.data1 = new cpr::Response{std::move(r)}; SDL_PushEvent(&event); } diff --git a/src/SaveTool/SaveTool_drawAbout.cpp b/src/SaveTool/SaveTool_drawAbout.cpp index ebcdea7..16d657b 100644 --- a/src/SaveTool/SaveTool_drawAbout.cpp +++ b/src/SaveTool/SaveTool_drawAbout.cpp @@ -270,31 +270,6 @@ void SaveTool::drawAbout() { ImGui::TreePop(); } - if(ImGui::TreeNodeEx("JSON for Modern C++ (aka json.hpp)", ImGuiTreeNodeFlags_SpanAvailWidth)) { - auto json_website = "https://json.nlohmann.me/"; - drawAlignedText(ICON_FA_GLOBE " %s", json_website); - ImGui::SameLine(); - if(ImGui::Button("Copy to clipboard")) { - ImGui::SetClipboardText(json_website); - } - ImGui::SameLine(); - if(ImGui::Button("Open in browser")) { - openUri(json_website); - } - - ImGui::TextUnformatted("Licence: MIT"); - - static auto json_licence = _rs.getRaw("LICENSE.json"); - if(ImGui::BeginChild("##jsonLicence", {0.0f, windowSize().y() * 0.3f}, true)) { - ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(json_licence); - ImGui::PopFont(); - } - ImGui::EndChild(); - - ImGui::TreePop(); - } - if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) { ImGui::TextUnformatted("Version used: 5.15.3"); auto fa_website = "https://fontawesome.com/"; diff --git a/src/assets.conf b/src/assets.conf index 4bb02d4..f9076c1 100644 --- a/src/assets.conf +++ b/src/assets.conf @@ -47,7 +47,3 @@ alias=LICENSE.efsw [file] filename=../third-party/cpr/LICENSE alias=LICENSE.cpr - -[file] -filename=../third-party/json/LICENSE.MIT -alias=LICENSE.json