Save Tool: improve logging and reorganise stuff.
This commit is contained in:
parent
63a8cf7075
commit
14d75e0e83
3 changed files with 91 additions and 32 deletions
|
@ -64,18 +64,6 @@ SaveTool::SaveTool(const Arguments& arguments):
|
||||||
tweak.enable(""_s, "../../"_s);
|
tweak.enable(""_s, "../../"_s);
|
||||||
#endif
|
#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::Blending);
|
||||||
GL::Renderer::enable(GL::Renderer::Feature::ScissorTest);
|
GL::Renderer::enable(GL::Renderer::Feature::ScissorTest);
|
||||||
GL::Renderer::disable(GL::Renderer::Feature::FaceCulling);
|
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::setBlendEquation(GL::Renderer::BlendEquation::Add,
|
||||||
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)) {
|
if((_initEventId = SDL_RegisterEvents(3)) == UnsignedInt(-1)) {
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
||||||
|
@ -97,20 +102,26 @@ SaveTool::SaveTool(const Arguments& arguments):
|
||||||
_updateEventId = _initEventId + 1;
|
_updateEventId = _initEventId + 1;
|
||||||
_fileEventId = _initEventId + 2;
|
_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());
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_configDir = Utility::Path::join(_gameDataDir, "Saved/Config/WindowsNoEditor");
|
if(!findGameDataDirectory()) {
|
||||||
_saveDir = Utility::Path::join(_gameDataDir, "Saved/SaveGames");
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
|
||||||
_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());
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -153,6 +164,9 @@ SaveTool::SaveTool(const Arguments& arguments):
|
||||||
GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false);
|
GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utility::Debug{} << "Initialisation successful.";
|
||||||
|
Utility::Debug{} << "===Running main loop===";
|
||||||
|
|
||||||
if(_skipDisclaimer) {
|
if(_skipDisclaimer) {
|
||||||
_uiState = UiState::Initialising;
|
_uiState = UiState::Initialising;
|
||||||
_initThread = std::thread{[this]{ initialiseManager(); }};
|
_initThread = std::thread{[this]{ initialiseManager(); }};
|
||||||
|
@ -160,8 +174,12 @@ SaveTool::SaveTool(const Arguments& arguments):
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveTool::~SaveTool() {
|
SaveTool::~SaveTool() {
|
||||||
|
Utility::Debug{} << "===Perfoming cleanup===";
|
||||||
|
|
||||||
SDL_RemoveTimer(_gameCheckTimerId);
|
SDL_RemoveTimer(_gameCheckTimerId);
|
||||||
|
|
||||||
|
Utility::Debug{} << "Saving the configuration...";
|
||||||
|
|
||||||
_conf.setValue("cheat_mode"_s, _cheatMode);
|
_conf.setValue("cheat_mode"_s, _cheatMode);
|
||||||
_conf.setValue("unsafe_mode"_s, _unsafeMode);
|
_conf.setValue("unsafe_mode"_s, _unsafeMode);
|
||||||
_conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup);
|
_conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup);
|
||||||
|
@ -180,6 +198,8 @@ SaveTool::~SaveTool() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_conf.save();
|
_conf.save();
|
||||||
|
|
||||||
|
Utility::Debug{} << "Exiting...";
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveTool::handleFileAction(efsw::WatchID watch_id,
|
void SaveTool::handleFileAction(efsw::WatchID watch_id,
|
||||||
|
@ -286,6 +306,7 @@ void SaveTool::initEvent(SDL_Event& event) {
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
break;
|
break;
|
||||||
case ProfileManagerFailure:
|
case ProfileManagerFailure:
|
||||||
|
Utility::Error{} << "Error initialising ProfileManager:" << _profileManager->lastError();
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising ProfileManager", _profileManager->lastError().data(), window());
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising ProfileManager", _profileManager->lastError().data(), window());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
break;
|
break;
|
||||||
|
@ -456,6 +477,8 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveTool::initialiseConfiguration() {
|
void SaveTool::initialiseConfiguration() {
|
||||||
|
Utility::Debug{} << "Reading configuration file...";
|
||||||
|
|
||||||
if(_conf.hasValue("cheat_mode"_s)) {
|
if(_conf.hasValue("cheat_mode"_s)) {
|
||||||
_cheatMode = _conf.value<bool>("cheat_mode"_s);
|
_cheatMode = _conf.value<bool>("cheat_mode"_s);
|
||||||
}
|
}
|
||||||
|
@ -505,6 +528,8 @@ void SaveTool::initialiseConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveTool::initialiseGui() {
|
void SaveTool::initialiseGui() {
|
||||||
|
Utility::Debug{} << "Initialising ImGui...";
|
||||||
|
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
@ -564,7 +589,9 @@ void SaveTool::initialiseManager() {
|
||||||
SDL_PushEvent(&event);
|
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");
|
_backupsDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "backups");
|
||||||
_stagingDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "staging");
|
_stagingDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "staging");
|
||||||
//_armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury");
|
//_armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury");
|
||||||
|
@ -573,52 +600,83 @@ void SaveTool::initialiseToolDirectories() {
|
||||||
//_stylesDir = Utility::Directory::join(_armouryDir, "styles");
|
//_stylesDir = Utility::Directory::join(_armouryDir, "styles");
|
||||||
|
|
||||||
if(!Utility::Path::exists(_backupsDir)) {
|
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)) {
|
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)) {
|
//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)) {
|
//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)) {
|
//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)) {
|
//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 {
|
auto SaveTool::findGameDataDirectory() -> bool {
|
||||||
|
Utility::Debug{} << "Searching for the game's save directory...";
|
||||||
|
|
||||||
wchar_t* localappdata_path = nullptr;
|
wchar_t* localappdata_path = nullptr;
|
||||||
Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree};
|
Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree};
|
||||||
if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_gameDataDir = Utility::Path::join(Utility::Path::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"_s);
|
_gameDataDir = Utility::Path::join(Utility::Path::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"_s);
|
||||||
|
|
||||||
if(!Utility::Path::exists(_gameDataDir)) {
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveTool::initialiseMassManager() {
|
void SaveTool::initialiseMassManager() {
|
||||||
_massManager.emplace(_saveDir, _currentProfile->account(), _currentProfile->isDemo(), _stagingDir);
|
_massManager.emplace(_saveDir, _currentProfile->account(), _currentProfile->isDemo(), _stagingDir);
|
||||||
initialiseFileWatcher();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveTool::initialiseFileWatcher() {
|
void SaveTool::initialiseFileWatcher() {
|
||||||
|
|
|
@ -96,7 +96,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
|
||||||
void initialiseConfiguration();
|
void initialiseConfiguration();
|
||||||
void initialiseGui();
|
void initialiseGui();
|
||||||
void initialiseManager();
|
void initialiseManager();
|
||||||
void initialiseToolDirectories();
|
auto initialiseToolDirectories() -> bool;
|
||||||
auto findGameDataDirectory() -> bool;
|
auto findGameDataDirectory() -> bool;
|
||||||
void initialiseMassManager();
|
void initialiseMassManager();
|
||||||
void initialiseFileWatcher();
|
void initialiseFileWatcher();
|
||||||
|
|
|
@ -88,6 +88,7 @@ void SaveTool::drawProfileManager() {
|
||||||
{
|
{
|
||||||
_currentProfile = _profileManager->getProfile(i);
|
_currentProfile = _profileManager->getProfile(i);
|
||||||
initialiseMassManager();
|
initialiseMassManager();
|
||||||
|
initialiseFileWatcher();
|
||||||
_uiState = UiState::MainManager;
|
_uiState = UiState::MainManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue