Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2008-08-13 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:56 +0300
commit173c07e166fdf6fcd20f18ea73008f1b628945df (patch)
tree13ebea85cdc4c16ae93714ff0627ee9f91ad7e08 /CPP/7zip/Archive/Rar
parent3901bf0ab88106a5b031cba7bc18d60cdebf7eef (diff)
4.59 beta
Diffstat (limited to 'CPP/7zip/Archive/Rar')
-rwxr-xr-xCPP/7zip/Archive/Rar/RarHandler.cpp131
-rwxr-xr-xCPP/7zip/Archive/Rar/RarHandler.h6
-rwxr-xr-xCPP/7zip/Archive/Rar/RarHeader.h12
-rwxr-xr-xCPP/7zip/Archive/Rar/RarIn.cpp158
-rwxr-xr-xCPP/7zip/Archive/Rar/RarIn.h9
-rwxr-xr-xCPP/7zip/Archive/Rar/RarItem.cpp95
-rwxr-xr-xCPP/7zip/Archive/Rar/RarItem.h68
-rwxr-xr-xCPP/7zip/Archive/Rar/RarVolumeInStream.cpp8
-rwxr-xr-xCPP/7zip/Archive/Rar/RarVolumeInStream.h4
-rwxr-xr-xCPP/7zip/Archive/Rar/rar.icobin3638 -> 0 bytes
10 files changed, 203 insertions, 288 deletions
diff --git a/CPP/7zip/Archive/Rar/RarHandler.cpp b/CPP/7zip/Archive/Rar/RarHandler.cpp
index 435c5c17..c8a20643 100755
--- a/CPP/7zip/Archive/Rar/RarHandler.cpp
+++ b/CPP/7zip/Archive/Rar/RarHandler.cpp
@@ -42,16 +42,16 @@ static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
static const wchar_t *kUnknownOS = L"Unknown";
-STATPROPSTG kProps[] =
+STATPROPSTG kProps[] =
{
{ NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsFolder, VT_BOOL},
+ { NULL, kpidIsDir, VT_BOOL},
{ NULL, kpidSize, VT_UI8},
- { NULL, kpidPackedSize, VT_UI8},
- { NULL, kpidLastWriteTime, VT_FILETIME},
- { NULL, kpidCreationTime, VT_FILETIME},
- { NULL, kpidLastAccessTime, VT_FILETIME},
- { NULL, kpidAttributes, VT_UI4},
+ { NULL, kpidPackSize, VT_UI8},
+ { NULL, kpidMTime, VT_FILETIME},
+ { NULL, kpidCTime, VT_FILETIME},
+ { NULL, kpidATime, VT_FILETIME},
+ { NULL, kpidAttrib, VT_UI4},
{ NULL, kpidEncrypted, VT_BOOL},
{ NULL, kpidSolid, VT_BOOL},
@@ -64,13 +64,14 @@ STATPROPSTG kProps[] =
{ NULL, kpidUnpackVer, VT_UI1}
};
-STATPROPSTG kArcProps[] =
+STATPROPSTG kArcProps[] =
{
{ NULL, kpidSolid, VT_BOOL},
{ NULL, kpidNumBlocks, VT_UI4},
{ NULL, kpidEncrypted, VT_BOOL},
{ NULL, kpidIsVolume, VT_BOOL},
{ NULL, kpidNumVolumes, VT_UI4},
+ { NULL, kpidPhySize, VT_UI8}
// { NULL, kpidCommented, VT_BOOL}
};
@@ -95,18 +96,18 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case kpidSolid: prop = _archiveInfo.IsSolid(); break;
case kpidEncrypted: prop = _archiveInfo.IsEncrypted(); break;
case kpidIsVolume: prop = _archiveInfo.IsVolume(); break;
+ case kpidNumVolumes: prop = (UInt32)_archives.Size(); break;
+ case kpidOffset: if (_archiveInfo.StartPosition != 0) prop = _archiveInfo.StartPosition; break;
+ // case kpidCommented: prop = _archiveInfo.IsCommented(); break;
case kpidNumBlocks:
{
UInt32 numBlocks = 0;
for (int i = 0; i < _refItems.Size(); i++)
if (!IsSolid(i))
numBlocks++;
- prop = (UInt32)numBlocks;
+ prop = (UInt32)numBlocks;
break;
}
- case kpidNumVolumes: prop = (UInt32)_archives.Size();
-
- // case kpidCommented: prop = _archiveInfo.IsCommented(); break;
}
prop.Detach(value);
return S_OK;
@@ -125,7 +126,7 @@ static bool RarTimeToFileTime(const CRarTime &rarTime, FILETIME &result)
return false;
UInt64 value = (((UInt64)result.dwHighDateTime) << 32) + result.dwLowDateTime;
value += (UInt64)rarTime.LowSecond * 10000000;
- value += ((UInt64)rarTime.SubTime[2] << 16) +
+ value += ((UInt64)rarTime.SubTime[2] << 16) +
((UInt64)rarTime.SubTime[1] << 8) +
((UInt64)rarTime.SubTime[0]);
result.dwLowDateTime = (DWORD)value;
@@ -164,13 +165,13 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va
prop = (const wchar_t *)NItemName::WinNameToOSName(u);
break;
}
- case kpidIsFolder: prop = item.IsDirectory(); break;
- case kpidSize: prop = item.UnPackSize; break;
- case kpidPackedSize: prop = GetPackSize(index); break;
- case kpidLastWriteTime: RarTimeToProp(item.LastWriteTime, prop); break;
- case kpidCreationTime: if (item.IsCreationTimeDefined) RarTimeToProp(item.CreationTime, prop); break;
- case kpidLastAccessTime: if (item.IsLastAccessTimeDefined) RarTimeToProp(item.LastAccessTime, prop); break;
- case kpidAttributes: prop = item.GetWinAttributes(); break;
+ case kpidIsDir: prop = item.IsDir(); break;
+ case kpidSize: prop = item.Size; break;
+ case kpidPackSize: prop = GetPackSize(index); break;
+ case kpidMTime: RarTimeToProp(item.MTime, prop); break;
+ case kpidCTime: if (item.CTimeDefined) RarTimeToProp(item.CTime, prop); break;
+ case kpidATime: if (item.ATimeDefined) RarTimeToProp(item.ATime, prop); break;
+ case kpidAttrib: prop = item.GetWinAttributes(); break;
case kpidEncrypted: prop = item.IsEncrypted(); break;
case kpidSolid: prop = IsSolid(index); break;
case kpidCommented: prop = item.IsCommented(); break;
@@ -192,7 +193,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va
wchar_t temp[32];
ConvertUInt64ToString(item.Method - Byte('0'), temp);
method += temp;
- if (!item.IsDirectory())
+ if (!item.IsDir())
{
method += L":";
ConvertUInt64ToString(16 + item.GetDictSize(), temp);
@@ -220,8 +221,8 @@ class CVolumeName
bool _first;
bool _newStyle;
UString _unchangedPart;
- UString _changedPart;
- UString _afterPart;
+ UString _changedPart;
+ UString _afterPart;
public:
CVolumeName(): _newStyle(true) {};
@@ -243,7 +244,7 @@ public:
{
_afterPart = L".rar";
basePart = name.Left(dotPos);
- }
+ }
else if (!_newStyle)
{
if (ext.CompareNoCase(L"000") == 0 || ext.CompareNoCase(L"001") == 0)
@@ -275,7 +276,7 @@ public:
numLetters++;
}
}
- else
+ else
return false;
_unchangedPart = basePart.Left(basePart.Length() - numLetters);
_changedPart = basePart.Right(numLetters);
@@ -284,7 +285,7 @@ public:
UString GetNextName()
{
- UString newName;
+ UString newName;
if (_newStyle || !_first)
{
int i;
@@ -314,13 +315,10 @@ public:
}
};
-STDMETHODIMP CHandler::Open(IInStream *stream,
+HRESULT CHandler::Open2(IInStream *stream,
const UInt64 *maxCheckStartPosition,
IArchiveOpenCallback *openArchiveCallback)
{
- COM_TRY_BEGIN
- Close();
- try
{
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
CMyComPtr<ICryptoGetTextPassword> getTextPassword;
@@ -328,12 +326,12 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
CVolumeName seqName;
+ UInt64 totalBytes = 0;
+ UInt64 curBytes = 0;
+
if (openArchiveCallback != NULL)
{
openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);
- RINOK(openArchiveCallback->SetTotal(NULL, NULL));
- UInt64 numFiles = _items.Size();
- RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
openArchiveCallbackWrap.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
}
@@ -371,10 +369,18 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
}
else
inStream = stream;
+
+ UInt64 endPos = 0;
+ if (openArchiveCallback != NULL)
+ {
+ RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
+ totalBytes += endPos;
+ RINOK(openArchiveCallback->SetTotal(NULL, &totalBytes));
+ }
NArchive::NRar::CInArchive archive;
- if(!archive.Open(inStream, maxCheckStartPosition))
- return S_FALSE;
+ RINOK(archive.Open(inStream, maxCheckStartPosition));
if (_archives.IsEmpty())
archive.GetArchiveInfo(_archiveInfo);
@@ -408,20 +414,35 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
_refItems.Add(refItem);
}
_items.Add(item);
- if (openArchiveCallback != NULL)
+ if (openArchiveCallback != NULL && _items.Size() % 100 == 0)
{
UInt64 numFiles = _items.Size();
- RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
+ UInt64 numBytes = curBytes + item.Position;
+ RINOK(openArchiveCallback->SetCompleted(&numFiles, &numBytes));
}
}
+ curBytes += endPos;
_archives.Add(archive);
}
}
- catch(...)
+ return S_OK;
+}
+
+STDMETHODIMP CHandler::Open(IInStream *stream,
+ const UInt64 *maxCheckStartPosition,
+ IArchiveOpenCallback *openArchiveCallback)
+{
+ COM_TRY_BEGIN
+ Close();
+ try
{
- return S_FALSE;
+ HRESULT res = Open2(stream, maxCheckStartPosition, openArchiveCallback);
+ if (res != S_OK)
+ Close();
+ return res;
}
- return S_OK;
+ catch(const CInArchiveException &) { Close(); return S_FALSE; }
+ catch(...) { Close(); throw; }
COM_TRY_END
}
@@ -449,9 +470,9 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
CMyComPtr<ICryptoGetTextPassword> getTextPassword;
bool testMode = (_aTestMode != 0);
CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;
- UInt64 censoredTotalUnPacked = 0,
+ UInt64 censoredTotalUnPacked = 0,
// censoredTotalPacked = 0,
- importantTotalUnPacked = 0;
+ importantTotalUnPacked = 0;
// importantTotalPacked = 0;
bool allFilesMode = (numItems == UInt32(-1));
if (allFilesMode)
@@ -467,7 +488,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
int index = allFilesMode ? t : indices[t];
const CRefItem &refItem = _refItems[index];
const CItemEx &item = _items[refItem.ItemIndex];
- censoredTotalUnPacked += item.UnPackSize;
+ censoredTotalUnPacked += item.Size;
// censoredTotalPacked += item.PackSize;
int j;
for(j = lastIndex; j <= index; j++)
@@ -481,7 +502,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
// const CItemEx &item = _items[j];
- importantTotalUnPacked += item.UnPackSize;
+ importantTotalUnPacked += item.Size;
// importantTotalPacked += item.PackSize;
importantIndexes.Add(j);
extractStatuses.Add(j == index);
@@ -515,7 +536,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
lps->Init(extractCallback, false);
bool solidStart = true;
- for(int i = 0; i < importantIndexes.Size(); i++,
+ for(int i = 0; i < importantIndexes.Size(); i++,
currentImportantTotalUnPacked += currentUnPackSize,
currentImportantTotalPacked += currentPackSize)
{
@@ -526,7 +547,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
Int32 askMode;
if(extractStatuses[i])
- askMode = testMode ?
+ askMode = testMode ?
NArchive::NExtract::NAskMode::kTest :
NArchive::NExtract::NAskMode::kExtract;
else
@@ -537,7 +558,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
const CRefItem &refItem = _refItems[index];
const CItemEx &item = _items[refItem.ItemIndex];
- currentUnPackSize = item.UnPackSize;
+ currentUnPackSize = item.Size;
currentPackSize = GetPackSize(index);
@@ -548,7 +569,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
if (!IsSolid(index))
solidStart = true;
- if(item.IsDirectory())
+ if(item.IsDir())
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
@@ -618,7 +639,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
}
rar29CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
CMyComPtr<ICompressSetDecoderProperties2> cryptoProperties;
- RINOK(rar29CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
+ RINOK(rar29CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
&cryptoProperties));
RINOK(cryptoProperties->SetDecoderProperties2(item.Salt, item.HasSalt() ? sizeof(item.Salt) : 0));
filterStreamSpec->Filter = rar29CryptoDecoder;
@@ -639,11 +660,11 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
continue;
}
- RINOK(filterStreamSpec->Filter.QueryInterface(IID_ICryptoSetPassword,
+ RINOK(filterStreamSpec->Filter.QueryInterface(IID_ICryptoSetPassword,
&cryptoSetPassword));
if (!getTextPassword)
- extractCallback.QueryInterface(IID_ICryptoGetTextPassword,
+ extractCallback.QueryInterface(IID_ICryptoGetTextPassword,
&getTextPassword);
if (getTextPassword)
{
@@ -722,7 +743,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
methodID += 1;
else if (item.UnPackVersion < 29)
methodID += 2;
- else
+ else
methodID += 3;
RINOK(CreateCoder(EXTERNAL_CODECS_VARS methodID, mi.Coder, false));
}
@@ -739,7 +760,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
CMyComPtr<ICompressCoder> decoder = methodItems[m].Coder;
CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;
- RINOK(decoder.QueryInterface(IID_ICompressSetDecoderProperties2,
+ RINOK(decoder.QueryInterface(IID_ICompressSetDecoderProperties2,
&compressSetDecoderProperties));
Byte isSolid = (Byte)((IsSolid(index) || item.IsSplitBefore()) ? 1: 0);
@@ -760,7 +781,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
continue;
}
- HRESULT result = commonCoder->Code(inStream, outStream, &packSize, &item.UnPackSize, progress);
+ HRESULT result = commonCoder->Code(inStream, outStream, &packSize, &item.Size, progress);
if (item.IsEncrypted())
filterStreamSpec->ReleaseInStream();
if (result == S_FALSE)
@@ -773,7 +794,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
return result;
/*
- if (refItem.NumItems == 1 &&
+ if (refItem.NumItems == 1 &&
!item.IsSplitBefore() && !item.IsSplitAfter())
*/
{
diff --git a/CPP/7zip/Archive/Rar/RarHandler.h b/CPP/7zip/Archive/Rar/RarHandler.h
index 811802a9..58e3fefc 100755
--- a/CPP/7zip/Archive/Rar/RarHandler.h
+++ b/CPP/7zip/Archive/Rar/RarHandler.h
@@ -12,7 +12,7 @@
namespace NArchive {
namespace NRar {
-class CHandler:
+class CHandler:
public IInArchive,
PUBLIC_ISetCompressCodecsInfo
public CMyUnknownImp
@@ -49,6 +49,10 @@ private:
}
return item.IsSolid();
}
+
+ HRESULT Open2(IInStream *stream,
+ const UInt64 *maxCheckStartPosition,
+ IArchiveOpenCallback *openArchiveCallback);
};
}}
diff --git a/CPP/7zip/Archive/Rar/RarHeader.h b/CPP/7zip/Archive/Rar/RarHeader.h
index 832a21c0..4df42e62 100755
--- a/CPP/7zip/Archive/Rar/RarHeader.h
+++ b/CPP/7zip/Archive/Rar/RarHeader.h
@@ -17,7 +17,7 @@ const int kArchiveSolid = 0x1;
namespace NBlockType
{
enum EBlockType
- {
+ {
kMarker = 0x72,
kArchiveHeader = 0x73,
kFileHeader = 0x74,
@@ -129,7 +129,7 @@ namespace NFile
Byte Method;
UInt16 NameSize;
UInt32 Attributes;
- UInt16 GetRealCRC(const void *aName, UInt32 aNameSize,
+ UInt16 GetRealCRC(const void *aName, UInt32 aNameSize,
bool anExtraDataDefined = false, Byte *anExtraData = 0) const;
};
struct CBlock64
@@ -157,10 +157,10 @@ namespace NFile
const int kWinFileDirectoryAttributeMask = 0x10;
enum CHostOS
- {
- kHostMSDOS = 0,
- kHostOS2 = 1,
- kHostWin32 = 2,
+ {
+ kHostMSDOS = 0,
+ kHostOS2 = 1,
+ kHostWin32 = 2,
kHostUnix = 3,
kHostMacOS = 4,
kHostBeOS = 5
diff --git a/CPP/7zip/Archive/Rar/RarIn.cpp b/CPP/7zip/Archive/Rar/RarIn.cpp
index efb87fb7..18669405 100755
--- a/CPP/7zip/Archive/Rar/RarIn.cpp
+++ b/CPP/7zip/Archive/Rar/RarIn.cpp
@@ -9,9 +9,11 @@
#include "../../Common/LimitedStreams.h"
#include "../../Common/StreamUtils.h"
-extern "C"
-{
- #include "../../../../C/7zCrc.h"
+#include "../Common/FindSignature.h"
+
+extern "C"
+{
+ #include "../../../../C/7zCrc.h"
}
namespace NArchive {
@@ -23,17 +25,18 @@ void CInArchive::ThrowExceptionWithCode(
throw CInArchiveException(cause);
}
-bool CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit)
+HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit)
{
- m_CryptoMode = false;
- if(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition) != S_OK)
- return false;
- m_Position = m_StreamStartPosition;
- m_Stream = inStream;
- if (ReadMarkerAndArchiveHeader(searchHeaderSizeLimit))
- return true;
- m_Stream.Release();
- return false;
+ try
+ {
+ Close();
+ HRESULT res = Open2(inStream, searchHeaderSizeLimit);
+ if (res == S_OK)
+ return res;
+ Close();
+ return res;
+ }
+ catch(...) { Close(); throw; }
}
void CInArchive::Close()
@@ -50,56 +53,14 @@ static inline bool TestMarkerCandidate(const void *aTestBytes)
return true;
}
-bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit)
+HRESULT CInArchive::FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
- // if (m_Length < NHeader::kMarkerSize)
- // return false;
- m_ArchiveStartPosition = 0;
- m_Position = m_StreamStartPosition;
- if(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL) != S_OK)
- return false;
-
- Byte marker[NHeader::kMarkerSize];
- UInt32 processedSize;
- ReadBytes(marker, NHeader::kMarkerSize, &processedSize);
- if(processedSize != NHeader::kMarkerSize)
- return false;
- if (TestMarkerCandidate(marker))
- return true;
-
- CByteDynamicBuffer dynamicBuffer;
- static const UInt32 kSearchMarkerBufferSize = 0x10000;
- dynamicBuffer.EnsureCapacity(kSearchMarkerBufferSize);
- Byte *buffer = dynamicBuffer;
- UInt32 numBytesPrev = NHeader::kMarkerSize - 1;
- memmove(buffer, marker + 1, numBytesPrev);
- UInt64 curTestPos = m_StreamStartPosition + 1;
- for (;;)
- {
- if (searchHeaderSizeLimit != NULL)
- if (curTestPos - m_StreamStartPosition > *searchHeaderSizeLimit)
- break;
- UInt32 numReadBytes = kSearchMarkerBufferSize - numBytesPrev;
- ReadBytes(buffer + numBytesPrev, numReadBytes, &processedSize);
- UInt32 numBytesInBuffer = numBytesPrev + processedSize;
- if (numBytesInBuffer < NHeader::kMarkerSize)
- break;
- UInt32 numTests = numBytesInBuffer - NHeader::kMarkerSize + 1;
- for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++)
- {
- if (TestMarkerCandidate(buffer + pos))
- {
- m_ArchiveStartPosition = curTestPos;
- m_Position = curTestPos + NHeader::kMarkerSize;
- if(m_Stream->Seek(m_Position, STREAM_SEEK_SET, NULL) != S_OK)
- return false;
- return true;
- }
- }
- numBytesPrev = numBytesInBuffer - numTests;
- memmove(buffer, buffer + numTests, numBytesPrev);
- }
- return false;
+ RINOK(FindSignatureInStream(stream,
+ NHeader::kMarker, NHeader::kMarkerSize,
+ searchHeaderSizeLimit, m_ArchiveStartPosition));
+ m_Stream = stream;
+ m_Position = m_ArchiveStartPosition + NHeader::kMarkerSize;
+ return m_Stream->Seek(m_Position, STREAM_SEEK_SET, NULL);
}
void CInArchive::ThrowUnexpectedEndOfArchiveException()
@@ -154,18 +115,21 @@ static UInt32 CrcUpdateUInt32(UInt32 crc, UInt32 v)
}
-bool CInArchive::ReadMarkerAndArchiveHeader(const UInt64 *searchHeaderSizeLimit)
+HRESULT CInArchive::Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
- if (!FindAndReadMarker(searchHeaderSizeLimit))
- return false;
+ m_CryptoMode = false;
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, &m_StreamStartPosition));
+ m_Position = m_StreamStartPosition;
+
+ RINOK(FindAndReadMarker(stream, searchHeaderSizeLimit));
Byte buf[NHeader::NArchive::kArchiveHeaderSize];
UInt32 processedSize;
ReadBytes(buf, sizeof(buf), &processedSize);
if (processedSize != sizeof(buf))
- return false;
+ return S_FALSE;
m_CurData = buf;
- m_CurPos = 0;
+ m_CurPos = 0;
m_PosLimit = sizeof(buf);
m_ArchiveHeader.CRC = ReadUInt16();
@@ -187,17 +151,17 @@ bool CInArchive::ReadMarkerAndArchiveHeader(const UInt64 *searchHeaderSizeLimit)
{
ReadBytes(&m_ArchiveHeader.EncryptVersion, 1, &processedSize);
if (processedSize != 1)
- return false;
+ return S_FALSE;
crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.EncryptVersion);
}
if(m_ArchiveHeader.CRC != (CRC_GET_DIGEST(crc) & 0xFFFF))
ThrowExceptionWithCode(CInArchiveException::kArchiveHeaderCRCError);
if (m_ArchiveHeader.Type != NHeader::NBlockType::kArchiveHeader)
- return false;
+ return S_FALSE;
m_ArchiveCommentPosition = m_Position;
m_SeekOnArchiveComment = true;
- return true;
+ return S_OK;
}
void CInArchive::SkipArchiveComment()
@@ -216,7 +180,7 @@ void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const
archiveInfo.CommentSize = (UInt16)(m_ArchiveHeader.Size - NHeader::NArchive::kArchiveHeaderSize);
}
-static void DecodeUnicodeFileName(const char *name, const Byte *encName,
+static void DecodeUnicodeFileName(const char *name, const Byte *encName,
int encSize, wchar_t *unicodeName, int maxDecSize)
{
int encPos = 0;
@@ -249,7 +213,7 @@ static void DecodeUnicodeFileName(const char *name, const Byte *encName,
if (length & 0x80)
{
Byte correction = encName[encPos++];
- for (length = (length & 0x7f) + 2;
+ for (length = (length & 0x7f) + 2;
length > 0 && decPos < maxDecSize; length--, decPos++)
unicodeName[decPos] = (wchar_t)(((name[decPos] + correction) & 0xff) + (highByte << 8));
}
@@ -289,7 +253,7 @@ void CInArchive::ReadName(CItemEx &item, int nameSize)
{
int unicodeNameSizeMax = MyMin(nameSize, (0x400));
_unicodeNameBuffer.EnsureCapacity(unicodeNameSizeMax + 1);
- DecodeUnicodeFileName(buffer, (const Byte *)buffer + mainLen + 1,
+ DecodeUnicodeFileName(buffer, (const Byte *)buffer + mainLen + 1,
nameSize - (mainLen + 1), _unicodeNameBuffer, unicodeNameSizeMax);
item.UnicodeName = _unicodeNameBuffer;
}
@@ -341,26 +305,26 @@ void CInArchive::ReadTime(Byte mask, CRarTime &rarTime)
void CInArchive::ReadHeaderReal(CItemEx &item)
{
- item.Flags = m_BlockHeader.Flags;
+ item.Flags = m_BlockHeader.Flags;
item.PackSize = ReadUInt32();
- item.UnPackSize = ReadUInt32();
+ item.Size = ReadUInt32();
item.HostOS = ReadByte();
item.FileCRC = ReadUInt32();
- item.LastWriteTime.DosTime = ReadUInt32();
+ item.MTime.DosTime = ReadUInt32();
item.UnPackVersion = ReadByte();
item.Method = ReadByte();
int nameSize = ReadUInt16();
- item.Attributes = ReadUInt32();
+ item.Attrib = ReadUInt32();
- item.LastWriteTime.LowSecond = 0;
- item.LastWriteTime.SubTime[0] =
- item.LastWriteTime.SubTime[1] =
- item.LastWriteTime.SubTime[2] = 0;
+ item.MTime.LowSecond = 0;
+ item.MTime.SubTime[0] =
+ item.MTime.SubTime[1] =
+ item.MTime.SubTime[2] = 0;
if((item.Flags & NHeader::NFile::kSize64Bits) != 0)
{
item.PackSize |= ((UInt64)ReadUInt32() << 32);
- item.UnPackSize |= ((UInt64)ReadUInt32() << 32);
+ item.Size |= ((UInt64)ReadUInt32() << 32);
}
ReadName(item, nameSize);
@@ -377,18 +341,18 @@ void CInArchive::ReadHeaderReal(CItemEx &item)
Byte modifMask = (Byte)(b >> 4);
Byte createMask = (Byte)(b & 0xF);
if ((modifMask & 8) != 0)
- ReadTime(modifMask, item.LastWriteTime);
- item.IsCreationTimeDefined = ((createMask & 8) != 0);
- if (item.IsCreationTimeDefined)
+ ReadTime(modifMask, item.MTime);
+ item.CTimeDefined = ((createMask & 8) != 0);
+ if (item.CTimeDefined)
{
- item.CreationTime.DosTime = ReadUInt32();
- ReadTime(createMask, item.CreationTime);
+ item.CTime.DosTime = ReadUInt32();
+ ReadTime(createMask, item.CTime);
}
- item.IsLastAccessTimeDefined = ((accessMask & 8) != 0);
- if (item.IsLastAccessTimeDefined)
+ item.ATimeDefined = ((accessMask & 8) != 0);
+ if (item.ATimeDefined)
{
- item.LastAccessTime.DosTime = ReadUInt32();
- ReadTime(accessMask, item.LastAccessTime);
+ item.ATime.DosTime = ReadUInt32();
+ ReadTime(accessMask, item.ATime);
}
}
@@ -418,7 +382,7 @@ HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPa
{
if(!SeekInArchive(m_Position))
return S_FALSE;
- if (!m_CryptoMode && (m_ArchiveHeader.Flags &
+ if (!m_CryptoMode && (m_ArchiveHeader.Flags &
NHeader::NArchive::kBlockHeadersAreEncrypted) != 0)
{
m_CryptoMode = false;
@@ -487,23 +451,23 @@ HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPa
if (m_BlockHeader.HeadSize < 7)
ThrowExceptionWithCode(CInArchiveException::kIncorrectArchive);
- if (m_BlockHeader.Type == NHeader::NBlockType::kEndOfArchive)
+ if (m_BlockHeader.Type == NHeader::NBlockType::kEndOfArchive)
return S_FALSE;
- if (m_BlockHeader.Type == NHeader::NBlockType::kFileHeader)
+ if (m_BlockHeader.Type == NHeader::NBlockType::kFileHeader)
{
m_FileHeaderData.EnsureCapacity(m_BlockHeader.HeadSize);
m_CurData = (Byte *)m_FileHeaderData;
m_PosLimit = m_BlockHeader.HeadSize;
ReadBytesAndTestResult(m_CurData + m_CurPos, m_BlockHeader.HeadSize - 7);
- ReadHeaderReal(item);
- if ((CrcCalc(m_CurData + 2,
+ ReadHeaderReal(item);
+ if ((CrcCalc(m_CurData + 2,
m_BlockHeader.HeadSize - item.CommentSize - 2) & 0xFFFF) != m_BlockHeader.CRC)
ThrowExceptionWithCode(CInArchiveException::kFileHeaderCRCError);
FinishCryptoBlock();
m_CryptoMode = false;
- SeekInArchive(m_Position); // Move Position to compressed Data;
+ SeekInArchive(m_Position); // Move Position to compressed Data;
AddToSeekValue(item.PackSize); // m_Position points to next header;
return S_OK;
}
diff --git a/CPP/7zip/Archive/Rar/RarIn.h b/CPP/7zip/Archive/Rar/RarIn.h
index 94cea223..7be3f53c 100755
--- a/CPP/7zip/Archive/Rar/RarIn.h
+++ b/CPP/7zip/Archive/Rar/RarIn.h
@@ -24,7 +24,7 @@ public:
kArchiveHeaderCRCError,
kFileHeaderCRCError,
kIncorrectArchive
- }
+ }
Cause;
CInArchiveException(CCauseType cause) : Cause(cause) {}
};
@@ -64,7 +64,9 @@ class CInArchive
bool ReadBytesAndTestSize(void *data, UInt32 size);
void ReadBytesAndTestResult(void *data, UInt32 size);
- bool FindAndReadMarker(const UInt64 *searchHeaderSizeLimit);
+ HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
+ HRESULT Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
+
void ThrowExceptionWithCode(CInArchiveException::CCauseType cause);
void ThrowUnexpectedEndOfArchiveException();
@@ -102,9 +104,8 @@ protected:
}
}
- bool ReadMarkerAndArchiveHeader(const UInt64 *searchHeaderSizeLimit);
public:
- bool Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit);
+ HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit);
void Close();
HRESULT GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPassword);
diff --git a/CPP/7zip/Archive/Rar/RarItem.cpp b/CPP/7zip/Archive/Rar/RarItem.cpp
index 61a72557..9216ae57 100755
--- a/CPP/7zip/Archive/Rar/RarItem.cpp
+++ b/CPP/7zip/Archive/Rar/RarItem.cpp
@@ -3,47 +3,24 @@
#include "StdAfx.h"
#include "RarItem.h"
-#include "RarHeader.h"
namespace NArchive{
namespace NRar{
-bool CItem::IsEncrypted() const
- { return (Flags & NHeader::NFile::kEncrypted) != 0; }
-bool CItem::IsSolid() const
- { return (Flags & NHeader::NFile::kSolid) != 0; }
-bool CItem::IsCommented() const
- { return (Flags & NHeader::NFile::kComment) != 0; }
-bool CItem::IsSplitBefore() const
- { return (Flags & NHeader::NFile::kSplitBefore) != 0; }
-bool CItem::IsSplitAfter() const
- { return (Flags & NHeader::NFile::kSplitAfter) != 0; }
-bool CItem::HasSalt() const
- { return (Flags & NHeader::NFile::kSalt) != 0; }
-bool CItem::HasExtTime() const
- { return (Flags & NHeader::NFile::kExtTime) != 0; }
-bool CItem::HasUnicodeName() const
- { return (Flags & NHeader::NFile::kUnicodeName) != 0; }
-bool CItem::IsOldVersion() const
- { return (Flags & NHeader::NFile::kOldVersion) != 0; }
-
bool CItem::IgnoreItem() const
-{
+{
switch(HostOS)
{
- case NHeader::NFile::kHostMSDOS:
- case NHeader::NFile::kHostOS2:
- case NHeader::NFile::kHostWin32:
- return ((Attributes & NHeader::NFile::kLabelFileAttribute) != 0);
+ case NHeader::NFile::kHostMSDOS:
+ case NHeader::NFile::kHostOS2:
+ case NHeader::NFile::kHostWin32:
+ return ((Attrib & NHeader::NFile::kLabelFileAttribute) != 0);
}
return false;
}
-UInt32 CItem::GetDictSize() const
-{ return (Flags >> NHeader::NFile::kDictBitStart) & NHeader::NFile::kDictMask; }
-
-bool CItem::IsDirectory() const
-{
+bool CItem::IsDir() const
+{
if (GetDictSize() == NHeader::NFile::kDictDirectoryValue)
return true;
switch(HostOS)
@@ -51,7 +28,7 @@ bool CItem::IsDirectory() const
case NHeader::NFile::kHostMSDOS:
case NHeader::NFile::kHostOS2:
case NHeader::NFile::kHostWin32:
- if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+ if ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)
return true;
}
return false;
@@ -62,57 +39,17 @@ UInt32 CItem::GetWinAttributes() const
UInt32 winAttributes;
switch(HostOS)
{
- case NHeader::NFile::kHostMSDOS:
- case NHeader::NFile::kHostOS2:
- case NHeader::NFile::kHostWin32:
- winAttributes = Attributes;
- break;
- default:
- winAttributes = 0; // must be converted from unix value;;
+ case NHeader::NFile::kHostMSDOS:
+ case NHeader::NFile::kHostOS2:
+ case NHeader::NFile::kHostWin32:
+ winAttributes = Attrib;
+ break;
+ default:
+ winAttributes = 0; // must be converted from unix value;
}
- if (IsDirectory()) // test it;
+ if (IsDir())
winAttributes |= NHeader::NFile::kWinFileDirectoryAttributeMask;
return winAttributes;
}
-void CItem::ClearFlags()
-{ Flags = 0; }
-
-void CItem::SetFlagBits(int startBitNumber, int numBits, int value)
-{
- UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber);
- Flags &= ~mask;
- Flags |= value << startBitNumber;
-}
-
-void CItem::SetBitMask(int bitMask, bool enable)
-{
- if(enable)
- Flags |= bitMask;
- else
- Flags &= ~bitMask;
-}
-
-void CItem::SetDictSize(UInt32 size)
-{
- SetFlagBits(NHeader::NFile::kDictBitStart, NHeader::NFile::kNumDictBits, (size & NHeader::NFile::kDictMask));
-}
-
-void CItem::SetAsDirectory(bool directory)
-{
- if (directory)
- SetDictSize(NHeader::NFile::kDictDirectoryValue);
-}
-
-void CItem::SetEncrypted(bool encrypted)
- { SetBitMask(NHeader::NFile::kEncrypted, encrypted); }
-void CItem::SetSolid(bool solid)
- { SetBitMask(NHeader::NFile::kSolid, solid); }
-void CItem::SetCommented(bool commented)
- { SetBitMask(NHeader::NFile::kComment, commented); }
-void CItem::SetSplitBefore(bool splitBefore)
- { SetBitMask(NHeader::NFile::kSplitBefore, splitBefore); }
-void CItem::SetSplitAfter(bool splitAfter)
- { SetBitMask(NHeader::NFile::kSplitAfter, splitAfter); }
-
}}
diff --git a/CPP/7zip/Archive/Rar/RarItem.h b/CPP/7zip/Archive/Rar/RarItem.h
index 5ab8a46e..4aa4d866 100755
--- a/CPP/7zip/Archive/Rar/RarItem.h
+++ b/CPP/7zip/Archive/Rar/RarItem.h
@@ -6,6 +6,8 @@
#include "Common/Types.h"
#include "Common/MyString.h"
+#include "RarHeader.h"
+
namespace NArchive{
namespace NRar{
@@ -16,59 +18,47 @@ struct CRarTime
Byte SubTime[3];
};
-class CItem
+struct CItem
{
-public:
- UInt16 Flags;
+ UInt64 Size;
UInt64 PackSize;
- UInt64 UnPackSize;
- Byte HostOS;
- UInt32 FileCRC;
- CRarTime CreationTime;
- CRarTime LastWriteTime;
- CRarTime LastAccessTime;
- bool IsCreationTimeDefined;
- // bool IsLastWriteTimeDefined;
- bool IsLastAccessTimeDefined;
+ CRarTime CTime;
+ CRarTime ATime;
+ CRarTime MTime;
+
+ UInt32 FileCRC;
+ UInt32 Attrib;
+ UInt16 Flags;
+ Byte HostOS;
Byte UnPackVersion;
Byte Method;
- UInt32 Attributes;
+
+ bool CTimeDefined;
+ bool ATimeDefined;
+
AString Name;
UString UnicodeName;
Byte Salt[8];
- bool IsEncrypted() const;
- bool IsSolid() const;
- bool IsCommented() const;
- bool IsSplitBefore() const;
- bool IsSplitAfter() const;
- bool HasSalt() const;
- bool HasExtTime() const;
-
- bool HasUnicodeName() const;
- bool IsOldVersion() const;
+ bool IsEncrypted() const { return (Flags & NHeader::NFile::kEncrypted) != 0; }
+ bool IsSolid() const { return (Flags & NHeader::NFile::kSolid) != 0; }
+ bool IsCommented() const { return (Flags & NHeader::NFile::kComment) != 0; }
+ bool IsSplitBefore() const { return (Flags & NHeader::NFile::kSplitBefore) != 0; }
+ bool IsSplitAfter() const { return (Flags & NHeader::NFile::kSplitAfter) != 0; }
+ bool HasSalt() const { return (Flags & NHeader::NFile::kSalt) != 0; }
+ bool HasExtTime() const { return (Flags & NHeader::NFile::kExtTime) != 0; }
+ bool HasUnicodeName()const { return (Flags & NHeader::NFile::kUnicodeName) != 0; }
+ bool IsOldVersion() const { return (Flags & NHeader::NFile::kOldVersion) != 0; }
- UInt32 GetDictSize() const;
- bool IsDirectory() const;
+ UInt32 GetDictSize() const { return (Flags >> NHeader::NFile::kDictBitStart) & NHeader::NFile::kDictMask; }
+ bool IsDir() const;
bool IgnoreItem() const;
UInt32 GetWinAttributes() const;
- CItem(): IsCreationTimeDefined(false), IsLastAccessTimeDefined(false) {}
-private:
- void SetFlagBits(int startBitNumber, int numBits, int value);
- void SetBitMask(int bitMask, bool enable);
-public:
- void ClearFlags();
- void SetDictSize(UInt32 size);
- void SetAsDirectory(bool directory);
- void SetEncrypted(bool encrypted);
- void SetSolid(bool solid);
- void SetCommented(bool commented);
- void SetSplitBefore(bool splitBefore);
- void SetSplitAfter(bool splitAfter);
+ CItem(): CTimeDefined(false), ATimeDefined(false) {}
};
class CItemEx: public CItem
@@ -87,5 +77,3 @@ public:
}}
#endif
-
-
diff --git a/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp b/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp
index aeb52ecc..1845e20a 100755
--- a/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp
+++ b/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp
@@ -7,16 +7,16 @@
#include "Windows/Defs.h"
#include "Common/Defs.h"
-extern "C"
-{
- #include "../../../../C/7zCrc.h"
+extern "C"
+{
+ #include "../../../../C/7zCrc.h"
}
namespace NArchive {
namespace NRar {
void CFolderInStream::Init(
- CObjectVector<CInArchive> *archives,
+ CObjectVector<CInArchive> *archives,
const CObjectVector<CItemEx> *items,
const CRefItem &refItem)
{
diff --git a/CPP/7zip/Archive/Rar/RarVolumeInStream.h b/CPP/7zip/Archive/Rar/RarVolumeInStream.h
index 7c5902b5..78d95b10 100755
--- a/CPP/7zip/Archive/Rar/RarVolumeInStream.h
+++ b/CPP/7zip/Archive/Rar/RarVolumeInStream.h
@@ -16,7 +16,7 @@ struct CRefItem
int NumItems;
};
-class CFolderInStream:
+class CFolderInStream:
public ISequentialInStream,
public CMyUnknownImp
{
@@ -37,7 +37,7 @@ private:
HRESULT OpenStream();
HRESULT CloseStream();
public:
- void Init(CObjectVector<CInArchive> *archives,
+ void Init(CObjectVector<CInArchive> *archives,
const CObjectVector<CItemEx> *items,
const CRefItem &refItem);
diff --git a/CPP/7zip/Archive/Rar/rar.ico b/CPP/7zip/Archive/Rar/rar.ico
deleted file mode 100755
index 2918d294..00000000
--- a/CPP/7zip/Archive/Rar/rar.ico
+++ /dev/null
Binary files differ