quazip.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. #ifndef QUA_ZIP_H
  2. #define QUA_ZIP_H
  3. /*
  4. Copyright (C) 2005-2014 Sergey A. Tachenov
  5. This file is part of QuaZIP.
  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. QuaZIP is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
  16. See COPYING file for the full LGPL text.
  17. Original ZIP package is copyrighted by Gilles Vollant, see
  18. quazip/(un)zip.h files for details, basically it's zlib license.
  19. **/
  20. #include <QString>
  21. #include <QStringList>
  22. #include <QTextCodec>
  23. #include "zip.h"
  24. #include "unzip.h"
  25. #include "quazip_global.h"
  26. #include "quazipfileinfo.h"
  27. // just in case it will be defined in the later versions of the ZIP/UNZIP
  28. #ifndef UNZ_OPENERROR
  29. // define additional error code
  30. #define UNZ_OPENERROR -1000
  31. #endif
  32. class QuaZipPrivate;
  33. /// ZIP archive.
  34. /** \class QuaZip quazip.h <quazip/quazip.h>
  35. * This class implements basic interface to the ZIP archive. It can be
  36. * used to read table contents of the ZIP archive and retreiving
  37. * information about the files inside it.
  38. *
  39. * You can also use this class to open files inside archive by passing
  40. * pointer to the instance of this class to the constructor of the
  41. * QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*)
  42. * for the possible pitfalls.
  43. *
  44. * This class is indended to provide interface to the ZIP subpackage of
  45. * the ZIP/UNZIP package as well as to the UNZIP subpackage. But
  46. * currently it supports only UNZIP.
  47. *
  48. * The use of this class is simple - just create instance using
  49. * constructor, then set ZIP archive file name using setFile() function
  50. * (if you did not passed the name to the constructor), then open() and
  51. * then use different functions to work with it! Well, if you are
  52. * paranoid, you may also wish to call close before destructing the
  53. * instance, to check for errors on close.
  54. *
  55. * You may also use getUnzFile() and getZipFile() functions to get the
  56. * ZIP archive handle and use it with ZIP/UNZIP package API directly.
  57. *
  58. * This class supports localized file names inside ZIP archive, but you
  59. * have to set up proper codec with setCodec() function. By default,
  60. * locale codec will be used, which is probably ok for UNIX systems, but
  61. * will almost certainly fail with ZIP archives created in Windows. This
  62. * is because Windows ZIP programs have strange habit of using DOS
  63. * encoding for file names in ZIP archives. For example, ZIP archive
  64. * with cyrillic names created in Windows will have file names in \c
  65. * IBM866 encoding instead of \c WINDOWS-1251. I think that calling one
  66. * function is not much trouble, but for true platform independency it
  67. * would be nice to have some mechanism for file name encoding auto
  68. * detection using locale information. Does anyone know a good way to do
  69. * it?
  70. **/
  71. class QUAZIP_EXPORT QuaZip {
  72. friend class QuaZipPrivate;
  73. public:
  74. /// Useful constants.
  75. enum Constants {
  76. MAX_FILE_NAME_LENGTH=256 /**< Maximum file name length. Taken from
  77. \c UNZ_MAXFILENAMEINZIP constant in
  78. unzip.c. */
  79. };
  80. /// Open mode of the ZIP file.
  81. enum Mode {
  82. mdNotOpen, ///< ZIP file is not open. This is the initial mode.
  83. mdUnzip, ///< ZIP file is open for reading files inside it.
  84. mdCreate, ///< ZIP file was created with open() call.
  85. mdAppend, /**< ZIP file was opened in append mode. This refers to
  86. * \c APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package
  87. * and means that zip is appended to some existing file
  88. * what is useful when that file contains
  89. * self-extractor code. This is obviously \em not what
  90. * you whant to use to add files to the existing ZIP
  91. * archive.
  92. **/
  93. mdAdd ///< ZIP file was opened for adding files in the archive.
  94. };
  95. /// Case sensitivity for the file names.
  96. /** This is what you specify when accessing files in the archive.
  97. * Works perfectly fine with any characters thanks to Qt's great
  98. * unicode support. This is different from ZIP/UNZIP API, where
  99. * only US-ASCII characters was supported.
  100. **/
  101. enum CaseSensitivity {
  102. csDefault=0, ///< Default for platform. Case sensitive for UNIX, not for Windows.
  103. csSensitive=1, ///< Case sensitive.
  104. csInsensitive=2 ///< Case insensitive.
  105. };
  106. /// Returns the actual case sensitivity for the specified QuaZIP one.
  107. /**
  108. \param cs The value to convert.
  109. \returns If CaseSensitivity::csDefault, then returns the default
  110. file name case sensitivity for the platform. Otherwise, just
  111. returns the appropriate value from the Qt::CaseSensitivity enum.
  112. */
  113. static Qt::CaseSensitivity convertCaseSensitivity(
  114. CaseSensitivity cs);
  115. private:
  116. QuaZipPrivate *p;
  117. // not (and will not be) implemented
  118. QuaZip(const QuaZip& that);
  119. // not (and will not be) implemented
  120. QuaZip& operator=(const QuaZip& that);
  121. public:
  122. /// Constructs QuaZip object.
  123. /** Call setName() before opening constructed object. */
  124. QuaZip();
  125. /// Constructs QuaZip object associated with ZIP file \a zipName.
  126. QuaZip(const QString& zipName);
  127. /// Constructs QuaZip object associated with ZIP file represented by \a ioDevice.
  128. /** The IO device must be seekable, otherwise an error will occur when opening. */
  129. QuaZip(QIODevice *ioDevice);
  130. /// Destroys QuaZip object.
  131. /** Calls close() if necessary. */
  132. ~QuaZip();
  133. /// Opens ZIP file.
  134. /**
  135. * Argument \a mode specifies open mode of the ZIP archive. See Mode
  136. * for details. Note that there is zipOpen2() function in the
  137. * ZIP/UNZIP API which accepts \a globalcomment argument, but it
  138. * does not use it anywhere, so this open() function does not have this
  139. * argument. See setComment() if you need to set global comment.
  140. *
  141. * If the ZIP file is accessed via explicitly set QIODevice, then
  142. * this device is opened in the necessary mode. If the device was
  143. * already opened by some other means, then QuaZIP checks if the
  144. * open mode is compatible to the mode needed for the requested operation.
  145. * If necessary, seeking is performed to position the device properly.
  146. *
  147. * \return \c true if successful, \c false otherwise.
  148. *
  149. * \note ZIP/UNZIP API open calls do not return error code - they
  150. * just return \c NULL indicating an error. But to make things
  151. * easier, quazip.h header defines additional error code \c
  152. * UNZ_ERROROPEN and getZipError() will return it if the open call
  153. * of the ZIP/UNZIP API returns \c NULL.
  154. *
  155. * Argument \a ioApi specifies IO function set for ZIP/UNZIP
  156. * package to use. See unzip.h, zip.h and ioapi.h for details. Note
  157. * that IO API for QuaZip is different from the original package.
  158. * The file path argument was changed to be of type \c voidpf, and
  159. * QuaZip passes a QIODevice pointer there. This QIODevice is either
  160. * set explicitly via setIoDevice() or the QuaZip(QIODevice*)
  161. * constructor, or it is created internally when opening the archive
  162. * by its file name. The default API (qioapi.cpp) just delegates
  163. * everything to the QIODevice API. Not only this allows to use a
  164. * QIODevice instead of file name, but also has a nice side effect
  165. * of raising the file size limit from 2G to 4G (in non-zip64 archives).
  166. *
  167. * \note If the zip64 support is needed, the ioApi argument \em must be NULL
  168. * because due to the backwards compatibility issues it can be used to
  169. * provide a 32-bit API only.
  170. *
  171. * \note If the \ref QuaZip::setAutoClose() "no-auto-close" feature is used,
  172. * then the \a ioApi argument \em should be NULL because the old API
  173. * doesn't support the 'fake close' operation, causing slight memory leaks
  174. * and other possible troubles (like closing the output device in case
  175. * when an error occurs during opening).
  176. *
  177. * In short: just forget about the \a ioApi argument and you'll be
  178. * fine.
  179. **/
  180. bool open(Mode mode, zlib_filefunc_def *ioApi =NULL);
  181. /// Closes ZIP file.
  182. /** Call getZipError() to determine if the close was successful.
  183. *
  184. * If the file was opened by name, then the underlying QIODevice is closed
  185. * and deleted.
  186. *
  187. * If the underlying QIODevice was set explicitly using setIoDevice() or
  188. * the appropriate constructor, then it is closed if the auto-close flag
  189. * is set (which it is by default). Call setAutoClose() to clear the
  190. * auto-close flag if this behavior is undesirable.
  191. *
  192. * Since Qt 5.1, the QSaveFile was introduced. It breaks the QIODevice API
  193. * by making close() private and crashing the application if it is called
  194. * from the base class where it is public. It is an excellent example
  195. * of poor design that illustrates why you should never ever break
  196. * an is-a relationship between the base class and a subclass. QuaZIP
  197. * works around this bug by checking if the QIODevice is an instance
  198. * of QSaveFile, using qobject_cast<>, and if it is, calls
  199. * QSaveFile::commit() instead of close(). It is a really ugly hack,
  200. * but at least it makes your programs work instead of crashing. Note that
  201. * if the auto-close flag is cleared, then this is a non-issue, and
  202. * commit() isn't called.
  203. */
  204. void close();
  205. /// Sets the codec used to encode/decode file names inside archive.
  206. /** This is necessary to access files in the ZIP archive created
  207. * under Windows with non-latin characters in file names. For
  208. * example, file names with cyrillic letters will be in \c IBM866
  209. * encoding.
  210. **/
  211. void setFileNameCodec(QTextCodec *fileNameCodec);
  212. /// Sets the codec used to encode/decode file names inside archive.
  213. /** \overload
  214. * Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
  215. **/
  216. void setFileNameCodec(const char *fileNameCodecName);
  217. /// Returns the codec used to encode/decode comments inside archive.
  218. QTextCodec* getFileNameCodec() const;
  219. /// Sets the codec used to encode/decode comments inside archive.
  220. /** This codec defaults to locale codec, which is probably ok.
  221. **/
  222. void setCommentCodec(QTextCodec *commentCodec);
  223. /// Sets the codec used to encode/decode comments inside archive.
  224. /** \overload
  225. * Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
  226. **/
  227. void setCommentCodec(const char *commentCodecName);
  228. /// Returns the codec used to encode/decode comments inside archive.
  229. QTextCodec* getCommentCodec() const;
  230. /// Returns the name of the ZIP file.
  231. /** Returns null string if no ZIP file name has been set, for
  232. * example when the QuaZip instance is set up to use a QIODevice
  233. * instead.
  234. * \sa setZipName(), setIoDevice(), getIoDevice()
  235. **/
  236. QString getZipName() const;
  237. /// Sets the name of the ZIP file.
  238. /** Does nothing if the ZIP file is open.
  239. *
  240. * Does not reset error code returned by getZipError().
  241. * \sa setIoDevice(), getIoDevice(), getZipName()
  242. **/
  243. void setZipName(const QString& zipName);
  244. /// Returns the device representing this ZIP file.
  245. /** Returns null string if no device has been set explicitly, for
  246. * example when opening a ZIP file by name.
  247. * \sa setIoDevice(), getZipName(), setZipName()
  248. **/
  249. QIODevice *getIoDevice() const;
  250. /// Sets the device representing the ZIP file.
  251. /** Does nothing if the ZIP file is open.
  252. *
  253. * Does not reset error code returned by getZipError().
  254. * \sa getIoDevice(), getZipName(), setZipName()
  255. **/
  256. void setIoDevice(QIODevice *ioDevice);
  257. /// Returns the mode in which ZIP file was opened.
  258. Mode getMode() const;
  259. /// Returns \c true if ZIP file is open, \c false otherwise.
  260. bool isOpen() const;
  261. /// Returns the error code of the last operation.
  262. /** Returns \c UNZ_OK if the last operation was successful.
  263. *
  264. * Error code resets to \c UNZ_OK every time you call any function
  265. * that accesses something inside ZIP archive, even if it is \c
  266. * const (like getEntriesCount()). open() and close() calls reset
  267. * error code too. See documentation for the specific functions for
  268. * details on error detection.
  269. **/
  270. int getZipError() const;
  271. /// Returns number of the entries in the ZIP central directory.
  272. /** Returns negative error code in the case of error. The same error
  273. * code will be returned by subsequent getZipError() call.
  274. **/
  275. int getEntriesCount() const;
  276. /// Returns global comment in the ZIP file.
  277. QString getComment() const;
  278. /// Sets the global comment in the ZIP file.
  279. /** The comment will be written to the archive on close operation.
  280. * QuaZip makes a distinction between a null QByteArray() comment
  281. * and an empty &quot;&quot; comment in the QuaZip::mdAdd mode.
  282. * A null comment is the default and it means &quot;don't change
  283. * the comment&quot;. An empty comment removes the original comment.
  284. *
  285. * \sa open()
  286. **/
  287. void setComment(const QString& comment);
  288. /// Sets the current file to the first file in the archive.
  289. /** Returns \c true on success, \c false otherwise. Call
  290. * getZipError() to get the error code.
  291. **/
  292. bool goToFirstFile();
  293. /// Sets the current file to the next file in the archive.
  294. /** Returns \c true on success, \c false otherwise. Call
  295. * getZipError() to determine if there was an error.
  296. *
  297. * Should be used only in QuaZip::mdUnzip mode.
  298. *
  299. * \note If the end of file was reached, getZipError() will return
  300. * \c UNZ_OK instead of \c UNZ_END_OF_LIST_OF_FILE. This is to make
  301. * things like this easier:
  302. * \code
  303. * for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
  304. * // do something
  305. * }
  306. * if(zip.getZipError()==UNZ_OK) {
  307. * // ok, there was no error
  308. * }
  309. * \endcode
  310. **/
  311. bool goToNextFile();
  312. /// Sets current file by its name.
  313. /** Returns \c true if successful, \c false otherwise. Argument \a
  314. * cs specifies case sensitivity of the file name. Call
  315. * getZipError() in the case of a failure to get error code.
  316. *
  317. * This is not a wrapper to unzLocateFile() function. That is
  318. * because I had to implement locale-specific case-insensitive
  319. * comparison.
  320. *
  321. * Here are the differences from the original implementation:
  322. *
  323. * - If the file was not found, error code is \c UNZ_OK, not \c
  324. * UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()).
  325. * - If this function fails, it unsets the current file rather than
  326. * resetting it back to what it was before the call.
  327. *
  328. * If \a fileName is null string then this function unsets the
  329. * current file and return \c true. Note that you should close the
  330. * file first if it is open! See
  331. * QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.
  332. *
  333. * Should be used only in QuaZip::mdUnzip mode.
  334. *
  335. * \sa setFileNameCodec(), CaseSensitivity
  336. **/
  337. bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
  338. /// Returns \c true if the current file has been set.
  339. bool hasCurrentFile() const;
  340. /// Retrieves information about the current file.
  341. /** Fills the structure pointed by \a info. Returns \c true on
  342. * success, \c false otherwise. In the latter case structure pointed
  343. * by \a info remains untouched. If there was an error,
  344. * getZipError() returns error code.
  345. *
  346. * Should be used only in QuaZip::mdUnzip mode.
  347. *
  348. * Does nothing and returns \c false in any of the following cases.
  349. * - ZIP is not open;
  350. * - ZIP does not have current file.
  351. *
  352. * In both cases getZipError() returns \c UNZ_OK since there
  353. * is no ZIP/UNZIP API call.
  354. *
  355. * This overload doesn't support zip64, but will work OK on zip64 archives
  356. * except that if one of the sizes (compressed or uncompressed) is greater
  357. * than 0xFFFFFFFFu, it will be set to exactly 0xFFFFFFFFu.
  358. *
  359. * \sa getCurrentFileInfo(QuaZipFileInfo64* info)const
  360. * \sa QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo&)const
  361. **/
  362. bool getCurrentFileInfo(QuaZipFileInfo* info)const;
  363. /// Retrieves information about the current file.
  364. /** \overload
  365. *
  366. * This function supports zip64. If the archive doesn't use zip64, it is
  367. * completely equivalent to getCurrentFileInfo(QuaZipFileInfo* info)
  368. * except for the argument type.
  369. *
  370. * \sa
  371. **/
  372. bool getCurrentFileInfo(QuaZipFileInfo64* info)const;
  373. /// Returns the current file name.
  374. /** Equivalent to calling getCurrentFileInfo() and then getting \c
  375. * name field of the QuaZipFileInfo structure, but faster and more
  376. * convenient.
  377. *
  378. * Should be used only in QuaZip::mdUnzip mode.
  379. **/
  380. QString getCurrentFileName()const;
  381. /// Returns \c unzFile handle.
  382. /** You can use this handle to directly call UNZIP part of the
  383. * ZIP/UNZIP package functions (see unzip.h).
  384. *
  385. * \warning When using the handle returned by this function, please
  386. * keep in mind that QuaZip class is unable to detect any changes
  387. * you make in the ZIP file state (e. g. changing current file, or
  388. * closing the handle). So please do not do anything with this
  389. * handle that is possible to do with the functions of this class.
  390. * Or at least return the handle in the original state before
  391. * calling some another function of this class (including implicit
  392. * destructor calls and calls from the QuaZipFile objects that refer
  393. * to this QuaZip instance!). So if you have changed the current
  394. * file in the ZIP archive - then change it back or you may
  395. * experience some strange behavior or even crashes.
  396. **/
  397. unzFile getUnzFile();
  398. /// Returns \c zipFile handle.
  399. /** You can use this handle to directly call ZIP part of the
  400. * ZIP/UNZIP package functions (see zip.h). Warnings about the
  401. * getUnzFile() function also apply to this function.
  402. **/
  403. zipFile getZipFile();
  404. /// Changes the data descriptor writing mode.
  405. /**
  406. According to the ZIP format specification, a file inside archive
  407. may have a data descriptor immediately following the file
  408. data. This is reflected by a special flag in the local file header
  409. and in the central directory. By default, QuaZIP sets this flag
  410. and writes the data descriptor unless both method and level were
  411. set to 0, in which case it operates in 1.0-compatible mode and
  412. never writes data descriptors.
  413. By setting this flag to false, it is possible to disable data
  414. descriptor writing, thus increasing compatibility with archive
  415. readers that don't understand this feature of the ZIP file format.
  416. Setting this flag affects all the QuaZipFile instances that are
  417. opened after this flag is set.
  418. The data descriptor writing mode is enabled by default.
  419. Note that if the ZIP archive is written into a QIODevice for which
  420. QIODevice::isSequential() returns \c true, then the data descriptor
  421. is mandatory and will be written even if this flag is set to false.
  422. \param enabled If \c true, enable local descriptor writing,
  423. disable it otherwise.
  424. \sa QuaZipFile::isDataDescriptorWritingEnabled()
  425. */
  426. void setDataDescriptorWritingEnabled(bool enabled);
  427. /// Returns the data descriptor default writing mode.
  428. /**
  429. \sa setDataDescriptorWritingEnabled()
  430. */
  431. bool isDataDescriptorWritingEnabled() const;
  432. /// Returns a list of files inside the archive.
  433. /**
  434. \return A list of file names or an empty list if there
  435. was an error or if the archive is empty (call getZipError() to
  436. figure out which).
  437. \sa getFileInfoList()
  438. */
  439. QStringList getFileNameList() const;
  440. /// Returns information list about all files inside the archive.
  441. /**
  442. \return A list of QuaZipFileInfo objects or an empty list if there
  443. was an error or if the archive is empty (call getZipError() to
  444. figure out which).
  445. This function doesn't support zip64, but will still work with zip64
  446. archives, converting results using QuaZipFileInfo64::toQuaZipFileInfo().
  447. If all file sizes are below 4 GB, it will work just fine.
  448. \sa getFileNameList()
  449. \sa getFileInfoList64()
  450. */
  451. QList<QuaZipFileInfo> getFileInfoList() const;
  452. /// Returns information list about all files inside the archive.
  453. /**
  454. \overload
  455. This function supports zip64.
  456. \sa getFileNameList()
  457. \sa getFileInfoList()
  458. */
  459. QList<QuaZipFileInfo64> getFileInfoList64() const;
  460. /// Enables the zip64 mode.
  461. /**
  462. * @param zip64 If \c true, the zip64 mode is enabled, disabled otherwise.
  463. *
  464. * Once this is enabled, all new files (until the mode is disabled again)
  465. * will be created in the zip64 mode, thus enabling the ability to write
  466. * files larger than 4 GB. By default, the zip64 mode is off due to
  467. * compatibility reasons.
  468. *
  469. * Note that this does not affect the ability to read zip64 archives in any
  470. * way.
  471. *
  472. * \sa isZip64Enabled()
  473. */
  474. void setZip64Enabled(bool zip64);
  475. /// Returns whether the zip64 mode is enabled.
  476. /**
  477. * @return \c true if and only if the zip64 mode is enabled.
  478. *
  479. * \sa setZip64Enabled()
  480. */
  481. bool isZip64Enabled() const;
  482. /// Returns the auto-close flag.
  483. /**
  484. @sa setAutoClose()
  485. */
  486. bool isAutoClose() const;
  487. /// Sets or unsets the auto-close flag.
  488. /**
  489. By default, QuaZIP opens the underlying QIODevice when open() is called,
  490. and closes it when close() is called. In some cases, when the device
  491. is set explicitly using setIoDevice(), it may be desirable to
  492. leave the device open. If the auto-close flag is unset using this method,
  493. then the device isn't closed automatically if it was set explicitly.
  494. If it is needed to clear this flag, it is recommended to do so before
  495. opening the archive because otherwise QuaZIP may close the device
  496. during the open() call if an error is encountered after the device
  497. is opened.
  498. If the device was not set explicitly, but rather the setZipName() or
  499. the appropriate constructor was used to set the ZIP file name instead,
  500. then the auto-close flag has no effect, and the internal device
  501. is closed nevertheless because there is no other way to close it.
  502. @sa isAutoClose()
  503. @sa setIoDevice()
  504. */
  505. void setAutoClose(bool autoClose) const;
  506. /// Sets the default file name codec to use.
  507. /**
  508. * The default codec is used by the constructors, so calling this function
  509. * won't affect the QuaZip instances already created at that moment.
  510. *
  511. * The codec specified here can be overriden by calling setFileNameCodec().
  512. * If neither function is called, QTextCodec::codecForLocale() will be used
  513. * to decode or encode file names. Use this function with caution if
  514. * the application uses other libraries that depend on QuaZIP. Those
  515. * libraries can either call this function by themselves, thus overriding
  516. * your setting or can rely on the default encoding, thus failing
  517. * mysteriously if you change it. For these reasons, it isn't recommended
  518. * to use this function if you are developing a library, not an application.
  519. * Instead, ask your library users to call it in case they need specific
  520. * encoding.
  521. *
  522. * In most cases, using setFileNameCodec() instead is the right choice.
  523. * However, if you depend on third-party code that uses QuaZIP, then the
  524. * reasons stated above can actually become a reason to use this function
  525. * in case the third-party code in question fails because it doesn't
  526. * understand the encoding you need and doesn't provide a way to specify it.
  527. * This applies to the JlCompress class as well, as it was contributed and
  528. * doesn't support explicit encoding parameters.
  529. *
  530. * In short: use setFileNameCodec() when you can, resort to
  531. * setDefaultFileNameCodec() when you don't have access to the QuaZip
  532. * instance.
  533. *
  534. * @param codec The codec to use by default. If NULL, resets to default.
  535. */
  536. static void setDefaultFileNameCodec(QTextCodec *codec);
  537. /**
  538. * @overload
  539. * Equivalent to calling
  540. * setDefltFileNameCodec(QTextCodec::codecForName(codecName)).
  541. */
  542. static void setDefaultFileNameCodec(const char *codecName);
  543. };
  544. #endif