This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -8,6 +8,7 @@
#include "../../Common/LimitedStreams.h"
#include "../../Common/ProgressUtils.h"
#include "../../Common/StreamUtils.h"
#include "../../Compress/CopyCoder.h"
@@ -48,28 +49,28 @@ static const Byte kArcProps[] =
IMP_IInArchive_Props
IMP_IInArchive_ArcProps
STDMETHODIMP CHandler::Open(IInStream *stream,
Z7_COM7F_IMF(CHandler::Open(IInStream *stream,
const UInt64 * /* maxCheckStartPosition */,
IArchiveOpenCallback * /* openArchiveCallback */)
IArchiveOpenCallback * /* openArchiveCallback */))
{
COM_TRY_BEGIN
Close();
{
RINOK(_archive.Open(stream));
RINOK(_archive.Open(stream))
_stream = stream;
}
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::Close()
Z7_COM7F_IMF(CHandler::Close())
{
_archive.Clear();
_stream.Release();
return S_OK;
}
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
{
*numItems = _archive.Refs.Size() + _archive.BootEntries.Size();
return S_OK;
@@ -100,7 +101,7 @@ static void AddErrorMessage(AString &s, const char *message)
s += message;
}
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -161,7 +162,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
COM_TRY_END
}
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -177,7 +178,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
if (_archive.BootEntries.Size() != 1)
{
s.Add_UInt32(index + 1);
s += '-';
s.Add_Minus();
}
s += be.GetName();
prop = s;
@@ -303,11 +304,11 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
COM_TRY_END
}
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback)
Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback))
{
COM_TRY_BEGIN
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
if (allFilesMode)
numItems = _archive.Refs.Size();
if (numItems == 0)
@@ -346,15 +347,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
{
lps->InSize = lps->OutSize = currentTotalSize;
RINOK(lps->SetCur());
RINOK(lps->SetCur())
currentItemSize = 0;
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ?
const Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
UInt32 index = allFilesMode ? i : indices[i];
const UInt32 index = allFilesMode ? i : indices[i];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
UInt64 blockIndex;
if (index < (UInt32)_archive.Refs.Size())
@@ -363,8 +364,8 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
const CDir &item = ref.Dir->_subItems[ref.Index];
if (item.IsDir())
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
RINOK(extractCallback->PrepareOperation(askMode))
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
continue;
}
currentItemSize = ref.TotalSize;
@@ -382,7 +383,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (!testMode && !realOutStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->PrepareOperation(askMode))
bool isOK = true;
if (index < (UInt32)_archive.Refs.Size())
@@ -395,9 +396,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (item2.Size == 0)
continue;
lps->InSize = lps->OutSize = currentTotalSize + offset;
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * kBlockSize, STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(_stream, (UInt64)item2.ExtentLocation * kBlockSize))
streamSpec->Init(item2.Size);
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress))
if (copyCoderSpec->TotalSize != item2.Size)
{
isOK = false;
@@ -408,25 +409,25 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
else
{
RINOK(_stream->Seek((UInt64)blockIndex * kBlockSize, STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(_stream, (UInt64)blockIndex * kBlockSize))
streamSpec->Init(currentItemSize);
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress))
if (copyCoderSpec->TotalSize != currentItemSize)
isOK = false;
}
realOutStream.Release();
RINOK(extractCallback->SetOperationResult(isOK ?
NExtract::NOperationResult::kOK:
NExtract::NOperationResult::kDataError));
NExtract::NOperationResult::kDataError))
}
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
{
COM_TRY_BEGIN
*stream = 0;
*stream = NULL;
UInt64 blockIndex;
UInt64 currentItemSize;

View File

@@ -1,29 +1,22 @@
// IsoHandler.h
#ifndef __ISO_HANDLER_H
#define __ISO_HANDLER_H
#ifndef ZIP7_INC_ISO_HANDLER_H
#define ZIP7_INC_ISO_HANDLER_H
#include "../../../Common/MyCom.h"
#include "../IArchive.h"
#include "IsoIn.h"
#include "IsoItem.h"
namespace NArchive {
namespace NIso {
class CHandler:
public IInArchive,
public IInArchiveGetStream,
public CMyUnknownImp
{
Z7_CLASS_IMP_CHandler_IInArchive_1(
IInArchiveGetStream
)
CMyComPtr<IInStream> _stream;
CInArchive _archive;
public:
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
INTERFACE_IInArchive(;)
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
};
}}

View File

@@ -1,7 +1,7 @@
// Archive/IsoHeader.h
#ifndef __ARCHIVE_ISO_HEADER_H
#define __ARCHIVE_ISO_HEADER_H
#ifndef ZIP7_INC_ARCHIVE_ISO_HEADER_H
#define ZIP7_INC_ARCHIVE_ISO_HEADER_H
#include "../../../Common/MyTypes.h"

View File

@@ -48,9 +48,9 @@ bool CBootInitialEntry::Parse(const Byte *p)
AString CBootInitialEntry::GetName() const
{
AString s (Bootable ? "Boot" : "NotBoot");
s += '-';
s.Add_Minus();
if (BootMediaType < ARRAY_SIZE(kMediaTypes))
if (BootMediaType < Z7_ARRAY_SIZE(kMediaTypes))
s += kMediaTypes[BootMediaType];
else
s.Add_UInt32(BootMediaType);
@@ -65,10 +65,10 @@ AString CBootInitialEntry::GetName() const
break;
if (i == sizeof(VendorSpec))
{
s += '-';
s.Add_Minus();
for (i = 1; i < sizeof(VendorSpec); i++)
{
char c = VendorSpec[i];
char c = (char)VendorSpec[i];
if (c == 0)
break;
if (c == '\\' || c == '/')
@@ -134,7 +134,7 @@ UInt16 CInArchive::ReadUInt16()
{
if (b[i] != b[3 - i])
IncorrectBigEndian = true;
val |= ((UInt16)(b[i]) << (8 * i));
val |= ((UInt32)(b[i]) << (8 * i));
}
return (UInt16)val;
}
@@ -316,7 +316,9 @@ static inline bool CheckSignature(const Byte *sig, const Byte *data)
void CInArchive::SeekToBlock(UInt32 blockIndex)
{
HRESULT res = _stream->Seek((UInt64)blockIndex * VolDescs[MainVolDescIndex].LogicalBlockSize, STREAM_SEEK_SET, &_position);
const HRESULT res = _stream->Seek(
(Int64)((UInt64)blockIndex * VolDescs[MainVolDescIndex].LogicalBlockSize),
STREAM_SEEK_SET, &_position);
if (res != S_OK)
throw CSystemException(res);
m_BufferPos = 0;
@@ -506,10 +508,10 @@ void CInArchive::ReadBootInfo()
HRESULT CInArchive::Open2()
{
_position = 0;
RINOK(_stream->Seek(0, STREAM_SEEK_END, &_fileSize));
RINOK(InStream_GetSize_SeekToEnd(_stream, _fileSize))
if (_fileSize < kStartPos)
return S_FALSE;
RINOK(_stream->Seek(kStartPos, STREAM_SEEK_SET, &_position));
RINOK(_stream->Seek(kStartPos, STREAM_SEEK_SET, &_position))
PhySize = _position;
m_BufferPos = 0;
@@ -584,7 +586,7 @@ HRESULT CInArchive::Open2()
if (VolDescs.IsEmpty())
return S_FALSE;
for (MainVolDescIndex = VolDescs.Size() - 1; MainVolDescIndex > 0; MainVolDescIndex--)
for (MainVolDescIndex = (int)VolDescs.Size() - 1; MainVolDescIndex > 0; MainVolDescIndex--)
if (VolDescs[MainVolDescIndex].IsJoliet())
break;
/* FIXME: some volume can contain Rock Ridge, that is better than
@@ -627,10 +629,10 @@ HRESULT CInArchive::Open2()
const UInt64 kRemMax = 1 << 21;
if (rem <= kRemMax)
{
RINOK(_stream->Seek(PhySize, STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(_stream, PhySize))
bool areThereNonZeros = false;
UInt64 numZeros = 0;
RINOK(ReadZeroTail(_stream, areThereNonZeros, numZeros, kRemMax));
RINOK(ReadZeroTail(_stream, areThereNonZeros, numZeros, kRemMax))
if (!areThereNonZeros)
PhySize += numZeros;
}
@@ -670,4 +672,22 @@ void CInArchive::Clear()
IsSusp = false;
}
UInt64 CInArchive::GetBootItemSize(unsigned index) const
{
const CBootInitialEntry &be = BootEntries[index];
UInt64 size = be.GetSize();
if (be.BootMediaType == NBootMediaType::k1d2Floppy) size = 1200 << 10;
else if (be.BootMediaType == NBootMediaType::k1d44Floppy) size = 1440 << 10;
else if (be.BootMediaType == NBootMediaType::k2d88Floppy) size = 2880 << 10;
const UInt64 startPos = (UInt64)be.LoadRBA * kBlockSize;
if (startPos < _fileSize)
{
const UInt64 rem = _fileSize - startPos;
if (rem < size)
size = rem;
}
return size;
}
}}

View File

@@ -1,7 +1,7 @@
// Archive/IsoIn.h
#ifndef __ARCHIVE_ISO_IN_H
#define __ARCHIVE_ISO_IN_H
#ifndef ZIP7_INC_ARCHIVE_ISO_IN_H
#define ZIP7_INC_ARCHIVE_ISO_IN_H
#include "../../../Common/MyCom.h"
@@ -20,7 +20,7 @@ struct CDir: public CDirRecord
void Clear()
{
Parent = 0;
Parent = NULL;
_subItems.Clear();
}
@@ -133,7 +133,7 @@ struct CDateTime
const bool res = NWindows::NTime::GetSecondsSince1601(Year, Month, Day, Hour, Minute, Second, v);
if (res)
{
v -= (Int64)((Int32)GmtOffset * 15 * 60);
v = (UInt64)((Int64)v - (Int64)((Int32)GmtOffset * 15 * 60));
v *= 10000000;
if (Hundredths < 100)
v += (UInt32)Hundredths * 100000;
@@ -244,10 +244,6 @@ class CInArchive
UInt32 m_BufferPos;
CDir _rootDir;
bool _bootIsDefined;
CBootRecordDescriptor _bootDesc;
void Skip(size_t size);
void SkipZeros(size_t size);
Byte ReadByte();
@@ -285,17 +281,21 @@ public:
// UInt32 BlockSize;
CObjectVector<CBootInitialEntry> BootEntries;
private:
bool _bootIsDefined;
public:
bool IsArc;
bool UnexpectedEnd;
bool HeadersError;
bool IncorrectBigEndian;
bool TooDeepDirs;
bool SelfLinkedDirs;
bool IsSusp;
unsigned SuspSkipSize;
CRecordVector<UInt32> UniqStartLocations;
Byte m_Buffer[kBlockSize];
void UpdatePhySize(UInt32 blockIndex, UInt64 size)
void UpdatePhySize(const UInt32 blockIndex, const UInt64 size)
{
const UInt64 alignedSize = (size + kBlockSize - 1) & ~((UInt64)kBlockSize - 1);
const UInt64 end = (UInt64)blockIndex * kBlockSize + alignedSize;
@@ -305,27 +305,12 @@ public:
bool IsJoliet() const { return VolDescs[MainVolDescIndex].IsJoliet(); }
UInt64 GetBootItemSize(int index) const
{
const CBootInitialEntry &be = BootEntries[index];
UInt64 size = be.GetSize();
if (be.BootMediaType == NBootMediaType::k1d2Floppy)
size = (1200 << 10);
else if (be.BootMediaType == NBootMediaType::k1d44Floppy)
size = (1440 << 10);
else if (be.BootMediaType == NBootMediaType::k2d88Floppy)
size = (2880 << 10);
UInt64 startPos = (UInt64)be.LoadRBA * kBlockSize;
if (startPos < _fileSize)
{
if (_fileSize - startPos < size)
size = _fileSize - startPos;
}
return size;
}
UInt64 GetBootItemSize(unsigned index) const;
bool IsSusp;
unsigned SuspSkipSize;
private:
CDir _rootDir;
Byte m_Buffer[kBlockSize];
CBootRecordDescriptor _bootDesc;
};
}}

View File

@@ -1,7 +1,7 @@
// Archive/IsoItem.h
#ifndef __ARCHIVE_ISO_ITEM_H
#define __ARCHIVE_ISO_ITEM_H
#ifndef ZIP7_INC_ARCHIVE_ISO_ITEM_H
#define ZIP7_INC_ARCHIVE_ISO_ITEM_H
#include "../../../../C/CpuArch.h"
@@ -31,7 +31,7 @@ struct CRecordingDateTime
const bool res = NWindows::NTime::GetSecondsSince1601(Year + 1900, Month, Day, Hour, Minute, Second, v);
if (res)
{
v -= (Int64)((Int32)GmtOffset * 15 * 60);
v = (UInt64)((Int64)v - (Int64)((Int32)GmtOffset * 15 * 60));
v *= 10000000;
prop.SetAsTimeFrom_Ft64_Prec(v, k_PropVar_TimePrec_Base);
}
@@ -101,29 +101,29 @@ struct CDirRecord
{
lenRes = 0;
if (SystemUse.Size() < skipSize)
return 0;
return NULL;
const Byte *p = (const Byte *)SystemUse + skipSize;
unsigned rem = (unsigned)(SystemUse.Size() - skipSize);
while (rem >= 5)
{
unsigned len = p[2];
if (len < 3 || len > rem)
return 0;
return NULL;
if (p[0] == id0 && p[1] == id1 && p[3] == 1)
{
if (len < 4)
return 0; // Check it
return NULL; // Check it
lenRes = len - 4;
return p + 4;
}
p += len;
rem -= len;
}
return 0;
return NULL;
}
const Byte* GetNameCur(bool checkSusp, int skipSize, unsigned &nameLenRes) const
const Byte* GetNameCur(bool checkSusp, unsigned skipSize, unsigned &nameLenRes) const
{
const Byte *res = NULL;
unsigned len = 0;
@@ -148,7 +148,7 @@ struct CDirRecord
}
bool GetSymLink(int skipSize, AString &link) const
bool GetSymLink(unsigned skipSize, AString &link) const
{
link.Empty();
const Byte *p = NULL;
@@ -185,13 +185,13 @@ struct CDirRecord
for (unsigned i = 0; i < cl; i++)
{
char c = p[i];
const Byte c = p[i];
if (c == 0)
{
break;
// return false;
}
link += c;
link += (char)c;
}
p += cl;
@@ -220,7 +220,7 @@ struct CDirRecord
}
bool GetPx(int skipSize, unsigned pxType, UInt32 &val) const
bool GetPx(unsigned skipSize, unsigned pxType, UInt32 &val) const
{
val = 0;
const Byte *p = NULL;
@@ -229,7 +229,7 @@ struct CDirRecord
if (!p)
return false;
// px.Clear();
if (len < ((unsigned)pxType + 1) * 8)
if (len < (pxType + 1) * 8)
return false;
return GetLe32Be32(p + pxType * 8, val);
@@ -302,7 +302,7 @@ struct CDirRecord
bool CheckSusp(unsigned &startPos) const
{
const Byte *p = (const Byte *)SystemUse;
unsigned len = (int)SystemUse.Size();
const size_t len = SystemUse.Size();
const unsigned kMinLen = 7;
if (len < kMinLen)
return false;

View File

@@ -12,7 +12,7 @@ namespace NIso {
static const Byte k_Signature[] = { 'C', 'D', '0', '0', '1' };
REGISTER_ARC_I(
"Iso", "iso img", 0, 0xE7,
"Iso", "iso img", NULL, 0xE7,
k_Signature,
NArchive::NIso::kStartPos + 1,
0,

View File

@@ -1,8 +1,11 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#ifndef ZIP7_INC_STDAFX_H
#define ZIP7_INC_STDAFX_H
#if defined(_MSC_VER) && _MSC_VER >= 1800
#pragma warning(disable : 4464) // relative include path contains '..'
#endif
#include "../../../Common/Common.h"
#endif