FGx  1
unzip.h
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-2011 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 
39 class QDir;
40 class QFile;
41 class QIODevice;
42 class QString;
43 class QStringList;
44 
45 OSDAB_BEGIN_NAMESPACE(Zip)
46 
47 class UnzipPrivate;
48 
49 class OSDAB_ZIP_EXPORT UnZip
50 {
51 public:
52  enum ErrorCode
53  {
54  Ok,
55  ZlibInit,
56  ZlibError,
57  OpenFailed,
58  PartiallyCorrupted,
59  Corrupted,
60  WrongPassword,
61  NoOpenArchive,
62  FileNotFound,
63  ReadFailed,
64  WriteFailed,
65  SeekFailed,
66  CreateDirFailed,
67  InvalidDevice,
68  InvalidArchive,
69  HeaderConsistencyError,
70 
71  Skip, SkipAll // internal use only
72  };
73 
75  {
77  ExtractPaths = 0x0001,
79  SkipPaths = 0x0002
80  };
81  Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
82 
83  enum CompressionMethod
84  {
85  NoCompression, Deflated, UnknownCompression
86  };
87 
88  enum FileType
89  {
90  File, Directory
91  };
92 
93  struct ZipEntry
94  {
95  ZipEntry();
96 
97  QString filename;
98  QString comment;
99 
100  quint32 compressedSize;
101  quint32 uncompressedSize;
102  quint32 crc32;
103 
104  QDateTime lastModified;
105 
106  CompressionMethod compression;
107  FileType type;
108 
109  bool encrypted;
110  };
111 
112  UnZip();
113  virtual ~UnZip();
114 
115  bool isOpen() const;
116 
117  ErrorCode openArchive(const QString& filename);
118  ErrorCode openArchive(QIODevice* device);
119  void closeArchive();
120 
121  QString archiveComment() const;
122 
123  QString formatError(UnZip::ErrorCode c) const;
124 
125  bool contains(const QString& file) const;
126 
127  QStringList fileList() const;
128  QList<ZipEntry> entryList() const;
129 
130  ErrorCode extractAll(const QString& dirname, ExtractionOptions options = ExtractPaths);
131  ErrorCode extractAll(const QDir& dir, ExtractionOptions options = ExtractPaths);
132 
133  ErrorCode extractFile(const QString& filename, const QString& dirname, ExtractionOptions options = ExtractPaths);
134  ErrorCode extractFile(const QString& filename, const QDir& dir, ExtractionOptions options = ExtractPaths);
135  ErrorCode extractFile(const QString& filename, QIODevice* device, ExtractionOptions options = ExtractPaths);
136 
137  ErrorCode extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options = ExtractPaths);
138  ErrorCode extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options = ExtractPaths);
139 
140  void setPassword(const QString& pwd);
141 
142 private:
143  UnzipPrivate* d;
144 };
145 
146 Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
147 
148 OSDAB_END_NAMESPACE
149 
150 #endif // OSDAB_UNZIP__H
Zip file compression.
Definition: zip.h:48
Definition: unzip.h:93
ErrorCode
Definition: unzip.h:52
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
Definition: unzip.h:49
Definition: unzip_p.h:54
ExtractionOption
Definition: unzip.h:74