forked from teamnwah/openmw-tes3coop
Added Morrowind.ini detection logic
This commit is contained in:
parent
8ea31e5050
commit
445f96434e
12 changed files with 137 additions and 92 deletions
|
@ -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)
|
||||
|
|
|
@ -19,7 +19,6 @@ namespace Wizard
|
|||
|
||||
private slots:
|
||||
void updateButton(QListWidgetItem *item);
|
||||
void debugMe(QString &text);
|
||||
|
||||
private:
|
||||
MainWizard *mWizard;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include "existinginstallationpage.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
|
||||
#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<QListWidgetItem*> 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("<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
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "installationpage.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QTextCodec>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
@ -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("<br><b>Could not open %0 for reading</b><br><br> \
|
||||
Please make sure you have the right permissions \
|
||||
and try again.<br>").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
|
||||
|
|
|
@ -20,9 +20,12 @@ namespace Wizard
|
|||
private:
|
||||
MainWizard *mWizard;
|
||||
|
||||
void setupSettings();
|
||||
|
||||
protected:
|
||||
void initializePage();
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,6 +19,9 @@ namespace Wizard
|
|||
|
||||
private:
|
||||
MainWizard *mWizard;
|
||||
|
||||
protected:
|
||||
void initializePage();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -38,23 +38,43 @@ 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();
|
||||
|
||||
install->hasMorrowind = (findFiles(QString("Morrowind"), path));
|
||||
install->hasTribunal = true;
|
||||
install->hasBloodmoon = false;
|
||||
|
||||
mInstallations.insert(QDir::toNativeSeparators(path), install);
|
||||
addInstallation(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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()
|
||||
{
|
||||
setPage(Page_Intro, new IntroPage(this));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<QString, Installation*> mInstallations;
|
||||
|
||||
private:
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>398</width>
|
||||
<height>298</height>
|
||||
<width>396</width>
|
||||
<height>296</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -69,48 +69,13 @@
|
|||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="languagesComboBox">
|
||||
<widget class="QComboBox" name="languageComboBox">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</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>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -143,8 +108,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../wizard/wizard.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in a new issue