forked from teamnwah/openmw-tes3coop
Redid the unshield thread stuff, this time the way it should be done
This commit is contained in:
parent
a2ca7b92a2
commit
691e007524
4 changed files with 69 additions and 66 deletions
|
@ -11,7 +11,8 @@ set(WIZARD
|
|||
main.cpp
|
||||
mainwizard.cpp
|
||||
methodselectionpage.cpp
|
||||
unshieldthread.cpp
|
||||
|
||||
unshield/unshieldworker.cpp
|
||||
|
||||
utils/componentlistwidget.cpp
|
||||
)
|
||||
|
@ -28,7 +29,8 @@ set(WIZARD_HEADER
|
|||
languageselectionpage.hpp
|
||||
mainwizard.hpp
|
||||
methodselectionpage.hpp
|
||||
unshieldthread.hpp
|
||||
|
||||
unshield/unshieldworker.hpp
|
||||
|
||||
utils/componentlistwidget.hpp
|
||||
)
|
||||
|
@ -45,7 +47,8 @@ set(WIZARD_HEADER_MOC
|
|||
languageselectionpage.hpp
|
||||
mainwizard.hpp
|
||||
methodselectionpage.hpp
|
||||
unshieldthread.hpp
|
||||
|
||||
unshield/unshieldworker.hpp
|
||||
|
||||
utils/componentlistwidget.hpp
|
||||
)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "mainwizard.hpp"
|
||||
#include "inisettings.hpp"
|
||||
#include "unshieldthread.hpp"
|
||||
#include "unshield/unshieldworker.hpp"
|
||||
|
||||
Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
|
||||
QWizardPage(wizard),
|
||||
|
@ -55,11 +55,23 @@ void Wizard::InstallationPage::startInstallation()
|
|||
QStringList components(field("installation.components").toStringList());
|
||||
QString path(field("installation.path").toString());
|
||||
|
||||
UnshieldThread *unshield = new UnshieldThread();
|
||||
QThread* thread = new QThread();
|
||||
UnshieldWorker* unshield = new UnshieldWorker();
|
||||
|
||||
unshield->moveToThread(thread);
|
||||
|
||||
connect(thread, SIGNAL(started()),
|
||||
unshield, SLOT(extract()));
|
||||
|
||||
connect(unshield, SIGNAL(finished()),
|
||||
thread, SLOT(quit()));
|
||||
|
||||
connect(unshield, SIGNAL(finished()),
|
||||
unshield, SLOT(deleteLater()));
|
||||
|
||||
connect(unshield, SIGNAL(finished()),
|
||||
thread, SLOT(deleteLater()));
|
||||
|
||||
connect(unshield, SIGNAL(finished()),
|
||||
this, SLOT(installationFinished()));
|
||||
|
||||
|
@ -114,12 +126,13 @@ void Wizard::InstallationPage::startInstallation()
|
|||
unshield->setIniCodec(QTextCodec::codecForName("windows-1252"));
|
||||
}
|
||||
|
||||
unshield->start();
|
||||
thread->start();
|
||||
|
||||
}
|
||||
|
||||
void Wizard::InstallationPage::installationFinished()
|
||||
{
|
||||
qDebug() << "finished!";
|
||||
mFinished = true;
|
||||
emit completeChanged();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "unshieldthread.hpp"
|
||||
#include "unshieldworker.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -10,11 +10,12 @@
|
|||
#include <QTextCodec>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
Wizard::UnshieldThread::UnshieldThread(QObject *parent) :
|
||||
QThread(parent),
|
||||
Wizard::UnshieldWorker::UnshieldWorker(QObject *parent) :
|
||||
QObject(parent),
|
||||
mIniSettings()
|
||||
{
|
||||
unshield_set_log_level(0);
|
||||
|
@ -28,40 +29,44 @@ Wizard::UnshieldThread::UnshieldThread(QObject *parent) :
|
|||
mInstallMorrowind = false;
|
||||
mInstallTribunal = false;
|
||||
mInstallBloodmoon = false;
|
||||
}
|
||||
|
||||
Wizard::UnshieldWorker::~UnshieldWorker()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setInstallMorrowind(bool install)
|
||||
void Wizard::UnshieldWorker::setInstallMorrowind(bool install)
|
||||
{
|
||||
mInstallMorrowind = install;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setInstallTribunal(bool install)
|
||||
void Wizard::UnshieldWorker::setInstallTribunal(bool install)
|
||||
{
|
||||
mInstallTribunal = install;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setInstallBloodmoon(bool install)
|
||||
void Wizard::UnshieldWorker::setInstallBloodmoon(bool install)
|
||||
{
|
||||
mInstallBloodmoon = install;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setPath(const QString &path)
|
||||
void Wizard::UnshieldWorker::setPath(const QString &path)
|
||||
{
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setIniPath(const QString &path)
|
||||
void Wizard::UnshieldWorker::setIniPath(const QString &path)
|
||||
{
|
||||
mIniPath = path;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setIniCodec(QTextCodec *codec)
|
||||
void Wizard::UnshieldWorker::setIniCodec(QTextCodec *codec)
|
||||
{
|
||||
mIniCodec = codec;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::setupSettings()
|
||||
void Wizard::UnshieldWorker::setupSettings()
|
||||
{
|
||||
// Create Morrowind.ini settings map
|
||||
if (mIniPath.isEmpty())
|
||||
|
@ -88,7 +93,7 @@ void Wizard::UnshieldThread::setupSettings()
|
|||
mIniSettings.readFile(stream);
|
||||
}
|
||||
|
||||
bool Wizard::UnshieldThread::removeDirectory(const QString &dirName)
|
||||
bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
|
||||
{
|
||||
bool result = true;
|
||||
QDir dir(dirName);
|
||||
|
@ -114,7 +119,7 @@ bool Wizard::UnshieldThread::removeDirectory(const QString &dirName)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Wizard::UnshieldThread::moveFile(const QString &source, const QString &destination)
|
||||
bool Wizard::UnshieldWorker::moveFile(const QString &source, const QString &destination)
|
||||
{
|
||||
QDir dir;
|
||||
QFile file;
|
||||
|
@ -132,7 +137,7 @@ bool Wizard::UnshieldThread::moveFile(const QString &source, const QString &dest
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Wizard::UnshieldThread::moveDirectory(const QString &source, const QString &destination)
|
||||
bool Wizard::UnshieldWorker::moveDirectory(const QString &source, const QString &destination)
|
||||
{
|
||||
QDir sourceDir(source);
|
||||
QDir destDir(destination);
|
||||
|
@ -173,7 +178,7 @@ bool Wizard::UnshieldThread::moveDirectory(const QString &source, const QString
|
|||
return result && removeDirectory(sourceDir.absolutePath());
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::extract()
|
||||
void Wizard::UnshieldWorker::extract()
|
||||
{
|
||||
emit textChanged(QLatin1String("Starting installation"));
|
||||
emit textChanged(QLatin1String("Installation target: ") + mPath);
|
||||
|
@ -211,22 +216,23 @@ void Wizard::UnshieldThread::extract()
|
|||
QString morrowindTempPath(tempPath + QLatin1String("/morrowind"));
|
||||
QString morrowindCab(QLatin1String("/mnt/cdrom/data1.hdr"));
|
||||
|
||||
extractCab(morrowindCab, morrowindTempPath);
|
||||
//extractCab(morrowindCab, morrowindTempPath);
|
||||
|
||||
// TODO: Throw error;
|
||||
// Move the files from the temporary path to the destination folder
|
||||
|
||||
//qDebug() << "rename: " << morrowindTempPath << " to: " << mPath;
|
||||
morrowindTempPath.append(QDir::separator() + QLatin1String("Data Files"));
|
||||
if (!moveDirectory(morrowindTempPath, mPath))
|
||||
qDebug() << "failed!";
|
||||
// if (!moveDirectory(morrowindTempPath, mPath))
|
||||
// qDebug() << "failed!";
|
||||
|
||||
QDir source(QLatin1String("/mnt/cdrom/"));
|
||||
QDir sourceDir(QLatin1String("/mnt/cdrom/"));
|
||||
QStringList directories;
|
||||
directories << QLatin1String("Fonts")
|
||||
<< QLatin1String("Music")
|
||||
<< QLatin1String("Sound")
|
||||
<< QLatin1String("Splash");
|
||||
<< QLatin1String("Splash")
|
||||
<< QLatin1String("Video");
|
||||
|
||||
QFileInfoList list(sourceDir.entryInfoList(QDir::NoDotAndDotDot |
|
||||
QDir::System | QDir::Hidden |
|
||||
|
@ -237,27 +243,13 @@ void Wizard::UnshieldThread::extract()
|
|||
if (info.isSymLink())
|
||||
continue;
|
||||
|
||||
qDebug() << "not found " << info.fileName();
|
||||
|
||||
if (directories.contains(info.fileName()))
|
||||
copyDirectory(info.absoluteFilePath(), mPath);
|
||||
qDebug() << "found " << info.fileName();
|
||||
// copyDirectory(info.absoluteFilePath(), mPath);
|
||||
}
|
||||
|
||||
|
||||
bfs::path fonts = findFile(from, "fonts", false);
|
||||
if(fonts.string() != "")
|
||||
installToPath(fonts, dFiles / "Fonts");
|
||||
|
||||
bfs::path music = findFile(from, "music", false);
|
||||
if(music.string() != "")
|
||||
installToPath(music, dFiles / "Music");
|
||||
|
||||
bfs::path sound = findFile(from, "sound", false);
|
||||
if(sound.string() != "")
|
||||
installToPath(sound, dFiles / "Sound");
|
||||
|
||||
bfs::path splash = findFile(from, "splash", false);
|
||||
if(splash.string() != "")
|
||||
installToPath(splash, dFiles / "Splash");
|
||||
|
||||
}
|
||||
|
||||
// if(!mMorrowindDone && mMorrowindPath.string().length() > 0)
|
||||
|
@ -299,10 +291,11 @@ void Wizard::UnshieldThread::extract()
|
|||
|
||||
|
||||
///
|
||||
emit finished();
|
||||
|
||||
}
|
||||
|
||||
bool Wizard::UnshieldThread::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)
|
||||
{
|
||||
bool success;
|
||||
QString path(outputDir);
|
||||
|
@ -344,7 +337,7 @@ bool Wizard::UnshieldThread::extractFile(Unshield *unshield, const QString &outp
|
|||
return success;
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::extractCab(const QString &cabFile, const QString &outputDir)
|
||||
void Wizard::UnshieldWorker::extractCab(const QString &cabFile, const QString &outputDir)
|
||||
{
|
||||
Unshield *unshield;
|
||||
unshield = unshield_open(cabFile.toLatin1().constData());
|
||||
|
@ -366,11 +359,3 @@ void Wizard::UnshieldThread::extractCab(const QString &cabFile, const QString &o
|
|||
|
||||
unshield_close(unshield);
|
||||
}
|
||||
|
||||
void Wizard::UnshieldThread::run()
|
||||
{
|
||||
qDebug() << "From worker thread: " << currentThreadId();
|
||||
|
||||
setupSettings();
|
||||
extract();
|
||||
}
|
|
@ -1,22 +1,22 @@
|
|||
#ifndef UNSHIELDTHREAD_HPP
|
||||
#define UNSHIELDTHREAD_HPP
|
||||
#ifndef UNSHIELDWORKER_HPP
|
||||
#define UNSHIELDWORKER_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include <libunshield.h>
|
||||
|
||||
#include "inisettings.hpp"
|
||||
|
||||
class QTextCodec;
|
||||
#include "../inisettings.hpp"
|
||||
|
||||
namespace Wizard
|
||||
{
|
||||
|
||||
class UnshieldThread : public QThread
|
||||
class UnshieldWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UnshieldThread(QObject *parent = 0);
|
||||
UnshieldWorker(QObject *parent = 0);
|
||||
~UnshieldWorker();
|
||||
|
||||
void setInstallMorrowind(bool install);
|
||||
void setInstallTribunal(bool install);
|
||||
|
@ -35,7 +35,6 @@ namespace Wizard
|
|||
bool moveDirectory(const QString &source, const QString &destination);
|
||||
|
||||
void setupSettings();
|
||||
void extract();
|
||||
|
||||
void extractCab(const QString &cabFile, const QString &outputDir);
|
||||
bool extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter);
|
||||
|
@ -52,15 +51,18 @@ namespace Wizard
|
|||
|
||||
QTextCodec *mIniCodec;
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
|
||||
public slots:
|
||||
void extract();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
void textChanged(const QString &text);
|
||||
void error(const QString &text);
|
||||
void progressChanged(int progress);
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // UNSHIELDTHREAD_HPP
|
||||
#endif // UNSHIELDWORKER_HPP
|
Loading…
Reference in a new issue