mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
api: Fix various crashes on bad settings data. (#186)
getSetting now returns a straight nlohmann::json instead of an optional. If the data isn't present, it will return a json null. All accesses to the settings will first check that the data has the expected type.
This commit is contained in:
@@ -5,7 +5,7 @@ namespace hex::plugin::builtin {
|
||||
void registerSettings() {
|
||||
|
||||
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) {
|
||||
static int selection = setting;
|
||||
static int selection = setting.is_number() ? static_cast<int>(setting) : 0;
|
||||
|
||||
const char* themes[] = {
|
||||
"hex.builtin.setting.interface.color.dark"_lang,
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace hex {
|
||||
static std::vector<std::string> read(std::string_view unlocalizedCategory, std::string_view unlocalizedName, const std::vector<std::string>& defaultValue = { });
|
||||
|
||||
static std::map<std::string, std::vector<Entry>>& getEntries();
|
||||
static std::optional<nlohmann::json> getSetting(std::string_view unlocalizedCategory, std::string_view unlocalizedName);
|
||||
static nlohmann::json getSetting(std::string_view unlocalizedCategory, std::string_view unlocalizedName);
|
||||
static nlohmann::json& getSettingsData();
|
||||
};
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace hex {
|
||||
return SharedData::settingsEntries;
|
||||
}
|
||||
|
||||
std::optional<nlohmann::json> ContentRegistry::Settings::getSetting(std::string_view unlocalizedCategory, std::string_view unlocalizedName) {
|
||||
nlohmann::json ContentRegistry::Settings::getSetting(std::string_view unlocalizedCategory, std::string_view unlocalizedName) {
|
||||
auto &settings = getSettingsData();
|
||||
|
||||
if (!settings.contains(unlocalizedCategory)) return { };
|
||||
|
||||
Reference in New Issue
Block a user