Compare commits

..

No commits in common. "d0716d624281b35365040e3b65faa3ac24945286" and "14c5a76891a0bef6248eb5d50f3b5dc06b0cc466" have entirely different histories.

10 changed files with 4 additions and 168 deletions

4
.gitmodules vendored
View file

@ -30,7 +30,3 @@
path = third-party/cpr path = third-party/cpr
url = https://github.com/whoshuu/cpr url = https://github.com/whoshuu/cpr
branch = master branch = master
[submodule "json.hpp"]
path = third-party/json
url = https://github.com/nlohmann/json
branch = master

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. 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) add_subdirectory(third-party/cpr EXCLUDE_FROM_ALL)
set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
add_subdirectory(third-party/json)
add_subdirectory(src) add_subdirectory(src)

View file

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

View file

@ -32,8 +32,6 @@
#include <cpr/cpr.h> #include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include <windef.h> #include <windef.h>
#include <winuser.h> #include <winuser.h>
#include <processthreadsapi.h> #include <processthreadsapi.h>
@ -135,11 +133,6 @@ SaveTool::SaveTool(const Arguments& arguments):
} }
initialiseConfiguration(); initialiseConfiguration();
if(_checkUpdatesOnStartup) {
_thread = std::thread{[this]{ checkForUpdates(); }};
_queue.addToast(Toast::Type::Default, "Checking for updates...");
}
} }
SaveTool::~SaveTool() { SaveTool::~SaveTool() {
@ -293,67 +286,7 @@ void SaveTool::initEvent(SDL_Event& event) {
void SaveTool::updateCheckEvent(SDL_Event& event) { void SaveTool::updateCheckEvent(SDL_Event& event) {
_thread.join(); _thread.join();
cpr::Response r{std::move(*static_cast<cpr::Response*>(event.user.data1))}; // TODO: implement
delete static_cast<cpr::Response*>(event.user.data1);
if(r.elapsed > 10.0) {
_queue.addToast(Toast::Type::Error, "The request timed out.");
return;
}
if(r.status_code != 200) {
_queue.addToast(Toast::Type::Error, Utility::formatString("The request failed with error code {}: {}", r.status_code, r.reason));
return;
}
using json = nlohmann::json;
json response = json::parse(r.text);
struct Version {
explicit Version(const std::string& str) {
std::size_t start_point = 0;
if(str[0] == 'v') {
start_point++;
}
major = std::atoi(str.c_str() + start_point);
start_point = str.find('.', start_point) + 1;
minor = std::atoi(str.c_str() + start_point);
start_point = str.find('.', start_point) + 1;
patch = std::atoi(str.c_str() + start_point);
}
Int major;
Int minor;
Int patch;
bool operator==(const Version& other) const {
return (major == other.major) && (minor == other.minor) && (patch == other.patch);
}
bool operator>(const Version& other) const {
return ( major * 10000 + minor * 100 + patch) >
(other.major * 10000 + other.minor * 100 + other.patch);
}
};
static const Version current_ver{SAVETOOL_VERSION};
Version latest_ver{response[0]["tag_name"]};
if(latest_ver == current_ver) {
_queue.addToast(Toast::Type::Success, "The application is already up to date.");
}
else if(latest_ver > current_ver) {
_queue.addToast(Toast::Type::Warning, "Your version is out of date.\nCheck the settings for more information.",
std::chrono::milliseconds{5000});
_updateAvailable = true;
_latestVersion = Utility::formatString("{}.{}.{}", latest_ver.major, latest_ver.minor, latest_ver.patch);
_releaseLink = response[0]["html_url"];
_downloadLink = response[0]["assets"][0]["browser_download_url"];
}
else if(current_ver > latest_ver) {
_queue.addToast(Toast::Type::Warning, "Your version is more recent than the latest one in the repo. How???");
}
} }
void SaveTool::initialiseConfiguration() { void SaveTool::initialiseConfiguration() {
@ -661,13 +594,10 @@ void SaveTool::checkGameState() {
} }
void SaveTool::checkForUpdates() { void SaveTool::checkForUpdates() {
cpr::Response r = cpr::Get(cpr::Url{"https://williamjcm.ovh/git/api/v1/repos/williamjcm/MassBuilderSaveTool/releases"}, // TODO: implement
cpr::Parameters{{"limit", "1"}}, cpr::Timeout{10000});
SDL_Event event; SDL_Event event;
SDL_zero(event); SDL_zero(event);
event.type = _updateEventId; event.type = _updateEventId;
event.user.code = r.status_code;
event.user.data1 = new cpr::Response{std::move(r)};
SDL_PushEvent(&event); SDL_PushEvent(&event);
} }

View file

@ -34,7 +34,6 @@
#include "../ProfileManager/ProfileManager.h" #include "../ProfileManager/ProfileManager.h"
#include "../MassManager/MassManager.h" #include "../MassManager/MassManager.h"
#include "../ToastQueue/ToastQueue.h"
using namespace Corrade; using namespace Corrade;
using namespace Magnum; using namespace Magnum;
@ -162,8 +161,6 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
bool _metricsWindow{false}; bool _metricsWindow{false};
#endif #endif
ToastQueue _queue;
std::thread _thread; // used for threaded operations such as profile manager init or update checking. std::thread _thread; // used for threaded operations such as profile manager init or update checking.
UnsignedInt _initEventId; UnsignedInt _initEventId;
@ -199,9 +196,4 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
bool _checkUpdatesOnStartup{true}; bool _checkUpdatesOnStartup{true};
bool _unsafeMode{false}; bool _unsafeMode{false};
bool _updateAvailable{false};
std::string _latestVersion;
std::string _releaseLink;
std::string _downloadLink;
}; };

View file

@ -251,58 +251,6 @@ void SaveTool::drawAbout() {
ImGui::TreePop(); ImGui::TreePop();
} }
if(ImGui::TreeNodeEx("C++ Requests (cpr)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::AlignTextToFramePadding();
const char* cpr_website = "https://whoshuu.github.io/cpr/";
ImGui::Text(ICON_FA_GLOBE " %s", cpr_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(cpr_website);
}
ImGui::SameLine();
if(ImGui::Button("Open in browser")) {
openUri(cpr_website);
}
ImGui::TextUnformatted("Licence: MIT");
static const auto cpr_licence = _rs.get("LICENSE.cpr");
if(ImGui::BeginChild("##cprLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(cpr_licence.c_str());
ImGui::PopFont();
}
ImGui::EndChild();
ImGui::TreePop();
}
if(ImGui::TreeNodeEx("JSON for Modern C++ (aka json.hpp)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::AlignTextToFramePadding();
const char* json_website = "https://json.nlohmann.me/";
ImGui::Text(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 const auto json_licence = _rs.get("LICENSE.json");
if(ImGui::BeginChild("##jsonLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(json_licence.c_str());
ImGui::PopFont();
}
ImGui::EndChild();
ImGui::TreePop();
}
if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::TextUnformatted("Version used: 5.15.3"); ImGui::TextUnformatted("Version used: 5.15.3");
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();

View file

@ -62,22 +62,7 @@ void SaveTool::drawMainMenu() {
ImGui::Checkbox("Check for updates on startup", &_checkUpdatesOnStartup); ImGui::Checkbox("Check for updates on startup", &_checkUpdatesOnStartup);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button(ICON_FA_SYNC_ALT " Check now")) { ImGui::Button(ICON_FA_SYNC_ALT " Check now");
_queue.addToast(Toast::Type::Default, "Checking for updates...");
_thread = std::thread{[this]{ checkForUpdates(); }};
}
if(_updateAvailable) {
ImGui::AlignTextToFramePadding();
ImGui::Text("Version %s is available.", _latestVersion.c_str());
if(ImGui::Button(ICON_FA_FILE_SIGNATURE " Release notes")) {
openUri(_releaseLink);
}
ImGui::SameLine();
if(ImGui::Button(ICON_FA_DOWNLOAD " Download now")) {
openUri(_downloadLink);
}
}
ImGui::EndMenu(); ImGui::EndMenu();
} }

View file

@ -138,9 +138,7 @@ void ToastQueue::draw(Vector2i viewport_size) {
break; break;
} }
if(current->type() != Toast::Type::Default) { ImGui::SameLine();
ImGui::SameLine();
}
if(current->message().length() > 127) { if(current->message().length() > 127) {
ImGui::TextColored(colour, "%.*s...", 127, current->message().c_str()); ImGui::TextColored(colour, "%.*s...", 127, current->message().c_str());

View file

@ -43,11 +43,3 @@ alias=LICENSE.libzip
[file] [file]
filename=../third-party/efsw/LICENSE filename=../third-party/efsw/LICENSE
alias=LICENSE.efsw alias=LICENSE.efsw
[file]
filename=../third-party/cpr/LICENSE
alias=LICENSE.cpr
[file]
filename=../third-party/json/LICENSE.MIT
alias=LICENSE.json

1
third-party/json vendored

@ -1 +0,0 @@
Subproject commit 350ff4f7ced7c4117eae2fb93df02823c8021fcb