From 36883f0eee6f2266ddd9d7bd59aff5a7f4e1aa1f Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Thu, 15 May 2014 14:20:50 +1000 Subject: [PATCH] Have the "copy" wizard page take a list of files to copy, rather than copying a predefined file. --- installwizard.cpp | 13 ++++++++ installwizard.h | 10 ++++++ installwizard_copy.cpp | 63 ++++++++++++++++++----------------- installwizard_copy.h | 8 +++-- installwizard_eula.cpp | 2 +- installwizard_installtype.cpp | 4 +-- 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/installwizard.cpp b/installwizard.cpp index 2c55605..1b8003b 100644 --- a/installwizard.cpp +++ b/installwizard.cpp @@ -36,6 +36,19 @@ InstallWizard::~InstallWizard() delete ui; } +void InstallWizard::addCopyFile(const QString &source, const QString &dest) +{ + CopyFile cf; + cf.source = source; + cf.dest = dest; + copyFiles.append(cf); +} + +const QList &InstallWizard::getCopyFiles() const +{ + return copyFiles; +} + void InstallWizard::cancel() { if (currentId() == Page_Copy) diff --git a/installwizard.h b/installwizard.h index c4aa641..2344f98 100644 --- a/installwizard.h +++ b/installwizard.h @@ -18,6 +18,15 @@ public: explicit InstallWizard(QWidget *parent, Settings *settings); ~InstallWizard(); + struct CopyFile + { + QString source; + QString dest; + }; + + void addCopyFile(const QString &source, const QString &dest); + const QList &getCopyFiles() const; + enum { Page_InstallType, @@ -35,6 +44,7 @@ private: Ui::InstallWizard *ui; QPushButton *cancelButton; Settings *settings; + QList copyFiles; }; #endif // INSTALLWIZARD_H diff --git a/installwizard_copy.cpp b/installwizard_copy.cpp index 16535c7..8dc3d11 100644 --- a/installwizard_copy.cpp +++ b/installwizard_copy.cpp @@ -4,49 +4,49 @@ #include "installwizard_copy.h" #include "ui_installwizard_copy.h" -CopyWorker::CopyWorker() : isCancelled(false) +CopyWorker::CopyWorker(const QList ©Files) : copyFiles(copyFiles), isCancelled(false) { } -void CopyWorker::copy(const QString &source, const QString &destination) +void CopyWorker::copy() { - QFile sourceFile(source); - - if (!sourceFile.open(QIODevice::ReadOnly)) + for (int i = 0; i < copyFiles.size(); i++) { - emit errorMessage(QString("'%1': %2").arg(source).arg(sourceFile.errorString())); - return; - } + QFile sourceFile(copyFiles.at(i).source); - QFile destinationFile(destination); + if (!sourceFile.open(QIODevice::ReadOnly)) + { + emit errorMessage(QString("'%1': %2").arg(copyFiles.at(i).source).arg(sourceFile.errorString())); + return; + } - if (!destinationFile.open(QIODevice::WriteOnly)) - { - emit errorMessage(QString("'%1': %2").arg(destination).arg(destinationFile.errorString())); - return; - } + QFile destinationFile(copyFiles.at(i).dest); - const qint64 totalBytes = sourceFile.size(); - qint64 totalBytesWritten = 0; + if (!destinationFile.open(QIODevice::WriteOnly)) + { + emit errorMessage(QString("'%1': %2").arg(copyFiles.at(i).dest).arg(destinationFile.errorString())); + return; + } - for (;;) - { - const qint64 bytesRead = sourceFile.read(buffer, bufferSize); + const qint64 totalBytes = sourceFile.size(); + qint64 totalBytesWritten = 0; - if (bytesRead == 0) - break; + for (;;) + { + const qint64 bytesRead = sourceFile.read(buffer, bufferSize); - const qint64 bytesWritten = destinationFile.write(buffer, bytesRead); - totalBytesWritten += bytesWritten; - emit progressChanged(totalBytesWritten, totalBytes); + if (bytesRead == 0) + break; - /*if (totalBytesWritten > 1024 * 1024 * 10) - break;*/ + const qint64 bytesWritten = destinationFile.write(buffer, bytesRead); + totalBytesWritten += bytesWritten; + emit progressChanged(totalBytesWritten, totalBytes); - QMutexLocker locker(&cancelMutex); + QMutexLocker locker(&cancelMutex); - if (isCancelled) - break; + if (isCancelled) + break; + } } emit copyFinished(); @@ -89,7 +89,7 @@ void InstallWizard_Copy::initializePage() } // Start copy thread. - copyWorker = new CopyWorker; + copyWorker = new CopyWorker(((InstallWizard *)wizard())->getCopyFiles()); copyWorker->moveToThread(©Thread); connect(©Thread, &QThread::finished, copyWorker, &QObject::deleteLater); connect(this, &InstallWizard_Copy::copy, copyWorker, &CopyWorker::copy); @@ -97,7 +97,8 @@ void InstallWizard_Copy::initializePage() connect(copyWorker, &CopyWorker::errorMessage, this, &InstallWizard_Copy::setCopyErrorMessage); connect(copyWorker, &CopyWorker::copyFinished, this, &InstallWizard_Copy::finishCopy); copyThread.start(); - emit copy(field("pak0").toString(), quake3Path + QString("/pak0.pk3")); + + emit copy(); } bool InstallWizard_Copy::isComplete() const diff --git a/installwizard_copy.h b/installwizard_copy.h index 560aa45..2202a54 100644 --- a/installwizard_copy.h +++ b/installwizard_copy.h @@ -4,6 +4,7 @@ #include #include #include +#include "installwizard.h" namespace Ui { class InstallWizard_Copy; @@ -14,11 +15,11 @@ class CopyWorker : public QObject Q_OBJECT public: - CopyWorker(); + CopyWorker(const QList ©Files); void cancel(); public slots: - void copy(const QString &source, const QString &destination); + void copy(); signals: void progressChanged(qint64 bytesWritten, qint64 bytesTotal); @@ -27,6 +28,7 @@ signals: private: static const int bufferSize = 32 * 1024; + const QList copyFiles; char buffer[bufferSize]; bool isCancelled; QMutex cancelMutex; @@ -49,7 +51,7 @@ private slots: void finishCopy(); signals: - void copy(const QString &source, const QString &destination); + void copy(); private: Ui::InstallWizard_Copy *ui; diff --git a/installwizard_eula.cpp b/installwizard_eula.cpp index 204a5ba..f2ae813 100644 --- a/installwizard_eula.cpp +++ b/installwizard_eula.cpp @@ -16,7 +16,7 @@ InstallWizard_Eula::~InstallWizard_Eula() int InstallWizard_Eula::nextId() const { - if (!field("pak0").toString().isEmpty()) + if (!((InstallWizard *)wizard())->getCopyFiles().isEmpty()) { return InstallWizard::Page_Copy; } diff --git a/installwizard_installtype.cpp b/installwizard_installtype.cpp index 9736779..f7ea87b 100644 --- a/installwizard_installtype.cpp +++ b/installwizard_installtype.cpp @@ -35,8 +35,6 @@ void InstallWizard_InstallType::initializePage() // Use the same default install directory as the Q3A installer. ui->txtInstallDest->setText(QString(qgetenv("PROGRAMFILES").constData()) + QString("\\Quake III Arena")); #endif - - registerField("pak0", ui->txtInstallSource); } bool InstallWizard_InstallType::validatePage() @@ -49,6 +47,8 @@ bool InstallWizard_InstallType::validatePage() return false; } + // Copy page will copy pak0.pk3. + ((InstallWizard *)wizard())->addCopyFile(ui->txtInstallSource->text(), ui->txtInstallDest->text() + QString("/baseq3/pak0.pk3")); registerField("quake3Path", ui->txtInstallDest); } #ifdef Q_OS_WIN32