From b8a901c870a0a1a93e2acab20c028500c8e4957c Mon Sep 17 00:00:00 2001 From: Shaolin Date: Wed, 9 May 2018 05:52:56 -0300 Subject: [PATCH] UI: Convert multiview layout string profiles to int This commit series changes the ini user configuration multiview layout so that string values were converted to int. In order to prevent past user saves to break we verify if the ini still have string values and convert that to int on obs init. This will make the code easier to maintain in clearer to read the multiview layout settings, also, makes the addition of new layouts easier. --- UI/obs-app.cpp | 39 +++++++++++++++++++++++++++++++++++++++ UI/obs-app.hpp | 2 ++ 2 files changed, 41 insertions(+) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index f8f76755c..fa106152e 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -591,6 +591,38 @@ static string GetSceneCollectionFileFromName(const char *name) return outputPath; } +bool OBSApp::UpdatePre22MultiviewLayout(const char *layout) +{ + if (!layout) + return false; + + if (astrcmpi(layout, "horizontaltop") == 0) { + config_set_int(globalConfig, "BasicWindow", "MultiviewLayout", + static_cast(MultiviewLayout::HORIZONTAL_TOP)); + return true; + } + + if (astrcmpi(layout, "horizontalbottom") == 0) { + config_set_int(globalConfig, "BasicWindow", "MultiviewLayout", + static_cast(MultiviewLayout::HORIZONTAL_BOTTOM)); + return true; + } + + if (astrcmpi(layout, "verticalleft") == 0) { + config_set_int(globalConfig, "BasicWindow", "MultiviewLayout", + static_cast(MultiviewLayout::VERTICAL_LEFT)); + return true; + } + + if (astrcmpi(layout, "verticalright") == 0) { + config_set_int(globalConfig, "BasicWindow", "MultiviewLayout", + static_cast(MultiviewLayout::VERTICAL_RIGHT)); + return true; + } + + return false; +} + bool OBSApp::InitGlobalConfig() { char path[512]; @@ -656,6 +688,13 @@ bool OBSApp::InitGlobalConfig() changed = true; } + if (config_has_user_value(globalConfig, "BasicWindow", + "MultiviewLayout")) { + const char *layout = config_get_string(globalConfig, + "BasicWindow", "MultiviewLayout"); + changed |= UpdatePre22MultiviewLayout(layout); + } + if (changed) config_save_safe(globalConfig, "tmp", nullptr); diff --git a/UI/obs-app.hpp b/UI/obs-app.hpp index c32896129..4a17e4971 100644 --- a/UI/obs-app.hpp +++ b/UI/obs-app.hpp @@ -78,6 +78,8 @@ private: std::deque translatorHooks; + bool UpdatePre22MultiviewLayout(const char *layout); + bool InitGlobalConfig(); bool InitGlobalConfigDefaults(); bool InitLocale();