ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
quazip.h
Go to the documentation of this file.
1 #ifndef QUA_ZIP_H
2 #define QUA_ZIP_H
3 
4 /*
5 Copyright (C) 2005-2014 Sergey A. Tachenov
6 
7 This file is part of QuaZIP.
8 
9 QuaZIP is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 QuaZIP is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
21 
22 See COPYING file for the full LGPL text.
23 
24 Original ZIP package is copyrighted by Gilles Vollant, see
25 quazip/(un)zip.h files for details, basically it's zlib license.
26  **/
27 
28 #include <QString>
29 #include <QStringList>
30 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
31 // Use project's QtCompat.h for QTextCodec compatibility
32 #include <QtCompat.h>
33 #include <QHash>
34 // QTextCodec compatibility wrapper using QtCompat's implementation
35 // This wrapper delegates to QtCompatTextCodec from QtCompat.h
36 class QTextCodec {
37 private:
38  QtCompatTextCodec* m_codec;
39 
40  // Private constructor - use static factory methods
41  QTextCodec(QtCompatTextCodec* codec) : m_codec(codec) {}
42 
43 public:
45  // QtCompat returns static instances, so we can safely wrap them
46  static QTextCodec* instance = new QTextCodec(qtCompatCodecForLocale());
47  return instance;
48  }
49 
50  static QTextCodec* codecForName(const char* name) {
51  // QtCompat returns static instances, so we can safely wrap them
52  // Use QtCompat's codecForName to get the appropriate codec
53  static QHash<QString, QTextCodec*> codecCache;
54  QString key = name ? QString::fromLatin1(name) : QString();
55  if (!codecCache.contains(key)) {
56  codecCache[key] = new QTextCodec(qtCompatCodecForName(name));
57  }
58  return codecCache[key];
59  }
60 
61  QByteArray fromUnicode(const QString& str) const {
62  return m_codec->fromUnicode(str);
63  }
64 
65  QString toUnicode(const QByteArray& ba) const {
66  return m_codec->toUnicode(ba);
67  }
68 
69  QString toUnicode(const char* chars, int len = -1) const {
70  return m_codec->toUnicode(chars, len);
71  }
72 };
73 #else
74 #include <QTextCodec>
75 #endif
76 
77 #include "quazip_global.h"
78 #include "quazipfileinfo.h"
79 #include "unzip.h"
80 #include "zip.h"
81 
82 // just in case it will be defined in the later versions of the ZIP/UNZIP
83 #ifndef UNZ_OPENERROR
84 // define additional error code
85 #define UNZ_OPENERROR -1000
86 #endif
87 
88 class QuaZipPrivate;
89 
91 
129  friend class QuaZipPrivate;
130 
131 public:
133  enum Constants {
134  MAX_FILE_NAME_LENGTH = 256
137  };
139  enum Mode {
143  mdAppend,
151  mdAdd
152  };
154 
160  csDefault = 0,
162  csSensitive = 1,
163  csInsensitive = 2
164  };
166 
172  static Qt::CaseSensitivity convertCaseSensitivity(CaseSensitivity cs);
173 
174 private:
175  QuaZipPrivate* p;
176  // not (and will not be) implemented
177  QuaZip(const QuaZip& that);
178  // not (and will not be) implemented
179  QuaZip& operator=(const QuaZip& that);
180 
181 public:
183 
184  QuaZip();
186  QuaZip(const QString& zipName);
189 
191  QuaZip(QIODevice* ioDevice);
193 
194  ~QuaZip();
196 
242  bool open(Mode mode, zlib_filefunc_def* ioApi = NULL);
244 
266  void close();
268 
273  void setFileNameCodec(QTextCodec* fileNameCodec);
275 
279  void setFileNameCodec(const char* fileNameCodecName);
281  QTextCodec* getFileNameCodec() const;
283 
285  void setCommentCodec(QTextCodec* commentCodec);
287 
291  void setCommentCodec(const char* commentCodecName);
293  QTextCodec* getCommentCodec() const;
295 
300  QString getZipName() const;
302 
307  void setZipName(const QString& zipName);
309 
313  QIODevice* getIoDevice() const;
315 
320  void setIoDevice(QIODevice* ioDevice);
322  Mode getMode() const;
324  bool isOpen() const;
326 
334  int getZipError() const;
336 
339  int getEntriesCount() const;
341  QString getComment() const;
343 
351  void setComment(const QString& comment);
353 
356  bool goToFirstFile();
358 
375  bool goToNextFile();
377 
401  bool setCurrentFile(const QString& fileName,
402  CaseSensitivity cs = csDefault);
404  bool hasCurrentFile() const;
406 
427  bool getCurrentFileInfo(QuaZipFileInfo* info) const;
429 
437  bool getCurrentFileInfo(QuaZipFileInfo64* info) const;
439 
445  QString getCurrentFileName() const;
447 
462  unzFile getUnzFile();
464 
468  zipFile getZipFile();
470 
497  void setDataDescriptorWritingEnabled(bool enabled);
499 
502  bool isDataDescriptorWritingEnabled() const;
504 
510  QStringList getFileNameList() const;
512 
524  QList<QuaZipFileInfo> getFileInfoList() const;
526 
534  QList<QuaZipFileInfo64> getFileInfoList64() const;
536 
549  void setZip64Enabled(bool zip64);
551 
556  bool isZip64Enabled() const;
558 
561  bool isAutoClose() const;
563 
583  void setAutoClose(bool autoClose) const;
585 
614  static void setDefaultFileNameCodec(QTextCodec* codec);
620  static void setDefaultFileNameCodec(const char* codecName);
621 };
622 
623 #endif
std::string name
QtCompatTextCodec * qtCompatCodecForName(const char *name)
Definition: QtCompat.h:657
QtCompatTextCodec * qtCompatCodecForLocale()
Definition: QtCompat.h:650
#define NULL
QString toUnicode(const QByteArray &ba) const
Definition: quazip.h:65
QByteArray fromUnicode(const QString &str) const
Definition: quazip.h:61
static QTextCodec * codecForName(const char *name)
Definition: quazip.h:50
QString toUnicode(const char *chars, int len=-1) const
Definition: quazip.h:69
static QTextCodec * codecForLocale()
Definition: quazip.h:44
QString toUnicode(const char *chars, int len=-1)
Definition: QtCompat.h:610
QByteArray fromUnicode(const QString &str)
Definition: QtCompat.h:594
ZIP archive.
Definition: quazip.h:128
Mode
Open mode of the ZIP file.
Definition: quazip.h:139
@ 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
@ mdNotOpen
ZIP file is not open. This is the initial mode.
Definition: quazip.h:140
CaseSensitivity
Case sensitivity for the file names.
Definition: quazip.h:159
Constants
Useful constants.
Definition: quazip.h:133
#define QUAZIP_EXPORT
Definition: quazip_global.h:46
#define isOpen(pFd)
Definition: sqlite3.c:52420
Information about a file inside archive (with zip64 support).
Information about a file inside archive.
voidp unzFile
Definition: unzip.h:80
voidp zipFile
Definition: zip.h:80