Added Morrowind.ini detection logic

loadfix
pvdk 11 years ago
parent 8ea31e5050
commit 445f96434e

@ -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) void Wizard::ComponentSelectionPage::updateButton(QListWidgetItem *item)
{ {
if (field("installation.new").toBool() == true) if (field("installation.new").toBool() == true)

@ -19,7 +19,6 @@ namespace Wizard
private slots: private slots:
void updateButton(QListWidgetItem *item); void updateButton(QListWidgetItem *item);
void debugMe(QString &text);
private: private:
MainWizard *mWizard; MainWizard *mWizard;

@ -1,7 +1,10 @@
#include "existinginstallationpage.hpp" #include "existinginstallationpage.hpp"
#include <QDebug> #include <QDebug>
#include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo>
#include <QFile>
#include "mainwizard.hpp" #include "mainwizard.hpp"
@ -32,16 +35,14 @@ void Wizard::ExistingInstallationPage::on_browseButton_clicked()
if (!info.exists()) if (!info.exists())
return; return;
QDir dir(info.absolutePath()); QString path(QDir::toNativeSeparators(info.absolutePath()));
if (!dir.cdUp())
return; // Cannot move out of the Data Files directory
QString path = QDir::toNativeSeparators(dir.absolutePath());
QList<QListWidgetItem*> items = detectedList->findItems(path, Qt::MatchExactly); QList<QListWidgetItem*> items = detectedList->findItems(path, Qt::MatchExactly);
if (items.isEmpty()) if (items.isEmpty())
{ {
// Path is not yet in the list, add it // Path is not yet in the list, add it
mWizard->addInstallation(path);
QListWidgetItem *item = new QListWidgetItem(path); QListWidgetItem *item = new QListWidgetItem(path);
detectedList->addItem(item); detectedList->addItem(item);
detectedList->setCurrentItem(item); // Select it too 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 // Set the installation path manually, as registerField doesn't work
if (!text.isEmpty()) if (!text.isEmpty())
wizard()->setField("installation.path", text); mWizard->setField("installation.path", text);
} }
void Wizard::ExistingInstallationPage::initializePage() void Wizard::ExistingInstallationPage::initializePage()
{ {
QStringList paths = mWizard->mInstallations.keys(); QStringList paths(mWizard->mInstallations.keys());
if (paths.isEmpty()) if (paths.isEmpty())
return; 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("<br><b>Could not find Morrowind.ini</b><br><br> \
The Wizard needs to update settings in this file.<br><br> \
Press \"Browse...\" to specify the location manually.<br>"));
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 bool Wizard::ExistingInstallationPage::isComplete() const
{ {
if (detectedList->selectionModel()->hasSelection()) { if (detectedList->selectionModel()->hasSelection()) {
@ -86,14 +131,11 @@ bool Wizard::ExistingInstallationPage::isComplete() const
int Wizard::ExistingInstallationPage::nextId() const int Wizard::ExistingInstallationPage::nextId() const
{ {
QString path = field("installation.path").toString(); QString path(field("installation.path").toString());
if (path.isEmpty()) if (path.isEmpty())
return MainWizard::Page_ComponentSelection; return MainWizard::Page_ComponentSelection;
if (!mWizard->mInstallations.contains(path))
return MainWizard::Page_ComponentSelection;
if (mWizard->mInstallations[path]->hasMorrowind == true && if (mWizard->mInstallations[path]->hasMorrowind == true &&
mWizard->mInstallations[path]->hasTribunal == true && mWizard->mInstallations[path]->hasTribunal == true &&
mWizard->mInstallations[path]->hasBloodmoon == true) mWizard->mInstallations[path]->hasBloodmoon == true)

@ -17,6 +17,7 @@ namespace Wizard
int nextId() const; int nextId() const;
virtual bool isComplete() const; virtual bool isComplete() const;
virtual bool validatePage();
private slots: private slots:
void on_browseButton_clicked(); void on_browseButton_clicked();
@ -28,7 +29,6 @@ namespace Wizard
protected: protected:
void initializePage(); void initializePage();
}; };
} }

@ -31,7 +31,7 @@ bool Wizard::IniSettings::readFile(QTextStream &stream)
while (!stream.atEnd()) while (!stream.atEnd())
{ {
const QString &line = stream.readLine(); QString line(stream.readLine());
if (line.isEmpty() || line.startsWith(";")) if (line.isEmpty() || line.startsWith(";"))
continue; continue;

@ -1,7 +1,9 @@
#include "installationpage.hpp" #include "installationpage.hpp"
#include <QDebug> #include <QDebug>
#include <QFileInfo>
#include <QFile> #include <QFile>
#include <QDir>
#include <QTextCodec> #include <QTextCodec>
#include <QMessageBox> #include <QMessageBox>
@ -17,8 +19,8 @@ Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
void Wizard::InstallationPage::initializePage() void Wizard::InstallationPage::initializePage()
{ {
QString path = field("installation.path").toString(); QString path(field("installation.path").toString());
QStringList components = field("installation.components").toStringList(); QStringList components(field("installation.components").toStringList());
logTextEdit->append(QString("Installing to %1").arg(path)); logTextEdit->append(QString("Installing to %1").arg(path));
logTextEdit->append(QString("Installing %1.").arg(components.join(", "))); logTextEdit->append(QString("Installing %1.").arg(components.join(", ")));
@ -44,45 +46,48 @@ void Wizard::InstallationPage::initializePage()
installProgressBar->setValue(100); installProgressBar->setValue(100);
if (field("installation.new").toBool() == false)
setupSettings();
}
void Wizard::InstallationPage::setupSettings()
{
// Test settings // Test settings
IniSettings iniSettings; 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)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error opening OpenMW configuration file")); msgBox.setWindowTitle(tr("Error opening Morrowind configuration file"));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \ msgBox.setText(QObject::tr("<br><b>Could not open %0 for reading</b><br><br> \
Please make sure you have the right permissions \ Please make sure you have the right permissions \
and try again.<br>").arg(file.fileName())); and try again.<br>").arg(file.fileName()));
msgBox.exec(); msgBox.exec();
mWizard->close();
return;
} }
QTextStream stream(&file); QTextStream stream(&file);
QString language = field("installation.language").toString(); QString language(field("installation.language").toString());
if (language == QLatin1String("English") || if (language == QLatin1String("Polish")) {
language == QLatin1String("German") || stream.setCodec(QTextCodec::codecForName("windows-1250"));
language == QLatin1String("French"))
{
stream.setCodec(QTextCodec::codecForName("windows-1252"));
} }
else if (language == QLatin1String("Russian")) else if (language == QLatin1String("Russian")) {
{
stream.setCodec(QTextCodec::codecForName("windows-1251")); stream.setCodec(QTextCodec::codecForName("windows-1251"));
} }
else if (language == QLatin1String("Polish")) else {
{ stream.setCodec(QTextCodec::codecForName("windows-1252"));
stream.setCodec(QTextCodec::codecForName("windows-1250"));
} }
iniSettings.readFile(stream); iniSettings.readFile(stream);
qDebug() << iniSettings.value("Game Files/GameFile0"); qDebug() << iniSettings.value("Game Files/GameFile0");
} }
int Wizard::InstallationPage::nextId() const int Wizard::InstallationPage::nextId() const

@ -20,9 +20,12 @@ namespace Wizard
private: private:
MainWizard *mWizard; MainWizard *mWizard;
void setupSettings();
protected: protected:
void initializePage(); void initializePage();
}; };
} }

