From cdaf1d17337600e01017fa2a53fba6f5771dc20f Mon Sep 17 00:00:00 2001 From: kh1 Date: Wed, 23 Nov 2011 14:49:37 +0100 Subject: Code cosmetics. Change-Id: Ibaf3c8625c9c1bfcb7ddedefa4c7952e36ecf313 Reviewed-by: Tim Jenssen --- .../3rdparty/p7zip_9.04/lib7z_facade.cpp | 816 ++++++++++----------- 1 file changed, 408 insertions(+), 408 deletions(-) (limited to 'installerbuilder/libinstaller/3rdparty') diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/lib7z_facade.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/lib7z_facade.cpp index cb0d44c55..88ee905dd 100644 --- a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/lib7z_facade.cpp +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/lib7z_facade.cpp @@ -61,27 +61,27 @@ typedef BOOL (WINAPI *CREATEHARDLINK)(LPCSTR dst, LPCSTR str, LPSECURITY_ATTRIBUTES sa); -bool CreateHardLinkWrapper( const QString& dest, const QString& file ) +bool CreateHardLinkWrapper(const QString &dest, const QString &file) { static HMODULE module = 0; static CREATEHARDLINK proc = 0; - if( module == 0 ) - module = LoadLibrary( L"kernel32.dll" ); - if( module == 0 ) + if (module == 0) + module = LoadLibrary(L"kernel32.dll"); + if (module == 0) return false; - if( proc == 0 ) - proc = (CREATEHARDLINK) GetProcAddress( module, "CreateHardLinkA" ); - if( proc == 0 ) + if (proc == 0) + proc = (CREATEHARDLINK) GetProcAddress(module, "CreateHardLinkA"); + if (proc == 0) return false; QString target = file; - if( !QFileInfo( file ).isAbsolute() ) + if (!QFileInfo(file).isAbsolute()) { - target = QFileInfo( dest ).dir().absoluteFilePath( file ); + target = QFileInfo(dest).dir().absoluteFilePath(file); } - const QString link = QDir::toNativeSeparators( dest ); - const QString existingFile = QDir::toNativeSeparators( target ); - return proc( link.toLocal8Bit(), existingFile.toLocal8Bit(), 0 ); + const QString link = QDir::toNativeSeparators(dest); + const QString existingFile = QDir::toNativeSeparators(target); + return proc(link.toLocal8Bit(), existingFile.toLocal8Bit(), 0); } #else @@ -101,20 +101,20 @@ namespace { * RAII class to create a directory (tryCreate()) and delete it on destruction unless released. */ struct DirectoryGuard { - explicit DirectoryGuard( const QString& path ) - : m_path( path ), - m_created( false ), - m_released( false ) + explicit DirectoryGuard(const QString &path) + : m_path(path), + m_created(false), + m_released(false) { - const QRegExp re( QLatin1String( "\\\\|/" ) ); - const QLatin1String sep( "/" ); - m_path.replace( re, sep ); + const QRegExp re(QLatin1String("\\\\|/")); + const QLatin1String sep("/"); + m_path.replace(re, sep); } ~DirectoryGuard() { - if ( !m_created || m_released ) + if (!m_created || m_released) return; - QDir dir( m_path ); - if ( !dir.rmdir( m_path ) ) + QDir dir(m_path); + if (!dir.rmdir(m_path)) qWarning() << "Could not delete directory " << m_path; } @@ -123,30 +123,30 @@ namespace { * Returns a list of every directory created. */ QStringList tryCreate() { - if( m_path.isEmpty() ) + if (m_path.isEmpty()) return QStringList(); - const QFileInfo fi( m_path ); - if ( fi.exists() && fi.isDir() ) + const QFileInfo fi(m_path); + if (fi.exists() && fi.isDir()) return QStringList(); - if ( fi.exists() && !fi.isDir() ) - throw SevenZipException( QObject::tr("Path exists but is not a folder: %1").arg( m_path ) ); - + if (fi.exists() && !fi.isDir()) + throw SevenZipException(QObject::tr("Path exists but is not a folder: %1").arg(m_path)); + QStringList created; - QDir toCreate( m_path ); - while( !toCreate.exists() ) + QDir toCreate(m_path); + while (!toCreate.exists()) { QString p = toCreate.absolutePath(); - created.push_front( p ); - p = p.section( QLatin1Char( '/' ), 0, -2 ); - toCreate = QDir( p ); + created.push_front(p); + p = p.section(QLatin1Char('/'), 0, -2); + toCreate = QDir(p); } - QDir dir( m_path ); - m_created = dir.mkpath( m_path ); - if ( !m_created ) - throw SevenZipException( QObject::tr("Could not create folder: %1").arg( m_path ) ); + QDir dir(m_path); + m_created = dir.mkpath(m_path); + if (!m_created) + throw SevenZipException(QObject::tr("Could not create folder: %1").arg(m_path)); return created; } @@ -161,121 +161,121 @@ namespace { }; } -static void throwIfNotOK( HRESULT result, const QString& msg ) { - if ( result != S_OK ) - throw SevenZipException( msg ); +static void throwIfNotOK(HRESULT result, const QString &msg) { + if (result != S_OK) + throw SevenZipException(msg); } -static UString QString2UString( const QString& str ) { +static UString QString2UString(const QString &str) { return str.toStdWString().c_str(); } -static QString UString2QString( const UString& str ) { - return QString::fromStdWString( static_cast( str ) ); +static QString UString2QString(const UString& str) { + return QString::fromStdWString(static_cast(str)); } static QString generateTempFileName() { QTemporaryFile tmp; - if ( !tmp.open() ) - throw SevenZipException( QObject::tr("Could not create temporary file") ); - return QDir::toNativeSeparators( tmp.fileName() ); + if (!tmp.open()) + throw SevenZipException(QObject::tr("Could not create temporary file")); + return QDir::toNativeSeparators(tmp.fileName()); } /* -static QStringList UStringVector2QStringList( const UStringVector& vec ) { +static QStringList UStringVector2QStringList(const UStringVector& vec) { QStringList res; - for( int i = 0; i < vec.Size(); ++i ) - res += UString2QString( vec[i] ); + for (int i = 0; i < vec.Size(); ++i) + res += UString2QString(vec[i]); return res; } */ -static NCOM::CPropVariant readProperty( IInArchive* archive, int index, int propId ) { +static NCOM::CPropVariant readProperty(IInArchive* archive, int index, int propId) { NCOM::CPropVariant prop; - throwIfNotOK( archive->GetProperty(index, propId, &prop), QObject::tr("Could not retrieve property %1 for item %2").arg( QString::number( propId ), QString::number( index ) ) ); + throwIfNotOK(archive->GetProperty(index, propId, &prop), QObject::tr("Could not retrieve property %1 for item %2").arg(QString::number(propId), QString::number(index))); return prop; } -static bool IsFileTimeZero( const FILETIME *lpFileTime ) +static bool IsFileTimeZero(const FILETIME *lpFileTime) { return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0); } -static bool IsDST( const QDateTime& datetime = QDateTime() ) +static bool IsDST(const QDateTime& datetime = QDateTime()) { - const time_t seconds = static_cast< time_t >( datetime.isValid() ? datetime.toTime_t() : QDateTime::currentDateTime().toTime_t() ); - const tm* const t = localtime( &seconds ); + const time_t seconds = static_cast< time_t >(datetime.isValid() ? datetime.toTime_t() : QDateTime::currentDateTime().toTime_t()); + const tm* const t = localtime(&seconds); return t->tm_isdst; } -static QDateTime getDateTimeProperty( IInArchive* archive, int index, int propId, const QDateTime& defaultValue ) { - const NCOM::CPropVariant prop = readProperty( archive, index, propId ); +static QDateTime getDateTimeProperty(IInArchive* archive, int index, int propId, const QDateTime& defaultValue) { + const NCOM::CPropVariant prop = readProperty(archive, index, propId); if (prop.vt != VT_FILETIME) - throw SevenZipException( QObject::tr("Property %1 for item %2 not of type VT_FILETIME but %3").arg( QString::number( propId ), QString::number( index ), QString::number( prop.vt ) ) ); - if ( IsFileTimeZero( &prop.filetime ) ) + throw SevenZipException(QObject::tr("Property %1 for item %2 not of type VT_FILETIME but %3").arg(QString::number(propId), QString::number(index), QString::number(prop.vt))); + if (IsFileTimeZero(&prop.filetime)) return defaultValue; FILETIME localFileTime; - if ( !FileTimeToLocalFileTime( &prop.filetime, &localFileTime ) ) - throw SevenZipException( QObject::tr("Could not convert file time to local time") ); + if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime)) + throw SevenZipException(QObject::tr("Could not convert file time to local time")); SYSTEMTIME st; - if ( !BOOLToBool(FileTimeToSystemTime(&localFileTime, &st)) ) - throw SevenZipException( QObject::tr("Could not convert local file time to system time") ); + if (!BOOLToBool(FileTimeToSystemTime(&localFileTime, &st))) + throw SevenZipException(QObject::tr("Could not convert local file time to system time")); - const QDate date( st.wYear, st.wMonth, st.wDay ); - const QTime time( st.wHour, st.wMinute, st.wSecond ); - QDateTime result( date, time ); + const QDate date(st.wYear, st.wMonth, st.wDay); + const QTime time(st.wHour, st.wMinute, st.wSecond); + QDateTime result(date, time); // fix daylight saving time const bool dst = IsDST(); - if( dst != IsDST( result ) ) - result = result.addSecs( dst ? -3600 : 3600 ); + if (dst != IsDST(result)) + result = result.addSecs(dst ? -3600 : 3600); return result; } -static quint64 getUInt64Property( IInArchive* archive, int index, int propId, quint64 defaultValue=0 ) { - const NCOM::CPropVariant prop = readProperty( archive, index, propId ); - if ( prop.vt == VT_EMPTY ) +static quint64 getUInt64Property(IInArchive* archive, int index, int propId, quint64 defaultValue=0) { + const NCOM::CPropVariant prop = readProperty(archive, index, propId); + if (prop.vt == VT_EMPTY) return defaultValue; - return static_cast( ConvertPropVariantToUInt64( prop ) ); + return static_cast(ConvertPropVariantToUInt64(prop)); } -static quint32 getUInt32Property( IInArchive* archive, int index, int propId, quint32 defaultValue=0 ) { - const NCOM::CPropVariant prop = readProperty( archive, index, propId ); - if ( prop.vt == VT_EMPTY ) +static quint32 getUInt32Property(IInArchive* archive, int index, int propId, quint32 defaultValue=0) { + const NCOM::CPropVariant prop = readProperty(archive, index, propId); + if (prop.vt == VT_EMPTY) return defaultValue; - return static_cast< quint32 >( prop.ulVal ); + return static_cast< quint32 >(prop.ulVal); } -static QFile::Permissions getPermissions( IInArchive* archive, int index, bool* hasPermissions = 0 ) +static QFile::Permissions getPermissions(IInArchive* archive, int index, bool* hasPermissions = 0) { - quint32 attributes = getUInt32Property( archive, index, kpidAttrib, 0 ); + quint32 attributes = getUInt32Property(archive, index, kpidAttrib, 0); QFile::Permissions permissions = 0; - if( attributes & FILE_ATTRIBUTE_UNIX_EXTENSION ) + if (attributes & FILE_ATTRIBUTE_UNIX_EXTENSION) { - if( hasPermissions != 0 ) + if (hasPermissions != 0) *hasPermissions = true; // filter the unix permissions - attributes = ( attributes >> 16 ) & 0777; - permissions |= static_cast< QFile::Permissions >( ( attributes & 0700 ) << 2 ); // owner rights - permissions |= static_cast< QFile::Permissions >( ( attributes & 0070 ) << 1 ); // group - permissions |= static_cast< QFile::Permissions >( ( attributes & 0007 ) << 0 ); // and world rights + attributes = (attributes >> 16) & 0777; + permissions |= static_cast< QFile::Permissions >((attributes & 0700) << 2); // owner rights + permissions |= static_cast< QFile::Permissions >((attributes & 0070) << 1); // group + permissions |= static_cast< QFile::Permissions >((attributes & 0007) << 0); // and world rights } - else if( hasPermissions != 0 ) + else if (hasPermissions != 0) *hasPermissions = false; return permissions; } - + namespace Lib7z { class QIODeviceSequentialOutStream : public ISequentialOutStream, public CMyUnknownImp { public: MY_UNKNOWN_IMP - explicit QIODeviceSequentialOutStream( QIODevice* device ); + explicit QIODeviceSequentialOutStream(QIODevice* device); ~QIODeviceSequentialOutStream(); - /* reimp */ STDMETHOD(Write)( const void* data, UInt32 size, UInt32* processedSize ); + /* reimp */ STDMETHOD(Write)(const void* data, UInt32 size, UInt32* processedSize); private: QPointer m_device; @@ -283,43 +283,43 @@ namespace Lib7z { }; - QIODeviceSequentialOutStream::QIODeviceSequentialOutStream( QIODevice* device ) - : ISequentialOutStream(), - CMyUnknownImp(), - m_device( device ), - closeOnDestroy( !device->isOpen() ) + QIODeviceSequentialOutStream::QIODeviceSequentialOutStream(QIODevice* device) + : ISequentialOutStream(), + CMyUnknownImp(), + m_device(device), + closeOnDestroy(!device->isOpen()) { - assert( m_device ); - if( closeOnDestroy ) - m_device->open( QIODevice::WriteOnly ); + assert(m_device); + if (closeOnDestroy) + m_device->open(QIODevice::WriteOnly); } QIODeviceSequentialOutStream::~QIODeviceSequentialOutStream() { - if( closeOnDestroy ) + if (closeOnDestroy) { m_device->close(); delete m_device; } } - HRESULT QIODeviceSequentialOutStream::Write( const void* data, UInt32 size, UInt32* processedSize ) { - if ( !m_device ) { - if ( processedSize ) + HRESULT QIODeviceSequentialOutStream::Write(const void* data, UInt32 size, UInt32* processedSize) { + if (!m_device) { + if (processedSize) *processedSize = 0; return E_FAIL; } - if( closeOnDestroy && !m_device->isOpen() ) { - const bool opened = m_device->open( QIODevice::WriteOnly ); - if ( !opened ) { - if ( processedSize ) + if (closeOnDestroy && !m_device->isOpen()) { + const bool opened = m_device->open(QIODevice::WriteOnly); + if (!opened) { + if (processedSize) *processedSize = 0; return E_FAIL; } } - const qint64 written = m_device->write( reinterpret_cast( data ), size ); - if ( processedSize ) + const qint64 written = m_device->write(reinterpret_cast(data), size); + if (processedSize) *processedSize = written; return written >= 0 ? S_OK : E_FAIL; } @@ -328,29 +328,29 @@ namespace Lib7z { public: MY_UNKNOWN_IMP - explicit QIODeviceInStream( QIODevice* device ) : IInStream(), CMyUnknownImp(), m_device( device ) { - assert( m_device ); - assert( !m_device->isSequential() ); + explicit QIODeviceInStream(QIODevice* device) : IInStream(), CMyUnknownImp(), m_device(device) { + assert(m_device); + assert(!m_device->isSequential()); } - /* reimp */ STDMETHOD(Read)( void* data, UInt32 size, UInt32* processedSize ) { - assert( m_device ); - assert( m_device->isReadable() ); - const qint64 actual = m_device->read( reinterpret_cast( data ), size ); - Q_ASSERT( actual != 0 || m_device->atEnd() ); - if ( processedSize ) + /* reimp */ STDMETHOD(Read)(void* data, UInt32 size, UInt32* processedSize) { + assert(m_device); + assert(m_device->isReadable()); + const qint64 actual = m_device->read(reinterpret_cast(data), size); + Q_ASSERT(actual != 0 || m_device->atEnd()); + if (processedSize) *processedSize = actual; return actual >= 0 ? S_OK : E_FAIL; } - /* reimp */ STDMETHOD(Seek)( Int64 offset, UInt32 seekOrigin, UInt64* newPosition ) { - assert( m_device ); - assert( !m_device->isSequential() ); - assert( m_device->isReadable() ); - if ( seekOrigin > STREAM_SEEK_END ) + /* reimp */ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64* newPosition) { + assert(m_device); + assert(!m_device->isSequential()); + assert(m_device->isReadable()); + if (seekOrigin > STREAM_SEEK_END) return STG_E_INVALIDFUNCTION; UInt64 np = 0; - switch( seekOrigin ) { + switch(seekOrigin) { case STREAM_SEEK_SET: np = offset; break; @@ -364,9 +364,9 @@ namespace Lib7z { return STG_E_INVALIDFUNCTION; } - np = qBound( static_cast( 0 ), np, static_cast( m_device->size() - 1 ) ); - const bool ok = m_device->seek( np ); - if ( newPosition ) + np = qBound(static_cast(0), np, static_cast(m_device->size() - 1)); + const bool ok = m_device->seek(np); + if (newPosition) *newPosition = np; return ok ? S_OK : E_FAIL; } @@ -376,48 +376,48 @@ namespace Lib7z { }; } -File::File() : permissions( 0 ), uncompressedSize( 0 ), compressedSize( 0 ), isDirectory( false ) { +File::File() : permissions(0), uncompressedSize(0), compressedSize(0), isDirectory(false) { } QVector File::subtreeInPreorder() const { QVector res; res += *this; - Q_FOREACH( const File& child, children ) + Q_FOREACH(const File& child, children) res += child.subtreeInPreorder(); return res; } -bool File::operator<( const File& other ) const { - if ( path != other.path ) +bool File::operator<(const File& other) const { + if (path != other.path) return path < other.path; - if ( mtime != other.mtime ) + if (mtime != other.mtime) return mtime < other.mtime; - if ( uncompressedSize != other.uncompressedSize ) + if (uncompressedSize != other.uncompressedSize) return uncompressedSize < other.uncompressedSize; - if ( compressedSize != other.compressedSize ) + if (compressedSize != other.compressedSize) return compressedSize < other.compressedSize; - if ( isDirectory != other.isDirectory ) + if (isDirectory != other.isDirectory) return !isDirectory; - if( permissions != other.permissions ) + if (permissions != other.permissions) return permissions < other.permissions; return false; } -bool File::operator==( const File& other ) const { +bool File::operator==(const File& other) const { return mtime == other.mtime && path == other.path && uncompressedSize == other.uncompressedSize && compressedSize == other.compressedSize && isDirectory == other.isDirectory && children == other.children - && (permissions == other.permissions || permissions == static_cast< QFile::Permissions >( -1 ) || other.permissions == static_cast< QFile::Permissions >( -1 ) ); + && (permissions == other.permissions || permissions == static_cast< QFile::Permissions >(-1) || other.permissions == static_cast< QFile::Permissions >(-1)); } -QByteArray Lib7z::formatKeyValuePairs( const QVariantList& l ) { - assert( l.size() % 2 == 0 ); +QByteArray Lib7z::formatKeyValuePairs(const QVariantList& l) { + assert(l.size() % 2 == 0); QByteArray res; - for ( QVariantList::ConstIterator it = l.constBegin(); it != l.constEnd(); ++it ) { - if ( !res.isEmpty() ) + for (QVariantList::ConstIterator it = l.constBegin(); it != l.constEnd(); ++it) { + if (!res.isEmpty()) res += ", "; res += qPrintable(it->toString()) + QByteArray(" = "); ++it; @@ -433,7 +433,7 @@ public: QString errorString; }; -Job::Job( QObject* parent ) : QObject( parent ), QRunnable(), d( new Private ) { +Job::Job(QObject* parent) : QObject(parent), QRunnable(), d(new Private) { } Job::~Job() { @@ -441,19 +441,19 @@ Job::~Job() { } void Job::emitResult() { - emit finished( this ); + emit finished(this); } -void Job::setError( int code ) { +void Job::setError(int code) { d->error = code; } -void Job::setErrorString( const QString& str ) { +void Job::setErrorString(const QString &str) { d->errorString = str; } -void Job::emitProgress( qint64 completed, qint64 total ) { - emit progress( completed, total ); +void Job::emitProgress(qint64 completed, qint64 total) { + emit progress(completed, total); } int Job::error() const { @@ -473,7 +473,7 @@ QString Job::errorString() const { } void Job::start() { - QMetaObject::invokeMethod( this, "doStart", Qt::QueuedConnection ); + QMetaObject::invokeMethod(this, "doStart", Qt::QueuedConnection); } class ListArchiveJob::Private { @@ -482,7 +482,7 @@ public: QVector files; }; -ListArchiveJob::ListArchiveJob( QObject* parent ) : Job( parent ), d( new Private ) { +ListArchiveJob::ListArchiveJob(QObject* parent) : Job(parent), d(new Private) { } ListArchiveJob::~ListArchiveJob() { @@ -493,7 +493,7 @@ QIODevice* ListArchiveJob::archive() const { return d->archive; } -void ListArchiveJob::setArchive( QIODevice* device ) { +void ListArchiveJob::setArchive(QIODevice* device) { d->archive = device; } @@ -504,21 +504,21 @@ QVector ListArchiveJob::index() const { class OpenArchiveInfo { private: - OpenArchiveInfo( QIODevice* device ) - : codecs( new CCodecs ), - stream( new QIODeviceInStream( device ) ) + OpenArchiveInfo(QIODevice* device) + : codecs(new CCodecs), + stream(new QIODeviceInStream(device)) { - throwIfNotOK( codecs->Load(), QObject::tr( "Could not load codecs" ) ); + throwIfNotOK(codecs->Load(), QObject::tr("Could not load codecs")); - if( !codecs->FindFormatForArchiveType( L"", formatIndices ) ) - throw SevenZipException( QObject::tr( "Could not retrieve default format" ) ); + if (!codecs->FindFormatForArchiveType(L"", formatIndices)) + throw SevenZipException(QObject::tr("Could not retrieve default format")); + + throwIfNotOK(archiveLink.Open2(codecs.get(), formatIndices, false, stream, UString(), 0), QObject::tr("Could not open archive")); + if (archiveLink.Arcs.Size() == 0) + throw SevenZipException(QObject::tr("No CArc found")); - throwIfNotOK( archiveLink.Open2( codecs.get(), formatIndices, false, stream, UString(), 0 ), QObject::tr( "Could not open archive" ) ); - if( archiveLink.Arcs.Size() == 0 ) - throw SevenZipException( QObject::tr( "No CArc found" ) ); - m_cleaner = new OpenArchiveInfoCleaner(); - m_cleaner->moveToThread( device->thread() ); + m_cleaner->moveToThread(device->thread()); QObject::connect(device, SIGNAL(destroyed(QObject*)), m_cleaner, SLOT(deviceDestroyed(QObject*))); } @@ -527,14 +527,14 @@ public: { m_cleaner->deleteLater(); } - + static QMap< QIODevice*, OpenArchiveInfo* > instances; - static OpenArchiveInfo* instance( QIODevice* device ) + static OpenArchiveInfo* instance(QIODevice* device) { - if( instances[ device ] == 0 ) - instances[ device ] = new OpenArchiveInfo( device ); - return instances[ device ]; + if (instances[device] == 0) + instances[device] = new OpenArchiveInfo(device); + return instances[device]; } std::auto_ptr< CCodecs > codecs; @@ -555,61 +555,61 @@ void OpenArchiveInfoCleaner::deviceDestroyed(QObject* dev) delete OpenArchiveInfo::instances.take(device); } -QVector Lib7z::listArchive( QIODevice* archive ) { - assert( archive ); +QVector Lib7z::listArchive(QIODevice* archive) { + assert(archive); try { - const OpenArchiveInfo* const openArchive = OpenArchiveInfo::instance( archive ); + const OpenArchiveInfo* const openArchive = OpenArchiveInfo::instance(archive); QVector flat; - for ( int i = 0; i < openArchive->archiveLink.Arcs.Size(); ++i ) { + for (int i = 0; i < openArchive->archiveLink.Arcs.Size(); ++i) { const CArc& arc = openArchive->archiveLink.Arcs[i]; IInArchive* const arch = arc.Archive; UInt32 numItems = 0; - throwIfNotOK( arch->GetNumberOfItems(&numItems), QObject::tr("Could not retrieve number of items in archive") ); - - flat.reserve( flat.size() + numItems ); - for ( uint item = 0; item < numItems; ++item ) { + throwIfNotOK(arch->GetNumberOfItems(&numItems), QObject::tr("Could not retrieve number of items in archive")); + + flat.reserve(flat.size() + numItems); + for (uint item = 0; item < numItems; ++item) { UString s; - throwIfNotOK( arc.GetItemPath( item, s ), QObject::tr("Could not retrieve path of archive item %1").arg( item ) ); + throwIfNotOK(arc.GetItemPath(item, s), QObject::tr("Could not retrieve path of archive item %1").arg(item)); File f; - f.archiveIndex.setX( i ); - f.archiveIndex.setY( item ); - f.path = UString2QString( s ).replace( QLatin1Char( '\\' ), QLatin1Char( '/' ) ); - IsArchiveItemFolder( arch, item, f.isDirectory ); - f.permissions = getPermissions( arch, item ); - f.mtime = getDateTimeProperty( arch, item, kpidMTime, QDateTime() ); - f.uncompressedSize = getUInt64Property( arch, item, kpidSize, 0 ); - f.compressedSize = getUInt64Property( arch, item, kpidPackSize, 0 ); - flat.push_back( f ); + f.archiveIndex.setX(i); + f.archiveIndex.setY(item); + f.path = UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/')); + IsArchiveItemFolder(arch, item, f.isDirectory); + f.permissions = getPermissions(arch, item); + f.mtime = getDateTimeProperty(arch, item, kpidMTime, QDateTime()); + f.uncompressedSize = getUInt64Property(arch, item, kpidSize, 0); + f.compressedSize = getUInt64Property(arch, item, kpidPackSize, 0); + flat.push_back(f); qApp->processEvents(); } } return flat; - } catch ( const SevenZipException& e ) { + } catch (const SevenZipException& e) { throw e; } catch(const char *err) { - throw SevenZipException( err ); + throw SevenZipException(err); } - catch ( ... ) { - throw SevenZipException( QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO)) ); + catch (...) { + throw SevenZipException(QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO))); } return QVector(); // never reached } void ListArchiveJob::doStart() { try { - if ( !d->archive ) - throw SevenZipException( tr("Could not list archive: QIODevice already destroyed") ); - d->files = listArchive( d->archive ); - } catch ( const SevenZipException& e ) { - setError( Failed ); - setErrorString( e.message() ); - } catch ( ... ) { - setError( Failed ); - setErrorString( QObject::tr("Unknown exception caught (%1)").arg( QObject::tr( "Failed" )) ); + if (!d->archive) + throw SevenZipException(tr("Could not list archive: QIODevice already destroyed")); + d->files = listArchive(d->archive); + } catch (const SevenZipException& e) { + setError(Failed); + setErrorString(e.message()); + } catch (...) { + setError(Failed); + setErrorString(QObject::tr("Unknown exception caught (%1)").arg(QObject::tr("Failed"))); } emitResult(); } @@ -617,118 +617,118 @@ void ListArchiveJob::doStart() { class Lib7z::ExtractCallbackImpl : public IArchiveExtractCallback, public CMyUnknownImp { public: MY_UNKNOWN_IMP - explicit ExtractCallbackImpl( ExtractCallback* qq ) - : q( qq ), - currentIndex( 0 ), - arc( 0 ), - total( 0 ), - completed( 0 ), - device( 0 ) + explicit ExtractCallbackImpl(ExtractCallback* qq) + : q(qq), + currentIndex(0), + arc(0), + total(0), + completed(0), + device(0) { } - void setTarget( QIODevice* dev ) + void setTarget(QIODevice* dev) { device = dev; } - void setTarget( const QString& targetDirectory ) + void setTarget(const QString &targetDirectory) { targetDir = targetDirectory; } // this method will be called by CFolderOutStream::OpenFile to stream via // CDecoder::CodeSpec extracted content to an output stream. - /* reimp */ STDMETHOD(GetStream)( UInt32 index, ISequentialOutStream** outStream, Int32 askExtractMode ) + /* reimp */ STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream** outStream, Int32 askExtractMode) { - Q_UNUSED( askExtractMode ) + Q_UNUSED(askExtractMode) *outStream = 0; - if( device != 0 ) + if (device != 0) { - CMyComPtr stream = new QIODeviceSequentialOutStream( device ); + CMyComPtr stream = new QIODeviceSequentialOutStream(device); *outStream = stream.Detach(); return S_OK; } - else if( !targetDir.isEmpty() ) + else if (!targetDir.isEmpty()) { - assert( arc ); + assert(arc); currentIndex = index; UString s; - throwIfNotOK( arc->GetItemPath( index, s ), QObject::tr( "Could not retrieve path of archive item %1" ).arg( index ) ); - const QString path = UString2QString( s ).replace( QLatin1Char( '\\' ), QLatin1Char( '/' ) ); - - const QFileInfo fi( QString::fromLatin1( "%1/%2" ).arg( targetDir, path ) ); - DirectoryGuard guard( fi.absolutePath() ); + throwIfNotOK(arc->GetItemPath(index, s), QObject::tr("Could not retrieve path of archive item %1").arg(index)); + const QString path = UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/')); + + const QFileInfo fi(QString::fromLatin1("%1/%2").arg(targetDir, path)); + DirectoryGuard guard(fi.absolutePath()); const QStringList directories = guard.tryCreate(); - + bool isDir = false; - IsArchiveItemFolder( arc->Archive, index, isDir ); - if( isDir ) + IsArchiveItemFolder(arc->Archive, index, isDir); + if (isDir) { - QDir( fi.absolutePath() ).mkdir( fi.fileName() ); + QDir(fi.absolutePath()).mkdir(fi.fileName()); } // this makes sure that all directories created get removed as well - for( QStringList::const_iterator it = directories.begin(); it != directories.end(); ++it ) - q->setCurrentFile( *it ); + for (QStringList::const_iterator it = directories.begin(); it != directories.end(); ++it) + q->setCurrentFile(*it); - if( !isDir && !q->prepareForFile( fi.absoluteFilePath() ) ) + if (!isDir && !q->prepareForFile(fi.absoluteFilePath())) return E_FAIL; - - q->setCurrentFile( fi.absoluteFilePath() ); - if( !isDir ) + q->setCurrentFile(fi.absoluteFilePath()); + + if (!isDir) { - CMyComPtr< ISequentialOutStream > stream = new QIODeviceSequentialOutStream( new QFile( fi.absoluteFilePath() ) ); + CMyComPtr< ISequentialOutStream > stream = new QIODeviceSequentialOutStream(new QFile(fi.absoluteFilePath())); *outStream = stream; stream.Detach(); } - + guard.release(); return S_OK; } return E_FAIL; } - /* reimp */ STDMETHOD(PrepareOperation)( Int32 askExtractMode ) { - Q_UNUSED( askExtractMode ) + /* reimp */ STDMETHOD(PrepareOperation)(Int32 askExtractMode) { + Q_UNUSED(askExtractMode) return S_OK; } - /* reimp */ STDMETHOD(SetOperationResult)( Int32 resultEOperationResult ) { - Q_UNUSED( resultEOperationResult ) + /* reimp */ STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) { + Q_UNUSED(resultEOperationResult) - if( !targetDir.isEmpty() ) + if (!targetDir.isEmpty() ) { bool hasPerm; - const QFile::Permissions permissions = getPermissions( arc->Archive, currentIndex, &hasPerm ); - if( hasPerm ) + const QFile::Permissions permissions = getPermissions(arc->Archive, currentIndex, &hasPerm); + if (hasPerm) { UString s; - throwIfNotOK( arc->GetItemPath( currentIndex, s ), QObject::tr( "Could not retrieve path of archive item %1" ).arg( currentIndex ) ); - const QString path = UString2QString( s ).replace( QLatin1Char( '\\' ), QLatin1Char( '/' ) ); - const QFileInfo fi( QString::fromLatin1( "%1/%2" ).arg( targetDir, path ) ); - QFile::setPermissions( fi.absoluteFilePath(), permissions ); + throwIfNotOK(arc->GetItemPath(currentIndex, s), QObject::tr("Could not retrieve path of archive item %1").arg(currentIndex)); + const QString path = UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/')); + const QFileInfo fi(QString::fromLatin1("%1/%2").arg(targetDir, path)); + QFile::setPermissions(fi.absoluteFilePath(), permissions); // do we have a symlink? - const quint32 attributes = getUInt32Property( arc->Archive, currentIndex, kpidAttrib, 0 ); + const quint32 attributes = getUInt32Property(arc->Archive, currentIndex, kpidAttrib, 0); struct stat stat_info; stat_info.st_mode = attributes >> 16; - if( S_ISLNK( stat_info.st_mode ) ) + if (S_ISLNK(stat_info.st_mode)) { - QFile f( fi.absoluteFilePath() ); - f.open( QIODevice::ReadOnly ); + QFile f(fi.absoluteFilePath()); + f.open(QIODevice::ReadOnly); const QByteArray path = f.readAll(); f.close(); f.remove(); #ifdef Q_OS_WIN - if( !CreateHardLinkWrapper( fi.absoluteFilePath(), QLatin1String( path ) ) ) - throw SevenZipException( QObject::tr( "Could not create file system lik at %1" ).arg( fi.absoluteFilePath() ) ); + if (!CreateHardLinkWrapper( fi.absoluteFilePath(), QLatin1String(path))) + throw SevenZipException(QObject::tr("Could not create file system lik at %1").arg(fi.absoluteFilePath())); #else - if( !QFile::link( QString::fromLatin1( path ), fi.absoluteFilePath() ) ) - throw SevenZipException( QObject::tr( "Could not create softlink at %1" ).arg( fi.absoluteFilePath() ) ); + if (!QFile::link(QString::fromLatin1(path), fi.absoluteFilePath())) + throw SevenZipException(QObject::tr("Could not create softlink at %1").arg(fi.absoluteFilePath())); #endif } } @@ -737,20 +737,20 @@ public: return S_OK; } - /* reimp */ STDMETHOD(SetTotal)( UInt64 t ) { + /* reimp */ STDMETHOD(SetTotal)(UInt64 t) { total = t; return S_OK; } - /* reimp */ STDMETHOD(SetCompleted)( const UInt64* c ) { + /* reimp */ STDMETHOD(SetCompleted)(const UInt64* c) { completed = *c; - if ( total > 0 ) { - return q->setCompleted( completed, total ); + if (total > 0) { + return q->setCompleted(completed, total); } return S_OK; } - void setArchive( const CArc* archive ) + void setArchive(const CArc* archive) { arc = archive; } @@ -768,14 +768,14 @@ private: class Lib7z::ExtractCallbackPrivate { public: - explicit ExtractCallbackPrivate( ExtractCallback* qq ) { - impl = new ExtractCallbackImpl( qq ); + explicit ExtractCallbackPrivate(ExtractCallback* qq) { + impl = new ExtractCallbackImpl(qq); } CMyComPtr impl; }; -ExtractCallback::ExtractCallback() : d( new ExtractCallbackPrivate( this ) ) { +ExtractCallback::ExtractCallback() : d(new ExtractCallbackPrivate(this)) { } ExtractCallback::~ExtractCallback() { @@ -790,36 +790,36 @@ const ExtractCallbackImpl* ExtractCallback::impl() const { return d->impl; } -void ExtractCallback::setTarget( QIODevice* dev ) +void ExtractCallback::setTarget(QIODevice* dev) { - d->impl->setTarget( dev ); + d->impl->setTarget(dev); } -void ExtractCallback::setTarget( const QString& dir ) +void ExtractCallback::setTarget(const QString &dir) { - d->impl->setTarget( dir ); + d->impl->setTarget(dir); } -HRESULT ExtractCallback::setCompleted( quint64, quint64 ) +HRESULT ExtractCallback::setCompleted(quint64, quint64) { return S_OK; } -void ExtractCallback::setCurrentFile( const QString& ) +void ExtractCallback::setCurrentFile(const QString&) { } -bool ExtractCallback::prepareForFile( const QString& ) +bool ExtractCallback::prepareForFile(const QString&) { return true; } class Lib7z::ExtractCallbackJobImpl : public ExtractCallback { public: - explicit ExtractCallbackJobImpl( ExtractItemJob* j ) : ExtractCallback(), job( j ) {} + explicit ExtractCallbackJobImpl(ExtractItemJob* j) : ExtractCallback(), job(j) {} private: - /* reimp */ HRESULT setCompleted( quint64 c, quint64 t ) { - emit job->progress( c, t ); + /* reimp */ HRESULT setCompleted(quint64 c, quint64 t) { + emit job->progress(c, t); return S_OK; } @@ -830,8 +830,8 @@ class Lib7z::UpdateCallbackImpl : public IUpdateCallbackUI2, public CMyUnknownIm { public: MY_UNKNOWN_IMP - explicit UpdateCallbackImpl( UpdateCallback* qq ) - : q( qq ) + explicit UpdateCallbackImpl(UpdateCallback* qq) + : q(qq) { } virtual ~UpdateCallbackImpl() @@ -840,18 +840,18 @@ public: /** * \reimp */ - HRESULT SetTotal( UInt64 ) + HRESULT SetTotal(UInt64) { return S_OK; } /** * \reimp */ - HRESULT SetCompleted( const UInt64* ) + HRESULT SetCompleted(const UInt64*) { return S_OK; } - HRESULT SetRatioInfo( const UInt64*, const UInt64* ) + HRESULT SetRatioInfo(const UInt64*, const UInt64*) { return S_OK; } @@ -863,19 +863,19 @@ public: { return S_OK; } - HRESULT SetNumFiles( UInt64 ) + HRESULT SetNumFiles(UInt64) { return S_OK; } - HRESULT GetStream( const wchar_t*, bool ) + HRESULT GetStream(const wchar_t*, bool) { return S_OK; } - HRESULT OpenFileError( const wchar_t*, DWORD ) + HRESULT OpenFileError(const wchar_t*, DWORD) { return S_OK; } - HRESULT CryptoGetTextPassword2( Int32* passwordIsDefined, OLECHAR** password ) + HRESULT CryptoGetTextPassword2(Int32* passwordIsDefined, OLECHAR** password) { *password = 0; *passwordIsDefined = false; @@ -885,7 +885,7 @@ public: { return E_NOTIMPL; } - HRESULT OpenResult(const wchar_t*, LONG ) + HRESULT OpenResult(const wchar_t*, LONG) { return S_OK; } @@ -917,16 +917,16 @@ public: /** * \reimp */ - HRESULT SetOperationResult( Int32 ) + HRESULT SetOperationResult(Int32) { // TODO! return S_OK; } - void setSource( const QStringList& dir ) + void setSource(const QStringList &dir) { sourceDir = dir; } - void setTarget( QIODevice* archive ) + void setTarget(QIODevice* archive) { target = archive; } @@ -941,9 +941,9 @@ private: class Lib7z::UpdateCallbackPrivate { public: - explicit UpdateCallbackPrivate( UpdateCallback* qq ) + explicit UpdateCallbackPrivate(UpdateCallback* qq) { - m_impl = new UpdateCallbackImpl( qq ); + m_impl = new UpdateCallbackImpl(qq); } UpdateCallbackImpl* impl() @@ -956,7 +956,7 @@ private: }; UpdateCallback::UpdateCallback() - : d( new UpdateCallbackPrivate( this ) ) + : d(new UpdateCallbackPrivate(this)) { } @@ -971,22 +971,22 @@ UpdateCallbackImpl* UpdateCallback::impl() } -void UpdateCallback::setSource( const QStringList& dir ) +void UpdateCallback::setSource(const QStringList &dir) { - d->impl()->setSource( dir ); + d->impl()->setSource(dir); } -void UpdateCallback::setTarget( QIODevice* target ) +void UpdateCallback::setTarget(QIODevice* target) { - d->impl()->setTarget( target ); + d->impl()->setTarget(target); } class ExtractItemJob::Private { public: - Private( ExtractItemJob* qq ) - : q( qq), - target( 0 ), - callback( new ExtractCallbackJobImpl( q ) ) + Private(ExtractItemJob* qq) + : q(qq), + target(0), + callback(new ExtractCallbackJobImpl(q)) { } @@ -1001,7 +1001,7 @@ public: ExtractCallback* callback; }; -ExtractItemJob::ExtractItemJob( QObject* parent ) : Job( parent ), d( new Private( this ) ) { +ExtractItemJob::ExtractItemJob(QObject* parent) : Job(parent), d(new Private(this)) { } ExtractItemJob::~ExtractItemJob() { @@ -1012,7 +1012,7 @@ File ExtractItemJob::item() const { return d->item; } -void ExtractItemJob::setItem( const File& item ) { +void ExtractItemJob::setItem(const File& item) { d->item = item; } @@ -1020,7 +1020,7 @@ QIODevice* ExtractItemJob::archive() const { return d->archive; } -void ExtractItemJob::setArchive( QIODevice* archive ) { +void ExtractItemJob::setArchive(QIODevice* archive) { d->archive = archive; } @@ -1028,232 +1028,232 @@ QString ExtractItemJob::targetDirectory() const { return d->targetDirectory; } -void ExtractItemJob::setTargetDirectory( const QString& dir ) { +void ExtractItemJob::setTargetDirectory(const QString &dir) { d->targetDirectory = dir; d->target = 0; } - -void ExtractItemJob::setTarget( QIODevice* dev ) + +void ExtractItemJob::setTarget(QIODevice* dev) { d->target = dev; } - -void Lib7z::createArchive( QIODevice* archive, const QStringList& sourceDirectories, UpdateCallback* callback ) + +void Lib7z::createArchive(QIODevice* archive, const QStringList &sourceDirectories, UpdateCallback* callback) { - assert( archive ); + assert(archive); - std::auto_ptr< UpdateCallback > dummyCallback( callback ? 0 : new UpdateCallback ); - if ( !callback ) + std::auto_ptr< UpdateCallback > dummyCallback(callback ? 0 : new UpdateCallback); + if (!callback) callback = dummyCallback.get(); try { - std::auto_ptr< CCodecs > codecs( new CCodecs ); - throwIfNotOK( codecs->Load(), QObject::tr( "Could not load codecs" ) ); + std::auto_ptr< CCodecs > codecs(new CCodecs); + throwIfNotOK(codecs->Load(), QObject::tr("Could not load codecs")); CIntVector formatIndices; - if( !codecs.get()->FindFormatForArchiveType( L"", formatIndices ) ) - throw SevenZipException( QObject::tr( "Could not retrieve default format" ) ); - + if (!codecs.get()->FindFormatForArchiveType(L"", formatIndices)) + throw SevenZipException(QObject::tr("Could not retrieve default format")); + // yes this is crap, but there seems to be no streaming solution to this... const QString tempFile = generateTempFileName(); NWildcard::CCensor censor; - foreach( QString dir, sourceDirectories) { - const UString sourceDirectoryPath = QString2UString( QDir::toNativeSeparators( dir)); - if( UString2QString( sourceDirectoryPath) != QDir::toNativeSeparators( dir)) - throw UString2QString( sourceDirectoryPath ).toLatin1().data(); - censor.AddItem( true, sourceDirectoryPath, true ); + foreach(QString dir, sourceDirectories) { + const UString sourceDirectoryPath = QString2UString(QDir::toNativeSeparators(dir)); + if (UString2QString(sourceDirectoryPath) != QDir::toNativeSeparators(dir)) + throw UString2QString(sourceDirectoryPath).toLatin1().data(); + censor.AddItem(true, sourceDirectoryPath, true); } CUpdateOptions options; CArchivePath archivePath; - archivePath.ParseFromPath( QString2UString( tempFile ) ); + archivePath.ParseFromPath(QString2UString(tempFile)); CUpdateArchiveCommand command; command.ArchivePath = archivePath; command.ActionSet = NUpdateArchive::kAddActionSet; - options.Commands.Add( command ); + options.Commands.Add(command); options.ArchivePath = archivePath; - options.MethodMode.FormatIndex = codecs->FindFormatForArchiveType( L"7z" ); - + options.MethodMode.FormatIndex = codecs->FindFormatForArchiveType(L"7z"); + CUpdateErrorInfo errorInfo; - - callback->setTarget( archive ); - callback->setSource( sourceDirectories ); - const HRESULT res = UpdateArchive( codecs.get(), censor, options, errorInfo, 0, callback->impl() ); - if( res != S_OK || !QFile::exists( tempFile ) ) - throw SevenZipException( QObject::tr( "Could not create archive %1" ).arg( tempFile ) ); + + callback->setTarget(archive); + callback->setSource(sourceDirectories); + const HRESULT res = UpdateArchive(codecs.get(), censor, options, errorInfo, 0, callback->impl()); + if (res != S_OK || !QFile::exists(tempFile)) + throw SevenZipException(QObject::tr("Could not create archive %1").arg(tempFile)); { //TODO remove temp file even if one the following throws - QFile file( tempFile ); - QInstaller::openForRead( &file, tempFile ); - QInstaller::blockingCopy( &file, archive, file.size() ); + QFile file(tempFile); + QInstaller::openForRead(&file, tempFile); + QInstaller::blockingCopy(&file, archive, file.size()); } - QFile file( tempFile ); - if ( !file.remove() ) - qWarning("%s: Could not remove temporary file %s: %s", Q_FUNC_INFO, qPrintable(tempFile), qPrintable(file.errorString()) ); + QFile file(tempFile); + if (!file.remove()) + qWarning("%s: Could not remove temporary file %s: %s", Q_FUNC_INFO, qPrintable(tempFile), qPrintable(file.errorString())); } catch(const char *err) { std::cout << err << std::endl; - throw SevenZipException( err ); + throw SevenZipException(err); } - catch (const QInstaller::Error &err ) + catch (const QInstaller::Error &err) { - throw SevenZipException( err.message() ); + throw SevenZipException(err.message()); } - catch( ... ) + catch(...) { - throw SevenZipException( QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO)) ); + throw SevenZipException(QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO))); } } -void Lib7z::extractArchive( QIODevice* archive, const File& item, QIODevice* target, ExtractCallback* callback ) { - assert( archive ); - assert( target ); +void Lib7z::extractArchive(QIODevice* archive, const File& item, QIODevice* target, ExtractCallback* callback) { + assert(archive); + assert(target); - std::auto_ptr dummyCallback( callback ? 0 : new ExtractCallback ); - if ( !callback ) + std::auto_ptr dummyCallback(callback ? 0 : new ExtractCallback); + if (!callback) callback = dummyCallback.get(); try { - const OpenArchiveInfo* const openArchive = OpenArchiveInfo::instance( archive ); + const OpenArchiveInfo* const openArchive = OpenArchiveInfo::instance(archive); const int arcIdx = item.archiveIndex.x(); - if ( arcIdx < 0 || arcIdx >= openArchive->archiveLink.Arcs.Size() ) - throw SevenZipException( QObject::tr("CArc index %1 out of bounds [0, %2]").arg( openArchive->archiveLink.Arcs.Size() - 1 ) ); + if (arcIdx < 0 || arcIdx >= openArchive->archiveLink.Arcs.Size()) + throw SevenZipException(QObject::tr("CArc index %1 out of bounds [0, %2]").arg(openArchive->archiveLink.Arcs.Size() - 1)); const CArc& arc = openArchive->archiveLink.Arcs[arcIdx]; IInArchive* const parchive = arc.Archive; const UInt32 itemIdx = item.archiveIndex.y(); UInt32 numItems = 0; - throwIfNotOK( parchive->GetNumberOfItems(&numItems), QObject::tr("Could not retrieve number of items in archive") ); - if ( itemIdx >= numItems ) - throw SevenZipException( QObject::tr("Item index %1 out of bounds [0, %2]").arg( itemIdx ).arg( numItems - 1 ) ); + throwIfNotOK(parchive->GetNumberOfItems(&numItems), QObject::tr("Could not retrieve number of items in archive")); + if (itemIdx >= numItems) + throw SevenZipException(QObject::tr("Item index %1 out of bounds [0, %2]").arg(itemIdx).arg(numItems - 1)); UString s; - throwIfNotOK( arc.GetItemPath( itemIdx, s ), QObject::tr( "Could not retrieve path of archive item %1" ).arg( itemIdx ) ); - assert( item.path == UString2QString( s ).replace( QLatin1Char( '\\' ), QLatin1Char( '/' ) ) ); + throwIfNotOK(arc.GetItemPath(itemIdx, s), QObject::tr("Could not retrieve path of archive item %1").arg(itemIdx)); + assert(item.path == UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/'))); - callback->setTarget( target ); - const LONG extractResult = parchive->Extract( &itemIdx, 1, /*testmode=*/1, callback->impl() ); + callback->setTarget(target); + const LONG extractResult = parchive->Extract(&itemIdx, 1, /*testmode=*/1, callback->impl()); //TODO: how to interpret result? - throwIfNotOK( extractResult, QObject::tr("Extracting %1 failed.").arg( item.path ) ); + throwIfNotOK(extractResult, QObject::tr("Extracting %1 failed.").arg(item.path)); } catch(const char *err) { - throw SevenZipException( err ); - } catch ( ... ) { - throw SevenZipException( QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO)) ); + throw SevenZipException(err); + } catch (...) { + throw SevenZipException(QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO))); } } -void Lib7z::extractArchive( QIODevice* archive, const File& item, const QString& targetDirectory, ExtractCallback* callback ) { - assert( archive ); +void Lib7z::extractArchive(QIODevice* archive, const File& item, const QString &targetDirectory, ExtractCallback* callback) { + assert(archive); - std::auto_ptr dummyCallback( callback ? 0 : new ExtractCallback ); - if ( !callback ) + std::auto_ptr dummyCallback(callback ? 0 : new ExtractCallback); + if (!callback) callback = dummyCallback.get(); - QFileInfo fi( targetDirectory + QLatin1String( "/" ) + item.path ); - DirectoryGuard outDir( fi.absolutePath() ); + QFileInfo fi(targetDirectory + QLatin1String("/") + item.path); + DirectoryGuard outDir(fi.absolutePath()); outDir.tryCreate(); - QFile out( fi.absoluteFilePath() ); - if ( !out.open( QIODevice::WriteOnly ) ) //TODO use tmp file - throw SevenZipException( QObject::tr("Could not create output file for writing: %1").arg( fi.absoluteFilePath() ) ); - if( item.permissions ) - out.setPermissions( item.permissions ); - callback->setTarget( &out ); - extractArchive( archive, item, &out, callback ); + QFile out(fi.absoluteFilePath()); + if (!out.open(QIODevice::WriteOnly)) //TODO use tmp file + throw SevenZipException(QObject::tr("Could not create output file for writing: %1").arg(fi.absoluteFilePath())); + if (item.permissions) + out.setPermissions(item.permissions); + callback->setTarget(&out); + extractArchive(archive, item, &out, callback); outDir.release(); } -void Lib7z::extractArchive( QIODevice* archive, const QString& targetDirectory, ExtractCallback* callback ) +void Lib7z::extractArchive(QIODevice* archive, const QString &targetDirectory, ExtractCallback* callback) { - assert( archive ); + assert(archive); - std::auto_ptr dummyCallback( callback ? 0 : new ExtractCallback ); - if ( !callback ) + std::auto_ptr dummyCallback(callback ? 0 : new ExtractCallback); + if (!callback) callback = dummyCallback.get(); - callback->setTarget( targetDirectory ); + callback->setTarget(targetDirectory); - const QFileInfo fi( targetDirectory ); - DirectoryGuard outDir( fi.absolutePath() ); + const QFileInfo fi(targetDirectory); + DirectoryGuard outDir(fi.absolutePath()); outDir.tryCreate(); - const OpenArchiveInfo* const openArchive = OpenArchiveInfo::instance( archive ); + const OpenArchiveInfo* const openArchive = OpenArchiveInfo::instance(archive); - for( int a = 0; a < openArchive->archiveLink.Arcs.Size(); ++a ) + for (int a = 0; a < openArchive->archiveLink.Arcs.Size(); ++a) { - const CArc& arc = openArchive->archiveLink.Arcs[ a ]; + const CArc& arc = openArchive->archiveLink.Arcs[a]; IInArchive* const arch = arc.Archive; - callback->impl()->setArchive( &arc ); - const LONG extractResult = arch->Extract( 0, static_cast< UInt32 >( -1 ), false, callback->impl() ); - throwIfNotOK( extractResult, QObject::tr("Extraction failed.") ); //TODO is it possible to get a more detailed error? + callback->impl()->setArchive(&arc); + const LONG extractResult = arch->Extract(0, static_cast< UInt32 >(-1), false, callback->impl()); + throwIfNotOK(extractResult, QObject::tr("Extraction failed.")); //TODO is it possible to get a more detailed error? } outDir.release(); } -bool Lib7z::isSupportedArchive( const QString& archive ) +bool Lib7z::isSupportedArchive(const QString &archive) { - QFile file( archive ); - if( !file.open( QIODevice::ReadOnly ) ) + QFile file(archive); + if (!file.open(QIODevice::ReadOnly)) return false; - return isSupportedArchive( &file ); + return isSupportedArchive(&file); } -bool Lib7z::isSupportedArchive( QIODevice* archive ) { - assert( archive ); - assert( !archive->isSequential() ); +bool Lib7z::isSupportedArchive(QIODevice* archive) { + assert(archive); + assert(!archive->isSequential()); const qint64 initialPos = archive->pos(); try { - std::auto_ptr codecs( new CCodecs ); - throwIfNotOK( codecs->Load(), QObject::tr("Could not load codecs") ); + std::auto_ptr codecs(new CCodecs); + throwIfNotOK(codecs->Load(), QObject::tr("Could not load codecs")); CIntVector formatIndices; - if ( !codecs.get()->FindFormatForArchiveType(L"", formatIndices) ) - throw SevenZipException( QObject::tr("Could not retrieve default format") ); + if (!codecs.get()->FindFormatForArchiveType(L"", formatIndices)) + throw SevenZipException(QObject::tr("Could not retrieve default format")); CArchiveLink archiveLink; - const CMyComPtr stream = new QIODeviceInStream( archive ); //CMyComPtr is needed, otherwise it crashes in OpenStream() + const CMyComPtr stream = new QIODeviceInStream(archive); //CMyComPtr is needed, otherwise it crashes in OpenStream() const HRESULT result = archiveLink.Open2(codecs.get(), formatIndices, /*stdInMode*/false, stream, UString(), 0); - archive->seek( initialPos ); + archive->seek(initialPos); return result == S_OK; - } catch ( const SevenZipException& e ) { - archive->seek( initialPos ); + } catch (const SevenZipException& e) { + archive->seek(initialPos); throw e; } catch(const char *err) { - archive->seek( initialPos ); - throw SevenZipException( err ); - } catch( ... ) { - archive->seek( initialPos ); - throw SevenZipException( QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO)) ); + archive->seek(initialPos); + throw SevenZipException(err); + } catch(...) { + archive->seek(initialPos); + throw SevenZipException(QObject::tr("Unknown exception caught (%1)").arg(QString::fromLatin1(Q_FUNC_INFO))); } return false; // never reached } void ExtractItemJob::doStart() { try { - if ( !d->archive ) - throw SevenZipException( tr("Could not list archive: QIODevice not set or already destroyed") ); - if ( d->target ) - extractArchive( d->archive, d->item, d->target, d->callback ); - else if( !d->item.path.isEmpty() ) - extractArchive( d->archive, d->item, d->targetDirectory, d->callback ); + if (!d->archive) + throw SevenZipException(tr("Could not list archive: QIODevice not set or already destroyed")); + if (d->target) + extractArchive(d->archive, d->item, d->target, d->callback); + else if (!d->item.path.isEmpty()) + extractArchive(d->archive, d->item, d->targetDirectory, d->callback); else - extractArchive( d->archive, d->targetDirectory, d->callback ); - } catch ( const SevenZipException& e ) { - setError( Failed ); - setErrorString( e.message() ); - } catch ( ... ) { - setError( Failed ); - setErrorString( QObject::tr("Unknown exception caught (%1)").arg( QObject::tr( "Failed" )) ); + extractArchive(d->archive, d->targetDirectory, d->callback); + } catch (const SevenZipException& e) { + setError(Failed); + setErrorString(e.message()); + } catch (...) { + setError(Failed); + setErrorString(QObject::tr("Unknown exception caught (%1)").arg(QObject::tr("Failed"))); } emitResult(); } -- cgit v1.2.3