Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config versioning to fix the Fullscreen Shortcut debacle #2966

Merged
merged 6 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions soh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -246,6 +253,7 @@ set(ALL_FILES
${Header_Files}
${Header_Files__include}
${soh__}
${soh__config}
${soh__Enhancements}
${soh__Extractor}
${soh__Resource}
Expand Down
6 changes: 6 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -789,6 +791,10 @@ extern "C" void InitOTR() {
CrowdControl::Instance->Disable();
}
#endif

std::shared_ptr<LUS::Config> conf = OTRGlobals::Instance->context->GetConfig();
conf->RegisterConfigVersionUpdater(std::make_shared<LUS::ConfigVersion1Updater>());
conf->RunVersionUpdates();
}

extern "C" void SaveManager_ThreadPoolWait() {
Expand Down
53 changes: 53 additions & 0 deletions soh/soh/config/ConfigUpdaters.cpp
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
9 changes: 9 additions & 0 deletions soh/soh/config/ConfigUpdaters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "libultraship/libultraship.h"

namespace LUS {
class ConfigVersion1Updater : public ConfigVersionUpdater {
public:
ConfigVersion1Updater();
void Update(Config* conf);
};
}
Loading