From 430d5cddf2a20e767ed92cec3e3a863f27c5659e Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 12 Jun 2023 18:59:23 -0400 Subject: [PATCH] Config versioning to fix the Fullscreen Shortcut debacle (#2966) * WIP adding new config version. * Implements a ConfigVersionUpdater * Updates to account for new LUS-side changes. * Change `ConfigVersionUpdater` to store `toVersion` * fix typo --- soh/CMakeLists.txt | 8 +++++ soh/soh/OTRGlobals.cpp | 6 ++++ soh/soh/config/ConfigUpdaters.cpp | 53 +++++++++++++++++++++++++++++++ soh/soh/config/ConfigUpdaters.h | 9 ++++++ 4 files changed, 76 insertions(+) create mode 100644 soh/soh/config/ConfigUpdaters.cpp create mode 100644 soh/soh/config/ConfigUpdaters.h diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index 5186d941f..5eda0d6aa 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -131,6 +131,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set_source_files_properties(soh/OTRGlobals.cpp PROPERTIES COMPILE_FLAGS "/utf-8") endif() +# soh/config {{{ +file(GLOB_RECURSE soh__config RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "soh/config/*.h" + "soh/config/*.cpp" +) +# }}} + # soh/enhancements {{{ file(GLOB_RECURSE soh__Enhancements RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "soh/Enhancements/*.c" @@ -246,6 +253,7 @@ set(ALL_FILES ${Header_Files} ${Header_Files__include} ${soh__} + ${soh__config} ${soh__Enhancements} ${soh__Extractor} ${soh__Resource} diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index a75416a71..c7646e1cc 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -110,6 +110,8 @@ CrowdControl* CrowdControl::Instance; #include "soh/resource/importer/TextFactory.h" #include "soh/resource/importer/BackgroundFactory.h" +#include "soh/config/ConfigUpdaters.h" + OTRGlobals* OTRGlobals::Instance; SaveManager* SaveManager::Instance; CustomMessageManager* CustomMessageManager::Instance; @@ -789,6 +791,10 @@ extern "C" void InitOTR() { CrowdControl::Instance->Disable(); } #endif + + std::shared_ptr conf = OTRGlobals::Instance->context->GetConfig(); + conf->RegisterConfigVersionUpdater(std::make_shared()); + conf->RunVersionUpdates(); } extern "C" void SaveManager_ThreadPoolWait() { diff --git a/soh/soh/config/ConfigUpdaters.cpp b/soh/soh/config/ConfigUpdaters.cpp new file mode 100644 index 000000000..f7da1cbfc --- /dev/null +++ b/soh/soh/config/ConfigUpdaters.cpp @@ -0,0 +1,53 @@ +#include "ConfigUpdaters.h" + +namespace LUS { + ConfigVersion1Updater::ConfigVersion1Updater() : ConfigVersionUpdater(1) {} + + void ConfigVersion1Updater::Update(Config* conf) { + if (conf->GetInt("Window.Width", 640) == 640) { + conf->Erase("Window.Width"); + } + if (conf->GetInt("Window.Height", 480) == 480) { + conf->Erase("Window.Height"); + } + if (conf->GetInt("Window.PositionX", 100) == 100) { + conf->Erase("Window.PositionX"); + } + if (conf->GetInt("Window.PositionY", 100) == 100) { + conf->Erase("Window.PositionY"); + } + if (conf->GetString("Window.GfxBackend", "") == "") { + conf->Erase("Window.GfxBackend"); + } + if (conf->GetString("Window.GfxApi", "") == "") { + conf->Erase("Window.GfxApi"); + } + if (conf->GetString("Window.AudioBackend", "") == "") { + conf->Erase("Window.AudioBackend"); + } + if (conf->GetBool("Window.Fullscreen.Enabled", false) == false) { + conf->Erase("Window.Fullscreen.Enabled"); + } + if (conf->GetInt("Window.Fullscreen.Width", 1920) == 1920) { + conf->Erase("Window.Fullscreen.Width"); + } + if (conf->GetInt("Window.Fullscreen.Height", 1080) == 1080) { + conf->Erase("Window.Fullscreen.Height"); + } + if (conf->GetInt("Shortcuts.Fullscreen", KbScancode::LUS_KB_F11) == KbScancode::LUS_KB_F10) { + conf->Erase("Shortcuts.Fullscreen"); + } + if (conf->GetInt("Shortcuts.Console", KbScancode::LUS_KB_OEM_3) == KbScancode::LUS_KB_OEM_3) { + conf->Erase("Shortcuts.Console"); + } + if (conf->GetString("Game.SaveName", "") == "") { + conf->Erase("Game.SaveName"); + } + if (conf->GetString("Game.Main Archive", "") == "") { + conf->Erase("Game.Main Archive"); + } + if (conf->GetString("Game.Patches Archive", "") == "") { + conf->Erase("Game.Patches Archive"); + } + } +} \ No newline at end of file diff --git a/soh/soh/config/ConfigUpdaters.h b/soh/soh/config/ConfigUpdaters.h new file mode 100644 index 000000000..e7f684ae4 --- /dev/null +++ b/soh/soh/config/ConfigUpdaters.h @@ -0,0 +1,9 @@ +#include "libultraship/libultraship.h" + +namespace LUS { +class ConfigVersion1Updater : public ConfigVersionUpdater { + public: + ConfigVersion1Updater(); + void Update(Config* conf); +}; +} \ No newline at end of file