mirror of
https://github.com/ioquake/launch.git
synced 2024-11-24 20:21:06 +00:00
Have the "copy" wizard page take a list of files to copy, rather than copying a predefined file.
This commit is contained in:
parent
91d101dee1
commit
36883f0eee
6 changed files with 63 additions and 37 deletions
|
@ -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::CopyFile> &InstallWizard::getCopyFiles() const
|
||||
{
|
||||
return copyFiles;
|
||||
}
|
||||
|
||||
void InstallWizard::cancel()
|
||||
{
|
||||
if (currentId() == Page_Copy)
|
||||
|
|
|
@ -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<CopyFile> &getCopyFiles() const;
|
||||
|
||||
enum
|
||||
{
|
||||
Page_InstallType,
|
||||
|
@ -35,6 +44,7 @@ private:
|
|||
Ui::InstallWizard *ui;
|
||||
QPushButton *cancelButton;
|
||||
Settings *settings;
|
||||
QList<CopyFile> copyFiles;
|
||||
};
|
||||
|
||||
#endif // INSTALLWIZARD_H
|
||||
|
|
|
@ -4,49 +4,49 @@
|
|||
#include "installwizard_copy.h"
|
||||
#include "ui_installwizard_copy.h"
|
||||
|
||||
CopyWorker::CopyWorker() : isCancelled(false)
|
||||
CopyWorker::CopyWorker(const QList<InstallWizard::CopyFile> ©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
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QMutex>
|
||||
#include <QThread>
|
||||
#include <QWizardPage>
|
||||
#include "installwizard.h"
|
||||
|
||||
namespace Ui {
|
||||
class InstallWizard_Copy;
|
||||
|
@ -14,11 +15,11 @@ class CopyWorker : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CopyWorker();
|
||||
CopyWorker(const QList<InstallWizard::CopyFile> ©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<InstallWizard::CopyFile> 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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue