Did some cleanup work on the unshield thread: more code re-use

loadfix
pvdk 11 years ago
parent 3fd88aca59
commit 2736527e5a

@ -8,7 +8,6 @@
#include "mainwizard.hpp" #include "mainwizard.hpp"
#include "inisettings.hpp" #include "inisettings.hpp"
#include "unshield/unshieldworker.hpp"
Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
QWizardPage(wizard), QWizardPage(wizard),
@ -58,9 +57,10 @@ void Wizard::InstallationPage::startInstallation()
QThread *thread = new QThread(); QThread *thread = new QThread();
mUnshield = new UnshieldWorker(); mUnshield = new UnshieldWorker();
mUnshield->moveToThread(thread); mUnshield->moveToThread(thread);
qRegisterMetaType<Wizard::Component>("Wizard::Component");
connect(thread, SIGNAL(started()), connect(thread, SIGNAL(started()),
mUnshield, SLOT(extract())); mUnshield, SLOT(extract()));
@ -88,30 +88,30 @@ void Wizard::InstallationPage::startInstallation()
connect(mUnshield, SIGNAL(progressChanged(int)), connect(mUnshield, SIGNAL(progressChanged(int)),
installProgressBar, SLOT(setValue(int)), Qt::QueuedConnection); installProgressBar, SLOT(setValue(int)), Qt::QueuedConnection);
connect(mUnshield, SIGNAL(requestFileDialog(QString)), connect(mUnshield, SIGNAL(requestFileDialog(Wizard::Component)),
this, SLOT(showFileDialog(QString)), Qt::QueuedConnection); this, SLOT(showFileDialog(Wizard::Component)), Qt::QueuedConnection);
if (field("installation.new").toBool() == true) if (field("installation.new").toBool() == true)
{ {
// Always install Morrowind // Always install Morrowind
mUnshield->setInstallMorrowind(true); mUnshield->setInstallComponent(Wizard::Component_Morrowind, true);
if (components.contains(QLatin1String("Tribunal"))) if (components.contains(QLatin1String("Tribunal")))
mUnshield->setInstallTribunal(true); mUnshield->setInstallComponent(Wizard::Component_Tribunal, true);
if (components.contains(QLatin1String("Bloodmoon"))) if (components.contains(QLatin1String("Bloodmoon")))
mUnshield->setInstallBloodmoon(true); mUnshield->setInstallComponent(Wizard::Component_Bloodmoon, true);
} else { } else {
// Morrowind should already be installed // Morrowind should already be installed
mUnshield->setInstallMorrowind(false); mUnshield->setInstallComponent(Wizard::Component_Morrowind, false);
if (components.contains(QLatin1String("Tribunal")) if (components.contains(QLatin1String("Tribunal"))
&& mWizard->mInstallations[path]->hasTribunal == false) && !mWizard->mInstallations[path]->hasTribunal)
mUnshield->setInstallTribunal(true); mUnshield->setInstallComponent(Wizard::Component_Tribunal, true);
if (components.contains(QLatin1String("Bloodmoon")) if (components.contains(QLatin1String("Bloodmoon"))
&& mWizard->mInstallations[path]->hasBloodmoon == false) && !mWizard->mInstallations[path]->hasBloodmoon)
mUnshield->setInstallBloodmoon(true); mUnshield->setInstallComponent(Wizard::Component_Bloodmoon, true);
// Set the location of the Morrowind.ini to update // Set the location of the Morrowind.ini to update
mUnshield->setIniPath(mWizard->mInstallations[path]->iniPath); mUnshield->setIniPath(mWizard->mInstallations[path]->iniPath);
@ -136,38 +136,21 @@ void Wizard::InstallationPage::startInstallation()
thread->start(); thread->start();
} }
void Wizard::InstallationPage::showFileDialog(const QString &component) void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
{ {
QString fileName; QString fileName = QFileDialog::getOpenFileName(
if (field("installation.new").toBool() == true)
{
fileName = QFileDialog::getOpenFileName(
this, this,
tr("Select %0 installation file").arg(component), tr("Select installation file"),
QDir::rootPath(), QDir::rootPath(),
tr("InstallShield header files (*.hdr)")); tr("InstallShield header files (*.hdr)"));
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
qDebug() << "Cancel was clicked!"; qDebug() << "Cancel was clicked!";
return; return;
}
QFileInfo info(fileName);
if (component == QLatin1String("Morrowind"))
{
mUnshield->setMorrowindPath(info.absolutePath());
}
else if (component == QLatin1String("Tribunal"))
{
mUnshield->setTribunalPath(info.absolutePath());
}
else if (component == QLatin1String("Bloodmoon"))
{
mUnshield->setBloodmoonPath(info.absolutePath());
}
} }
QFileInfo info(fileName);
mUnshield->setComponentPath(component, info.absolutePath());
} }
void Wizard::InstallationPage::installationFinished() void Wizard::InstallationPage::installationFinished()

