Overhauled config clean-up code: Allow up to three "obsolete" sections. If more than three "obsolete" sections are found, all but the latest three are removed.
This commit is contained in:
parent
cabe1b3fca
commit
eb4ba3cbd7
@ -35,7 +35,7 @@
|
||||
#define VER_LAMEXP_MINOR_LO 3
|
||||
#define VER_LAMEXP_TYPE Alpha
|
||||
#define VER_LAMEXP_PATCH 1
|
||||
#define VER_LAMEXP_BUILD 1820
|
||||
#define VER_LAMEXP_BUILD 1821
|
||||
#define VER_LAMEXP_CONFG 1818
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -336,24 +336,41 @@ SettingsModel::SettingsModel(void)
|
||||
//Create settings
|
||||
QSettings *configFile = new QSettings(configPath, QSettings::IniFormat);
|
||||
const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_confg());
|
||||
QStringList childGroups =configFile->childGroups();
|
||||
const QStringList childGroups = configFile->childGroups();
|
||||
|
||||
//Clean-up settings
|
||||
while(!childGroups.isEmpty())
|
||||
if (!childGroups.empty())
|
||||
{
|
||||
QString current = childGroups.takeFirst();
|
||||
static const int MAX_GROUPS = 3;
|
||||
QRegExp filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$");
|
||||
if(filter.indexIn(current) >= 0)
|
||||
QStringList obsoleteGroups;
|
||||
for (QStringList::ConstIterator iter = childGroups.constBegin(); iter != childGroups.constEnd(); iter++)
|
||||
{
|
||||
bool ok = false;
|
||||
unsigned int temp = filter.cap(3).toUInt(&ok) + 10;
|
||||
if(ok && (temp >= lamexp_version_confg()))
|
||||
if (filter.indexIn(*iter) >= 0)
|
||||
{
|
||||
continue;
|
||||
quint32 temp[3] = { 0, 0, 0 };
|
||||
if (MUtils::regexp_parse_uint32(filter, temp, 3))
|
||||
{
|
||||
if ((temp[0] < lamexp_version_major()) || ((temp[0] == lamexp_version_major()) && ((temp[1] < lamexp_version_minor()) || ((temp[1] == lamexp_version_minor()) && (temp[2] < lamexp_version_confg())))))
|
||||
{
|
||||
obsoleteGroups.append(*iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (obsoleteGroups.count() > MAX_GROUPS)
|
||||
{
|
||||
qSort(obsoleteGroups);
|
||||
for (int i = 0; i < MAX_GROUPS; i++)
|
||||
{
|
||||
obsoleteGroups.removeLast();
|
||||
}
|
||||
for (QStringList::ConstIterator iter = obsoleteGroups.constBegin(); iter != obsoleteGroups.constEnd(); iter++)
|
||||
{
|
||||
qWarning("Deleting obsolete group from config: %s", MUTILS_UTF8(*iter));
|
||||
REMOVE_GROUP(configFile, (*iter));
|
||||
}
|
||||
}
|
||||
qWarning("Deleting obsolete group from config: %s", MUTILS_UTF8(current));
|
||||
REMOVE_GROUP(configFile, current);
|
||||
}
|
||||
|
||||
//Setup settings
|
||||
|
Loading…
Reference in New Issue
Block a user