From 22ec6aa53e44069c03c7baf94881949c7a4facff Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Tue, 19 May 2015 16:06:33 +0200 Subject: Update documentation and adjust some code to match. Change-Id: I3a8d9afb79628135051e4133bea9fc66e14a514a Reviewed-by: Kai Koehne --- src/libs/installer/lib7z_facade.cpp | 60 +++++++++++++++++++++++++++---------- src/libs/installer/lib7z_facade.h | 45 ++-------------------------- 2 files changed, 48 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/libs/installer/lib7z_facade.cpp b/src/libs/installer/lib7z_facade.cpp index b4eb36d37..3c1a190a3 100644 --- a/src/libs/installer/lib7z_facade.cpp +++ b/src/libs/installer/lib7z_facade.cpp @@ -906,8 +906,15 @@ void ExtractCallback::setCurrentFile(const QString&) { } -bool ExtractCallback::prepareForFile(const QString&) +/*! + Reimplement to prepare for file \a filename to be extracted, e.g. by renaming existing + files. Return \c true if the preparation was successful and extraction can be continued. + If \c false is returned, the extraction will be aborted. Default implementation returns + \c true. +*/ +bool ExtractCallback::prepareForFile(const QString &filename) { + Q_UNUSED(filename) return true; } @@ -1205,7 +1212,11 @@ void Lib7z::createArchive(QFileDevice *archive, const QStringList &sourcePaths, } } -void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, QFileDevice *target, +/*! + Extracts the given File \a file from \a archive into output device \a target using + the provided extract callback \a callback. Throws Lib7z::SevenZipException on error. +*/ +void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &file, QFileDevice *target, ExtractCallback *callback) { assert(archive); @@ -1218,7 +1229,7 @@ void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, QFile try { const OpenArchiveInfo *const openArchive = OpenArchiveInfo::value(archive); - const int arcIdx = item.archiveIndex.x(); + const int arcIdx = file.archiveIndex.x(); if (arcIdx < 0 || arcIdx >= openArchive->archiveLink.Arcs.Size()) { throw SevenZipException(QCoreApplication::translate("Lib7z", "CArc index %1 out of bounds [0, %2]").arg(openArchive->archiveLink.Arcs.Size() - 1)); @@ -1226,7 +1237,7 @@ void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, QFile const CArc &arc = openArchive->archiveLink.Arcs[arcIdx]; IInArchive *const parchive = arc.Archive; - const UInt32 itemIdx = item.archiveIndex.y(); + const UInt32 itemIdx = file.archiveIndex.y(); UInt32 numItems = 0; if (parchive->GetNumberOfItems(&numItems) != S_OK) { throw SevenZipException(QCoreApplication::translate("Lib7z", @@ -1243,7 +1254,7 @@ void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, QFile throw SevenZipException(QCoreApplication::translate("Lib7z", "Could not retrieve path of archive item %1").arg(itemIdx)); } - assert(item.path == UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/'))); + assert(file.path == UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/'))); callback->setTarget(target); const LONG extractResult = parchive->Extract(&itemIdx, 1, /*testmode=*/0, callback->impl()); @@ -1261,8 +1272,14 @@ void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, QFile } } -void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, - const QString &targetDirectory, ExtractCallback *callback) +/*! + Extracts the given File \a file from \a archive into target directory \a directory using the + provided extract callback \a callback. The output filename is deduced from the \a file path + name. Throws Lib7z::SevenZipException on error. +*/ + +void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &file, const QString &directory, + ExtractCallback *callback) { assert(archive); @@ -1270,7 +1287,7 @@ void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, if (!callback) callback = dummyCallback.data(); - QFileInfo fi(targetDirectory + QLatin1String("/") + item.path); + QFileInfo fi(directory + QLatin1String("/") + file.path); DirectoryGuard outDir(fi.absolutePath()); outDir.tryCreate(); QFile out(fi.absoluteFilePath()); @@ -1279,14 +1296,19 @@ void Lib7z::extractFileFromArchive(QFileDevice *archive, const File &item, "Could not create output file for writing: %1").arg(fi.absoluteFilePath())); } callback->setTarget(&out); - extractFileFromArchive(archive, item, &out, callback); - if (item.permissions) - out.setPermissions(item.permissions); + extractFileFromArchive(archive, file, &out, callback); + if (file.permissions) + out.setPermissions(file.permissions); outDir.release(); } -void Lib7z::extractArchive(QFileDevice *archive, const QString &targetDirectory, - ExtractCallback *callback) +/*! + Extracts the given \a archive content into target directory \a directory using the provided + extract callback \a callback. The output filenames are deduced from the \a archive content. + Throws Lib7z::SevenZipException on error. +*/ + +void Lib7z::extractArchive(QFileDevice *archive, const QString &directory, ExtractCallback *callback) { assert(archive); @@ -1294,9 +1316,9 @@ void Lib7z::extractArchive(QFileDevice *archive, const QString &targetDirectory, if (!callback) callback = dummyCallback.data(); - callback->setTarget(targetDirectory); + callback->setTarget(directory); - const QFileInfo fi(targetDirectory); + const QFileInfo fi(directory); DirectoryGuard outDir(fi.absolutePath()); outDir.tryCreate(); @@ -1315,6 +1337,10 @@ void Lib7z::extractArchive(QFileDevice *archive, const QString &targetDirectory, outDir.release(); } +/*! + Returns \c true if the given \a archive is supported; otherwise returns \c false. Throws + Lib7z::SevenZipException on error. +*/ bool Lib7z::isSupportedArchive(const QString &archive) { QFile file(archive); @@ -1324,6 +1350,10 @@ bool Lib7z::isSupportedArchive(const QString &archive) return isSupportedArchive(&file); } +/*! + Returns \c true if the given \a archive is supported; otherwise returns \c false. Throws + Lib7z::SevenZipException on error. +*/ bool Lib7z::isSupportedArchive(QFileDevice *archive) { assert(archive); diff --git a/src/libs/installer/lib7z_facade.h b/src/libs/installer/lib7z_facade.h index ff0e7a1e4..8bc4b1780 100644 --- a/src/libs/installer/lib7z_facade.h +++ b/src/libs/installer/lib7z_facade.h @@ -97,12 +97,6 @@ namespace Lib7z { void setTarget(const QString &dir); protected: - /*! - Reimplement to prepare for file @p filename to be extracted, e.g. by renaming existing - files. @return @p true if the preparation was successful and extraction can be continued. - If @p false is returned, the extraction will be aborted. Default implementation returns - @p true. - */ virtual bool prepareForFile(const QString &filename); virtual void setCurrentFile(const QString &filename); virtual HRESULT setCompleted(quint64 completed, quint64 total); @@ -145,54 +139,21 @@ namespace Lib7z { void deviceDestroyed(QObject*); }; - /*! - Extracts the given File \a file from \a archive into output device \a out using the - provided extract callback \a callback. + void INSTALLER_EXPORT extractFileFromArchive(QFileDevice *archive, const File &file, + QFileDevice *target, ExtractCallback *callback = 0); - Throws Lib7z::SevenZipException on error. - */ - void INSTALLER_EXPORT extractFileFromArchive(QFileDevice *archive, const File &item, - QFileDevice *out, ExtractCallback *callback = 0); - - /*! - Extracts the given File \a file from \a archive into target directory \a targetDirectory - using the provided extract callback \a callback. The output filename is deduced from the - \a file path name. - - Throws Lib7z::SevenZipException on error. - */ - void INSTALLER_EXPORT extractFileFromArchive(QFileDevice *archive, const File &item, + void INSTALLER_EXPORT extractFileFromArchive(QFileDevice *archive, const File &file, const QString &targetDirectory, ExtractCallback *callback = 0); - /*! - Extracts the given \a archive content into target directory \a targetDirectory using the - provided extract callback \a callback. The output filenames are deduced from the \a archive - content. - - Throws Lib7z::SevenZipException on error. - */ void INSTALLER_EXPORT extractArchive(QFileDevice *archive, const QString &targetDirectory, ExtractCallback *callback = 0); - /* - @thows Lib7z::SevenZipException - */ void INSTALLER_EXPORT createArchive(QFileDevice *archive, const QStringList &sourcePaths, UpdateCallback *callback = 0); - /*! - @thows Lib7z::SevenZipException - */ QVector INSTALLER_EXPORT listArchive(QFileDevice *archive); - /*! - @throws Lib7z::SevenZipException - */ bool INSTALLER_EXPORT isSupportedArchive(QFileDevice *archive); - - /*! - @throws Lib7z::SevenZipException - */ bool INSTALLER_EXPORT isSupportedArchive(const QString &archive); } -- cgit v1.2.3