From 445f96434e537613234f7641ebaf28e9e0708a6f Mon Sep 17 00:00:00 2001 From: pvdk Date: Tue, 24 Dec 2013 23:09:31 +0100 Subject: [PATCH] Added Morrowind.ini detection logic --- apps/wizard/componentselectionpage.cpp | 5 -- apps/wizard/componentselectionpage.hpp | 1 - apps/wizard/existinginstallationpage.cpp | 64 ++++++++++++++++++++---- apps/wizard/existinginstallationpage.hpp | 2 +- apps/wizard/inisettings.cpp | 2 +- apps/wizard/installationpage.cpp | 37 ++++++++------ apps/wizard/installationpage.hpp | 3 ++ apps/wizard/languageselectionpage.cpp | 16 +++++- apps/wizard/languageselectionpage.hpp | 3 ++ apps/wizard/mainwizard.cpp | 41 ++++++++++----- apps/wizard/mainwizard.hpp | 6 ++- files/ui/wizard/languageselectionpage.ui | 45 ++--------------- 12 files changed, 135 insertions(+), 90 deletions(-) diff --git a/apps/wizard/componentselectionpage.cpp b/apps/wizard/componentselectionpage.cpp index 50e6e8ef4..7d934fe84 100644 --- a/apps/wizard/componentselectionpage.cpp +++ b/apps/wizard/componentselectionpage.cpp @@ -21,11 +21,6 @@ Wizard::ComponentSelectionPage::ComponentSelectionPage(MainWizard *wizard) : } -void Wizard::ComponentSelectionPage::debugMe(QString &text) -{ - qDebug() << "Debug Me" << text; -} - void Wizard::ComponentSelectionPage::updateButton(QListWidgetItem *item) { if (field("installation.new").toBool() == true) diff --git a/apps/wizard/componentselectionpage.hpp b/apps/wizard/componentselectionpage.hpp index f5e955782..8b4c186d0 100644 --- a/apps/wizard/componentselectionpage.hpp +++ b/apps/wizard/componentselectionpage.hpp @@ -19,7 +19,6 @@ namespace Wizard private slots: void updateButton(QListWidgetItem *item); - void debugMe(QString &text); private: MainWizard *mWizard; diff --git a/apps/wizard/existinginstallationpage.cpp b/apps/wizard/existinginstallationpage.cpp index f9eb7c283..aeaa5a1f6 100644 --- a/apps/wizard/existinginstallationpage.cpp +++ b/apps/wizard/existinginstallationpage.cpp @@ -1,7 +1,10 @@ #include "existinginstallationpage.hpp" #include +#include #include +#include +#include #include "mainwizard.hpp" @@ -32,16 +35,14 @@ void Wizard::ExistingInstallationPage::on_browseButton_clicked() if (!info.exists()) return; - QDir dir(info.absolutePath()); - if (!dir.cdUp()) - return; // Cannot move out of the Data Files directory - - QString path = QDir::toNativeSeparators(dir.absolutePath()); + QString path(QDir::toNativeSeparators(info.absolutePath())); QList items = detectedList->findItems(path, Qt::MatchExactly); if (items.isEmpty()) { // Path is not yet in the list, add it + mWizard->addInstallation(path); + QListWidgetItem *item = new QListWidgetItem(path); detectedList->addItem(item); detectedList->setCurrentItem(item); // Select it too @@ -55,13 +56,13 @@ void Wizard::ExistingInstallationPage::textChanged(const QString &text) { // Set the installation path manually, as registerField doesn't work if (!text.isEmpty()) - wizard()->setField("installation.path", text); + mWizard->setField("installation.path", text); } void Wizard::ExistingInstallationPage::initializePage() { - QStringList paths = mWizard->mInstallations.keys(); + QStringList paths(mWizard->mInstallations.keys()); if (paths.isEmpty()) return; @@ -75,6 +76,50 @@ void Wizard::ExistingInstallationPage::initializePage() } +bool Wizard::ExistingInstallationPage::validatePage() +{ + // See if Morrowind.ini is detected, if not, ask the user + // It can be missing entirely + // Or failed to be detected due to the target being a symlink + + QString path(field("installation.path").toString()); + QFile file(mWizard->mInstallations[path]->iniPath); + + if (!file.exists()) { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error detecting Morrowind configuration")); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setText(QObject::tr("
Could not find Morrowind.ini

\ + The Wizard needs to update settings in this file.

\ + Press \"Browse...\" to specify the location manually.
")); + + QAbstractButton *browseButton = + msgBox.addButton(QObject::tr("B&rowse..."), QMessageBox::ActionRole); + + msgBox.exec(); + + QString iniFile; + if (msgBox.clickedButton() == browseButton) { + iniFile = QFileDialog::getOpenFileName( + NULL, + QObject::tr("Select configuration file"), + QDir::currentPath(), + QString(tr("Morrowind configuration file (*.ini)"))); + } + + if (iniFile.isEmpty()) { + return false; // Cancel was clicked; + } + + // A proper Morrowind.ini was selected, set it + QFileInfo info(iniFile); + mWizard->mInstallations[path]->iniPath = info.absoluteFilePath(); + } + + return true; +} + bool Wizard::ExistingInstallationPage::isComplete() const { if (detectedList->selectionModel()->hasSelection()) { @@ -86,14 +131,11 @@ bool Wizard::ExistingInstallationPage::isComplete() const int Wizard::ExistingInstallationPage::nextId() const { - QString path = field("installation.path").toString(); + QString path(field("installation.path").toString()); if (path.isEmpty()) return MainWizard::Page_ComponentSelection; - if (!mWizard->mInstallations.contains(path)) - return MainWizard::Page_ComponentSelection; - if (mWizard->mInstallations[path]->hasMorrowind == true && mWizard->mInstallations[path]->hasTribunal == true && mWizard->mInstallations[path]->hasBloodmoon == true) diff --git a/apps/wizard/existinginstallationpage.hpp b/apps/wizard/existinginstallationpage.hpp index 88d6913bc..d243bb868 100644 --- a/apps/wizard/existinginstallationpage.hpp +++ b/apps/wizard/existinginstallationpage.hpp @@ -17,6 +17,7 @@ namespace Wizard int nextId() const; virtual bool isComplete() const; + virtual bool validatePage(); private slots: void on_browseButton_clicked(); @@ -28,7 +29,6 @@ namespace Wizard protected: void initializePage(); - }; } diff --git a/apps/wizard/inisettings.cpp b/apps/wizard/inisettings.cpp index 8bdac5ad0..2c099acec 100644 --- a/apps/wizard/inisettings.cpp +++ b/apps/wizard/inisettings.cpp @@ -31,7 +31,7 @@ bool Wizard::IniSettings::readFile(QTextStream &stream) while (!stream.atEnd()) { - const QString &line = stream.readLine(); + QString line(stream.readLine()); if (line.isEmpty() || line.startsWith(";")) continue; diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index 5d943dbfa..e98d75ba4 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -1,7 +1,9 @@ #include "installationpage.hpp" #include +#include #include +#include #include #include @@ -17,8 +19,8 @@ Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : void Wizard::InstallationPage::initializePage() { - QString path = field("installation.path").toString(); - QStringList components = field("installation.components").toStringList(); + QString path(field("installation.path").toString()); + QStringList components(field("installation.components").toStringList()); logTextEdit->append(QString("Installing to %1").arg(path)); logTextEdit->append(QString("Installing %1.").arg(components.join(", "))); @@ -44,45 +46,48 @@ void Wizard::InstallationPage::initializePage() installProgressBar->setValue(100); + if (field("installation.new").toBool() == false) + setupSettings(); +} + +void Wizard::InstallationPage::setupSettings() +{ // Test settings IniSettings iniSettings; - QFile file("/home/pvdk/.wine/drive_c/Program Files/Bethesda Softworks/Morrowind/Morrowind.ini"); + QString path(field("installation.path").toString()); + QFile file(mWizard->mInstallations[path]->iniPath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error opening OpenMW configuration file")); + msgBox.setWindowTitle(tr("Error opening Morrowind configuration file")); msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setText(QObject::tr("
Could not open %0 for reading

\ Please make sure you have the right permissions \ and try again.
").arg(file.fileName())); msgBox.exec(); + mWizard->close(); + return; } QTextStream stream(&file); - QString language = field("installation.language").toString(); + QString language(field("installation.language").toString()); - if (language == QLatin1String("English") || - language == QLatin1String("German") || - language == QLatin1String("French")) - { - stream.setCodec(QTextCodec::codecForName("windows-1252")); + if (language == QLatin1String("Polish")) { + stream.setCodec(QTextCodec::codecForName("windows-1250")); } - else if (language == QLatin1String("Russian")) - { + else if (language == QLatin1String("Russian")) { stream.setCodec(QTextCodec::codecForName("windows-1251")); } - else if (language == QLatin1String("Polish")) - { - stream.setCodec(QTextCodec::codecForName("windows-1250")); + else { + stream.setCodec(QTextCodec::codecForName("windows-1252")); } iniSettings.readFile(stream); qDebug() << iniSettings.value("Game Files/GameFile0"); - } int Wizard::InstallationPage::nextId() const diff --git a/apps/wizard/installationpage.hpp b/apps/wizard/installationpage.hpp index cb206e225..b4fecc3ba 100644 --- a/apps/wizard/installationpage.hpp +++ b/apps/wizard/installationpage.hpp @@ -20,9 +20,12 @@ namespace Wizard private: MainWizard *mWizard; + void setupSettings(); + protected: void initializePage(); + }; } diff --git a/apps/wizard/languageselectionpage.cpp b/apps/wizard/languageselectionpage.cpp index 903ab175f..102a4c39a 100644 --- a/apps/wizard/languageselectionpage.cpp +++ b/apps/wizard/languageselectionpage.cpp @@ -8,7 +8,21 @@ Wizard::LanguageSelectionPage::LanguageSelectionPage(MainWizard *wizard) : { setupUi(this); - registerField(QLatin1String("installation.language"), languagesComboBox); + registerField(QLatin1String("installation.language"), languageComboBox); +} + +void Wizard::LanguageSelectionPage::initializePage() +{ + QStringList languages; + languages << "English" + << "French" + << "German" + << "Italian" + << "Polish" + << "Russian" + << "Spanish"; + + languageComboBox->addItems(languages); } int Wizard::LanguageSelectionPage::nextId() const diff --git a/apps/wizard/languageselectionpage.hpp b/apps/wizard/languageselectionpage.hpp index aa7a81ff1..3c17514f9 100644 --- a/apps/wizard/languageselectionpage.hpp +++ b/apps/wizard/languageselectionpage.hpp @@ -19,6 +19,9 @@ namespace Wizard private: MainWizard *mWizard; + + protected: + void initializePage(); }; } diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index e752d0455..9b133cee1 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -38,21 +38,41 @@ void Wizard::MainWizard::setupInstallations() { // TODO: detect existing installations QStringList paths; - paths << QString("/home/pvdk/.wine/drive_c/Program Files/Bethesda Softworks/Morrowind"); + paths << QString("/home/pvdk/.wine/drive_c/Program Files/Bethesda Softworks/Morrowind/Data Files"); paths << QString("/home/pvdk/openmw/Data Files"); paths << QString("/usr/games/morrowind"); foreach (const QString &path, paths) { - Installation* install = new Installation(); + addInstallation(path); + } + +} - install->hasMorrowind = (findFiles(QString("Morrowind"), path)); - install->hasTribunal = true; - install->hasBloodmoon = false; +void Wizard::MainWizard::addInstallation(const QString &path) +{ + qDebug() << "add installation in: " << path; + Installation* install = new Installation(); + + install->hasMorrowind = findFiles(QLatin1String("Morrowind"), path); + install->hasTribunal = findFiles(QLatin1String("Tribunal"), path); + install->hasBloodmoon = findFiles(QLatin1String("Bloodmoon"), path); - mInstallations.insert(QDir::toNativeSeparators(path), install); + // Try to autodetect the Morrowind.ini location + QDir dir(path); + QFile file(dir.filePath("Morrowind.ini")); + + // Try the parent directory + // In normal Morrowind installations that's where Morrowind.ini is + if (!file.exists()) { + dir.cdUp(); + file.setFileName(dir.filePath(QLatin1String("Morrowind.ini"))); } + if (file.exists()) + install->iniPath = file.fileName(); + + mInstallations.insert(QDir::toNativeSeparators(path), install); } void Wizard::MainWizard::setupPages() @@ -76,16 +96,13 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path) if (!dir.exists()) return false; - if (!dir.cd(QString("Data Files"))) - return false; - - qDebug() << "name: " << name + QString(".esm") << dir.absolutePath(); - // TODO: add MIME handling to make sure the files are real - if (dir.exists(name + QString(".esm")) && dir.exists(name + QString(".bsa"))) + if (dir.exists(name + QLatin1String(".esm")) && dir.exists(name + QLatin1String(".bsa"))) { + qDebug() << name << " exists!"; return true; } else { + qDebug() << name << " doesn't exist!"; return false; } diff --git a/apps/wizard/mainwizard.hpp b/apps/wizard/mainwizard.hpp index c6b541d35..c025c729e 100644 --- a/apps/wizard/mainwizard.hpp +++ b/apps/wizard/mainwizard.hpp @@ -16,6 +16,8 @@ namespace Wizard bool hasMorrowind; bool hasTribunal; bool hasBloodmoon; + + QString iniPath; }; enum { @@ -32,7 +34,9 @@ namespace Wizard MainWizard(QWidget *parent = 0); - static bool findFiles(const QString &name, const QString &path); + bool findFiles(const QString &name, const QString &path); + void addInstallation(const QString &path); + QMap mInstallations; private: diff --git a/files/ui/wizard/languageselectionpage.ui b/files/ui/wizard/languageselectionpage.ui index a76e3004b..fccd2aa42 100644 --- a/files/ui/wizard/languageselectionpage.ui +++ b/files/ui/wizard/languageselectionpage.ui @@ -6,8 +6,8 @@ 0 0 - 398 - 298 + 396 + 296 @@ -69,48 +69,13 @@ - + 250 0 - - - English - - - - - French - - - - - Russian - - - - - Polish - - - - - Italian - - - - - Spanish - - - - - German - - @@ -143,8 +108,6 @@ - - - +