1 /****************************************************************************
2 ** Filename: unzip.h
3 ** Last updated [dd/mm/yyyy]: 27/03/2011
4 **
5 ** pkzip 2.0 decompression.
6 **
7 ** Some of the code has been inspired by other open source projects,
8 ** (mainly Info-Zip and Gilles Vollant's minizip).
9 ** Compression and decompression actually uses the zlib library.
10 **
11 ** Copyright (C) 2007-2012 Angius Fabrizio. All rights reserved.
12 **
13 ** This file is part of the OSDaB project (http://osdab.42cows.org/).
14 **
15 ** This file may be distributed and/or modified under the terms of the
16 ** GNU General Public License version 2 as published by the Free Software
17 ** Foundation and appearing in the file LICENSE.GPL included in the
18 ** packaging of this file.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See the file LICENSE.GPL that came with this software distribution or
24 ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
25 **
26 **********************************************************************/
27
28 #ifndef OSDAB_UNZIP__H
29 #define OSDAB_UNZIP__H
30
31 #include "zipglobal.h"
32
33 #include <QtCore/QDateTime>
34 #include <QtCore/QMap>
35 #include <QtCore/QtGlobal>
36
37 #include <zlib.h>
38 //#include <zlib/zlib.h>
39
40 class QDir;
41 class QFile;
42 class QIODevice;
43 class QString;
44 #include <QStringList>
45
OSDAB_BEGIN_NAMESPACE(Zip)46 OSDAB_BEGIN_NAMESPACE(Zip)
47
48 class UnzipPrivate;
49
50 class /*OSDAB_ZIP_EXPORT*/ UnZip
51 {
52 public:
53 enum ErrorCode
54 {
55 Ok,
56 ZlibInit,
57 ZlibError,
58 OpenFailed,
59 PartiallyCorrupted,
60 Corrupted,
61 WrongPassword,
62 NoOpenArchive,
63 FileNotFound,
64 ReadFailed,
65 WriteFailed,
66 SeekFailed,
67 CreateDirFailed,
68 InvalidDevice,
69 InvalidArchive,
70 HeaderConsistencyError,
71
72 Skip, SkipAll // internal use only
73 };
74
75 enum ExtractionOption
76 {
77 ExtractPaths = 0x0001,
78 SkipPaths = 0x0002,
79 VerifyOnly = 0x0004,
80 NoSilentDirectoryCreation = 0x0008
81 };
82 Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
83
84 enum CompressionMethod
85 {
86 NoCompression, Deflated, UnknownCompression
87 };
88
89 enum FileType
90 {
91 File, Directory
92 };
93
94 struct ZipEntry
95 {
96 ZipEntry();
97
98 QString filename;
99 QString comment;
100
101 quint32 compressedSize;
102 quint32 uncompressedSize;
103 quint32 crc32;
104
105 QDateTime lastModified;
106
107 CompressionMethod compression;
108 FileType type;
109
110 bool encrypted;
111 };
112
113 UnZip();
114 virtual ~UnZip();
115
116 bool isOpen() const;
117
118 ErrorCode openArchive(const QString& filename);
119 ErrorCode openArchive(QIODevice* device);
120 void closeArchive();
121
122 QString archiveComment() const;
123
124 QString formatError(UnZip::ErrorCode c) const;
125
126 bool contains(const QString& file) const;
127
128 QStringList fileList() const;
129 QList<ZipEntry> entryList() const;
130
131 ErrorCode verifyArchive();
132
133 ErrorCode extractAll(const QString& dirname, ExtractionOptions options = ExtractPaths);
134 ErrorCode extractAll(const QDir& dir, ExtractionOptions options = ExtractPaths);
135
136 ErrorCode extractFile(const QString& filename, const QString& dirname, ExtractionOptions options = ExtractPaths);
137 ErrorCode extractFile(const QString& filename, const QDir& dir, ExtractionOptions options = ExtractPaths);
138 ErrorCode extractFile(const QString& filename, QIODevice* device, ExtractionOptions options = ExtractPaths);
139
140 ErrorCode extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options = ExtractPaths);
141 ErrorCode extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options = ExtractPaths);
142
143 void setPassword(const QString& pwd);
144
145 private:
146 UnzipPrivate* d;
147 };
148
149 Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
150
151 OSDAB_END_NAMESPACE
152
153 #endif // OSDAB_UNZIP__H
154