ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QuaZip Class Reference

ZIP archive. More...

#include <quazip/quazip.h>

+ Collaboration diagram for QuaZip:

Public Types

enum  Constants { MAX_FILE_NAME_LENGTH =256 }
 Useful constants. More...
 
enum  Mode {
  mdNotOpen, mdUnzip, mdCreate, mdAppend,
  mdAdd
}
 Open mode of the ZIP file. More...
 
enum  CaseSensitivity { csDefault =0, csSensitive =1, csInsensitive =2 }
 Case sensitivity for the file names. More...
 

Public Member Functions

 QuaZip ()
 Constructs QuaZip object. More...
 
 QuaZip (const QString &zipName)
 Constructs QuaZip object associated with ZIP file zipName. More...
 
 QuaZip (QIODevice *ioDevice)
 Constructs QuaZip object associated with ZIP file represented by ioDevice. More...
 
 ~QuaZip ()
 Destroys QuaZip object. More...
 
bool open (Mode mode, zlib_filefunc_def *ioApi=NULL)
 Opens ZIP file. More...
 
void close ()
 Closes ZIP file. More...
 
void setFileNameCodec (QTextCodec *fileNameCodec)
 Sets the codec used to encode/decode file names inside archive. More...
 
void setFileNameCodec (const char *fileNameCodecName)
 Sets the codec used to encode/decode file names inside archive. More...
 
QTextCodec * getFileNameCodec () const
 Returns the codec used to encode/decode comments inside archive. More...
 
void setCommentCodec (QTextCodec *commentCodec)
 Sets the codec used to encode/decode comments inside archive. More...
 
void setCommentCodec (const char *commentCodecName)
 Sets the codec used to encode/decode comments inside archive. More...
 
QTextCodec * getCommentCodec () const
 Returns the codec used to encode/decode comments inside archive. More...
 
QString getZipName () const
 Returns the name of the ZIP file. More...
 
void setZipName (const QString &zipName)
 Sets the name of the ZIP file. More...
 
QIODevicegetIoDevice () const
 Returns the device representing this ZIP file. More...
 
void setIoDevice (QIODevice *ioDevice)
 Sets the device representing the ZIP file. More...
 
Mode getMode () const
 Returns the mode in which ZIP file was opened. More...
 
bool isOpen () const
 Returns true if ZIP file is open, false otherwise. More...
 
int getZipError () const
 Returns the error code of the last operation. More...
 
int getEntriesCount () const
 Returns number of the entries in the ZIP central directory. More...
 
QString getComment () const
 Returns global comment in the ZIP file. More...
 
void setComment (const QString &comment)
 Sets the global comment in the ZIP file. More...
 
bool goToFirstFile ()
 Sets the current file to the first file in the archive. More...
 
bool goToNextFile ()
 Sets the current file to the next file in the archive. More...
 
bool setCurrentFile (const QString &fileName, CaseSensitivity cs=csDefault)
 Sets current file by its name. More...
 
bool hasCurrentFile () const
 Returns true if the current file has been set. More...
 
bool getCurrentFileInfo (QuaZipFileInfo *info) const
 Retrieves information about the current file. More...
 
bool getCurrentFileInfo (QuaZipFileInfo64 *info) const
 Retrieves information about the current file. More...
 
QString getCurrentFileName () const
 Returns the current file name. More...
 
unzFile getUnzFile ()
 Returns unzFile handle. More...
 
zipFile getZipFile ()
 Returns zipFile handle. More...
 
void setDataDescriptorWritingEnabled (bool enabled)
 Changes the data descriptor writing mode. More...
 
bool isDataDescriptorWritingEnabled () const
 Returns the data descriptor default writing mode. More...
 
QStringList getFileNameList () const
 Returns a list of files inside the archive. More...
 
QList< QuaZipFileInfogetFileInfoList () const
 Returns information list about all files inside the archive. More...
 
QList< QuaZipFileInfo64getFileInfoList64 () const
 Returns information list about all files inside the archive. More...
 
void setZip64Enabled (bool zip64)
 Enables the zip64 mode. More...
 
bool isZip64Enabled () const
 Returns whether the zip64 mode is enabled. More...
 
bool isAutoClose () const
 Returns the auto-close flag. More...
 
void setAutoClose (bool autoClose) const
 Sets or unsets the auto-close flag. More...
 

Static Public Member Functions

static Qt::CaseSensitivity convertCaseSensitivity (CaseSensitivity cs)
 Returns the actual case sensitivity for the specified QuaZIP one. More...
 
static void setDefaultFileNameCodec (QTextCodec *codec)
 Sets the default file name codec to use. More...
 
static void setDefaultFileNameCodec (const char *codecName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to calling setDefltFileNameCodec(QTextCodec::codecForName(codecName)). More...
 

Private Member Functions

 QuaZip (const QuaZip &that)
 
QuaZipoperator= (const QuaZip &that)
 

Private Attributes

QuaZipPrivatep
 

Friends

class QuaZipPrivate
 

Detailed Description

This class implements basic interface to the ZIP archive. It can be used to read table contents of the ZIP archive and retreiving information about the files inside it.

You can also use this class to open files inside archive by passing pointer to the instance of this class to the constructor of the QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*) for the possible pitfalls.

This class is indended to provide interface to the ZIP subpackage of the ZIP/UNZIP package as well as to the UNZIP subpackage. But currently it supports only UNZIP.

The use of this class is simple - just create instance using constructor, then set ZIP archive file name using setFile() function (if you did not passed the name to the constructor), then open() and then use different functions to work with it! Well, if you are paranoid, you may also wish to call close before destructing the instance, to check for errors on close.

You may also use getUnzFile() and getZipFile() functions to get the ZIP archive handle and use it with ZIP/UNZIP package API directly.

This class supports localized file names inside ZIP archive, but you have to set up proper codec with setCodec() function. By default, locale codec will be used, which is probably ok for UNIX systems, but will almost certainly fail with ZIP archives created in Windows. This is because Windows ZIP programs have strange habit of using DOS encoding for file names in ZIP archives. For example, ZIP archive with cyrillic names created in Windows will have file names in IBM866 encoding instead of WINDOWS-1251. I think that calling one function is not much trouble, but for true platform independency it would be nice to have some mechanism for file name encoding auto detection using locale information. Does anyone know a good way to do it?

Definition at line 84 of file quazip.h.

Member Enumeration Documentation

This is what you specify when accessing files in the archive. Works perfectly fine with any characters thanks to Qt's great unicode support. This is different from ZIP/UNZIP API, where only US-ASCII characters was supported.

Enumerator
csDefault 

Default for platform. Case sensitive for UNIX, not for Windows.

csSensitive 

Case sensitive.

csInsensitive 

Case insensitive.

Definition at line 114 of file quazip.h.

114  {
115  csDefault=0,
116  csSensitive=1,
117  csInsensitive=2
118  };
Case insensitive.
Definition: quazip.h:117
Case sensitive.
Definition: quazip.h:116
Default for platform. Case sensitive for UNIX, not for Windows.
Definition: quazip.h:115
Enumerator
MAX_FILE_NAME_LENGTH 

Maximum file name length.

Taken from UNZ_MAXFILENAMEINZIP constant in unzip.c.

Definition at line 88 of file quazip.h.

88  {
92  };
Maximum file name length.
Definition: quazip.h:89
Enumerator
mdNotOpen 

ZIP file is not open. This is the initial mode.

mdUnzip 

ZIP file is open for reading files inside it.

mdCreate 

ZIP file was created with open() call.

mdAppend 

ZIP file was opened in append mode.

