diff options
5 files changed, 105 insertions, 44 deletions
diff --git a/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.cpp b/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.cpp index c23badb5b..59fd625e5 100644 --- a/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.cpp +++ b/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.cpp @@ -325,7 +325,7 @@ struct KDUpdater::LocalFileDownloader::LocalFileDownloaderData downloaded(false), timerId(-1) { } QFile* source; - QTemporaryFile* destination; + QFile* destination; QString destFileName; bool downloaded; int timerId; @@ -370,8 +370,6 @@ void KDUpdater::LocalFileDownloader::doDownload() // Open source and destination files QString localFile = this->url().toLocalFile(); d->source = new QFile(localFile, this); - d->destination = new QTemporaryFile(this); - if( !d->source->open(QFile::ReadOnly) ) { onError(); @@ -379,7 +377,15 @@ void KDUpdater::LocalFileDownloader::doDownload() return; } - if( !d->destination->open() ) + if (d->destFileName.isEmpty()) { + QTemporaryFile *file = new QTemporaryFile(this); + file->open(); + d->destination = file; + } else { + d->destination = new QFile(d->destFileName, this); + d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate); + } + if( !d->destination->isOpen() ) { onError(); setDownloadAborted(tr("Cannot open destination file for writing.")); @@ -397,6 +403,11 @@ QString KDUpdater::LocalFileDownloader::downloadedFileName() const return d->destFileName; } +void KDUpdater::LocalFileDownloader::setDownloadedFileName(const QString &name) +{ + d->destFileName = name; +} + KDUpdater::LocalFileDownloader* KDUpdater::LocalFileDownloader::clone( QObject* parent ) const { return new LocalFileDownloader( parent ); @@ -453,7 +464,8 @@ void LocalFileDownloader::onSuccess() { d->downloaded = true; d->destFileName = d->destination->fileName(); - d->destination->setAutoRemove( false ); + if (QTemporaryFile *file = dynamic_cast<QTemporaryFile*> (d->destination)) + file->setAutoRemove( false ); d->destination->close(); delete d->destination; d->destination = 0; @@ -535,6 +547,11 @@ QString KDUpdater::ResourceFileDownloader::downloadedFileName() const return d->destFileName; } +void KDUpdater::ResourceFileDownloader::setDownloadedFileName(const QString &/*name*/) +{ + Q_ASSERT_X(false, "KDUpdater::ResourceFileDownloader::setDownloadedFileName", "Not supported!"); +} + KDUpdater::ResourceFileDownloader* KDUpdater::ResourceFileDownloader::clone( QObject* parent ) const { return new ResourceFileDownloader( parent ); @@ -578,7 +595,7 @@ struct KDUpdater::FtpDownloader::FtpDownloaderData downloaded(false), ftpCmdId(-1), aborted(false) { } QFtp* ftp; - QTemporaryFile* destination; + QFile* destination; QString destFileName; bool downloaded; int ftpCmdId; @@ -634,6 +651,11 @@ QString KDUpdater::FtpDownloader::downloadedFileName() const return d->destFileName; } +void KDUpdater::FtpDownloader::setDownloadedFileName(const QString &name) +{ + d->destFileName = name; +} + KDUpdater::FtpDownloader* KDUpdater::FtpDownloader::clone( QObject* parent ) const { return new FtpDownloader( parent ); @@ -697,7 +719,8 @@ void FtpDownloader::onSuccess() { d->downloaded = true; d->destFileName = d->destination->fileName(); - d->destination->setAutoRemove( false ); + if (QTemporaryFile *file = dynamic_cast<QTemporaryFile*> (d->destination)) + file->setAutoRemove( false ); delete d->destination; d->destination = 0; @@ -718,8 +741,14 @@ void KDUpdater::FtpDownloader::ftpStateChanged(int state) { case QFtp::Connected: // begin the download - d->destination = new QTemporaryFile(this); - d->destination->open(); //PENDING handle error + if (d->destFileName.isEmpty()) { + QTemporaryFile *file = new QTemporaryFile(this); + file->open(); //PENDING handle error + d->destination = file; + } else { + d->destination = new QFile(d->destFileName, this); + d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate); + } d->ftpCmdId = d->ftp->get( url().path(), d->destination ); break; case QFtp::Unconnected: @@ -751,7 +780,7 @@ struct KDUpdater::HttpDownloader::HttpDownloaderData HttpDownloader* const q; QNetworkAccessManager manager; QNetworkReply* http; - QTemporaryFile* destination; + QFile* destination; QString destFileName; bool downloaded; bool aborted; @@ -817,8 +846,15 @@ void KDUpdater::HttpDownloader::doDownload() */ // Begin the download - d->destination = new QTemporaryFile(this); - if ( !d->destination->open() ) { + if (d->destFileName.isEmpty()) { + QTemporaryFile *file = new QTemporaryFile(this); + file->open(); + d->destination = file; + } else { + d->destination = new QFile(d->destFileName, this); + d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate); + } + if ( !d->destination->isOpen() ) { const QString err = d->destination->errorString(); d->shutDown(); setDownloadAborted( tr("Cannot download %1: Could not create temporary file: %2").arg( url().toString(), err ) ); @@ -831,6 +867,11 @@ QString KDUpdater::HttpDownloader::downloadedFileName() const return d->destFileName; } +void KDUpdater::HttpDownloader::setDownloadedFileName(const QString &name) +{ + d->destFileName = name; +} + KDUpdater::HttpDownloader* KDUpdater::HttpDownloader::clone( QObject* parent ) const { return new HttpDownloader( parent ); @@ -920,7 +961,8 @@ void KDUpdater::HttpDownloader::onSuccess() { d->downloaded = true; d->destFileName = d->destination->fileName(); - d->destination->setAutoRemove( false ); + if (QTemporaryFile *file = dynamic_cast<QTemporaryFile*> (d->destination)) + file->setAutoRemove( false ); delete d->destination; d->destination = 0; } @@ -948,8 +990,14 @@ void KDUpdater::HttpDownloader::httpReqFinished() connect( d->http, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( httpError( QNetworkReply::NetworkError ) ) ); // Begin the download - d->destination = new QTemporaryFile(this); - d->destination->open(); //PENDING handle error + if (d->destFileName.isEmpty()) { + QTemporaryFile *file = new QTemporaryFile(this); + file->open(); //PENDING handle error + d->destination = file; + } else { + d->destination = new QFile(d->destFileName, this); + d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate); + } } else { @@ -1043,6 +1091,11 @@ QString SignatureVerificationDownloader::downloadedFileName() const return d->downloadedFileName; } +void SignatureVerificationDownloader::setDownloadedFileName(const QString &/*name*/) +{ + Q_ASSERT_X(false, "SignatureVerificationDownloader::setDownloadedFileName", "Not supported!"); +} + FileDownloader* SignatureVerificationDownloader::clone( QObject* parent ) const { return new SignatureVerificationDownloader( d->downloader->clone(), parent ); diff --git a/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.h b/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.h index 754917aa8..00ca58c1a 100644 --- a/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.h +++ b/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader.h @@ -60,6 +60,7 @@ namespace KDUpdater virtual bool canDownload() const = 0; virtual bool isDownloaded() const = 0; virtual QString downloadedFileName() const = 0; + virtual void setDownloadedFileName(const QString &name) = 0; virtual FileDownloader* clone( QObject* parent=0 ) const = 0; void download(); diff --git a/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader_p.h b/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader_p.h index 841e48c03..06d3b9734 100644 --- a/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader_p.h +++ b/installerbuilder/libinstaller/3rdparty/kdtools/KDUpdater/kdupdaterfiledownloader_p.h @@ -83,6 +83,7 @@ namespace KDUpdater bool canDownload() const; bool isDownloaded() const; QString downloadedFileName() const; + /* reimp */ void setDownloadedFileName(const QString &name); /* reimp */ LocalFileDownloader* clone( QObject* parent=0 ) const; public Q_SLOTS: @@ -112,6 +113,7 @@ namespace KDUpdater bool canDownload() const; bool isDownloaded() const; QString downloadedFileName() const; + /* reimp */ void setDownloadedFileName(const QString &name); /* reimp */ ResourceFileDownloader* clone( QObject* parent=0 ) const; public Q_SLOTS: @@ -141,6 +143,7 @@ namespace KDUpdater bool canDownload() const; bool isDownloaded() const; QString downloadedFileName() const; + /* reimp */ void setDownloadedFileName(const QString &name); /* reimp */ FtpDownloader* clone( QObject* parent=0 ) const; public Q_SLOTS: @@ -174,6 +177,7 @@ namespace KDUpdater bool canDownload() const; bool isDownloaded() const; QString downloadedFileName() const; + /* reimp */ void setDownloadedFileName(const QString &name); /* reimp */ HttpDownloader* clone( QObject* parent=0 ) const; public Q_SLOTS: @@ -217,6 +221,7 @@ namespace KDUpdater /* reimp */ bool canDownload() const; /* reimp */ bool isDownloaded() const; /* reimp */ QString downloadedFileName() const; + /* reimp */ void setDownloadedFileName(const QString &name); /* reimp */ FileDownloader* clone( QObject* parent=0 ) const; public Q_SLOTS: diff --git a/installerbuilder/libinstaller/downloadarchivesjob.cpp b/installerbuilder/libinstaller/downloadarchivesjob.cpp index 5c0f19697..1db8a9c6c 100644 --- a/installerbuilder/libinstaller/downloadarchivesjob.cpp +++ b/installerbuilder/libinstaller/downloadarchivesjob.cpp @@ -127,19 +127,15 @@ void DownloadArchivesJob::fetchNextArchiveHash() if (m_downloader) m_downloader->deleteLater(); - QString hashUrl = m_archivesToDownload.first().second; - const QUrl url(hashUrl + QLatin1String(".sha1")); - const QUrl sigUrl = m_publicKey.isEmpty() ? QUrl() : QUrl(m_archivesToDownload.first().second - + QLatin1String(".sig")); const CryptoSignatureVerifier verifier(m_publicKey); + const QUrl url(m_archivesToDownload.first().second + QLatin1String(".sha1")); m_downloader = FileDownloaderFactory::instance().create(url.scheme(), m_publicKey.isEmpty() ? 0 - : &verifier, sigUrl, this); + : &verifier, QUrl(m_archivesToDownload.first().second + QLatin1String(".sig")), this); + const QString &scheme = url.scheme(); if (!m_downloader) { - m_archivesToDownload.pop_front(); - const QString errMsg = tr("Scheme not supported: %1 (%2)").arg(url.scheme(), url.toString()); - verbose() << errMsg << std::endl; - emit outputTextChanged(errMsg); + m_archivesToDownload.removeFirst(); + emit outputTextChanged(tr("Scheme not supported: %1 (%2)").arg(scheme, url.toString())); QMetaObject::invokeMethod(this, "fetchNextArchiveHash", Qt::QueuedConnection); return; } @@ -154,8 +150,13 @@ void DownloadArchivesJob::fetchNextArchiveHash() m_downloader->setUrl(url); m_downloader->setAutoRemoveDownloadedFile(false); - const QString comp = QFileInfo(QFileInfo(m_archivesToDownload.first().first).path()).fileName(); - const Component *const component = m_core->componentByName(comp); + const QFileInfo fi = QFileInfo(m_archivesToDownload.first().first); + const Component *const component = m_core->componentByName(QFileInfo(fi.path()).fileName()); + if (scheme == QLatin1String("http") || scheme == QLatin1String("ftp") + || scheme == QLatin1String("file")) { + m_downloader->setDownloadedFileName(component->localTempPath() + QLatin1String("/") + + component->name() + QLatin1String("/") + fi.fileName() + QLatin1String(".sha1")); + } emit outputTextChanged(tr("Downloading archive hash for component: %1").arg(component->displayName())); m_downloader->download(); @@ -175,7 +176,7 @@ void DownloadArchivesJob::finishedHashDownload() else finishWithError(tr("Downloading hash signature failed.")); - m_temporaryFiles.push_back(tempFile); + m_temporaryFiles.insert(tempFile); fetchNextArchive(); } @@ -198,18 +199,15 @@ void DownloadArchivesJob::fetchNextArchive() if (m_downloader != 0) m_downloader->deleteLater(); - const QUrl url(m_archivesToDownload.first().second); - const QUrl sigUrl = m_publicKey.isEmpty() ? QUrl() : QUrl(m_archivesToDownload.first().second - + QLatin1String(".sig")); const CryptoSignatureVerifier verifier(m_publicKey); + const QUrl url(m_archivesToDownload.first().second); m_downloader = FileDownloaderFactory::instance().create(url.scheme(), m_publicKey.isEmpty() ? 0 - : &verifier, sigUrl, this); + : &verifier, m_archivesToDownload.first().second + QLatin1String(".sig"), this); + const QString &scheme = url.scheme(); if (!m_downloader) { - m_archivesToDownload.pop_front(); - const QString errMsg = tr("Scheme not supported: %1 (%2)").arg(url.scheme(), url.toString()); - verbose() << errMsg; - emit outputTextChanged(errMsg); + m_archivesToDownload.removeFirst(); + emit outputTextChanged(tr("Scheme not supported: %1 (%2)").arg(scheme, url.toString())); QMetaObject::invokeMethod(this, "fetchNextArchive", Qt::QueuedConnection); return; } @@ -222,8 +220,13 @@ void DownloadArchivesJob::fetchNextArchive() m_downloader->setUrl(url); m_downloader->setAutoRemoveDownloadedFile(false); - const QString comp = QFileInfo(QFileInfo(m_archivesToDownload.first().first).path()).fileName(); - const Component* const component = m_core->componentByName(comp); + const QFileInfo fi = QFileInfo(m_archivesToDownload.first().first); + const Component *const component = m_core->componentByName(QFileInfo(fi.path()).fileName()); + if (scheme == QLatin1String("http") || scheme == QLatin1String("ftp") + || scheme == QLatin1String("file")) { + m_downloader->setDownloadedFileName(component->localTempPath() + QLatin1String("/") + + component->name() + QLatin1String("/") + fi.fileName()); + } emit outputTextChanged(tr("Downloading archive for component: %1").arg(component->displayName())); emit progressChanged(double(m_archivesDownloaded) / m_archivesToDownloadCount); @@ -296,11 +299,10 @@ void DownloadArchivesJob::registerFile() finishWithError(tr("Could not open %1").arg(tempFile)); } - const QString path = m_archivesToDownload.first().first; - m_archivesToDownload.pop_front(); - m_temporaryFiles.push_back(tempFile); - - QInstallerCreator::BinaryFormatEngineHandler::instance()->registerArchive(path, tempFile); + m_temporaryFiles.insert(tempFile); + m_archivesToDownload.removeFirst(); + QInstallerCreator::BinaryFormatEngineHandler::instance()->registerArchive(m_archivesToDownload.first() + .first, tempFile); fetchNextArchiveHash(); } diff --git a/installerbuilder/libinstaller/downloadarchivesjob.h b/installerbuilder/libinstaller/downloadarchivesjob.h index 15cd888b5..555c4b933 100644 --- a/installerbuilder/libinstaller/downloadarchivesjob.h +++ b/installerbuilder/libinstaller/downloadarchivesjob.h @@ -29,7 +29,7 @@ #include <KDToolsCore/KDJob> #include <QtCore/QPair> -#include <QtCore/QStringList> +#include <QtCore/QSet> QT_BEGIN_NAMESPACE class QTimerEvent; @@ -83,7 +83,7 @@ private: bool m_canceled; const QByteArray m_publicKey; - QStringList m_temporaryFiles; + QSet<QString> m_temporaryFiles; QByteArray m_currentHash; double m_lastFileProgress; int m_progressChangedTimerId; |