unzip.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /****************************************************************************
  2. ** Filename: unzip.h
  3. ** Last updated [dd/mm/yyyy]: 27/03/2011
  4. **
  5. ** pkzip 2.0 decompression.
  6. **
  7. ** Some of the code has been inspired by other open source projects,
  8. ** (mainly Info-Zip and Gilles Vollant's minizip).
  9. ** Compression and decompression actually uses the zlib library.
  10. **
  11. ** Copyright (C) 2007-2012 Angius Fabrizio. All rights reserved.
  12. **
  13. ** This file is part of the OSDaB project (http://osdab.42cows.org/).
  14. **
  15. ** This file may be distributed and/or modified under the terms of the
  16. ** GNU General Public License version 2 as published by the Free Software
  17. ** Foundation and appearing in the file LICENSE.GPL included in the
  18. ** packaging of this file.
  19. **
  20. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  21. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22. **
  23. ** See the file LICENSE.GPL that came with this software distribution or
  24. ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
  25. **
  26. **********************************************************************/
  27. #ifndef OSDAB_UNZIP__H
  28. #define OSDAB_UNZIP__H
  29. #include "zipglobal.h"
  30. #include <QtCore/QDateTime>
  31. #include <QtCore/QMap>
  32. #include <QtCore/QtGlobal>
  33. #include <zlib/zlib.h>
  34. class QDir;
  35. class QFile;
  36. class QIODevice;
  37. class QString;
  38. class QStringList;
  39. OSDAB_BEGIN_NAMESPACE(Zip)
  40. class UnzipPrivate;
  41. class OSDAB_ZIP_EXPORT UnZip
  42. {
  43. public:
  44. enum ErrorCode
  45. {
  46. Ok,
  47. ZlibInit,
  48. ZlibError,
  49. OpenFailed,
  50. PartiallyCorrupted,
  51. Corrupted,
  52. WrongPassword,
  53. NoOpenArchive,
  54. FileNotFound,
  55. ReadFailed,
  56. WriteFailed,
  57. SeekFailed,
  58. CreateDirFailed,
  59. InvalidDevice,
  60. InvalidArchive,
  61. HeaderConsistencyError,
  62. Skip, SkipAll // internal use only
  63. };
  64. enum ExtractionOption
  65. {
  66. ExtractPaths = 0x0001,
  67. SkipPaths = 0x0002,
  68. VerifyOnly = 0x0004
  69. };
  70. Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
  71. enum CompressionMethod
  72. {
  73. NoCompression, Deflated, UnknownCompression
  74. };
  75. enum FileType
  76. {
  77. File, Directory
  78. };
  79. struct ZipEntry
  80. {
  81. ZipEntry();
  82. QString filename;
  83. QString comment;
  84. quint32 compressedSize;
  85. quint32 uncompressedSize;
  86. quint32 crc32;
  87. QDateTime lastModified;
  88. CompressionMethod compression;
  89. FileType type;
  90. bool encrypted;
  91. };
  92. UnZip();
  93. virtual ~UnZip();
  94. bool isOpen() const;
  95. ErrorCode openArchive(const QString& filename);
  96. ErrorCode openArchive(QIODevice* device);
  97. void closeArchive();
  98. QString archiveComment() const;
  99. QString formatError(UnZip::ErrorCode c) const;
  100. bool contains(const QString& file) const;
  101. QStringList fileList() const;
  102. QList<ZipEntry> entryList() const;
  103. ErrorCode verifyArchive();
  104. ErrorCode extractAll(const QString& dirname, ExtractionOptions options = ExtractPaths);
  105. ErrorCode extractAll(const QDir& dir, ExtractionOptions options = ExtractPaths);
  106. ErrorCode extractFile(const QString& filename, const QString& dirname, ExtractionOptions options = ExtractPaths);
  107. ErrorCode extractFile(const QString& filename, const QDir& dir, ExtractionOptions options = ExtractPaths);
  108. ErrorCode extractFile(const QString& filename, QIODevice* device, ExtractionOptions options = ExtractPaths);
  109. ErrorCode extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options = ExtractPaths);
  110. ErrorCode extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options = ExtractPaths);
  111. void setPassword(const QString& pwd);
  112. private:
  113. UnzipPrivate* d;
  114. };
  115. Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
  116. OSDAB_END_NAMESPACE
  117. #endif // OSDAB_UNZIP__H