centralDir.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/fileHeader.h"
  23. #ifndef _CENTRALDIR_H_
  24. #define _CENTRALDIR_H_
  25. namespace Zip
  26. {
  27. /// @addtogroup zipint_group
  28. /// @ingroup zip_group
  29. // @{
  30. /// Internal flags used by the zip code when writing zips
  31. enum CDIntFlags
  32. {
  33. CDFileDirty = BIT(0),
  34. CDFileAdded = BIT(1),
  35. CDFileDeleted = BIT(2),
  36. CDFileOpen = BIT(3)
  37. };
  38. class CentralDir : public FileHeader
  39. {
  40. typedef FileHeader Parent;
  41. static const U32 mCentralDirSignature = 0x02014b50;
  42. public:
  43. U16 mDiskNumStart;
  44. U16 mInternalFileAttr;
  45. U32 mExternalFileAttr;
  46. U32 mLocalHeadOffset;
  47. U16 mVersionMadeBy;
  48. const char *mFileComment;
  49. U32 mInternalFlags;
  50. CentralDir();
  51. CentralDir(FileHeader &fh);
  52. virtual ~CentralDir();
  53. virtual bool read(Stream *stream);
  54. virtual bool write(Stream *stream);
  55. void setFileComment(const char *comment);
  56. };
  57. class EndOfCentralDir
  58. {
  59. static const U32 mEOCDSignature = 0x06054b50;
  60. /// The size of the EndOfCentralDir record in the zip file, used to locate it
  61. /// at the end of the file.
  62. static const U32 mRecordSize = 20;
  63. /// The number of bytes from the end of the file to start searching for the EOCD
  64. static const U32 mEOCDSearchSize = 64 * 1024;
  65. public:
  66. U32 mHeaderSig;
  67. U16 mDiskNum;
  68. U16 mStartCDDiskNum;
  69. U16 mNumEntriesInThisCD;
  70. U16 mTotalEntriesInCD;
  71. U32 mCDSize;
  72. U32 mCDOffset;
  73. U16 mCommentSize;
  74. const char *mZipComment;
  75. EndOfCentralDir();
  76. virtual ~EndOfCentralDir();
  77. virtual bool findInStream(Stream *stream);
  78. virtual bool read(Stream *stream);
  79. virtual bool write(Stream *stream);
  80. virtual void setZipComment(const char *zipComment);
  81. virtual void setZipComment(U16 commentSize, const char *zipComment);
  82. };
  83. // @}
  84. } // end namespace Zip
  85. #endif // _CENTRALDIR_H_