1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 19:19:56 +00:00

Redid the unshield thread stuff, this time the way it should be done

This commit is contained in:
pvdk 2014-01-01 22:46:29 +01:00
parent a2ca7b92a2
commit 691e007524
4 changed files with 69 additions and 66 deletions

View file

@ -11,7 +11,8 @@ set(WIZARD
main.cpp main.cpp
mainwizard.cpp mainwizard.cpp
methodselectionpage.cpp methodselectionpage.cpp
unshieldthread.cpp
unshield/unshieldworker.cpp
utils/componentlistwidget.cpp utils/componentlistwidget.cpp
) )
@ -28,7 +29,8 @@ set(WIZARD_HEADER
languageselectionpage.hpp languageselectionpage.hpp
mainwizard.hpp mainwizard.hpp
methodselectionpage.hpp methodselectionpage.hpp
unshieldthread.hpp
unshield/unshieldworker.hpp
utils/componentlistwidget.hpp utils/componentlistwidget.hpp
) )
@ -45,7 +47,8 @@ set(WIZARD_HEADER_MOC
languageselectionpage.hpp languageselectionpage.hpp
mainwizard.hpp mainwizard.hpp
methodselectionpage.hpp methodselectionpage.hpp
unshieldthread.hpp
unshield/unshieldworker.hpp
utils/componentlistwidget.hpp utils/componentlistwidget.hpp
) )

View file

@ -5,7 +5,7 @@
#include "mainwizard.hpp" #include "mainwizard.hpp"
#include "inisettings.hpp" #include "inisettings.hpp"
#include "unshieldthread.hpp" #include "unshield/unshieldworker.hpp"
Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
QWizardPage(wizard), QWizardPage(wizard),
@ -55,11 +55,23 @@ void Wizard::InstallationPage::startInstallation()
QStringList components(field("installation.components").toStringList()); QStringList components(field("installation.components").toStringList());
QString path(field("installation.path").toString()); 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()), connect(unshield, SIGNAL(finished()),
unshield, SLOT(deleteLater())); unshield, SLOT(deleteLater()));
connect(unshield, SIGNAL(finished()),
thread, SLOT(deleteLater()));
connect(unshield, SIGNAL(finished()), connect(unshield, SIGNAL(finished()),
this, SLOT(installationFinished())); this, SLOT(installationFinished()));
@ -114,12 +126,13 @@ void Wizard::InstallationPage::startInstallation()
unshield->setIniCodec(QTextCodec::codecForName("windows-1252")); unshield->setIniCodec(QTextCodec::codecForName("windows-1252"));
} }
unshield->start(); thread->start();
} }
void Wizard::InstallationPage::installationFinished() void Wizard::InstallationPage::installationFinished()
{ {
qDebug() << "finished!";
mFinished = true; mFinished = true;
emit completeChanged(); emit completeChanged();
} }

View file

