FGx  1
zip.h
1 /****************************************************************************
2 ** Filename: zip.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-2011 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 #ifndef OSDAB_ZIP__H
29 #define OSDAB_ZIP__H
30 
31 #include "zipglobal.h"
32 
33 #include <QtCore/QMap>
34 #include <QtCore/QtGlobal>
35 
36 #include "zlib.h"
37 
38 class QIODevice;
39 class QFile;
40 class QDir;
41 class QStringList;
42 class QString;
43 
44 OSDAB_BEGIN_NAMESPACE(Zip)
45 
46 class ZipPrivate;
47 
48 class OSDAB_ZIP_EXPORT Zip
49 {
50 public:
51  enum ErrorCode
52  {
53  Ok,
54  ZlibInit,
55  ZlibError,
56  FileExists,
57  OpenFailed,
58  NoOpenArchive,
59  FileNotFound,
60  ReadFailed,
61  WriteFailed,
62  SeekFailed
63  };
64 
66  {
67  Store,
68  Deflate1 = 1, Deflate2, Deflate3, Deflate4,
69  Deflate5, Deflate6, Deflate7, Deflate8, Deflate9,
70  AutoCPU, AutoMIME, AutoFull
71  };
72 
74  {
76  RelativePaths = 0x0001,
78  AbsolutePaths = 0x0002,
80  IgnorePaths = 0x0004
81  };
82  Q_DECLARE_FLAGS(CompressionOptions, CompressionOption)
83 
84  Zip();
85  virtual ~Zip();
86 
87  bool isOpen() const;
88 
89  void setPassword(const QString& pwd);
90  void clearPassword();
91  QString password() const;
92 
93  ErrorCode createArchive(const QString& file, bool overwrite = true);
94  ErrorCode createArchive(QIODevice* device);
95 
96  QString archiveComment() const;
97  void setArchiveComment(const QString& comment);
98 
99  ErrorCode addDirectoryContents(const QString& path, CompressionLevel level = AutoFull);
100  ErrorCode addDirectoryContents(const QString& path, const QString& root, CompressionLevel level = AutoFull);
101 
102  ErrorCode addDirectory(const QString& path, CompressionOptions options = RelativePaths, CompressionLevel level = AutoFull);
103  ErrorCode addDirectory(const QString& path, const QString& root, CompressionLevel level = AutoFull);
104  ErrorCode addDirectory(const QString& path, const QString& root, CompressionOptions options = RelativePaths, CompressionLevel level = AutoFull);
105 
106  ErrorCode closeArchive();
107 
108  QString formatError(ErrorCode c) const;
109 
110 private:
111  ZipPrivate* d;
112 };
113 
114 Q_DECLARE_OPERATORS_FOR_FLAGS(Zip::CompressionOptions)
115 
116 OSDAB_END_NAMESPACE
117 
118 #endif // OSDAB_ZIP__H
Zip file compression.
Definition: zip.h:48
CompressionOption
Definition: zip.h:73
CompressionLevel
Definition: zip.h:65
Definition: zip_p.h:57
ErrorCode
Definition: zip.h:51