00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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