From 2131452fac11eaddf6ed0047dbca6f6ebb6f45bd Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 3 May 2011 15:09:21 +0200 Subject: [PATCH] Fixed file loading problem with relative paths when launcher wasn't run from cmdline --- apps/launcher/datafilespage.cpp | 2 +- apps/launcher/main.cpp | 19 +++++++++++++++++ apps/launcher/maindialog.cpp | 36 ++++++++++++++++++++------------- apps/launcher/playpage.cpp | 2 +- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index fa8375f3d..e4c20d1a3 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -309,7 +309,7 @@ void DataFilesPage::setupDataFiles(const QString &path) void DataFilesPage::setupConfig() { qDebug() << "setupConfig called"; - QString config = "launcher.cfg"; + QString config = "./launcher.cfg"; QFile file(config); if (!file.exists()) { diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 870d16f4c..d008c3a48 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "maindialog.hpp" @@ -6,6 +7,24 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + // Now we make sure the current dir is set to application path + QDir dir(QCoreApplication::applicationDirPath()); +#if defined(Q_OS_WIN) + if (dir.dirName().toLower() == "debug" || + dir.dirName().toLower() == "release") + { + dir.cdUp(); + } +#elif defined(Q_OS_MAC) + if (dir.dirName() == "MacOS") + { + dir.cdUp(); + dir.cdUp(); + dir.cdUp(); + } +#endif + + QDir::setCurrent(dir.absolutePath()); MainDialog dialog; return dialog.exec(); diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 7fa73e6a2..903cbe457 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -151,10 +151,8 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) void MainDialog::closeEvent(QCloseEvent *event) { qDebug() << "Close event"; - mDataFilesPage->writeConfig(); - mDataFilesPage->mLauncherConfig->sync(); - // Now write to the game config + // Now write all config files writeConfig(); event->accept(); @@ -162,6 +160,8 @@ void MainDialog::closeEvent(QCloseEvent *event) void MainDialog::play() { + // First do a write of all the configs, just to be sure + writeConfig(); #if Q_WS_WIN // Windows TODO: proper install path handling @@ -192,7 +192,7 @@ void MainDialog::play() void MainDialog::setupConfig() { // First we read the OpenMW config - QString config = "openmw.cfg"; + QString config = "./openmw.cfg"; QFile file(config); if (!file.exists()) { @@ -210,9 +210,13 @@ void MainDialog::setupConfig() void MainDialog::writeConfig() { + // Write the profiles + mDataFilesPage->writeConfig(); + mDataFilesPage->mLauncherConfig->sync(); + // Write to the openmw.cfg - QString dataPath = mGameConfig->value("data").toString(); - dataPath.append("/"); + //QString dataPath = mGameConfig->value("data").toString(); + //dataPath.append("/"); QStringList dataFiles = mDataFilesPage->selectedMasters(); dataFiles.append(mDataFilesPage->checkedPlugins()); @@ -220,7 +224,10 @@ 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 } @@ -248,16 +255,17 @@ void MainDialog::writeConfig() // Write the list of game files to the config foreach (const QString ¤tFile, dataFiles) { - QFileInfo dataFile = QFileInfo(QString(currentFile).prepend(dataPath)); + //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; - } + //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(); + qDebug() << "Writing done!"; } diff --git a/apps/launcher/playpage.cpp b/apps/launcher/playpage.cpp index 5f9949eb6..27e2f08bb 100644 --- a/apps/launcher/playpage.cpp +++ b/apps/launcher/playpage.cpp @@ -5,7 +5,7 @@ PlayPage::PlayPage(QWidget *parent) : QWidget(parent) { // Load the stylesheet - QFile file("launcher.qss"); + QFile file("./launcher.qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll());