Prepare for the new defaulting mechanism, IniFile cleanup

This commit is contained in:
Henrik Rydgård
2025-11-05 11:24:58 +01:00
parent 2651a3a241
commit 2b863aafe1
8 changed files with 106 additions and 174 deletions
+5 -85
View File
@@ -189,11 +189,12 @@ void Section::Clear() {
lines_.clear();
}
bool Section::GetKeys(std::vector<std::string> &keys) const {
keys.clear();
bool Section::GetKeys(std::vector<std::string> *keys) const {
keys->clear();
keys->reserve(lines_.size());
for (const auto &line : lines_) {
if (!line.Key().empty())
keys.emplace_back(line.Key());
keys->emplace_back(line.Key());
}
return true;
}
@@ -366,7 +367,7 @@ bool Section::Get(std::string_view key, double* value) const {
return false;
}
bool Section::Exists(std::string_view key) const {
bool Section::HasKey(std::string_view key) const {
for (auto &line : lines_) {
if (equalsNoCase(key, line.Key()))
return true;
@@ -438,35 +439,6 @@ bool IniFile::DeleteSection(std::string_view sectionName) {
return false;
}
bool IniFile::Exists(std::string_view sectionName, std::string_view key) const {
const Section* section = GetSection(sectionName);
if (!section)
return false;
return section->Exists(key);
}
bool IniFile::DeleteKey(std::string_view sectionName, std::string_view key) {
Section* section = GetSection(sectionName);
if (!section)
return false;
ParsedIniLine *line = section->GetLine(key);
for (auto liter = section->lines_.begin(); liter != section->lines_.end(); ++liter) {
if (line == &(*liter)) {
section->lines_.erase(liter);
return true;
}
}
return false; //shouldn't happen
}
// Return a list of all keys in a section
bool IniFile::GetKeys(std::string_view sectionName, std::vector<std::string>& keys) const {
const Section *section = GetSection(sectionName);
if (!section)
return false;
return section->GetKeys(keys);
}
void IniFile::SortSections() {
std::sort(sections.begin(), sections.end());
}
@@ -566,55 +538,3 @@ bool IniFile::Save(const Path &filename)
fclose(file);
return true;
}
bool IniFile::Get(std::string_view sectionName, std::string_view key, std::string *value) const {
const Section *section = GetSection(sectionName);
if (!section) {
return false;
}
return section->Get(key, value);
}
bool IniFile::Get(std::string_view sectionName, std::string_view key, std::vector<std::string> *values) const {
const Section *section = GetSection(sectionName);
if (!section) {
return false;
}
return section->Get(key, values);
}
bool IniFile::Get(std::string_view sectionName, std::string_view key, int *value) const {
const Section *section = GetSection(sectionName);
if (!section) {
return false;
} else {
return section->Get(key, value);
}
}
bool IniFile::Get(std::string_view sectionName, std::string_view key, uint32_t *value) const {
const Section *section = GetSection(sectionName);
if (!section) {
return false;
} else {
return section->Get(key, value);
}
}
bool IniFile::Get(std::string_view sectionName, std::string_view key, uint64_t *value) const {
const Section *section = GetSection(sectionName);
if (!section) {
return false;
} else {
return section->Get(key, value);
}
}
bool IniFile::Get(std::string_view sectionName, std::string_view key, bool *value) const {
const Section *section = GetSection(sectionName);
if (!section) {
return false;
} else {
return section->Get(key, value);
}
}
+2 -16
View File
@@ -55,7 +55,7 @@ public:
Section() {}
Section(std::string_view name) : name_(name) {}
bool Exists(std::string_view key) const;
bool HasKey(std::string_view key) const;
bool Delete(std::string_view key);
void Clear();
@@ -96,7 +96,7 @@ public:
bool Get(std::string_view key, std::vector<std::string> *values) const;
// Return a list of all keys in this section
bool GetKeys(std::vector<std::string> &keys) const;
bool GetKeys(std::vector<std::string> *keys) const;
bool operator < (const Section& other) const {
return name_ < other.name_;
@@ -125,20 +125,6 @@ public:
bool Save(const Path &path);
// Returns true if key exists in section
bool Exists(std::string_view sectionName, std::string_view key) const;
// These will not create the section if it doesn't exist.
bool Get(std::string_view sectionName, std::string_view key, std::string *value) const;
bool Get(std::string_view sectionName, std::string_view key, int* value) const;
bool Get(std::string_view sectionName, std::string_view key, uint32_t* value) const;
bool Get(std::string_view sectionName, std::string_view key, uint64_t* value) const;
bool Get(std::string_view sectionName, std::string_view key, bool* value) const;
bool Get(std::string_view sectionName, std::string_view key, std::vector<std::string> *values) const;
bool GetKeys(std::string_view sectionName, std::vector<std::string>& keys) const;
bool DeleteKey(std::string_view sectionName, std::string_view key);
bool DeleteSection(std::string_view sectionName);
void SortSections();
+12 -5
View File
@@ -170,13 +170,18 @@ void Compatibility::CheckVRSettings(IniFile &iniFile, const std::string &gameID)
void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) {
if (ignored_.find(option) == ignored_.end()) {
iniFile.Get(option, gameID.c_str(), flag);
Section *section = iniFile.GetSection(option);
if (!section) {
// Not found, skip.
return;
}
section->Get(gameID, flag);
// Shortcut for debugging, sometimes useful to globally enable compat flags.
bool all = false;
iniFile.Get(option, "ALL", &all);
section->Get("ALL", &all);
if (all) {
*flag |= all;
*flag = true;
if (!activeList_.empty()) {
activeList_ += "\n";
}
@@ -187,14 +192,16 @@ void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, co
void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, float *flag) {
std::string value;
if (iniFile.Get(option, gameID.c_str(), &value)) {
Section *section = iniFile.GetSection(option);
if (section && section->Get(gameID.c_str(), &value)) {
*flag = stof(value);
}
}
void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, int *flag) {
std::string value;
if (iniFile.Get(option, gameID.c_str(), &value)) {
Section *section = iniFile.GetSection(option);
if (section && section->Get(gameID.c_str(), &value)) {
*flag = stof(value);
}
}
+9 -7
View File
@@ -113,8 +113,10 @@ std::string DefaultLangRegion() {
IniFile mapping;
mapping.LoadFromVFS(g_VFS, "langregion.ini");
std::vector<std::string> keys;
mapping.GetKeys("LangRegionNames", keys);
Section *section = mapping.GetSection("LangRegionNames");
if (section) {
section->GetKeys(&keys);
}
for (const std::string &key : keys) {
if (startsWithNoCase(key, langRegion)) {
// Exact submatch, or different case. Let's use it.
@@ -1161,8 +1163,8 @@ bool Config::LoadAppendedConfig() {
}
IterateSettingsIni(iniFile, [&iniFile](ConfigBlock *configBlock, Section *section, const ConfigSetting &setting) {
if (section->Exists(setting.iniKey_)) {
setting.ReadFromIniSection(configBlock, section);
if (section->HasKey(setting.iniKey_)) {
setting.ReadFromIniSection(configBlock, section, true);
}
}, true);
@@ -1204,7 +1206,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
}
IterateSettingsIni(iniFile, [](ConfigBlock *configBlock, const Section *section, const ConfigSetting &setting) {
setting.ReadFromIniSection(configBlock, section);
setting.ReadFromIniSection(configBlock, section, true);
}, true);
iRunCount++;
@@ -1691,7 +1693,7 @@ bool Config::LoadGameConfig(const std::string &gameId) {
IterateSettingsIni(iniFile, [](ConfigBlock *configBlock, const Section *section, const ConfigSetting &setting) {
if (setting.PerGame()) {
setting.ReadFromIniSection(configBlock, section);
setting.ReadFromIniSection(configBlock, section, true);
}
}, true);
@@ -1720,7 +1722,7 @@ void Config::UnloadGameConfig() {
IniFile iniFile;
iniFile.Load(iniFilename_);
IterateSettingsIni(iniFile, [](ConfigBlock *configBlock, const Section *section, const ConfigSetting &setting) {
setting.ReadFromIniSection(configBlock, section);
setting.ReadFromIniSection(configBlock, section, true);
}, true);
auto postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting")->ToMap();
+53 -39
View File
@@ -12,14 +12,16 @@ bool ConfigSetting::perGame(void *ptr) {
return g_Config.gameSpecific_ && g_Config.getPtrLUT().count(ptr) > 0 && g_Config.getPtrLUT()[ptr]->PerGame();
}
bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *section) const {
bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *section, bool applyDefaultIfMissing) const {
char *owner = (char *)configBlock;
switch (type_) {
case Type::TYPE_BOOL:
{
bool *target = (bool *)(owner + offset_);
if (!section->Get(iniKey_, target)) {
*target = cb_.b ? cb_.b() : default_.b;
if (applyDefaultIfMissing) {
*target = defaultCallback_.b ? defaultCallback_.b() : default_.b;
}
return false;
}
return true;
@@ -35,7 +37,9 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
}
}
if (!section->Get(iniKey_, target)) {
*target = cb_.i ? cb_.i() : default_.i;
if (applyDefaultIfMissing) {
*target = defaultCallback_.i ? defaultCallback_.i() : default_.i;
}
return false;
}
return true;
@@ -44,7 +48,9 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
{
uint32_t *target = (uint32_t *)(owner + offset_);
if (!section->Get(iniKey_, target)) {
*target = cb_.u ? cb_.u() : default_.u;
if (applyDefaultIfMissing) {
*target = defaultCallback_.u ? defaultCallback_.u() : default_.u;
}
return false;
}
return true;
@@ -53,7 +59,9 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
{
uint64_t *target = (uint64_t *)(owner + offset_);
if (!section->Get(iniKey_, target)) {
*target = cb_.lu ? cb_.lu() : default_.lu;
if (applyDefaultIfMissing) {
*target = defaultCallback_.lu ? defaultCallback_.lu() : default_.lu;
}
return false;
}
return true;
@@ -62,7 +70,9 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
{
float *target = (float *)(owner + offset_);
if (!section->Get(iniKey_, target)) {
*target = cb_.f ? cb_.f() : default_.f;
if (applyDefaultIfMissing) {
*target = defaultCallback_.f ? defaultCallback_.f() : default_.f;
}
return false;
}
return true;
@@ -71,12 +81,14 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
{
std::string *target = (std::string *)(owner + offset_);
if (!section->Get(iniKey_, target)) {
if (cb_.s) {
*target = cb_.s();
} else if (default_.s) {
*target = default_.s;
} else {
target->clear();
if (applyDefaultIfMissing) {
if (defaultCallback_.s) {
*target = defaultCallback_.s();
} else if (default_.s) {
*target = default_.s;
} else {
target->clear();
}
}
return false;
}
@@ -87,7 +99,7 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
// No support for callbacks for these yet. that's not an issue.
std::vector<std::string> *ptr = (std::vector<std::string> *)(owner + offset_);
if (!section->Get(iniKey_, ptr)) {
if (default_.v) {
if (applyDefaultIfMissing && default_.v) {
CopyStrings(ptr, *default_.v);
}
return false;
@@ -97,21 +109,21 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
}
case Type::TYPE_TOUCH_POS:
{
ConfigTouchPos defaultTouchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos;
ConfigTouchPos defaultTouchPos = defaultCallback_.touchPos ? defaultCallback_.touchPos() : default_.touchPos;
ConfigTouchPos *touchPos = ((ConfigTouchPos *)(owner + offset_));
if (!section->Get(iniKey_, &touchPos->x)) {
if (!section->Get(iniKey_, &touchPos->x) && applyDefaultIfMissing) {
touchPos->x = defaultTouchPos.x;
}
if (!section->Get(ini2_, &touchPos->y)) {
if (!section->Get(ini2_, &touchPos->y) && applyDefaultIfMissing) {
touchPos->y = defaultTouchPos.y;
}
if (!section->Get(ini3_, &touchPos->scale)) {
if (!section->Get(ini3_, &touchPos->scale) && applyDefaultIfMissing) {
touchPos->scale = defaultTouchPos.scale;
}
if (ini4_ && section->Get(ini4_, &touchPos->show)) {
// do nothing, succeeded.
} else {
} else if (applyDefaultIfMissing) {
touchPos->show = defaultTouchPos.show;
}
return true;
@@ -121,10 +133,12 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
Path *target = (Path *)(owner + offset_);
std::string tmp;
if (!section->Get(iniKey_, &tmp)) {
if (cb_.p) {
*target = cb_.p();
} else {
*target = Path(default_.p);
if (applyDefaultIfMissing) {
if (defaultCallback_.p) {
*target = defaultCallback_.p();
} else {
*target = Path(default_.p);
}
}
return false;
}
@@ -133,22 +147,22 @@ bool ConfigSetting::ReadFromIniSection(ConfigBlock *configBlock, const Section *
}
case Type::TYPE_CUSTOM_BUTTON:
{
ConfigCustomButton defaultCustomButton = cb_.customButton ? cb_.customButton() : default_.customButton;
ConfigCustomButton defaultCustomButton = defaultCallback_.customButton ? defaultCallback_.customButton() : default_.customButton;
ConfigCustomButton *customButton = ((ConfigCustomButton *)(owner + offset_));
if (!section->Get(iniKey_, &customButton->key)) {
if (!section->Get(iniKey_, &customButton->key) && applyDefaultIfMissing) {
customButton->key = defaultCustomButton.key;
}
if (!section->Get(ini2_, &customButton->image)) {
if (!section->Get(ini2_, &customButton->image) && applyDefaultIfMissing) {
customButton->image = defaultCustomButton.image;
}
if (!section->Get(ini3_, &customButton->shape)) {
if (!section->Get(ini3_, &customButton->shape) && applyDefaultIfMissing) {
customButton->shape = defaultCustomButton.shape;
}
if (!section->Get(ini4_, &customButton->toggle)) {
if (!section->Get(ini4_, &customButton->toggle) && applyDefaultIfMissing) {
customButton->toggle = defaultCustomButton.toggle;
}
if (!section->Get(ini5_, &customButton->repeat)) {
if (!section->Get(ini5_, &customButton->repeat) && applyDefaultIfMissing) {
customButton->repeat = defaultCustomButton.repeat;
}
return true;
@@ -224,7 +238,7 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
{
bool *ptr_b = (bool *)(owner + offset_);
const bool origValue = *ptr_b;
*ptr_b = cb_.b ? cb_.b() : default_.b;
*ptr_b = defaultCallback_.b ? defaultCallback_.b() : default_.b;
if (*ptr_b != origValue) {
if (log) {
INFO_LOG(Log::System, "Restored %.*s from %s to default %s", STR_VIEW(iniKey_),
@@ -239,7 +253,7 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
{
int *ptr_i = (int *)(owner + offset_);
const int origValue = *ptr_i;
*ptr_i = cb_.i ? cb_.i() : default_.i;
*ptr_i = defaultCallback_.i ? defaultCallback_.i() : default_.i;
if (*ptr_i != origValue) {
if (log) {
INFO_LOG(Log::System, "Restored %.*s from %d to default %d", STR_VIEW(iniKey_),
@@ -253,7 +267,7 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
{
uint32_t *ptr_u = (uint32_t *)(owner + offset_);
const uint32_t origValue = *ptr_u;
*ptr_u = cb_.u ? cb_.u() : default_.u;
*ptr_u = defaultCallback_.u ? defaultCallback_.u() : default_.u;
if (*ptr_u != origValue) {
if (log) {
INFO_LOG(Log::System, "Restored %.*s from %u to default %u", STR_VIEW(iniKey_),
@@ -267,7 +281,7 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
{
uint64_t *ptr_lu = (uint64_t *)(owner + offset_);
const uint64_t origValue = *ptr_lu;
*ptr_lu = cb_.lu ? cb_.lu() : default_.lu;
*ptr_lu = defaultCallback_.lu ? defaultCallback_.lu() : default_.lu;
if (*ptr_lu != origValue) {
if (log) {
INFO_LOG(Log::System, "Restored %.*s from %llu to default %llu", STR_VIEW(iniKey_),
@@ -281,7 +295,7 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
{
float *ptr_f = (float *)(owner + offset_);
const float origValue = *ptr_f;
*ptr_f = cb_.f ? cb_.f() : default_.f;
*ptr_f = defaultCallback_.f ? defaultCallback_.f() : default_.f;
if (*ptr_f != origValue) {
if (log) {
INFO_LOG(Log::System, "Restored %.*s from %f to default %f", STR_VIEW(iniKey_),
@@ -295,8 +309,8 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
{
std::string *ptr_s = (std::string *)(owner + offset_);
const std::string origValue = *ptr_s;
if (cb_.s) {
*ptr_s = cb_.s();
if (defaultCallback_.s) {
*ptr_s = defaultCallback_.s();
} else if (default_.s != nullptr) {
*ptr_s = default_.s;
} else {
@@ -320,14 +334,14 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
case Type::TYPE_TOUCH_POS:
{
ConfigTouchPos *ptr_touchPos = (ConfigTouchPos *)(owner + offset_);
*ptr_touchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos;
*ptr_touchPos = defaultCallback_.touchPos ? defaultCallback_.touchPos() : default_.touchPos;
break;
}
case Type::TYPE_PATH:
{
Path *ptr_path = (Path *)(owner + offset_);
if (cb_.p) {
*ptr_path = cb_.p();
if (defaultCallback_.p) {
*ptr_path = defaultCallback_.p();
break;
} else if (default_.p) {
*ptr_path = Path(default_.p);
@@ -339,7 +353,7 @@ bool ConfigSetting::RestoreToDefault(ConfigBlock *configBlock, bool log) const {
case Type::TYPE_CUSTOM_BUTTON:
{
ConfigCustomButton *ptr_customButton = (ConfigCustomButton *)(owner + offset_);
*ptr_customButton = cb_.customButton ? cb_.customButton() : default_.customButton;
*ptr_customButton = defaultCallback_.customButton ? defaultCallback_.customButton() : default_.customButton;
break;
}
default:
+19 -19
View File
@@ -69,43 +69,43 @@ struct ConfigSetting {
ConfigSetting(std::string_view ini, const char *owner, bool *v, bool def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_BOOL), flags_(flags), offset_((const char *)v - owner) {
cb_.b = nullptr;
defaultCallback_.b = nullptr;
default_.b = def;
}
ConfigSetting(std::string_view ini, const char *owner, int *v, int def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_INT), flags_(flags), offset_((const char *)v - owner) {
cb_.i = nullptr;
defaultCallback_.i = nullptr;
default_.i = def;
}
ConfigSetting(std::string_view ini, const char *owner, int *v, int def, std::string (*transTo)(int), int (*transFrom)(const std::string &), CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_INT), flags_(flags), translateTo_(transTo), translateFrom_(transFrom), offset_((const char *)v - owner) {
cb_.i = nullptr;
defaultCallback_.i = nullptr;
default_.i = def;
}
ConfigSetting(std::string_view ini, const char *owner, uint32_t *v, uint32_t def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_UINT32), flags_(flags), offset_((const char *)v - owner) {
cb_.u = nullptr;
defaultCallback_.u = nullptr;
default_.u = def;
}
ConfigSetting(std::string_view ini, const char *owner, uint64_t *v, uint64_t def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_UINT64), flags_(flags), offset_((const char *)v - owner) {
cb_.lu = nullptr;
defaultCallback_.lu = nullptr;
default_.lu = def;
}
ConfigSetting(std::string_view ini, const char *owner, float *v, float def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_FLOAT), flags_(flags), offset_((const char *)v - owner) {
cb_.f = nullptr;
defaultCallback_.f = nullptr;
default_.f = def;
}
ConfigSetting(std::string_view ini, const char *owner, std::string *v, const char *def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_STRING), flags_(flags), offset_((const char *)v - owner) {
cb_.s = nullptr;
defaultCallback_.s = nullptr;
default_.s = def;
}
@@ -116,58 +116,58 @@ struct ConfigSetting {
ConfigSetting(std::string_view ini, const char *owner, Path *v, const char *def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_PATH), flags_(flags), offset_((const char *)v - owner) {
cb_.p = nullptr;
defaultCallback_.p = nullptr;
default_.p = def;
}
ConfigSetting(const char *iniX, const char *iniY, const char *iniScale, const char *iniShow, const char *owner, ConfigTouchPos *v, ConfigTouchPos def, CfgFlag flags) noexcept
: iniKey_(iniX), ini2_(iniY), ini3_(iniScale), ini4_(iniShow), type_(Type::TYPE_TOUCH_POS), flags_(flags), offset_((const char *)v - owner) {
cb_.touchPos = nullptr;
defaultCallback_.touchPos = nullptr;
default_.touchPos = def;
}
ConfigSetting(const char *iniKey, const char *iniImage, const char *iniShape, const char *iniToggle, const char *iniRepeat, const char *owner, ConfigCustomButton *v, ConfigCustomButton def, CfgFlag flags) noexcept
: iniKey_(iniKey), ini2_(iniImage), ini3_(iniShape), ini4_(iniToggle), ini5_(iniRepeat), type_(Type::TYPE_CUSTOM_BUTTON), flags_(flags), offset_((const char *)v - owner) {
cb_.customButton = nullptr;
defaultCallback_.customButton = nullptr;
default_.customButton = def;
}
ConfigSetting(std::string_view ini, const char *owner, bool *v, BoolDefaultCallback def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_BOOL), flags_(flags), offset_((const char *)v - owner) {
cb_.b = def;
defaultCallback_.b = def;
}
ConfigSetting(std::string_view ini, const char *owner, int *v, IntDefaultCallback def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_INT), flags_(flags), offset_((const char *)v - owner) {
cb_.i = def;
defaultCallback_.i = def;
}
ConfigSetting(std::string_view ini, const char *owner, int *v, IntDefaultCallback def, std::string(*transTo)(int), int(*transFrom)(const std::string &), CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_INT), flags_(flags), offset_((const char *)v - owner), translateTo_(transTo), translateFrom_(transFrom) {
cb_.i = def;
defaultCallback_.i = def;
}
ConfigSetting(std::string_view ini, const char *owner, uint32_t *v, Uint32DefaultCallback def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_UINT32), flags_(flags), offset_((const char *)v - owner) {
cb_.u = def;
defaultCallback_.u = def;
}
ConfigSetting(std::string_view ini, const char *owner, float *v, FloatDefaultCallback def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_FLOAT), flags_(flags), offset_((const char *)v - owner) {
cb_.f = def;
defaultCallback_.f = def;
}
ConfigSetting(std::string_view ini, const char *owner, std::string *v, StringDefaultCallback def, CfgFlag flags) noexcept
: iniKey_(ini), type_(Type::TYPE_STRING), flags_(flags), offset_((const char *)v - owner) {
cb_.s = def;
defaultCallback_.s = def;
}
ConfigSetting(std::string_view iniX, const char *iniY, const char *iniScale, const char *iniShow, const char *owner, ConfigTouchPos *v, TouchPosDefaultCallback def, CfgFlag flags) noexcept
: iniKey_(iniX), ini2_(iniY), ini3_(iniScale), ini4_(iniShow), type_(Type::TYPE_TOUCH_POS), flags_(flags), offset_((const char *)v - owner) {
cb_.touchPos = def;
defaultCallback_.touchPos = def;
}
bool ReadFromIniSection(ConfigBlock *configBlock, const Section *section) const;
bool ReadFromIniSection(ConfigBlock *configBlock, const Section *section, bool applyDefaultIfMissing) const;
// Yes, this can be const because what's modified is not the ConfigSetting struct, but the value which is stored elsewhere.
// Should actually be called WriteToIni or something.
@@ -203,7 +203,7 @@ struct ConfigSetting {
private:
CfgFlag flags_;
DefaultValue default_{};
DefaultCallback cb_{};
DefaultCallback defaultCallback_{};
u32 offset_;
// We only support transform for ints.
+4 -1
View File
@@ -264,7 +264,10 @@ const std::map<std::string, std::pair<std::string, int>, std::less<>> &GetLangVa
IniFile mapping;
mapping.LoadFromVFS(g_VFS, "langregion.ini");
std::vector<std::string> keys;
mapping.GetKeys("LangRegionNames", keys);
Section *section = mapping.GetSection("LangRegionNames");
if (section) {
section->GetKeys(&keys);
}
const Section *langRegionNames = mapping.GetOrCreateSection("LangRegionNames");
const Section *systemLanguage = mapping.GetOrCreateSection("SystemLanguage");
+2 -2
View File
@@ -137,7 +137,7 @@ void LoadPostShaderInfo(Draw::DrawContext *draw, const std::vector<Path> &direct
continue;
}
if (section.Exists("Fragment") && section.Exists("Vertex") &&
if (section.HasKey("Fragment") && section.HasKey("Vertex") &&
(strncasecmp(shaderType.c_str(), "render", shaderType.size()) == 0 ||
strncasecmp(shaderType.c_str(), "StereoToMono", shaderType.size()) == 0)) {
// Valid shader!
@@ -197,7 +197,7 @@ void LoadPostShaderInfo(Draw::DrawContext *draw, const std::vector<Path> &direct
} else {
notVisible.push_back(info);
}
} else if (section.Exists("Compute") && strncasecmp(shaderType.c_str(), "texture", shaderType.size()) == 0) {
} else if (section.HasKey("Compute") && strncasecmp(shaderType.c_str(), "texture", shaderType.size()) == 0) {
// This is a texture shader.
TextureShaderInfo info{};
std::string temp;