1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 04:39:42 +00:00

Merge branch 'dont_notice_me_launcher_senpai' into 'master'

Don't load content entries from global and local configs

Closes #6441

See merge request OpenMW/openmw!2068
This commit is contained in:
AnyOldName3 2022-07-02 16:02:10 +00:00
commit 6609243c87
3 changed files with 38 additions and 44 deletions

View file

@ -334,54 +334,46 @@ bool Launcher::MainDialog::setupGameSettings()
QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()); QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str());
QString globalPath = QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str()); QString globalPath = QString::fromUtf8(mCfgMgr.getGlobalPath().string().c_str());
QFile file;
auto loadFile = [&] (const QString& path, bool(Config::GameSettings::*reader)(QTextStream&, bool), bool ignoreContent = false) -> std::optional<bool>
{
qDebug() << "Loading config file:" << path.toUtf8().constData();
file.setFileName(path);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
cfgError(tr("Error opening OpenMW configuration file"),
tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
return {};
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
(mGameSettings.*reader)(stream, ignoreContent);
file.close();
return true;
}
return false;
};
// Load the user config file first, separately // Load the user config file first, separately
// So we can write it properly, uncontaminated // So we can write it properly, uncontaminated
QString path = userPath + QLatin1String("openmw.cfg"); if(!loadFile(userPath + QLatin1String("openmw.cfg"), &Config::GameSettings::readUserFile))
QFile file(path);
qDebug() << "Loading config file:" << path.toUtf8().constData();
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
cfgError(tr("Error opening OpenMW configuration file"),
tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
return false; return false;
}
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
mGameSettings.readUserFile(stream);
file.close();
}
// Now the rest - priority: user > local > global // Now the rest - priority: user > local > global
QStringList paths; if(auto result = loadFile(localPath + QString("openmw.cfg"), &Config::GameSettings::readFile, true))
paths.append(globalPath + QString("openmw.cfg"));
paths.append(localPath + QString("openmw.cfg"));
paths.append(userPath + QString("openmw.cfg"));
for (const QString &path2 : paths)
{ {
qDebug() << "Loading config file:" << path2.toUtf8().constData(); // Load global if local wasn't found
if(!*result && !loadFile(globalPath + QString("openmw.cfg"), &Config::GameSettings::readFile, true))
file.setFileName(path2);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
cfgError(tr("Error opening OpenMW configuration file"),
tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName()));
return false; return false;
} }
QTextStream stream(&file); else
stream.setCodec(QTextCodec::codecForName("UTF-8")); return false;
if(!loadFile(userPath + QString("openmw.cfg"), &Config::GameSettings::readFile))
mGameSettings.readFile(stream); return false;
file.close();
}
}
return true; return true;
} }

View file

@ -80,17 +80,17 @@ QStringList Config::GameSettings::values(const QString &key, const QStringList &
return defaultValues; return defaultValues;
} }
bool Config::GameSettings::readFile(QTextStream &stream) bool Config::GameSettings::readFile(QTextStream &stream, bool ignoreContent)
{ {
return readFile(stream, mSettings); return readFile(stream, mSettings, ignoreContent);
} }
bool Config::GameSettings::readUserFile(QTextStream &stream) bool Config::GameSettings::readUserFile(QTextStream &stream, bool ignoreContent)
{ {
return readFile(stream, mUserSettings); return readFile(stream, mUserSettings, ignoreContent);
} }
bool Config::GameSettings::readFile(QTextStream &stream, QMultiMap<QString, QString> &settings) bool Config::GameSettings::readFile(QTextStream &stream, QMultiMap<QString, QString> &settings, bool ignoreContent)
{ {
QMultiMap<QString, QString> cache; QMultiMap<QString, QString> cache;
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
@ -139,6 +139,8 @@ bool Config::GameSettings::readFile(QTextStream &stream, QMultiMap<QString, QStr
} }
} }
} }
else if(ignoreContent && key == QLatin1String("content"))
continue;
QStringList values = cache.values(key); QStringList values = cache.values(key);
values.append(settings.values(key)); values.append(settings.values(key));

View file

@ -64,9 +64,9 @@ namespace Config
QStringList values(const QString &key, const QStringList &defaultValues = QStringList()) const; QStringList values(const QString &key, const QStringList &defaultValues = QStringList()) const;
bool readFile(QTextStream &stream); bool readFile(QTextStream &stream, bool ignoreContent = false);
bool readFile(QTextStream &stream, QMultiMap<QString, QString> &settings); bool readFile(QTextStream &stream, QMultiMap<QString, QString> &settings, bool ignoreContent = false);
bool readUserFile(QTextStream &stream); bool readUserFile(QTextStream &stream, bool ignoreContent = false);
bool writeFile(QTextStream &stream); bool writeFile(QTextStream &stream);
bool writeFileWithComments(QFile &file); bool writeFileWithComments(QFile &file);