This refers to APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package and means that zip is appended to some existing file what is useful when that file contains self-extractor code. This is obviously not what you whant to use to add files to the existing ZIP archive.

mdAdd 

ZIP file was opened for adding files in the archive.

Definition at line 94 of file quazip.h.

94  {
95  mdNotOpen,
96  mdUnzip,
97  mdCreate,
98  mdAppend,
106  mdAdd
107  };
ZIP file was opened for adding files in the archive.
Definition: quazip.h:106
ZIP file is not open. This is the initial mode.
Definition: quazip.h:95
ZIP file was created with open() call.
Definition: quazip.h:97
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZIP file was opened in append mode.
Definition: quazip.h:98

Constructor & Destructor Documentation

QuaZip::QuaZip ( const QuaZip that)
private
QuaZip::QuaZip ( )

Call setName() before opening constructed object.

Definition at line 193 of file quazip.cpp.

193  :
194  p(new QuaZipPrivate(this))
195 {
196 }
friend class QuaZipPrivate
Definition: quazip.h:85
QuaZipPrivate * p
Definition: quazip.h:129
QuaZip::QuaZip ( const QString &  zipName)

Definition at line 198 of file quazip.cpp.

198  :
199  p(new QuaZipPrivate(this, zipName))
200 {
201 }
friend class QuaZipPrivate
Definition: quazip.h:85
QuaZipPrivate * p
Definition: quazip.h:129
QuaZip::QuaZip ( QIODevice ioDevice)

The IO device must be seekable, otherwise an error will occur when opening.

Definition at line 203 of file quazip.cpp.

203  :
204  p(new QuaZipPrivate(this, ioDevice))
205 {
206 }
friend class QuaZipPrivate
Definition: quazip.h:85
QuaZipPrivate * p
Definition: quazip.h:129
QuaZip::~QuaZip ( )

Calls close() if necessary.

Definition at line 208 of file quazip.cpp.

References close(), isOpen(), and p.

209 {
210  if(isOpen())
211  close();
212  delete p;
213 }
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:619
QuaZipPrivate * p
Definition: quazip.h:129
void close()
Closes ZIP file.
Definition: quazip.cpp:324

+ Here is the call graph for this function:

Member Function Documentation

void QuaZip::close ( )

Call getZipError() to determine if the close was successful.

If the file was opened by name, then the underlying QIODevice is closed and deleted.

If the underlying QIODevice was set explicitly using setIoDevice() or the appropriate constructor, then it is closed if the auto-close flag is set (which it is by default). Call setAutoClose() to clear the auto-close flag if this behavior is undesirable.

Since Qt 5.1, the QSaveFile was introduced. It breaks the QIODevice API by making close() private and crashing the application if it is called from the base class where it is public. It is an excellent example of poor design that illustrates why you should never ever break an is-a relationship between the base class and a subclass. QuaZIP works around this bug by checking if the QIODevice is an instance of QSaveFile, using qobject_cast<>, and if it is, calls QSaveFile::commit() instead of close(). It is a really ugly hack, but at least it makes your programs work instead of crashing. Note that if the auto-close flag is cleared, then this is a non-issue, and commit() isn't called.

Definition at line 324 of file quazip.cpp.

References QuaZipPrivate::clearDirectoryMap(), QuaZipPrivate::comment, QuaZipPrivate::commentCodec, QuaZipPrivate::ioDevice, mdAdd, mdAppend, mdCreate, mdNotOpen, mdUnzip, QuaZipPrivate::mode, p, UNZ_OK, unzClose(), zipClose(), QuaZipPrivate::zipError, and QuaZipPrivate::zipName.

Referenced by QuaZipFile::close(), JlCompress::compressDir(), JlCompress::compressFile(), JlCompress::compressFiles(), JlCompress::extractDir(), JlCompress::extractFile(), JlCompress::extractFiles(), JlCompress::getFileList(), QuaZipFile::open(), and ~QuaZip().

325 {
326  p->zipError=UNZ_OK;
327  switch(p->mode) {
328  case mdNotOpen:
329  qWarning("QuaZip::close(): ZIP is not open");
330  return;
331  case mdUnzip:
332  p->zipError=unzClose(p->unzFile_f);
333  break;
334  case mdCreate:
335  case mdAppend:
336  case mdAdd:
337  p->zipError=zipClose(p->zipFile_f,
338  p->comment.isNull() ? NULL
339  : p->commentCodec->fromUnicode(p->comment).constData());
340  break;
341  default:
342  qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
343  return;
344  }
345  // opened by name, need to delete the internal IO device
346  if (!p->zipName.isEmpty()) {
347  delete p->ioDevice;
348  p->ioDevice = NULL;
349  }
350  p->clearDirectoryMap();
351  if(p->zipError==UNZ_OK)
352  p->mode=mdNotOpen;
353 }
QIODevice * ioDevice
The device to access the archive.
Definition: quazip.cpp:51
#define UNZ_OK
Definition: unzip.h:79
QuaZipPrivate * p
Definition: quazip.h:129
ZIP file was opened for adding files in the archive.
Definition: quazip.h:106
ZIP file is not open. This is the initial mode.
Definition: quazip.h:95
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:815
QString comment
The global comment.
Definition: quazip.cpp:53
ZIP file was created with open() call.
Definition: quazip.h:97
QTextCodec * commentCodec
The codec for comments.
Definition: quazip.cpp:47
void clearDirectoryMap()
Stores map of filenames and file locations for unzipping.
Definition: quazip.cpp:145
QString zipName
The archive file name.
Definition: quazip.cpp:49
int zipError
The last error.
Definition: quazip.cpp:65
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZIP file was opened in append mode.
Definition: quazip.h:98
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1942

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Qt::CaseSensitivity QuaZip::convertCaseSensitivity ( QuaZip::CaseSensitivity  cs)
static
Parameters
csThe value to convert.
Returns
If CaseSensitivity::csDefault, then returns the default file name case sensitivity for the platform. Otherwise, just returns the appropriate value from the Qt::CaseSensitivity enum.

Definition at line 747 of file quazip.cpp.

References csDefault, and csSensitive.

Referenced by QuaZipDir::exists(), and setCurrentFile().

748 {
749  if (cs == csDefault) {
750 #ifdef Q_WS_WIN
751  return Qt::CaseInsensitive;
752 #else
753  return Qt::CaseSensitive;
754 #endif
755  } else {
756  return cs == csSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
757  }
758 }
Case sensitive.
Definition: quazip.h:116
Default for platform. Case sensitive for UNIX, not for Windows.
Definition: quazip.h:115

+ Here is the caller graph for this function:

QString QuaZip::getComment ( ) const

Definition at line 389 of file quazip.cpp.

References QuaZipPrivate::commentCodec, mdUnzip, QuaZipPrivate::mode, p, unz_global_info64_s::size_comment, UNZ_OK, unzGetGlobalComment(), unzGetGlobalInfo64(), and QuaZipPrivate::zipError.

390 {
391  QuaZip *fakeThis=(QuaZip*)this; // non-const
392  fakeThis->p->zipError=UNZ_OK;
393  if(p->mode!=mdUnzip) {
394  qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode");
395  return QString();
396  }
397  unz_global_info64 globalInfo;
398  QByteArray comment;
399  if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
400  return QString();
401  comment.resize(globalInfo.size_comment);
402  if((fakeThis->p->zipError=unzGetGlobalComment(p->unzFile_f, comment.data(), comment.size())) < 0)
403  return QString();
404  fakeThis->p->zipError = UNZ_OK;
405  return p->commentCodec->toUnicode(comment);
406 }
#define UNZ_OK
Definition: unzip.h:79
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * commentCodec
The codec for comments.
Definition: quazip.cpp:47
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:838
int zipError
The last error.
Definition: quazip.cpp:65
ZIP file is open for reading files inside it.
Definition: quazip.h:96
int ZEXPORT unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf)
Definition: unzip.c:2059
ZIP archive.
Definition: quazip.h:84
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
uLong size_comment
Definition: unzip.h:108

