diff options
author | elfmz <fenix1905@tut.by> | 2022-09-03 16:40:49 +0300 |
---|---|---|
committer | elfmz <fenix1905@tut.by> | 2022-09-03 16:40:49 +0300 |
commit | 7dc09d4938cb9ac34387253ce2529caa4411e398 (patch) | |
tree | 4b454a64efb1edb620daa52c98235df271c63381 | |
parent | 8fb5855053a33cfe8d20e5e8dd8ae141390a4971 (diff) |
make key_macro.ini to be case-insensitive (fix #1322)
-rw-r--r-- | far2l/src/cfg/ConfigRW.cpp | 80 |
1 files changed, 37 insertions, 43 deletions
diff --git a/far2l/src/cfg/ConfigRW.cpp b/far2l/src/cfg/ConfigRW.cpp index a2595634..d575a735 100644 --- a/far2l/src/cfg/ConfigRW.cpp +++ b/far2l/src/cfg/ConfigRW.cpp @@ -21,43 +21,37 @@ static bool IsSectionOrSubsection(const std::string &haystack, const char *needl return true; } -static const char *Section2Ini(const std::string §ion) -{ - if (IsSectionOrSubsection(section, "KeyMacros")) - return "settings/key_macros.ini"; - - if (IsSectionOrSubsection(section, "Associations")) - return "settings/associations.ini"; - - if (IsSectionOrSubsection(section, "Panel")) - return "settings/panel.ini"; - - if (IsSectionOrSubsection(section, "CodePages")) - return "settings/codepages.ini"; - - if (IsSectionOrSubsection(section, "XLat")) - return "settings/xlat.ini"; - - if (IsSectionOrSubsection(section, "Colors") - || IsSectionOrSubsection(section, "SortGroups") ) - return "settings/colors.ini"; - - if (IsSectionOrSubsection(section, "UserMenu")) - return "settings/user_menu.ini"; - - if (IsSectionOrSubsection(section, "SavedDialogHistory")) - return "history/dialogs.hst"; - - if (IsSectionOrSubsection(section, "SavedHistory")) - return "history/commands.hst"; - - if (IsSectionOrSubsection(section, "SavedFolderHistory")) - return "history/folders.hst"; - - if (IsSectionOrSubsection(section, "SavedViewHistory")) - return "history/view.hst"; +static const struct SectionProps +{ + const char *name; + const char *ini; + bool case_insensitive; +} s_default_section_props = { "", CONFIG_INI, false }; + +static const SectionProps s_section_props [] = { + {"KeyMacros", "settings/key_macros.ini", true}, + {"Associations", "settings/associations.ini", false}, + {"Panel", "settings/panel.ini", false}, + {"CodePages", "settings/codepages.ini", false}, + {"XLat", "settings/xlat.ini", false}, + {"Colors", "settings/colors.ini", false}, + {"SortGroups", "settings/colors.ini", false}, + {"UserMenu", "settings/user_menu.ini", false}, + {"SavedDialogHistory", "history/dialogs.hst", false}, + {"SavedHistory", "history/commands.hst", false}, + {"SavedFolderHistory", "history/folders.hst", false}, + {"SavedViewHistory", "history/view.hst", false} +}; + +static const SectionProps &GetSectionProps(const std::string §ion) +{ + for (const auto &sp : s_section_props) { + if (IsSectionOrSubsection(section, sp.name)) { + return sp; + } + } - return CONFIG_INI; + return s_default_section_props; } void ConfigSection::SelectSection(const std::string §ion) @@ -96,7 +90,7 @@ ConfigReader::ConfigReader(const std::string &preselect_section) struct stat ConfigReader::SavedSectionStat(const std::string §ion) { struct stat out; - if (stat(InMyConfig(Section2Ini(section)).c_str(), &out) == -1) { + if (stat(InMyConfig(GetSectionProps(section).ini).c_str(), &out) == -1) { memset(&out, 0, sizeof(out)); } return out; @@ -104,10 +98,10 @@ struct stat ConfigReader::SavedSectionStat(const std::string §ion) void ConfigReader::OnSectionSelected() { - const char *ini = Section2Ini(_section); - auto &selected_kfh = _ini2kfh[ini]; + const auto &sp = GetSectionProps(_section); + auto &selected_kfh = _ini2kfh[sp.ini]; if (!selected_kfh) { - selected_kfh.reset(new KeyFileReadHelper(InMyConfig(ini))); + selected_kfh.reset(new KeyFileReadHelper(InMyConfig(sp.ini), nullptr, sp.case_insensitive)); } _selected_kfh = selected_kfh.get(); _selected_section_values = _selected_kfh->GetSectionValues(_section); @@ -223,10 +217,10 @@ bool ConfigWriter::Save() void ConfigWriter::OnSectionSelected() { - const char *ini = Section2Ini(_section); - auto &selected_kfh = _ini2kfh[ini]; + const auto &sp = GetSectionProps(_section); + auto &selected_kfh = _ini2kfh[sp.ini]; if (!selected_kfh) { - selected_kfh.reset(new KeyFileHelper(InMyConfig(ini))); + selected_kfh.reset(new KeyFileHelper(InMyConfig(sp.ini), true, sp.case_insensitive)); } _selected_kfh = selected_kfh.get(); |