mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 13:45:35 +00:00
Added error messages and fixed config file loading
This commit is contained in:
parent
8c04d00a50
commit
f219b0d47a
2 changed files with 45 additions and 17 deletions
|
@ -22,9 +22,6 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
|||
mPluginsProxyModel->setDynamicSortFilter(true);
|
||||
mPluginsProxyModel->setSourceModel(mPluginsModel);
|
||||
|
||||
// TODO: decide what to do with the selection model
|
||||
mPluginsSelectModel = new QItemSelectionModel(mPluginsModel);
|
||||
|
||||
QLabel *filterLabel = new QLabel(tr("Filter:"), this);
|
||||
LineEdit *filterLineEdit = new LineEdit(this);
|
||||
|
||||
|
@ -49,7 +46,6 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
|||
mMastersWidget->insertColumn(0);
|
||||
|
||||
mPluginsTable->setModel(mPluginsProxyModel);
|
||||
mPluginsTable->setSelectionModel(mPluginsSelectModel);
|
||||
mPluginsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
mPluginsTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
mPluginsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
|
|
|
@ -100,9 +100,18 @@ void MainDialog::createPages()
|
|||
// We can't use QSettings directly because it
|
||||
// does not support multiple keys with the same name
|
||||
QFile file(mGameConfig->fileName());
|
||||
qDebug() << "createPages gamefilename: " << mGameConfig->fileName();
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return; // File cannot be opened or created TODO: throw error
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error opening OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not open %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(); // File cannot be opened or created
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
|
@ -124,8 +133,20 @@ void MainDialog::createPages()
|
|||
dataDirs.append(dataLocal);
|
||||
}
|
||||
|
||||
// Now pass the datadirs on to the DataFilesPage
|
||||
mDataFilesPage->setupDataFiles(dataDirs, mGameConfig->value("fs-strict").toBool());
|
||||
if (!dataDirs.isEmpty()) {
|
||||
// Now pass the datadirs on to the DataFilesPage
|
||||
mDataFilesPage->setupDataFiles(dataDirs, mGameConfig->value("fs-strict").toBool());
|
||||
} else {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error reading OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not read the location of the data files</b><br><br> \
|
||||
Please make sure OpenMW is correctly configured and try again.<br>"));
|
||||
msgBox.exec();
|
||||
|
||||
QApplication::exit(); // No data or data-local entries in openmw.cfg
|
||||
}
|
||||
|
||||
// Set the combobox of the play page to imitate the comobox on the datafilespage
|
||||
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
||||
|
@ -192,7 +213,6 @@ void MainDialog::play()
|
|||
writeConfig();
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
// Windows TODO: proper install path handling
|
||||
QString game = "./openmw.exe";
|
||||
QFile file(game);
|
||||
#else
|
||||
|
@ -255,7 +275,7 @@ void MainDialog::setupConfig()
|
|||
|
||||
if (!file.exists()) {
|
||||
config = QString::fromStdString(Files::getPath(Files::Path_ConfigUser,
|
||||
"openmw", "launcher.cfg"));
|
||||
"openmw", "openmw.cfg"));
|
||||
}
|
||||
|
||||
file.setFileName(config); // Just for displaying information
|
||||
|
@ -286,12 +306,19 @@ void MainDialog::writeConfig()
|
|||
qDebug() << "Writing to openmw.cfg";
|
||||
|
||||
// Open the config as a QFile
|
||||
QFile file(mGameConfig->fileName());
|
||||
|
||||
QString cfgfile = "./openmw.cfg";
|
||||
|
||||
QFile file(cfgfile);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
// File cannot be opened or created TODO: throw error
|
||||
// File cannot be opened or created
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error opening OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not open %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
|
@ -309,7 +336,15 @@ void MainDialog::writeConfig()
|
|||
|
||||
// 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
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setText(tr("<br><b>Could not write to %0</b><br><br> \
|
||||
Please make sure you have the right permissions and try again.<br>").arg(file.fileName()));
|
||||
msgBox.exec();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
file.write(buffer);
|
||||
|
@ -317,15 +352,12 @@ void MainDialog::writeConfig()
|
|||
|
||||
// Write the list of game files to the config
|
||||
foreach (const QString ¤tFile, 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();
|
||||
|
|
Loading…
Reference in a new issue