@ -8,7 +8,21 @@ Wizard::LanguageSelectionPage::LanguageSelectionPage(MainWizard *wizard) :
{ {
setupUi(this); 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 int Wizard::LanguageSelectionPage::nextId() const

@ -19,6 +19,9 @@ namespace Wizard
private: private:
MainWizard *mWizard; MainWizard *mWizard;
protected:
void initializePage();
}; };
} }

@ -38,21 +38,41 @@ void Wizard::MainWizard::setupInstallations()
{ {
// TODO: detect existing installations // TODO: detect existing installations
QStringList paths; 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("/home/pvdk/openmw/Data Files");
paths << QString("/usr/games/morrowind"); paths << QString("/usr/games/morrowind");
foreach (const QString &path, paths) foreach (const QString &path, paths)
{ {
Installation* install = new Installation(); addInstallation(path);
}
}
install->hasMorrowind = (findFiles(QString("Morrowind"), path)); void Wizard::MainWizard::addInstallation(const QString &path)
install->hasTribunal = true; {
install->hasBloodmoon = false; 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() void Wizard::MainWizard::setupPages()
@ -76,16 +96,13 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path)
if (!dir.exists()) if (!dir.exists())
return false; 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 // 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; return true;
} else { } else {
qDebug() << name << " doesn't exist!";
return false; return false;
} }

@ -16,6 +16,8 @@ namespace Wizard
bool hasMorrowind; bool hasMorrowind;
bool hasTribunal; bool hasTribunal;
bool hasBloodmoon; bool hasBloodmoon;
QString iniPath;
}; };
enum { enum {
@ -32,7 +34,9 @@ namespace Wizard
MainWizard(QWidget *parent = 0); 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<QString, Installation*> mInstallations; QMap<QString, Installation*> mInstallations;
private: private:

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>398</width> <width>396</width>
<height>298</height> <height>296</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -69,48 +69,13 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QComboBox" name="languagesComboBox"> <widget class="QComboBox" name="languageComboBox">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>250</width> <width>250</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<item>
<property name="text">
<string>English</string>
</property>
</item>
<item>
<property name="text">
<string>French</string>
</property>
</item>
<item>
<property name="text">
<string>Russian</string>
</property>
</item>
<item>
<property name="text">
<string>Polish</string>
</property>
</item>
<item>
<property name="text">
<string>Italian</string>
</property>
</item>
<item>
<property name="text">
<string>Spanish</string>
</property>
</item>
<item>
<property name="text">
<string>German</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>
@ -143,8 +108,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<resources> <resources/>
<include location="../../wizard/wizard.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

Loading…
Cancel
Save