diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp new file mode 100644 index 0000000..5854eba --- /dev/null +++ b/src/Application/Application.cpp @@ -0,0 +1,77 @@ +// MassBuilderSaveTool +// Copyright (C) 2021-2022 Guillaume Jacquemin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include + +#include + +#include "../Configuration/Configuration.h" +#include "../Logger/Logger.h" + +#include "Application.h" + +Application::Application(const Arguments& args): + Platform::ScreenedApplication( + args, + Configuration{}.setTitle("M.A.S.S. Builder Save Tool " SAVETOOL_VERSION " (\"" SAVETOOL_CODENAME "\")") + .setSize({960, 720}) + ) +{ + //ctor +} + +Application::~Application() { + LOG_INFO("Cleaning up."); + + SDL_RemoveTimer(_gameCheckTimerId); + + LOG_INFO("Saving the configuration."); + + conf().save(); +} + +void +Application::globalBeforeDrawEvent() { + GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); +} + +void +Application::globalDrawEvent() { + swapBuffers(); + + if(conf().swapInterval() == 0 && conf().fpsCap() < 301.0f) { + while(_timeline.currentFrameDuration() < (1.0f / conf().fpsCap())); + } + + redraw(); + + _timeline.nextFrame(); +} + +void +Application::globalViewportEvent(ViewportEvent& event) { + if(event.event().type & SDL_WINDOWEVENT_SIZE_CHANGED) { + GL::defaultFramebuffer.setViewport({{}, event.windowSize()}); + + const Vector2 size = Vector2{windowSize()}/dpiScaling(); + _imgui.relayout(size, windowSize(), framebufferSize()); + } +} + +void +Application::anyEvent(SDL_Event& event) { + // +} diff --git a/src/Application/Application.h b/src/Application/Application.h new file mode 100644 index 0000000..7220283 --- /dev/null +++ b/src/Application/Application.h @@ -0,0 +1,51 @@ +#pragma once + +// MassBuilderSaveTool +// Copyright (C) 2021-2022 Guillaume Jacquemin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include +#include +#include +#include + +#include + +using namespace Magnum; + +class Application: public Platform::ScreenedApplication { + public: + explicit Application(const Arguments& args); + ~Application(); + + Application(const Application&) = delete; + Application& operator=(const Application&) = delete; + Application(Application&&) = delete; + Application& operator=(Application&&) = delete; + + private: + // Events + void globalBeforeDrawEvent() override; + void globalDrawEvent() override; + void globalViewportEvent(ViewportEvent& event) override; + + void anyEvent(SDL_Event& event) override; + + Timeline _timeline; + + ImGuiIntegration::Context _imgui{NoCreate}; + + SDL_TimerID _gameCheckTimerId = 0; +}; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9022e66..a40687f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,8 @@ add_subdirectory(UESaveFile EXCLUDE_FROM_ALL) add_executable(MassBuilderSaveTool WIN32 main.cpp + Application/Application.h + Application/Application.cpp SaveTool/SaveTool.h SaveTool/SaveTool.cpp SaveTool/SaveTool_drawAbout.cpp @@ -87,6 +89,8 @@ add_executable(MassBuilderSaveTool WIN32 Maps/WeaponTypes.hpp ToastQueue/ToastQueue.h ToastQueue/ToastQueue.cpp + UpdateChecker/UpdateChecker.h + UpdateChecker/UpdateChecker.cpp Utilities/Crc32.h FontAwesome/IconsFontAwesome5.h FontAwesome/IconsFontAwesome5Brands.h diff --git a/src/SaveTool/SaveTool_Initialisation.cpp b/src/SaveTool/SaveTool_Initialisation.cpp index e14bb2b..2ed430f 100644 --- a/src/SaveTool/SaveTool_Initialisation.cpp +++ b/src/SaveTool/SaveTool_Initialisation.cpp @@ -198,9 +198,10 @@ SaveTool::findGameDataDirectory() -> bool { 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) + auto result = SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path); + if(result != S_OK) { - _lastError = Utility::format("SHGetKnownFolderPath() failed with error code {}.", GetLastError()); + _lastError = Utility::format("SHGetKnownFolderPath() failed with error code {}.", result); LOG_ERROR(_lastError); return false; } diff --git a/src/UpdateChecker/UpdateChecker.cpp b/src/UpdateChecker/UpdateChecker.cpp new file mode 100644 index 0000000..dbf3f84 --- /dev/null +++ b/src/UpdateChecker/UpdateChecker.cpp @@ -0,0 +1,31 @@ +// MassBuilderSaveTool +// Copyright (C) 2021-2022 Guillaume Jacquemin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include + +#include "../Logger/Logger.h" + +#include "UpdateChecker.h" + +UpdateChecker::UpdateChecker() { + LOG_INFO("Initialising update checker."); + curl_global_init(CURL_GLOBAL_DEFAULT); +} + +UpdateChecker::~UpdateChecker() { + LOG_INFO("Shutting libcurl down."); + curl_global_cleanup(); +} diff --git a/src/UpdateChecker/UpdateChecker.h b/src/UpdateChecker/UpdateChecker.h new file mode 100644 index 0000000..f941cd9 --- /dev/null +++ b/src/UpdateChecker/UpdateChecker.h @@ -0,0 +1,38 @@ +#pragma once + +// MassBuilderSaveTool +// Copyright (C) 2021-2022 Guillaume Jacquemin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include + +class UpdateChecker { + public: + UpdateChecker(); + ~UpdateChecker(); + + void lock() { + _mutex.lock(); + } + bool tryLock() { + return _mutex.try_lock(); + } + void unlock() { + _mutex.unlock(); + } + + private: + std::mutex _mutex; +};