From e981fa53f32df0bed93e0bbf5c113e2b9fb061b1 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 5 Jul 2022 09:01:09 +0200 Subject: [PATCH] fix: std::u8string usage with nlohmann::json --- .../include/hex/api/content_registry.hpp | 6 --- lib/libimhex/source/api/content_registry.cpp | 52 ------------------- .../builtin/source/content/welcome_screen.cpp | 6 +-- 3 files changed, 3 insertions(+), 61 deletions(-) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index ba4f22e1d..c1a15e014 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -71,23 +71,17 @@ namespace hex { void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue, const Callback &callback, bool requiresRestart = false); void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback, bool requiresRestart = false); - void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::u8string &defaultValue, const Callback &callback, bool requiresRestart = false); void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue, const Callback &callback, bool requiresRestart = false); - void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue, const Callback &callback, bool requiresRestart = false); void addCategoryDescription(const std::string &unlocalizedCategory, const std::string &unlocalizedCategoryDescription); void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 value); void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &value); - void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::u8string &value); void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &value); - void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &value); i64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue); std::string read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue); - std::u8string read(const std::string &unlocalizedCategory, const std::u8string &unlocalizedName, const std::string &defaultValue); std::vector read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue = {}); - std::vector read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue = {}); std::map> &getEntries(); std::map &getCategoryDescriptions(); diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 4420a3bd3..238725728 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -80,19 +80,6 @@ namespace hex { json[unlocalizedCategory][unlocalizedName] = std::string(defaultValue); } - void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::u8string &defaultValue, const Callback &callback, bool requiresRestart) { - log::info("Registered new string setting: [{}]: {}", unlocalizedCategory, unlocalizedName); - - getCategoryEntry(unlocalizedCategory)->second.emplace_back(Entry { unlocalizedName, requiresRestart, callback }); - - auto &json = getSettingsData(); - - if (!json.contains(unlocalizedCategory)) - json[unlocalizedCategory] = nlohmann::json::object(); - if (!json[unlocalizedCategory].contains(unlocalizedName) || !json[unlocalizedCategory][unlocalizedName].is_string()) - json[unlocalizedCategory][unlocalizedName] = defaultValue; - } - void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue, const Callback &callback, bool requiresRestart) { log::info("Registered new string array setting: [{}]: {}", unlocalizedCategory, unlocalizedName); @@ -106,19 +93,6 @@ namespace hex { json[unlocalizedCategory][unlocalizedName] = defaultValue; } - void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue, const Callback &callback, bool requiresRestart) { - log::info("Registered new u8string array setting: [{}]: {}", unlocalizedCategory, unlocalizedName); - - getCategoryEntry(unlocalizedCategory)->second.emplace_back(Entry { unlocalizedName, requiresRestart, callback }); - - auto &json = getSettingsData(); - - if (!json.contains(unlocalizedCategory)) - json[unlocalizedCategory] = nlohmann::json::object(); - if (!json[unlocalizedCategory].contains(unlocalizedName) || !json[unlocalizedCategory][unlocalizedName].is_array()) - json[unlocalizedCategory][unlocalizedName] = defaultValue; - } - void addCategoryDescription(const std::string &unlocalizedCategory, const std::string &unlocalizedCategoryDescription) { getCategoryDescriptions()[unlocalizedCategory] = unlocalizedCategoryDescription; } @@ -150,15 +124,6 @@ namespace hex { json[unlocalizedCategory][unlocalizedName] = value; } - void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &value) { - auto &json = getSettingsData(); - - if (!json.contains(unlocalizedCategory)) - json[unlocalizedCategory] = nlohmann::json::object(); - - json[unlocalizedCategory][unlocalizedName] = value; - } - i64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue) { auto &json = getSettingsData(); @@ -205,23 +170,6 @@ namespace hex { return json[unlocalizedCategory][unlocalizedName].get>(); } - std::vector read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector &defaultValue) { - auto &json = getSettingsData(); - - if (!json.contains(unlocalizedCategory)) - return defaultValue; - if (!json[unlocalizedCategory].contains(unlocalizedName)) - return defaultValue; - - if (!json[unlocalizedCategory][unlocalizedName].is_array()) - json[unlocalizedCategory][unlocalizedName] = defaultValue; - - if (!json[unlocalizedCategory][unlocalizedName].array().empty() && !json[unlocalizedCategory][unlocalizedName][0].is_string()) - json[unlocalizedCategory][unlocalizedName] = defaultValue; - - return json[unlocalizedCategory][unlocalizedName].get>(); - } - std::map> &getEntries() { static std::map> entries; diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index 6e1315e6c..b9f5d2f17 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -403,9 +403,9 @@ namespace hex::plugin::builtin { } { - std::vector recentFilesVector; + std::vector recentFilesVector; for (const auto &recentPath : s_recentFilePaths) - recentFilesVector.push_back(recentPath.u8string()); + recentFilesVector.push_back(recentPath.string()); ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files", recentFilesVector); } @@ -450,7 +450,7 @@ namespace hex::plugin::builtin { } } - for (const auto &pathString : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files", std::vector{ })) { + for (const auto &pathString : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files")) { std::fs::path path = std::u8string(pathString.begin(), pathString.end()); if (fs::exists(path)) s_recentFilePaths.emplace_back(path);