mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 01:36:44 +00:00
Fix for Bug #922: Launcher writing merged openmw.cfg files
This commit is contained in:
parent
19e5978a01
commit
da9b67b6d2
3 changed files with 63 additions and 15 deletions
|
@ -443,6 +443,32 @@ bool Launcher::MainDialog::setupGameSettings()
|
||||||
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
|
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
|
||||||
QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string());
|
QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string());
|
||||||
|
|
||||||
|
// Load the user config file first, separately
|
||||||
|
// So we can write it properly, uncontaminated
|
||||||
|
QString path = userPath + QLatin1String("openmw.cfg");
|
||||||
|
QFile file(path);
|
||||||
|
|
||||||
|
qDebug() << "Loading config file:" << qPrintable(path);
|
||||||
|
|
||||||
|
if (file.exists()) {
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("Error opening OpenMW configuration file"));
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setText(QObject::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()));
|
||||||
|
msgBox.exec();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QTextStream stream(&file);
|
||||||
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
mGameSettings.readUserFile(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now the rest
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
paths.append(userPath + QString("openmw.cfg"));
|
paths.append(userPath + QString("openmw.cfg"));
|
||||||
paths.append(QString("openmw.cfg"));
|
paths.append(QString("openmw.cfg"));
|
||||||
|
|
|
@ -90,6 +90,16 @@ QStringList Launcher::GameSettings::values(const QString &key, const QStringList
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launcher::GameSettings::readFile(QTextStream &stream)
|
bool Launcher::GameSettings::readFile(QTextStream &stream)
|
||||||
|
{
|
||||||
|
return readFile(stream, mSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Launcher::GameSettings::readUserFile(QTextStream &stream)
|
||||||
|
{
|
||||||
|
return readFile(stream, mUserSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Launcher::GameSettings::readFile(QTextStream &stream, QMap<QString, QString> &settings)
|
||||||
{
|
{
|
||||||
QMap<QString, QString> cache;
|
QMap<QString, QString> cache;
|
||||||
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
||||||
|
@ -107,10 +117,10 @@ bool Launcher::GameSettings::readFile(QTextStream &stream)
|
||||||
|
|
||||||
// Don't remove existing data entries
|
// Don't remove existing data entries
|
||||||
if (key != QLatin1String("data"))
|
if (key != QLatin1String("data"))
|
||||||
mSettings.remove(key);
|
settings.remove(key);
|
||||||
|
|
||||||
QStringList values = cache.values(key);
|
QStringList values = cache.values(key);
|
||||||
values.append(mSettings.values(key));
|
values.append(settings.values(key));
|
||||||
|
|
||||||
if (!values.contains(value)) {
|
if (!values.contains(value)) {
|
||||||
cache.insertMulti(key, value);
|
cache.insertMulti(key, value);
|
||||||
|
@ -118,23 +128,24 @@ bool Launcher::GameSettings::readFile(QTextStream &stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSettings.isEmpty()) {
|
if (settings.isEmpty()) {
|
||||||
mSettings = cache; // This is the first time we read a file
|
settings = cache; // This is the first time we read a file
|
||||||
validatePaths();
|
validatePaths();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge the changed keys with those which didn't
|
// Merge the changed keys with those which didn't
|
||||||
mSettings.unite(cache);
|
settings.unite(cache);
|
||||||
validatePaths();
|
validatePaths();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Launcher::GameSettings::writeFile(QTextStream &stream)
|
bool Launcher::GameSettings::writeFile(QTextStream &stream)
|
||||||
{
|
{
|
||||||
// Iterate in reverse order to preserve insertion order
|
// Iterate in reverse order to preserve insertion order
|
||||||
QMapIterator<QString, QString> i(mSettings);
|
QMapIterator<QString, QString> i(mUserSettings);
|
||||||
i.toBack();
|
i.toBack();
|
||||||
|
|
||||||
while (i.hasPrevious()) {
|
while (i.hasPrevious()) {
|
||||||
|
@ -162,7 +173,7 @@ bool Launcher::GameSettings::writeFile(QTextStream &stream)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList content = mSettings.values(QString("content"));
|
QStringList content = mUserSettings.values(QString("content"));
|
||||||
for (int i = content.count(); i--;) {
|
for (int i = content.count(); i--;) {
|
||||||
stream << "content=" << content.at(i) << "\n";
|
stream << "content=" << content.at(i) << "\n";
|
||||||
}
|
}
|
||||||
|
@ -172,14 +183,14 @@ bool Launcher::GameSettings::writeFile(QTextStream &stream)
|
||||||
|
|
||||||
bool Launcher::GameSettings::hasMaster()
|
bool Launcher::GameSettings::hasMaster()
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
QStringList content = mSettings.values(QString("content"));
|
QStringList content = mSettings.values(QString("content"));
|
||||||
for (int i = 0; i < content.count(); ++i) {
|
for (int i = 0; i < content.count(); ++i) {
|
||||||
if (content.at(i).contains(".omwgame") || content.at(i).contains(".esm")) {
|
if (content.at(i).contains(".omwgame") || content.at(i).contains(".esm")) {
|
||||||
result = true;
|
result = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace Launcher
|
||||||
inline void setValue(const QString &key, const QString &value)
|
inline void setValue(const QString &key, const QString &value)
|
||||||
{
|
{
|
||||||
mSettings.insert(key, value);
|
mSettings.insert(key, value);
|
||||||
|
mUserSettings.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setMultiValue(const QString &key, const QString &value)
|
inline void setMultiValue(const QString &key, const QString &value)
|
||||||
|
@ -38,11 +39,16 @@ namespace Launcher
|
||||||
QStringList values = mSettings.values(key);
|
QStringList values = mSettings.values(key);
|
||||||
if (!values.contains(value))
|
if (!values.contains(value))
|
||||||
mSettings.insertMulti(key, value);
|
mSettings.insertMulti(key, value);
|
||||||
|
|
||||||
|
values = mUserSettings.values(key);
|
||||||
|
if (!values.contains(value))
|
||||||
|
mUserSettings.insertMulti(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void remove(const QString &key)
|
inline void remove(const QString &key)
|
||||||
{
|
{
|
||||||
mSettings.remove(key);
|
mSettings.remove(key);
|
||||||
|
mUserSettings.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QStringList getDataDirs() { return mDataDirs; }
|
inline QStringList getDataDirs() { return mDataDirs; }
|
||||||
|
@ -52,7 +58,11 @@ namespace Launcher
|
||||||
bool hasMaster();
|
bool hasMaster();
|
||||||
|
|
||||||
QStringList values(const QString &key, const QStringList &defaultValues = QStringList());
|
QStringList values(const QString &key, const QStringList &defaultValues = QStringList());
|
||||||
|
|
||||||
bool readFile(QTextStream &stream);
|
bool readFile(QTextStream &stream);
|
||||||
|
bool readFile(QTextStream &stream, QMap<QString, QString> &settings);
|
||||||
|
bool readUserFile(QTextStream &stream);
|
||||||
|
|
||||||
bool writeFile(QTextStream &stream);
|
bool writeFile(QTextStream &stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -60,6 +70,7 @@ namespace Launcher
|
||||||
|
|
||||||
void validatePaths();
|
void validatePaths();
|
||||||
QMap<QString, QString> mSettings;
|
QMap<QString, QString> mSettings;
|
||||||
|
QMap<QString, QString> mUserSettings;
|
||||||
|
|
||||||
QStringList mDataDirs;
|
QStringList mDataDirs;
|
||||||
QString mDataLocal;
|
QString mDataLocal;
|
||||||
|
|
Loading…
Reference in a new issue