+ Here is the call graph for this function:

QTextCodec * QuaZip::getCommentCodec ( ) const

Definition at line 597 of file quazip.cpp.

References QuaZipPrivate::commentCodec, and p.

Referenced by QuaZipFile::open().

598 {
599  return p->commentCodec;
600 }
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * commentCodec
The codec for comments.
Definition: quazip.cpp:47

+ Here is the caller graph for this function:

bool QuaZip::getCurrentFileInfo ( QuaZipFileInfo info) const

Fills the structure pointed by info. Returns true on success, false otherwise. In the latter case structure pointed by info remains untouched. If there was an error, getZipError() returns error code.

Should be used only in QuaZip::mdUnzip mode.

Does nothing and returns false in any of the following cases.

  • ZIP is not open;
  • ZIP does not have current file.

In both cases getZipError() returns UNZ_OK since there is no ZIP/UNZIP API call.

This overload doesn't support zip64, but will work OK on zip64 archives except that if one of the sizes (compressed or uncompressed) is greater than 0xFFFFFFFFu, it will be set to exactly 0xFFFFFFFFu.

See Also
getCurrentFileInfo(QuaZipFileInfo64* info)const
QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo&)const

Definition at line 492 of file quazip.cpp.

References QuaZipFileInfo64::toQuaZipFileInfo().

Referenced by JlCompress::extractFile(), QuaZipFile::getFileInfo(), JlCompress::getFileList(), QuaZip_getFileInfo(), and QuaZipDir_getFileInfo().

493 {
494  QuaZipFileInfo64 info64;
495  if (info == NULL) { // Very unlikely because of the overloads
496  return false;
497  }
498  if (getCurrentFileInfo(&info64)) {
499  info64.toQuaZipFileInfo(*info);
500  return true;
501  } else {
502  return false;
503  }
504 }
bool toQuaZipFileInfo(QuaZipFileInfo &info) const
Converts to QuaZipFileInfo.
Information about a file inside archive (with zip64 support).
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.
Definition: quazip.cpp:492

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool QuaZip::getCurrentFileInfo ( QuaZipFileInfo64 info) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function supports zip64. If the archive doesn't use zip64, it is completely equivalent to getCurrentFileInfo(QuaZipFileInfo* info) except for the argument type.

See Also

Definition at line 506 of file quazip.cpp.

References QuaZipPrivate::addCurrentFileToDirectoryMap(), QuaZipFileInfo64::comment, QuaZipPrivate::commentCodec, unz_file_info64_s::compressed_size, QuaZipFileInfo64::compressedSize, unz_file_info64_s::compression_method, QuaZipFileInfo64::crc, unz_file_info64_s::crc, QuaZipFileInfo64::dateTime, unz_file_info64_s::disk_num_start, QuaZipFileInfo64::diskNumberStart, unz_file_info64_s::external_fa, QuaZipFileInfo64::externalAttr, QuaZipFileInfo64::extra, QuaZipPrivate::fileNameCodec, unz_file_info64_s::flag, QuaZipFileInfo64::flags, hasCurrentFile(), unz_file_info64_s::internal_fa, QuaZipFileInfo64::internalAttr, isOpen(), mdUnzip, QuaZipFileInfo64::method, QuaZipPrivate::mode, QuaZipFileInfo64::name, p, unz_file_info64_s::size_file_comment, unz_file_info64_s::size_file_extra, unz_file_info64_s::size_filename, tm_unz_s::tm_hour, tm_unz_s::tm_mday, tm_unz_s::tm_min, tm_unz_s::tm_mon, tm_unz_s::tm_sec, tm_unz_s::tm_year, unz_file_info64_s::tmu_date, unz_file_info64_s::uncompressed_size, QuaZipFileInfo64::uncompressedSize, UNZ_OK, unzGetCurrentFileInfo64(), unz_file_info64_s::version, unz_file_info64_s::version_needed, QuaZipFileInfo64::versionCreated, QuaZipFileInfo64::versionNeeded, and QuaZipPrivate::zipError.

507 {
508  QuaZip *fakeThis=(QuaZip*)this; // non-const
509  fakeThis->p->zipError=UNZ_OK;
510  if(p->mode!=mdUnzip) {
511  qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode");
512  return false;
513  }
514  unz_file_info64 info_z;
515  QByteArray fileName;
516  QByteArray extra;
517  QByteArray comment;
518  if(info==NULL) return false;
519  if(!isOpen()||!hasCurrentFile()) return false;
520  if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &info_z, NULL, 0, NULL, 0, NULL, 0))!=UNZ_OK)
521  return false;
522  fileName.resize(info_z.size_filename);
523  extra.resize(info_z.size_file_extra);
524  comment.resize(info_z.size_file_comment);
525  if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL,
526  fileName.data(), fileName.size(),
527  extra.data(), extra.size(),
528  comment.data(), comment.size()))!=UNZ_OK)
529  return false;
530  info->versionCreated=info_z.version;
531  info->versionNeeded=info_z.version_needed;
532  info->flags=info_z.flag;
533  info->method=info_z.compression_method;
534  info->crc=info_z.crc;
535  info->compressedSize=info_z.compressed_size;
536  info->uncompressedSize=info_z.uncompressed_size;
537  info->diskNumberStart=info_z.disk_num_start;
538  info->internalAttr=info_z.internal_fa;
539  info->externalAttr=info_z.external_fa;
540  info->name=p->fileNameCodec->toUnicode(fileName);
541  info->comment=p->commentCodec->toUnicode(comment);
542  info->extra=extra;
543  info->dateTime=QDateTime(
544  QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon+1, info_z.tmu_date.tm_mday),
545  QTime(info_z.tmu_date.tm_hour, info_z.tmu_date.tm_min, info_z.tmu_date.tm_sec));
546  // Add to directory map
548  return true;
549 }
quint16 diskNumberStart
Disk number start.
ZPOS64_T compressed_size
Definition: unzip.h:127
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:619
uInt tm_mday
Definition: unzip.h:97
QByteArray extra
Extra field.
quint16 versionCreated
Version created by.
QString comment
Comment.
#define UNZ_OK
Definition: unzip.h:79
quint32 externalAttr
External file attributes.
quint16 versionNeeded
Version needed to extract.
tm_unz tmu_date
Definition: unzip.h:137
QuaZipPrivate * p
Definition: quazip.h:129
uInt tm_sec
Definition: unzip.h:94
QTextCodec * commentCodec
The codec for comments.
Definition: quazip.cpp:47
void addCurrentFileToDirectoryMap(const QString &fileName)
Definition: quazip.cpp:153
uLong size_file_extra
Definition: unzip.h:130
uLong size_file_comment
Definition: unzip.h:131
uLong size_filename
Definition: unzip.h:129
uLong compression_method
Definition: unzip.h:124
uInt tm_year
Definition: unzip.h:99
ZPOS64_T uncompressed_size
Definition: unzip.h:128
quint32 crc
CRC.
quint64 compressedSize
Compressed file size.
uLong version_needed
Definition: unzip.h:122
uInt tm_min
Definition: unzip.h:95
int zipError
The last error.
Definition: quazip.cpp:65
uLong version
Definition: unzip.h:121
ZIP file is open for reading files inside it.
Definition: quazip.h:96
quint16 method
Compression method.
uLong internal_fa
Definition: unzip.h:134
uLong disk_num_start
Definition: unzip.h:133
quint64 uncompressedSize
Uncompressed file size.
uLong external_fa
Definition: unzip.h:135
ZIP archive.
Definition: quazip.h:84
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1134
uInt tm_hour
Definition: unzip.h:96
uInt tm_mon
Definition: unzip.h:98
QDateTime dateTime
Last modification date and time.
quint16 flags
General purpose flags.
bool hasCurrentFile() const
Returns true if the current file has been set.
Definition: quazip.cpp:634
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
QString name
File name.
QTextCodec * fileNameCodec
The codec for file names.
Definition: quazip.cpp:45
quint16 internalAttr
Internal file attributes.