@ -3,6 +3,7 @@
#include <QWizardPage> #include <QWizardPage>
#include "unshield/unshieldworker.hpp"
#include "ui_installationpage.h" #include "ui_installationpage.h"
#include "inisettings.hpp" #include "inisettings.hpp"
@ -33,7 +34,7 @@ namespace Wizard
void startInstallation(); void startInstallation();
private slots: private slots:
void showFileDialog(const QString &component); void showFileDialog(Wizard::Component component);
void installationFinished(); void installationFinished();
void installationError(const QString &text); void installationError(const QString &text);

@ -14,8 +14,6 @@
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
#include <qmath.h>
Wizard::UnshieldWorker::UnshieldWorker(QObject *parent) : Wizard::UnshieldWorker::UnshieldWorker(QObject *parent) :
QObject(parent), QObject(parent),
mIniSettings() mIniSettings()
@ -46,81 +44,106 @@ Wizard::UnshieldWorker::~UnshieldWorker()
} }
void Wizard::UnshieldWorker::setInstallMorrowind(bool install) void Wizard::UnshieldWorker::setInstallComponent(Wizard::Component component, bool install)
{ {
QWriteLocker writeLock(&mLock); QWriteLocker writeLock(&mLock);
mInstallMorrowind = install; switch (component) {
}
void Wizard::UnshieldWorker::setInstallTribunal(bool install) case Wizard::Component_Morrowind:
{ mInstallMorrowind = install;
QWriteLocker writeLock(&mLock); break;
mInstallTribunal = install; case Wizard::Component_Tribunal:
} mInstallTribunal = install;
break;
void Wizard::UnshieldWorker::setInstallBloodmoon(bool install) case Wizard::Component_Bloodmoon:
{ mInstallBloodmoon = install;
QWriteLocker writeLock(&mLock); break;
mInstallBloodmoon = install; }
} }
bool Wizard::UnshieldWorker::getInstallMorrowind() bool Wizard::UnshieldWorker::getInstallComponent(Component component)
{ {
QReadLocker readLock(&mLock); QReadLocker readLock(&mLock);
return mInstallMorrowind; switch (component) {
}
bool Wizard::UnshieldWorker::getInstallTribunal() case Wizard::Component_Morrowind:
{ return mInstallMorrowind;
QReadLocker readLock(&mLock); case Wizard::Component_Tribunal:
return mInstallTribunal; return mInstallTribunal;
} case Wizard::Component_Bloodmoon:
return mInstallBloodmoon;
}
bool Wizard::UnshieldWorker::getInstallBloodmoon() return false;
{
QReadLocker readLock(&mLock);
return mInstallBloodmoon;
} }
void Wizard::UnshieldWorker::setMorrowindPath(const QString &path) void Wizard::UnshieldWorker::setComponentPath(Wizard::Component component, const QString &path)
{ {
QWriteLocker writeLock(&mLock); QWriteLocker writeLock(&mLock);
mMorrowindPath = path; switch (component) {
mWait.wakeAll();
case Wizard::Component_Morrowind:
mMorrowindPath = path;
break;
case Wizard::Component_Tribunal:
mTribunalPath = path;
break;
case Wizard::Component_Bloodmoon:
mBloodmoonPath = path;
break;
}
mWait.wakeAll();
} }
void Wizard::UnshieldWorker::setTribunalPath(const QString &path) QString Wizard::UnshieldWorker::getComponentPath(Component component)
{ {
QWriteLocker writeLock(&mLock); QReadLocker readLock(&mLock);
mTribunalPath = path; switch (component) {
mWait.wakeAll();
case Wizard::Component_Morrowind:
return mMorrowindPath;
case Wizard::Component_Tribunal:
return mTribunalPath;
case Wizard::Component_Bloodmoon:
return mBloodmoonPath;
}
return QString();
} }
void Wizard::UnshieldWorker::setBloodmoonPath(const QString &path) void Wizard::UnshieldWorker::setComponentDone(Component component, bool done)
{ {
QWriteLocker writeLock(&mLock); QWriteLocker writeLock(&mLock);
mBloodmoonPath = path; switch (component) {
mWait.wakeAll();
case Wizard::Component_Morrowind:
mMorrowindDone = done;
break;
case Wizard::Component_Tribunal:
mTribunalDone = done;
break;
case Wizard::Component_Bloodmoon:
mBloodmoonDone = done;
break;
}
} }
QString Wizard::UnshieldWorker::getMorrowindPath() bool Wizard::UnshieldWorker::getComponentDone(Component component)
{ {
QReadLocker readLock(&mLock); QReadLocker readLock(&mLock);
return mMorrowindPath; switch (component)
} {
QString Wizard::UnshieldWorker::getTribunalPath() case Wizard::Component_Morrowind:
{ return mMorrowindDone;
QReadLocker readLock(&mLock); case Wizard::Component_Tribunal:
return mTribunalPath; return mTribunalDone;
} case Wizard::Component_Bloodmoon:
return mBloodmoonDone;
}
QString Wizard::UnshieldWorker::getBloodmoonPath() return false;
{
QReadLocker readLock(&mLock);
return mBloodmoonPath;
} }
void Wizard::UnshieldWorker::setPath(const QString &path) void Wizard::UnshieldWorker::setPath(const QString &path)
@ -153,42 +176,6 @@ void Wizard::UnshieldWorker::setIniCodec(QTextCodec *codec)
mIniCodec = codec; mIniCodec = codec;
} }
void Wizard::UnshieldWorker::setMorrowindDone(bool done)
{
QWriteLocker writeLock(&mLock);
mMorrowindDone = done;
}
void Wizard::UnshieldWorker::setTribunalDone(bool done)
{
QWriteLocker writeLock(&mLock);
mTribunalDone = done;
}
void Wizard::UnshieldWorker::setBloodmoonDone(bool done)
{
QWriteLocker writeLock(&mLock);
mBloodmoonDone = done;
}
bool Wizard::UnshieldWorker::getMorrowindDone()
{
QReadLocker readLock(&mLock);
return mMorrowindDone;
}
bool Wizard::UnshieldWorker::getTribunalDone()
{
QReadLocker readLock(&mLock);
return mTribunalDone;
}
bool Wizard::UnshieldWorker::getBloodmoonDone()
{
QReadLocker readLock(&mLock);
return mBloodmoonDone;
}
void Wizard::UnshieldWorker::setupSettings() void Wizard::UnshieldWorker::setupSettings()
{ {
// Create Morrowind.ini settings map // Create Morrowind.ini settings map
@ -287,8 +274,7 @@ bool Wizard::UnshieldWorker::copyDirectory(const QString &source, const QString
if (info.isDir()) { if (info.isDir()) {
result = moveDirectory(info.absoluteFilePath(), destDir.absolutePath() + relativePath); result = moveDirectory(info.absoluteFilePath(), destDir.absolutePath() + relativePath);
} else { } else {
qDebug() << "moving: " << info.absoluteFilePath() << " to: " << destDir.absolutePath() + relativePath; // qDebug() << "moving: " << info.absoluteFilePath() << " to: " << destDir.absolutePath() + relativePath;
result = moveFile(info.absoluteFilePath(), destDir.absolutePath() + relativePath); result = moveFile(info.absoluteFilePath(), destDir.absolutePath() + relativePath);
} }
} }
@ -346,36 +332,35 @@ void Wizard::UnshieldWorker::installDirectories(const QString &source)
} }
void Wizard::UnshieldWorker::extract() void Wizard::UnshieldWorker::extract()
{ {
qDebug() << "extract!"; qDebug() << "extract!";
QDir disk; QDir disk;
if (getInstallMorrowind()) if (getInstallComponent(Wizard::Component_Morrowind))
{ {
while (!getMorrowindDone()) while (!getComponentDone(Wizard::Component_Morrowind))
{ {
if (getMorrowindPath().isEmpty()) { if (getComponentPath(Wizard::Component_Morrowind).isEmpty()) {
qDebug() << "request file dialog"; qDebug() << "request file dialog";
QReadLocker readLock(&mLock); QReadLocker readLock(&mLock);
emit requestFileDialog(QLatin1String("Morrowind")); emit requestFileDialog(Wizard::Component_Morrowind);
mWait.wait(&mLock); mWait.wait(&mLock);
} }
if (!getMorrowindPath().isEmpty()) { if (!getComponentPath(Wizard::Component_Morrowind).isEmpty()) {
disk.setPath(getMorrowindPath()); disk.setPath(getComponentPath(Wizard::Component_Morrowind));
if (!findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Morrowind.bsa")) if (!findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Morrowind.bsa"))
| findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Tribunal.bsa")) | findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Tribunal.bsa"))
| findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Bloodmoon.bsa"))) | findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Bloodmoon.bsa")))
{ {
QReadLocker readLock(&mLock); QReadLocker readLock(&mLock);
emit requestFileDialog(QLatin1String("Morrowind")); emit requestFileDialog(Wizard::Component_Morrowind);
mWait.wait(&mLock); mWait.wait(&mLock);
} else { } else {
if (installMorrowind()) { if (installComponent(Wizard::Component_Morrowind)) {
setMorrowindDone(true); setComponentDone(Wizard::Component_Morrowind, true);
} else { } else {
qDebug() << "Erorr installing Morrowind"; qDebug() << "Erorr installing Morrowind";
return; return;
@ -385,111 +370,29 @@ void Wizard::UnshieldWorker::extract()
} }
} }
if (getInstallTribunal()) if (getInstallComponent(Wizard::Component_Tribunal))
{ {
while (!getTribunalDone()) setupAddon(Wizard::Component_Tribunal);
{
QDir tribunal(disk);
if (!tribunal.cd(QLatin1String("Tribunal"))) {
qDebug() << "not found on cd!";
QReadLocker locker(&mLock);
emit requestFileDialog(QLatin1String("Tribunal"));
mWait.wait(&mLock);
} else if (tribunal.exists(QLatin1String("data1.hdr"))) {
qDebug() << "Exists! " << tribunal.absolutePath();
setTribunalPath(tribunal.absolutePath());
}
if (getTribunalPath().isEmpty()) {
qDebug() << "request file dialog";
QReadLocker locker(&mLock);
emit requestFileDialog(QLatin1String("Tribunal"));
mWait.wait(&mLock);
}
// Make sure the dir is up-to-date
tribunal.setPath(getTribunalPath());
if (!getTribunalPath().isEmpty()) {
if (!findFile(tribunal.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Tribunal.bsa")))
{
qDebug() << "found";
QReadLocker locker(&mLock);
emit requestFileDialog(QLatin1String("Tribunal"));
mWait.wait(&mLock);
} else {
if (installTribunal()) {
setTribunalDone(true);
} else {
qDebug() << "Erorr installing Tribunal";
return;
}
}
}
}
} }
if (getInstallBloodmoon()) if (getInstallComponent(Wizard::Component_Bloodmoon))
{ {
while (!getBloodmoonDone()) setupAddon(Wizard::Component_Bloodmoon);
{
QDir bloodmoon(disk);
qDebug() << "Test!: " << bloodmoon.absolutePath();
if (!bloodmoon.cd(QLatin1String("Bloodmoon"))) {
qDebug() << "not found on cd!";
QReadLocker locker(&mLock);
emit requestFileDialog(QLatin1String("Bloodmoon"));
mWait.wait(&mLock);
} else if (bloodmoon.exists(QLatin1String("data1.hdr"))) {
qDebug() << "Exists! " << bloodmoon.absolutePath();
setBloodmoonPath(bloodmoon.absolutePath());
}
if (getBloodmoonPath().isEmpty()) {
qDebug() << "request file dialog";
QReadLocker locker(&mLock);
emit requestFileDialog(QLatin1String("Bloodmoon"));
mWait.wait(&mLock);
}
// Make sure the dir is up-to-date
bloodmoon.setPath(getBloodmoonPath());
if (!findFile(bloodmoon.absoluteFilePath(QLatin1String("data1.hdr")), QLatin1String("Bloodmoon.bsa")))
{
QReadLocker locker(&mLock);
emit requestFileDialog(QLatin1String("Bloodmoon"));
mWait.wait(&mLock);
} else {
if (installBloodmoon()) {
setBloodmoonDone(true);
} else {
qDebug() << "Erorr installing Bloodmoon";
return;
}
}
}
} }
// Remove the temporary directory // Remove the temporary directory
removeDirectory(mPath + QDir::separator() + QLatin1String("extract-temp")); removeDirectory(getPath() + QDir::separator() + QLatin1String("extract-temp"));
// Fill the progress bar // Fill the progress bar
int total = 0; int total = 0;
if (getInstallMorrowind()) if (getInstallComponent(Wizard::Component_Morrowind))
total = 100; total = 100;
if (getInstallTribunal()) if (getInstallComponent(Wizard::Component_Tribunal))
total = total + 100; total = total + 100;
if (getInstallBloodmoon()) if (getInstallComponent(Wizard::Component_Bloodmoon))
total = total + 100; total = total + 100;
emit textChanged(tr("Installation finished!")); emit textChanged(tr("Installation finished!"));
@ -499,83 +402,87 @@ void Wizard::UnshieldWorker::extract()
qDebug() << "installation finished!"; qDebug() << "installation finished!";
} }
bool Wizard::UnshieldWorker::installMorrowind() void Wizard::UnshieldWorker::setupAddon(Component component)
{ {
qDebug() << "install morrowind!"; while (!getComponentDone(component))
emit textChanged(QLatin1String("Installing Morrowind")); {
QDir disk(getComponentPath(Wizard::Component_Morrowind));
QDir disk(getMorrowindPath()); QString name;
if (component == Wizard::Component_Tribunal)
name = QLatin1String("Tribunal");
if (component == Wizard::Component_Bloodmoon)
name = QLatin1String("Bloodmoon");
if (name.isEmpty())
return; // Not a valid addon
if (!disk.cd(name)) {
qDebug() << "not found on cd!";
QReadLocker locker(&mLock);
emit requestFileDialog(component);
mWait.wait(&mLock);
} else if (disk.exists(QLatin1String("data1.hdr"))) {
qDebug() << "Exists! " << disk.absolutePath();
setComponentPath(component, disk.absolutePath());
}
if (!disk.exists()) { if (getComponentPath(component).isEmpty()) {
qDebug() << "getMorrowindPath: " << getMorrowindPath(); qDebug() << "request file dialog";
return false; QReadLocker locker(&mLock);
} emit requestFileDialog(Wizard::Component_Tribunal);
mWait.wait(&mLock);
}
// Create temporary extract directory // Make sure the dir is up-to-date
// TODO: Use QTemporaryDir in Qt 5.0 disk.setPath(getComponentPath(component));
QString tempPath(getPath() + QDir::separator() + QLatin1String("extract-temp"));
QDir temp;
// Make sure the temporary folder is empty if (!getComponentPath(component).isEmpty()) {
removeDirectory(tempPath);
if (!temp.mkpath(tempPath)) { if (!findFile(disk.absoluteFilePath(QLatin1String("data1.hdr")), name + QLatin1String(".bsa")))
qDebug() << "Can't make path"; {
return false; QReadLocker locker(&mLock);
emit requestFileDialog(component);
mWait.wait(&mLock);
} else {
// Now do the actual installing
if (installComponent(component)) {
setComponentDone(component, true);
} else {
qDebug() << "Error installing " << name;
return;
}
}
}
} }
}
temp.setPath(tempPath); bool Wizard::UnshieldWorker::installComponent(Component component)
{
if (!temp.mkdir(QLatin1String("morrowind"))) { QString name;
qDebug() << "Can't make dir"; switch (component) {
return false;
}
if (!temp.cd(QLatin1String("morrowind"))) { case Wizard::Component_Morrowind:
qDebug() << "Can't cd to dir"; name = QLatin1String("Morrowind");
return false; break;
case Wizard::Component_Tribunal:
name = QLatin1String("Tribunal");
break;
case Wizard::Component_Bloodmoon:
name = QLatin1String("Bloodmoon");
break;
} }
// Extract the installation files if (name.isEmpty())
extractCab(disk.absoluteFilePath(QLatin1String("data1.hdr")), temp.absolutePath());
// TODO: Throw error;
// Move the files from the temporary path to the destination folder
emit textChanged(tr("Moving installation files"));
if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), getPath())) {
qDebug() << "failed to move files!";
return false; return false;
}
// Install files outside of cab archives
installDirectories(disk.absolutePath());
// Copy Morrowind configuration file emit textChanged(tr("Installing %0").arg(name));
QString iniPath(temp.absoluteFilePath(QLatin1String("App Executables")));
iniPath.append(QDir::separator() + QLatin1String("Morrowind.ini"));
QFileInfo info(iniPath); QDir disk(getComponentPath(component));
if (info.exists()) {
emit textChanged(tr("Extracting: Morrowind.ini"));
moveFile(info.absoluteFilePath(), getPath() + QDir::separator() + QLatin1String("Morrowind.ini"));
} else {
qDebug() << "Could not find ini file!";
return false;
}
emit textChanged(tr("Morrowind installation finished!"));
return true;
}
bool Wizard::UnshieldWorker::installTribunal()
{
emit textChanged(QLatin1String("Installing Tribunal"));
QDir disk(getTribunalPath());
if (!disk.exists()) { if (!disk.exists()) {
qDebug() << "disk does not exist! " << disk.absolutePath() << getTribunalPath(); qDebug() << "Component path not set: " << getComponentPath(Wizard::Component_Morrowind);
return false; return false;
} }
@ -594,12 +501,12 @@ bool Wizard::UnshieldWorker::installTribunal()
temp.setPath(tempPath); temp.setPath(tempPath);
if (!temp.mkdir(QLatin1String("tribunal"))) { if (!temp.mkdir(name)) {
qDebug() << "Can't make dir"; qDebug() << "Can't make dir";
return false; return false;
} }
if (!temp.cd(QLatin1String("tribunal"))) { if (!temp.cd(name)) {
qDebug() << "Can't cd to dir"; qDebug() << "Can't cd to dir";
return false; return false;
} }
@ -610,8 +517,7 @@ bool Wizard::UnshieldWorker::installTribunal()
// TODO: Throw error; // TODO: Throw error;
// Move the files from the temporary path to the destination folder // Move the files from the temporary path to the destination folder
emit textChanged(tr("Moving installation files")); emit textChanged(tr("Moving installation files"));
if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), getPath())) if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), getPath())) {
{
qDebug() << "failed to move files!"; qDebug() << "failed to move files!";
return false; return false;
} }
@ -619,71 +525,39 @@ bool Wizard::UnshieldWorker::installTribunal()
// Install files outside of cab archives // Install files outside of cab archives
installDirectories(disk.absolutePath()); installDirectories(disk.absolutePath());
emit textChanged(tr("Tribunal installation finished!")); if (component == Wizard::Component_Morrowind)
return true; {
} // Copy Morrowind configuration file
QString iniPath(temp.absoluteFilePath(QLatin1String("App Executables")));
bool Wizard::UnshieldWorker::installBloodmoon() iniPath.append(QDir::separator() + QLatin1String("Morrowind.ini"));
{
emit textChanged(QLatin1String("Installing Bloodmoon"));
QDir disk(getBloodmoonPath());
if (!disk.exists()) {
return false;
}
// Create temporary extract directory
// TODO: Use QTemporaryDir in Qt 5.0
QString tempPath(getPath() + QDir::separator() + QLatin1String("extract-temp"));
QDir temp;
// Make sure the temporary folder is empty
removeDirectory(tempPath);
if (!temp.mkpath(tempPath)) {
qDebug() << "Can't make path";
return false;
}
temp.setPath(tempPath);
if (!temp.mkdir(QLatin1String("bloodmoon"))) {
qDebug() << "Can't make dir";
return false;
}
if (!temp.cd(QLatin1String("bloodmoon"))) {
qDebug() << "Can't cd to dir";
return false;
}
// Extract the installation files QFileInfo info(iniPath);
extractCab(disk.absoluteFilePath(QLatin1String("data1.hdr")), temp.absolutePath());
// TODO: Throw error; if (info.exists()) {
// Move the files from the temporary path to the destination folder emit textChanged(tr("Extracting: Morrowind.ini"));
emit textChanged(tr("Moving installation files")); moveFile(info.absoluteFilePath(), getPath() + QDir::separator() + QLatin1String("Morrowind.ini"));
if (!moveDirectory(temp.absoluteFilePath(QLatin1String("Data Files")), getPath())) { } else {
qDebug() << "failed to move files!"; qDebug() << "Could not find ini file!";
return false; return false;
}
} }
// Install files outside of cab archives if (component == Wizard::Component_Bloodmoon)
installDirectories(disk.absolutePath()); {
QFileInfo patch(temp.absoluteFilePath(QLatin1String("Tribunal Patch") + QDir::separator() + QLatin1String("Tribunal.esm")));
QFileInfo original(getPath() + QDir::separator() + QLatin1String("Tribunal.esm"));
QFileInfo patch(temp.absoluteFilePath(QLatin1String("Tribunal Patch") + QDir::separator() + QLatin1String("Tribunal.esm"))); if (original.exists() && patch.exists()) {
QFileInfo original(getPath() + QDir::separator() + QLatin1String("Tribunal.esm")); emit textChanged(tr("Extracting: Tribunal patch"));
copyFile(patch.absoluteFilePath(), original.absoluteFilePath());
}
if (original.exists() && patch.exists()) {
emit textChanged(tr("Extracting: Tribunal patch"));
copyFile(patch.absoluteFilePath(), original.absoluteFilePath());
} }
emit textChanged(tr("Bloodmoon installation finished!")); emit textChanged(tr("%0 installation finished!").arg(name));
return true; return true;
}
}
bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter) bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter)
{ {
@ -713,10 +587,10 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &outp
// Calculate the percentage done // Calculate the percentage done
int progress = (((float) counter / (float) unshield_file_count(unshield)) * 100); int progress = (((float) counter / (float) unshield_file_count(unshield)) * 100);
if (getMorrowindDone()) if (getComponentDone(Wizard::Component_Morrowind))
progress = progress + 100; progress = progress + 100;
if (getTribunalDone()) if (getComponentDone(Wizard::Component_Tribunal))
progress = progress + 100; progress = progress + 100;
emit textChanged(tr("Extracting: %1").arg(QString::fromLatin1(unshield_file_name(unshield, index)))); emit textChanged(tr("Extracting: %1").arg(QString::fromLatin1(unshield_file_name(unshield, index))));

@ -11,31 +11,29 @@
#include "../inisettings.hpp" #include "../inisettings.hpp"
namespace Wizard namespace Wizard
{ {
enum Component {
Component_Morrowind,
Component_Tribunal,
Component_Bloodmoon
};
//Q_DECLARE_METATYPE(Wizard::Component)
class UnshieldWorker : public QObject class UnshieldWorker : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS(Wizard::Component)
public: public:
UnshieldWorker(QObject *parent = 0); UnshieldWorker(QObject *parent = 0);
~UnshieldWorker(); ~UnshieldWorker();
void setInstallMorrowind(bool install); void setInstallComponent(Wizard::Component component, bool install);
void setInstallTribunal(bool install);
void setInstallBloodmoon(bool install);
bool getInstallMorrowind(); void setComponentPath(Wizard::Component component, const QString &path);
bool getInstallTribunal();
bool getInstallBloodmoon();
void setMorrowindPath(const QString &path);
void setTribunalPath(const QString &path);
void setBloodmoonPath(const QString &path);
QString getMorrowindPath();
QString getTribunalPath();
QString getBloodmoonPath();
void setPath(const QString &path); void setPath(const QString &path);
void setIniPath(const QString &path); void setIniPath(const QString &path);
@ -47,13 +45,12 @@ namespace Wizard
private: private:
void setMorrowindDone(bool done); bool getInstallComponent(Component component);
void setTribunalDone(bool done);
void setBloodmoonDone(bool done);
bool getMorrowindDone(); QString getComponentPath(Component component);
bool getTribunalDone();
bool getBloodmoonDone(); void setComponentDone(Component component, bool done = true);
bool getComponentDone(Component component);
bool removeDirectory(const QString &dirName); bool removeDirectory(const QString &dirName);
@ -75,6 +72,9 @@ namespace Wizard
bool installTribunal(); bool installTribunal();
bool installBloodmoon(); bool installBloodmoon();
bool installComponent(Component component);
void setupAddon(Component component);
bool mInstallMorrowind; bool mInstallMorrowind;
bool mInstallTribunal; bool mInstallTribunal;
bool mInstallBloodmoon; bool mInstallBloodmoon;
@ -104,7 +104,7 @@ namespace Wizard
signals: signals:
void finished(); void finished();
void requestFileDialog(const QString &component); void requestFileDialog(Wizard::Component component);
void textChanged(const QString &text); void textChanged(const QString &text);
void logTextChanged(const QString &text); void logTextChanged(const QString &text);

Loading…
Cancel
Save