From 9f8db9c010ea72a1b0d832071de4990796815fa7 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sat, 5 Mar 2011 17:43:57 +0100 Subject: [PATCH] Added code to remove obsolete/unknown group's from the config file, so information left from previous versions will not flood the config file. --- src/Config.h | 2 +- src/Model_Settings.cpp | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Config.h b/src/Config.h index d7a7fc11..7860ca8f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 1 -#define VER_LAMEXP_BUILD 350 +#define VER_LAMEXP_BUILD 351 #define VER_LAMEXP_SUFFIX Beta-6 /* diff --git a/src/Model_Settings.cpp b/src/Model_Settings.cpp index c1914605..dbbbb72b 100644 --- a/src/Model_Settings.cpp +++ b/src/Model_Settings.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////// @@ -58,6 +59,7 @@ void SettingsModel::OPT(unsigned int value) { m_settings->setValue(g_settingsId_ unsigned int SettingsModel::OPT##Default(void) { return DEF; } #define MAKE_ID(DEC,STR) static const char *g_settingsId_##DEC = STR +#define REMOVE_GROUP(OBJ,ID) OBJ->beginGroup(ID); OBJ->remove(""); OBJ->endGroup(); //////////////////////////////////////////////////////////// //Constants @@ -134,7 +136,27 @@ SettingsModel::SettingsModel(void) } m_settings = new QSettings(configPath, QSettings::IniFormat); - m_settings->beginGroup(QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build())); + const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()); + QStringList childGroups = m_settings->childGroups(); + + while(!childGroups.isEmpty()) + { + QString current = childGroups.takeFirst(); + QRegExp filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$"); + if(filter.indexIn(current) >= 0) + { + bool ok = false; + unsigned int temp = filter.cap(3).toUInt(&ok) + 10; + if(ok && (temp >= lamexp_version_build())) + { + continue; + } + } + qWarning("Deleting obsolete group from config: %s", current.toUtf8().constData()); + REMOVE_GROUP(m_settings, current); + } + + m_settings->beginGroup(groupKey); m_settings->setValue(g_settingsId_versionNumber, QApplication::applicationVersion()); m_settings->sync(); }