Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelfmz <fenix1905@tut.by>2022-09-03 16:40:49 +0300
committerelfmz <fenix1905@tut.by>2022-09-03 16:40:49 +0300
commit7dc09d4938cb9ac34387253ce2529caa4411e398 (patch)
tree4b454a64efb1edb620daa52c98235df271c63381
parent8fb5855053a33cfe8d20e5e8dd8ae141390a4971 (diff)
make key_macro.ini to be case-insensitive (fix #1322)
-rw-r--r--far2l/src/cfg/ConfigRW.cpp80
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 &section)
-{
- 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 &section)
+{
+ 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 &section)
@@ -96,7 +90,7 @@ ConfigReader::ConfigReader(const std::string &preselect_section)
struct stat ConfigReader::SavedSectionStat(const std::string &section)
{
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 &section)
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();