When downloading linuxq3apoint-1.32b-3.x86.run, skip writing the first 8251 bytes so a valid tar.gz file is written.

This commit is contained in:
Jonathan Young 2014-05-13 14:24:23 +10:00
parent 8f22984ca1
commit 82854ab6e9
2 changed files with 24 additions and 2 deletions

View file

@ -10,7 +10,8 @@ InstallWizard_Patch::InstallWizard_Patch(QWidget *parent) :
patchFile(NULL), patchFile(NULL),
networkReply(NULL), networkReply(NULL),
isCancelled(false), isCancelled(false),
isDownloadFinished(false) isDownloadFinished(false),
usePatchFileBuffer(true)
{ {
ui->setupUi(this); ui->setupUi(this);
} }
@ -24,6 +25,8 @@ InstallWizard_Patch::~InstallWizard_Patch()
void InstallWizard_Patch::initializePage() void InstallWizard_Patch::initializePage()
{ {
isCancelled = isDownloadFinished = false; isCancelled = isDownloadFinished = false;
patchFileBuffer.clear();
usePatchFileBuffer = true;
patchFile = new QTemporaryFile; patchFile = new QTemporaryFile;
patchFile->open(); patchFile->open();
@ -56,9 +59,26 @@ void InstallWizard_Patch::cancel()
} }
void InstallWizard_Patch::downloadRead() void InstallWizard_Patch::downloadRead()
{
// 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()); patchFile->write(networkReply->readAll());
} }
}
void InstallWizard_Patch::downloadProgress(qint64 bytesRead, qint64 bytesTotal) void InstallWizard_Patch::downloadProgress(qint64 bytesRead, qint64 bytesTotal)
{ {

View file

@ -33,6 +33,8 @@ private:
QNetworkReply *networkReply; QNetworkReply *networkReply;
bool isCancelled; bool isCancelled;
bool isDownloadFinished; bool isDownloadFinished;
bool usePatchFileBuffer;
QByteArray patchFileBuffer;
}; };
#endif // INSTALLWIZARD_PATCH_H #endif // INSTALLWIZARD_PATCH_H