ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
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 "quazip.h"
26 
27 #include <QFile>
28 #include <QFlags>
29 #include <QHash>
30 
32 
39 class QuaZipPrivate {
40  friend class QuaZip;
41 
42 private:
43  Q_DISABLE_COPY(QuaZipPrivate)
45  QuaZip *q;
47  QTextCodec *fileNameCodec;
49  QTextCodec *commentCodec;
51  QString zipName;
53  QIODevice *ioDevice;
55  QString comment;
57  QuaZip::Mode mode;
58  union {
60  unzFile unzFile_f;
62  zipFile zipFile_f;
63  };
65  bool hasCurrentFile_f;
67  int zipError;
70  bool dataDescriptorWritingEnabled;
72  bool zip64;
74  bool autoClose;
75  inline QTextCodec *getDefaultFileNameCodec() {
76  if (defaultFileNameCodec == NULL) {
78  } else {
79  return defaultFileNameCodec;
80  }
81  }
83  inline QuaZipPrivate(QuaZip *q)
84  : q(q),
85  fileNameCodec(getDefaultFileNameCodec()),
86  commentCodec(QTextCodec::codecForLocale()),
87  ioDevice(NULL),
88  mode(QuaZip::mdNotOpen),
89  hasCurrentFile_f(false),
90  zipError(UNZ_OK),
91  dataDescriptorWritingEnabled(true),
92  zip64(false),
93  autoClose(true) {
94  unzFile_f = NULL;
95  zipFile_f = NULL;
96  lastMappedDirectoryEntry.num_of_file = 0;
97  lastMappedDirectoryEntry.pos_in_zip_directory = 0;
98  }
100  inline QuaZipPrivate(QuaZip *q, const QString &zipName)
101  : q(q),
102  fileNameCodec(getDefaultFileNameCodec()),
103  commentCodec(QTextCodec::codecForLocale()),
104  zipName(zipName),
105  ioDevice(NULL),
106  mode(QuaZip::mdNotOpen),
107  hasCurrentFile_f(false),
108  zipError(UNZ_OK),
109  dataDescriptorWritingEnabled(true),
110  zip64(false),
111  autoClose(true) {
112  unzFile_f = NULL;
113  zipFile_f = NULL;
114  lastMappedDirectoryEntry.num_of_file = 0;
115  lastMappedDirectoryEntry.pos_in_zip_directory = 0;
116  }
118  inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice)
119  : q(q),
120  fileNameCodec(getDefaultFileNameCodec()),
121  commentCodec(QTextCodec::codecForLocale()),
122  ioDevice(ioDevice),
123  mode(QuaZip::mdNotOpen),
124  hasCurrentFile_f(false),
125  zipError(UNZ_OK),
126  dataDescriptorWritingEnabled(true),
127  zip64(false),
128  autoClose(true) {
129  unzFile_f = NULL;
130  zipFile_f = NULL;
131  lastMappedDirectoryEntry.num_of_file = 0;
132  lastMappedDirectoryEntry.pos_in_zip_directory = 0;
133  }
135  template <typename TFileInfo>
136  bool getFileInfoList(QList<TFileInfo> *result) const;
137 
139  inline void clearDirectoryMap();
140  inline void addCurrentFileToDirectoryMap(const QString &fileName);
141  bool goToFirstUnmappedFile();
142  QHash<QString, unz64_file_pos> directoryCaseSensitive;
143  QHash<QString, unz64_file_pos> directoryCaseInsensitive;
144  unz64_file_pos lastMappedDirectoryEntry;
145  static QTextCodec *defaultFileNameCodec;
146 };
147 
148 QTextCodec *QuaZipPrivate::defaultFileNameCodec = NULL;
149 
150 void QuaZipPrivate::clearDirectoryMap() {
151  directoryCaseInsensitive.clear();
152  directoryCaseSensitive.clear();
153  lastMappedDirectoryEntry.num_of_file = 0;
154  lastMappedDirectoryEntry.pos_in_zip_directory = 0;
155 }
156 
157 void QuaZipPrivate::addCurrentFileToDirectoryMap(const QString &fileName) {
158  if (!hasCurrentFile_f || fileName.isEmpty()) {
159  return;
160  }
161  // Adds current file to filename map as fileName
162  unz64_file_pos fileDirectoryPos;
163  unzGetFilePos64(unzFile_f, &fileDirectoryPos);
164  directoryCaseSensitive.insert(fileName, fileDirectoryPos);
165  // Only add lowercase to directory map if not already there
166  // ensures only map the first one seen
167  QString lower = fileName.toLower();
168  if (!directoryCaseInsensitive.contains(lower))
169  directoryCaseInsensitive.insert(lower, fileDirectoryPos);
170  // Mark last one
171  if (fileDirectoryPos.pos_in_zip_directory >
172  lastMappedDirectoryEntry.pos_in_zip_directory)
173  lastMappedDirectoryEntry = fileDirectoryPos;
174 }
175 
176 bool QuaZipPrivate::goToFirstUnmappedFile() {
177  zipError = UNZ_OK;
178  if (mode != QuaZip::mdUnzip) {
179  qWarning(
180  "QuaZipPrivate::goToNextUnmappedFile(): ZIP is not open in "
181  "mdUnzip mode");
182  return false;
183  }
184  // If not mapped anything, go to beginning
185  if (lastMappedDirectoryEntry.pos_in_zip_directory == 0) {
186  unzGoToFirstFile(unzFile_f);
187  } else {
188  // Goto the last one mapped, plus one
189  unzGoToFilePos64(unzFile_f, &lastMappedDirectoryEntry);
190  unzGoToNextFile(unzFile_f);
191  }
192  hasCurrentFile_f = zipError == UNZ_OK;
193  if (zipError == UNZ_END_OF_LIST_OF_FILE) zipError = UNZ_OK;
194  return hasCurrentFile_f;
195 }
196 
197 QuaZip::QuaZip() : p(new QuaZipPrivate(this)) {}
198 
199 QuaZip::QuaZip(const QString &zipName) : p(new QuaZipPrivate(this, zipName)) {}
200 
201 QuaZip::QuaZip(QIODevice *ioDevice) : p(new QuaZipPrivate(this, ioDevice)) {}
202 
204  if (isOpen()) close();
205  delete p;
206 }
207 
208 bool QuaZip::open(Mode mode, zlib_filefunc_def *ioApi) {
209  p->zipError = UNZ_OK;
210  if (isOpen()) {
211  qWarning("QuaZip::open(): ZIP already opened");
212  return false;
213  }
214  QIODevice *ioDevice = p->ioDevice;
215  if (ioDevice == NULL) {
216  if (p->zipName.isEmpty()) {
217  qWarning(
218  "QuaZip::open(): set either ZIP file name or IO device "
219  "first");
220  return false;
221  } else {
222  ioDevice = new QFile(p->zipName);
223  }
224  }
225  unsigned flags = 0;
226  switch (mode) {
227  case mdUnzip:
228  if (ioApi == NULL) {
229  if (p->autoClose) flags |= UNZ_AUTO_CLOSE;
230  p->unzFile_f = unzOpenInternal(ioDevice, NULL, 1, flags);
231  } else {
232  // QuaZIP pre-zip64 compatibility mode
233  p->unzFile_f = unzOpen2(ioDevice, ioApi);
234  if (p->unzFile_f != NULL) {
235  if (p->autoClose) {
236  unzSetFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
237  } else {
238  unzClearFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
239  }
240  }
241  }
242  if (p->unzFile_f != NULL) {
243  if (ioDevice->isSequential()) {
244  unzClose(p->unzFile_f);
245  if (!p->zipName.isEmpty()) delete ioDevice;
246  qWarning(
247  "QuaZip::open(): "
248  "only mdCreate can be used with "
249  "sequential devices");
250  return false;
251  }
252  p->mode = mode;
253  p->ioDevice = ioDevice;
254  return true;
255  } else {
256  p->zipError = UNZ_OPENERROR;
257  if (!p->zipName.isEmpty()) delete ioDevice;
258  return false;
259  }
260  case mdCreate:
261  case mdAppend:
262  case mdAdd:
263  if (ioApi == NULL) {
264  if (p->autoClose) flags |= ZIP_AUTO_CLOSE;
265  if (p->dataDescriptorWritingEnabled)
266  flags |= ZIP_WRITE_DATA_DESCRIPTOR;
267  p->zipFile_f =
268  zipOpen3(ioDevice,
272  NULL, NULL, flags);
273  } else {
274  // QuaZIP pre-zip64 compatibility mode
275  p->zipFile_f =
276  zipOpen2(ioDevice,
280  NULL, ioApi);
281  if (p->zipFile_f != NULL) {
282  zipSetFlags(p->zipFile_f, flags);
283  }
284  }
285  if (p->zipFile_f != NULL) {
286  if (ioDevice->isSequential()) {
287  if (mode != mdCreate) {
288  zipClose(p->zipFile_f, NULL);
289  qWarning(
290  "QuaZip::open(): "
291  "only mdCreate can be used with "
292  "sequential devices");
293  if (!p->zipName.isEmpty()) delete ioDevice;
294  return false;
295  }
296  zipSetFlags(p->zipFile_f, ZIP_SEQUENTIAL);
297  }
298  p->mode = mode;
299  p->ioDevice = ioDevice;
300  return true;
301  } else {
302  p->zipError = UNZ_OPENERROR;
303  if (!p->zipName.isEmpty()) delete ioDevice;
304  return false;
305  }
306  default:
307  qWarning("QuaZip::open(): unknown mode: %d", (int)mode);
308  if (!p->zipName.isEmpty()) delete ioDevice;
309  return false;
310  break;
311  }
312 }
313 
315  p->zipError = UNZ_OK;
316  switch (p->mode) {
317  case mdNotOpen:
318  qWarning("QuaZip::close(): ZIP is not open");
319  return;
320  case mdUnzip:
321  p->zipError = unzClose(p->unzFile_f);
322  break;
323  case mdCreate:
324  case mdAppend:
325  case mdAdd:
326  p->zipError =
327  zipClose(p->zipFile_f,
328  p->comment.isNull()
329  ? NULL
330  : p->commentCodec->fromUnicode(p->comment)
331  .constData());
332  break;
333  default:
334  qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
335  return;
336  }
337  // opened by name, need to delete the internal IO device
338  if (!p->zipName.isEmpty()) {
339  delete p->ioDevice;
340  p->ioDevice = NULL;
341  }
342  p->clearDirectoryMap();
343  if (p->zipError == UNZ_OK) p->mode = mdNotOpen;
344 }
345 
346 void QuaZip::setZipName(const QString &zipName) {
347  if (isOpen()) {
348  qWarning("QuaZip::setZipName(): ZIP is already open!");
349  return;
350  }
351  p->zipName = zipName;
352  p->ioDevice = NULL;
353 }
354 
355 void QuaZip::setIoDevice(QIODevice *ioDevice) {
356  if (isOpen()) {
357  qWarning("QuaZip::setIoDevice(): ZIP is already open!");
358  return;
359  }
360  p->ioDevice = ioDevice;
361  p->zipName = QString();
362 }
363 
365  QuaZip *fakeThis = (QuaZip *)this; // non-const
366  fakeThis->p->zipError = UNZ_OK;
367  if (p->mode != mdUnzip) {
368  qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode");
369  return -1;
370  }
371  unz_global_info64 globalInfo;
372  if ((fakeThis->p->zipError =
373  unzGetGlobalInfo64(p->unzFile_f, &globalInfo)) != UNZ_OK)
374  return p->zipError;
375  return (int)globalInfo.number_entry;
376 }
377 
378 QString QuaZip::getComment() const {
379  QuaZip *fakeThis = (QuaZip *)this; // non-const
380  fakeThis->p->zipError = UNZ_OK;
381  if (p->mode != mdUnzip) {
382  qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode");
383  return QString();
384  }
385  unz_global_info64 globalInfo;
386  QByteArray comment;
387  if ((fakeThis->p->zipError =
388  unzGetGlobalInfo64(p->unzFile_f, &globalInfo)) != UNZ_OK)
389  return QString();
390  comment.resize(globalInfo.size_comment);
391  if ((fakeThis->p->zipError = unzGetGlobalComment(
392  p->unzFile_f, comment.data(), comment.size())) < 0)
393  return QString();
394  fakeThis->p->zipError = UNZ_OK;
395  return p->commentCodec->toUnicode(comment);
396 }
397 
398 bool QuaZip::setCurrentFile(const QString &fileName, CaseSensitivity cs) {
399  p->zipError = UNZ_OK;
400  if (p->mode != mdUnzip) {
401  qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode");
402  return false;
403  }
404  if (fileName.isEmpty()) {
405  p->hasCurrentFile_f = false;
406  return true;
407  }
408  // Unicode-aware reimplementation of the unzLocateFile function
409  if (p->unzFile_f == NULL) {
410  p->zipError = UNZ_PARAMERROR;
411  return false;
412  }
413  if (fileName.length() > MAX_FILE_NAME_LENGTH) {
414  p->zipError = UNZ_PARAMERROR;
415  return false;
416  }
417  // Find the file by name
418  bool sens = convertCaseSensitivity(cs) == Qt::CaseSensitive;
419  QString lower, current;
420  if (!sens) lower = fileName.toLower();
421  p->hasCurrentFile_f = false;
422 
423  // Check the appropriate Map
424  unz64_file_pos fileDirPos;
425  fileDirPos.pos_in_zip_directory = 0;
426  if (sens) {
427  if (p->directoryCaseSensitive.contains(fileName))
428  fileDirPos = p->directoryCaseSensitive.value(fileName);
429  } else {
430  if (p->directoryCaseInsensitive.contains(lower))
431  fileDirPos = p->directoryCaseInsensitive.value(lower);
432  }
433 
434  if (fileDirPos.pos_in_zip_directory != 0) {
435  p->zipError = unzGoToFilePos64(p->unzFile_f, &fileDirPos);
436  p->hasCurrentFile_f = p->zipError == UNZ_OK;
437  }
438 
439  if (p->hasCurrentFile_f) return p->hasCurrentFile_f;
440 
441  // Not mapped yet, start from where we have got to so far
442  for (bool more = p->goToFirstUnmappedFile(); more; more = goToNextFile()) {
443  current = getCurrentFileName();
444  if (current.isEmpty()) return false;
445  if (sens) {
446  if (current == fileName) break;
447  } else {
448  if (current.toLower() == lower) break;
449  }
450  }
451  return p->hasCurrentFile_f;
452 }
453 
455  p->zipError = UNZ_OK;
456  if (p->mode != mdUnzip) {
457  qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
458  return false;
459  }
460  p->zipError = unzGoToFirstFile(p->unzFile_f);
461  p->hasCurrentFile_f = p->zipError == UNZ_OK;
462  return p->hasCurrentFile_f;
463 }
464 
466  p->zipError = UNZ_OK;
467  if (p->mode != mdUnzip) {
468  qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
469  return false;
470  }
471  p->zipError = unzGoToNextFile(p->unzFile_f);
472  p->hasCurrentFile_f = p->zipError == UNZ_OK;
473  if (p->zipError == UNZ_END_OF_LIST_OF_FILE) p->zipError = UNZ_OK;
474  return p->hasCurrentFile_f;
475 }
476 
478  QuaZipFileInfo64 info64;
479  if (info == NULL) { // Very unlikely because of the overloads
480  return false;
481  }
482  if (getCurrentFileInfo(&info64)) {
483  info64.toQuaZipFileInfo(*info);
484  return true;
485  } else {
486  return false;
487  }
488 }
489 
491  QuaZip *fakeThis = (QuaZip *)this; // non-const
492  fakeThis->p->zipError = UNZ_OK;
493  if (p->mode != mdUnzip) {
494  qWarning(
495  "QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip "
496  "mode");
497  return false;
498  }
499  unz_file_info64 info_z;
500  QByteArray fileName;
501  QByteArray extra;
502  QByteArray comment;
503  if (info == NULL) return false;
504  if (!isOpen() || !hasCurrentFile()) return false;
505  if ((fakeThis->p->zipError = unzGetCurrentFileInfo64(
506  p->unzFile_f, &info_z, NULL, 0, NULL, 0, NULL, 0)) != UNZ_OK)
507  return false;
508  fileName.resize(info_z.size_filename);
509  extra.resize(info_z.size_file_extra);
510  comment.resize(info_z.size_file_comment);
511  if ((fakeThis->p->zipError = unzGetCurrentFileInfo64(
512  p->unzFile_f, NULL, fileName.data(), fileName.size(),
513  extra.data(), extra.size(), comment.data(), comment.size())) !=
514  UNZ_OK)
515  return false;
516  info->versionCreated = info_z.version;
517  info->versionNeeded = info_z.version_needed;
518  info->flags = info_z.flag;
519  info->method = info_z.compression_method;
520  info->crc = info_z.crc;
521  info->compressedSize = info_z.compressed_size;
522  info->uncompressedSize = info_z.uncompressed_size;
523  info->diskNumberStart = info_z.disk_num_start;
524  info->internalAttr = info_z.internal_fa;
525  info->externalAttr = info_z.external_fa;
526  info->name = p->fileNameCodec->toUnicode(fileName);
527  info->comment = p->commentCodec->toUnicode(comment);
528  info->extra = extra;
529  info->dateTime =
530  QDateTime(QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon + 1,
531  info_z.tmu_date.tm_mday),
532  QTime(info_z.tmu_date.tm_hour, info_z.tmu_date.tm_min,
533  info_z.tmu_date.tm_sec));
534  // Add to directory map
535  p->addCurrentFileToDirectoryMap(info->name);
536  return true;
537 }
538 
539 QString QuaZip::getCurrentFileName() const {
540  QuaZip *fakeThis = (QuaZip *)this; // non-const
541  fakeThis->p->zipError = UNZ_OK;
542  if (p->mode != mdUnzip) {
543  qWarning(
544  "QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip "
545  "mode");
546  return QString();
547  }
548  if (!isOpen() || !hasCurrentFile()) return QString();
549  QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
550  if ((fakeThis->p->zipError = unzGetCurrentFileInfo64(
551  p->unzFile_f, NULL, fileName.data(), fileName.size(), NULL, 0,
552  NULL, 0)) != UNZ_OK)
553  return QString();
554  QString result = p->fileNameCodec->toUnicode(fileName.constData());
555  if (result.isEmpty()) return result;
556  // Add to directory map
557  p->addCurrentFileToDirectoryMap(result);
558  return result;
559 }
560 
561 void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec) {
562  p->fileNameCodec = fileNameCodec;
563 }
564 
565 void QuaZip::setFileNameCodec(const char *fileNameCodecName) {
566  p->fileNameCodec = QTextCodec::codecForName(fileNameCodecName);
567 }
568 
569 QTextCodec *QuaZip::getFileNameCodec() const { return p->fileNameCodec; }
570 
571 void QuaZip::setCommentCodec(QTextCodec *commentCodec) {
572  p->commentCodec = commentCodec;
573 }
574 
575 void QuaZip::setCommentCodec(const char *commentCodecName) {
576  p->commentCodec = QTextCodec::codecForName(commentCodecName);
577 }
578 
579 QTextCodec *QuaZip::getCommentCodec() const { return p->commentCodec; }
580 
581 QString QuaZip::getZipName() const { return p->zipName; }
582 
583 QIODevice *QuaZip::getIoDevice() const {
584  if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice
585  return NULL;
586  return p->ioDevice;
587 }
588 
589 QuaZip::Mode QuaZip::getMode() const { return p->mode; }
590 
591 bool QuaZip::isOpen() const { return p->mode != mdNotOpen; }
592 
593 int QuaZip::getZipError() const { return p->zipError; }
594 
595 void QuaZip::setComment(const QString &comment) { p->comment = comment; }
596 
597 bool QuaZip::hasCurrentFile() const { return p->hasCurrentFile_f; }
598 
599 unzFile QuaZip::getUnzFile() { return p->unzFile_f; }
600 
601 zipFile QuaZip::getZipFile() { return p->zipFile_f; }
602 
604  p->dataDescriptorWritingEnabled = enabled;
605 }
606 
608  return p->dataDescriptorWritingEnabled;
609 }
610 
611 template <typename TFileInfo>
612 TFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok);
613 
614 template <>
616  QuaZipFileInfo info;
617  *ok = zip->getCurrentFileInfo(&info);
618  return info;
619 }
620 
621 template <>
623  QuaZipFileInfo64 info;
624  *ok = zip->getCurrentFileInfo(&info);
625  return info;
626 }
627 
628 template <>
629 QString QuaZip_getFileInfo(QuaZip *zip, bool *ok) {
630  QString name = zip->getCurrentFileName();
631  *ok = !name.isEmpty();
632  return name;
633 }
634 
635 template <typename TFileInfo>
636 bool QuaZipPrivate::getFileInfoList(QList<TFileInfo> *result) const {
637  QuaZipPrivate *fakeThis = const_cast<QuaZipPrivate *>(this);
638  fakeThis->zipError = UNZ_OK;
639  if (mode != QuaZip::mdUnzip) {
640  qWarning(
641  "QuaZip::getFileNameList/getFileInfoList(): "
642  "ZIP is not open in mdUnzip mode");
643  return false;
644  }
645  QString currentFile;
646  if (q->hasCurrentFile()) {
647  currentFile = q->getCurrentFileName();
648  }
649  if (q->goToFirstFile()) {
650  do {
651  bool ok;
652  result->append(QuaZip_getFileInfo<TFileInfo>(q, &ok));
653  if (!ok) return false;
654  } while (q->goToNextFile());
655  }
656  if (zipError != UNZ_OK) return false;
657  if (currentFile.isEmpty()) {
658  if (!q->goToFirstFile()) return false;
659  } else {
660  if (!q->setCurrentFile(currentFile)) return false;
661  }
662  return true;
663 }
664 
665 QStringList QuaZip::getFileNameList() const {
666  QStringList list;
667  if (p->getFileInfoList(&list))
668  return list;
669  else
670  return QStringList();
671 }
672 
673 QList<QuaZipFileInfo> QuaZip::getFileInfoList() const {
674  QList<QuaZipFileInfo> list;
675  if (p->getFileInfoList(&list))
676  return list;
677  else
678  return QList<QuaZipFileInfo>();
679 }
680 
681 QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const {
682  QList<QuaZipFileInfo64> list;
683  if (p->getFileInfoList(&list))
684  return list;
685  else
686  return QList<QuaZipFileInfo64>();
687 }
688 
690  if (cs == csDefault) {
691 #ifdef Q_OS_WIN
692  return Qt::CaseInsensitive;
693 #else
694  return Qt::CaseSensitive;
695 #endif
696  } else {
697  return cs == csSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
698  }
699 }
700 
702  QuaZipPrivate::defaultFileNameCodec = codec;
703 }
704 
705 void QuaZip::setDefaultFileNameCodec(const char *codecName) {
707 }
708 
709 void QuaZip::setZip64Enabled(bool zip64) { p->zip64 = zip64; }
710 
711 bool QuaZip::isZip64Enabled() const { return p->zip64; }
712 
713 bool QuaZip::isAutoClose() const { return p->autoClose; }
714 
715 void QuaZip::setAutoClose(bool autoClose) const { p->autoClose = autoClose; }
std::string name
#define NULL
core::Tensor result
Definition: VtkUtils.cpp:76
static QTextCodec * codecForName(const char *name)
Definition: quazip.h:50
static QTextCodec * codecForLocale()
Definition: quazip.h:44
ZIP archive.
Definition: quazip.h:128
QString getZipName() const
Returns the name of the ZIP file.
Definition: quazip.cpp:581
int getEntriesCount() const
Returns number of the entries in the ZIP central directory.
Definition: quazip.cpp:364
void setComment(const QString &comment)
Sets the global comment in the ZIP file.
Definition: quazip.cpp:595
void setCommentCodec(QTextCodec *commentCodec)
Sets the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:571
static Qt::CaseSensitivity convertCaseSensitivity(CaseSensitivity cs)
Returns the actual case sensitivity for the specified QuaZIP one.
Definition: quazip.cpp:689
bool isAutoClose() const
Returns the auto-close flag.
Definition: quazip.cpp:713
bool isDataDescriptorWritingEnabled() const
Returns the data descriptor default writing mode.
Definition: quazip.cpp:607
QStringList getFileNameList() const
Returns a list of files inside the archive.
Definition: quazip.cpp:665
static void setDefaultFileNameCodec(QTextCodec *codec)
Sets the default file name codec to use.
Definition: quazip.cpp:701
void setFileNameCodec(QTextCodec *fileNameCodec)
Sets the codec used to encode/decode file names inside archive.
Definition: quazip.cpp:561
QTextCodec * getCommentCodec() const
Returns the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:579
unzFile getUnzFile()
Returns unzFile handle.
Definition: quazip.cpp:599
zipFile getZipFile()
Returns zipFile handle.
Definition: quazip.cpp:601
void setAutoClose(bool autoClose) const
Sets or unsets the auto-close flag.
Definition: quazip.cpp:715
Mode
Open mode of the ZIP file.
Definition: quazip.h:139
@ mdAdd
ZIP file was opened for adding files in the archive.
Definition: quazip.h:151
@ mdCreate
ZIP file was created with open() call.
Definition: quazip.h:142
@ mdUnzip
ZIP file is open for reading files inside it.
Definition: quazip.h:141
@ mdAppend
Definition: quazip.h:143
@ mdNotOpen
ZIP file is not open. This is the initial mode.
Definition: quazip.h:140
QString getComment() const
Returns global comment in the ZIP file.
Definition: quazip.cpp:378
Mode getMode() const
Returns the mode in which ZIP file was opened.
Definition: quazip.cpp:589
CaseSensitivity
Case sensitivity for the file names.
Definition: quazip.h:159
@ csDefault
Definition: quazip.h:160
@ csSensitive
Case sensitive.
Definition: quazip.h:162
void setIoDevice(QIODevice *ioDevice)
Sets the device representing the ZIP file.
Definition: quazip.cpp:355
void setDataDescriptorWritingEnabled(bool enabled)
Changes the data descriptor writing mode.
Definition: quazip.cpp:603
bool setCurrentFile(const QString &fileName, CaseSensitivity cs=csDefault)
Sets current file by its name.
Definition: quazip.cpp:398
bool goToFirstFile()
Sets the current file to the first file in the archive.
Definition: quazip.cpp:454
void close()
Closes ZIP file.
Definition: quazip.cpp:314
QList< QuaZipFileInfo > getFileInfoList() const
Returns information list about all files inside the archive.
Definition: quazip.cpp:673
QIODevice * getIoDevice() const
Returns the device representing this ZIP file.
Definition: quazip.cpp:583
QuaZip()
Constructs QuaZip object.
Definition: quazip.cpp:197
QString getCurrentFileName() const
Returns the current file name.
Definition: quazip.cpp:539
bool isZip64Enabled() const
Returns whether the zip64 mode is enabled.
Definition: quazip.cpp:711
void setZipName(const QString &zipName)
Sets the name of the ZIP file.
Definition: quazip.cpp:346
QTextCodec * getFileNameCodec() const
Returns the codec used to encode/decode comments inside archive.
Definition: quazip.cpp:569
int getZipError() const
Returns the error code of the last operation.
Definition: quazip.cpp:593
void setZip64Enabled(bool zip64)
Enables the zip64 mode.
Definition: quazip.cpp:709
bool open(Mode mode, zlib_filefunc_def *ioApi=NULL)
Opens ZIP file.
Definition: quazip.cpp:208
QList< QuaZipFileInfo64 > getFileInfoList64() const
Returns information list about all files inside the archive.
Definition: quazip.cpp:681
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.
Definition: quazip.cpp:477
@ MAX_FILE_NAME_LENGTH
Definition: quazip.h:134
bool isOpen() const
Returns true if ZIP file is open, false otherwise.
Definition: quazip.cpp:591
bool goToNextFile()
Sets the current file to the next file in the archive.
Definition: quazip.cpp:465
bool hasCurrentFile() const
Returns true if the current file has been set.
Definition: quazip.cpp:597
~QuaZip()
Destroys QuaZip object.
Definition: quazip.cpp:203
constexpr QRegularExpression::PatternOption CaseInsensitive
Definition: QtCompat.h:174
TFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok)
Definition: quazip.cpp:615
#define UNZ_OPENERROR
Definition: quazip.h:85
Information about a file inside archive (with zip64 support).
quint16 versionNeeded
Version needed to extract.
QString name
File name.
quint32 externalAttr
External file attributes.
quint16 method
Compression method.
QDateTime dateTime
Last modification date and time.
quint64 uncompressedSize
Uncompressed file size.
quint16 flags
General purpose flags.
quint16 versionCreated
Version created by.
bool toQuaZipFileInfo(QuaZipFileInfo &info) const
Converts to QuaZipFileInfo.
QString comment
Comment.
quint16 diskNumberStart
Disk number start.
QByteArray extra
Extra field.
quint64 compressedSize
Compressed file size.
quint16 internalAttr
Internal file attributes.
Information about a file inside archive.
uInt tm_mon
Definition: unzip.h:101
uInt tm_mday
Definition: unzip.h:100
uInt tm_year
Definition: unzip.h:102
uInt tm_sec
Definition: unzip.h:97
uInt tm_min
Definition: unzip.h:98
uInt tm_hour
Definition: unzip.h:99
ZPOS64_T pos_in_zip_directory
Definition: unzip.h:280
uLong size_file_extra
Definition: unzip.h:130
uLong internal_fa
Definition: unzip.h:134
uLong version
Definition: unzip.h:121
ZPOS64_T uncompressed_size
Definition: unzip.h:128
tm_unz tmu_date
Definition: unzip.h:137
uLong size_filename
Definition: unzip.h:129
uLong compression_method
Definition: unzip.h:124
uLong external_fa
Definition: unzip.h:135
uLong version_needed
Definition: unzip.h:122
uLong disk_num_start
Definition: unzip.h:133
ZPOS64_T compressed_size
Definition: unzip.h:127
uLong size_file_comment
Definition: unzip.h:131
ZPOS64_T number_entry
Definition: unzip.h:108
uLong size_comment
Definition: unzip.h:110
unzFile ZEXPORT unzOpen2(voidpf file, zlib_filefunc_def *pzlib_filefunc32_def)
Definition: unzip.c:772
int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
Definition: unzip.c:1318
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
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1188
int ZEXPORT unzClearFlags(unzFile file, unsigned flags)
Definition: unzip.c:2139
int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos)
Definition: unzip.c:1348
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:838
int ZEXPORT unzSetFlags(unzFile file, unsigned flags)
Definition: unzip.c:2128
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1209
int ZEXPORT unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf)
Definition: unzip.c:2051
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:815
#define UNZ_AUTO_CLOSE
Definition: unzip.h:92
#define UNZ_END_OF_LIST_OF_FILE
Definition: unzip.h:84
#define UNZ_PARAMERROR
Definition: unzip.h:87
voidp unzFile
Definition: unzip.h:80
#define UNZ_OK
Definition: unzip.h:83
int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1936
zipFile ZEXPORT zipOpen2(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc32_def)
Definition: zip.c:939
int ZEXPORT zipSetFlags(zipFile file, unsigned flags)
Definition: zip.c:2071
zipFile ZEXPORT zipOpen3(voidpf file, int append, zipcharpc *globalcomment, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, unsigned flags)
Definition: zip.c:862
#define ZIP_AUTO_CLOSE
Definition: zip.h:91
#define ZIP_SEQUENTIAL
Definition: zip.h:92
#define APPEND_STATUS_ADDINZIP
Definition: zip.h:128
#define ZIP_WRITE_DATA_DESCRIPTOR
Definition: zip.h:90
#define APPEND_STATUS_CREATEAFTER
Definition: zip.h:127
#define APPEND_STATUS_CREATE
Definition: zip.h:126
voidp zipFile
Definition: zip.h:80