diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index 6b864e8..eaf9b1a 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include @@ -81,12 +83,15 @@ SaveTool::SaveTool(const Arguments& arguments): initialiseGui(); - if((_initEventId = SDL_RegisterEvents(1)) == UnsignedInt(-1)) { + if((_initEventId = SDL_RegisterEvents(2)) == UnsignedInt(-1)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL_RegisterEvents failed in SaveTool::SaveTool(). Exiting...", window()); exit(EXIT_FAILURE); + return; } + _updateEventId = _initEventId + 1; + _backupsDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "backups"); _stagingDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging"); @@ -101,6 +106,7 @@ SaveTool::SaveTool(const Arguments& arguments): if(!findGameDataDirectory()) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.c_str(), window()); exit(EXIT_FAILURE); + return; } _configDir = Utility::Directory::join(_gameDataDir, "Saved/Config/WindowsNoEditor"); @@ -110,6 +116,7 @@ SaveTool::SaveTool(const Arguments& arguments): if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window()); exit(EXIT_FAILURE); + return; } checkGameState(); @@ -122,6 +129,7 @@ SaveTool::SaveTool(const Arguments& arguments): if(_gameCheckTimerId == 0) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window()); exit(EXIT_FAILURE); + return; } } @@ -247,6 +255,9 @@ void SaveTool::anyEvent(SDL_Event& event) { if(event.type == _initEventId) { initEvent(event); } + else if(event.type == _updateEventId) { + updateCheckEvent(event); + } } void SaveTool::initEvent(SDL_Event& event) { @@ -266,6 +277,12 @@ void SaveTool::initEvent(SDL_Event& event) { } } +void SaveTool::updateCheckEvent(SDL_Event& event) { + _thread.join(); + + // TODO: implement +} + void SaveTool::initialiseGui() { ImGui::CreateContext(); @@ -549,3 +566,12 @@ void SaveTool::checkGameState() { _gameState = GameState::Unknown; } } + +void SaveTool::checkForUpdates() { + // TODO: implement + + SDL_Event event; + SDL_zero(event); + event.type = _updateEventId; + SDL_PushEvent(&event); +} diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index cc56934..e786b0b 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -70,6 +70,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener ProfileManagerFailure }; void initEvent(SDL_Event& event); + void updateCheckEvent(SDL_Event& event); // Initialisation methods void initialiseGui(); @@ -136,6 +137,8 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener void checkGameState(); + void checkForUpdates(); + Utility::Resource _rs{"assets"}; // GUI-related members @@ -155,8 +158,10 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener bool _metricsWindow{false}; #endif - std::thread _thread; + std::thread _thread; // used for threaded operations such as profile manager init or update checking. + UnsignedInt _initEventId; + UnsignedInt _updateEventId; std::string _lastError; diff --git a/src/SaveTool/SaveTool_drawMainMenu.cpp b/src/SaveTool/SaveTool_drawMainMenu.cpp index 188e6b5..87b3d25 100644 --- a/src/SaveTool/SaveTool_drawMainMenu.cpp +++ b/src/SaveTool/SaveTool_drawMainMenu.cpp @@ -54,6 +54,12 @@ void SaveTool::drawMainMenu() { ImGui::Separator(); + if(ImGui::MenuItem(ICON_FA_SYNC_ALT " Check for updates", nullptr, false, false)) { + // TODO: implement + } + + ImGui::Separator(); + if(ImGui::MenuItem(ICON_FA_SIGN_OUT_ALT " Quit##QuitMenuItem")) { exit(EXIT_SUCCESS); }