Compare commits

...

4 commits

10 changed files with 143 additions and 114 deletions

4
.gitmodules vendored
View file

@ -30,7 +30,3 @@
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,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>
@ -64,18 +62,6 @@ 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);
@ -85,7 +71,24 @@ SaveTool::SaveTool(const Arguments& arguments):
GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add,
GL::Renderer::BlendEquation::Add);
initialiseGui();
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;
}
}
if((_initEventId = SDL_RegisterEvents(3)) == UnsignedInt(-1)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
@ -97,20 +100,26 @@ SaveTool::SaveTool(const Arguments& arguments):
_updateEventId = _initEventId + 1;
_fileEventId = _initEventId + 2;
initialiseToolDirectories();
if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window());
exit(EXIT_FAILURE);
return;
}
if(!findGameDataDirectory()) {
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;
}
_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());
if(!findGameDataDirectory()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
exit(EXIT_FAILURE);
return;
}
@ -153,6 +162,9 @@ 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(); }};
@ -160,8 +172,12 @@ 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);
@ -180,6 +196,8 @@ SaveTool::~SaveTool() {
}
_conf.save();
Utility::Debug{} << "Exiting...";
}
void SaveTool::handleFileAction(efsw::WatchID watch_id,
@ -286,6 +304,7 @@ 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;
@ -310,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;
@ -327,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);
@ -346,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);
}
}
@ -456,6 +480,8 @@ 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);
}
@ -505,6 +531,8 @@ void SaveTool::initialiseConfiguration() {
}
void SaveTool::initialiseGui() {
Utility::Debug{} << "Initialising ImGui...";
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
@ -564,7 +592,9 @@ void SaveTool::initialiseManager() {
SDL_PushEvent(&event);
}
void SaveTool::initialiseToolDirectories() {
auto SaveTool::initialiseToolDirectories() -> bool {
Utility::Debug{} << "Initialising Save Tool directories...";
_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");
@ -573,52 +603,83 @@ void SaveTool::initialiseToolDirectories() {
//_stylesDir = Utility::Directory::join(_armouryDir, "styles");
if(!Utility::Path::exists(_backupsDir)) {
Utility::Path::make(_backupsDir);
Utility::Debug{} << "Backups directory not found, creating...";
if(!Utility::Path::make(_backupsDir)) {
Utility::Error{} << (_lastError = "Couldn't create the backups directory.");
return false;
}
}
if(!Utility::Path::exists(_stagingDir)) {
Utility::Path::make(_stagingDir);
Utility::Debug{} << "Staging directory not found, creating...";
if(!Utility::Path::make(_stagingDir)) {
Utility::Error{} << (_lastError = "Couldn't create the backups directory.");
return false;
}
}
//if(!Utility::Directory::exists(_armouryDir)) {
// Utility::Directory::mkpath(_armouryDir);
// Utility::Debug{} << "Armoury directory not found, creating...";
// if(!Utility::Path::make(_armouryDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the armoury directory.");
// return false;
// }
//}
//if(!Utility::Directory::exists(_armoursDir)) {
// Utility::Directory::mkpath(_armoursDir);
// Utility::Debug{} << "Armours directory not found, creating...";
// if(!Utility::Path::make(_armoursDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the armours directory.");
// return false;
// }
//}
//if(!Utility::Directory::exists(_weaponsDir)) {
// Utility::Directory::mkpath(_weaponsDir);
// Utility::Debug{} << "Weapons directory not found, creating...";
// if(!Utility::Path::make(_weaponsDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the weapons directory.");
// return false;
// }
//}
//if(!Utility::Directory::exists(_stylesDir)) {
// Utility::Directory::mkpath(_stylesDir);
// Utility::Debug{} << "Styles directory not found, creating...";
// if(!Utility::Path::make(_stylesDir)) {
// Utility::Error{} << (_lastError = "Couldn't create the styles directory.");
// return false;
// }
//}
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)
{
_lastError = "SHGetKnownFolderPath() failed in SaveTool::findGameDataDirectory()"_s;
Utility::Error{} << (_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)) {
_lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."_s;
Utility::Error{} << (_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() {
@ -826,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

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

View file

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

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

View file

@ -25,7 +25,20 @@
#include <winerror.h>
int main(int argc, char** argv) {
void* mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
#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");
if(!mutex_handle) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
@ -39,14 +52,7 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
#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
Utility::Debug{} << "===Initialising OpenGL renderer===";
SaveTool app({argc, argv});
Int result = app.exec();

1
third-party/json vendored

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