Fixed writeAllConfigs.

Ignore changes if value does not change.
This commit is contained in:
Dirk Jahnke 2019-06-07 09:22:12 +02:00
parent 30a30b30de
commit f4fbd95183
1 changed files with 17 additions and 19 deletions

View File

@ -128,26 +128,22 @@ void Config::loadFile(const char *filename, const char * const sectionConfigItem
} }
void Config::writeAllConfigs(void) { void Config::writeAllConfigs(void) {
boolean allChangesWritten = false;
logHeap(); logHeap();
debug.out(F("Write all changed configs, checking ")); debug.out(numberOfConfigItems); debug.outln(F(" items."));
while (!allChangesWritten) { for (int i=0; i<numberOfConfigItems; ++i) {
for (int i=0; i<numberOfConfigItems; ++i) { debug.out("["); debug.out(i); debug.out("] ");
debug.out(configItems[i].section); debug.out(configItems[i].section);
debug.out("."); debug.out(".");
debug.out(configItems[i].name); debug.out(configItems[i].name);
debug.out("("); debug.out("(");
debug.out(configItems[i].changed ? "changed" : "-"); debug.out(configItems[i].changed ? "changed" : "-");
debug.out(")="); debug.out(")=");
debug.outln(configItems[i].value); debug.outln(configItems[i].value);
if (configItems[i].changed) { if (configItems[i].changed) {
writeConfigFile(configItems[i].section); writeConfigFile(configItems[i].section);
break; // leave for-loop and restart search for changes
}
} }
// no further changes found, we are done
allChangesWritten = true;
} }
logHeap();
} }
void Config::writeConfigFile(String filename) { void Config::writeConfigFile(String filename) {
@ -229,8 +225,10 @@ void Config::setString(String key, String value) {
debug.out(F("ERROR: Tried to set new value, but cannot find config item ")); debug.outln(key); debug.out(F("ERROR: Tried to set new value, but cannot find config item ")); debug.outln(key);
} else { } else {
// debug.outln(configItems[index].value); // debug.outln(configItems[index].value);
configItems[index].value = String(value); if (!configItems[index].value.equals(value)) {
configItems[index].changed = true; configItems[index].value = String(value);
configItems[index].changed = true;
}
} }
} }