MythTV  master
unzip.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Filename: unzip.h
3 ** Last updated [dd/mm/yyyy]: 28/01/2007
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-2008 Angius Fabrizio. All rights reserved.
12 **
13 ** This file is part of the OSDaB project (http://osdab.sourceforge.net/).
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 <QtGlobal>
32 #include <QMap>
33 #include <QDateTime>
34 
35 #include <zlib.h>
36 #undef Z_NULL
37 #define Z_NULL nullptr
38 
39 #include "mythbaseexp.h"
40 
41 class UnzipPrivate;
42 class QIODevice;
43 class QFile;
44 class QDir;
45 class QStringList;
46 class QString;
47 
48 
50 {
51 public:
52  enum ErrorCode
53  {
54  Ok,
70 
71  Skip, SkipAll // internal use only
72  };
73 
75  {
77  ExtractPaths = 0x0001,
79  SkipPaths = 0x0002
80  };
81  Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
82 
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;
102  quint32 crc32;
103 
104  QDateTime lastModified;
105 
108 
109  bool encrypted;
110  };
111 
112  UnZip();
113  virtual ~UnZip();
114 
115  UnZip(const UnZip &) = delete; // not copyable
116  UnZip &operator=(const UnZip &) = delete; // not copyable
117 
118  bool isOpen() const;
119 
120  ErrorCode openArchive(const QString& filename);
121  ErrorCode openArchive(QIODevice* device);
122  void closeArchive();
123 
124  QString archiveComment() const;
125 
126  static QString formatError(UnZip::ErrorCode c) ;
127 
128  bool contains(const QString& file) const;
129 
130  QStringList fileList() const;
131  QList<ZipEntry> entryList() const;
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; // NOLINT(readability-identifier-naming)
147 };
148 
149 Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
150 
151 #endif // OSDAB_UNZIP__H
bool encrypted
Definition: unzip.h:109
QString comment
Definition: unzip.h:98
CompressionMethod compression
Definition: unzip.h:106
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
QDateTime lastModified
Definition: unzip.h:104
quint32 crc32
Definition: unzip.h:102
ErrorCode
Definition: unzip.h:52
FileType type
Definition: unzip.h:107
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
Definition: unzip.h:49
QString filename
Definition: unzip.h:97
quint32 compressedSize
Definition: unzip.h:100
UnzipPrivate * d
Definition: unzip.h:146
FileType
Definition: unzip.h:88
CompressionMethod
Definition: unzip.h:83
quint32 uncompressedSize
Definition: unzip.h:101
ExtractionOption
Definition: unzip.h:74