diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index 514d0b7..c561ce5 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -64,18 +64,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 +73,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 +102,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 +164,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 +174,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 +198,8 @@ SaveTool::~SaveTool() { } _conf.save(); + + Utility::Debug{} << "Exiting..."; } void SaveTool::handleFileAction(efsw::WatchID watch_id, @@ -286,6 +306,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; @@ -456,6 +477,8 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) { } void SaveTool::initialiseConfiguration() { + Utility::Debug{} << "Reading configuration file..."; + if(_conf.hasValue("cheat_mode"_s)) { _cheatMode = _conf.value("cheat_mode"_s); } @@ -505,6 +528,8 @@ void SaveTool::initialiseConfiguration() { } void SaveTool::initialiseGui() { + Utility::Debug{} << "Initialising ImGui..."; + ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); @@ -564,7 +589,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 +600,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() { diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index 64b796a..0c2a9c7 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -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(); diff --git a/src/SaveTool/SaveTool_ProfileManager.cpp b/src/SaveTool/SaveTool_ProfileManager.cpp index b52555a..f149151 100644 --- a/src/SaveTool/SaveTool_ProfileManager.cpp +++ b/src/SaveTool/SaveTool_ProfileManager.cpp @@ -88,6 +88,7 @@ void SaveTool::drawProfileManager() { { _currentProfile = _profileManager->getProfile(i); initialiseMassManager(); + initialiseFileWatcher(); _uiState = UiState::MainManager; }