+ Here is the call graph for this function:

QString QuaZip::getCurrentFileName ( ) const

Equivalent to calling getCurrentFileInfo() and then getting name field of the QuaZipFileInfo structure, but faster and more convenient.

Should be used only in QuaZip::mdUnzip mode.

Definition at line 551 of file quazip.cpp.

References QuaZipPrivate::addCurrentFileToDirectoryMap(), QuaZipPrivate::fileNameCodec, hasCurrentFile(), isOpen(), MAX_FILE_NAME_LENGTH, mdUnzip, QuaZipPrivate::mode, p, UNZ_OK, unzGetCurrentFileInfo64(), and QuaZipPrivate::zipError.

Referenced by JlCompress::extractDir(), QuaZipFile::getActualFileName(), QuaZipPrivate::getFileInfoList(), QuaZip_getFileInfo(), and setCurrentFile().

552 {
553  QuaZip *fakeThis=(QuaZip*)this; // non-const
554  fakeThis->p->zipError=UNZ_OK;
555  if(p->mode!=mdUnzip) {
556  qWarning("QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip mode");
557  return QString();
558  }
559  if(!isOpen()||!hasCurrentFile()) return QString();
560  QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
561  if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL, fileName.data(), fileName.size(),
562  NULL, 0, NULL, 0))!=UNZ_OK)
563  return QString();
564  QString result = p->fileNameCodec->toUnicode(fileName.constData());
565  if (result.isEmpty())
566  return result;
567  // Add to directory map
569  return result;
570 }
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:619
#define UNZ_OK
Definition: unzip.h:79
QuaZipPrivate * p
Definition: quazip.h:129
void addCurrentFileToDirectoryMap(const QString &fileName)
Definition: quazip.cpp:153
int zipError
The last error.
Definition: quazip.cpp:65
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZIP archive.
Definition: quazip.h:84
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1134
bool hasCurrentFile() const
Returns true if the current file has been set.
Definition: quazip.cpp:634
Maximum file name length.
Definition: quazip.h:89
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
QTextCodec * fileNameCodec
The codec for file names.
Definition: quazip.cpp:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int QuaZip::getEntriesCount ( ) const

Returns negative error code in the case of error. The same error code will be returned by subsequent getZipError() call.

Definition at line 375 of file quazip.cpp.

References mdUnzip, QuaZipPrivate::mode, unz_global_info64_s::number_entry, p, UNZ_OK, unzGetGlobalInfo64(), and QuaZipPrivate::zipError.

376 {
377  QuaZip *fakeThis=(QuaZip*)this; // non-const
378  fakeThis->p->zipError=UNZ_OK;
379  if(p->mode!=mdUnzip) {
380  qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode");
381  return -1;
382  }
383  unz_global_info64 globalInfo;
384  if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
385  return p->zipError;
386  return (int)globalInfo.number_entry;
387 }
#define UNZ_OK
Definition: unzip.h:79
QuaZipPrivate * p
Definition: quazip.h:129
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:838
int zipError
The last error.
Definition: quazip.cpp:65
ZIP file is open for reading files inside it.
Definition: quazip.h:96
ZPOS64_T number_entry
Definition: unzip.h:106
ZIP archive.
Definition: quazip.h:84
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55

+ Here is the call graph for this function:

QList< QuaZipFileInfo > QuaZip::getFileInfoList ( ) const
Returns
A list of QuaZipFileInfo objects or an empty list if there was an error or if the archive is empty (call getZipError() to figure out which).

This function doesn't support zip64, but will still work with zip64 archives, converting results using QuaZipFileInfo64::toQuaZipFileInfo(). If all file sizes are below 4 GB, it will work just fine.

See Also
getFileNameList()
getFileInfoList64()

Definition at line 729 of file quazip.cpp.

References QuaZipPrivate::getFileInfoList(), and p.

730 {
731  QList<QuaZipFileInfo> list;
732  if (p->getFileInfoList(&list))
733  return list;
734  else
735  return QList<QuaZipFileInfo>();
736 }
QuaZipPrivate * p
Definition: quazip.h:129
bool getFileInfoList(QList< TFileInfo > *result) const
Returns either a list of file names or a list of QuaZipFileInfo.
Definition: quazip.cpp:687

+ Here is the call graph for this function:

QList< QuaZipFileInfo64 > QuaZip::getFileInfoList64 ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function supports zip64.

See Also
getFileNameList()
getFileInfoList()

Definition at line 738 of file quazip.cpp.

References QuaZipPrivate::getFileInfoList(), and p.

739 {
740  QList<QuaZipFileInfo64> list;
741  if (p->getFileInfoList(&list))
742  return list;
743  else
744  return QList<QuaZipFileInfo64>();
745 }
QuaZipPrivate * p
Definition: quazip.h:129
bool getFileInfoList(QList< TFileInfo > *result) const
Returns either a list of file names or a list of QuaZipFileInfo.
Definition: quazip.cpp:687

+ Here is the call graph for this function:

QTextCodec * QuaZip::getFileNameCodec ( ) const

Definition at line 582 of file quazip.cpp.

References QuaZipPrivate::fileNameCodec, and p.

Referenced by QuaZipFile::open().

583 {
584  return p->fileNameCodec;
585 }
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * fileNameCodec
The codec for file names.
Definition: quazip.cpp:45

+ Here is the caller graph for this function:

QStringList QuaZip::getFileNameList ( ) const
Returns
A list of file names or an empty list if there was an error or if the archive is empty (call getZipError() to figure out which).
See Also
getFileInfoList()

Definition at line 720 of file quazip.cpp.

References QuaZipPrivate::getFileInfoList(), and p.

721 {
722  QStringList list;
723  if (p->getFileInfoList(&list))
724  return list;
725  else
726  return QStringList();
727 }
QuaZipPrivate * p
Definition: quazip.h:129
bool getFileInfoList(QList< TFileInfo > *result) const
Returns either a list of file names or a list of QuaZipFileInfo.
Definition: quazip.cpp:687

+ Here is the call graph for this function:

QIODevice * QuaZip::getIoDevice ( ) const

Returns null string if no device has been set explicitly, for example when opening a ZIP file by name.

See Also
setIoDevice(), getZipName(), setZipName()

Definition at line 607 of file quazip.cpp.

References QuaZipPrivate::ioDevice, p, and QuaZipPrivate::zipName.

608 {
609  if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice
610  return NULL;
611  return p->ioDevice;
612 }
QIODevice * ioDevice
The device to access the archive.
Definition: quazip.cpp:51
QuaZipPrivate * p
Definition: quazip.h:129
QString zipName
The archive file name.
Definition: quazip.cpp:49
QuaZip::Mode QuaZip::getMode ( ) const

Definition at line 614 of file quazip.cpp.

References QuaZipPrivate::mode, and p.

Referenced by JlCompress::compressFile(), JlCompress::compressSubDir(), QuaZipFile::csize(), JlCompress::extractFile(), QuaZipFile::getFileInfo(), QuaZipFile::open(), and QuaZipFile::usize().

