SaveTool: add skeleton for update checking.

This commit is contained in:
Guillaume Jacquemin 2021-07-22 11:39:53 +02:00
parent 4dd2064aae
commit d0eee0caeb
3 changed files with 39 additions and 2 deletions

View file

@ -30,6 +30,8 @@
#include <Magnum/ImGuiIntegration/Integration.h> #include <Magnum/ImGuiIntegration/Integration.h>
#include <Magnum/ImGuiIntegration/Context.hpp> #include <Magnum/ImGuiIntegration/Context.hpp>
#include <cpr/cpr.h>
#include <windef.h> #include <windef.h>
#include <winuser.h> #include <winuser.h>
#include <processthreadsapi.h> #include <processthreadsapi.h>
@ -81,12 +83,15 @@ SaveTool::SaveTool(const Arguments& arguments):
initialiseGui(); initialiseGui();
if((_initEventId = SDL_RegisterEvents(1)) == UnsignedInt(-1)) { if((_initEventId = SDL_RegisterEvents(2)) == UnsignedInt(-1)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"SDL_RegisterEvents failed in SaveTool::SaveTool(). Exiting...", window()); "SDL_RegisterEvents failed in SaveTool::SaveTool(). Exiting...", window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return;
} }
_updateEventId = _initEventId + 1;
_backupsDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "backups"); _backupsDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "backups");
_stagingDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging"); _stagingDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging");
@ -101,6 +106,7 @@ SaveTool::SaveTool(const Arguments& arguments):
if(!findGameDataDirectory()) { if(!findGameDataDirectory()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.c_str(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.c_str(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return;
} }
_configDir = Utility::Directory::join(_gameDataDir, "Saved/Config/WindowsNoEditor"); _configDir = Utility::Directory::join(_gameDataDir, "Saved/Config/WindowsNoEditor");
@ -110,6 +116,7 @@ SaveTool::SaveTool(const Arguments& arguments):
if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) { if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return;
} }
checkGameState(); checkGameState();
@ -122,6 +129,7 @@ SaveTool::SaveTool(const Arguments& arguments):
if(_gameCheckTimerId == 0) { if(_gameCheckTimerId == 0) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return;
} }
} }
@ -247,6 +255,9 @@ void SaveTool::anyEvent(SDL_Event& event) {
if(event.type == _initEventId) { if(event.type == _initEventId) {
initEvent(event); initEvent(event);
} }
else if(event.type == _updateEventId) {
updateCheckEvent(event);
}
} }
void SaveTool::initEvent(SDL_Event& 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() { void SaveTool::initialiseGui() {
ImGui::CreateContext(); ImGui::CreateContext();
@ -549,3 +566,12 @@ void SaveTool::checkGameState() {
_gameState = GameState::Unknown; _gameState = GameState::Unknown;
} }
} }
void SaveTool::checkForUpdates() {
// TODO: implement
SDL_Event event;
SDL_zero(event);
event.type = _updateEventId;
SDL_PushEvent(&event);
}

View file

@ -70,6 +70,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
ProfileManagerFailure ProfileManagerFailure
}; };
void initEvent(SDL_Event& event); void initEvent(SDL_Event& event);
void updateCheckEvent(SDL_Event& event);
// Initialisation methods // Initialisation methods
void initialiseGui(); void initialiseGui();
@ -136,6 +137,8 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
void checkGameState(); void checkGameState();
void checkForUpdates();
Utility::Resource _rs{"assets"}; Utility::Resource _rs{"assets"};
// GUI-related members // GUI-related members
@ -155,8 +158,10 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
bool _metricsWindow{false}; bool _metricsWindow{false};
#endif #endif
std::thread _thread; std::thread _thread; // used for threaded operations such as profile manager init or update checking.
UnsignedInt _initEventId; UnsignedInt _initEventId;
UnsignedInt _updateEventId;
std::string _lastError; std::string _lastError;

View file

@ -54,6 +54,12 @@ void SaveTool::drawMainMenu() {
ImGui::Separator(); 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")) { if(ImGui::MenuItem(ICON_FA_SIGN_OUT_ALT " Quit##QuitMenuItem")) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }