other-licenses/7zstub/src/7zip/Archive/7z/7zIn.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/7zip/Archive/7z/7zIn.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,288 @@
     1.4 +// 7zIn.h
     1.5 +
     1.6 +#ifndef __7Z_IN_H
     1.7 +#define __7Z_IN_H
     1.8 +
     1.9 +#include "../../IStream.h"
    1.10 +#include "../../IPassword.h"
    1.11 +#include "../../../Common/MyCom.h"
    1.12 +#include "../../Common/InBuffer.h"
    1.13 +
    1.14 +#include "7zHeader.h"
    1.15 +#include "7zItem.h"
    1.16 + 
    1.17 +namespace NArchive {
    1.18 +namespace N7z {
    1.19 +  
    1.20 +class CInArchiveException
    1.21 +{
    1.22 +public:
    1.23 +  enum CCauseType
    1.24 +  {
    1.25 +    kUnsupportedVersion = 0,
    1.26 +    kUnexpectedEndOfArchive = 0,
    1.27 +    kIncorrectHeader,
    1.28 +  } Cause;
    1.29 +  CInArchiveException(CCauseType cause);
    1.30 +};
    1.31 +
    1.32 +struct CInArchiveInfo
    1.33 +{
    1.34 +  CArchiveVersion Version;
    1.35 +  UInt64 StartPosition;
    1.36 +  UInt64 StartPositionAfterHeader;
    1.37 +  UInt64 DataStartPosition;
    1.38 +  UInt64 DataStartPosition2;
    1.39 +  CRecordVector<UInt64> FileInfoPopIDs;
    1.40 +  void Clear()
    1.41 +  {
    1.42 +    FileInfoPopIDs.Clear();
    1.43 +  }
    1.44 +};
    1.45 +
    1.46 +
    1.47 +struct CArchiveDatabaseEx: public CArchiveDatabase
    1.48 +{
    1.49 +  CInArchiveInfo ArchiveInfo;
    1.50 +  CRecordVector<UInt64> PackStreamStartPositions;
    1.51 +  CRecordVector<CNum> FolderStartPackStreamIndex;
    1.52 +  CRecordVector<CNum> FolderStartFileIndex;
    1.53 +  CRecordVector<CNum> FileIndexToFolderIndexMap;
    1.54 +
    1.55 +  void Clear()
    1.56 +  {
    1.57 +    CArchiveDatabase::Clear();
    1.58 +    ArchiveInfo.Clear();
    1.59 +    PackStreamStartPositions.Clear();
    1.60 +    FolderStartPackStreamIndex.Clear();
    1.61 +    FolderStartFileIndex.Clear();
    1.62 +    FileIndexToFolderIndexMap.Clear();
    1.63 +  }
    1.64 +
    1.65 +  void FillFolderStartPackStream();
    1.66 +  void FillStartPos();
    1.67 +  void FillFolderStartFileIndex();
    1.68 +
    1.69 +  void Fill()
    1.70 +  {
    1.71 +    FillFolderStartPackStream();
    1.72 +    FillStartPos();
    1.73 +    FillFolderStartFileIndex();
    1.74 +  }
    1.75 +  
    1.76 +  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
    1.77 +  {
    1.78 +    return ArchiveInfo.DataStartPosition +
    1.79 +        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] +
    1.80 +        indexInFolder];
    1.81 +  }
    1.82 +  
    1.83 +  UInt64 GetFolderFullPackSize(int folderIndex) const 
    1.84 +  {
    1.85 +    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
    1.86 +    const CFolder &folder = Folders[folderIndex];
    1.87 +    UInt64 size = 0;
    1.88 +    for (int i = 0; i < folder.PackStreams.Size(); i++)
    1.89 +      size += PackSizes[packStreamIndex + i];
    1.90 +    return size;
    1.91 +  }
    1.92 +  
    1.93 +  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const 
    1.94 +  {
    1.95 +    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
    1.96 +  }
    1.97 +
    1.98 +  UInt64 GetFilePackSize(CNum fileIndex) const
    1.99 +  {
   1.100 +    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
   1.101 +    if (folderIndex >= 0)
   1.102 +    {
   1.103 +      if (FolderStartFileIndex[folderIndex] == fileIndex)
   1.104 +        return GetFolderFullPackSize(folderIndex);
   1.105 +    }
   1.106 +    return 0;
   1.107 +  }
   1.108 +};
   1.109 +
   1.110 +class CInByte2
   1.111 +{
   1.112 +  const Byte *_buffer;
   1.113 +  size_t _size;
   1.114 +  size_t _pos;
   1.115 +public:
   1.116 +  void Init(const Byte *buffer, size_t size)
   1.117 +  {
   1.118 +    _buffer = buffer;
   1.119 +    _size = size;
   1.120 +    _pos = 0;
   1.121 +  }
   1.122 +  bool ReadByte(Byte &b)
   1.123 +  {
   1.124 +    if(_pos >= _size)
   1.125 +      return false;
   1.126 +    b = _buffer[_pos++];
   1.127 +    return true;
   1.128 +  }
   1.129 +  void ReadBytes(void *data, size_t size, size_t &processedSize)
   1.130 +  {
   1.131 +    for(processedSize = 0; processedSize < size && _pos < _size; processedSize++)
   1.132 +      ((Byte *)data)[processedSize] = _buffer[_pos++];
   1.133 +  }
   1.134 +  
   1.135 +  bool ReadBytes(void *data, size_t size)
   1.136 +  {
   1.137 +    size_t processedSize;
   1.138 +    ReadBytes(data, size, processedSize);
   1.139 +    return (processedSize == size);
   1.140 +  }
   1.141 +  
   1.142 +  size_t GetProcessedSize() const { return _pos; }
   1.143 +};
   1.144 +
   1.145 +class CStreamSwitch;
   1.146 +class CInArchive
   1.147 +{
   1.148 +  friend class CStreamSwitch;
   1.149 +
   1.150 +  CMyComPtr<IInStream> _stream;
   1.151 +  #ifdef _7Z_VOL
   1.152 +  bool _finishSignature;
   1.153 +  #endif
   1.154 +
   1.155 +  CObjectVector<CInByte2> _inByteVector;
   1.156 +  CInByte2 *_inByteBack;
   1.157 + 
   1.158 +  UInt64 _arhiveBeginStreamPosition;
   1.159 +  UInt64 _position;
   1.160 +
   1.161 +  void AddByteStream(const Byte *buffer, size_t size)
   1.162 +  {
   1.163 +    _inByteVector.Add(CInByte2());
   1.164 +    _inByteBack = &_inByteVector.Back();
   1.165 +    _inByteBack->Init(buffer, size);
   1.166 +  }
   1.167 +  
   1.168 +  void DeleteByteStream()
   1.169 +  {
   1.170 +    _inByteVector.DeleteBack();
   1.171 +    if (!_inByteVector.IsEmpty())
   1.172 +      _inByteBack = &_inByteVector.Back();
   1.173 +  }
   1.174 +
   1.175 +private:
   1.176 +  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
   1.177 +  #ifdef _7Z_VOL
   1.178 +  HRESULT FindFinishSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
   1.179 +  #endif
   1.180 +  
   1.181 +  HRESULT ReadFileNames(CObjectVector<CFileItem> &files);
   1.182 +  
   1.183 +  HRESULT ReadDirect(IInStream *stream, void *data, UInt32 size, 
   1.184 +      UInt32 *processedSize);
   1.185 +  HRESULT ReadDirect(void *data, UInt32 size, UInt32 *processedSize);
   1.186 +  HRESULT SafeReadDirect(void *data, UInt32 size);
   1.187 +  HRESULT SafeReadDirectByte(Byte &b);
   1.188 +  HRESULT SafeReadDirectUInt32(UInt32 &value);
   1.189 +  HRESULT SafeReadDirectUInt64(UInt64 &value);
   1.190 +
   1.191 +  HRESULT ReadBytes(void *data, size_t size)
   1.192 +  {
   1.193 +    if (!_inByteBack->ReadBytes(data, size))
   1.194 +      return E_FAIL;
   1.195 +    return S_OK;
   1.196 +  }
   1.197 +
   1.198 +  HRESULT ReadByte(Byte &b)
   1.199 +  {
   1.200 +    if (!_inByteBack->ReadByte(b))
   1.201 +      return E_FAIL;
   1.202 +    return S_OK;
   1.203 +  }
   1.204 +
   1.205 +  HRESULT ReadWideCharLE(wchar_t &c)
   1.206 +  {
   1.207 +    Byte b1;
   1.208 +    if (!_inByteBack->ReadByte(b1))
   1.209 +      return E_FAIL;
   1.210 +    Byte b2;
   1.211 +    if (!_inByteBack->ReadByte(b2))
   1.212 +      return E_FAIL;
   1.213 +    c = (wchar_t(b2) << 8) + b1;
   1.214 +    return S_OK;
   1.215 +  }
   1.216 +
   1.217 +  HRESULT ReadNumber(UInt64 &value);
   1.218 +  HRESULT ReadNum(CNum &value);
   1.219 +  HRESULT ReadID(UInt64 &value) { return ReadNumber(value); }
   1.220 +  HRESULT ReadUInt32(UInt32 &value);
   1.221 +  HRESULT ReadUInt64(UInt64 &value);
   1.222 +  
   1.223 +  HRESULT SkeepData(UInt64 size);
   1.224 +  HRESULT SkeepData();
   1.225 +  HRESULT WaitAttribute(UInt64 attribute);
   1.226 +
   1.227 +  HRESULT ReadArchiveProperties(CInArchiveInfo &archiveInfo);
   1.228 +  HRESULT GetNextFolderItem(CFolder &itemInfo);
   1.229 +  HRESULT ReadHashDigests(int numItems,
   1.230 +      CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests);
   1.231 +  
   1.232 +  HRESULT ReadPackInfo(
   1.233 +      UInt64 &dataOffset,
   1.234 +      CRecordVector<UInt64> &packSizes,
   1.235 +      CRecordVector<bool> &packCRCsDefined,
   1.236 +      CRecordVector<UInt32> &packCRCs);
   1.237 +  
   1.238 +  HRESULT ReadUnPackInfo(
   1.239 +      const CObjectVector<CByteBuffer> *dataVector,
   1.240 +      CObjectVector<CFolder> &folders);
   1.241 +  
   1.242 +  HRESULT ReadSubStreamsInfo(
   1.243 +      const CObjectVector<CFolder> &folders,
   1.244 +      CRecordVector<CNum> &numUnPackStreamsInFolders,
   1.245 +      CRecordVector<UInt64> &unPackSizes,
   1.246 +      CRecordVector<bool> &digestsDefined, 
   1.247 +      CRecordVector<UInt32> &digests);
   1.248 +
   1.249 +  HRESULT ReadStreamsInfo(
   1.250 +      const CObjectVector<CByteBuffer> *dataVector,
   1.251 +      UInt64 &dataOffset,
   1.252 +      CRecordVector<UInt64> &packSizes,
   1.253 +      CRecordVector<bool> &packCRCsDefined,
   1.254 +      CRecordVector<UInt32> &packCRCs,
   1.255 +      CObjectVector<CFolder> &folders,
   1.256 +      CRecordVector<CNum> &numUnPackStreamsInFolders,
   1.257 +      CRecordVector<UInt64> &unPackSizes,
   1.258 +      CRecordVector<bool> &digestsDefined, 
   1.259 +      CRecordVector<UInt32> &digests);
   1.260 +
   1.261 +
   1.262 +  HRESULT GetNextFileItem(CFileItem &itemInfo);
   1.263 +  HRESULT ReadBoolVector(int numItems, CBoolVector &v);
   1.264 +  HRESULT ReadBoolVector2(int numItems, CBoolVector &v);
   1.265 +  HRESULT ReadTime(const CObjectVector<CByteBuffer> &dataVector,
   1.266 +      CObjectVector<CFileItem> &files, UInt64 type);
   1.267 +  HRESULT ReadAndDecodePackedStreams(UInt64 baseOffset, UInt64 &dataOffset,
   1.268 +      CObjectVector<CByteBuffer> &dataVector
   1.269 +      #ifndef _NO_CRYPTO
   1.270 +      , ICryptoGetTextPassword *getTextPassword
   1.271 +      #endif
   1.272 +      );
   1.273 +  HRESULT ReadHeader(CArchiveDatabaseEx &database
   1.274 +      #ifndef _NO_CRYPTO
   1.275 +      ,ICryptoGetTextPassword *getTextPassword
   1.276 +      #endif
   1.277 +      );
   1.278 +public:
   1.279 +  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
   1.280 +  void Close();
   1.281 +
   1.282 +  HRESULT ReadDatabase(CArchiveDatabaseEx &database 
   1.283 +      #ifndef _NO_CRYPTO
   1.284 +      ,ICryptoGetTextPassword *getTextPassword
   1.285 +      #endif
   1.286 +      );
   1.287 +};
   1.288 +  
   1.289 +}}
   1.290 +  
   1.291 +#endif

mercurial