chore: initial commit (extracted from Launchers monorepo)
Plugin: ns7zip v2.0.0 Architectures: x86-ansi, x86-unicode, amd64-unicode License: LGPL-2.1-or-later
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
@@ -0,0 +1,427 @@
|
||||
// UdfHandler.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/ComTry.h"
|
||||
|
||||
#include "../../../Windows/PropVariant.h"
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
|
||||
#include "../../Common/LimitedStreams.h"
|
||||
#include "../../Common/ProgressUtils.h"
|
||||
#include "../../Common/RegisterArc.h"
|
||||
#include "../../Common/StreamObjects.h"
|
||||
|
||||
#include "../../Compress/CopyCoder.h"
|
||||
|
||||
#include "UdfHandler.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NUdf {
|
||||
|
||||
static void UdfTimeToFileTime(const CTime &t, NWindows::NCOM::CPropVariant &prop)
|
||||
{
|
||||
UInt64 numSecs;
|
||||
const Byte *d = t.Data;
|
||||
if (!NWindows::NTime::GetSecondsSince1601(t.GetYear(), d[4], d[5], d[6], d[7], d[8], numSecs))
|
||||
return;
|
||||
if (t.IsLocal())
|
||||
numSecs = (UInt64)((Int64)numSecs - (Int64)((Int32)t.GetMinutesOffset() * 60));
|
||||
const UInt32 m0 = d[9];
|
||||
const UInt32 m1 = d[10];
|
||||
const UInt32 m2 = d[11];
|
||||
unsigned numDigits = 0;
|
||||
UInt64 v = numSecs * 10000000;
|
||||
if (m0 < 100 && m1 < 100 && m2 < 100)
|
||||
{
|
||||
v += m0 * 100000 + m1 * 1000 + m2 * 10;
|
||||
numDigits = 6;
|
||||
}
|
||||
prop.SetAsTimeFrom_Ft64_Prec(v, k_PropVar_TimePrec_Base + numDigits);
|
||||
}
|
||||
|
||||
static const Byte kProps[] =
|
||||
{
|
||||
kpidPath,
|
||||
kpidIsDir,
|
||||
kpidSize,
|
||||
kpidPackSize,
|
||||
kpidMTime,
|
||||
kpidATime,
|
||||
kpidCTime,
|
||||
kpidChangeTime,
|
||||
// kpidUserId,
|
||||
// kpidGroupId,
|
||||
// kpidPosixAttrib,
|
||||
kpidLinks
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
{
|
||||
kpidUnpackVer,
|
||||
kpidClusterSize,
|
||||
kpidSectorSize,
|
||||
kpidCTime,
|
||||
kpidMTime,
|
||||
kpidComment
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps
|
||||
|
||||
Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPhySize: prop = _archive.PhySize; break;
|
||||
|
||||
case kpidUnpackVer:
|
||||
{
|
||||
if (_archive.LogVols.Size() == 1)
|
||||
{
|
||||
UString s;
|
||||
const CLogVol &vol = _archive.LogVols[0];
|
||||
vol.DomainId.AddUdfVersionTo(s);
|
||||
if (!s.IsEmpty())
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kpidComment:
|
||||
{
|
||||
UString comment = _archive.GetComment();
|
||||
if (!comment.IsEmpty())
|
||||
prop = comment;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidClusterSize:
|
||||
if (_archive.LogVols.Size() > 0)
|
||||
{
|
||||
UInt32 blockSize = _archive.LogVols[0].BlockSize;
|
||||
unsigned i;
|
||||
for (i = 1; i < _archive.LogVols.Size(); i++)
|
||||
if (_archive.LogVols[i].BlockSize != blockSize)
|
||||
break;
|
||||
if (i == _archive.LogVols.Size())
|
||||
prop = blockSize;
|
||||
}
|
||||
break;
|
||||
|
||||
case kpidSectorSize: prop = ((UInt32)1 << _archive.SecLogSize); break;
|
||||
|
||||
case kpidCTime:
|
||||
if (_archive.LogVols.Size() == 1)
|
||||
{
|
||||
const CLogVol &vol = _archive.LogVols[0];
|
||||
if (vol.FileSets.Size() >= 1)
|
||||
UdfTimeToFileTime(vol.FileSets[0].RecordingTime, prop);
|
||||
}
|
||||
break;
|
||||
case kpidMTime:
|
||||
if (_archive.PrimeVols.Size() == 1)
|
||||
{
|
||||
const CPrimeVol &pv = _archive.PrimeVols[0];
|
||||
UdfTimeToFileTime(pv.RecordingTime, prop);
|
||||
}
|
||||
break;
|
||||
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
if (!_archive.IsArc) v |= kpv_ErrorFlags_IsNotArc;
|
||||
if (_archive.Unsupported) v |= kpv_ErrorFlags_UnsupportedFeature;
|
||||
if (_archive.UnexpectedEnd) v |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
if (_archive.NoEndAnchor) v |= kpv_ErrorFlags_HeadersError;
|
||||
prop = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
class CProgressImp Z7_final: public CProgressVirt
|
||||
{
|
||||
CMyComPtr<IArchiveOpenCallback> _callback;
|
||||
UInt64 _numFiles;
|
||||
UInt64 _numBytes;
|
||||
public:
|
||||
HRESULT SetTotal(UInt64 numBytes) Z7_override;
|
||||
HRESULT SetCompleted(UInt64 numFiles, UInt64 numBytes) Z7_override;
|
||||
HRESULT SetCompleted() Z7_override;
|
||||
CProgressImp(IArchiveOpenCallback *callback): _callback(callback), _numFiles(0), _numBytes(0) {}
|
||||
};
|
||||
|
||||
HRESULT CProgressImp::SetTotal(UInt64 numBytes)
|
||||
{
|
||||
if (_callback)
|
||||
return _callback->SetTotal(NULL, &numBytes);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressImp::SetCompleted(UInt64 numFiles, UInt64 numBytes)
|
||||
{
|
||||
_numFiles = numFiles;
|
||||
_numBytes = numBytes;
|
||||
return SetCompleted();
|
||||
}
|
||||
|
||||
HRESULT CProgressImp::SetCompleted()
|
||||
{
|
||||
if (_callback)
|
||||
return _callback->SetCompleted(&_numFiles, &_numBytes);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *callback))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
{
|
||||
Close();
|
||||
CProgressImp progressImp(callback);
|
||||
RINOK(_archive.Open(stream, &progressImp))
|
||||
bool showVolName = (_archive.LogVols.Size() > 1);
|
||||
FOR_VECTOR (volIndex, _archive.LogVols)
|
||||
{
|
||||
const CLogVol &vol = _archive.LogVols[volIndex];
|
||||
bool showFileSetName = (vol.FileSets.Size() > 1);
|
||||
// showFileSetName = true; // for debug
|
||||
FOR_VECTOR (fsIndex, vol.FileSets)
|
||||
{
|
||||
const CFileSet &fs = vol.FileSets[fsIndex];
|
||||
for (unsigned i = ((showVolName || showFileSetName) ? 0 : 1); i < fs.Refs.Size(); i++)
|
||||
{
|
||||
CRef2 ref2;
|
||||
ref2.Vol = volIndex;
|
||||
ref2.Fs = fsIndex;
|
||||
ref2.Ref = i;
|
||||
_refs2.Add(ref2);
|
||||
}
|
||||
}
|
||||
}
|
||||
_inStream = stream;
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CHandler::Close())
|
||||
{
|
||||
_inStream.Release();
|
||||
_archive.Clear();
|
||||
_refs2.Clear();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
|
||||
{
|
||||
*numItems = _refs2.Size();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
{
|
||||
const CRef2 &ref2 = _refs2[index];
|
||||
const CLogVol &vol = _archive.LogVols[ref2.Vol];
|
||||
const CRef &ref = vol.FileSets[ref2.Fs].Refs[ref2.Ref];
|
||||
const CFile &file = _archive.Files[ref.FileIndex];
|
||||
const CItem &item = _archive.Items[file.ItemIndex];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath: prop = _archive.GetItemPath(ref2.Vol, ref2.Fs, ref2.Ref,
|
||||
_archive.LogVols.Size() > 1, vol.FileSets.Size() > 1); break;
|
||||
case kpidIsDir: prop = item.IsDir(); break;
|
||||
case kpidSize: if (!item.IsDir()) prop = (UInt64)item.Size; break;
|
||||
case kpidPackSize: if (!item.IsDir()) prop = (UInt64)item.NumLogBlockRecorded * vol.BlockSize; break;
|
||||
case kpidMTime: UdfTimeToFileTime(item.MTime, prop); break;
|
||||
case kpidATime: UdfTimeToFileTime(item.ATime, prop); break;
|
||||
case kpidCTime:
|
||||
if (item.IsExtended)
|
||||
UdfTimeToFileTime(item.CreateTime, prop);
|
||||
break;
|
||||
case kpidChangeTime: UdfTimeToFileTime(item.AttribTime, prop); break;
|
||||
// case kpidUserId: prop = item.Uid; break;
|
||||
// case kpidGroupId: prop = item.Gid; break;
|
||||
// case kpidPosixAttrib: prop = (UInt32)item.Permissions; break;
|
||||
case kpidLinks: prop = (UInt32)item.FileLinkCount; break;
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
|
||||
{
|
||||
*stream = NULL;
|
||||
|
||||
const CRef2 &ref2 = _refs2[index];
|
||||
const CLogVol &vol = _archive.LogVols[ref2.Vol];
|
||||
const CRef &ref = vol.FileSets[ref2.Fs].Refs[ref2.Ref];
|
||||
const CFile &file = _archive.Files[ref.FileIndex];
|
||||
const CItem &item = _archive.Items[file.ItemIndex];
|
||||
UInt64 size = item.Size;
|
||||
|
||||
if (!item.IsRecAndAlloc() || !item.CheckChunkSizes() || ! _archive.CheckItemExtents(ref2.Vol, item))
|
||||
return E_NOTIMPL;
|
||||
|
||||
if (item.IsInline)
|
||||
{
|
||||
Create_BufInStream_WithNewBuffer(item.InlineData, stream);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CExtentsStream *extentStreamSpec = new CExtentsStream();
|
||||
CMyComPtr<ISequentialInStream> extentStream = extentStreamSpec;
|
||||
|
||||
extentStreamSpec->Stream = _inStream;
|
||||
|
||||
UInt64 virtOffset = 0;
|
||||
FOR_VECTOR (extentIndex, item.Extents)
|
||||
{
|
||||
const CMyExtent &extent = item.Extents[extentIndex];
|
||||
UInt32 len = extent.GetLen();
|
||||
if (len == 0)
|
||||
continue;
|
||||
if (size < len)
|
||||
return S_FALSE;
|
||||
|
||||
const unsigned partitionIndex = vol.PartitionMaps[extent.PartitionRef].PartitionIndex;
|
||||
UInt32 logBlockNumber = extent.Pos;
|
||||
const CPartition &partition = _archive.Partitions[partitionIndex];
|
||||
UInt64 offset = ((UInt64)partition.Pos << _archive.SecLogSize) +
|
||||
(UInt64)logBlockNumber * vol.BlockSize;
|
||||
|
||||
CSeekExtent se;
|
||||
se.Phy = offset;
|
||||
se.Virt = virtOffset;
|
||||
virtOffset += len;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
|
||||
size -= len;
|
||||
}
|
||||
if (size != 0)
|
||||
return S_FALSE;
|
||||
CSeekExtent se;
|
||||
se.Phy = 0;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
extentStreamSpec->Init();
|
||||
*stream = extentStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = _refs2.Size();
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
const UInt32 index = (allFilesMode ? i : indices[i]);
|
||||
const CRef2 &ref2 = _refs2[index];
|
||||
const CRef &ref = _archive.LogVols[ref2.Vol].FileSets[ref2.Fs].Refs[ref2.Ref];
|
||||
const CFile &file = _archive.Files[ref.FileIndex];
|
||||
const CItem &item = _archive.Items[file.ItemIndex];
|
||||
if (!item.IsDir())
|
||||
totalSize += item.Size;
|
||||
}
|
||||
RINOK(extractCallback->SetTotal(totalSize))
|
||||
|
||||
UInt64 currentTotalSize = 0;
|
||||
|
||||
CMyComPtr2_Create<ICompressProgressInfo, CLocalProgress> lps;
|
||||
lps->Init(extractCallback, false);
|
||||
CMyComPtr2_Create<ICompressCoder, NCompress::CCopyCoder> copyCoder;
|
||||
CMyComPtr2_Create<ISequentialOutStream, CLimitedSequentialOutStream> outStream;
|
||||
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
lps->InSize = lps->OutSize = currentTotalSize;
|
||||
RINOK(lps->SetCur())
|
||||
if (i >= numItems)
|
||||
break;
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
const Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
const UInt32 index = allFilesMode ? i : indices[i];
|
||||
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
|
||||
|
||||
const CRef2 &ref2 = _refs2[index];
|
||||
const CRef &ref = _archive.LogVols[ref2.Vol].FileSets[ref2.Fs].Refs[ref2.Ref];
|
||||
const CFile &file = _archive.Files[ref.FileIndex];
|
||||
const CItem &item = _archive.Items[file.ItemIndex];
|
||||
|
||||
if (item.IsDir())
|
||||
{
|
||||
RINOK(extractCallback->PrepareOperation(askMode))
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
|
||||
continue;
|
||||
}
|
||||
currentTotalSize += item.Size;
|
||||
|
||||
if (!testMode && !realOutStream)
|
||||
continue;
|
||||
|
||||
RINOK(extractCallback->PrepareOperation(askMode))
|
||||
outStream->SetStream(realOutStream);
|
||||
realOutStream.Release();
|
||||
outStream->Init(item.Size);
|
||||
Int32 opRes;
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> udfInStream;
|
||||
const HRESULT res = GetStream(index, &udfInStream);
|
||||
if (res == E_NOTIMPL)
|
||||
opRes = NExtract::NOperationResult::kUnsupportedMethod;
|
||||
else if (res != S_OK)
|
||||
opRes = NExtract::NOperationResult::kDataError;
|
||||
else
|
||||
{
|
||||
RINOK(copyCoder.Interface()->Code(udfInStream, outStream, NULL, NULL, lps))
|
||||
opRes = outStream->IsFinishedOK() ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kDataError;
|
||||
}
|
||||
}
|
||||
outStream->ReleaseStream();
|
||||
RINOK(extractCallback->SetOperationResult(opRes))
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
static const UInt32 kIsoStartPos = 0x8000;
|
||||
|
||||
// 5, { 0, 'N', 'S', 'R', '0' },
|
||||
|
||||
static const Byte k_Signature[] =
|
||||
{
|
||||
8, 0, 'B', 'E', 'A', '0', '1', 1, 0,
|
||||
6, 1, 'C', 'D', '0', '0', '1'
|
||||
};
|
||||
|
||||
REGISTER_ARC_I(
|
||||
"Udf", "udf iso img", NULL, 0xE0,
|
||||
k_Signature,
|
||||
kIsoStartPos,
|
||||
NArcInfoFlags::kMultiSignature |
|
||||
NArcInfoFlags::kStartOpen,
|
||||
IsArc_Udf)
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,32 @@
|
||||
// UdfHandler.h
|
||||
|
||||
#ifndef ZIP7_INC_UDF_HANDLER_H
|
||||
#define ZIP7_INC_UDF_HANDLER_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../IArchive.h"
|
||||
|
||||
#include "UdfIn.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NUdf {
|
||||
|
||||
struct CRef2
|
||||
{
|
||||
unsigned Vol;
|
||||
unsigned Fs;
|
||||
unsigned Ref;
|
||||
};
|
||||
|
||||
Z7_CLASS_IMP_CHandler_IInArchive_1(
|
||||
IInArchiveGetStream
|
||||
)
|
||||
CRecordVector<CRef2> _refs2;
|
||||
CMyComPtr<IInStream> _inStream;
|
||||
CInArchive _archive;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,507 @@
|
||||
// Archive/UdfIn.h -- UDF / ECMA-167
|
||||
|
||||
#ifndef ZIP7_INC_ARCHIVE_UDF_IN_H
|
||||
#define ZIP7_INC_ARCHIVE_UDF_IN_H
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../../Common/MyMap.h"
|
||||
#include "../../../Common/MyString.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NUdf {
|
||||
|
||||
// ---------- ECMA Part 1 ----------
|
||||
|
||||
// ECMA 1/7.2.12
|
||||
// UDF 2.1.3
|
||||
|
||||
struct CDString32
|
||||
{
|
||||
Byte Data[32];
|
||||
|
||||
void Parse(const Byte *buf) { memcpy(Data, buf, sizeof(Data)); }
|
||||
UString GetString() const;
|
||||
};
|
||||
|
||||
struct CDString128
|
||||
{
|
||||
Byte Data[128];
|
||||
|
||||
void Parse(const Byte *buf) { memcpy(Data, buf, sizeof(Data)); }
|
||||
UString GetString() const;
|
||||
};
|
||||
|
||||
struct CDString
|
||||
{
|
||||
CByteBuffer Data;
|
||||
|
||||
void Parse(const Byte *p, unsigned size);
|
||||
UString GetString() const;
|
||||
};
|
||||
|
||||
|
||||
// ECMA 1/7.3
|
||||
// UDF 2.1.4 timestamp
|
||||
|
||||
struct CTime
|
||||
{
|
||||
Byte Data[12];
|
||||
|
||||
unsigned GetType() const { return Data[1] >> 4; }
|
||||
bool IsLocal() const { return GetType() == 1; }
|
||||
int GetMinutesOffset() const
|
||||
{
|
||||
int t = (Data[0] | ((unsigned)Data[1] << 8)) & 0xFFF;
|
||||
if ((t >> 11) != 0)
|
||||
t -= (1 << 12);
|
||||
return (t > (60 * 24) || t < -(60 * 24)) ? 0 : t;
|
||||
}
|
||||
unsigned GetYear() const { return (Data[2] | ((unsigned)Data[3] << 8)); }
|
||||
void Parse(const Byte *buf);
|
||||
};
|
||||
|
||||
|
||||
// ECMA 1/7.4 regid
|
||||
// UDF 2.1.5 EntityID
|
||||
|
||||
struct CRegId
|
||||
{
|
||||
Byte Flags;
|
||||
char Id[23];
|
||||
Byte Suffix[8];
|
||||
|
||||
void Parse(const Byte *buf);
|
||||
void AddCommentTo(UString &s) const;
|
||||
void AddUdfVersionTo(UString &s) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ---------- ECMA Part 3: Volume Structure ----------
|
||||
|
||||
// ECMA 3/7.1
|
||||
|
||||
struct CExtent
|
||||
{
|
||||
UInt32 Len;
|
||||
UInt32 Pos; // logical sector number
|
||||
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
|
||||
|
||||
// ECMA 3/10.1
|
||||
// UDF 2.2.2 PrimaryVolumeDescriptor
|
||||
|
||||
struct CPrimeVol
|
||||
{
|
||||
// UInt32 VolumeDescriptorSequenceNumber;
|
||||
UInt32 PrimaryVolumeDescriptorNumber;
|
||||
CDString32 VolumeId;
|
||||
UInt16 VolumeSequenceNumber;
|
||||
UInt16 MaximumVolumeSequenceNumber;
|
||||
// UInt16 InterchangeLevel;
|
||||
// UInt16 MaximumInterchangeLevel;
|
||||
// UInt32 CharacterSetList;
|
||||
// UInt32 MaximumCharacterSetList;
|
||||
CDString128 VolumeSetId;
|
||||
// charspec DescriptorCharacterSet; // (1/7.2.1)
|
||||
// charspec ExplanatoryCharacterSet; // (1/7.2.1)
|
||||
// CExtent VolumeAbstract;
|
||||
// CExtent VolumeCopyrightNotice;
|
||||
CRegId ApplicationId;
|
||||
CTime RecordingTime;
|
||||
CRegId ImplId;
|
||||
// bytes ImplementationUse
|
||||
// UInt32 PredecessorVolumeDescriptorSequenceLocation;
|
||||
// UInt16 Flags;
|
||||
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
|
||||
|
||||
// ECMA 3/10.5
|
||||
// UDF 2.2.14 PartitionDescriptor
|
||||
|
||||
struct CPartition
|
||||
{
|
||||
UInt32 Pos;
|
||||
UInt32 Len;
|
||||
|
||||
UInt16 Flags;
|
||||
UInt16 Number;
|
||||
CRegId ContentsId;
|
||||
// Byte ContentsUse[128];
|
||||
UInt32 AccessType;
|
||||
|
||||
CRegId ImplId;
|
||||
// Byte ImplUse[128];
|
||||
|
||||
// int VolIndex;
|
||||
CMap32 Map;
|
||||
|
||||
bool IsMetadata;
|
||||
|
||||
CPartition():
|
||||
// VolIndex(-1),
|
||||
IsMetadata(false) {}
|
||||
|
||||
// bool IsNsr() const { return (strncmp(ContentsId.Id, "+NSR0", 5) == 0); }
|
||||
// bool IsAllocated() const { return ((Flags & 1) != 0); }
|
||||
};
|
||||
|
||||
|
||||
// ECMA 4/7.1 lb_addr
|
||||
|
||||
struct CLogBlockAddr
|
||||
{
|
||||
UInt32 Pos;
|
||||
UInt16 PartitionRef;
|
||||
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
|
||||
|
||||
enum EShortAllocDescType
|
||||
{
|
||||
SHORT_ALLOC_DESC_TYPE_RecordedAndAllocated = 0,
|
||||
SHORT_ALLOC_DESC_TYPE_NotRecordedButAllocated = 1,
|
||||
SHORT_ALLOC_DESC_TYPE_NotRecordedAndNotAllocated = 2,
|
||||
SHORT_ALLOC_DESC_TYPE_NextExtent = 3
|
||||
};
|
||||
|
||||
|
||||
// ECMA 4/14.14.1 short_ad
|
||||
|
||||
struct CShortAllocDesc
|
||||
{
|
||||
UInt32 Len;
|
||||
UInt32 Pos;
|
||||
|
||||
// UInt32 GetLen() const { return Len & 0x3FFFFFFF; }
|
||||
// UInt32 GetType() const { return Len >> 30; }
|
||||
// bool IsRecAndAlloc() const { return GetType() == SHORT_ALLOC_DESC_TYPE_RecordedAndAllocated; }
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
|
||||
/*
|
||||
struct CADImpUse
|
||||
{
|
||||
UInt16 Flags;
|
||||
UInt32 UdfUniqueId;
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
*/
|
||||
|
||||
// ECMA 4/14.14.2 long_ad
|
||||
// UDF 2.3.10.1
|
||||
|
||||
struct CLongAllocDesc
|
||||
{
|
||||
UInt32 Len;
|
||||
CLogBlockAddr Location;
|
||||
|
||||
// Byte ImplUse[6];
|
||||
// CADImpUse adImpUse; // UDF
|
||||
|
||||
UInt32 GetLen() const { return Len & 0x3FFFFFFF; }
|
||||
UInt32 GetType() const { return Len >> 30; }
|
||||
bool IsRecAndAlloc() const { return GetType() == SHORT_ALLOC_DESC_TYPE_RecordedAndAllocated; }
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
|
||||
|
||||
// ECMA 3/10.7 Partition maps
|
||||
// UDF 2.2.8-2.2.10 Partition Maps
|
||||
|
||||
struct CPartitionMap
|
||||
{
|
||||
unsigned PartitionIndex;
|
||||
|
||||
Byte Type;
|
||||
// Byte Len;
|
||||
|
||||
// ECMA 10.7.2
|
||||
UInt16 VolumeSequenceNumber;
|
||||
UInt16 PartitionNumber;
|
||||
|
||||
CRegId PartitionTypeId;
|
||||
|
||||
// UDF 2.2.10 Metadata Partition Map
|
||||
UInt32 MetadataFileLocation;
|
||||
// UInt32 MetadataMirrorFileLocation;
|
||||
// UInt32 MetadataBitmapFileLocation;
|
||||
// UInt32 AllocationUnitSize; // (Blocks)
|
||||
// UInt16 AlignmentUnitSize; // (Blocks)
|
||||
// Byte Flags;
|
||||
|
||||
// Byte Data[256];
|
||||
// CPartitionMap(): PartitionIndex(-1) {}
|
||||
};
|
||||
|
||||
|
||||
// ECMA 4/14.6.6
|
||||
|
||||
enum EIcbFileType
|
||||
{
|
||||
ICB_FILE_TYPE_DIR = 4,
|
||||
ICB_FILE_TYPE_FILE = 5,
|
||||
|
||||
ICB_FILE_TYPE_METADATA = 250, // 2.2.13.1 Metadata File
|
||||
ICB_FILE_TYPE_METADATA_MIRROR = 251
|
||||
};
|
||||
|
||||
enum EIcbDescriptorType
|
||||
{
|
||||
ICB_DESC_TYPE_SHORT = 0,
|
||||
ICB_DESC_TYPE_LONG = 1,
|
||||
ICB_DESC_TYPE_EXTENDED = 2,
|
||||
ICB_DESC_TYPE_INLINE = 3
|
||||
};
|
||||
|
||||
// ECMA 4/14.6
|
||||
// UDF 3.3.2
|
||||
|
||||
struct CIcbTag
|
||||
{
|
||||
// UInt32 PriorDirectNum;
|
||||
// UInt16 StrategyType;
|
||||
// UInt16 StrategyParam;
|
||||
// UInt16 MaxNumOfEntries;
|
||||
Byte FileType;
|
||||
// CLogBlockAddr ParentIcb;
|
||||
UInt16 Flags;
|
||||
|
||||
bool IsDir() const { return FileType == ICB_FILE_TYPE_DIR; }
|
||||
int GetDescriptorType() const { return Flags & 3; }
|
||||
void Parse(const Byte *p);
|
||||
};
|
||||
|
||||
|
||||
// ECMA 4/14.4.3
|
||||
// UDF 2.3.4.2 FileCharacteristics
|
||||
|
||||
// const Byte FILEID_CHARACS_Existance = (1 << 0);
|
||||
const Byte FILEID_CHARACS_Dir = (1 << 1);
|
||||
const Byte FILEID_CHARACS_Deleted = (1 << 2);
|
||||
const Byte FILEID_CHARACS_Parent = (1 << 3);
|
||||
// const Byte FILEID_CHARACS_Metadata = (1 << 4);
|
||||
|
||||
struct CFile
|
||||
{
|
||||
int ItemIndex;
|
||||
// UInt16 FileVersion;
|
||||
// Byte FileCharacteristics;
|
||||
// CByteBuffer ImplUse;
|
||||
CDString Id;
|
||||
|
||||
CFile(): /* FileVersion(0), FileCharacteristics(0), */ ItemIndex(-1) {}
|
||||
UString GetName() const { return Id.GetString(); }
|
||||
};
|
||||
|
||||
|
||||
struct CMyExtent
|
||||
{
|
||||
UInt32 Pos;
|
||||
UInt32 Len;
|
||||
unsigned PartitionRef; // index in CLogVol::PartitionMaps
|
||||
|
||||
UInt32 GetLen() const { return Len & 0x3FFFFFFF; }
|
||||
UInt32 GetType() const { return Len >> 30; }
|
||||
bool IsRecAndAlloc() const { return GetType() == SHORT_ALLOC_DESC_TYPE_RecordedAndAllocated; }
|
||||
};
|
||||
|
||||
|
||||
struct CItem
|
||||
{
|
||||
CIcbTag IcbTag;
|
||||
|
||||
// UInt32 Uid;
|
||||
// UInt32 Gid;
|
||||
// UInt32 Permissions;
|
||||
UInt16 FileLinkCount;
|
||||
// Byte RecordFormat;
|
||||
// Byte RecordDisplayAttr;
|
||||
// UInt32 RecordLen;
|
||||
UInt64 Size;
|
||||
UInt64 NumLogBlockRecorded;
|
||||
// UInt64 ObjectSize;
|
||||
|
||||
CTime ATime;
|
||||
CTime MTime;
|
||||
CTime AttribTime; // Attribute time : most recent date and time of the day of file creation or modification of the attributes of.
|
||||
CTime CreateTime;
|
||||
// UInt32 CheckPoint;
|
||||
// CLongAllocDesc ExtendedAttrIcb;
|
||||
// CRegId ImplId;
|
||||
// UInt64 UniqueId;
|
||||
|
||||
bool IsExtended;
|
||||
bool IsInline;
|
||||
CByteBuffer InlineData;
|
||||
CRecordVector<CMyExtent> Extents;
|
||||
CUIntVector SubFiles;
|
||||
|
||||
void Parse(const Byte *p);
|
||||
|
||||
bool IsRecAndAlloc() const
|
||||
{
|
||||
FOR_VECTOR (i, Extents)
|
||||
if (!Extents[i].IsRecAndAlloc())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
UInt64 GetChunksSumSize() const
|
||||
{
|
||||
if (IsInline)
|
||||
return InlineData.Size();
|
||||
UInt64 size = 0;
|
||||
FOR_VECTOR (i, Extents)
|
||||
size += Extents[i].GetLen();
|
||||
return size;
|
||||
}
|
||||
|
||||
bool CheckChunkSizes() const { return GetChunksSumSize() == Size; }
|
||||
|
||||
bool IsDir() const { return IcbTag.IsDir(); }
|
||||
};
|
||||
|
||||
|
||||
struct CRef
|
||||
{
|
||||
unsigned FileIndex;
|
||||
int Parent;
|
||||
};
|
||||
|
||||
|
||||
// ECMA 4 / 14.1
|
||||
struct CFileSet
|
||||
{
|
||||
CRecordVector<CRef> Refs;
|
||||
|
||||
CTime RecordingTime;
|
||||
// UInt16 InterchangeLevel;
|
||||
// UInt16 MaxInterchangeLevel;
|
||||
UInt32 FileSetNumber;
|
||||
UInt32 FileSetDescNumber;
|
||||
CDString128 LogicalVolumeId;
|
||||
CDString32 Id;
|
||||
CDString32 CopyrightId;
|
||||
CDString32 AbstractId;
|
||||
|
||||
CLongAllocDesc RootDirICB;
|
||||
CRegId DomainId;
|
||||
// CLongAllocDesc SystemStreamDirICB;
|
||||
};
|
||||
|
||||
|
||||
/* 8.3 Volume descriptors
|
||||
8.4
|
||||
A Volume Descriptor Sequence:
|
||||
shall contain one or more Primary Volume Descriptors.
|
||||
*/
|
||||
|
||||
// ECMA 3/10.6
|
||||
// UDF 2.2.4 LogicalVolumeDescriptor
|
||||
|
||||
struct CLogVol
|
||||
{
|
||||
CObjectVector<CPartitionMap> PartitionMaps;
|
||||
CObjectVector<CFileSet> FileSets;
|
||||
|
||||
UInt32 BlockSize;
|
||||
CDString128 Id;
|
||||
CRegId DomainId;
|
||||
|
||||
// Byte ContentsUse[16];
|
||||
CLongAllocDesc FileSetLocation; // UDF
|
||||
|
||||
CRegId ImplId;
|
||||
// Byte ImplUse[128];
|
||||
// CExtent IntegritySequenceExtent;
|
||||
|
||||
UString GetName() const { return Id.GetString(); }
|
||||
};
|
||||
|
||||
|
||||
Z7_PURE_INTERFACES_BEGIN
|
||||
struct Z7_DECLSPEC_NOVTABLE CProgressVirt
|
||||
{
|
||||
virtual HRESULT SetTotal(UInt64 numBytes) =0; \
|
||||
virtual HRESULT SetCompleted(UInt64 numFiles, UInt64 numBytes) =0; \
|
||||
virtual HRESULT SetCompleted() =0; \
|
||||
};
|
||||
Z7_PURE_INTERFACES_END
|
||||
|
||||
class CInArchive
|
||||
{
|
||||
public:
|
||||
CObjectVector<CLogVol> LogVols;
|
||||
CObjectVector<CItem> Items;
|
||||
CObjectVector<CFile> Files;
|
||||
CObjectVector<CPartition> Partitions;
|
||||
|
||||
unsigned SecLogSize;
|
||||
UInt64 PhySize;
|
||||
UInt64 FileSize;
|
||||
|
||||
bool IsArc;
|
||||
bool Unsupported;
|
||||
bool UnexpectedEnd;
|
||||
bool NoEndAnchor;
|
||||
|
||||
CObjectVector<CPrimeVol> PrimeVols;
|
||||
|
||||
HRESULT Open(IInStream *inStream, CProgressVirt *progress);
|
||||
void Clear();
|
||||
|
||||
UString GetComment() const;
|
||||
UString GetItemPath(unsigned volIndex, unsigned fsIndex, unsigned refIndex,
|
||||
bool showVolName, bool showFsName) const;
|
||||
|
||||
bool CheckItemExtents(unsigned volIndex, const CItem &item) const;
|
||||
|
||||
private:
|
||||
IInStream *_stream;
|
||||
CProgressVirt *_progress;
|
||||
|
||||
HRESULT Read(unsigned volIndex, unsigned partitionRef, UInt32 blockPos, UInt32 len, Byte *buf);
|
||||
HRESULT ReadLad(unsigned volIndex, const CLongAllocDesc &lad, Byte *buf);
|
||||
HRESULT ReadFromFile(unsigned volIndex, const CItem &item, CByteBuffer &buf);
|
||||
|
||||
HRESULT ReadFileItem(unsigned volIndex, unsigned fsIndex, const CLongAllocDesc &lad, bool isDir, int numRecurseAllowed);
|
||||
HRESULT ReadItem(unsigned volIndex, int fsIndex, const CLongAllocDesc &lad, bool isDir, int numRecurseAllowed);
|
||||
|
||||
HRESULT Open2();
|
||||
HRESULT FillRefs(CFileSet &fs, unsigned fileIndex, int parent, int numRecurseAllowed);
|
||||
|
||||
UInt64 _processedProgressBytes;
|
||||
|
||||
UInt64 _fileNameLengthTotal;
|
||||
unsigned _numRefs;
|
||||
UInt32 _numExtents;
|
||||
UInt64 _inlineExtentsSize;
|
||||
bool CheckExtent(unsigned volIndex, unsigned partitionRef, UInt32 blockPos, UInt32 len) const;
|
||||
|
||||
void UpdatePhySize(UInt64 val)
|
||||
{
|
||||
if (PhySize < val)
|
||||
PhySize = val;
|
||||
}
|
||||
|
||||
void UpdatePhySize(const CExtent &e)
|
||||
{
|
||||
UpdatePhySize(((UInt64)e.Pos << SecLogSize) + e.Len);
|
||||
}
|
||||
};
|
||||
|
||||
API_FUNC_IsArc IsArc_Udf(const Byte *p, size_t size);
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user