From 82854ab6e9e2dce76ad3441e32a2667b939aad6f Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Tue, 13 May 2014 14:24:23 +1000 Subject: [PATCH] When downloading linuxq3apoint-1.32b-3.x86.run, skip writing the first 8251 bytes so a valid tar.gz file is written. --- installwizard_patch.cpp | 24 ++++++++++++++++++++++-- installwizard_patch.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/installwizard_patch.cpp b/installwizard_patch.cpp index bc41f07..51a9971 100644 --- a/installwizard_patch.cpp +++ b/installwizard_patch.cpp @@ -10,7 +10,8 @@ InstallWizard_Patch::InstallWizard_Patch(QWidget *parent) : patchFile(NULL), networkReply(NULL), isCancelled(false), - isDownloadFinished(false) + isDownloadFinished(false), + usePatchFileBuffer(true) { ui->setupUi(this); } @@ -24,6 +25,8 @@ InstallWizard_Patch::~InstallWizard_Patch() void InstallWizard_Patch::initializePage() { isCancelled = isDownloadFinished = false; + patchFileBuffer.clear(); + usePatchFileBuffer = true; patchFile = new QTemporaryFile; patchFile->open(); @@ -57,7 +60,24 @@ void InstallWizard_Patch::cancel() void InstallWizard_Patch::downloadRead() { - patchFile->write(networkReply->readAll()); + // Skip the first n bytes, giving a valid tar.gz file. + if (usePatchFileBuffer) + { + const qint64 bytesToSkip = 8251; + + patchFileBuffer.append(networkReply->readAll()); + + if (patchFileBuffer.length() > bytesToSkip + 1) + { + patchFile->write(&patchFileBuffer.data()[bytesToSkip], patchFileBuffer.length() - bytesToSkip); + usePatchFileBuffer = false; + patchFileBuffer.clear(); + } + } + else + { + patchFile->write(networkReply->readAll()); + } } void InstallWizard_Patch::downloadProgress(qint64 bytesRead, qint64 bytesTotal) diff --git a/installwizard_patch.h b/installwizard_patch.h index bac9dcd..5ae352a 100644 --- a/installwizard_patch.h +++ b/installwizard_patch.h @@ -33,6 +33,8 @@ private: QNetworkReply *networkReply; bool isCancelled; bool isDownloadFinished; + bool usePatchFileBuffer; + QByteArray patchFileBuffer; }; #endif // INSTALLWIZARD_PATCH_H