615 {
616  return p->mode;
617 }
QuaZipPrivate * p
Definition: quazip.h:129
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55

+ Here is the caller graph for this function:

unzFile QuaZip::getUnzFile ( )

You can use this handle to directly call UNZIP part of the ZIP/UNZIP package functions (see unzip.h).

Warning
When using the handle returned by this function, please keep in mind that QuaZip class is unable to detect any changes you make in the ZIP file state (e. g. changing current file, or closing the handle). So please do not do anything with this handle that is possible to do with the functions of this class. Or at least return the handle in the original state before calling some another function of this class (including implicit destructor calls and calls from the QuaZipFile objects that refer to this QuaZip instance!). So if you have changed the current file in the ZIP archive - then change it back or you may experience some strange behavior or even crashes.

Definition at line 639 of file quazip.cpp.

References p.

Referenced by QuaZipFile::atEnd(), QuaZipFile::close(), QuaZipFile::csize(), QuaZipFile::open(), QuaZipFile::pos(), QuaZipFile::readData(), and QuaZipFile::usize().

640 {
641  return p->unzFile_f;
642 }
QuaZipPrivate * p
Definition: quazip.h:129

+ Here is the caller graph for this function:

int QuaZip::getZipError ( ) const

Returns UNZ_OK if the last operation was successful.

Error code resets to UNZ_OK every time you call any function that accesses something inside ZIP archive, even if it is const (like getEntriesCount()). open() and close() calls reset error code too. See documentation for the specific functions for details on error detection.

Definition at line 624 of file quazip.cpp.

References p, and QuaZipPrivate::zipError.

Referenced by QuaZipFile::close(), JlCompress::compressDir(), JlCompress::compressFile(), JlCompress::compressFiles(), JlCompress::extractDir(), JlCompress::extractFile(), JlCompress::extractFiles(), QuaZipFile::getActualFileName(), QuaZipFile::getFileInfo(), JlCompress::getFileList(), and QuaZipFile::open().

625 {
626  return p->zipError;
627 }
QuaZipPrivate * p
Definition: quazip.h:129
int zipError
The last error.
Definition: quazip.cpp:65

+ Here is the caller graph for this function:

zipFile QuaZip::getZipFile ( )

You can use this handle to directly call ZIP part of the ZIP/UNZIP package functions (see zip.h). Warnings about the getUnzFile() function also apply to this function.

Definition at line 644 of file quazip.cpp.

References p.

Referenced by QuaZipFile::close(), QuaZipFile::open(), and QuaZipFile::writeData().

645 {
646  return p->zipFile_f;
647 }
QuaZipPrivate * p
Definition: quazip.h:129

+ Here is the caller graph for this function:

QString QuaZip::getZipName ( ) const

Returns null string if no ZIP file name has been set, for example when the QuaZip instance is set up to use a QIODevice instead.

See Also
setZipName(), setIoDevice(), getIoDevice()

Definition at line 602 of file quazip.cpp.

References p, and QuaZipPrivate::zipName.

Referenced by JlCompress::compressSubDir(), and QuaZipFile::getZipName().

603 {
604  return p->zipName;
605 }
QuaZipPrivate * p
Definition: quazip.h:129
QString zipName
The archive file name.
Definition: quazip.cpp:49

+ Here is the caller graph for this function:

bool QuaZip::goToFirstFile ( )

Returns true on success, false otherwise. Call getZipError() to get the error code.

Definition at line 466 of file quazip.cpp.

References QuaZipPrivate::hasCurrentFile_f, mdUnzip, QuaZipPrivate::mode, p, UNZ_OK, unzGoToFirstFile(), and QuaZipPrivate::zipError.

Referenced by JlCompress::extractDir(), QuaZipPrivate::getFileInfoList(), and JlCompress::getFileList().

467 {
468  p->zipError=UNZ_OK;
469  if(p->mode!=mdUnzip) {
470  qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
471  return false;
472  }
473  p->zipError=unzGoToFirstFile(p->unzFile_f);
475  return p->hasCurrentFile_f;
476 }
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1188
#define UNZ_OK
Definition: unzip.h:79
QuaZipPrivate * p
Definition: quazip.h:129
int zipError
The last error.
Definition: quazip.cpp:65
ZIP file is open for reading files inside it.
Definition: quazip.h:96
bool hasCurrentFile_f
Whether a current file is set.
Definition: quazip.cpp:63
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool QuaZip::goToNextFile ( )

Returns true on success, false otherwise. Call getZipError() to determine if there was an error.

Should be used only in QuaZip::mdUnzip mode.

Note
If the end of file was reached, getZipError() will return UNZ_OK instead of UNZ_END_OF_LIST_OF_FILE. This is to make things like this easier:
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
// do something
}
if(zip.getZipError()==UNZ_OK) {
// ok, there was no error
}

Definition at line 478 of file quazip.cpp.

References QuaZipPrivate::hasCurrentFile_f, mdUnzip, QuaZipPrivate::mode, p, UNZ_END_OF_LIST_OF_FILE, UNZ_OK, unzGoToNextFile(), and QuaZipPrivate::zipError.

Referenced by JlCompress::extractDir(), QuaZipPrivate::getFileInfoList(), JlCompress::getFileList(), and setCurrentFile().

479 {
480  p->zipError=UNZ_OK;
481  if(p->mode!=mdUnzip) {
482  qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
483  return false;
484  }
485  p->zipError=unzGoToNextFile(p->unzFile_f);
488  p->zipError=UNZ_OK;
489  return p->hasCurrentFile_f;
490 }
#define UNZ_OK
Definition: unzip.h:79
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1209
QuaZipPrivate * p
Definition: quazip.h:129
int zipError
The last error.
Definition: quazip.cpp:65
ZIP file is open for reading files inside it.
Definition: quazip.h:96
bool hasCurrentFile_f
Whether a current file is set.
Definition: quazip.cpp:63
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
#define UNZ_END_OF_LIST_OF_FILE
Definition: unzip.h:80

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool QuaZip::hasCurrentFile ( ) const

Definition at line 634 of file quazip.cpp.

References QuaZipPrivate::hasCurrentFile_f, and p.

Referenced by getCurrentFileInfo(), getCurrentFileName(), QuaZipPrivate::getFileInfoList(), and QuaZipFile::open().

635 {
636  return p->hasCurrentFile_f;
637 }
QuaZipPrivate * p
Definition: quazip.h:129
bool hasCurrentFile_f
Whether a current file is set.
Definition: quazip.cpp:63

+ Here is the caller graph for this function:

bool QuaZip::isAutoClose ( ) const
See Also
setAutoClose()

Definition at line 780 of file quazip.cpp.

References QuaZipPrivate::autoClose, and p.

781 {
782  return p->autoClose;
783 }
QuaZipPrivate * p
Definition: quazip.h:129
bool autoClose
The auto-close flag.
Definition: quazip.cpp:71
bool QuaZip::isDataDescriptorWritingEnabled ( ) const
See Also
setDataDescriptorWritingEnabled()

Definition at line 654 of file quazip.cpp.

References QuaZipPrivate::dataDescriptorWritingEnabled, and p.

Referenced by QuaZipFile::open().

655 {
657 }
QuaZipPrivate * p
Definition: quazip.h:129
bool dataDescriptorWritingEnabled
Whether the data descriptor writing mode is enabled.
Definition: quazip.cpp:67

+ Here is the caller graph for this function:

bool QuaZip::isOpen ( ) const

Definition at line 619 of file quazip.cpp.

References mdNotOpen, QuaZipPrivate::mode, and p.

