MythTV  master
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
UnZip Class Reference

PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupported compression algorithms. Versions after 2.7 may have an incompatible header format and thus be completely incompatible. More...

#include <unzip.h>

Collaboration diagram for UnZip:
Collaboration graph
[legend]

Classes

struct  ZipEntry
 

Public Types

enum  ErrorCode {
  Ok, ZlibInit, ZlibError, OpenFailed,
  PartiallyCorrupted, Corrupted, WrongPassword, NoOpenArchive,
  FileNotFound, ReadFailed, WriteFailed, SeekFailed,
  CreateDirFailed, InvalidDevice, InvalidArchive, HeaderConsistencyError,
  Skip, SkipAll
}
 
enum  ExtractionOption { ExtractPaths = 0x0001, SkipPaths = 0x0002 }
 
enum  CompressionMethod { NoCompression, Deflated, UnknownCompression }
 
enum  FileType { File, Directory }
 

Public Member Functions

 UnZip ()
 
virtual ~UnZip ()
 
 UnZip (const UnZip &)=delete
 
UnZipoperator= (const UnZip &)=delete
 
bool isOpen () const
 
ErrorCode openArchive (const QString &filename)
 
ErrorCode openArchive (QIODevice *device)
 
void closeArchive ()
 
QString archiveComment () const
 
bool contains (const QString &file) const
 
QStringList fileList () const
 
QList< ZipEntryentryList () const
 
ErrorCode extractAll (const QString &dirname, ExtractionOptions options=ExtractPaths)
 
ErrorCode extractAll (const QDir &dir, ExtractionOptions options=ExtractPaths)
 
ErrorCode extractFile (const QString &filename, const QString &dirname, ExtractionOptions options=ExtractPaths)
 
ErrorCode extractFile (const QString &filename, const QDir &dir, ExtractionOptions options=ExtractPaths)
 
ErrorCode extractFile (const QString &filename, QIODevice *device, ExtractionOptions options=ExtractPaths)
 
ErrorCode extractFiles (const QStringList &filenames, const QString &dirname, ExtractionOptions options=ExtractPaths)
 
ErrorCode extractFiles (const QStringList &filenames, const QDir &dir, ExtractionOptions options=ExtractPaths)
 
void setPassword (const QString &pwd)
 

Static Public Member Functions

static QString formatError (UnZip::ErrorCode c)
 

Private Attributes

UnzipPrivated
 

Detailed Description

PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupported compression algorithms. Versions after 2.7 may have an incompatible header format and thus be completely incompatible.

Definition at line 49 of file unzip.h.

Member Enumeration Documentation

◆ ErrorCode

The result of a decompression operation.

Enumerator
Ok 

No error occurred.

ZlibInit 

Failed to init or load the zlib library.

ZlibError 

The zlib library returned some error.

OpenFailed 

Unable to create or open a device.

PartiallyCorrupted 

Corrupted zip archive - some files could be extracted.

Corrupted 

Corrupted or invalid zip archive.

WrongPassword 

Unable to decrypt a password protected file.

NoOpenArchive 

No archive has been opened yet.

FileNotFound 

Unable to find the requested file in the archive.

ReadFailed 

Reading of a file failed.

WriteFailed 

Writing of a file failed.

SeekFailed 

Seek failed.

CreateDirFailed 

Could not create a directory.

InvalidDevice 

A null device has been passed as parameter.

InvalidArchive 

This is not a valid (or supported) ZIP archive.

HeaderConsistencyError 

Local header record info does not match with the central directory record info. The archive may be corrupted.

Skip 

Internal use only.

SkipAll 

Internal use only.

Definition at line 52 of file unzip.h.

◆ ExtractionOption

Some options for the file extraction methods.

Enumerator
ExtractPaths 

Extracts paths (default)

Default. Does not ignore the path of the zipped files.

SkipPaths 

Ignores paths and extracts all the files to the same directory.

Default. Ignores the path of the zipped files and extracts them all to the same root directory.

Definition at line 74 of file unzip.h.

◆ CompressionMethod

Enumerator
NoCompression 
Deflated 
UnknownCompression 

Definition at line 83 of file unzip.h.

◆ FileType

Enumerator
File 
Directory 

Definition at line 88 of file unzip.h.

Constructor & Destructor Documentation

◆ UnZip() [1/2]

UnZip::UnZip ( )

Creates a new Zip file decompressor.

Definition at line 203 of file unzip.cpp.

◆ ~UnZip()

UnZip::~UnZip ( )
virtual

Closes any open archive and releases used resources.

Definition at line 211 of file unzip.cpp.

◆ UnZip() [2/2]

UnZip::UnZip ( const UnZip )
delete

Member Function Documentation

◆ operator=()

UnZip& UnZip::operator= ( const UnZip )
delete

◆ isOpen()

bool UnZip::isOpen ( void  ) const

Returns true if there is an open archive.

Definition at line 220 of file unzip.cpp.

◆ openArchive() [1/2]

UnZip::ErrorCode UnZip::openArchive ( const QString &  filename)

Opens a zip archive and reads the files list. Closes any previously opened archive.

Definition at line 228 of file unzip.cpp.

Referenced by extractZIP().

◆ openArchive() [2/2]

UnZip::ErrorCode UnZip::openArchive ( QIODevice *  device)

Opens a zip archive and reads the entries list. Closes any previously opened archive.

Warning
The class takes ownership of the device so don't delete it!

Definition at line 250 of file unzip.cpp.

◆ closeArchive()

void UnZip::closeArchive ( )

Closes the archive and releases all the used resources (like cached passwords).

Definition at line 264 of file unzip.cpp.

Referenced by extractZIP(), UnzipPrivate::openArchive(), and ~UnZip().

◆ archiveComment()

QString UnZip::archiveComment ( ) const

Definition at line 269 of file unzip.cpp.

◆ formatError()

QString UnZip::formatError ( UnZip::ErrorCode  c)
static

Returns a locale translated error string for a given error code.

Definition at line 279 of file unzip.cpp.

◆ contains()

bool UnZip::contains ( const QString &  file) const

Returns true if the archive contains a file with the given path and name.

Definition at line 308 of file unzip.cpp.

◆ fileList()

QStringList UnZip::fileList ( ) const

Returns complete paths of files and directories in this archive.

Definition at line 319 of file unzip.cpp.

◆ entryList()

QList< UnZip::ZipEntry > UnZip::entryList ( ) const

Returns information for each (correctly parsed) entry of this archive.

Definition at line 327 of file unzip.cpp.

◆ extractAll() [1/2]

UnZip::ErrorCode UnZip::extractAll ( const QString &  dirname,
ExtractionOptions  options = ExtractPaths 
)

Extracts the whole archive to a directory.

Definition at line 363 of file unzip.cpp.

Referenced by extractZIP().

◆ extractAll() [2/2]

UnZip::ErrorCode UnZip::extractAll ( const QDir &  dir,
ExtractionOptions  options = ExtractPaths 
)

Extracts the whole archive to a directory.

Definition at line 371 of file unzip.cpp.

◆ extractFile() [1/3]

UnZip::ErrorCode UnZip::extractFile ( const QString &  filename,
const QString &  dirname,
ExtractionOptions  options = ExtractPaths 
)

Extracts a single file to a directory.

Definition at line 417 of file unzip.cpp.

Referenced by UnzipPrivate::extractFile(), and extractFiles().

◆ extractFile() [2/3]

UnZip::ErrorCode UnZip::extractFile ( const QString &  filename,
const QDir &  dir,
ExtractionOptions  options = ExtractPaths 
)

Extracts a single file to a directory.

Definition at line 425 of file unzip.cpp.

◆ extractFile() [3/3]

UnZip::ErrorCode UnZip::extractFile ( const QString &  filename,
QIODevice *  dev,
ExtractionOptions  options = ExtractPaths 
)

Extracts a single file to a directory.

Definition at line 441 of file unzip.cpp.

◆ extractFiles() [1/2]

UnZip::ErrorCode UnZip::extractFiles ( const QStringList &  filenames,
const QString &  dirname,
ExtractionOptions  options = ExtractPaths 
)

Extracts a list of files. Stops extraction at the first error (but continues if a file does not exist in the archive).

Definition at line 460 of file unzip.cpp.

◆ extractFiles() [2/2]

UnZip::ErrorCode UnZip::extractFiles ( const QStringList &  filenames,
const QDir &  dir,
ExtractionOptions  options = ExtractPaths 
)

Extracts a list of files. Stops extraction at the first error (but continues if a file does not exist in the archive).

Definition at line 481 of file unzip.cpp.

◆ setPassword()

void UnZip::setPassword ( const QString &  pwd)

Remove/replace this method to add your own password retrieval routine.

Definition at line 500 of file unzip.cpp.

Member Data Documentation

◆ d

UnzipPrivate* UnZip::d
private

The documentation for this class was generated from the following files: