Browse Source

settings: fix migrate routine never working with empty settings

mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
17814d8003
2 changed files with 19 additions and 3 deletions
  1. +12
    -2
      code/espurna/migrate.cpp
  2. +7
    -1
      code/espurna/settings.h

+ 12
- 2
code/espurna/migrate.cpp View File

@ -27,13 +27,23 @@ void _cmpMoveIndexDown(const char * key, int offset = 0) {
// 3: based on Embedis, with board definitions 0-based
// 4: based on Embedis, no board definitions
int migrateVersion() {
const static auto version = getSetting("cfg", CFG_VERSION);
if (version == CFG_VERSION) {
return 0;
}
return version;
}
void migrate() {
// Update if not on the latest version
const auto version = getSetting("cfg", CFG_VERSION);
if (version == CFG_VERSION) return;
const auto version = migrateVersion();
setSetting("cfg", CFG_VERSION);
if (!version) return;
switch (version) {
// migrate old version with 1-based indices
case 2:


+ 7
- 1
code/espurna/settings.h View File

@ -225,9 +225,15 @@ void settingsProcessConfig(const settings_cfg_list_t& config, settings_filter_t
size_t settingsSize();
void migrate();
void settingsSetup();
// -----------------------------------------------------------------------------
// Configuration updates
// -----------------------------------------------------------------------------
int migrateVersion();
void migrate();
// -----------------------------------------------------------------------------
// Deprecated implementation
// -----------------------------------------------------------------------------


Loading…
Cancel
Save