Referenced by QuaZipFile::close(), getCurrentFileInfo(), getCurrentFileName(), open(), setIoDevice(), setZipName(), and ~QuaZip().

620 {
621  return p->mode!=mdNotOpen;
622 }
QuaZipPrivate * p
Definition: quazip.h:129
ZIP file is not open. This is the initial mode.
Definition: quazip.h:95
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55

+ Here is the caller graph for this function:

bool QuaZip::isZip64Enabled ( ) const
Returns
true if and only if the zip64 mode is enabled.
See Also
setZip64Enabled()

Definition at line 775 of file quazip.cpp.

References p, and QuaZipPrivate::zip64.

Referenced by QuaZipFile::open().

776 {
777  return p->zip64;
778 }
QuaZipPrivate * p
Definition: quazip.h:129
bool zip64
The zip64 mode.
Definition: quazip.cpp:69

+ Here is the caller graph for this function:

bool QuaZip::open ( Mode  mode,
zlib_filefunc_def ioApi = NULL 
)

Argument mode specifies open mode of the ZIP archive. See Mode for details. Note that there is zipOpen2() function in the ZIP/UNZIP API which accepts globalcomment argument, but it does not use it anywhere, so this open() function does not have this argument. See setComment() if you need to set global comment.

If the ZIP file is accessed via explicitly set QIODevice, then this device is opened in the necessary mode. If the device was already opened by some other means, then QuaZIP checks if the open mode is compatible to the mode needed for the requested operation. If necessary, seeking is performed to position the device properly.

Returns
true if successful, false otherwise.
Note
ZIP/UNZIP API open calls do not return error code - they just return NULL indicating an error. But to make things easier, quazip.h header defines additional error code UNZ_ERROROPEN and getZipError() will return it if the open call of the ZIP/UNZIP API returns NULL.

Argument ioApi specifies IO function set for ZIP/UNZIP package to use. See unzip.h, zip.h and ioapi.h for details. Note that IO API for QuaZip is different from the original package. The file path argument was changed to be of type voidpf, and QuaZip passes a QIODevice pointer there. This QIODevice is either set explicitly via setIoDevice() or the QuaZip(QIODevice*) constructor, or it is created internally when opening the archive by its file name. The default API (qioapi.cpp) just delegates everything to the QIODevice API. Not only this allows to use a QIODevice instead of file name, but also has a nice side effect of raising the file size limit from 2G to 4G (in non-zip64 archives).

Note
If the zip64 support is needed, the ioApi argument must be NULL because due to the backwards compatibility issues it can be used to provide a 32-bit API only.
If the no-auto-close feature is used, then the ioApi argument should be NULL because the old API doesn't support the 'fake close' operation, causing slight memory leaks and other possible troubles (like closing the output device in case when an error occurs during opening).

In short: just forget about the ioApi argument and you'll be fine.

Definition at line 215 of file quazip.cpp.

References APPEND_STATUS_ADDINZIP, APPEND_STATUS_CREATE, APPEND_STATUS_CREATEAFTER, QuaZipPrivate::autoClose, QuaZipPrivate::dataDescriptorWritingEnabled, QuaZipPrivate::ioDevice, isOpen(), mdAdd, mdAppend, mdCreate, mdUnzip, QuaZipPrivate::mode, p, UNZ_AUTO_CLOSE, UNZ_OK, UNZ_OPENERROR, unzClearFlags(), unzClose(), unzOpen2(), unzOpenInternal(), unzSetFlags(), ZIP_AUTO_CLOSE, ZIP_SEQUENTIAL, ZIP_WRITE_DATA_DESCRIPTOR, zipClose(), QuaZipPrivate::zipError, QuaZipPrivate::zipName, zipOpen2(), zipOpen3(), and zipSetFlags().

Referenced by KbFirmware::_fileForBoard(), JlCompress::compressDir(), JlCompress::compressFile(), JlCompress::compressFiles(), JlCompress::extractDir(), JlCompress::extractFile(), JlCompress::extractFiles(), JlCompress::getFileList(), and QuaZipFile::open().

216 {
217  p->zipError=UNZ_OK;
218  if(isOpen()) {
219  qWarning("QuaZip::open(): ZIP already opened");
220  return false;
221  }
222  QIODevice *ioDevice = p->ioDevice;
223  if (ioDevice == NULL) {
224  if (p->zipName.isEmpty()) {
225  qWarning("QuaZip::open(): set either ZIP file name or IO device first");
226  return false;
227  } else {
228  ioDevice = new QFile(p->zipName);
229  }
230  }
231  unsigned flags = 0;
232  switch(mode) {
233  case mdUnzip:
234  if (ioApi == NULL) {
235  if (p->autoClose)
236  flags |= UNZ_AUTO_CLOSE;
237  p->unzFile_f=unzOpenInternal(ioDevice, NULL, 1, flags);
238  } else {
239  // QuaZIP pre-zip64 compatibility mode
240  p->unzFile_f=unzOpen2(ioDevice, ioApi);
241  if (p->unzFile_f != NULL) {
242  if (p->autoClose) {
243  unzSetFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
244  } else {
245  unzClearFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
246  }
247  }
248  }
249  if(p->unzFile_f!=NULL) {
250  if (ioDevice->isSequential()) {
251  unzClose(p->unzFile_f);
252  if (!p->zipName.isEmpty())
253  delete ioDevice;
254  qWarning("QuaZip::open(): "
255  "only mdCreate can be used with "
256  "sequential devices");
257  return false;
258  }
259  p->mode=mode;
260  p->ioDevice = ioDevice;
261  return true;
262  } else {
264  if (!p->zipName.isEmpty())
265  delete ioDevice;
266  return false;
267  }
268  case mdCreate:
269  case mdAppend:
270  case mdAdd:
271  if (ioApi == NULL) {
272  if (p->autoClose)
273  flags |= ZIP_AUTO_CLOSE;
275  flags |= ZIP_WRITE_DATA_DESCRIPTOR;
276  p->zipFile_f=zipOpen3(ioDevice,
280  NULL, NULL, flags);
281  } else {
282  // QuaZIP pre-zip64 compatibility mode
283  p->zipFile_f=zipOpen2(ioDevice,
287  NULL,
288  ioApi);
289  if (p->zipFile_f != NULL) {
290  zipSetFlags(p->zipFile_f, flags);
291  }
292  }
293  if(p->zipFile_f!=NULL) {
294  if (ioDevice->isSequential()) {
295  if (mode != mdCreate) {
296  zipClose(p->zipFile_f, NULL);
297  qWarning("QuaZip::open(): "
298  "only mdCreate can be used with "
299  "sequential devices");
300  if (!p->zipName.isEmpty())
301  delete ioDevice;
302  return false;
303  }
304  zipSetFlags(p->zipFile_f, ZIP_SEQUENTIAL);
305  }
306  p->mode=mode;
307  p->ioDevice = ioDevice;
308  return true;
309  } else {
311  if (!p->zipName.isEmpty())
312  delete ioDevice;
313  return false;
314  }
315  default:
316  qWarning("QuaZip::open(): unknown mode: %d", (int)mode);
317  if (!p->zipName.isEmpty())
318  delete ioDevice;
319  return false;
320  break;
321  }
322 }
QIODevice * ioDevice
The device to access the archive.
Definition: quazip.cpp:51
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:619
#define ZIP_WRITE_DATA_DESCRIPTOR
Definition: zip.h:85
unzFile unzOpenInternal(voidpf file, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, int is64bitOpenFunction, unsigned flags)
Definition: unzip.c:587
#define UNZ_OK
Definition: unzip.h:79
QuaZipPrivate * p
Definition: quazip.h:129
#define APPEND_STATUS_CREATEAFTER
Definition: zip.h:124
ZIP file was opened for adding files in the archive.
Definition: quazip.h:106
int ZEXPORT unzSetFlags(unzFile file, unsigned flags)
Definition: unzip.c:2136
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:815
ZIP file was created with open() call.
Definition: quazip.h:97
bool dataDescriptorWritingEnabled
Whether the data descriptor writing mode is enabled.
Definition: quazip.cpp:67
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862
int ZEXPORT zipSetFlags(zipFile file, unsigned flags)
Definition: zip.c:2077
int ZEXPORT unzClearFlags(unzFile file, unsigned flags)
Definition: unzip.c:2147
QString zipName
The archive file name.
Definition: quazip.cpp:49
int zipError
The last error.
Definition: quazip.cpp:65
#define ZIP_AUTO_CLOSE
Definition: zip.h:86
bool autoClose
The auto-close flag.
Definition: quazip.cpp:71
ZIP file is open for reading files inside it.
Definition: quazip.h:96
#define UNZ_OPENERROR
Definition: quazip.h:41
#define ZIP_SEQUENTIAL
Definition: zip.h:87
ZIP file was opened in append mode.
Definition: quazip.h:98
zipFile ZEXPORT zipOpen2(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc32_def)
Definition: zip.c:939
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
unzFile ZEXPORT unzOpen2(voidpf file, zlib_filefunc_def *pzlib_filefunc32_def)
Definition: unzip.c:772
#define APPEND_STATUS_ADDINZIP
Definition: zip.h:125
#define UNZ_AUTO_CLOSE
Definition: unzip.h:88
#define APPEND_STATUS_CREATE
Definition: zip.h:123
int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1942

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QuaZip& QuaZip::operator= ( const QuaZip that)
private
void QuaZip::setAutoClose ( bool  autoClose) const

