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.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2005-2014 Sergey A. Tachenov
3 
4 This file is part of QuaZIP.
5 
6 QuaZIP is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10 
11 QuaZIP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public License
17 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
18 
19 See COPYING file for the full LGPL text.
20 
21 Original ZIP package is copyrighted by Gilles Vollant, see
22 quazip/(un)zip.h files for details, basically it's zlib license.
23  **/
24 
25 #include <QFile>
26 #include <QFlags>
27 #include <QHash>
28 
29 #include "quazip.h"
30 
32 
40  friend class QuaZip;
41  private:
45  QTextCodec *fileNameCodec;
47  QTextCodec *commentCodec;
49  QString zipName;
53  QString comment;
56  union {
58  unzFile unzFile_f;
60  zipFile zipFile_f;
61  };
65  int zipError;
69  bool zip64;
71  bool autoClose;
72  inline QTextCodec *getDefaultFileNameCodec()
73  {
74  if (defaultFileNameCodec == NULL) {
75  return QTextCodec::codecForLocale();
76  } else {
77  return defaultFileNameCodec;
78  }
79  }
82  q(q),
84  commentCodec(QTextCodec::codecForLocale()),
85  ioDevice(NULL),
86  mode(QuaZip::mdNotOpen),
87  hasCurrentFile_f(false),
90  zip64(false),
91  autoClose(true)
92  {
95  }
97  inline QuaZipPrivate(QuaZip *q, const QString &zipName):
98  q(q),
100  commentCodec(QTextCodec::codecForLocale()),
101  zipName(zipName),
102  ioDevice(NULL),
103  mode(QuaZip::mdNotOpen),
104  hasCurrentFile_f(false),
105  zipError(UNZ_OK),
107  zip64(false),
108  autoClose(true)
109  {
112  }
115  q(q),
117  commentCodec(QTextCodec::codecForLocale()),
118  ioDevice(ioDevice),
119  mode(QuaZip::mdNotOpen),
120  hasCurrentFile_f(false),
121  zipError(UNZ_OK),
123  zip64(false),
124  autoClose(true)
125  {
128  }
130  template<typename TFileInfo>
131  bool getFileInfoList(QList<TFileInfo> *result) const;
132 
134  inline void clearDirectoryMap();
135  inline void addCurrentFileToDirectoryMap(const QString &fileName);
136  bool goToFirstUnmappedFile();
137  QHash<QString, unz64_file_pos> directoryCaseSensitive;
138  QHash<QString, unz64_file_pos> directoryCaseInsensitive;
140  static QTextCodec *defaultFileNameCodec;
141 };
142 
143 QTextCodec *QuaZipPrivate::defaultFileNameCodec = NULL;
144 
146 {
147  directoryCaseInsensitive.clear();
148  directoryCaseSensitive.clear();
151 }
152 
153 void QuaZipPrivate::addCurrentFileToDirectoryMap(const QString &fileName)
154 {
155  if (!hasCurrentFile_f || fileName.isEmpty()) {
156  return;
157  }
158  // Adds current file to filename map as fileName
159  unz64_file_pos fileDirectoryPos;
160  unzGetFilePos64(unzFile_f, &fileDirectoryPos);
161  directoryCaseSensitive.insert(fileName, fileDirectoryPos);
162  // Only add lowercase to directory map if not already there
163  // ensures only map the first one seen
164  QString lower = fileName.toLower();
165  if (!directoryCaseInsensitive.contains(lower))
166  directoryCaseInsensitive.insert(lower, fileDirectoryPos);
167  // Mark last one
169  lastMappedDirectoryEntry = fileDirectoryPos;
170 }
171 
173 {
174  zipError = UNZ_OK;
175  if (mode != QuaZip::mdUnzip) {
176  qWarning("QuaZipPrivate::goToNextUnmappedFile(): ZIP is not open in mdUnzip mode");
177  return false;
178  }
179  // If not mapped anything, go to beginning
181  unzGoToFirstFile(unzFile_f);
182  } else {
183  // Goto the last one mapped, plus one
185  unzGoToNextFile(unzFile_f);
186  }
190  return hasCurrentFile_f;
191 }
192 
194  p(new QuaZipPrivate(this))
195 {
196 }
197 
198 QuaZip::QuaZip(const QString& zipName):
199  p(new QuaZipPrivate(this, zipName))
200 {
201 }
202 
204  p(new QuaZipPrivate(this, ioDevice))
205 {
206 }
207 
209 {
210  if(isOpen())
211  close();
212  delete p;
213 }
214 
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 }
323 
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 }
354 
355 void QuaZip::setZipName(const QString& 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 }
364 
366 {
367  if(isOpen()) {
368  qWarning("QuaZip::setIoDevice(): ZIP is already open!");
369  return;
370  }
371  p->ioDevice = ioDevice;
372  p->zipName = QString();
373 }
374 
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 }
388 
389 QString QuaZip::getComment()const
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 }
407 
408 bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
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 }
465 
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 }
477 
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 }
491 
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 }
505 
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 }
550 
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 }
571 
572 void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec)
573 {
574  p->fileNameCodec=fileNameCodec;
575 }
576 
577 void QuaZip::setFileNameCodec(const char *fileNameCodecName)
578 {
579  p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
580 }
581 
582 QTextCodec *QuaZip::getFileNameCodec()const
583 {
584  return p->fileNameCodec;
585 }
586 
587 void QuaZip::setCommentCodec(QTextCodec *commentCodec)
588 {
589  p->commentCodec=commentCodec;
590 }
591 
592 void QuaZip::setCommentCodec(const char *commentCodecName)
593 {
594  p->commentCodec=QTextCodec::codecForName(commentCodecName);
595 }
596 
597 QTextCodec *QuaZip::getCommentCodec()const
598 {
599  return p->commentCodec;
600 }
601 
602 QString QuaZip::getZipName() const
603 {
604  return p->zipName;
605 }
606 
608 {
609  if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice
610  return NULL;
611  return p->ioDevice;
612 }
613 
615 {
616  return p->mode;
617 }
618 
619 bool QuaZip::isOpen()const
620 {
621  return p->mode!=mdNotOpen;
622 }
623 
625 {
626  return p->zipError;
627 }
628 
629 void QuaZip::setComment(const QString& comment)
630 {
631  p->comment=comment;
632 }
633 
635 {
636  return p->hasCurrentFile_f;
637 }
638 
640 {
641  return p->unzFile_f;
642 }
643 
645 {
646  return p->zipFile_f;
647 }
648 
650 {
651  p->dataDescriptorWritingEnabled = enabled;
652 }
653 
655 {
657 }
658 
659 template<typename TFileInfo>
660 TFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok);
661 
662 template<>
664 {
665  QuaZipFileInfo info;
666  *ok = zip->getCurrentFileInfo(&info);
667  return info;
668 }
669 
670 template<>
672 {
673  QuaZipFileInfo64 info;
674  *ok = zip->getCurrentFileInfo(&info);
675  return info;
676 }
677 
678 template<>
679 QString QuaZip_getFileInfo(QuaZip *zip, bool *ok)
680 {
681  QString name = zip->getCurrentFileName();
682  *ok = !name.isEmpty();
683  return name;
684 }
685 
686 template<typename TFileInfo>
687 bool QuaZipPrivate::getFileInfoList(QList<TFileInfo> *result) const
688 {
689  QuaZipPrivate *fakeThis=const_cast<QuaZipPrivate*>(this);
690  fakeThis->zipError=UNZ_OK;
691  if (mode!=QuaZip::mdUnzip) {
692  qWarning("QuaZip::getFileNameList/getFileInfoList(): "
693  "ZIP is not open in mdUnzip mode");
694  return false;
695  }
696  QString currentFile;
697  if (q->hasCurrentFile()) {
698  currentFile = q->getCurrentFileName();
699  }
700  if (q->goToFirstFile()) {
701  do {
702  bool ok;
703  result->append(QuaZip_getFileInfo<TFileInfo>(q, &ok));
704  if (!ok)
705  return false;
706  } while (q->goToNextFile());
707  }
708  if (zipError != UNZ_OK)
709  return false;
710  if (currentFile.isEmpty()) {
711  if (!q->goToFirstFile())
712  return false;
713  } else {
714  if (!q->setCurrentFile(currentFile))
715  return false;
716  }
717  return true;
718 }
719 
720 QStringList QuaZip::getFileNameList() const
721 {
722  QStringList list;
723  if (p->getFileInfoList(&list))
724  return list;
725  else
726  return QStringList();
727 }
728 
729 QList<QuaZipFileInfo> QuaZip::getFileInfoList() const
730 {
731  QList<QuaZipFileInfo> list;
732  if (p->getFileInfoList(&list))
733  return list;
734  else
735  return QList<QuaZipFileInfo>();
736 }
737 
738 QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const
739 {
740  QList<QuaZipFileInfo64> list;
741  if (p->getFileInfoList(&list))
742  return list;
743  else
744  return QList<QuaZipFileInfo64>();
745 }
746 
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 }
759 
760 void QuaZip::setDefaultFileNameCodec(QTextCodec *codec)
761 {
763 }
764 
765 void QuaZip::setDefaultFileNameCodec(const char *codecName)
766 {
767  setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
768 }
769 
770 void QuaZip::setZip64Enabled(bool zip64)
771 {
772  p->zip64 = zip64;
773 }
774 
776 {
777  return p->zip64;
778 }
779 
781 {
782  return p->autoClose;
783 }
784 
785 void QuaZip::setAutoClose(bool autoClose) const
786 {
787  p->autoClose = autoClose;
788 }
static Qt::CaseSensitivity convertCaseSensitivity(CaseSensitivity cs)
Returns the actual case sensitivity for the specified QuaZIP one.
Definition: quazip.cpp:747
quint16 diskNumberStart
Disk number start.
ZPOS64_T compressed_size
Definition: unzip.h:127
QIODevice * ioDevice
The device to access the archive.
Definition: quazip.cpp:51
QStringList getFileNameList() const
Returns a list of files inside the archive.
Definition: quazip.cpp:720
rgb * current
Definition: main.c:46
#define UNZ_PARAMERROR
Definition: unzip.h:83
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.
#define ZIP_WRITE_DATA_DESCRIPTOR
Definition: zip.h:85
bool goToFirstFile()
Sets the current file to the first file in the archive.
Definition: quazip.cpp:466
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1188
quint16 versionCreated
Version created by.
QHash< QString, unz64_file_pos > directoryCaseInsensitive
Definition: quazip.cpp:138
QString comment
Comment.
unzFile unzOpenInternal(voidpf file, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, int is64bitOpenFunction, unsigned flags)
Definition: unzip.c:587
voidp unzFile
Definition: unzip.h:75
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
QuaZipPrivate(QuaZip *q)
The constructor for the corresponding QuaZip constructor.
Definition: quazip.cpp:81
#define UNZ_OK
Definition: unzip.h:79
quint32 externalAttr
External file attributes.
ZPOS64_T pos_in_zip_directory
Definition: unzip.h:294
quint16 versionNeeded
Version needed to extract.
QTextCodec * getCommentCodec() const
Returns the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:597
int getEntriesCount() const
Returns number of the entries in the ZIP central directory.
Definition: quazip.cpp:375
int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
Definition: unzip.c:1318
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1209
tm_unz tmu_date
Definition: unzip.h:137
void setDataDescriptorWritingEnabled(bool enabled)
Changes the data descriptor writing mode.
Definition: quazip.cpp:649
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
Mode getMode() const
Returns the mode in which ZIP file was opened.
Definition: quazip.cpp:614
ZIP file is not open. This is the initial mode.
Definition: quazip.h:95
static void setDefaultFileNameCodec(QTextCodec *codec)
Sets the default file name codec to use.
Definition: quazip.cpp:760
int ZEXPORT unzSetFlags(unzFile file, unsigned flags)
Definition: unzip.c:2136
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
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
unz64_file_pos lastMappedDirectoryEntry
Definition: quazip.cpp:139
int getZipError() const
Returns the error code of the last operation.
Definition: quazip.cpp:624
uLong size_file_extra
Definition: unzip.h:130
uLong size_file_comment
Definition: unzip.h:131
bool toQuaZipFileInfo(QuaZipFileInfo &info) const
Converts to QuaZipFileInfo.
uLong size_filename
Definition: unzip.h:129
QIODevice * getIoDevice() const
Returns the device representing this ZIP file.
Definition: quazip.cpp:607
Information about a file inside archive.
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:838
QTextCodec * getDefaultFileNameCodec()
Definition: quazip.cpp:72
ZPOS64_T num_of_file
Definition: unzip.h:295
uLong compression_method
Definition: unzip.h:124
bool dataDescriptorWritingEnabled
Whether the data descriptor writing mode is enabled.
Definition: quazip.cpp:67
void setCommentCodec(QTextCodec *commentCodec)
Sets the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:587
uInt tm_year
Definition: unzip.h:99
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862
QuaZip()
Constructs QuaZip object.
Definition: quazip.cpp:193
int ZEXPORT zipSetFlags(zipFile file, unsigned flags)
Definition: zip.c:2077
ZPOS64_T uncompressed_size
Definition: unzip.h:128
voidp zipFile
Definition: zip.h:75
quint32 crc
CRC.
quint64 compressedSize
Compressed file size.
zipFile getZipFile()
Returns zipFile handle.
Definition: quazip.cpp:644
int ZEXPORT unzClearFlags(unzFile file, unsigned flags)
Definition: unzip.c:2147
uLong version_needed
Definition: unzip.h:122
void clearDirectoryMap()
Stores map of filenames and file locations for unzipping.
Definition: quazip.cpp:145
Mode
Open mode of the ZIP file.
Definition: quazip.h:94
QHash< QString, unz64_file_pos > directoryCaseSensitive
Definition: quazip.cpp:137
uInt tm_min
Definition: unzip.h:95
QuaZipPrivate(QuaZip *q, QIODevice *ioDevice)
The constructor for the corresponding QuaZip constructor.
Definition: quazip.cpp:114
QString getZipName() const
Returns the name of the ZIP file.
Definition: quazip.cpp:602
QString zipName
The archive file name.
Definition: quazip.cpp:49
int zipError
The last error.
Definition: quazip.cpp:65
bool isZip64Enabled() const
Returns whether the zip64 mode is enabled.
Definition: quazip.cpp:775
bool zip64
The zip64 mode.
Definition: quazip.cpp:69
uLong version
Definition: unzip.h:121
bool getFileInfoList(QList< TFileInfo > *result) const
Returns either a list of file names or a list of QuaZipFileInfo.
Definition: quazip.cpp:687
bool goToNextFile()
Sets the current file to the next file in the archive.
Definition: quazip.cpp:478
#define ZIP_AUTO_CLOSE
Definition: zip.h:86
Information about a file inside archive (with zip64 support).
static QTextCodec * defaultFileNameCodec
Definition: quazip.cpp:140
QTextCodec * getFileNameCodec() const
Returns the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:582
bool autoClose
The auto-close flag.
Definition: quazip.cpp:71
bool setCurrentFile(const QString &fileName, CaseSensitivity cs=csDefault)
Sets current file by its name.
Definition: quazip.cpp:408
ZIP file is open for reading files inside it.
Definition: quazip.h:96
quint16 method
Compression method.
void close()
Closes ZIP file.
Definition: quazip.cpp:324
void setZipName(const QString &zipName)
Sets the name of the ZIP file.
Definition: quazip.cpp:355
bool isAutoClose() const
Returns the auto-close flag.
Definition: quazip.cpp:780
QuaZip * q
The pointer to the corresponding QuaZip instance.
Definition: quazip.cpp:43
uLong internal_fa
Definition: unzip.h:134
uLong disk_num_start
Definition: unzip.h:133
int ZEXPORT unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf)
Definition: unzip.c:2059
ZPOS64_T number_entry
Definition: unzip.h:106
QuaZipPrivate(QuaZip *q, const QString &zipName)
The constructor for the corresponding QuaZip constructor.
Definition: quazip.cpp:97
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
#define UNZ_OPENERROR
Definition: quazip.h:41
QList< QuaZipFileInfo > getFileInfoList() const
Returns information list about all files inside the archive.
Definition: quazip.cpp:729
uInt tm_hour
Definition: unzip.h:96
uInt tm_mon
Definition: unzip.h:98
unzFile getUnzFile()
Returns unzFile handle.
Definition: quazip.cpp:639
CaseSensitivity
Case sensitivity for the file names.
Definition: quazip.h:114
All the internal stuff for the QuaZip class.
Definition: quazip.cpp:39
Case sensitive.
Definition: quazip.h:116
bool isDataDescriptorWritingEnabled() const
Returns the data descriptor default writing mode.
Definition: quazip.cpp:654
void setAutoClose(bool autoClose) const
Sets or unsets the auto-close flag.
Definition: quazip.cpp:785
QDateTime dateTime
Last modification date and time.
#define ZIP_SEQUENTIAL
Definition: zip.h:87
ZIP file was opened in append mode.
Definition: quazip.h:98
quint16 flags
General purpose flags.
bool open(Mode mode, zlib_filefunc_def *ioApi=NULL)
Opens ZIP file.
Definition: quazip.cpp:215
void setComment(const QString &comment)
Sets the global comment in the ZIP file.
Definition: quazip.cpp:629
zipFile ZEXPORT zipOpen2(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc32_def)
Definition: zip.c:939
bool hasCurrentFile() const
Returns true if the current file has been set.
Definition: quazip.cpp:634
Maximum file name length.
Definition: quazip.h:89
bool hasCurrentFile_f
Whether a current file is set.
Definition: quazip.cpp:63
~QuaZip()
Destroys QuaZip object.
Definition: quazip.cpp:208
QString getComment() const
Returns global comment in the ZIP file.
Definition: quazip.cpp:389
QuaZip::Mode mode
The open mode.
Definition: quazip.cpp:55
QString name
File name.
unzFile ZEXPORT unzOpen2(voidpf file, zlib_filefunc_def *pzlib_filefunc32_def)
Definition: unzip.c:772
Default for platform. Case sensitive for UNIX, not for Windows.
Definition: quazip.h:115
#define APPEND_STATUS_ADDINZIP
Definition: zip.h:125
QTextCodec * fileNameCodec
The codec for file names.
Definition: quazip.cpp:45
void setZip64Enabled(bool zip64)
Enables the zip64 mode.
Definition: quazip.cpp:770
quint16 internalAttr
Internal file attributes.
#define UNZ_AUTO_CLOSE
Definition: unzip.h:88
#define APPEND_STATUS_CREATE
Definition: zip.h:123
#define UNZ_END_OF_LIST_OF_FILE
Definition: unzip.h:80
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.
Definition: quazip.cpp:492
int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1942
TFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok)
Definition: quazip.cpp:663
uLong size_comment
Definition: unzip.h:108
QList< QuaZipFileInfo64 > getFileInfoList64() const
Returns information list about all files inside the archive.
Definition: quazip.cpp:738
void setIoDevice(QIODevice *ioDevice)
Sets the device representing the ZIP file.
Definition: quazip.cpp:365
void setFileNameCodec(QTextCodec *fileNameCodec)
Sets the codec used to encode/decode file names inside archive.
Definition: quazip.cpp:572
bool goToFirstUnmappedFile()
Definition: quazip.cpp:172