SaveTool: remove the dependency on json.hpp.

This commit is contained in:
Guillaume Jacquemin 2022-03-30 15:15:54 +02:00
parent ef05c075ba
commit 2c2e5ad936
5 changed files with 37 additions and 68 deletions

View File

@ -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)

View File

@ -192,6 +192,5 @@ target_link_libraries(MassBuilderSaveTool PRIVATE
efsw
zip
cpr::cpr
nlohmann_json::nlohmann_json
imm32
wtsapi32)

View File

@ -35,8 +35,6 @@
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include <windef.h>
#include <winuser.h>
#include <processthreadsapi.h>
@ -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<std::string>().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<std::string>().c_str();
_downloadLink = release["assets"][0]["browser_download_url"].get<std::string>().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);
}

View File

@ -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/";

View File

@ -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