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 
47 {
48 public:
49  enum ErrorCode
50  {
51  Ok,
67 
68  Skip, SkipAll // internal use only
69  };
70 
72  {
74  ExtractPaths = 0x0001,
76  SkipPaths = 0x0002
77  };
78  Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
79 
81  {
82  NoCompression, Deflated, UnknownCompression
83  };
84 
85  enum FileType
86  {
87  File, Directory
88  };
89 
90  struct ZipEntry
91  {
92  ZipEntry();
93 
94  QString filename;
95  QString comment;
96 
97  quint32 compressedSize;
99  quint32 crc32;
100 
101  QDateTime lastModified;
102 
105 
106  bool encrypted;
107  };
108 
109  UnZip();
110  virtual ~UnZip();
111 
112  UnZip(const UnZip &) = delete; // not copyable
113  UnZip &operator=(const UnZip &) = delete; // not copyable
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  static QString formatError(UnZip::ErrorCode c) ;
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; // NOLINT(readability-identifier-naming)
144 };
145 
146 Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
147 
148 #endif // OSDAB_UNZIP_H
UnZip::SeekFailed
@ SeekFailed
Definition: unzip.h:62
UnZip::ExtractionOption
ExtractionOption
Definition: unzip.h:71
UnZip::ZipEntry::encrypted
bool encrypted
Definition: unzip.h:106
UnZip::ZipEntry::compressedSize
quint32 compressedSize
Definition: unzip.h:97
UnZip::InvalidDevice
@ InvalidDevice
Definition: unzip.h:64
UnZip::ZipEntry::lastModified
QDateTime lastModified
Definition: unzip.h:101
UnZip::ZlibInit
@ ZlibInit
Definition: unzip.h:52
mythbaseexp.h
UnZip::ZipEntry::comment
QString comment
Definition: unzip.h:95
UnZip::WrongPassword
@ WrongPassword
Definition: unzip.h:57
UnZip::OpenFailed
@ OpenFailed
Definition: unzip.h:54
build_compdb.file
file
Definition: build_compdb.py:55
UnzipPrivate
Definition: unzip_p.h:53
UnZip::ZipEntry::type
FileType type
Definition: unzip.h:104
UnZip::WriteFailed
@ WriteFailed
Definition: unzip.h:61
UnZip::HeaderConsistencyError
@ HeaderConsistencyError
Definition: unzip.h:66
UnZip::File
@ File
Definition: unzip.h:87
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
UnZip::ErrorCode
ErrorCode
Definition: unzip.h:49
UnZip::FileNotFound
@ FileNotFound
Definition: unzip.h:59
UnZip::ZipEntry::filename
QString filename
Definition: unzip.h:94
UnZip::ZipEntry::crc32
quint32 crc32
Definition: unzip.h:99
UnZip::ReadFailed
@ ReadFailed
Definition: unzip.h:60
UnZip::ZlibError
@ ZlibError
Definition: unzip.h:53
UnZip::ZipEntry::compression
CompressionMethod compression
Definition: unzip.h:103
UnZip::CompressionMethod
CompressionMethod
Definition: unzip.h:80
UnZip::NoOpenArchive
@ NoOpenArchive
Definition: unzip.h:58
UnZip::PartiallyCorrupted
@ PartiallyCorrupted
Definition: unzip.h:55
UnZip::FileType
FileType
Definition: unzip.h:85
UnZip
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
Definition: unzip.h:46
UnZip::ZipEntry::uncompressedSize
quint32 uncompressedSize
Definition: unzip.h:98
UnZip::Ok
@ Ok
Definition: unzip.h:51
UnZip::InvalidArchive
@ InvalidArchive
Definition: unzip.h:65
UnZip::Corrupted
@ Corrupted
Definition: unzip.h:56
UnZip::CreateDirFailed
@ CreateDirFailed
Definition: unzip.h:63
UnZip::d
UnzipPrivate * d
Definition: unzip.h:143
UnZip::ZipEntry
Definition: unzip.h:90
build_compdb.filename
filename
Definition: build_compdb.py:21
build_compdb.options
options
Definition: build_compdb.py:11