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
UnZip::NoCompression
@ NoCompression
Definition: unzip.h:85
UnZip::SeekFailed
@ SeekFailed
Definition: unzip.h:65
UnZip::ExtractionOption
ExtractionOption
Definition: unzip.h:75
UnZip::ZipEntry::encrypted
bool encrypted
Definition: unzip.h:109
UnZip::ZipEntry::compressedSize
quint32 compressedSize
Definition: unzip.h:100
UnZip::InvalidDevice
@ InvalidDevice
Definition: unzip.h:67
UnZip::ZipEntry::lastModified
QDateTime lastModified
Definition: unzip.h:104
UnZip::ZlibInit
@ ZlibInit
Definition: unzip.h:55
mythbaseexp.h
UnZip::ZipEntry::comment
QString comment
Definition: unzip.h:98
UnZip::WrongPassword
@ WrongPassword
Definition: unzip.h:60
UnZip::OpenFailed
@ OpenFailed
Definition: unzip.h:57
build_compdb.file
file
Definition: build_compdb.py:55
UnzipPrivate
Definition: unzip_p.h:54
UnZip::ZipEntry::type
FileType type
Definition: unzip.h:107
UnZip::UnZip
UnZip(const UnZip &)=delete
UnZip::WriteFailed
@ WriteFailed
Definition: unzip.h:64
UnZip::HeaderConsistencyError
@ HeaderConsistencyError
Definition: unzip.h:69
UnZip::File
@ File
Definition: unzip.h:90
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
UnZip::ErrorCode
ErrorCode
Definition: unzip.h:53
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:640
UnZip::FileNotFound
@ FileNotFound
Definition: unzip.h:62
UnZip::ZipEntry::filename
QString filename
Definition: unzip.h:97
UnZip::ZipEntry::crc32
quint32 crc32
Definition: unzip.h:102
UnZip::ReadFailed
@ ReadFailed
Definition: unzip.h:63
UnZip::ZlibError
@ ZlibError
Definition: unzip.h:56
UnZip::ZipEntry::compression
CompressionMethod compression
Definition: unzip.h:106
UnZip::CompressionMethod
CompressionMethod
Definition: unzip.h:84
UnZip::NoOpenArchive
@ NoOpenArchive
Definition: unzip.h:61
UnZip::PartiallyCorrupted
@ PartiallyCorrupted
Definition: unzip.h:58
UnZip::operator=
UnZip & operator=(const UnZip &)=delete
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1177
UnZip::FileType
FileType
Definition: unzip.h:89
UnZip
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
Definition: unzip.h:50
UnZip::ZipEntry::uncompressedSize
quint32 uncompressedSize
Definition: unzip.h:101
UnZip::Ok
@ Ok
Definition: unzip.h:54
UnZip::InvalidArchive
@ InvalidArchive
Definition: unzip.h:68
UnZip::Corrupted
@ Corrupted
Definition: unzip.h:59
UnZip::CreateDirFailed
@ CreateDirFailed
Definition: unzip.h:66
UnZip::d
UnzipPrivate * d
Definition: unzip.h:146
UnZip::Skip
@ Skip
Definition: unzip.h:71
UnZip::ZipEntry
Definition: unzip.h:94
build_compdb.options
options
Definition: build_compdb.py:11