Plugins and masters from the current profile are written to openmw.cfg now

pull/21/head
Pieter van der Kloet 14 years ago
parent a68be84b7f
commit 7bf21262a1

@ -369,10 +369,10 @@ void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const
QString masterstr;
// Create a QStringList containing all the masters
const QList<QTableWidgetItem *> selectedMasters = mMastersWidget->selectedItems();
const QStringList masterList = selectedMasters();
foreach (const QTableWidgetItem *item, selectedMasters) {
masters.append(item->data(Qt::DisplayRole).toString());
foreach (const QString &currentMaster, masterList) {
masters.append(currentMaster);
}
masters.sort();
@ -488,6 +488,18 @@ void DataFilesPage::setCheckstate(QModelIndex index)
}
}
const QStringList DataFilesPage::selectedMasters()
{
QStringList masters;
const QList<QTableWidgetItem *> selectedMasters = mMastersWidget->selectedItems();
foreach (const QTableWidgetItem *item, selectedMasters) {
masters.append(item->data(Qt::DisplayRole).toString());
}
return masters;
}
const QStringList DataFilesPage::checkedPlugins()
{
QStringList checkedItems;
@ -611,12 +623,12 @@ void DataFilesPage::writeConfig(QString profile)
mLauncherConfig->remove(""); // Clear the subgroup
// First write the masters to the config
const QList<QTableWidgetItem *> selectedMasters = mMastersWidget->selectedItems();
const QStringList masterList = selectedMasters();
// We don't use foreach because we need i
for (int i = 0; i < selectedMasters.size(); ++i) {
const QTableWidgetItem *item = selectedMasters.at(i);
mLauncherConfig->setValue(QString("Master%0").arg(i), item->data(Qt::DisplayRole).toString());
for (int i = 0; i < masterList.size(); ++i) {
const QString master = masterList.at(i);
mLauncherConfig->setValue(QString("Master%0").arg(i), master);
}
// Now write all checked plugins

@ -27,6 +27,7 @@ public:
QSettings *mLauncherConfig;
const QStringList checkedPlugins();
const QStringList selectedMasters();
void setupConfig();
void readConfig();
void writeConfig(QString profile = QString());

@ -140,6 +140,58 @@ void MainDialog::closeEvent(QCloseEvent *event)
qDebug() << "Close event";
mDataFilesPage->writeConfig();
mDataFilesPage->mLauncherConfig->sync();
// Write to the openmw.cfg
QString dataPath = mGameConfig->value("data").toString();
dataPath.append("/");
QStringList dataFiles = mDataFilesPage->selectedMasters();
dataFiles.append(mDataFilesPage->checkedPlugins());
qDebug() << "Writing to openmw.cfg";
// Open the config as a QFile
QFile file(mGameConfig->fileName());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// File cannot be opened or created TODO: throw error
}
QTextStream in(&file);
QByteArray buffer;
// Remove all previous master/plugin entries from config
while (!in.atEnd()) {
QString line = in.readLine();
if (!line.contains("master") && !line.contains("plugin")) {
buffer += line += "\n";
}
}
file.close();
// Now we write back the other config entries
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
// File cannot be opened or created TODO: throw error
}
file.write(buffer);
QTextStream out(&file);
// Write the list of game files to the config
foreach (const QString &currentFile, dataFiles) {
QFileInfo dataFile = QFileInfo(QString(currentFile).prepend(dataPath));
if (dataFile.exists()) {
if (currentFile.endsWith(QString(".esm"), Qt::CaseInsensitive)) {
out << "master=" << currentFile << endl;
} else if (currentFile.endsWith(QString(".esp"), Qt::CaseInsensitive)) {
out << "plugin=" << currentFile << endl;
}
}
}
file.close();
event->accept();
}

Loading…
Cancel
Save