centralDir.h

Engine/source/core/util/zip/centralDir.h

More...

Classes:

Namespaces:

namespace

Namespace for the zip code.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "core/util/zip/fileHeader.h"
 25
 26#ifndef _CENTRALDIR_H_
 27#define _CENTRALDIR_H_
 28
 29namespace Zip
 30{
 31
 32/// @addtogroup zipint_group
 33/// @ingroup zip_group
 34// @{
 35
 36/// Internal flags used by the zip code when writing zips
 37enum CDIntFlags
 38{
 39   CDFileDirty = BIT(0),
 40   CDFileAdded = BIT(1),
 41   CDFileDeleted = BIT(2),
 42   CDFileOpen = BIT(3)
 43};
 44
 45class CentralDir : public FileHeader
 46{
 47   typedef FileHeader Parent;
 48
 49   static const U32 mCentralDirSignature = 0x02014b50;
 50   
 51   char *mFileComment;
 52
 53public:
 54   U16 mDiskNumStart;
 55   
 56   U16 mInternalFileAttr;
 57   U32 mExternalFileAttr;
 58   
 59   U32 mLocalHeadOffset;
 60   
 61   U16 mVersionMadeBy;
 62
 63   U32 mInternalFlags;
 64
 65   CentralDir();
 66   CentralDir(FileHeader &fh);
 67   virtual ~CentralDir();
 68
 69   virtual bool read(Stream *stream);
 70   virtual bool write(Stream *stream);
 71
 72   void setFileComment(const char *comment);
 73};
 74
 75class EndOfCentralDir
 76{
 77   static const U32 mEOCDSignature = 0x06054b50;
 78   /// The size of the EndOfCentralDir record in the zip file, used to locate it
 79   /// at the end of the file.
 80   static const U32 mRecordSize = 20;
 81   /// The number of bytes from the end of the file to start searching for the EOCD
 82   static const U32 mEOCDSearchSize = 64 * 1024;
 83
 84public:
 85   U32 mHeaderSig;
 86
 87   U16 mDiskNum;
 88   U16 mStartCDDiskNum;
 89   U16 mNumEntriesInThisCD;
 90   U16 mTotalEntriesInCD;
 91   U32 mCDSize;
 92   U32 mCDOffset;
 93   U16 mCommentSize;
 94   
 95   const char *mZipComment;
 96
 97   EndOfCentralDir();
 98   virtual ~EndOfCentralDir();
 99
100   virtual bool findInStream(Stream *stream);
101
102   virtual bool read(Stream *stream);
103   virtual bool write(Stream *stream);
104
105   virtual void setZipComment(const char *zipComment);
106   virtual void setZipComment(U16 commentSize, const char *zipComment);
107};
108
109// @}
110
111} // end namespace Zip
112
113#endif // _CENTRALDIR_H_
114