By default, QuaZIP opens the underlying QIODevice when open() is called, and closes it when close() is called. In some cases, when the device is set explicitly using setIoDevice(), it may be desirable to leave the device open. If the auto-close flag is unset using this method, then the device isn't closed automatically if it was set explicitly.

If it is needed to clear this flag, it is recommended to do so before opening the archive because otherwise QuaZIP may close the device during the open() call if an error is encountered after the device is opened.

If the device was not set explicitly, but rather the setZipName() or the appropriate constructor was used to set the ZIP file name instead, then the auto-close flag has no effect, and the internal device is closed nevertheless because there is no other way to close it.

See Also
isAutoClose()
setIoDevice()

Definition at line 785 of file quazip.cpp.

References QuaZipPrivate::autoClose, and p.

786 {
787  p->autoClose = autoClose;
788 }
QuaZipPrivate * p
Definition: quazip.h:129
bool autoClose
The auto-close flag.
Definition: quazip.cpp:71
void QuaZip::setComment ( const QString &  comment)

The comment will be written to the archive on close operation. QuaZip makes a distinction between a null QByteArray() comment and an empty "" comment in the QuaZip::mdAdd mode. A null comment is the default and it means "don't change the comment". An empty comment removes the original comment.

See Also
open()

Definition at line 629 of file quazip.cpp.

References QuaZipPrivate::comment, and p.

630 {
631  p->comment=comment;
632 }
QuaZipPrivate * p
Definition: quazip.h:129
QString comment
The global comment.
Definition: quazip.cpp:53
void QuaZip::setCommentCodec ( QTextCodec *  commentCodec)

This codec defaults to locale codec, which is probably ok.

Definition at line 587 of file quazip.cpp.

References QuaZipPrivate::commentCodec, and p.

588 {
589  p->commentCodec=commentCodec;
590 }
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * commentCodec
The codec for comments.
Definition: quazip.cpp:47
void QuaZip::setCommentCodec ( const char *  commentCodecName)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));

Definition at line 592 of file quazip.cpp.

References QuaZipPrivate::commentCodec, and p.

593 {
594  p->commentCodec=QTextCodec::codecForName(commentCodecName);
595 }
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * commentCodec
The codec for comments.
Definition: quazip.cpp:47
bool QuaZip::setCurrentFile ( const QString &  fileName,
CaseSensitivity  cs = csDefault 
)

Returns true if successful, false otherwise. Argument cs specifies case sensitivity of the file name. Call getZipError() in the case of a failure to get error code.

This is not a wrapper to unzLocateFile() function. That is because I had to implement locale-specific case-insensitive comparison.

Here are the differences from the original implementation:

  • If the file was not found, error code is UNZ_OK, not UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()).
  • If this function fails, it unsets the current file rather than resetting it back to what it was before the call.

If fileName is null string then this function unsets the current file and return true. Note that you should close the file first if it is open! See QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.

Should be used only in QuaZip::mdUnzip mode.

See Also
setFileNameCodec(), CaseSensitivity

Definition at line 408 of file quazip.cpp.

References convertCaseSensitivity(), current, QuaZipPrivate::directoryCaseInsensitive, QuaZipPrivate::directoryCaseSensitive, getCurrentFileName(), QuaZipPrivate::goToFirstUnmappedFile(), goToNextFile(), QuaZipPrivate::hasCurrentFile_f, MAX_FILE_NAME_LENGTH, mdUnzip, QuaZipPrivate::mode, p, unz64_file_pos_s::pos_in_zip_directory, UNZ_OK, UNZ_PARAMERROR, unzGoToFilePos64(), and QuaZipPrivate::zipError.

Referenced by KbFirmware::_fileForBoard(), JlCompress::extractFile(), QuaZipPrivate::getFileInfoList(), and QuaZipFile::open().

409 {
410  p->zipError=UNZ_OK;
411  if(p->mode!=mdUnzip) {
412  qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode");
413  return false;
414  }
415  if(fileName.isEmpty()) {
416  p->hasCurrentFile_f=false;
417  return true;
418  }
419  // Unicode-aware reimplementation of the unzLocateFile function
420  if(p->unzFile_f==NULL) {
422  return false;
423  }
424  if(fileName.length()>MAX_FILE_NAME_LENGTH) {
426  return false;
427  }
428  // Find the file by name
429  bool sens = convertCaseSensitivity(cs) == Qt::CaseSensitive;
430  QString lower, current;
431  if(!sens) lower=fileName.toLower();
432  p->hasCurrentFile_f=false;
433 
434  // Check the appropriate Map
435  unz64_file_pos fileDirPos;
436  fileDirPos.pos_in_zip_directory = 0;
437  if (sens) {
438  if (p->directoryCaseSensitive.contains(fileName))
439  fileDirPos = p->directoryCaseSensitive.value(fileName);
440  } else {
441  if (p->directoryCaseInsensitive.contains(lower))
442  fileDirPos = p->directoryCaseInsensitive.value(lower);
443  }
444 
445  if (fileDirPos.pos_in_zip_directory != 0) {
446  p->zipError = unzGoToFilePos64(p->unzFile_f, &fileDirPos);
448  }
449 
450  if (p->hasCurrentFile_f)
451  return p->hasCurrentFile_f;
452 
453  // Not mapped yet, start from where we have got to so far
454  for(bool more=p->goToFirstUnmappedFile(); more; more=goToNextFile()) {
455  current=getCurrentFileName();
456  if(current.isEmpty()) return false;
457  if(sens) {
458  if(current==fileName) break;
459  } else {
460  if(current.toLower()==lower) break;
461  }
462  }
463  return p->hasCurrentFile_f;
464 }
static Qt::CaseSensitivity convertCaseSensitivity(CaseSensitivity cs)
Returns the actual case sensitivity for the specified QuaZIP one.
Definition: quazip.cpp:747
rgb * current
Definition: main.c:46
#define UNZ_PARAMERROR
Definition: unzip.h:83
QHash< QString, unz64_file_pos > directoryCaseInsensitive
Definition: quazip.cpp:138
int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos)
Definition: unzip.c:1348
QString getCurrentFileName() const
Returns the current file name.
Definition: quazip.cpp:551
#define UNZ_OK
Definition: unzip.h:79
ZPOS64_T pos_in_zip_directory
Definition: unzip.h:294
QuaZipPrivate * p
Definition: quazip.h:129
QHash< QString, unz64_file_pos > directoryCaseSensitive
Definition: quazip.cpp:137
int zipError
The last error.
Definition: quazip.cpp:65
bool goToNextFile()
Sets the current file to the next file in the archive.
Definition: quazip.cpp:478
ZIP file is open for reading files inside it.
Definition: quazip.h:96
Maximum file name length.
Definition: quazip.h:89
bool hasCurrentFile_f
Whether a current file is set.
Definition: quazip.cpp:63
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
bool goToFirstUnmappedFile()
Definition: quazip.cpp:172

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QuaZip::setDataDescriptorWritingEnabled ( bool  enabled)

