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/zconf.h> |
50 |
|
51 |
/*! |
52 |
zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate()) |
53 |
we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;) |
54 |
*/ |
55 |
#define ZIP_READ_BUFFER (256*1024) |
56 |
|
57 |
OSDAB_BEGIN_NAMESPACE(Zip) |
58 |
|
59 |
class ZipPrivate : public QObject |
60 |
{ |
61 |
Q_OBJECT |
62 |
|
63 |
public: |
64 |
// uLongf from zconf.h |
65 |
typedef uLongf crc_t; |
66 |
|
67 |
ZipPrivate(); |
68 |
virtual ~ZipPrivate(); |
69 |
|
70 |
QMap<QString,ZipEntryP*>* headers; |
71 |
|
72 |
QIODevice* device; |
73 |
QFile* file; |
74 |
|
75 |
char buffer1[ZIP_READ_BUFFER]; |
76 |
char buffer2[ZIP_READ_BUFFER]; |
77 |
|
78 |
unsigned char* uBuffer; |
79 |
|
80 |
const crc_t* crcTable; |
81 |
|
82 |
QString comment; |
83 |
QString password; |
84 |
|
85 |
Zip::ErrorCode createArchive(QIODevice* device); |
86 |
Zip::ErrorCode closeArchive(); |
87 |
void reset(); |
88 |
|
89 |
bool zLibInit(); |
90 |
|
91 |
bool containsEntry(const QFileInfo& info) const; |
92 |
|
93 |
Zip::ErrorCode addDirectory(const QString& path, const QString& root, |
94 |
Zip::CompressionOptions options, Zip::CompressionLevel level, |
95 |
int hierarchyLevel, int* addedFiles = 0); |
96 |
Zip::ErrorCode addFiles(const QStringList& paths, const QString& root, |
97 |
Zip::CompressionOptions options, Zip::CompressionLevel level, |
98 |
int* addedFiles); |
99 |
|
100 |
Zip::ErrorCode createEntry(const QFileInfo& file, const QString& root, |
101 |
Zip::CompressionLevel level); |
102 |
Zip::CompressionLevel detectCompressionByMime(const QString& ext); |
103 |
|
104 |
inline quint32 updateChecksum(const quint32& crc, const quint32& val) const; |
105 |
|
106 |
inline void encryptBytes(quint32* keys, char* buffer, qint64 read); |
107 |
|
108 |
inline void setULong(quint32 v, char* buffer, unsigned int offset); |
109 |
inline void updateKeys(quint32* keys, int c) const; |
110 |
inline void initKeys(quint32* keys) const; |
111 |
inline int decryptByte(quint32 key2) const; |
112 |
|
113 |
inline QString extractRoot(const QString& p, Zip::CompressionOptions o); |
114 |
|
115 |
private slots: |
116 |
void deviceDestroyed(QObject*); |
117 |
|
118 |
private: |
119 |
int compressionStrategy(const QString& path, QIODevice& file) const; |
120 |
Zip::ErrorCode deflateFile(const QFileInfo& fileInfo, |
121 |
quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys); |
122 |
Zip::ErrorCode storeFile(const QString& path, QIODevice& file, |
123 |
quint32& crc, qint64& written, quint32** keys); |
124 |
Zip::ErrorCode compressFile(const QString& path, QIODevice& file, |
125 |
quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys); |
126 |
Zip::ErrorCode do_closeArchive(); |
127 |
Zip::ErrorCode writeEntry(const QString& fileName, const ZipEntryP* h, quint32& szCentralDir); |
128 |
Zip::ErrorCode writeCentralDir(quint32 offCentralDir, quint32 szCentralDir); |
129 |
}; |
130 |
|
131 |
OSDAB_END_NAMESPACE |
132 |
|
133 |
#endif // OSDAB_ZIP_P__H |