From a64db0b340b221dde2407bcb1e8e6a90fdbc29be Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Thu, 20 Mar 2025 20:45:58 -0300 Subject: [PATCH] ordering is separation in a function --- src/common/config.cpp | 95 +++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 58 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 695fff073..b75783e4f 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -897,6 +897,37 @@ void load(const std::filesystem::path& path) { } } +void sortTomlSections(toml::ordered_value& data) { + toml::ordered_value ordered_data; + std::vector section_order = {"General", "Input", "GPU", "Vulkan", + "Debug", "Keys", "GUI", "Settings"}; + + for (const auto& section : section_order) { + if (data.contains(section)) { + std::vector keys; + for (const auto& item : data.at(section).as_table()) { + keys.push_back(item.first); + } + + std::sort(keys.begin(), keys.end(), [](const std::string& a, const std::string& b) { + return std::lexicographical_compare( + a.begin(), a.end(), b.begin(), b.end(), [](char a_char, char b_char) { + return std::tolower(a_char) < std::tolower(b_char); + }); + }); + + toml::ordered_value ordered_section; + for (const auto& key : keys) { + ordered_section[key] = data.at(section).at(key); + } + + ordered_data[section] = ordered_section; + } + } + + data = ordered_data; +} + void save(const std::filesystem::path& path) { toml::ordered_value data; @@ -1007,37 +1038,11 @@ void save(const std::filesystem::path& path) { data["GUI"]["showBackgroundImage"] = showBackgroundImage; data["Settings"]["consoleLanguage"] = m_language; - toml::ordered_value ordered_data; - - // Set the order of main sections - std::vector section_order = {"General", "Input", "GPU", "Vulkan", - "Debug", "Keys", "GUI", "Settings"}; - - for (const auto& section : section_order) { - if (data.contains(section)) { - std::vector keys; - for (const auto& item : data.at(section).as_table()) { - keys.push_back(item.first); - } - - std::sort(keys.begin(), keys.end(), [](const std::string& a, const std::string& b) { - return std::lexicographical_compare( - a.begin(), a.end(), b.begin(), b.end(), [](char a_char, char b_char) { - return std::tolower(a_char) < std::tolower(b_char); - }); - }); - - toml::ordered_value ordered_section; - for (const auto& key : keys) { - ordered_section[key] = data.at(section).at(key); - } - - ordered_data[section] = ordered_section; - } - } + // Sorting of TOML sections + sortTomlSections(data); std::ofstream file(path, std::ios::binary); - file << ordered_data; + file << data; file.close(); saveMainWindow(path); @@ -1081,37 +1086,11 @@ void saveMainWindow(const std::filesystem::path& path) { data["GUI"]["elfDirs"] = m_elf_viewer; data["GUI"]["recentFiles"] = m_recent_files; - toml::ordered_value ordered_data; - - // Set the order of main sections - std::vector section_order = {"General", "Input", "GPU", "Vulkan", - "Debug", "Keys", "GUI", "Settings"}; - - for (const auto& section : section_order) { - if (data.contains(section)) { - std::vector keys; - for (const auto& item : data.at(section).as_table()) { - keys.push_back(item.first); - } - - std::sort(keys.begin(), keys.end(), [](const std::string& a, const std::string& b) { - return std::lexicographical_compare( - a.begin(), a.end(), b.begin(), b.end(), [](char a_char, char b_char) { - return std::tolower(a_char) < std::tolower(b_char); - }); - }); - - toml::ordered_value ordered_section; - for (const auto& key : keys) { - ordered_section[key] = data.at(section).at(key); - } - - ordered_data[section] = ordered_section; - } - } + // Sorting of TOML sections + sortTomlSections(data); std::ofstream file(path, std::ios::binary); - file << ordered_data; + file << data; file.close(); }