fileHeader.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "io/zip/extraField.h"
  23. #include "collection/vector.h"
  24. #ifndef _FILEHEADER_H_
  25. #define _FILEHEADER_H_
  26. // Forward Refs
  27. class Stream;
  28. namespace Zip
  29. {
  30. /// @addtogroup zipint_group
  31. /// @ingroup zip_group
  32. // @{
  33. enum FileFlags
  34. {
  35. Encrypted = BIT(0),
  36. // For implode compression
  37. Implode8KDictionary = BIT(1),
  38. Implode3ShannonFanoTrees = BIT(2),
  39. // For deflate compression
  40. DeflateTypeMask = BIT(1) | BIT(2),
  41. FileInfoInDirectory = BIT(3),
  42. // Note that much of the following flag bits are unsupported for various reasons
  43. ReservedEnhDeflate = BIT(4),
  44. PatchData = BIT(5),
  45. StrongEncryption = BIT(6),
  46. UnusedReserved1 = BIT(7),
  47. UnusedReserved2 = BIT(8),
  48. UnusedReserved3 = BIT(9),
  49. UnusedReserved4 = BIT(10),
  50. UnusedReserved5 = BIT(11),
  51. ReservedPKWARE1 = BIT(12),
  52. EncryptedDirectory = BIT(13),
  53. ReservedPKWARE2 = BIT(14),
  54. ReservedPKWARE3 = BIT(15),
  55. };
  56. class FileHeader
  57. {
  58. static const U32 mFileHeaderSignature = 0x04034b50;
  59. protected:
  60. bool readExtraFields(Stream *stream, U16 efLen);
  61. public:
  62. U32 mHeaderSig;
  63. U16 mExtractVer;
  64. U16 mFlags;
  65. U16 mCompressMethod;
  66. U16 mModTime;
  67. U16 mModDate;
  68. U32 mCRC32;
  69. U32 mCompressedSize;
  70. U32 mUncompressedSize;
  71. const char *mFilename;
  72. Vector<ExtraField *> mExtraFields;
  73. FileHeader();
  74. virtual ~FileHeader();
  75. virtual bool read(Stream *stream);
  76. virtual bool write(Stream *stream);
  77. ExtraField *findExtraField(U16 id);
  78. void setFilename(const char *filename);
  79. };
  80. // @}
  81. } // end namespace Zip
  82. #endif