AbZip  1.5
AbZip.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Andy Bray
4 **
5 ** This file is part of AbZip.
6 **
7 ** AbZip is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** AbZip is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with AbZip. If not, see <http://www.gnu.org/licenses/>.
19 **
20 ****************************************************************************/
21 
22 #ifndef ABZIP_H
23 #define ABZIP_H
24 
25 #include "zipglobal.h"
26 
27 #include <QObject>
28 #include <QIODevice>
29 #include <QDir>
30 
31 class AbZipPrivate;
32 class ZipInfo;
33 class ZipFileInfo;
34 
35 class ZIP_EXPORT AbZip : public QObject
36 {
37  Q_OBJECT
38 
39  AbZipPrivate* const d_ptr;
40  Q_DECLARE_PRIVATE(AbZip)
41 
42  friend class ZipDirIteratorPrivate;
43 
44 public:
46  AbZip(QObject *parent = 0);
47 
49  AbZip(const QString& zipName, QObject *parent = 0);
50 
52  AbZip(QIODevice *ioDevice, QObject *parent = 0);
53 
55  virtual ~AbZip();
56 
57  enum Mode { modeOpenRead,
58  modeOpenWrite,
60  modeCreateNew
61  };
65 
67  enum ErrorCode
68  {
69  Ok,
91  CentralDirError
92  };
93 
95  enum Option
96  {
97  None = 0x0000,
98  VerifyOnly = 0x0001,
99  CaseSensitive = 0x0002,
101  Recursive = 0x0004,
102  DontOverwrite = 0x0008,
103  IgnoreFolders = 0x0010,
104  IgnoreFiles = 0x0020,
105 
106  BackupExisting = 0x0040,
107 
110  ExtractPaths = 0x0080,
111 
112  AddRelativePaths = 0x0100,
113  AddAbsolutePaths = 0x0200,
114  AddIgnorePaths = 0x0400,
115  AddReplaceFiles = 0x1000,
118  SkipExistingFiles = 0x2000,
119  ContinueOnError = 0x4000,
120 
121  IgnoreStoreOnlyChecks = 0x8000,
122 
124  useBZip2Compression = 0x10000,
125  useAESEncryption = 0x20000,
127  useLzmaCompression = 0x40000,
128 
131  SortByName = 0x80000,
132  SortByTime = 0x100000,
133  SortByCompressedSize = 0x200000,
134  SortByUncompressedSize = 0x400000,
135  SortByType = 0x800000,
136  SortReversed = 0x1000000
137 
138  };
139  Q_DECLARE_FLAGS(ZipOptions, Option)
140 
141 
155  bool open( Mode mode = modeOpenRead, ZipOptions options = None );
156 
162  void close();
163 
168  bool isOpen();
169 
184  bool addFile(const QString& file, const QString& root, ZipOptions options = AddRelativePaths, int level = -1 );
185 
199  bool addFile(const QString& file, ZipOptions options = AddRelativePaths, int level = -1 );
200 
219  bool addDirectory(const QString& srcPath, const QString& root, ZipOptions options = AddRelativePaths, int level = -1 );
220 
234  bool addDirectory(const QString& srcPath, ZipOptions options = AddRelativePaths, int level = -1 );
235 
246  bool extractAll(const QString& destPath, ZipOptions options = ExtractPaths);
255  bool extractAll(const QString& destPath, const QString& fromRoot, ZipOptions options = ExtractPaths);
256 
266  bool extractFile(const QString& filename, const QString& destPath, ZipOptions options = ExtractPaths);
267 
278  bool extractFiles(const QStringList& listFiles, const QString& destPath, ZipOptions options = ExtractPaths);
279 
292  bool deleteFile(const QString& filename, ZipOptions options = AbZip::None);
293 
302  bool renameFile(const QString& oldFilename, const QString& newFilename, AbZip::ZipOptions options = AbZip::None);
303 
304 
311  bool checkIntegrity();
312 
320  bool repairArchive();
321 
333  QList<ZipFileInfo> findFile( const QString& filename, ZipOptions options = Recursive );
334 
347  QList<ZipFileInfo> findFile( const QString& filename, const QString& root, ZipOptions options = Recursive );
348 
356  void setNameFilters( const QStringList& nameFilters );
357 
363  void clearNameFilters( );
364 
377  void setPassword( const QString& password );
378 
384  void clearPassword( );
385 
395  int errorCode() const;
396 
406  int errorCount() const;
407 
418  const QString& errorString() const;
419 
423  void clearErrors();
424 
430  bool setComment(const QString& comment);
431 
439  QString getComment()const;
440 
448  ZipInfo getInfo() const;
449 
450  void setZipFileName( const QString& name );
451 };
452 Q_DECLARE_OPERATORS_FOR_FLAGS(AbZip::ZipOptions)
453 
454 #endif // ABZIP_H
The file to be extracted already exists and you have specified the AbZip::DontOverwrite option...
Definition: AbZip.h:77
An error occurred extracting the file data from the archive. See errorString() for more information...
Definition: AbZip.h:78
General error message.
Definition: AbZip.h:70
Option
Archive options.
Definition: AbZip.h:95
Corrupt data found during extraction. CRC or AES validation failed.
Definition: AbZip.h:85
Mode
Definition: AbZip.h:57
Unable to open the archive file or the file being added.
Definition: AbZip.h:72
The decompression method required to extract the file is not supported by this library.
Definition: AbZip.h:82
The Central Directory Header file does not match the Local File Header.
Definition: AbZip.h:90
This is a simple class to hold information about the archive.
Definition: ZipFileInfo.h:15
Failed to locate Local File Header in the zip file. Most likely a corrupt Central Directory record...
Definition: AbZip.h:75
Invalid WinZip AES extra data specified.
Definition: AbZip.h:87
An error occurred copying the temporary extracted file to the destination folder. ...
Definition: AbZip.h:80
The Archive is open in Read mode and you are trying to perform a write action. Close and re-open for ...
Definition: AbZip.h:76
The file to be added or extracted was not found.
Definition: AbZip.h:88
Unable to set the last modified time for the extracted file to that stored in the archive...
Definition: AbZip.h:81
Definition: AbZip.h:35
Unable to create a temporary file for extraction.
Definition: AbZip.h:73
This class holds information about a file stored within the archive file.
Definition: ZipFileInfo.h:45
An error occurred writing to a temp archive while deleting files from the current archive...
Definition: AbZip.h:84
The decryption method required to extract the file is not supported by this library.
Definition: AbZip.h:83
An error occurred writing the Central Directory to file.
Definition: AbZip.h:89
ErrorCode
Error codes. For all errors other than Ok, call errorString() to retrieve the error message...
Definition: AbZip.h:67
No Error.
Definition: AbZip.h:69
A error occurred compressing and adding the data to the archive. See errorString() for more informati...
Definition: AbZip.h:79
Invalid password specified for decryption.
Definition: AbZip.h:86
Failed to create a new folder.
Definition: AbZip.h:71
Unable to read the Central Directory form the archive file. It&#39;s either correcpt or not a valid Zip f...
Definition: AbZip.h:74