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,11 +128,10 @@ 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);
@ -142,12 +141,9 @@ void Config::writeAllConfigs(void) {
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 logHeap();
allChangesWritten = true;
}
} }
void Config::writeConfigFile(String filename) { void Config::writeConfigFile(String filename) {
@ -229,9 +225,11 @@ 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);
if (!configItems[index].value.equals(value)) {
configItems[index].value = String(value); configItems[index].value = String(value);
configItems[index].changed = true; configItems[index].changed = true;
} }
}
} }