zip_p.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /****************************************************************************
  2. ** Filename: zip_p.h
  3. ** Last updated [dd/mm/yyyy]: 27/03/2011
  4. **
  5. ** pkzip 2.0 file compression.
  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. //
  28. // W A R N I N G
  29. // -------------
  30. //
  31. // This file is not part of the Zip/UnZip API. It exists purely as an
  32. // implementation detail. This header file may change from version to
  33. // version without notice, or even be removed.
  34. //
  35. // We mean it.
  36. //
  37. #ifndef OSDAB_ZIP_P__H
  38. #define OSDAB_ZIP_P__H
  39. #include "zip.h"
  40. #include "zipentry_p.h"
  41. #include <QtCore/QFileInfo>
  42. #include <QtCore/QObject>
  43. #include <QtCore/QtGlobal>
  44. /*!
  45. zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
  46. we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
  47. */
  48. #define ZIP_READ_BUFFER (256*1024)
  49. OSDAB_BEGIN_NAMESPACE(Zip)
  50. class ZipPrivate : public QObject
  51. {
  52. Q_OBJECT
  53. public:
  54. // uLongf from zconf.h
  55. typedef unsigned long crc_t;
  56. ZipPrivate();
  57. virtual ~ZipPrivate();
  58. QMap<QString,ZipEntryP*>* headers;
  59. QIODevice* device;
  60. QFile* file;
  61. char buffer1[ZIP_READ_BUFFER];
  62. char buffer2[ZIP_READ_BUFFER];
  63. unsigned char* uBuffer;
  64. const crc_t* crcTable;
  65. QString comment;
  66. QString password;
  67. Zip::ErrorCode createArchive(QIODevice* device);
  68. Zip::ErrorCode closeArchive();
  69. void reset();
  70. bool zLibInit();
  71. bool containsEntry(const QFileInfo& info) const;
  72. Zip::ErrorCode addDirectory(const QString& path, const QString& root,
  73. Zip::CompressionOptions options, Zip::CompressionLevel level,
  74. int hierarchyLevel, int* addedFiles = 0);
  75. Zip::ErrorCode addFiles(const QStringList& paths, const QString& root,
  76. Zip::CompressionOptions options, Zip::CompressionLevel level,
  77. int* addedFiles);
  78. Zip::ErrorCode createEntry(const QFileInfo& file, const QString& root,
  79. Zip::CompressionLevel level);
  80. Zip::CompressionLevel detectCompressionByMime(const QString& ext);
  81. inline quint32 updateChecksum(const quint32& crc, const quint32& val) const;
  82. inline void encryptBytes(quint32* keys, char* buffer, qint64 read);
  83. inline void setULong(quint32 v, char* buffer, unsigned int offset);
  84. inline void updateKeys(quint32* keys, int c) const;
  85. inline void initKeys(quint32* keys) const;
  86. inline int decryptByte(quint32 key2) const;
  87. inline QString extractRoot(const QString& p, Zip::CompressionOptions o);
  88. private slots:
  89. void deviceDestroyed(QObject*);
  90. private:
  91. int compressionStrategy(const QString& path, QIODevice& file) const;
  92. Zip::ErrorCode deflateFile(const QFileInfo& fileInfo,
  93. quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys);
  94. Zip::ErrorCode storeFile(const QString& path, QIODevice& file,
  95. quint32& crc, qint64& written, quint32** keys);
  96. Zip::ErrorCode compressFile(const QString& path, QIODevice& file,
  97. quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys);
  98. Zip::ErrorCode do_closeArchive();
  99. Zip::ErrorCode writeEntry(const QString& fileName, const ZipEntryP* h, quint32& szCentralDir);
  100. Zip::ErrorCode writeCentralDir(quint32 offCentralDir, quint32 szCentralDir);
  101. };
  102. OSDAB_END_NAMESPACE
  103. #endif // OSDAB_ZIP_P__H