According to the ZIP format specification, a file inside archive may have a data descriptor immediately following the file data. This is reflected by a special flag in the local file header and in the central directory. By default, QuaZIP sets this flag and writes the data descriptor unless both method and level were set to 0, in which case it operates in 1.0-compatible mode and never writes data descriptors.

By setting this flag to false, it is possible to disable data descriptor writing, thus increasing compatibility with archive readers that don't understand this feature of the ZIP file format.

Setting this flag affects all the QuaZipFile instances that are opened after this flag is set.

The data descriptor writing mode is enabled by default.

Note that if the ZIP archive is written into a QIODevice for which QIODevice::isSequential() returns true, then the data descriptor is mandatory and will be written even if this flag is set to false.

Parameters
enabledIf true, enable local descriptor writing, disable it otherwise.
See Also
QuaZipFile::isDataDescriptorWritingEnabled()

Definition at line 649 of file quazip.cpp.

References QuaZipPrivate::dataDescriptorWritingEnabled, and p.

650 {
651  p->dataDescriptorWritingEnabled = enabled;
652 }
QuaZipPrivate * p
Definition: quazip.h:129
bool dataDescriptorWritingEnabled
Whether the data descriptor writing mode is enabled.
Definition: quazip.cpp:67
void QuaZip::setDefaultFileNameCodec ( QTextCodec *  codec)
static

The default codec is used by the constructors, so calling this function won't affect the QuaZip instances already created at that moment.

The codec specified here can be overriden by calling setFileNameCodec(). If neither function is called, QTextCodec::codecForLocale() will be used to decode or encode file names. Use this function with caution if the application uses other libraries that depend on QuaZIP. Those libraries can either call this function by themselves, thus overriding your setting or can rely on the default encoding, thus failing mysteriously if you change it. For these reasons, it isn't recommended to use this function if you are developing a library, not an application. Instead, ask your library users to call it in case they need specific encoding.

In most cases, using setFileNameCodec() instead is the right choice. However, if you depend on third-party code that uses QuaZIP, then the reasons stated above can actually become a reason to use this function in case the third-party code in question fails because it doesn't understand the encoding you need and doesn't provide a way to specify it. This applies to the JlCompress class as well, as it was contributed and doesn't support explicit encoding parameters.

In short: use setFileNameCodec() when you can, resort to setDefaultFileNameCodec() when you don't have access to the QuaZip instance.

Parameters
codecThe codec to use by default. If NULL, resets to default.

Definition at line 760 of file quazip.cpp.

References QuaZipPrivate::defaultFileNameCodec.

Referenced by setDefaultFileNameCodec().

761 {
763 }
static QTextCodec * defaultFileNameCodec
Definition: quazip.cpp:140

+ Here is the caller graph for this function:

void QuaZip::setDefaultFileNameCodec ( const char *  codecName)
static

Definition at line 765 of file quazip.cpp.

References setDefaultFileNameCodec().

766 {
767  setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
768 }
static void setDefaultFileNameCodec(QTextCodec *codec)
Sets the default file name codec to use.
Definition: quazip.cpp:760

+ Here is the call graph for this function:

void QuaZip::setFileNameCodec ( QTextCodec *  fileNameCodec)

This is necessary to access files in the ZIP archive created under Windows with non-latin characters in file names. For example, file names with cyrillic letters will be in IBM866 encoding.

Definition at line 572 of file quazip.cpp.

References QuaZipPrivate::fileNameCodec, and p.

573 {
574  p->fileNameCodec=fileNameCodec;
575 }
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * fileNameCodec
The codec for file names.
Definition: quazip.cpp:45
void QuaZip::setFileNameCodec ( const char *  fileNameCodecName)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));

Definition at line 577 of file quazip.cpp.

References QuaZipPrivate::fileNameCodec, and p.

578 {
579  p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
580 }
QuaZipPrivate * p
Definition: quazip.h:129
QTextCodec * fileNameCodec
The codec for file names.
Definition: quazip.cpp:45
void QuaZip::setIoDevice ( QIODevice ioDevice)

Does nothing if the ZIP file is open.

Does not reset error code returned by getZipError().

See Also
getIoDevice(), getZipName(), setZipName()

Definition at line 365 of file quazip.cpp.

References QuaZipPrivate::ioDevice, isOpen(), p, and QuaZipPrivate::zipName.

366 {
367  if(isOpen()) {
368  qWarning("QuaZip::setIoDevice(): ZIP is already open!");
369  return;
370  }
371  p->ioDevice = ioDevice;
372  p->zipName = QString();
373 }
QIODevice * ioDevice
The device to access the archive.
Definition: quazip.cpp:51
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:619
QuaZipPrivate * p
Definition: quazip.h:129
QString zipName
The archive file name.
Definition: quazip.cpp:49

+ Here is the call graph for this function:

void QuaZip::setZip64Enabled ( bool  zip64)
Parameters
zip64If true, the zip64 mode is enabled, disabled otherwise.

Once this is enabled, all new files (until the mode is disabled again) will be created in the zip64 mode, thus enabling the ability to write files larger than 4 GB. By default, the zip64 mode is off due to compatibility reasons.

Note that this does not affect the ability to read zip64 archives in any way.

See Also
isZip64Enabled()

Definition at line 770 of file quazip.cpp.

References p, and QuaZipPrivate::zip64.

771 {
772  p->zip64 = zip64;
773 }
QuaZipPrivate * p
Definition: quazip.h:129
bool zip64
The zip64 mode.
Definition: quazip.cpp:69
void QuaZip::setZipName ( const QString &  zipName)

Does nothing if the ZIP file is open.

Does not reset error code returned by getZipError().

See Also
setIoDevice(), getIoDevice(), getZipName()

Definition at line 355 of file quazip.cpp.

References QuaZipPrivate::ioDevice, isOpen(), p, and QuaZipPrivate::zipName.

356 {
357  if(isOpen()) {
358  qWarning("QuaZip::setZipName(): ZIP is already open!");
359  return;
360  }
361  p->zipName=zipName;
362  p->ioDevice = NULL;
363 }
QIODevice * ioDevice
The device to access the archive.
Definition: quazip.cpp:51
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:619
QuaZipPrivate * p
Definition: quazip.h:129
QString zipName
The archive file name.
Definition: quazip.cpp:49

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class QuaZipPrivate
friend

Definition at line 85 of file quazip.h.

Field Documentation


The documentation for this class was generated from the following files: