unzip.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Filename: unzip.h
00003 ** Last updated [dd/mm/yyyy]: 28/01/2007
00004 **
00005 ** pkzip 2.0 decompression.
00006 **
00007 ** Some of the code has been inspired by other open source projects,
00008 ** (mainly Info-Zip and Gilles Vollant's minizip).
00009 ** Compression and decompression actually uses the zlib library.
00010 **
00011 ** Copyright (C) 2007 Angius Fabrizio. All rights reserved.
00012 **
00013 ** This file is part of the OSDaB project (http://osdab.sourceforge.net/).
00014 **
00015 ** This file may be distributed and/or modified under the terms of the
00016 ** GNU General Public License version 2 as published by the Free Software
00017 ** Foundation and appearing in the file LICENSE.GPL included in the
00018 ** packaging of this file.
00019 **
00020 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022 **
00023 ** See the file LICENSE.GPL that came with this software distribution or
00024 ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
00025 **
00026 **********************************************************************/
00027 
00028 #ifndef OSDAB_UNZIP__H
00029 #define OSDAB_UNZIP__H
00030 
00031 #include <QtGlobal>
00032 #include <QMap>
00033 #include <QDateTime>
00034 
00035 #include <zlib.h>
00036 
00037 class UnzipPrivate;
00038 class QIODevice;
00039 class QFile;
00040 class QDir;
00041 class QStringList;
00042 class QString;
00043 
00044 
00045 class UnZip
00046 {
00047 public:
00048     enum ErrorCode
00049     {
00050         Ok,
00051         ZlibInit,
00052         ZlibError,
00053         OpenFailed,
00054         PartiallyCorrupted,
00055         Corrupted,
00056         WrongPassword,
00057         NoOpenArchive,
00058         FileNotFound,
00059         ReadFailed,
00060         WriteFailed,
00061         SeekFailed,
00062         CreateDirFailed,
00063         InvalidDevice,
00064         InvalidArchive,
00065         HeaderConsistencyError,
00066 
00067         Skip, SkipAll // internal use only
00068     };
00069 
00070     enum ExtractionOption
00071     {
00073         ExtractPaths = 0x0001,
00075         SkipPaths = 0x0002
00076     };
00077     Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
00078 
00079     enum CompressionMethod
00080     {
00081         NoCompression, Deflated, UnknownCompression
00082     };
00083 
00084     enum FileType
00085     {
00086         File, Directory
00087     };
00088 
00089     typedef struct ZipEntry
00090     {
00091         ZipEntry();
00092 
00093         QString filename;
00094         QString comment;
00095 
00096         quint32 compressedSize;
00097         quint32 uncompressedSize;
00098         quint32 crc32;
00099 
00100         QDateTime lastModified;
00101 
00102         CompressionMethod compression;
00103         FileType type;
00104 
00105         bool encrypted;
00106     };
00107 
00108     UnZip();
00109     virtual ~UnZip();
00110 
00111     bool isOpen() const;
00112 
00113     ErrorCode openArchive(const QString& filename);
00114     ErrorCode openArchive(QIODevice* device);
00115     void closeArchive();
00116 
00117     QString archiveComment() const;
00118 
00119     QString formatError(UnZip::ErrorCode c) const;
00120 
00121     bool contains(const QString& file) const;
00122 
00123     QStringList fileList() const;
00124     QList<ZipEntry> entryList() const;
00125 
00126     ErrorCode extractAll(const QString& dirname, ExtractionOptions options = ExtractPaths);
00127     ErrorCode extractAll(const QDir& dir, ExtractionOptions options = ExtractPaths);
00128 
00129     ErrorCode extractFile(const QString& filename, const QString& dirname, ExtractionOptions options = ExtractPaths);
00130     ErrorCode extractFile(const QString& filename, const QDir& dir, ExtractionOptions options = ExtractPaths);
00131     ErrorCode extractFile(const QString& filename, QIODevice* device, ExtractionOptions options = ExtractPaths);
00132 
00133     ErrorCode extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options = ExtractPaths);
00134     ErrorCode extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options = ExtractPaths);
00135 
00136     void setPassword(const QString& pwd);
00137 
00138 private:
00139     UnzipPrivate* d;
00140 };
00141 
00142 Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
00143 
00144 #endif // OSDAB_UNZIP__H