michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: #ifndef _nsZipHeader_h_ michael@0: #define _nsZipHeader_h_ michael@0: michael@0: #include "nsString.h" michael@0: #include "nsIOutputStream.h" michael@0: #include "nsIInputStream.h" michael@0: #include "nsIZipReader.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: // High word is S_IFREG, low word is DOS file attribute michael@0: #define ZIP_ATTRS_FILE 0x80000000 michael@0: // High word is S_IFDIR, low word is DOS dir attribute michael@0: #define ZIP_ATTRS_DIRECTORY 0x40000010 michael@0: #define PERMISSIONS_FILE 0644 michael@0: #define PERMISSIONS_DIR 0755 michael@0: michael@0: // Combine file type attributes with unix style permissions michael@0: #define ZIP_ATTRS(p, a) ((p & 0xfff) << 16) | a michael@0: michael@0: class nsZipHeader MOZ_FINAL : public nsIZipEntry michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIZIPENTRY michael@0: michael@0: nsZipHeader() : michael@0: mCRC(0), michael@0: mCSize(0), michael@0: mUSize(0), michael@0: mEAttr(0), michael@0: mOffset(0), michael@0: mFieldLength(0), michael@0: mLocalFieldLength(0), michael@0: mVersionMade(0x0300 + 23), // Generated on Unix by v2.3 (matches infozip) michael@0: mVersionNeeded(20), // Requires v2.0 to extract michael@0: mFlags(0), michael@0: mMethod(0), michael@0: mTime(0), michael@0: mDate(0), michael@0: mDisk(0), michael@0: mIAttr(0), michael@0: mInited(false), michael@0: mWriteOnClose(false), michael@0: mExtraField(nullptr), michael@0: mLocalExtraField(nullptr) michael@0: { michael@0: } michael@0: michael@0: ~nsZipHeader() michael@0: { michael@0: mExtraField = nullptr; michael@0: mLocalExtraField = nullptr; michael@0: } michael@0: michael@0: uint32_t mCRC; michael@0: uint32_t mCSize; michael@0: uint32_t mUSize; michael@0: uint32_t mEAttr; michael@0: uint32_t mOffset; michael@0: uint32_t mFieldLength; michael@0: uint32_t mLocalFieldLength; michael@0: uint16_t mVersionMade; michael@0: uint16_t mVersionNeeded; michael@0: uint16_t mFlags; michael@0: uint16_t mMethod; michael@0: uint16_t mTime; michael@0: uint16_t mDate; michael@0: uint16_t mDisk; michael@0: uint16_t mIAttr; michael@0: bool mInited; michael@0: bool mWriteOnClose; michael@0: nsCString mName; michael@0: nsCString mComment; michael@0: nsAutoArrayPtr mExtraField; michael@0: nsAutoArrayPtr mLocalExtraField; michael@0: michael@0: void Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr, michael@0: uint32_t aOffset); michael@0: uint32_t GetFileHeaderLength(); michael@0: nsresult WriteFileHeader(nsIOutputStream *aStream); michael@0: uint32_t GetCDSHeaderLength(); michael@0: nsresult WriteCDSHeader(nsIOutputStream *aStream); michael@0: nsresult ReadCDSHeader(nsIInputStream *aStream); michael@0: const uint8_t * GetExtraField(uint16_t aTag, bool aLocal, uint16_t *aBlockSize); michael@0: nsresult PadExtraField(uint32_t aOffset, uint16_t aAlignSize); michael@0: }; michael@0: michael@0: #endif