Compare commits

..

No commits in common. "b287c827d23646b7a483727d09a76e079fd37fa0" and "63a8cf70754faa2542a4b04120cb01ec9dba1b03" have entirely different histories.

10 changed files with 117 additions and 146 deletions

4
.gitmodules vendored
View file

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

View file

@ -92,4 +92,7 @@ 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,5 +192,6 @@ target_link_libraries(MassBuilderSaveTool PRIVATE
efsw
zip
cpr::cpr
nlohmann_json::nlohmann_json
imm32
wtsapi32)

View file

@ -35,6 +35,8 @@
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include <windef.h>
#include <winuser.h>
#include <processthreadsapi.h>
@ -62,6 +64,18 @@ SaveTool::SaveTool(const Arguments& arguments):
tweak.enable(""_s, "../../"_s);
#endif
if(SDL_VERSION_ATLEAST(2, 0, 5)) {
if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1", SDL_HINT_OVERRIDE) == SDL_TRUE) {
Utility::Debug{} << "Clickthrough is available."_s;
}
else {
Utility::Warning{} << "Clickthrough is not available (hint couldn't be set)."_s;
}
}
else {
Utility::Warning{} << "Clickthrough is not available (SDL2 is too old)."_s;
}
GL::Renderer::enable(GL::Renderer::Feature::Blending);
GL::Renderer::enable(GL::Renderer::Feature::ScissorTest);
GL::Renderer::disable(GL::Renderer::Feature::FaceCulling);
@ -71,24 +85,7 @@ SaveTool::SaveTool(const Arguments& arguments):
GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add,
GL::Renderer::BlendEquation::Add);
Utility::Debug{} << "Renderer initialisation successful.";
Utility::Debug{} << "===Configuring SDL2===";
{
Utility::Debug d{};
d << "Enabling clickthrough...";
if(SDL_VERSION_ATLEAST(2, 0, 5)) {
if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1", SDL_HINT_OVERRIDE) == SDL_TRUE) {
d << "success!"_s;
} else {
d << "error: hint couldn't be set."_s;
}
} else {
d << "error: SDL2 is too old (version < 2.0.5)."_s;
}
}
initialiseGui();
if((_initEventId = SDL_RegisterEvents(3)) == UnsignedInt(-1)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
@ -100,23 +97,7 @@ SaveTool::SaveTool(const Arguments& arguments):
_updateEventId = _initEventId + 1;
_fileEventId = _initEventId + 2;
if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window());
exit(EXIT_FAILURE);
return;
}
Utility::Debug{} << "SDL2 configuration successful.";
Utility::Debug{} << "===Initialising the Save Tool===";
initialiseGui();
if(!initialiseToolDirectories()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
exit(EXIT_FAILURE);
return;
}
initialiseToolDirectories();
if(!findGameDataDirectory()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
@ -124,6 +105,16 @@ SaveTool::SaveTool(const Arguments& arguments):
return;
}
_configDir = Utility::Path::join(_gameDataDir, "Saved/Config/WindowsNoEditor");
_saveDir = Utility::Path::join(_gameDataDir, "Saved/SaveGames");
_screenshotsDir = Utility::Path::join(_gameDataDir, "Saved/Screenshots/WindowsNoEditor");
if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window());
exit(EXIT_FAILURE);
return;
}
checkGameState();
_gameCheckTimerId = SDL_AddTimer(2000,
[](UnsignedInt interval, void* param)->UnsignedInt{
@ -162,9 +153,6 @@ SaveTool::SaveTool(const Arguments& arguments):
GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false);
}
Utility::Debug{} << "Initialisation successful.";
Utility::Debug{} << "===Running main loop===";
if(_skipDisclaimer) {
_uiState = UiState::Initialising;
_initThread = std::thread{[this]{ initialiseManager(); }};
@ -172,12 +160,8 @@ SaveTool::SaveTool(const Arguments& arguments):
}
SaveTool::~SaveTool() {
Utility::Debug{} << "===Perfoming cleanup===";
SDL_RemoveTimer(_gameCheckTimerId);
Utility::Debug{} << "Saving the configuration...";
_conf.setValue("cheat_mode"_s, _cheatMode);
_conf.setValue("unsafe_mode"_s, _unsafeMode);
_conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup);
@ -196,8 +180,6 @@ SaveTool::~SaveTool() {
}
_conf.save();
Utility::Debug{} << "Exiting...";
}
void SaveTool::handleFileAction(efsw::WatchID watch_id,
@ -304,7 +286,6 @@ void SaveTool::initEvent(SDL_Event& event) {
ImGui::CloseCurrentPopup();
break;
case ProfileManagerFailure:
Utility::Error{} << "Error initialising ProfileManager:" << _profileManager->lastError();
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising ProfileManager", _profileManager->lastError().data(), window());
exit(EXIT_FAILURE);
break;
@ -329,6 +310,10 @@ 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;
@ -342,31 +327,17 @@ 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 fullVersion;
Int major = 0;
Int minor = 0;
Int patch = 0;
bool prerelease = false;
Int major;
Int minor;
Int patch;
bool operator==(const Version& other) const {
return fullVersion == other.fullVersion;
return (major == other.major) && (minor == other.minor) && (patch == other.patch);
}
bool operator>(const Version& other) const {
if((fullVersion > other.fullVersion) ||
(fullVersion == other.fullVersion && prerelease == false && other.prerelease == true))
{
return true;
}
else {
return false;
}
return ( major * 10000 + minor * 100 + patch) >
(other.major * 10000 + other.minor * 100 + other.patch);
}
operator Containers::String() const {
return Utility::format("{}.{}.{}", major, minor, patch);
@ -375,24 +346,29 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
static const Version current_ver{SAVETOOL_VERSION};
Containers::String response = r.text.c_str();
auto components = response.split('\n');
for(auto& release : response) {
if(release["prerelease"] == true) {
continue;
}
Version latest_ver{components.front()};
Version latest_ver{release["tag_name"].get<std::string>().c_str()};
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);
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;
}
}
@ -480,8 +456,6 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
}
void SaveTool::initialiseConfiguration() {
Utility::Debug{} << "Reading configuration file...";
if(_conf.hasValue("cheat_mode"_s)) {
_cheatMode = _conf.value<bool>("cheat_mode"_s);
}
@ -531,8 +505,6 @@ void SaveTool::initialiseConfiguration() {
}
void SaveTool::initialiseGui() {
Utility::Debug{} << "Initialising ImGui...";
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
@ -592,9 +564,7 @@ void SaveTool::initialiseManager() {
SDL_PushEvent(&event);
}
auto SaveTool::initialiseToolDirectories() -> bool {
Utility::Debug{} << "Initialising Save Tool directories...";
void SaveTool::initialiseToolDirectories() {
_backupsDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "backups");
_stagingDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "staging");
//_armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury");
@ -603,83 +573,52 @@ auto SaveTool::initialiseToolDirectories() -> bool {
//_stylesDir = Utility::Directory::join(_armouryDir, "styles");
if(!Utility::Path::exists(_backupsDir)) {
Utility::Debug{} << "Backups directory not found, creating...";
if(!Utility::Path::make(_backupsDir)) {
Utility::Error{} << (_lastError = "Couldn't create the backups directory.");
return false;
}
Utility::Path::make(_backupsDir);
}
if(!Utility::Path::exists(_stagingDir)) {
Utility::Debug{} << "Staging directory not found, creating...";
if(!Utility::Path::make(_stagingDir)) {
Utility::Error{} << (_lastError = "Couldn't create the backups directory.");
return false;
}
Utility::Path::make(_stagingDir);
}
//if(!Utility::Directory::exists(_armouryDir)) {
// Utility::Debug{} << "Armoury directory not found, creating...";
// if(!Utility::Path::make(_armouryDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the armoury directory.");
// return false;
// }
// Utility::Directory::mkpath(_armouryDir);
//}
//if(!Utility::Directory::exists(_armoursDir)) {
// Utility::Debug{} << "Armours directory not found, creating...";
// if(!Utility::Path::make(_armoursDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the armours directory.");
// return false;
// }
// Utility::Directory::mkpath(_armoursDir);
//}
//if(!Utility::Directory::exists(_weaponsDir)) {
// Utility::Debug{} << "Weapons directory not found, creating...";
// if(!Utility::Path::make(_weaponsDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the weapons directory.");
// return false;
// }
// Utility::Directory::mkpath(_weaponsDir);
//}
//if(!Utility::Directory::exists(_stylesDir)) {
// Utility::Debug{} << "Styles directory not found, creating...";
// if(!Utility::Path::make(_stylesDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the styles directory.");
// return false;
// }
// Utility::Directory::mkpath(_stylesDir);
//}
return true;
}
auto SaveTool::findGameDataDirectory() -> bool {
Utility::Debug{} << "Searching for the game's save directory...";
wchar_t* localappdata_path = nullptr;
Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree};
if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK)
{
Utility::Error{} << (_lastError = "SHGetKnownFolderPath() failed in SaveTool::findGameDataDirectory()"_s);
_lastError = "SHGetKnownFolderPath() failed in SaveTool::findGameDataDirectory()"_s;
return false;
}
_gameDataDir = Utility::Path::join(Utility::Path::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"_s);
if(!Utility::Path::exists(_gameDataDir)) {
Utility::Error{} << (_lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."_s);
_lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."_s;
return false;
}
_configDir = Utility::Path::join(_gameDataDir, "Saved/Config/WindowsNoEditor"_s);
_saveDir = Utility::Path::join(_gameDataDir, "Saved/SaveGames"_s);
_screenshotsDir = Utility::Path::join(_gameDataDir, "Saved/Screenshots/WindowsNoEditor"_s);
return true;
}
void SaveTool::initialiseMassManager() {
_massManager.emplace(_saveDir, _currentProfile->account(), _currentProfile->isDemo(), _stagingDir);
initialiseFileWatcher();
}
void SaveTool::initialiseFileWatcher() {
@ -887,11 +826,12 @@ void SaveTool::checkGameState() {
}
void SaveTool::checkForUpdates() {
cpr::Response r = cpr::Get(cpr::Url{"https://williamjcm.ovh/mbst/version"}, cpr::Timeout{10000});
cpr::Response r = cpr::Get(cpr::Url{"https://williamjcm.ovh/git/api/v1/repos/williamjcm/MassBuilderSaveTool/releases"}, 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

@ -96,7 +96,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
void initialiseConfiguration();
void initialiseGui();
void initialiseManager();
auto initialiseToolDirectories() -> bool;
void initialiseToolDirectories();
auto findGameDataDirectory() -> bool;
void initialiseMassManager();
void initialiseFileWatcher();

View file

@ -88,7 +88,6 @@ void SaveTool::drawProfileManager() {
{
_currentProfile = _profileManager->getProfile(i);
initialiseMassManager();
initialiseFileWatcher();
_uiState = UiState::MainManager;
}

View file

@ -270,6 +270,31 @@ 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,3 +47,7 @@ alias=LICENSE.efsw
[file]
filename=../third-party/cpr/LICENSE
alias=LICENSE.cpr
[file]
filename=../third-party/json/LICENSE.MIT
alias=LICENSE.json

View file

@ -25,20 +25,7 @@
#include <winerror.h>
int main(int argc, char** argv) {
#ifndef SAVETOOL_DEBUG_BUILD
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
Utility::Debug d{&output};
Utility::Warning w{&output};
Utility::Error e{&output};
#else
Utility::Warning w{Utility::Debug::defaultOutput()};
Utility::Error e{Utility::Debug::defaultOutput()};
#endif
Utility::Debug{} << "===M.A.S.S. Builder Save Tool version " SAVETOOL_VERSION "===";
auto mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
void* mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
if(!mutex_handle) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
@ -52,7 +39,14 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
Utility::Debug{} << "===Initialising OpenGL renderer===";
#ifndef SAVETOOL_DEBUG_BUILD
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
Utility::Debug d{&output};
Utility::Warning w{&output};
Utility::Error e{&output};
#endif
SaveTool app({argc, argv});
Int result = app.exec();

1
third-party/json vendored Submodule

@ -0,0 +1 @@
Subproject commit 626e7d61e44dee32887126c8f437dd077dec09cf