Scribus
Open source desktop publishing at your fingertips
zip_p.h
1 /****************************************************************************
2 ** Filename: zip_p.h
3 ** Last updated [dd/mm/yyyy]: 27/03/2011
4 **
5 ** pkzip 2.0 file compression.
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 //
29 // W A R N I N G
30 // -------------
31 //
32 // This file is not part of the Zip/UnZip API. It exists purely as an
33 // implementation detail. This header file may change from version to
34 // version without notice, or even be removed.
35 //
36 // We mean it.
37 //
38 
39 #ifndef OSDAB_ZIP_P__H
40 #define OSDAB_ZIP_P__H
41 
42 #include "zip.h"
43 #include "zipentry_p.h"
44 
45 #include <QtCore/QFileInfo>
46 #include <QtCore/QObject>
47 #include <QtCore/QtGlobal>
48 
49 #include <zlib.h>
50 //#include <zlib/zconf.h>
51 
56 #define ZIP_READ_BUFFER (256*1024)
57 
58 OSDAB_BEGIN_NAMESPACE(Zip)
59 
60 class ZipPrivate : public QObject
61 {
62  Q_OBJECT
63 
64 public:
65  typedef z_crc_t crc_t;
66  ZipPrivate();
67  virtual ~ZipPrivate();
68 
69  QMap<QString,ZipEntryP*>* headers;
70 
71  QIODevice* device;
72  QFile* file;
73 
74  char buffer1[ZIP_READ_BUFFER];
75  char buffer2[ZIP_READ_BUFFER];
76 
77  unsigned char* uBuffer;
78 
79  const crc_t* crcTable;
80 
81  QString comment;
82  QString password;
83 
84  Zip::ErrorCode createArchive(QIODevice* device);
85  Zip::ErrorCode closeArchive();
86  void reset();
87 
88  bool zLibInit();
89 
90  bool containsEntry(const QFileInfo& info) const;
91 
92  Zip::ErrorCode addDirectory(const QString& path, const QString& root,
93  Zip::CompressionOptions options, Zip::CompressionLevel level,
94  int hierarchyLevel, int* addedFiles = 0);
95  Zip::ErrorCode addFiles(const QStringList& paths, const QString& root,
96  Zip::CompressionOptions options, Zip::CompressionLevel level,
97  int* addedFiles);
98 
99  Zip::ErrorCode createEntry(const QFileInfo& file, const QString& root,
100  Zip::CompressionLevel level);
101  Zip::CompressionLevel detectCompressionByMime(const QString& ext);
102 
103  inline quint32 updateChecksum(const quint32& crc, const quint32& val) const;
104 
105  inline void encryptBytes(quint32* keys, char* buffer, qint64 read);
106 
107  inline void setULong(quint32 v, char* buffer, unsigned int offset);
108  inline void updateKeys(quint32* keys, int c) const;
109  inline void initKeys(quint32* keys) const;
110  inline int decryptByte(quint32 key2) const;
111 
112  inline QString extractRoot(const QString& p, Zip::CompressionOptions o);
113 
114 private slots:
115  void deviceDestroyed(QObject*);
116 
117 private:
118  int compressionStrategy(const QString& path, QIODevice& file) const;
119  Zip::ErrorCode deflateFile(const QFileInfo& fileInfo,
120  quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys);
121  Zip::ErrorCode storeFile(const QString& path, QIODevice& file,
122  quint32& crc, qint64& written, quint32** keys);
123  Zip::ErrorCode compressFile(const QString& path, QIODevice& file,
124  quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys);
125  Zip::ErrorCode do_closeArchive();
126  Zip::ErrorCode writeEntry(const QString& fileName, const ZipEntryP* h, quint32& szCentralDir);
127  Zip::ErrorCode writeCentralDir(quint32 offCentralDir, quint32 szCentralDir);
128 };
129 
130 OSDAB_END_NAMESPACE
131 
132 #endif // OSDAB_ZIP_P__H
CompressionLevel
Definition: zip.h:67
Zip file compression.
Definition: zip.h:49
Definition: zipentry_p.h:47
Definition: zip_p.h:60
ErrorCode
Definition: zip.h:52
Binary buffer.
Definition: pdbim.h:93