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.
107 lines
2.3 KiB
C++
107 lines
2.3 KiB
C++
#include "launchersettings.hpp"
|
|
|
|
#include <QTextStream>
|
|
#include <QString>
|
|
#include <QRegExp>
|
|
#include <QMap>
|
|
|
|
#include <QDebug>
|
|
|
|
Config::LauncherSettings::LauncherSettings()
|
|
{
|
|
}
|
|
|
|
Config::LauncherSettings::~LauncherSettings()
|
|
{
|
|
}
|
|
|
|
QStringList Config::LauncherSettings::values(const QString &key, Qt::MatchFlags flags)
|
|
{
|
|
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;
|
|
}
|
|
|
|
QStringList Config::LauncherSettings::subKeys(const QString &key)
|
|
{
|
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
|
QStringList keys = settings.uniqueKeys();
|
|
|
|
qDebug() << keys;
|
|
|
|
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;
|
|
}
|
|
|
|
bool Config::LauncherSettings::writeFile(QTextStream &stream)
|
|
{
|
|
QString sectionPrefix;
|
|
QRegExp sectionRe("([^/]+)/(.+)$");
|
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
|
|
|
QMapIterator<QString, QString> i(settings);
|
|
i.toBack();
|
|
|
|
while (i.hasPrevious()) {
|
|
i.previous();
|
|
|
|
QString prefix;
|
|
QString key;
|
|
|
|
if (sectionRe.exactMatch(i.key())) {
|
|
prefix = sectionRe.cap(1);
|
|
key = sectionRe.cap(2);
|
|
}
|
|
|
|
// Get rid of legacy settings
|
|
if (key.contains(QChar('\\')))
|
|
continue;
|
|
|
|
if (key == QLatin1String("CurrentProfile"))
|
|
continue;
|
|
|
|
if (sectionPrefix != prefix) {
|
|
sectionPrefix = prefix;
|
|
stream << "\n[" << prefix << "]\n";
|
|
}
|
|
|
|
stream << key << "=" << i.value() << "\n";
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|