@ -1,4 +1,4 @@
#include "unshieldthread.hpp" #include "unshieldworker.hpp"
#include <QDebug> #include <QDebug>
@ -10,11 +10,12 @@
#include <QTextCodec> #include <QTextCodec>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QDirIterator>
#include <qmath.h> #include <qmath.h>
Wizard::UnshieldThread::UnshieldThread(QObject *parent) : Wizard::UnshieldWorker::UnshieldWorker(QObject *parent) :
QThread(parent), QObject(parent),
mIniSettings() mIniSettings()
{ {
unshield_set_log_level(0); unshield_set_log_level(0);
@ -28,40 +29,44 @@ Wizard::UnshieldThread::UnshieldThread(QObject *parent) :
mInstallMorrowind = false; mInstallMorrowind = false;
mInstallTribunal = false; mInstallTribunal = false;
mInstallBloodmoon = false; mInstallBloodmoon = false;
}
Wizard::UnshieldWorker::~UnshieldWorker()
{
} }
void Wizard::UnshieldThread::setInstallMorrowind(bool install) void Wizard::UnshieldWorker::setInstallMorrowind(bool install)
{ {
mInstallMorrowind = install; mInstallMorrowind = install;
} }
void Wizard::UnshieldThread::setInstallTribunal(bool install) void Wizard::UnshieldWorker::setInstallTribunal(bool install)
{ {
mInstallTribunal = install; mInstallTribunal = install;
} }
void Wizard::UnshieldThread::setInstallBloodmoon(bool install) void Wizard::UnshieldWorker::setInstallBloodmoon(bool install)
{ {
mInstallBloodmoon = install; mInstallBloodmoon = install;
} }
void Wizard::UnshieldThread::setPath(const QString &path) void Wizard::UnshieldWorker::setPath(const QString &path)
{ {
mPath = path; mPath = path;
} }
void Wizard::UnshieldThread::setIniPath(const QString &path) void Wizard::UnshieldWorker::setIniPath(const QString &path)
{ {
mIniPath = path; mIniPath = path;
} }
void Wizard::UnshieldThread::setIniCodec(QTextCodec *codec) void Wizard::UnshieldWorker::setIniCodec(QTextCodec *codec)
{ {
mIniCodec = codec; mIniCodec = codec;
} }
void Wizard::UnshieldThread::setupSettings() void Wizard::UnshieldWorker::setupSettings()
{ {
// Create Morrowind.ini settings map // Create Morrowind.ini settings map
if (mIniPath.isEmpty()) if (mIniPath.isEmpty())
@ -88,7 +93,7 @@ void Wizard::UnshieldThread::setupSettings()
mIniSettings.readFile(stream); mIniSettings.readFile(stream);
} }
bool Wizard::UnshieldThread::removeDirectory(const QString &dirName) bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
{ {
bool result = true; bool result = true;
QDir dir(dirName); QDir dir(dirName);
@ -114,7 +119,7 @@ bool Wizard::UnshieldThread::removeDirectory(const QString &dirName)
return result; return result;
} }
bool Wizard::UnshieldThread::moveFile(const QString &source, const QString &destination) bool Wizard::UnshieldWorker::moveFile(const QString &source, const QString &destination)
{ {
QDir dir; QDir dir;
QFile file; QFile file;
@ -132,7 +137,7 @@ bool Wizard::UnshieldThread::moveFile(const QString &source, const QString &dest
return false; 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 sourceDir(source);
QDir destDir(destination); QDir destDir(destination);
@ -173,7 +178,7 @@ bool Wizard::UnshieldThread::moveDirectory(const QString &source, const QString
return result && removeDirectory(sourceDir.absolutePath()); return result && removeDirectory(sourceDir.absolutePath());
} }
void Wizard::UnshieldThread::extract() void Wizard::UnshieldWorker::extract()
{ {
emit textChanged(QLatin1String("Starting installation")); emit textChanged(QLatin1String("Starting installation"));
emit textChanged(QLatin1String("Installation target: ") + mPath); emit textChanged(QLatin1String("Installation target: ") + mPath);
@ -211,22 +216,23 @@ void Wizard::UnshieldThread::extract()
QString morrowindTempPath(tempPath + QLatin1String("/morrowind")); QString morrowindTempPath(tempPath + QLatin1String("/morrowind"));
QString morrowindCab(QLatin1String("/mnt/cdrom/data1.hdr")); QString morrowindCab(QLatin1String("/mnt/cdrom/data1.hdr"));
extractCab(morrowindCab, morrowindTempPath); //extractCab(morrowindCab, morrowindTempPath);
// 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
//qDebug() << "rename: " << morrowindTempPath << " to: " << mPath; //qDebug() << "rename: " << morrowindTempPath << " to: " << mPath;
morrowindTempPath.append(QDir::separator() + QLatin1String("Data Files")); morrowindTempPath.append(QDir::separator() + QLatin1String("Data Files"));
if (!moveDirectory(morrowindTempPath, mPath)) // if (!moveDirectory(morrowindTempPath, mPath))
qDebug() << "failed!"; // qDebug() << "failed!";
QDir source(QLatin1String("/mnt/cdrom/")); QDir sourceDir(QLatin1String("/mnt/cdrom/"));
QStringList directories; QStringList directories;
directories << QLatin1String("Fonts") directories << QLatin1String("Fonts")
<< QLatin1String("Music") << QLatin1String("Music")
<< QLatin1String("Sound") << QLatin1String("Sound")
<< QLatin1String("Splash"); << QLatin1String("Splash")
<< QLatin1String("Video");
QFileInfoList list(sourceDir.entryInfoList(QDir::NoDotAndDotDot | QFileInfoList list(sourceDir.entryInfoList(QDir::NoDotAndDotDot |
QDir::System | QDir::Hidden | QDir::System | QDir::Hidden |
@ -237,27 +243,13 @@ void Wizard::UnshieldThread::extract()
if (info.isSymLink()) if (info.isSymLink())
continue; continue;
qDebug() << "not found " << info.fileName();
if (directories.contains(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) // 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; bool success;
QString path(outputDir); QString path(outputDir);
@ -344,7 +337,7 @@ bool Wizard::UnshieldThread::extractFile(Unshield *unshield, const QString &outp
return success; 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;
unshield = unshield_open(cabFile.toLatin1().constData()); unshield = unshield_open(cabFile.toLatin1().constData());
@ -366,11 +359,3 @@ void Wizard::UnshieldThread::extractCab(const QString &cabFile, const QString &o
unshield_close(unshield); unshield_close(unshield);
} }
void Wizard::UnshieldThread::run()
{
qDebug() << "From worker thread: " << currentThreadId();
setupSettings();
extract();
}

View file

@ -1,22 +1,22 @@
#ifndef UNSHIELDTHREAD_HPP #ifndef UNSHIELDWORKER_HPP
#define UNSHIELDTHREAD_HPP #define UNSHIELDWORKER_HPP
#include <QObject>
#include <QThread> #include <QThread>
#include <libunshield.h> #include <libunshield.h>
#include "inisettings.hpp" #include "../inisettings.hpp"
class QTextCodec;
namespace Wizard namespace Wizard
{ {
class UnshieldWorker : public QObject
class UnshieldThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UnshieldThread(QObject *parent = 0); UnshieldWorker(QObject *parent = 0);
~UnshieldWorker();
void setInstallMorrowind(bool install); void setInstallMorrowind(bool install);
void setInstallTribunal(bool install); void setInstallTribunal(bool install);
@ -35,7 +35,6 @@ namespace Wizard
bool moveDirectory(const QString &source, const QString &destination); bool moveDirectory(const QString &source, const QString &destination);
void setupSettings(); void setupSettings();
void extract();
void extractCab(const QString &cabFile, const QString &outputDir); void extractCab(const QString &cabFile, const QString &outputDir);
bool extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter); bool extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter);
@ -52,15 +51,18 @@ namespace Wizard
QTextCodec *mIniCodec; QTextCodec *mIniCodec;
protected:
virtual void run(); public slots:
void extract();
signals: signals:
void finished();
void textChanged(const QString &text); void textChanged(const QString &text);
void error(const QString &text);
void progressChanged(int progress); void progressChanged(int progress);
};
};
} }
#endif // UNSHIELDTHREAD_HPP #endif // UNSHIELDWORKER_HPP