mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-01 18:23:43 +01:00
Change how defaults work in the inifile reader (more flexible this way)
This commit is contained in:
1 parent
c98b7591d3
commit
14ddad5ce3
14 files changed
+266
-181
No files matched your search
+100
-25
@@ -15,25 +15,66 @@ bool ConfigSetting::perGame(void *ptr) {
|
||||
bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) const {
|
||||
switch (type_) {
|
||||
case Type::TYPE_BOOL:
|
||||
return section->Get(iniKey_, (bool *)(owner + offset_), cb_.b ? cb_.b() : default_.b);
|
||||
|
||||
{
|
||||
bool *target = (bool *)(owner + offset_);
|
||||
if (!section->Get(iniKey_, target)) {
|
||||
*target = cb_.b ? cb_.b() : default_.b;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_INT:
|
||||
{
|
||||
int *target = (int *)(owner + offset_);
|
||||
if (translateFrom_) {
|
||||
std::string value;
|
||||
if (section->Get(iniKey_, &value, nullptr)) {
|
||||
if (section->Get(iniKey_, &value)) {
|
||||
*((int *)(owner + offset_)) = translateFrom_(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return section->Get(iniKey_, (int *)(owner + offset_), cb_.i ? cb_.i() : default_.i);
|
||||
if (!section->Get(iniKey_, target)) {
|
||||
*target = cb_.i ? cb_.i() : default_.i;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_UINT32:
|
||||
return section->Get(iniKey_, (uint32_t *)(owner + offset_), cb_.u ? cb_.u() : default_.u);
|
||||
{
|
||||
uint32_t *target = (uint32_t *)(owner + offset_);
|
||||
if (!section->Get(iniKey_, target)) {
|
||||
*target = cb_.u ? cb_.u() : default_.u;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_UINT64:
|
||||
return section->Get(iniKey_, (uint64_t *)(owner + offset_), cb_.lu ? cb_.lu() : default_.lu);
|
||||
{
|
||||
uint64_t *target = (uint64_t *)(owner + offset_);
|
||||
if (!section->Get(iniKey_, target)) {
|
||||
*target = cb_.lu ? cb_.lu() : default_.lu;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_FLOAT:
|
||||
return section->Get(iniKey_, (float *)(owner + offset_), cb_.f ? cb_.f() : default_.f);
|
||||
{
|
||||
float *target = (float *)(owner + offset_);
|
||||
if (!section->Get(iniKey_, target)) {
|
||||
*target = cb_.f ? cb_.f() : default_.f;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_STRING:
|
||||
return section->Get(iniKey_, (std::string *)(owner + offset_), cb_.s ? cb_.s().c_str() : default_.s);
|
||||
{
|
||||
std::string *target = (std::string *)(owner + offset_);
|
||||
if (!section->Get(iniKey_, target)) {
|
||||
*target = cb_.s ? cb_.s().c_str() : default_.s;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_STRING_VECTOR:
|
||||
{
|
||||
// No support for callbacks for these yet. that's not an issue.
|
||||
@@ -49,11 +90,17 @@ bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) cons
|
||||
ConfigTouchPos defaultTouchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos;
|
||||
|
||||
ConfigTouchPos *touchPos = ((ConfigTouchPos *)(owner + offset_));
|
||||
section->Get(iniKey_, &touchPos->x, defaultTouchPos.x);
|
||||
section->Get(ini2_, &touchPos->y, defaultTouchPos.y);
|
||||
section->Get(ini3_, &touchPos->scale, defaultTouchPos.scale);
|
||||
if (ini4_) {
|
||||
section->Get(ini4_, &touchPos->show, defaultTouchPos.show);
|
||||
if (!section->Get(iniKey_, &touchPos->x)) {
|
||||
touchPos->x = defaultTouchPos.x;
|
||||
}
|
||||
if (!section->Get(ini2_, &touchPos->y)) {
|
||||
touchPos->y = defaultTouchPos.y;
|
||||
}
|
||||
if (!section->Get(ini3_, &touchPos->scale)) {
|
||||
touchPos->scale = defaultTouchPos.scale;
|
||||
}
|
||||
if (ini4_ && section->Get(ini4_, &touchPos->show)) {
|
||||
// do nothing, succeeded.
|
||||
} else {
|
||||
touchPos->show = defaultTouchPos.show;
|
||||
}
|
||||
@@ -61,24 +108,39 @@ bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) cons
|
||||
}
|
||||
case Type::TYPE_PATH:
|
||||
{
|
||||
Path *target = (Path *)(owner + offset_);
|
||||
std::string tmp;
|
||||
bool result = section->Get(iniKey_, &tmp, cb_.p ? cb_.p() : default_.p);
|
||||
if (result) {
|
||||
Path *path = (Path *)(owner + offset_);
|
||||
*path = Path(tmp);
|
||||
if (!section->Get(iniKey_, &tmp)) {
|
||||
if (cb_.p) {
|
||||
*target = cb_.p();
|
||||
} else {
|
||||
*target = Path(default_.p);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
*target = Path(tmp);
|
||||
return true;
|
||||
}
|
||||
case Type::TYPE_CUSTOM_BUTTON:
|
||||
{
|
||||
ConfigCustomButton defaultCustomButton = cb_.customButton ? cb_.customButton() : default_.customButton;
|
||||
|
||||
ConfigCustomButton *customButton = ((ConfigCustomButton *)(owner + offset_));
|
||||
section->Get(iniKey_, &customButton->key, defaultCustomButton.key);
|
||||
section->Get(ini2_, &customButton->image, defaultCustomButton.image);
|
||||
section->Get(ini3_, &customButton->shape, defaultCustomButton.shape);
|
||||
section->Get(ini4_, &customButton->toggle, defaultCustomButton.toggle);
|
||||
section->Get(ini5_, &customButton->repeat, defaultCustomButton.repeat);
|
||||
if (!section->Get(iniKey_, &customButton->key)) {
|
||||
customButton->key = defaultCustomButton.key;
|
||||
}
|
||||
if (!section->Get(ini2_, &customButton->image)) {
|
||||
customButton->image = defaultCustomButton.image;
|
||||
}
|
||||
if (!section->Get(ini3_, &customButton->shape)) {
|
||||
customButton->shape = defaultCustomButton.shape;
|
||||
}
|
||||
if (!section->Get(ini4_, &customButton->toggle)) {
|
||||
customButton->toggle = defaultCustomButton.toggle;
|
||||
}
|
||||
if (!section->Get(ini5_, &customButton->repeat)) {
|
||||
customButton->repeat = defaultCustomButton.repeat;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@@ -221,7 +283,13 @@ bool ConfigSetting::RestoreToDefault(const char *owner, bool log) const {
|
||||
{
|
||||
std::string *ptr_s = (std::string *)(owner + offset_);
|
||||
const std::string origValue = *ptr_s;
|
||||
*ptr_s = cb_.s ? cb_.s() : default_.s;
|
||||
if (cb_.s) {
|
||||
*ptr_s = cb_.s();
|
||||
} else if (default_.s != nullptr) {
|
||||
*ptr_s = default_.s;
|
||||
} else {
|
||||
*ptr_s = "";
|
||||
}
|
||||
if (*ptr_s != origValue) {
|
||||
if (log) {
|
||||
INFO_LOG(Log::System, "Restored %.*s from \"%s\" to default \"%s\"", STR_VIEW(iniKey_),
|
||||
@@ -246,7 +314,14 @@ bool ConfigSetting::RestoreToDefault(const char *owner, bool log) const {
|
||||
case Type::TYPE_PATH:
|
||||
{
|
||||
Path *ptr_path = (Path *)(owner + offset_);
|
||||
*ptr_path = Path(cb_.p ? cb_.p() : default_.p);
|
||||
if (cb_.p) {
|
||||
*ptr_path = cb_.p();
|
||||
break;
|
||||
} else if (default_.p) {
|
||||
*ptr_path = Path(default_.p);
|
||||
} else {
|
||||
ptr_path->clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Type::TYPE_CUSTOM_BUTTON:
|
||||
|
||||
Reference in new issue
Block a user