This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -1,7 +1,5 @@
// 7zIn.h
#pragma once
#ifndef __7Z_IN_H
#define __7Z_IN_H
@@ -31,11 +29,11 @@ public:
struct CInArchiveInfo
{
CArchiveVersion Version;
UINT64 StartPosition;
UINT64 StartPositionAfterHeader;
UINT64 DataStartPosition;
UINT64 DataStartPosition2;
CRecordVector<UINT64> FileInfoPopIDs;
UInt64 StartPosition;
UInt64 StartPositionAfterHeader;
UInt64 DataStartPosition;
UInt64 DataStartPosition2;
CRecordVector<UInt64> FileInfoPopIDs;
void Clear()
{
FileInfoPopIDs.Clear();
@@ -46,10 +44,10 @@ struct CInArchiveInfo
struct CArchiveDatabaseEx: public CArchiveDatabase
{
CInArchiveInfo ArchiveInfo;
CRecordVector<UINT64> PackStreamStartPositions;
CRecordVector<UINT32> FolderStartPackStreamIndex;
CRecordVector<UINT64> FolderStartFileIndex;
CRecordVector<int> FileIndexToFolderIndexMap;
CRecordVector<UInt64> PackStreamStartPositions;
CRecordVector<CNum> FolderStartPackStreamIndex;
CRecordVector<CNum> FolderStartFileIndex;
CRecordVector<CNum> FileIndexToFolderIndexMap;
void Clear()
{
@@ -58,69 +56,88 @@ struct CArchiveDatabaseEx: public CArchiveDatabase
PackStreamStartPositions.Clear();
FolderStartPackStreamIndex.Clear();
FolderStartFileIndex.Clear();
FolderStartFileIndex.Clear();
FileIndexToFolderIndexMap.Clear();
}
void FillFolderStartPackStream();
void FillStartPos();
void FillFolderStartFileIndex();
void Fill()
{
FillFolderStartPackStream();
FillStartPos();
FillFolderStartFileIndex();
}
UINT64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
{
return ArchiveInfo.DataStartPosition +
PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] +
indexInFolder];
}
UINT64 GetFolderFullPackSize(int folderIndex) const
UInt64 GetFolderFullPackSize(int folderIndex) const
{
UINT32 packStreamIndex = FolderStartPackStreamIndex[folderIndex];
CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
const CFolder &folder = Folders[folderIndex];
UINT64 size = 0;
UInt64 size = 0;
for (int i = 0; i < folder.PackStreams.Size(); i++)
size += PackSizes[packStreamIndex + i];
return size;
}
UINT64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
{
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
}
UInt64 GetFilePackSize(CNum fileIndex) const
{
CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex >= 0)
{
const CFolder &folderInfo = Folders[folderIndex];
if (FolderStartFileIndex[folderIndex] == fileIndex)
return GetFolderFullPackSize(folderIndex);
}
return 0;
}
};
class CInByte2
{
const BYTE *_buffer;
UINT32 _size;
UINT32 _pos;
const Byte *_buffer;
size_t _size;
size_t _pos;
public:
void Init(const BYTE *buffer, UINT32 size)
void Init(const Byte *buffer, size_t size)
{
_buffer = buffer;
_size = size;
_pos = 0;
}
bool ReadByte(BYTE &b)
bool ReadByte(Byte &b)
{
if(_pos >= _size)
return false;
b = _buffer[_pos++];
return true;
}
void ReadBytes(void *data, UINT32 size, UINT32 &processedSize)
void ReadBytes(void *data, size_t size, size_t &processedSize)
{
for(processedSize = 0; processedSize < size && _pos < _size; processedSize++)
((BYTE *)data)[processedSize] = _buffer[_pos++];
((Byte *)data)[processedSize] = _buffer[_pos++];
}
bool ReadBytes(void *data, UINT32 size)
bool ReadBytes(void *data, size_t size)
{
UINT32 processedSize;
size_t processedSize;
ReadBytes(data, size, processedSize);
return (processedSize == size);
}
UINT32 GetProcessedSize() const { return _pos; }
size_t GetProcessedSize() const { return _pos; }
};
class CStreamSwitch;
@@ -129,14 +146,17 @@ class CInArchive
friend class CStreamSwitch;
CMyComPtr<IInStream> _stream;
#ifdef _7Z_VOL
bool _finishSignature;
#endif
CObjectVector<CInByte2> _inByteVector;
CInByte2 *_inByteBack;
UINT64 _arhiveBeginStreamPosition;
UINT64 _position;
UInt64 _arhiveBeginStreamPosition;
UInt64 _position;
void AddByteStream(const BYTE *buffer, UINT32 size)
void AddByteStream(const Byte *buffer, size_t size)
{
_inByteVector.Add(CInByte2());
_inByteBack = &_inByteVector.Back();
@@ -151,62 +171,67 @@ class CInArchive
}
private:
HRESULT FindAndReadSignature(IInStream *stream, const UINT64 *searchHeaderSizeLimit); // S_FALSE means is not archive
HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
#ifdef _7Z_VOL
HRESULT FindFinishSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
#endif
HRESULT ReadFileNames(CObjectVector<CFileItem> &files);
HRESULT ReadBytes(IInStream *stream, void *data, UINT32 size,
UINT32 *processedSize);
HRESULT ReadBytes(void *data, UINT32 size, UINT32 *processedSize);
HRESULT SafeReadBytes(void *data, UINT32 size);
HRESULT ReadDirect(IInStream *stream, void *data, UInt32 size,
UInt32 *processedSize);
HRESULT ReadDirect(void *data, UInt32 size, UInt32 *processedSize);
HRESULT SafeReadDirect(void *data, UInt32 size);
HRESULT SafeReadDirectByte(Byte &b);
HRESULT SafeReadDirectUInt32(UInt32 &value);
HRESULT SafeReadDirectUInt64(UInt64 &value);
HRESULT SafeReadBytes2(void *data, UINT32 size)
HRESULT ReadBytes(void *data, size_t size)
{
if (!_inByteBack->ReadBytes(data, size))
return E_FAIL;
return S_OK;
}
HRESULT SafeReadByte2(BYTE &b)
HRESULT ReadByte(Byte &b)
{
if (!_inByteBack->ReadByte(b))
return E_FAIL;
return S_OK;
}
HRESULT SafeReadWideCharLE(wchar_t &c)
HRESULT ReadWideCharLE(wchar_t &c)
{
BYTE b1;
Byte b1;
if (!_inByteBack->ReadByte(b1))
return E_FAIL;
BYTE b2;
Byte b2;
if (!_inByteBack->ReadByte(b2))
return E_FAIL;
c = (int(b2) << 8) + b1;
c = (wchar_t(b2) << 8) + b1;
return S_OK;
}
HRESULT ReadNumber(UINT64 &value);
HRESULT ReadID(UINT64 &value)
{
return ReadNumber(value);
}
HRESULT ReadNumber(UInt64 &value);
HRESULT ReadNum(CNum &value);
HRESULT ReadID(UInt64 &value) { return ReadNumber(value); }
HRESULT ReadUInt32(UInt32 &value);
HRESULT ReadUInt64(UInt64 &value);
HRESULT SkeepData(UINT64 size);
HRESULT SkeepData(UInt64 size);
HRESULT SkeepData();
HRESULT WaitAttribute(UINT64 attribute);
HRESULT WaitAttribute(UInt64 attribute);
HRESULT ReadArchiveProperties(CInArchiveInfo &archiveInfo);
HRESULT GetNextFolderItem(CFolder &itemInfo);
HRESULT ReadHashDigests(int numItems,
CRecordVector<bool> &digestsDefined, CRecordVector<UINT32> &digests);
CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests);
HRESULT ReadPackInfo(
UINT64 &dataOffset,
CRecordVector<UINT64> &packSizes,
UInt64 &dataOffset,
CRecordVector<UInt64> &packSizes,
CRecordVector<bool> &packCRCsDefined,
CRecordVector<UINT32> &packCRCs);
CRecordVector<UInt32> &packCRCs);
HRESULT ReadUnPackInfo(
const CObjectVector<CByteBuffer> *dataVector,
@@ -214,31 +239,30 @@ private:
HRESULT ReadSubStreamsInfo(
const CObjectVector<CFolder> &folders,
CRecordVector<UINT64> &numUnPackStreamsInFolders,
CRecordVector<UINT64> &unPackSizes,
CRecordVector<CNum> &numUnPackStreamsInFolders,
CRecordVector<UInt64> &unPackSizes,
CRecordVector<bool> &digestsDefined,
CRecordVector<UINT32> &digests);
CRecordVector<UInt32> &digests);
HRESULT CInArchive::ReadStreamsInfo(
const CObjectVector<CByteBuffer> *dataVector,
UINT64 &dataOffset,
CRecordVector<UINT64> &packSizes,
UInt64 &dataOffset,
CRecordVector<UInt64> &packSizes,
CRecordVector<bool> &packCRCsDefined,
CRecordVector<UINT32> &packCRCs,
CRecordVector<UInt32> &packCRCs,
CObjectVector<CFolder> &folders,
CRecordVector<UINT64> &numUnPackStreamsInFolders,
CRecordVector<UINT64> &unPackSizes,
CRecordVector<CNum> &numUnPackStreamsInFolders,
CRecordVector<UInt64> &unPackSizes,
CRecordVector<bool> &digestsDefined,
CRecordVector<UINT32> &digests);
CRecordVector<UInt32> &digests);
HRESULT GetNextFileItem(CFileItem &itemInfo);
HRESULT ReadBoolVector(UINT32 numItems, CBoolVector &vector);
HRESULT ReadBoolVector2(UINT32 numItems, CBoolVector &vector);
HRESULT ReadBoolVector(int numItems, CBoolVector &v);
HRESULT ReadBoolVector2(int numItems, CBoolVector &v);
HRESULT ReadTime(const CObjectVector<CByteBuffer> &dataVector,
CObjectVector<CFileItem> &files, UINT64 type);
HRESULT ReadAndDecodePackedStreams(UINT64 baseOffset, UINT64 &dataOffset,
CObjectVector<CFileItem> &files, UInt64 type);
HRESULT ReadAndDecodePackedStreams(UInt64 baseOffset, UInt64 &dataOffset,
CObjectVector<CByteBuffer> &dataVector
#ifndef _NO_CRYPTO
, ICryptoGetTextPassword *getTextPassword
@@ -250,7 +274,7 @@ private:
#endif
);
public:
HRESULT Open(IInStream *stream, const UINT64 *searchHeaderSizeLimit); // S_FALSE means is not archive
HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
void Close();
HRESULT ReadDatabase(CArchiveDatabaseEx &database
@@ -258,7 +282,6 @@ public:
,ICryptoGetTextPassword *getTextPassword
#endif
);
HRESULT CheckIntegrity();
};
}}