From 40486370d951fd68a29e30d078e43f2e13c407e4 Mon Sep 17 00:00:00 2001 From: pvdk Date: Wed, 25 Dec 2013 18:52:34 +0100 Subject: [PATCH] Working on the Unshield functionality --- apps/wizard/installationpage.cpp | 71 ++++++++++++++++++++++++++++- apps/wizard/installationpage.hpp | 6 +++ apps/wizard/unshieldthread.cpp | 61 +++++++++++++++++++++++++ apps/wizard/unshieldthread.hpp | 47 +++++++++++++++++++ files/ui/wizard/installationpage.ui | 6 +-- 5 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 apps/wizard/unshieldthread.cpp create mode 100644 apps/wizard/unshieldthread.hpp diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index e98d75ba4..bff465fee 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -9,6 +9,7 @@ #include "mainwizard.hpp" #include "inisettings.hpp" +#include "unshieldthread.hpp" Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : QWizardPage(wizard), @@ -37,10 +38,12 @@ void Wizard::InstallationPage::initializePage() } else { - if (components.contains("Tribunal") && mWizard->mInstallations[path]->hasTribunal == false) + if (components.contains(QLatin1String("Tribunal")) + && mWizard->mInstallations[path]->hasTribunal == false) installProgressBar->setMaximum(100); - if (components.contains("Bloodmoon") && mWizard->mInstallations[path]->hasBloodmoon == false) + if (components.contains(QLatin1String("Bloodmoon")) + && mWizard->mInstallations[path]->hasBloodmoon == false) installProgressBar->setMaximum(installProgressBar->maximum() + 100); } @@ -48,6 +51,9 @@ void Wizard::InstallationPage::initializePage() if (field("installation.new").toBool() == false) setupSettings(); + + startInstallation(); + } void Wizard::InstallationPage::setupSettings() @@ -90,6 +96,67 @@ void Wizard::InstallationPage::setupSettings() qDebug() << iniSettings.value("Game Files/GameFile0"); } +void Wizard::InstallationPage::startInstallation() +{ + QStringList components(field("installation.components").toStringList()); + QString path(field("installation.path").toString()); + + UnshieldThread *unshield = new UnshieldThread(); + + connect(unshield, SIGNAL(finished()), + unshield, SLOT(deleteLater())); + + connect(unshield, SIGNAL(finished()), + this, SLOT(installationFinished())); + + connect(unshield, SIGNAL(textChanged(QString)), + installProgressLabel, SLOT(setText(QString))); + + connect(unshield, SIGNAL(textChanged(QString)), + logTextEdit, SLOT(append(QString))); + + if (field("installation.new").toBool() == true) + { + // Always install Morrowind + unshield->setInstallMorrowind(true); + + if (components.contains(QLatin1String("Tribunal"))) + unshield->setInstallTribunal(true); + + if (components.contains(QLatin1String("Bloodmoon"))) + unshield->setInstallBloodmoon(true); + } else { + // Morrowind should already be installed + unshield->setInstallMorrowind(false); + + if (components.contains(QLatin1String("Tribunal")) + && mWizard->mInstallations[path]->hasTribunal == false) + unshield->setInstallTribunal(false); + + if (components.contains(QLatin1String("Bloodmoon")) + && mWizard->mInstallations[path]->hasBloodmoon == false) + unshield->setInstallBloodmoon(true); + } + + + // Set the installation target path + unshield->setPath(path); + + unshield->start(); + +} + +void Wizard::InstallationPage::installationFinished() +{ + qDebug() << "Installation finished!"; + mFinished = true; +} + +bool Wizard::InstallationPage::isComplete() const +{ + return mFinished; +} + int Wizard::InstallationPage::nextId() const { return MainWizard::Page_Import; diff --git a/apps/wizard/installationpage.hpp b/apps/wizard/installationpage.hpp index b4fecc3ba..022b34c64 100644 --- a/apps/wizard/installationpage.hpp +++ b/apps/wizard/installationpage.hpp @@ -16,11 +16,17 @@ namespace Wizard InstallationPage(MainWizard *wizard); int nextId() const; + virtual bool isComplete() const; private: MainWizard *mWizard; + bool mFinished; void setupSettings(); + void startInstallation(); + + private slots: + void installationFinished(); protected: void initializePage(); diff --git a/apps/wizard/unshieldthread.cpp b/apps/wizard/unshieldthread.cpp new file mode 100644 index 000000000..23257e2d8 --- /dev/null +++ b/apps/wizard/unshieldthread.cpp @@ -0,0 +1,61 @@ +#include "unshieldthread.hpp" + +#include +#include + +Wizard::UnshieldThread::UnshieldThread(QObject *parent) : + QThread(parent) +{ + unshield_set_log_level(0); + + mInstallMorrowind = false; + mInstallTribunal = false; + mInstallBloodmoon = false; + +} + +void Wizard::UnshieldThread::setInstallMorrowind(bool install) +{ + mInstallMorrowind = install; +} + +void Wizard::UnshieldThread::setInstallTribunal(bool install) +{ + mInstallTribunal = install; +} + +void Wizard::UnshieldThread::setInstallBloodmoon(bool install) +{ + mInstallBloodmoon = install; +} + +void Wizard::UnshieldThread::setPath(const QString &path) +{ + mPath = path; +} + +void Wizard::UnshieldThread::extract() +{ + emit textChanged(QLatin1String("Starting installation")); + emit textChanged(QLatin1String("Installation target: ") + mPath); + + QStringList components; + if (mInstallMorrowind) + components << QLatin1String("Morrowind"); + + if (mInstallTribunal) + components << QLatin1String("Tribunal"); + + if (mInstallBloodmoon) + components << QLatin1String("Bloodmoon"); + + emit textChanged(QLatin1String("Components: ") + components.join(QLatin1String(", "))); + +} + +void Wizard::UnshieldThread::run() +{ + qDebug() << "From worker thread: " << currentThreadId(); + + extract(); +} diff --git a/apps/wizard/unshieldthread.hpp b/apps/wizard/unshieldthread.hpp new file mode 100644 index 000000000..764a99e6a --- /dev/null +++ b/apps/wizard/unshieldthread.hpp @@ -0,0 +1,47 @@ +#ifndef UNSHIELDTHREAD_HPP +#define UNSHIELDTHREAD_HPP + +#include + +#include + +namespace Wizard +{ + + class UnshieldThread : public QThread + { + Q_OBJECT + public: + explicit UnshieldThread(QObject *parent = 0); + + void setInstallMorrowind(bool install); + void setInstallTribunal(bool install); + void setInstallBloodmoon(bool install); + + void setPath(const QString &path); + + private: + void extract(); + + void extractCab(const QString &cabFile, + const QString &outputDir, bool extractIni); + //void extractFile(Unshield *unshield, + // ) + + bool mInstallMorrowind; + bool mInstallTribunal; + bool mInstallBloodmoon; + + QString mPath; + + protected: + virtual void run(); + + signals: + void textChanged(const QString &text); + + }; + +} + +#endif // UNSHIELDTHREAD_HPP diff --git a/files/ui/wizard/installationpage.ui b/files/ui/wizard/installationpage.ui index 3e94c1e30..6c1a3c493 100644 --- a/files/ui/wizard/installationpage.ui +++ b/files/ui/wizard/installationpage.ui @@ -6,8 +6,8 @@ 0 0 - 518 - 423 + 516 + 421 @@ -21,7 +21,7 @@ - + Extracting: %1