QuaZIP  quazip-0-7-6
quazip.h
1 #ifndef QUA_ZIP_H
2 #define QUA_ZIP_H
3 
4 /*
5 Copyright (C) 2005-2014 Sergey A. Tachenov
6 
7 This file is part of QuaZIP.
8 
9 QuaZIP is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 QuaZIP is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
21 
22 See COPYING file for the full LGPL text.
23 
24 Original ZIP package is copyrighted by Gilles Vollant, see
25 quazip/(un)zip.h files for details, basically it's zlib license.
26  **/
27 
28 #include <QString>
29 #include <QStringList>
30 #include <QTextCodec>
31 
32 #include "zip.h"
33 #include "unzip.h"
34 
35 #include "quazip_global.h"
36 #include "quazipfileinfo.h"
37 
38 // just in case it will be defined in the later versions of the ZIP/UNZIP
39 #ifndef UNZ_OPENERROR
40 // define additional error code
41 #define UNZ_OPENERROR -1000
42 #endif
43 
44 class QuaZipPrivate;
45 
47 
84 class QUAZIP_EXPORT QuaZip {
85  friend class QuaZipPrivate;
86  public:
88  enum Constants {
89  MAX_FILE_NAME_LENGTH=256
92  };
94  enum Mode {
98  mdAppend,
106  mdAdd
107  };
109 
115  csDefault=0,
116  csSensitive=1,
117  csInsensitive=2
118  };
120 
126  static Qt::CaseSensitivity convertCaseSensitivity(
127  CaseSensitivity cs);
128  private:
129  QuaZipPrivate *p;
130  // not (and will not be) implemented
131  QuaZip(const QuaZip& that);
132  // not (and will not be) implemented
133  QuaZip& operator=(const QuaZip& that);
134  public:
136 
137  QuaZip();
139  QuaZip(const QString& zipName);
141 
142  QuaZip(QIODevice *ioDevice);
144 
145  ~QuaZip();
147 
193  bool open(Mode mode, zlib_filefunc_def *ioApi =NULL);
195 
217  void close();
219 
224  void setFileNameCodec(QTextCodec *fileNameCodec);
226 
229  void setFileNameCodec(const char *fileNameCodecName);
231  QTextCodec* getFileNameCodec() const;
233 
235  void setCommentCodec(QTextCodec *commentCodec);
237 
240  void setCommentCodec(const char *commentCodecName);
242  QTextCodec* getCommentCodec() const;
244 
249  QString getZipName() const;
251 
256  void setZipName(const QString& zipName);
258 
262  QIODevice *getIoDevice() const;
264 
269  void setIoDevice(QIODevice *ioDevice);
271  Mode getMode() const;
273  bool isOpen() const;
275 
283  int getZipError() const;
285 
288  int getEntriesCount() const;
290  QString getComment() const;
292 
300  void setComment(const QString& comment);
302 
305  bool goToFirstFile();
307 
324  bool goToNextFile();
326 
350  bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
352  bool hasCurrentFile() const;
354 
375  bool getCurrentFileInfo(QuaZipFileInfo* info)const;
377 
385  bool getCurrentFileInfo(QuaZipFileInfo64* info)const;
387 
393  QString getCurrentFileName()const;
395 
410  unzFile getUnzFile();
412 
416  zipFile getZipFile();
418 
445  void setDataDescriptorWritingEnabled(bool enabled);
447 
450  bool isDataDescriptorWritingEnabled() const;
452 
458  QStringList getFileNameList() const;
460 
472  QList<QuaZipFileInfo> getFileInfoList() const;
474 
482  QList<QuaZipFileInfo64> getFileInfoList64() const;
484 
497  void setZip64Enabled(bool zip64);
499 
504  bool isZip64Enabled() const;
506 
509  bool isAutoClose() const;
511 
531  void setAutoClose(bool autoClose) const;
533 
562  static void setDefaultFileNameCodec(QTextCodec *codec);
568  static void setDefaultFileNameCodec(const char *codecName);
569 };
570 
571 #endif
QuaZip::setDataDescriptorWritingEnabled
void setDataDescriptorWritingEnabled(bool enabled)
Changes the data descriptor writing mode.
Definition: quazip.cpp:656
QuaZipFileInfo64::toQuaZipFileInfo
bool toQuaZipFileInfo(QuaZipFileInfo &info) const
Converts to QuaZipFileInfo.
Definition: quazipfileinfo.cpp:62
QuaZip::mdAppend
@ mdAppend
Definition: quazip.h:98
QuaZipFileInfo64::versionCreated
quint16 versionCreated
Version created by.
Definition: quazipfileinfo.h:85
QuaZipFileInfo64::comment
QString comment
Comment.
Definition: quazipfileinfo.h:114
QuaZip::isOpen
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:626
QuaZip::setDefaultFileNameCodec
static void setDefaultFileNameCodec(QTextCodec *codec)
Sets the default file name codec to use.
Definition: quazip.cpp:767
QuaZip::getFileInfoList
QList< QuaZipFileInfo > getFileInfoList() const
Returns information list about all files inside the archive.
Definition: quazip.cpp:736
QuaZipFileInfo64::extra
QByteArray extra
Extra field.
Definition: quazipfileinfo.h:116
QuaZip::getMode
Mode getMode() const
Returns the mode in which ZIP file was opened.
Definition: quazip.cpp:621
QuaZip::setCommentCodec
void setCommentCodec(QTextCodec *commentCodec)
Sets the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:594
QuaZip::mdCreate
@ mdCreate
ZIP file was created with open() call.
Definition: quazip.h:97
QuaZipPrivate::unzFile_f
unzFile unzFile_f
The internal handle for UNZIP modes.
Definition: quazip.cpp:59
QuaZip::convertCaseSensitivity
static Qt::CaseSensitivity convertCaseSensitivity(CaseSensitivity cs)
Returns the actual case sensitivity for the specified QuaZIP one.
Definition: quazip.cpp:754
QuaZip::setIoDevice
void setIoDevice(QIODevice *ioDevice)
Sets the device representing the ZIP file.
Definition: quazip.cpp:372
QuaZipFileInfo64::versionNeeded
quint16 versionNeeded
Version needed to extract.
Definition: quazipfileinfo.h:87
QuaZipFileInfo64::externalAttr
quint32 externalAttr
External file attributes.
Definition: quazipfileinfo.h:112
QuaZip::isAutoClose
bool isAutoClose() const
Returns the auto-close flag.
Definition: quazip.cpp:787
QuaZip::mdUnzip
@ mdUnzip
ZIP file is open for reading files inside it.
Definition: quazip.h:96
QuaZip::getFileInfoList64
QList< QuaZipFileInfo64 > getFileInfoList64() const
Returns information list about all files inside the archive.
Definition: quazip.cpp:745
QuaZip::isZip64Enabled
bool isZip64Enabled() const
Returns whether the zip64 mode is enabled.
Definition: quazip.cpp:782
QuaZip::Mode
Mode
Open mode of the ZIP file.
Definition: quazip.h:94
QuaZip::getIoDevice
QIODevice * getIoDevice() const
Returns the device representing this ZIP file.
Definition: quazip.cpp:614
QuaZip::goToNextFile
bool goToNextFile()
Sets the current file to the next file in the archive.
Definition: quazip.cpp:485
QuaZip::getCurrentFileInfo
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.
Definition: quazip.cpp:499
QuaZip::getZipError
int getZipError() const
Returns the error code of the last operation.
Definition: quazip.cpp:631
QuaZip::setCurrentFile
bool setCurrentFile(const QString &fileName, CaseSensitivity cs=csDefault)
Sets current file by its name.
Definition: quazip.cpp:415
QuaZipFileInfo
Information about a file inside archive.
Definition: quazipfileinfo.h:41
QuaZip::setAutoClose
void setAutoClose(bool autoClose) const
Sets or unsets the auto-close flag.
Definition: quazip.cpp:792
QuaZip::getFileNameList
QStringList getFileNameList() const
Returns a list of files inside the archive.
Definition: quazip.cpp:727
QuaZip::getZipName
QString getZipName() const
Returns the name of the ZIP file.
Definition: quazip.cpp:609
QuaZipFileInfo64::crc
quint32 crc
CRC.
Definition: quazipfileinfo.h:102
QuaZipFileInfo64::compressedSize
quint64 compressedSize
Compressed file size.
Definition: quazipfileinfo.h:104
QuaZip::getUnzFile
unzFile getUnzFile()
Returns unzFile handle.
Definition: quazip.cpp:646
QuaZip::CaseSensitivity
CaseSensitivity
Case sensitivity for the file names.
Definition: quazip.h:114
QuaZip
ZIP archive.
Definition: quazip.h:84
QuaZipFileInfo64::method
quint16 method
Compression method.
Definition: quazipfileinfo.h:91
QuaZip::isDataDescriptorWritingEnabled
bool isDataDescriptorWritingEnabled() const
Returns the data descriptor default writing mode.
Definition: quazip.cpp:661
QuaZipFileInfo64::uncompressedSize
quint64 uncompressedSize
Uncompressed file size.
Definition: quazipfileinfo.h:106
QuaZip::getFileNameCodec
QTextCodec * getFileNameCodec() const
Returns the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:589
QuaZip::getZipFile
zipFile getZipFile()
Returns zipFile handle.
Definition: quazip.cpp:651
QuaZip::QuaZip
QuaZip()
Constructs QuaZip object.
Definition: quazip.cpp:200
QuaZip::csSensitive
@ csSensitive
Case sensitive.
Definition: quazip.h:116
QuaZipPrivate
All the internal stuff for the QuaZip class.
Definition: quazip.cpp:39
QuaZip::getEntriesCount
int getEntriesCount() const
Returns number of the entries in the ZIP central directory.
Definition: quazip.cpp:382
QuaZipFileInfo64::dateTime
QDateTime dateTime
Last modification date and time.
Definition: quazipfileinfo.h:100
QuaZip::getComment
QString getComment() const
Returns global comment in the ZIP file.
Definition: quazip.cpp:396
QuaZipFileInfo64::flags
quint16 flags
General purpose flags.
Definition: quazipfileinfo.h:89
QuaZip::setZipName
void setZipName(const QString &zipName)
Sets the name of the ZIP file.
Definition: quazip.cpp:362
QuaZip::csDefault
@ csDefault
Default for platform. Case sensitive for UNIX, not for Windows.
Definition: quazip.h:115
QuaZip::setFileNameCodec
void setFileNameCodec(QTextCodec *fileNameCodec)
Sets the codec used to encode/decode file names inside archive.
Definition: quazip.cpp:579
QuaZip::getCurrentFileName
QString getCurrentFileName() const
Returns the current file name.
Definition: quazip.cpp:558
QuaZip::setZip64Enabled
void setZip64Enabled(bool zip64)
Enables the zip64 mode.
Definition: quazip.cpp:777
QuaZip::hasCurrentFile
bool hasCurrentFile() const
Returns true if the current file has been set.
Definition: quazip.cpp:641
QuaZipFileInfo64
Information about a file inside archive (with zip64 support).
Definition: quazipfileinfo.h:81
QuaZip::close
void close()
Closes ZIP file.
Definition: quazip.cpp:331
QuaZipFileInfo64::name
QString name
File name.
Definition: quazipfileinfo.h:83
QuaZip::Constants
Constants
Useful constants.
Definition: quazip.h:88
QuaZipPrivate::zipFile_f
zipFile zipFile_f
The internal handle for ZIP modes.
Definition: quazip.cpp:61
QuaZip::goToFirstFile
bool goToFirstFile()
Sets the current file to the first file in the archive.
Definition: quazip.cpp:473
QuaZip::open
bool open(Mode mode, zlib_filefunc_def *ioApi=NULL)
Opens ZIP file.
Definition: quazip.cpp:222
QuaZip::MAX_FILE_NAME_LENGTH
@ MAX_FILE_NAME_LENGTH
Definition: quazip.h:89
QuaZip::mdAdd
@ mdAdd
ZIP file was opened for adding files in the archive.
Definition: quazip.h:106
QuaZipFileInfo64::diskNumberStart
quint16 diskNumberStart
Disk number start.
Definition: quazipfileinfo.h:108
QuaZip::mdNotOpen
@ mdNotOpen
ZIP file is not open. This is the initial mode.
Definition: quazip.h:95
QuaZipFileInfo64::internalAttr
quint16 internalAttr
Internal file attributes.
Definition: quazipfileinfo.h:110
QuaZip::getCommentCodec
QTextCodec * getCommentCodec() const
Returns the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:604
QuaZip::setComment
void setComment(const QString &comment)
Sets the global comment in the ZIP file.
Definition: quazip.cpp:636
QuaZip::~QuaZip
~QuaZip()
Destroys QuaZip object.
Definition: quazip.cpp:215