diff --git a/Common/Data/Format/IniFile.cpp b/Common/Data/Format/IniFile.cpp index df0952c8ff..6fab869ff5 100644 --- a/Common/Data/Format/IniFile.cpp +++ b/Common/Data/Format/IniFile.cpp @@ -308,13 +308,10 @@ void Section::Set(std::string_view key, const std::vector &newValue Set(key, temp.c_str()); } -bool Section::Get(std::string_view key, std::vector *values, const std::vector *defaultValues) const { +bool Section::Get(std::string_view key, std::vector *values) const { std::string temp; bool retval = Get(key, &temp); if (!retval) { - if (defaultValues) { - CopyStrings(values, *defaultValues); - } return false; } SplitString(temp, ',', *values, true); diff --git a/Common/Data/Format/IniFile.h b/Common/Data/Format/IniFile.h index ba341148bf..9cdae179cd 100644 --- a/Common/Data/Format/IniFile.h +++ b/Common/Data/Format/IniFile.h @@ -93,7 +93,7 @@ public: bool Get(std::string_view key, bool* value) const; bool Get(std::string_view key, float* value) const; bool Get(std::string_view key, double* value) const; - bool Get(std::string_view key, std::vector *values, const std::vector *defaultValue = nullptr) const; + bool Get(std::string_view key, std::vector *values) const; // Return a list of all keys in this section bool GetKeys(std::vector &keys) const; diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 961c5a13d7..a7d518da23 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -70,6 +70,8 @@ inline bool equals(std::string_view str, std::string_view key) { inline bool equalsNoCase(std::string_view str, std::string_view key) { if (str.size() != key.size()) return false; + if (str.empty()) + return true; // due to the check above, the other one is also empty. return strncasecmp(str.data(), key.data(), key.size()) == 0; } @@ -134,6 +136,14 @@ inline size_t truncate_cpy(char(&out)[Count], std::string_view src) { return truncate_cpy(out, Count, src); } +inline std::string join(std::string_view a, std::string_view b) { + std::string result; + result.reserve(a.size() + b.size()); + result.append(a); + result.append(b); + return result; +} + inline const char *safe_string(const char *s) { return s ? s : "(null)"; } diff --git a/Core/ConfigSettings.cpp b/Core/ConfigSettings.cpp index fc31de8cd7..3311e7c5cb 100644 --- a/Core/ConfigSettings.cpp +++ b/Core/ConfigSettings.cpp @@ -70,7 +70,13 @@ bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) cons { std::string *target = (std::string *)(owner + offset_); if (!section->Get(iniKey_, target)) { - *target = cb_.s ? cb_.s().c_str() : default_.s; + if (cb_.s) { + *target = cb_.s(); + } else if (default_.s) { + *target = default_.s; + } else { + target->clear(); + } return false; } return true; @@ -79,11 +85,14 @@ bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) cons { // No support for callbacks for these yet. that's not an issue. std::vector *ptr = (std::vector *)(owner + offset_); - bool success = section->Get(iniKey_, ptr, default_.v); - if (success) { - MakeUnique(*ptr); + if (!section->Get(iniKey_, ptr)) { + if (default_.v) { + CopyStrings(ptr, *default_.v); + } + return false; } - return success; + MakeUnique(*ptr); + return true; } case Type::TYPE_TOUCH_POS: { @@ -341,7 +350,7 @@ void ConfigSetting::ReportSetting(const char *owner, UrlEncoder &data, const std if (!Report()) return; - const std::string key = prefix + std::string(iniKey_); + const std::string key = join(prefix, std::string(iniKey_)); switch (type_) { case Type::TYPE_BOOL: return data.Add(key, (const bool *)(owner + offset_)); diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index 407c80e93d..df34b92b56 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -103,7 +103,7 @@ void LoadPostShaderInfo(Draw::DrawContext *draw, const std::vector &direct section.Get("Type", &shaderType); std::vector vendorBlacklist; - section.Get("VendorBlacklist", &vendorBlacklist, nullptr); + section.Get("VendorBlacklist", &vendorBlacklist); bool skipped = false; for (auto &item : vendorBlacklist) { Draw::GPUVendor blacklistedVendor = Draw::GPUVendor::VENDOR_UNKNOWN;