mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.2 KiB
C++
101 lines
2.2 KiB
C++
12 years ago
|
#include "launchersettings.hpp"
|
||
|
|
||
12 years ago
|
#include <QTextStream>
|
||
|
#include <QString>
|
||
|
#include <QRegExp>
|
||
|
#include <QMap>
|
||
|
|
||
11 years ago
|
#include <QDebug>
|
||
|
|
||
11 years ago
|
Config::LauncherSettings::LauncherSettings()
|
||
12 years ago
|
{
|
||
|
}
|
||
|
|
||
11 years ago
|
Config::LauncherSettings::~LauncherSettings()
|
||
12 years ago
|
{
|
||
|
}
|
||
|
|
||
11 years ago
|
QStringList Config::LauncherSettings::values(const QString &key, Qt::MatchFlags flags)
|
||
12 years ago
|
{
|
||
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
||
|
|
||
|
if (flags == Qt::MatchExactly)
|
||
|
return settings.values(key);
|
||
|
|
||
|
QStringList result;
|
||
|
|
||
|
if (flags == Qt::MatchStartsWith) {
|
||
|
QStringList keys = settings.keys();
|
||
|
|
||
|
foreach (const QString ¤tKey, keys) {
|
||
|
if (currentKey.startsWith(key))
|
||
|
result.append(settings.value(currentKey));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
11 years ago
|
QStringList Config::LauncherSettings::subKeys(const QString &key)
|
||
12 years ago
|
{
|
||
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
||
12 years ago
|
QStringList keys = settings.uniqueKeys();
|
||
12 years ago
|
|
||
|
QRegExp keyRe("(.+)/");
|
||
|
|
||
|
QStringList result;
|
||
|
|
||
|
foreach (const QString ¤tKey, keys) {
|
||
|
if (keyRe.indexIn(currentKey) != -1) {
|
||
|
QString prefixedKey = keyRe.cap(1);
|
||
|
if(prefixedKey.startsWith(key)) {
|
||
|
QString subKey = prefixedKey.remove(key);
|
||
|
if (!subKey.isEmpty())
|
||
|
result.append(subKey);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
result.removeDuplicates();
|
||
|
return result;
|
||
|
}
|
||
12 years ago
|
|
||
11 years ago
|
bool Config::LauncherSettings::writeFile(QTextStream &stream)
|
||
12 years ago
|
{
|
||
|
QString sectionPrefix;
|
||
|
QRegExp sectionRe("([^/]+)/(.+)$");
|
||
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
||
|
|
||
|
QMapIterator<QString, QString> i(settings);
|
||
12 years ago
|
i.toBack();
|
||
|
|
||
|
while (i.hasPrevious()) {
|
||
|
i.previous();
|
||
12 years ago
|
|
||
|
QString prefix;
|
||
|
QString key;
|
||
|
|
||
|
if (sectionRe.exactMatch(i.key())) {
|
||
|
prefix = sectionRe.cap(1);
|
||
|
key = sectionRe.cap(2);
|
||
|
}
|
||
|
|
||
12 years ago
|
// Get rid of legacy settings
|
||
|
if (key.contains(QChar('\\')))
|
||
|
continue;
|
||
|
|
||
|
if (key == QLatin1String("CurrentProfile"))
|
||
|
continue;
|
||
|
|
||
12 years ago
|
if (sectionPrefix != prefix) {
|
||
|
sectionPrefix = prefix;
|
||
|
stream << "\n[" << prefix << "]\n";
|
||
|
}
|
||
|
|
||
|
stream << key << "=" << i.value() << "\n";
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
|
||
|
}
|