in src/modules/fancyzones/FancyZonesLib/Settings.cpp [160:256]
void FancyZonesSettings::LoadSettings(PCWSTR config, bool fromFile) noexcept
{
try
{
PowerToysSettings::PowerToyValues values = fromFile ?
PowerToysSettings::PowerToyValues::load_from_settings_file(m_moduleKey) :
PowerToysSettings::PowerToyValues::from_json_string(config, m_moduleKey);
for (auto const& setting : m_configBools)
{
if (const auto val = values.get_bool_value(setting.name))
{
*setting.value = *val;
}
}
if (auto val = values.get_string_value(NonLocalizable::ZoneColorID))
{
m_settings.zoneColor = std::move(*val);
}
if (auto val = values.get_string_value(NonLocalizable::ZoneBorderColorID))
{
m_settings.zoneBorderColor = std::move(*val);
}
if (auto val = values.get_string_value(NonLocalizable::ZoneHighlightColorID))
{
m_settings.zoneHighlightColor = std::move(*val);
}
if (auto val = values.get_string_value(NonLocalizable::ZoneNumberColorID))
{
m_settings.zoneNumberColor = std::move(*val);
}
if (const auto val = values.get_json(NonLocalizable::EditorHotkeyID))
{
m_settings.editorHotkey = PowerToysSettings::HotkeyObject::from_json(*val);
}
if (const auto val = values.get_json(NonLocalizable::NextTabHotkeyID))
{
m_settings.nextTabHotkey = PowerToysSettings::HotkeyObject::from_json(*val);
}
if (const auto val = values.get_json(NonLocalizable::PrevTabHotkeyID))
{
m_settings.prevTabHotkey = PowerToysSettings::HotkeyObject::from_json(*val);
}
if (auto val = values.get_string_value(NonLocalizable::ExcludedAppsID))
{
m_settings.excludedApps = std::move(*val);
m_settings.excludedAppsArray.clear();
auto excludedUppercase = m_settings.excludedApps;
CharUpperBuffW(excludedUppercase.data(), (DWORD)excludedUppercase.length());
std::wstring_view view(excludedUppercase);
while (view.starts_with('\n') || view.starts_with('\r'))
{
view.remove_prefix(1);
}
while (!view.empty())
{
auto pos = (std::min)(view.find_first_of(L"\r\n"), view.length());
m_settings.excludedAppsArray.emplace_back(view.substr(0, pos));
view.remove_prefix(pos);
while (view.starts_with('\n') || view.starts_with('\r'))
{
view.remove_prefix(1);
}
}
}
if (auto val = values.get_int_value(NonLocalizable::ZoneHighlightOpacityID))
{
m_settings.zoneHighlightOpacity = *val;
}
if (auto val = values.get_int_value(NonLocalizable::OverlappingZonesAlgorithmID))
{
// Avoid undefined behavior
if (*val >= 0 || *val < (int)OverlappingZonesAlgorithm::EnumElements)
{
m_settings.overlappingZonesAlgorithm = (OverlappingZonesAlgorithm)*val;
}
}
}
catch (...)
{
// Failure to load settings does not break FancyZones functionality. Display error message and continue with default settings.
MessageBox(NULL,
GET_RESOURCE_STRING(IDS_FANCYZONES_SETTINGS_LOAD_ERROR).c_str(),
GET_RESOURCE_STRING(IDS_POWERTOYS_FANCYZONES).c_str(),
MB_OK);
}
}