mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-06 09:39:49 +00:00
Working on the installshield thread
This commit is contained in:
parent
40486370d9
commit
3a55d88bac
@ -1,11 +1,7 @@
|
|||||||
#include "installationpage.hpp"
|
#include "installationpage.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QMessageBox>
|
|
||||||
|
|
||||||
#include "mainwizard.hpp"
|
#include "mainwizard.hpp"
|
||||||
#include "inisettings.hpp"
|
#include "inisettings.hpp"
|
||||||
@ -16,6 +12,8 @@ Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
|
|||||||
mWizard(wizard)
|
mWizard(wizard)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
|
mFinished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::InstallationPage::initializePage()
|
void Wizard::InstallationPage::initializePage()
|
||||||
@ -49,51 +47,7 @@ void Wizard::InstallationPage::initializePage()
|
|||||||
|
|
||||||
installProgressBar->setValue(100);
|
installProgressBar->setValue(100);
|
||||||
|
|
||||||
if (field("installation.new").toBool() == false)
|
|
||||||
setupSettings();
|
|
||||||
|
|
||||||
startInstallation();
|
startInstallation();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Wizard::InstallationPage::setupSettings()
|
|
||||||
{
|
|
||||||
// Test settings
|
|
||||||
IniSettings iniSettings;
|
|
||||||
|
|
||||||
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 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());
|
|
||||||
|
|
||||||
if (language == QLatin1String("Polish")) {
|
|
||||||
stream.setCodec(QTextCodec::codecForName("windows-1250"));
|
|
||||||
}
|
|
||||||
else if (language == QLatin1String("Russian")) {
|
|
||||||
stream.setCodec(QTextCodec::codecForName("windows-1251"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stream.setCodec(QTextCodec::codecForName("windows-1252"));
|
|
||||||
}
|
|
||||||
|
|
||||||
iniSettings.readFile(stream);
|
|
||||||
|
|
||||||
qDebug() << iniSettings.value("Game Files/GameFile0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::InstallationPage::startInstallation()
|
void Wizard::InstallationPage::startInstallation()
|
||||||
@ -115,6 +69,9 @@ void Wizard::InstallationPage::startInstallation()
|
|||||||
connect(unshield, SIGNAL(textChanged(QString)),
|
connect(unshield, SIGNAL(textChanged(QString)),
|
||||||
logTextEdit, SLOT(append(QString)));
|
logTextEdit, SLOT(append(QString)));
|
||||||
|
|
||||||
|
connect(unshield, SIGNAL(progressChanged(int)),
|
||||||
|
installProgressBar, SLOT(setValue(int)));
|
||||||
|
|
||||||
if (field("installation.new").toBool() == true)
|
if (field("installation.new").toBool() == true)
|
||||||
{
|
{
|
||||||
// Always install Morrowind
|
// Always install Morrowind
|
||||||
@ -131,25 +88,40 @@ void Wizard::InstallationPage::startInstallation()
|
|||||||
|
|
||||||
if (components.contains(QLatin1String("Tribunal"))
|
if (components.contains(QLatin1String("Tribunal"))
|
||||||
&& mWizard->mInstallations[path]->hasTribunal == false)
|
&& mWizard->mInstallations[path]->hasTribunal == false)
|
||||||
unshield->setInstallTribunal(false);
|
unshield->setInstallTribunal(true);
|
||||||
|
|
||||||
if (components.contains(QLatin1String("Bloodmoon"))
|
if (components.contains(QLatin1String("Bloodmoon"))
|
||||||
&& mWizard->mInstallations[path]->hasBloodmoon == false)
|
&& mWizard->mInstallations[path]->hasBloodmoon == false)
|
||||||
unshield->setInstallBloodmoon(true);
|
unshield->setInstallBloodmoon(true);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Set the location of the Morrowind.ini to update
|
||||||
|
unshield->setIniPath(mWizard->mInstallations[path]->iniPath);
|
||||||
|
}
|
||||||
|
|
||||||
// Set the installation target path
|
// Set the installation target path
|
||||||
unshield->setPath(path);
|
unshield->setPath(path);
|
||||||
|
|
||||||
|
// Set the right codec to use for Morrowind.ini
|
||||||
|
QString language(field("installation.language").toString());
|
||||||
|
|
||||||
|
if (language == QLatin1String("Polish")) {
|
||||||
|
unshield->setIniCodec(QTextCodec::codecForName("windows-1250"));
|
||||||
|
}
|
||||||
|
else if (language == QLatin1String("Russian")) {
|
||||||
|
unshield->setIniCodec(QTextCodec::codecForName("windows-1251"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unshield->setIniCodec(QTextCodec::codecForName("windows-1252"));
|
||||||
|
}
|
||||||
|
|
||||||
unshield->start();
|
unshield->start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::InstallationPage::installationFinished()
|
void Wizard::InstallationPage::installationFinished()
|
||||||
{
|
{
|
||||||
qDebug() << "Installation finished!";
|
|
||||||
mFinished = true;
|
mFinished = true;
|
||||||
|
emit completeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::InstallationPage::isComplete() const
|
bool Wizard::InstallationPage::isComplete() const
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
#include <QWizardPage>
|
#include <QWizardPage>
|
||||||
|
|
||||||
#include "ui_installationpage.h"
|
#include "ui_installationpage.h"
|
||||||
|
#include "inisettings.hpp"
|
||||||
|
|
||||||
namespace Wizard
|
namespace Wizard
|
||||||
{
|
{
|
||||||
class MainWizard;
|
class MainWizard;
|
||||||
|
class IniSettings;
|
||||||
|
|
||||||
class InstallationPage : public QWizardPage, private Ui::InstallationPage
|
class InstallationPage : public QWizardPage, private Ui::InstallationPage
|
||||||
{
|
{
|
||||||
@ -22,7 +24,6 @@ namespace Wizard
|
|||||||
MainWizard *mWizard;
|
MainWizard *mWizard;
|
||||||
bool mFinished;
|
bool mFinished;
|
||||||
|
|
||||||
void setupSettings();
|
|
||||||
void startInstallation();
|
void startInstallation();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -1,13 +1,28 @@
|
|||||||
#include "unshieldthread.hpp"
|
#include "unshieldthread.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#include <qmath.h>
|
||||||
|
|
||||||
Wizard::UnshieldThread::UnshieldThread(QObject *parent) :
|
Wizard::UnshieldThread::UnshieldThread(QObject *parent) :
|
||||||
QThread(parent)
|
QThread(parent),
|
||||||
|
mIniSettings()
|
||||||
{
|
{
|
||||||
unshield_set_log_level(0);
|
unshield_set_log_level(0);
|
||||||
|
|
||||||
|
mPath = QString();
|
||||||
|
mIniPath = QString();
|
||||||
|
|
||||||
|
// Default to Latin encoding
|
||||||
|
mIniCodec = QTextCodec::codecForName("windows-1252");
|
||||||
|
|
||||||
mInstallMorrowind = false;
|
mInstallMorrowind = false;
|
||||||
mInstallTribunal = false;
|
mInstallTribunal = false;
|
||||||
mInstallBloodmoon = false;
|
mInstallBloodmoon = false;
|
||||||
@ -34,6 +49,43 @@ void Wizard::UnshieldThread::setPath(const QString &path)
|
|||||||
mPath = path;
|
mPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Wizard::UnshieldThread::setIniPath(const QString &path)
|
||||||
|
{
|
||||||
|
mIniPath = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wizard::UnshieldThread::setIniCodec(QTextCodec *codec)
|
||||||
|
{
|
||||||
|
mIniCodec = codec;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wizard::UnshieldThread::setupSettings()
|
||||||
|
{
|
||||||
|
// Create Morrowind.ini settings map
|
||||||
|
if (mIniPath.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFile file(mIniPath);
|
||||||
|
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
// TODO: Emit error signal
|
||||||
|
QMessageBox msgBox;
|
||||||
|
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();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream stream(&file);
|
||||||
|
stream.setCodec(mIniCodec);
|
||||||
|
|
||||||
|
mIniSettings.readFile(stream);
|
||||||
|
}
|
||||||
|
|
||||||
void Wizard::UnshieldThread::extract()
|
void Wizard::UnshieldThread::extract()
|
||||||
{
|
{
|
||||||
emit textChanged(QLatin1String("Starting installation"));
|
emit textChanged(QLatin1String("Starting installation"));
|
||||||
@ -51,11 +103,144 @@ void Wizard::UnshieldThread::extract()
|
|||||||
|
|
||||||
emit textChanged(QLatin1String("Components: ") + components.join(QLatin1String(", ")));
|
emit textChanged(QLatin1String("Components: ") + components.join(QLatin1String(", ")));
|
||||||
|
|
||||||
|
emit textChanged(QLatin1String("Updating Morrowind.ini: ") + mIniPath);
|
||||||
|
|
||||||
|
//emit progressChanged(45);
|
||||||
|
|
||||||
|
///
|
||||||
|
// bfs::path outputDataFilesDir = mOutputPath;
|
||||||
|
// outputDataFilesDir /= "Data Files";
|
||||||
|
// bfs::path extractPath = mOutputPath;
|
||||||
|
// extractPath /= "extract-temp";
|
||||||
|
|
||||||
|
// Create temporary extract directory
|
||||||
|
// TODO: Use QTemporaryDir in Qt 5.0
|
||||||
|
QString tempPath(mPath + QLatin1String("/extract-temp"));
|
||||||
|
QDir dir;
|
||||||
|
dir.mkpath(tempPath);
|
||||||
|
|
||||||
|
if (mInstallMorrowind)
|
||||||
|
{
|
||||||
|
QString morrowindTempPath(tempPath + QLatin1String("/morrowind"));
|
||||||
|
QString morrowindCab(QLatin1String("/mnt/cdrom/data1.hdr"));
|
||||||
|
|
||||||
|
extractCab(morrowindCab, morrowindTempPath);
|
||||||
|
|
||||||
|
// TODO: Throw error;
|
||||||
|
// Move the files from the temporary path to the destination folder
|
||||||
|
|
||||||
|
qDebug() << "rename: " << morrowindTempPath << " to: " << mPath;
|
||||||
|
if (!dir.rename(morrowindTempPath, mPath))
|
||||||
|
qDebug() << "failed!";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(!mMorrowindDone && mMorrowindPath.string().length() > 0)
|
||||||
|
// {
|
||||||
|
// mMorrowindDone = true;
|
||||||
|
|
||||||
|
// bfs::path mwExtractPath = extractPath / "morrowind";
|
||||||
|
// extract_cab(mMorrowindPath, mwExtractPath, true);
|
||||||
|
|
||||||
|
// bfs::path dFilesDir = findFile(mwExtractPath, "morrowind.esm").parent_path();
|
||||||
|
|
||||||
|
// installToPath(dFilesDir, outputDataFilesDir);
|
||||||
|
|
||||||
|
// install_dfiles_outside(mwExtractPath, outputDataFilesDir);
|
||||||
|
|
||||||
|
// // Videos are often kept uncompressed on the cd
|
||||||
|
// bfs::path videosPath = findFile(mMorrowindPath.parent_path(), "video", false);
|
||||||
|
// if(videosPath.string() != "")
|
||||||
|
// {
|
||||||
|
// emit signalGUI(QString("Installing Videos..."));
|
||||||
|
// installToPath(videosPath, outputDataFilesDir / "Video", true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// bfs::path cdDFiles = findFile(mMorrowindPath.parent_path(), "data files", false);
|
||||||
|
// if(cdDFiles.string() != "")
|
||||||
|
// {
|
||||||
|
// emit signalGUI(QString("Installing Uncompressed Data files from CD..."));
|
||||||
|
// installToPath(cdDFiles, outputDataFilesDir, true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// bfs::rename(findFile(mwExtractPath, "morrowind.ini"), outputDataFilesDir / "Morrowind.ini");
|
||||||
|
|
||||||
|
// mTribunalDone = contains(outputDataFilesDir, "tribunal.esm");
|
||||||
|
// mBloodmoonDone = contains(outputDataFilesDir, "bloodmoon.esm");
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wizard::UnshieldThread::extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter)
|
||||||
|
{
|
||||||
|
bool success;
|
||||||
|
QString path(outputDir);
|
||||||
|
path.append('/');
|
||||||
|
|
||||||
|
int directory = unshield_file_directory(unshield, index);
|
||||||
|
|
||||||
|
if (!prefix.isEmpty())
|
||||||
|
path.append(prefix + QLatin1Char('/'));
|
||||||
|
|
||||||
|
if (directory >= 0)
|
||||||
|
path.append(QString::fromLatin1(unshield_directory_name(unshield, directory)) + QLatin1Char('/'));
|
||||||
|
|
||||||
|
// Ensure the target path exists
|
||||||
|
QDir dir;
|
||||||
|
dir.mkpath(path);
|
||||||
|
|
||||||
|
QString fileName(path);
|
||||||
|
fileName.append(QString::fromLatin1(unshield_file_name(unshield, index)));
|
||||||
|
|
||||||
|
// Calculate the percentage done
|
||||||
|
int progress = qCeil(((float) counter / (float) unshield_file_count(unshield)) * 100);
|
||||||
|
|
||||||
|
qDebug() << progress << counter << unshield_file_count(unshield);
|
||||||
|
|
||||||
|
emit textChanged(QLatin1String("Extracting: ") + QString::fromLatin1(unshield_file_name(unshield, index)));
|
||||||
|
emit progressChanged(progress);
|
||||||
|
|
||||||
|
success = unshield_file_save(unshield, index, fileName.toLatin1().constData());
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
dir.remove(fileName);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wizard::UnshieldThread::extractCab(const QString &cabFile, const QString &outputDir)
|
||||||
|
{
|
||||||
|
Unshield *unshield;
|
||||||
|
unshield = unshield_open(cabFile.toLatin1().constData());
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for (int i=0; i<unshield_file_group_count(unshield); ++i)
|
||||||
|
{
|
||||||
|
UnshieldFileGroup *group = unshield_file_group_get(unshield, i);
|
||||||
|
|
||||||
|
for (size_t j=group->first_file; j<=group->last_file; ++j)
|
||||||
|
{
|
||||||
|
if (unshield_file_is_valid(unshield, j)) {
|
||||||
|
extractFile(unshield, outputDir, group->name, j, counter);
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unshield_close(unshield);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::UnshieldThread::run()
|
void Wizard::UnshieldThread::run()
|
||||||
{
|
{
|
||||||
qDebug() << "From worker thread: " << currentThreadId();
|
qDebug() << "From worker thread: " << currentThreadId();
|
||||||
|
|
||||||
|
setupSettings();
|
||||||
extract();
|
extract();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
#include <libunshield.h>
|
#include <libunshield.h>
|
||||||
|
|
||||||
|
#include "inisettings.hpp"
|
||||||
|
|
||||||
|
class QTextCodec;
|
||||||
|
|
||||||
namespace Wizard
|
namespace Wizard
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -19,26 +23,36 @@ namespace Wizard
|
|||||||
void setInstallBloodmoon(bool install);
|
void setInstallBloodmoon(bool install);
|
||||||
|
|
||||||
void setPath(const QString &path);
|
void setPath(const QString &path);
|
||||||
|
void setIniPath(const QString &path);
|
||||||
|
|
||||||
|
void setIniCodec(QTextCodec *codec);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void setupSettings();
|
||||||
void extract();
|
void extract();
|
||||||
|
|
||||||
void extractCab(const QString &cabFile,
|
void extractCab(const QString &cabFile, const QString &outputDir);
|
||||||
const QString &outputDir, bool extractIni);
|
bool extractFile(Unshield *unshield, const QString &outputDir, const QString &prefix, int index, int counter);
|
||||||
//void extractFile(Unshield *unshield,
|
|
||||||
// )
|
|
||||||
|
|
||||||
bool mInstallMorrowind;
|
bool mInstallMorrowind;
|
||||||
bool mInstallTribunal;
|
bool mInstallTribunal;
|
||||||
bool mInstallBloodmoon;
|
bool mInstallBloodmoon;
|
||||||
|
|
||||||
QString mPath;
|
QString mPath;
|
||||||
|
QString mIniPath;
|
||||||
|
|
||||||
|
IniSettings mIniSettings;
|
||||||
|
|
||||||
|
QTextCodec *mIniCodec;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void textChanged(const QString &text);
|
void textChanged(const QString &text);
|
||||||
|
void progressChanged(int progress);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user