diff src/win32/7zip/7z/CPP/7zip/Archive/7z/7zIn.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zIn.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,245 @@
     1.4 +// 7zIn.h
     1.5 +
     1.6 +#ifndef __7Z_IN_H
     1.7 +#define __7Z_IN_H
     1.8 +
     1.9 +#include "../../../Common/MyCom.h"
    1.10 +
    1.11 +#include "../../IPassword.h"
    1.12 +#include "../../IStream.h"
    1.13 +
    1.14 +#include "../../Common/CreateCoder.h"
    1.15 +#include "../../Common/InBuffer.h"
    1.16 +
    1.17 +#include "7zItem.h"
    1.18 + 
    1.19 +namespace NArchive {
    1.20 +namespace N7z {
    1.21 +  
    1.22 +struct CInArchiveInfo
    1.23 +{
    1.24 +  CArchiveVersion Version;
    1.25 +  UInt64 StartPosition;
    1.26 +  UInt64 StartPositionAfterHeader;
    1.27 +  UInt64 DataStartPosition;
    1.28 +  UInt64 DataStartPosition2;
    1.29 +  CRecordVector<UInt64> FileInfoPopIDs;
    1.30 +  void Clear()
    1.31 +  {
    1.32 +    FileInfoPopIDs.Clear();
    1.33 +  }
    1.34 +};
    1.35 +
    1.36 +struct CArchiveDatabaseEx: public CArchiveDatabase
    1.37 +{
    1.38 +  CInArchiveInfo ArchiveInfo;
    1.39 +  CRecordVector<UInt64> PackStreamStartPositions;
    1.40 +  CRecordVector<CNum> FolderStartPackStreamIndex;
    1.41 +  CRecordVector<CNum> FolderStartFileIndex;
    1.42 +  CRecordVector<CNum> FileIndexToFolderIndexMap;
    1.43 +
    1.44 +  UInt64 HeadersSize;
    1.45 +  UInt64 PhySize;
    1.46 +
    1.47 +  void Clear()
    1.48 +  {
    1.49 +    CArchiveDatabase::Clear();
    1.50 +    ArchiveInfo.Clear();
    1.51 +    PackStreamStartPositions.Clear();
    1.52 +    FolderStartPackStreamIndex.Clear();
    1.53 +    FolderStartFileIndex.Clear();
    1.54 +    FileIndexToFolderIndexMap.Clear();
    1.55 +
    1.56 +    HeadersSize = 0;
    1.57 +    PhySize = 0;
    1.58 +  }
    1.59 +
    1.60 +  void FillFolderStartPackStream();
    1.61 +  void FillStartPos();
    1.62 +  void FillFolderStartFileIndex();
    1.63 +
    1.64 +  void Fill()
    1.65 +  {
    1.66 +    FillFolderStartPackStream();
    1.67 +    FillStartPos();
    1.68 +    FillFolderStartFileIndex();
    1.69 +  }
    1.70 +  
    1.71 +  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
    1.72 +  {
    1.73 +    return ArchiveInfo.DataStartPosition +
    1.74 +        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];
    1.75 +  }
    1.76 +  
    1.77 +  UInt64 GetFolderFullPackSize(int folderIndex) const
    1.78 +  {
    1.79 +    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
    1.80 +    const CFolder &folder = Folders[folderIndex];
    1.81 +    UInt64 size = 0;
    1.82 +    for (int i = 0; i < folder.PackStreams.Size(); i++)
    1.83 +      size += PackSizes[packStreamIndex + i];
    1.84 +    return size;
    1.85 +  }
    1.86 +  
    1.87 +  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
    1.88 +  {
    1.89 +    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
    1.90 +  }
    1.91 +
    1.92 +  UInt64 GetFilePackSize(CNum fileIndex) const
    1.93 +  {
    1.94 +    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
    1.95 +    if (folderIndex != kNumNoIndex)
    1.96 +      if (FolderStartFileIndex[folderIndex] == fileIndex)
    1.97 +        return GetFolderFullPackSize(folderIndex);
    1.98 +    return 0;
    1.99 +  }
   1.100 +};
   1.101 +
   1.102 +class CInByte2
   1.103 +{
   1.104 +  const Byte *_buffer;
   1.105 +  size_t _size;
   1.106 +public:
   1.107 +  size_t _pos;
   1.108 +  void Init(const Byte *buffer, size_t size)
   1.109 +  {
   1.110 +    _buffer = buffer;
   1.111 +    _size = size;
   1.112 +    _pos = 0;
   1.113 +  }
   1.114 +  Byte ReadByte();
   1.115 +  void ReadBytes(Byte *data, size_t size);
   1.116 +  void SkeepData(UInt64 size);
   1.117 +  void SkeepData();
   1.118 +  UInt64 ReadNumber();
   1.119 +  CNum ReadNum();
   1.120 +  UInt32 ReadUInt32();
   1.121 +  UInt64 ReadUInt64();
   1.122 +  void ReadString(UString &s);
   1.123 +};
   1.124 +
   1.125 +class CStreamSwitch;
   1.126 +
   1.127 +const UInt32 kHeaderSize = 32;
   1.128 +
   1.129 +class CInArchive
   1.130 +{
   1.131 +  friend class CStreamSwitch;
   1.132 +
   1.133 +  CMyComPtr<IInStream> _stream;
   1.134 +
   1.135 +  CObjectVector<CInByte2> _inByteVector;
   1.136 +  CInByte2 *_inByteBack;
   1.137 + 
   1.138 +  UInt64 _arhiveBeginStreamPosition;
   1.139 +
   1.140 +  Byte _header[kHeaderSize];
   1.141 +
   1.142 +  UInt64 HeadersSize;
   1.143 +
   1.144 +  void AddByteStream(const Byte *buffer, size_t size)
   1.145 +  {
   1.146 +    _inByteVector.Add(CInByte2());
   1.147 +    _inByteBack = &_inByteVector.Back();
   1.148 +    _inByteBack->Init(buffer, size);
   1.149 +  }
   1.150 +  
   1.151 +  void DeleteByteStream()
   1.152 +  {
   1.153 +    _inByteVector.DeleteBack();
   1.154 +    if (!_inByteVector.IsEmpty())
   1.155 +      _inByteBack = &_inByteVector.Back();
   1.156 +  }
   1.157 +
   1.158 +private:
   1.159 +  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
   1.160 +  
   1.161 +  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }
   1.162 +  Byte ReadByte() { return _inByteBack->ReadByte(); }
   1.163 +  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }
   1.164 +  CNum ReadNum() { return _inByteBack->ReadNum(); }
   1.165 +  UInt64 ReadID() { return _inByteBack->ReadNumber(); }
   1.166 +  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }
   1.167 +  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }
   1.168 +  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }
   1.169 +  void SkeepData() { _inByteBack->SkeepData(); }
   1.170 +  void WaitAttribute(UInt64 attribute);
   1.171 +
   1.172 +  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
   1.173 +  void GetNextFolderItem(CFolder &itemInfo);
   1.174 +  void ReadHashDigests(int numItems,
   1.175 +      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);
   1.176 +  
   1.177 +  void ReadPackInfo(
   1.178 +      UInt64 &dataOffset,
   1.179 +      CRecordVector<UInt64> &packSizes,
   1.180 +      CBoolVector &packCRCsDefined,
   1.181 +      CRecordVector<UInt32> &packCRCs);
   1.182 +  
   1.183 +  void ReadUnpackInfo(
   1.184 +      const CObjectVector<CByteBuffer> *dataVector,
   1.185 +      CObjectVector<CFolder> &folders);
   1.186 +  
   1.187 +  void ReadSubStreamsInfo(
   1.188 +      const CObjectVector<CFolder> &folders,
   1.189 +      CRecordVector<CNum> &numUnpackStreamsInFolders,
   1.190 +      CRecordVector<UInt64> &unpackSizes,
   1.191 +      CBoolVector &digestsDefined,
   1.192 +      CRecordVector<UInt32> &digests);
   1.193 +
   1.194 +  void ReadStreamsInfo(
   1.195 +      const CObjectVector<CByteBuffer> *dataVector,
   1.196 +      UInt64 &dataOffset,
   1.197 +      CRecordVector<UInt64> &packSizes,
   1.198 +      CBoolVector &packCRCsDefined,
   1.199 +      CRecordVector<UInt32> &packCRCs,
   1.200 +      CObjectVector<CFolder> &folders,
   1.201 +      CRecordVector<CNum> &numUnpackStreamsInFolders,
   1.202 +      CRecordVector<UInt64> &unpackSizes,
   1.203 +      CBoolVector &digestsDefined,
   1.204 +      CRecordVector<UInt32> &digests);
   1.205 +
   1.206 +
   1.207 +  void ReadBoolVector(int numItems, CBoolVector &v);
   1.208 +  void ReadBoolVector2(int numItems, CBoolVector &v);
   1.209 +  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
   1.210 +      CUInt64DefVector &v, int numFiles);
   1.211 +  HRESULT ReadAndDecodePackedStreams(
   1.212 +      DECL_EXTERNAL_CODECS_LOC_VARS
   1.213 +      UInt64 baseOffset, UInt64 &dataOffset,
   1.214 +      CObjectVector<CByteBuffer> &dataVector
   1.215 +      #ifndef _NO_CRYPTO
   1.216 +      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
   1.217 +      #endif
   1.218 +      );
   1.219 +  HRESULT ReadHeader(
   1.220 +      DECL_EXTERNAL_CODECS_LOC_VARS
   1.221 +      CArchiveDatabaseEx &db
   1.222 +      #ifndef _NO_CRYPTO
   1.223 +      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
   1.224 +      #endif
   1.225 +      );
   1.226 +  HRESULT ReadDatabase2(
   1.227 +      DECL_EXTERNAL_CODECS_LOC_VARS
   1.228 +      CArchiveDatabaseEx &db
   1.229 +      #ifndef _NO_CRYPTO
   1.230 +      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
   1.231 +      #endif
   1.232 +      );
   1.233 +public:
   1.234 +  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
   1.235 +  void Close();
   1.236 +
   1.237 +  HRESULT ReadDatabase(
   1.238 +      DECL_EXTERNAL_CODECS_LOC_VARS
   1.239 +      CArchiveDatabaseEx &db
   1.240 +      #ifndef _NO_CRYPTO
   1.241 +      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
   1.242 +      #endif
   1.243 +      );
   1.244 +};
   1.245 +  
   1.246 +}}
   1.247 +  
   1.248 +#endif