mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-10 04:07:12 -06:00
Normalize all the line endings
This commit is contained in:
@@ -1,489 +1,489 @@
|
||||
// IsoHandler.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/ComTry.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "../../../Windows/PropVariant.h"
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
|
||||
#include "../../Common/LimitedStreams.h"
|
||||
#include "../../Common/ProgressUtils.h"
|
||||
|
||||
#include "../../Compress/CopyCoder.h"
|
||||
|
||||
#include "../Common/ItemNameUtils.h"
|
||||
|
||||
#include "IsoHandler.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NTime;
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
static const Byte kProps[] =
|
||||
{
|
||||
kpidPath,
|
||||
kpidIsDir,
|
||||
kpidSize,
|
||||
kpidPackSize,
|
||||
kpidMTime,
|
||||
// kpidCTime,
|
||||
// kpidATime,
|
||||
kpidPosixAttrib,
|
||||
// kpidUser,
|
||||
// kpidGroup,
|
||||
// kpidLinks,
|
||||
kpidSymLink
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
{
|
||||
kpidComment,
|
||||
kpidCTime,
|
||||
kpidMTime,
|
||||
// kpidHeadersSize
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps
|
||||
|
||||
STDMETHODIMP CHandler::Open(IInStream *stream,
|
||||
const UInt64 * /* maxCheckStartPosition */,
|
||||
IArchiveOpenCallback * /* openArchiveCallback */)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
Close();
|
||||
{
|
||||
RINOK(_archive.Open(stream));
|
||||
_stream = stream;
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
_archive.Clear();
|
||||
_stream.Release();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
{
|
||||
*numItems = _archive.Refs.Size() + _archive.BootEntries.Size();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void AddString(AString &s, const char *name, const Byte *p, unsigned size)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < size && p[i]; i++);
|
||||
for (; i > 0 && p[i - 1] == ' '; i--);
|
||||
if (i != 0)
|
||||
{
|
||||
AString d;
|
||||
d.SetFrom((const char *)p, i);
|
||||
s += '\n';
|
||||
s += name;
|
||||
s += ": ";
|
||||
s += d;
|
||||
}
|
||||
}
|
||||
|
||||
#define ADD_STRING(n, v) AddString(s, n, vol. v, sizeof(vol. v))
|
||||
|
||||
static void AddErrorMessage(AString &s, const char *message)
|
||||
{
|
||||
if (!s.IsEmpty())
|
||||
s += ". ";
|
||||
s += message;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
if (_stream)
|
||||
{
|
||||
const CVolumeDescriptor &vol = _archive.VolDescs[_archive.MainVolDescIndex];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidComment:
|
||||
{
|
||||
AString s;
|
||||
ADD_STRING("System", SystemId);
|
||||
ADD_STRING("Volume", VolumeId);
|
||||
ADD_STRING("VolumeSet", VolumeSetId);
|
||||
ADD_STRING("Publisher", PublisherId);
|
||||
ADD_STRING("Preparer", DataPreparerId);
|
||||
ADD_STRING("Application", ApplicationId);
|
||||
ADD_STRING("Copyright", CopyrightFileId);
|
||||
ADD_STRING("Abstract", AbstractFileId);
|
||||
ADD_STRING("Bib", BibFileId);
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
case kpidCTime: { FILETIME utc; if (vol.CTime.GetFileTime(utc)) prop = utc; break; }
|
||||
case kpidMTime: { FILETIME utc; if (vol.MTime.GetFileTime(utc)) prop = utc; break; }
|
||||
}
|
||||
}
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPhySize: prop = _archive.PhySize; break;
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
if (!_archive.IsArc) v |= kpv_ErrorFlags_IsNotArc;
|
||||
if (_archive.UnexpectedEnd) v |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
if (_archive.HeadersError) v |= kpv_ErrorFlags_HeadersError;
|
||||
prop = v;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidError:
|
||||
{
|
||||
AString s;
|
||||
if (_archive.IncorrectBigEndian)
|
||||
AddErrorMessage(s, "Incorrect big-endian headers");
|
||||
if (_archive.SelfLinkedDirs)
|
||||
AddErrorMessage(s, "Self-linked directory");
|
||||
if (_archive.TooDeepDirs)
|
||||
AddErrorMessage(s, "Too deep directory levels");
|
||||
if (!s.IsEmpty())
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
if (index >= (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
index -= _archive.Refs.Size();
|
||||
const CBootInitialEntry &be = _archive.BootEntries[index];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
{
|
||||
AString s ("[BOOT]" STRING_PATH_SEPARATOR);
|
||||
if (_archive.BootEntries.Size() != 1)
|
||||
{
|
||||
s.Add_UInt32(index + 1);
|
||||
s += '-';
|
||||
}
|
||||
s += be.GetName();
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
case kpidIsDir: prop = false; break;
|
||||
case kpidSize:
|
||||
case kpidPackSize:
|
||||
prop = (UInt64)_archive.GetBootItemSize(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
// if (item.FileId.GetCapacity() >= 0)
|
||||
{
|
||||
UString s;
|
||||
if (_archive.IsJoliet())
|
||||
item.GetPathU(s);
|
||||
else
|
||||
s = MultiByteToUnicodeString(item.GetPath(_archive.IsSusp, _archive.SuspSkipSize), CP_OEMCP);
|
||||
|
||||
if (s.Len() >= 2 && s[s.Len() - 2] == ';' && s.Back() == '1')
|
||||
s.DeleteFrom(s.Len() - 2);
|
||||
|
||||
if (!s.IsEmpty() && s.Back() == L'.')
|
||||
s.DeleteBack();
|
||||
|
||||
NItemName::ReplaceToOsSlashes_Remove_TailSlash(s);
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
|
||||
case kpidSymLink:
|
||||
if (_archive.IsSusp)
|
||||
{
|
||||
UString s;
|
||||
UInt32 mode;
|
||||
if (item.GetPx(_archive.SuspSkipSize, k_Px_Mode, mode))
|
||||
{
|
||||
if (((mode >> 12) & 0xF) == 10)
|
||||
{
|
||||
AString s8;
|
||||
if (item.GetSymLink(_archive.SuspSkipSize, s8))
|
||||
{
|
||||
s = MultiByteToUnicodeString(s8, CP_OEMCP);
|
||||
prop = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case kpidPosixAttrib:
|
||||
/*
|
||||
case kpidLinks:
|
||||
case kpidUser:
|
||||
case kpidGroup:
|
||||
*/
|
||||
{
|
||||
if (_archive.IsSusp)
|
||||
{
|
||||
UInt32 t = 0;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPosixAttrib: t = k_Px_Mode; break;
|
||||
/*
|
||||
case kpidLinks: t = k_Px_Links; break;
|
||||
case kpidUser: t = k_Px_User; break;
|
||||
case kpidGroup: t = k_Px_Group; break;
|
||||
*/
|
||||
}
|
||||
UInt32 v;
|
||||
if (item.GetPx(_archive.SuspSkipSize, t, v))
|
||||
prop = v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidIsDir: prop = item.IsDir(); break;
|
||||
case kpidSize:
|
||||
case kpidPackSize:
|
||||
if (!item.IsDir())
|
||||
prop = (UInt64)ref.TotalSize;
|
||||
break;
|
||||
|
||||
case kpidMTime:
|
||||
// case kpidCTime:
|
||||
// case kpidATime:
|
||||
{
|
||||
FILETIME utc;
|
||||
if (/* propID == kpidMTime && */ item.DateTime.GetFileTime(utc))
|
||||
prop = utc;
|
||||
/*
|
||||
else
|
||||
{
|
||||
UInt32 t = 0;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidMTime: t = k_Tf_MTime; break;
|
||||
case kpidCTime: t = k_Tf_CTime; break;
|
||||
case kpidATime: t = k_Tf_ATime; break;
|
||||
}
|
||||
CRecordingDateTime dt;
|
||||
if (item.GetTf(_archive.SuspSkipSize, t, dt))
|
||||
{
|
||||
FILETIME utc;
|
||||
if (dt.GetFileTime(utc))
|
||||
prop = utc;
|
||||
}
|
||||
}
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = _archive.Refs.Size();
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 index = (allFilesMode ? i : indices[i]);
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
if (!item.IsDir())
|
||||
totalSize += ref.TotalSize;
|
||||
}
|
||||
else
|
||||
totalSize += _archive.GetBootItemSize(index - _archive.Refs.Size());
|
||||
}
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
UInt64 currentTotalSize = 0;
|
||||
UInt64 currentItemSize;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
|
||||
{
|
||||
lps->InSize = lps->OutSize = currentTotalSize;
|
||||
RINOK(lps->SetCur());
|
||||
currentItemSize = 0;
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
UInt32 index = allFilesMode ? i : indices[i];
|
||||
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
|
||||
UInt64 blockIndex;
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
if (item.IsDir())
|
||||
{
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
|
||||
continue;
|
||||
}
|
||||
currentItemSize = ref.TotalSize;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned bootIndex = index - _archive.Refs.Size();
|
||||
const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
|
||||
currentItemSize = _archive.GetBootItemSize(bootIndex);
|
||||
blockIndex = be.LoadRBA;
|
||||
}
|
||||
|
||||
|
||||
if (!testMode && !realOutStream)
|
||||
continue;
|
||||
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
bool isOK = true;
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
UInt64 offset = 0;
|
||||
for (UInt32 e = 0; e < ref.NumExtents; e++)
|
||||
{
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + e];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
lps->InSize = lps->OutSize = currentTotalSize + offset;
|
||||
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(item2.Size);
|
||||
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
|
||||
if (copyCoderSpec->TotalSize != item2.Size)
|
||||
{
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
offset += item2.Size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(_stream->Seek((UInt64)blockIndex * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(currentItemSize);
|
||||
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));
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*stream = 0;
|
||||
UInt64 blockIndex;
|
||||
UInt64 currentItemSize;
|
||||
|
||||
if (index < _archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
if (item.IsDir())
|
||||
return S_FALSE;
|
||||
|
||||
if (ref.NumExtents > 1)
|
||||
{
|
||||
CExtentsStream *extentStreamSpec = new CExtentsStream();
|
||||
CMyComPtr<ISequentialInStream> extentStream = extentStreamSpec;
|
||||
|
||||
extentStreamSpec->Stream = _stream;
|
||||
|
||||
UInt64 virtOffset = 0;
|
||||
for (UInt32 i = 0; i < ref.NumExtents; i++)
|
||||
{
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + i];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
CSeekExtent se;
|
||||
se.Phy = (UInt64)item2.ExtentLocation * kBlockSize;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
virtOffset += item2.Size;
|
||||
}
|
||||
if (virtOffset != ref.TotalSize)
|
||||
return S_FALSE;
|
||||
CSeekExtent se;
|
||||
se.Phy = 0;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
extentStreamSpec->Init();
|
||||
*stream = extentStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
currentItemSize = item.Size;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned bootIndex = index - _archive.Refs.Size();
|
||||
const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
|
||||
currentItemSize = _archive.GetBootItemSize(bootIndex);
|
||||
blockIndex = be.LoadRBA;
|
||||
}
|
||||
|
||||
return CreateLimitedInStream(_stream, (UInt64)blockIndex * kBlockSize, currentItemSize, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
}}
|
||||
// IsoHandler.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/ComTry.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "../../../Windows/PropVariant.h"
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
|
||||
#include "../../Common/LimitedStreams.h"
|
||||
#include "../../Common/ProgressUtils.h"
|
||||
|
||||
#include "../../Compress/CopyCoder.h"
|
||||
|
||||
#include "../Common/ItemNameUtils.h"
|
||||
|
||||
#include "IsoHandler.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NTime;
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
static const Byte kProps[] =
|
||||
{
|
||||
kpidPath,
|
||||
kpidIsDir,
|
||||
kpidSize,
|
||||
kpidPackSize,
|
||||
kpidMTime,
|
||||
// kpidCTime,
|
||||
// kpidATime,
|
||||
kpidPosixAttrib,
|
||||
// kpidUser,
|
||||
// kpidGroup,
|
||||
// kpidLinks,
|
||||
kpidSymLink
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
{
|
||||
kpidComment,
|
||||
kpidCTime,
|
||||
kpidMTime,
|
||||
// kpidHeadersSize
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps
|
||||
|
||||
STDMETHODIMP CHandler::Open(IInStream *stream,
|
||||
const UInt64 * /* maxCheckStartPosition */,
|
||||
IArchiveOpenCallback * /* openArchiveCallback */)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
Close();
|
||||
{
|
||||
RINOK(_archive.Open(stream));
|
||||
_stream = stream;
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
_archive.Clear();
|
||||
_stream.Release();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
{
|
||||
*numItems = _archive.Refs.Size() + _archive.BootEntries.Size();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void AddString(AString &s, const char *name, const Byte *p, unsigned size)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < size && p[i]; i++);
|
||||
for (; i > 0 && p[i - 1] == ' '; i--);
|
||||
if (i != 0)
|
||||
{
|
||||
AString d;
|
||||
d.SetFrom((const char *)p, i);
|
||||
s += '\n';
|
||||
s += name;
|
||||
s += ": ";
|
||||
s += d;
|
||||
}
|
||||
}
|
||||
|
||||
#define ADD_STRING(n, v) AddString(s, n, vol. v, sizeof(vol. v))
|
||||
|
||||
static void AddErrorMessage(AString &s, const char *message)
|
||||
{
|
||||
if (!s.IsEmpty())
|
||||
s += ". ";
|
||||
s += message;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
if (_stream)
|
||||
{
|
||||
const CVolumeDescriptor &vol = _archive.VolDescs[_archive.MainVolDescIndex];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidComment:
|
||||
{
|
||||
AString s;
|
||||
ADD_STRING("System", SystemId);
|
||||
ADD_STRING("Volume", VolumeId);
|
||||
ADD_STRING("VolumeSet", VolumeSetId);
|
||||
ADD_STRING("Publisher", PublisherId);
|
||||
ADD_STRING("Preparer", DataPreparerId);
|
||||
ADD_STRING("Application", ApplicationId);
|
||||
ADD_STRING("Copyright", CopyrightFileId);
|
||||
ADD_STRING("Abstract", AbstractFileId);
|
||||
ADD_STRING("Bib", BibFileId);
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
case kpidCTime: { FILETIME utc; if (vol.CTime.GetFileTime(utc)) prop = utc; break; }
|
||||
case kpidMTime: { FILETIME utc; if (vol.MTime.GetFileTime(utc)) prop = utc; break; }
|
||||
}
|
||||
}
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPhySize: prop = _archive.PhySize; break;
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
if (!_archive.IsArc) v |= kpv_ErrorFlags_IsNotArc;
|
||||
if (_archive.UnexpectedEnd) v |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
if (_archive.HeadersError) v |= kpv_ErrorFlags_HeadersError;
|
||||
prop = v;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidError:
|
||||
{
|
||||
AString s;
|
||||
if (_archive.IncorrectBigEndian)
|
||||
AddErrorMessage(s, "Incorrect big-endian headers");
|
||||
if (_archive.SelfLinkedDirs)
|
||||
AddErrorMessage(s, "Self-linked directory");
|
||||
if (_archive.TooDeepDirs)
|
||||
AddErrorMessage(s, "Too deep directory levels");
|
||||
if (!s.IsEmpty())
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
if (index >= (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
index -= _archive.Refs.Size();
|
||||
const CBootInitialEntry &be = _archive.BootEntries[index];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
{
|
||||
AString s ("[BOOT]" STRING_PATH_SEPARATOR);
|
||||
if (_archive.BootEntries.Size() != 1)
|
||||
{
|
||||
s.Add_UInt32(index + 1);
|
||||
s += '-';
|
||||
}
|
||||
s += be.GetName();
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
case kpidIsDir: prop = false; break;
|
||||
case kpidSize:
|
||||
case kpidPackSize:
|
||||
prop = (UInt64)_archive.GetBootItemSize(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
// if (item.FileId.GetCapacity() >= 0)
|
||||
{
|
||||
UString s;
|
||||
if (_archive.IsJoliet())
|
||||
item.GetPathU(s);
|
||||
else
|
||||
s = MultiByteToUnicodeString(item.GetPath(_archive.IsSusp, _archive.SuspSkipSize), CP_OEMCP);
|
||||
|
||||
if (s.Len() >= 2 && s[s.Len() - 2] == ';' && s.Back() == '1')
|
||||
s.DeleteFrom(s.Len() - 2);
|
||||
|
||||
if (!s.IsEmpty() && s.Back() == L'.')
|
||||
s.DeleteBack();
|
||||
|
||||
NItemName::ReplaceToOsSlashes_Remove_TailSlash(s);
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
|
||||
case kpidSymLink:
|
||||
if (_archive.IsSusp)
|
||||
{
|
||||
UString s;
|
||||
UInt32 mode;
|
||||
if (item.GetPx(_archive.SuspSkipSize, k_Px_Mode, mode))
|
||||
{
|
||||
if (((mode >> 12) & 0xF) == 10)
|
||||
{
|
||||
AString s8;
|
||||
if (item.GetSymLink(_archive.SuspSkipSize, s8))
|
||||
{
|
||||
s = MultiByteToUnicodeString(s8, CP_OEMCP);
|
||||
prop = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case kpidPosixAttrib:
|
||||
/*
|
||||
case kpidLinks:
|
||||
case kpidUser:
|
||||
case kpidGroup:
|
||||
*/
|
||||
{
|
||||
if (_archive.IsSusp)
|
||||
{
|
||||
UInt32 t = 0;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPosixAttrib: t = k_Px_Mode; break;
|
||||
/*
|
||||
case kpidLinks: t = k_Px_Links; break;
|
||||
case kpidUser: t = k_Px_User; break;
|
||||
case kpidGroup: t = k_Px_Group; break;
|
||||
*/
|
||||
}
|
||||
UInt32 v;
|
||||
if (item.GetPx(_archive.SuspSkipSize, t, v))
|
||||
prop = v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidIsDir: prop = item.IsDir(); break;
|
||||
case kpidSize:
|
||||
case kpidPackSize:
|
||||
if (!item.IsDir())
|
||||
prop = (UInt64)ref.TotalSize;
|
||||
break;
|
||||
|
||||
case kpidMTime:
|
||||
// case kpidCTime:
|
||||
// case kpidATime:
|
||||
{
|
||||
FILETIME utc;
|
||||
if (/* propID == kpidMTime && */ item.DateTime.GetFileTime(utc))
|
||||
prop = utc;
|
||||
/*
|
||||
else
|
||||
{
|
||||
UInt32 t = 0;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidMTime: t = k_Tf_MTime; break;
|
||||
case kpidCTime: t = k_Tf_CTime; break;
|
||||
case kpidATime: t = k_Tf_ATime; break;
|
||||
}
|
||||
CRecordingDateTime dt;
|
||||
if (item.GetTf(_archive.SuspSkipSize, t, dt))
|
||||
{
|
||||
FILETIME utc;
|
||||
if (dt.GetFileTime(utc))
|
||||
prop = utc;
|
||||
}
|
||||
}
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = _archive.Refs.Size();
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 index = (allFilesMode ? i : indices[i]);
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
if (!item.IsDir())
|
||||
totalSize += ref.TotalSize;
|
||||
}
|
||||
else
|
||||
totalSize += _archive.GetBootItemSize(index - _archive.Refs.Size());
|
||||
}
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
UInt64 currentTotalSize = 0;
|
||||
UInt64 currentItemSize;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
|
||||
{
|
||||
lps->InSize = lps->OutSize = currentTotalSize;
|
||||
RINOK(lps->SetCur());
|
||||
currentItemSize = 0;
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
UInt32 index = allFilesMode ? i : indices[i];
|
||||
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
|
||||
UInt64 blockIndex;
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
if (item.IsDir())
|
||||
{
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
|
||||
continue;
|
||||
}
|
||||
currentItemSize = ref.TotalSize;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned bootIndex = index - _archive.Refs.Size();
|
||||
const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
|
||||
currentItemSize = _archive.GetBootItemSize(bootIndex);
|
||||
blockIndex = be.LoadRBA;
|
||||
}
|
||||
|
||||
|
||||
if (!testMode && !realOutStream)
|
||||
continue;
|
||||
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
bool isOK = true;
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
UInt64 offset = 0;
|
||||
for (UInt32 e = 0; e < ref.NumExtents; e++)
|
||||
{
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + e];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
lps->InSize = lps->OutSize = currentTotalSize + offset;
|
||||
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(item2.Size);
|
||||
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
|
||||
if (copyCoderSpec->TotalSize != item2.Size)
|
||||
{
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
offset += item2.Size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(_stream->Seek((UInt64)blockIndex * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(currentItemSize);
|
||||
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));
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*stream = 0;
|
||||
UInt64 blockIndex;
|
||||
UInt64 currentItemSize;
|
||||
|
||||
if (index < _archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
if (item.IsDir())
|
||||
return S_FALSE;
|
||||
|
||||
if (ref.NumExtents > 1)
|
||||
{
|
||||
CExtentsStream *extentStreamSpec = new CExtentsStream();
|
||||
CMyComPtr<ISequentialInStream> extentStream = extentStreamSpec;
|
||||
|
||||
extentStreamSpec->Stream = _stream;
|
||||
|
||||
UInt64 virtOffset = 0;
|
||||
for (UInt32 i = 0; i < ref.NumExtents; i++)
|
||||
{
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + i];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
CSeekExtent se;
|
||||
se.Phy = (UInt64)item2.ExtentLocation * kBlockSize;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
virtOffset += item2.Size;
|
||||
}
|
||||
if (virtOffset != ref.TotalSize)
|
||||
return S_FALSE;
|
||||
CSeekExtent se;
|
||||
se.Phy = 0;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
extentStreamSpec->Init();
|
||||
*stream = extentStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
currentItemSize = item.Size;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned bootIndex = index - _archive.Refs.Size();
|
||||
const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
|
||||
currentItemSize = _archive.GetBootItemSize(bootIndex);
|
||||
blockIndex = be.LoadRBA;
|
||||
}
|
||||
|
||||
return CreateLimitedInStream(_stream, (UInt64)blockIndex * kBlockSize, currentItemSize, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
// IsoHandler.h
|
||||
|
||||
#ifndef __ISO_HANDLER_H
|
||||
#define __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
|
||||
{
|
||||
CMyComPtr<IInStream> _stream;
|
||||
CInArchive _archive;
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive(;)
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
// IsoHandler.h
|
||||
|
||||
#ifndef __ISO_HANDLER_H
|
||||
#define __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
|
||||
{
|
||||
CMyComPtr<IInStream> _stream;
|
||||
CInArchive _archive;
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive(;)
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Archive/Iso/Header.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "IsoHeader.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
const char * const kElToritoSpec = "EL TORITO SPECIFICATION\0\0\0\0\0\0\0\0\0";
|
||||
|
||||
}}
|
||||
// Archive/Iso/Header.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "IsoHeader.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
const char * const kElToritoSpec = "EL TORITO SPECIFICATION\0\0\0\0\0\0\0\0\0";
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
// Archive/IsoHeader.h
|
||||
|
||||
#ifndef __ARCHIVE_ISO_HEADER_H
|
||||
#define __ARCHIVE_ISO_HEADER_H
|
||||
|
||||
#include "../../../Common/MyTypes.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
namespace NVolDescType
|
||||
{
|
||||
const Byte kBootRecord = 0;
|
||||
const Byte kPrimaryVol = 1;
|
||||
const Byte kSupplementaryVol = 2;
|
||||
const Byte kVolParttition = 3;
|
||||
const Byte kTerminator = 255;
|
||||
}
|
||||
|
||||
const Byte kVersion = 1;
|
||||
|
||||
namespace NFileFlags
|
||||
{
|
||||
const Byte kDirectory = 1 << 1;
|
||||
const Byte kNonFinalExtent = 1 << 7;
|
||||
}
|
||||
|
||||
extern const char * const kElToritoSpec;
|
||||
|
||||
const UInt32 kStartPos = 0x8000;
|
||||
|
||||
namespace NBootEntryId
|
||||
{
|
||||
const Byte kValidationEntry = 1;
|
||||
const Byte kInitialEntryNotBootable = 0;
|
||||
const Byte kInitialEntryBootable = 0x88;
|
||||
|
||||
const Byte kMoreHeaders = 0x90;
|
||||
const Byte kFinalHeader = 0x91;
|
||||
|
||||
const Byte kExtensionIndicator = 0x44;
|
||||
}
|
||||
|
||||
namespace NBootPlatformId
|
||||
{
|
||||
const Byte kX86 = 0;
|
||||
const Byte kPowerPC = 1;
|
||||
const Byte kMac = 2;
|
||||
}
|
||||
|
||||
const Byte kBootMediaTypeMask = 0xF;
|
||||
|
||||
namespace NBootMediaType
|
||||
{
|
||||
const Byte kNoEmulation = 0;
|
||||
const Byte k1d2Floppy = 1;
|
||||
const Byte k1d44Floppy = 2;
|
||||
const Byte k2d88Floppy = 3;
|
||||
const Byte kHardDisk = 4;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
// Archive/IsoHeader.h
|
||||
|
||||
#ifndef __ARCHIVE_ISO_HEADER_H
|
||||
#define __ARCHIVE_ISO_HEADER_H
|
||||
|
||||
#include "../../../Common/MyTypes.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
namespace NVolDescType
|
||||
{
|
||||
const Byte kBootRecord = 0;
|
||||
const Byte kPrimaryVol = 1;
|
||||
const Byte kSupplementaryVol = 2;
|
||||
const Byte kVolParttition = 3;
|
||||
const Byte kTerminator = 255;
|
||||
}
|
||||
|
||||
const Byte kVersion = 1;
|
||||
|
||||
namespace NFileFlags
|
||||
{
|
||||
const Byte kDirectory = 1 << 1;
|
||||
const Byte kNonFinalExtent = 1 << 7;
|
||||
}
|
||||
|
||||
extern const char * const kElToritoSpec;
|
||||
|
||||
const UInt32 kStartPos = 0x8000;
|
||||
|
||||
namespace NBootEntryId
|
||||
{
|
||||
const Byte kValidationEntry = 1;
|
||||
const Byte kInitialEntryNotBootable = 0;
|
||||
const Byte kInitialEntryBootable = 0x88;
|
||||
|
||||
const Byte kMoreHeaders = 0x90;
|
||||
const Byte kFinalHeader = 0x91;
|
||||
|
||||
const Byte kExtensionIndicator = 0x44;
|
||||
}
|
||||
|
||||
namespace NBootPlatformId
|
||||
{
|
||||
const Byte kX86 = 0;
|
||||
const Byte kPowerPC = 1;
|
||||
const Byte kMac = 2;
|
||||
}
|
||||
|
||||
const Byte kBootMediaTypeMask = 0xF;
|
||||
|
||||
namespace NBootMediaType
|
||||
{
|
||||
const Byte kNoEmulation = 0;
|
||||
const Byte k1d2Floppy = 1;
|
||||
const Byte k1d44Floppy = 2;
|
||||
const Byte k2d88Floppy = 3;
|
||||
const Byte kHardDisk = 4;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,332 +1,332 @@
|
||||
// Archive/IsoIn.h
|
||||
|
||||
#ifndef __ARCHIVE_ISO_IN_H
|
||||
#define __ARCHIVE_ISO_IN_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
#include "IsoHeader.h"
|
||||
#include "IsoItem.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
struct CDir: public CDirRecord
|
||||
{
|
||||
CDir *Parent;
|
||||
CObjectVector<CDir> _subItems;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Parent = 0;
|
||||
_subItems.Clear();
|
||||
}
|
||||
|
||||
AString GetPath(bool checkSusp, unsigned skipSize) const
|
||||
{
|
||||
AString s;
|
||||
|
||||
unsigned len = 0;
|
||||
const CDir *cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen;
|
||||
cur->GetNameCur(checkSusp, skipSize, curLen);
|
||||
len += curLen;
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
len++;
|
||||
}
|
||||
|
||||
char *p = s.GetBuf_SetEnd(len) + len;
|
||||
|
||||
cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen;
|
||||
const Byte *name = cur->GetNameCur(checkSusp, skipSize, curLen);
|
||||
p -= curLen;
|
||||
if (curLen != 0)
|
||||
memcpy(p, name, curLen);
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
p--;
|
||||
*p = CHAR_PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void GetPathU(UString &s) const
|
||||
{
|
||||
s.Empty();
|
||||
|
||||
unsigned len = 0;
|
||||
const CDir *cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen = (unsigned)(cur->FileId.Size() / 2);
|
||||
const Byte *fid = cur->FileId;
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < curLen; i++)
|
||||
if (fid[i * 2] == 0 && fid[i * 2 + 1] == 0)
|
||||
break;
|
||||
len += i;
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
len++;
|
||||
}
|
||||
|
||||
wchar_t *p = s.GetBuf_SetEnd(len) + len;
|
||||
|
||||
cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen = (unsigned)(cur->FileId.Size() / 2);
|
||||
const Byte *fid = cur->FileId;
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < curLen; i++)
|
||||
if (fid[i * 2] == 0 && fid[i * 2 + 1] == 0)
|
||||
break;
|
||||
curLen = i;
|
||||
|
||||
p -= curLen;
|
||||
for (i = 0; i < curLen; i++)
|
||||
p[i] = (wchar_t)(((wchar_t)fid[i * 2] << 8) | fid[i * 2 + 1]);
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
p--;
|
||||
*p = WCHAR_PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CDateTime
|
||||
{
|
||||
UInt16 Year;
|
||||
Byte Month;
|
||||
Byte Day;
|
||||
Byte Hour;
|
||||
Byte Minute;
|
||||
Byte Second;
|
||||
Byte Hundredths;
|
||||
signed char GmtOffset; // min intervals from -48 (West) to +52 (East) recorded.
|
||||
|
||||
bool NotSpecified() const { return Year == 0 && Month == 0 && Day == 0 &&
|
||||
Hour == 0 && Minute == 0 && Second == 0 && GmtOffset == 0; }
|
||||
|
||||
bool GetFileTime(FILETIME &ft) const
|
||||
{
|
||||
UInt64 value;
|
||||
bool res = NWindows::NTime::GetSecondsSince1601(Year, Month, Day, Hour, Minute, Second, value);
|
||||
if (res)
|
||||
{
|
||||
value -= (Int64)((Int32)GmtOffset * 15 * 60);
|
||||
value *= 10000000;
|
||||
}
|
||||
ft.dwLowDateTime = (DWORD)value;
|
||||
ft.dwHighDateTime = (DWORD)(value >> 32);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
struct CBootRecordDescriptor
|
||||
{
|
||||
Byte BootSystemId[32]; // a-characters
|
||||
Byte BootId[32]; // a-characters
|
||||
Byte BootSystemUse[1977];
|
||||
};
|
||||
|
||||
struct CBootValidationEntry
|
||||
{
|
||||
Byte PlatformId;
|
||||
Byte Id[24]; // to identify the manufacturer/developer of the CD-ROM.
|
||||
};
|
||||
|
||||
struct CBootInitialEntry
|
||||
{
|
||||
bool Bootable;
|
||||
Byte BootMediaType;
|
||||
UInt16 LoadSegment;
|
||||
/* This is the load segment for the initial boot image. If this
|
||||
value is 0 the system will use the traditional segment of 7C0. If this value
|
||||
is non-zero the system will use the specified segment. This applies to x86
|
||||
architectures only. For "flat" model architectures (such as Motorola) this
|
||||
is the address divided by 10. */
|
||||
Byte SystemType; // This must be a copy of byte 5 (System Type) from the
|
||||
// Partition Table found in the boot image.
|
||||
UInt16 SectorCount; // This is the number of virtual/emulated sectors the system
|
||||
// will store at Load Segment during the initial boot procedure.
|
||||
UInt32 LoadRBA; // This is the start address of the virtual disk. CDs use
|
||||
// Relative/Logical block addressing.
|
||||
|
||||
Byte VendorSpec[20];
|
||||
|
||||
UInt32 GetSize() const
|
||||
{
|
||||
// if (BootMediaType == NBootMediaType::k1d44Floppy) (1440 << 10);
|
||||
return (UInt32)SectorCount * 512;
|
||||
}
|
||||
|
||||
bool Parse(const Byte *p);
|
||||
AString GetName() const;
|
||||
};
|
||||
|
||||
struct CVolumeDescriptor
|
||||
{
|
||||
Byte VolFlags;
|
||||
Byte SystemId[32]; // a-characters. An identification of a system
|
||||
// which can recognize and act upon the content of the Logical
|
||||
// Sectors with logical Sector Numbers 0 to 15 of the volume.
|
||||
Byte VolumeId[32]; // d-characters. An identification of the volume.
|
||||
UInt32 VolumeSpaceSize; // the number of Logical Blocks in which the Volume Space of the volume is recorded
|
||||
Byte EscapeSequence[32];
|
||||
UInt16 VolumeSetSize;
|
||||
UInt16 VolumeSequenceNumber; // the ordinal number of the volume in the Volume Set of which the volume is a member.
|
||||
UInt16 LogicalBlockSize;
|
||||
UInt32 PathTableSize;
|
||||
UInt32 LPathTableLocation;
|
||||
UInt32 LOptionalPathTableLocation;
|
||||
UInt32 MPathTableLocation;
|
||||
UInt32 MOptionalPathTableLocation;
|
||||
CDirRecord RootDirRecord;
|
||||
Byte VolumeSetId[128];
|
||||
Byte PublisherId[128];
|
||||
Byte DataPreparerId[128];
|
||||
Byte ApplicationId[128];
|
||||
Byte CopyrightFileId[37];
|
||||
Byte AbstractFileId[37];
|
||||
Byte BibFileId[37];
|
||||
CDateTime CTime;
|
||||
CDateTime MTime;
|
||||
CDateTime ExpirationTime;
|
||||
CDateTime EffectiveTime;
|
||||
Byte FileStructureVersion; // = 1;
|
||||
Byte ApplicationUse[512];
|
||||
|
||||
bool IsJoliet() const
|
||||
{
|
||||
if ((VolFlags & 1) != 0)
|
||||
return false;
|
||||
Byte b = EscapeSequence[2];
|
||||
return (EscapeSequence[0] == 0x25 && EscapeSequence[1] == 0x2F &&
|
||||
(b == 0x40 || b == 0x43 || b == 0x45));
|
||||
}
|
||||
};
|
||||
|
||||
struct CRef
|
||||
{
|
||||
const CDir *Dir;
|
||||
UInt32 Index;
|
||||
UInt32 NumExtents;
|
||||
UInt64 TotalSize;
|
||||
};
|
||||
|
||||
const UInt32 kBlockSize = 1 << 11;
|
||||
|
||||
class CInArchive
|
||||
{
|
||||
IInStream *_stream;
|
||||
UInt64 _position;
|
||||
|
||||
UInt32 m_BufferPos;
|
||||
|
||||
CDir _rootDir;
|
||||
bool _bootIsDefined;
|
||||
CBootRecordDescriptor _bootDesc;
|
||||
|
||||
void Skip(size_t size);
|
||||
void SkipZeros(size_t size);
|
||||
Byte ReadByte();
|
||||
void ReadBytes(Byte *data, UInt32 size);
|
||||
UInt16 ReadUInt16();
|
||||
UInt32 ReadUInt32Le();
|
||||
UInt32 ReadUInt32Be();
|
||||
UInt32 ReadUInt32();
|
||||
UInt64 ReadUInt64();
|
||||
UInt32 ReadDigits(int numDigits);
|
||||
void ReadDateTime(CDateTime &d);
|
||||
void ReadRecordingDateTime(CRecordingDateTime &t);
|
||||
void ReadDirRecord2(CDirRecord &r, Byte len);
|
||||
void ReadDirRecord(CDirRecord &r);
|
||||
|
||||
void ReadBootRecordDescriptor(CBootRecordDescriptor &d);
|
||||
void ReadVolumeDescriptor(CVolumeDescriptor &d);
|
||||
|
||||
void SeekToBlock(UInt32 blockIndex);
|
||||
void ReadDir(CDir &d, int level);
|
||||
void CreateRefs(CDir &d);
|
||||
|
||||
void ReadBootInfo();
|
||||
HRESULT Open2();
|
||||
public:
|
||||
HRESULT Open(IInStream *inStream);
|
||||
void Clear();
|
||||
|
||||
UInt64 _fileSize;
|
||||
UInt64 PhySize;
|
||||
|
||||
CRecordVector<CRef> Refs;
|
||||
CObjectVector<CVolumeDescriptor> VolDescs;
|
||||
int MainVolDescIndex;
|
||||
// UInt32 BlockSize;
|
||||
CObjectVector<CBootInitialEntry> BootEntries;
|
||||
|
||||
bool IsArc;
|
||||
bool UnexpectedEnd;
|
||||
bool HeadersError;
|
||||
bool IncorrectBigEndian;
|
||||
bool TooDeepDirs;
|
||||
bool SelfLinkedDirs;
|
||||
CRecordVector<UInt32> UniqStartLocations;
|
||||
|
||||
Byte m_Buffer[kBlockSize];
|
||||
|
||||
void UpdatePhySize(UInt32 blockIndex, UInt64 size)
|
||||
{
|
||||
const UInt64 alignedSize = (size + kBlockSize - 1) & ~((UInt64)kBlockSize - 1);
|
||||
const UInt64 end = (UInt64)blockIndex * kBlockSize + alignedSize;
|
||||
if (PhySize < end)
|
||||
PhySize = end;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool IsSusp;
|
||||
unsigned SuspSkipSize;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
// Archive/IsoIn.h
|
||||
|
||||
#ifndef __ARCHIVE_ISO_IN_H
|
||||
#define __ARCHIVE_ISO_IN_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
#include "IsoHeader.h"
|
||||
#include "IsoItem.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
struct CDir: public CDirRecord
|
||||
{
|
||||
CDir *Parent;
|
||||
CObjectVector<CDir> _subItems;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Parent = 0;
|
||||
_subItems.Clear();
|
||||
}
|
||||
|
||||
AString GetPath(bool checkSusp, unsigned skipSize) const
|
||||
{
|
||||
AString s;
|
||||
|
||||
unsigned len = 0;
|
||||
const CDir *cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen;
|
||||
cur->GetNameCur(checkSusp, skipSize, curLen);
|
||||
len += curLen;
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
len++;
|
||||
}
|
||||
|
||||
char *p = s.GetBuf_SetEnd(len) + len;
|
||||
|
||||
cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen;
|
||||
const Byte *name = cur->GetNameCur(checkSusp, skipSize, curLen);
|
||||
p -= curLen;
|
||||
if (curLen != 0)
|
||||
memcpy(p, name, curLen);
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
p--;
|
||||
*p = CHAR_PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void GetPathU(UString &s) const
|
||||
{
|
||||
s.Empty();
|
||||
|
||||
unsigned len = 0;
|
||||
const CDir *cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen = (unsigned)(cur->FileId.Size() / 2);
|
||||
const Byte *fid = cur->FileId;
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < curLen; i++)
|
||||
if (fid[i * 2] == 0 && fid[i * 2 + 1] == 0)
|
||||
break;
|
||||
len += i;
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
len++;
|
||||
}
|
||||
|
||||
wchar_t *p = s.GetBuf_SetEnd(len) + len;
|
||||
|
||||
cur = this;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned curLen = (unsigned)(cur->FileId.Size() / 2);
|
||||
const Byte *fid = cur->FileId;
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < curLen; i++)
|
||||
if (fid[i * 2] == 0 && fid[i * 2 + 1] == 0)
|
||||
break;
|
||||
curLen = i;
|
||||
|
||||
p -= curLen;
|
||||
for (i = 0; i < curLen; i++)
|
||||
p[i] = (wchar_t)(((wchar_t)fid[i * 2] << 8) | fid[i * 2 + 1]);
|
||||
cur = cur->Parent;
|
||||
if (!cur || !cur->Parent)
|
||||
break;
|
||||
p--;
|
||||
*p = WCHAR_PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CDateTime
|
||||
{
|
||||
UInt16 Year;
|
||||
Byte Month;
|
||||
Byte Day;
|
||||
Byte Hour;
|
||||
Byte Minute;
|
||||
Byte Second;
|
||||
Byte Hundredths;
|
||||
signed char GmtOffset; // min intervals from -48 (West) to +52 (East) recorded.
|
||||
|
||||
bool NotSpecified() const { return Year == 0 && Month == 0 && Day == 0 &&
|
||||
Hour == 0 && Minute == 0 && Second == 0 && GmtOffset == 0; }
|
||||
|
||||
bool GetFileTime(FILETIME &ft) const
|
||||
{
|
||||
UInt64 value;
|
||||
bool res = NWindows::NTime::GetSecondsSince1601(Year, Month, Day, Hour, Minute, Second, value);
|
||||
if (res)
|
||||
{
|
||||
value -= (Int64)((Int32)GmtOffset * 15 * 60);
|
||||
value *= 10000000;
|
||||
}
|
||||
ft.dwLowDateTime = (DWORD)value;
|
||||
ft.dwHighDateTime = (DWORD)(value >> 32);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
struct CBootRecordDescriptor
|
||||
{
|
||||
Byte BootSystemId[32]; // a-characters
|
||||
Byte BootId[32]; // a-characters
|
||||
Byte BootSystemUse[1977];
|
||||
};
|
||||
|
||||
struct CBootValidationEntry
|
||||
{
|
||||
Byte PlatformId;
|
||||
Byte Id[24]; // to identify the manufacturer/developer of the CD-ROM.
|
||||
};
|
||||
|
||||
struct CBootInitialEntry
|
||||
{
|
||||
bool Bootable;
|
||||
Byte BootMediaType;
|
||||
UInt16 LoadSegment;
|
||||
/* This is the load segment for the initial boot image. If this
|
||||
value is 0 the system will use the traditional segment of 7C0. If this value
|
||||
is non-zero the system will use the specified segment. This applies to x86
|
||||
architectures only. For "flat" model architectures (such as Motorola) this
|
||||
is the address divided by 10. */
|
||||
Byte SystemType; // This must be a copy of byte 5 (System Type) from the
|
||||
// Partition Table found in the boot image.
|
||||
UInt16 SectorCount; // This is the number of virtual/emulated sectors the system
|
||||
// will store at Load Segment during the initial boot procedure.
|
||||
UInt32 LoadRBA; // This is the start address of the virtual disk. CDs use
|
||||
// Relative/Logical block addressing.
|
||||
|
||||
Byte VendorSpec[20];
|
||||
|
||||
UInt32 GetSize() const
|
||||
{
|
||||
// if (BootMediaType == NBootMediaType::k1d44Floppy) (1440 << 10);
|
||||
return (UInt32)SectorCount * 512;
|
||||
}
|
||||
|
||||
bool Parse(const Byte *p);
|
||||
AString GetName() const;
|
||||
};
|
||||
|
||||
struct CVolumeDescriptor
|
||||
{
|
||||
Byte VolFlags;
|
||||
Byte SystemId[32]; // a-characters. An identification of a system
|
||||
// which can recognize and act upon the content of the Logical
|
||||
// Sectors with logical Sector Numbers 0 to 15 of the volume.
|
||||
Byte VolumeId[32]; // d-characters. An identification of the volume.
|
||||
UInt32 VolumeSpaceSize; // the number of Logical Blocks in which the Volume Space of the volume is recorded
|
||||
Byte EscapeSequence[32];
|
||||
UInt16 VolumeSetSize;
|
||||
UInt16 VolumeSequenceNumber; // the ordinal number of the volume in the Volume Set of which the volume is a member.
|
||||
UInt16 LogicalBlockSize;
|
||||
UInt32 PathTableSize;
|
||||
UInt32 LPathTableLocation;
|
||||
UInt32 LOptionalPathTableLocation;
|
||||
UInt32 MPathTableLocation;
|
||||
UInt32 MOptionalPathTableLocation;
|
||||
CDirRecord RootDirRecord;
|
||||
Byte VolumeSetId[128];
|
||||
Byte PublisherId[128];
|
||||
Byte DataPreparerId[128];
|
||||
Byte ApplicationId[128];
|
||||
Byte CopyrightFileId[37];
|
||||
Byte AbstractFileId[37];
|
||||
Byte BibFileId[37];
|
||||
CDateTime CTime;
|
||||
CDateTime MTime;
|
||||
CDateTime ExpirationTime;
|
||||
CDateTime EffectiveTime;
|
||||
Byte FileStructureVersion; // = 1;
|
||||
Byte ApplicationUse[512];
|
||||
|
||||
bool IsJoliet() const
|
||||
{
|
||||
if ((VolFlags & 1) != 0)
|
||||
return false;
|
||||
Byte b = EscapeSequence[2];
|
||||
return (EscapeSequence[0] == 0x25 && EscapeSequence[1] == 0x2F &&
|
||||
(b == 0x40 || b == 0x43 || b == 0x45));
|
||||
}
|
||||
};
|
||||
|
||||
struct CRef
|
||||
{
|
||||
const CDir *Dir;
|
||||
UInt32 Index;
|
||||
UInt32 NumExtents;
|
||||
UInt64 TotalSize;
|
||||
};
|
||||
|
||||
const UInt32 kBlockSize = 1 << 11;
|
||||
|
||||
class CInArchive
|
||||
{
|
||||
IInStream *_stream;
|
||||
UInt64 _position;
|
||||
|
||||
UInt32 m_BufferPos;
|
||||
|
||||
CDir _rootDir;
|
||||
bool _bootIsDefined;
|
||||
CBootRecordDescriptor _bootDesc;
|
||||
|
||||
void Skip(size_t size);
|
||||
void SkipZeros(size_t size);
|
||||
Byte ReadByte();
|
||||
void ReadBytes(Byte *data, UInt32 size);
|
||||
UInt16 ReadUInt16();
|
||||
UInt32 ReadUInt32Le();
|
||||
UInt32 ReadUInt32Be();
|
||||
UInt32 ReadUInt32();
|
||||
UInt64 ReadUInt64();
|
||||
UInt32 ReadDigits(int numDigits);
|
||||
void ReadDateTime(CDateTime &d);
|
||||
void ReadRecordingDateTime(CRecordingDateTime &t);
|
||||
void ReadDirRecord2(CDirRecord &r, Byte len);
|
||||
void ReadDirRecord(CDirRecord &r);
|
||||
|
||||
void ReadBootRecordDescriptor(CBootRecordDescriptor &d);
|
||||
void ReadVolumeDescriptor(CVolumeDescriptor &d);
|
||||
|
||||
void SeekToBlock(UInt32 blockIndex);
|
||||
void ReadDir(CDir &d, int level);
|
||||
void CreateRefs(CDir &d);
|
||||
|
||||
void ReadBootInfo();
|
||||
HRESULT Open2();
|
||||
public:
|
||||
HRESULT Open(IInStream *inStream);
|
||||
void Clear();
|
||||
|
||||
UInt64 _fileSize;
|
||||
UInt64 PhySize;
|
||||
|
||||
CRecordVector<CRef> Refs;
|
||||
CObjectVector<CVolumeDescriptor> VolDescs;
|
||||
int MainVolDescIndex;
|
||||
// UInt32 BlockSize;
|
||||
CObjectVector<CBootInitialEntry> BootEntries;
|
||||
|
||||
bool IsArc;
|
||||
bool UnexpectedEnd;
|
||||
bool HeadersError;
|
||||
bool IncorrectBigEndian;
|
||||
bool TooDeepDirs;
|
||||
bool SelfLinkedDirs;
|
||||
CRecordVector<UInt32> UniqStartLocations;
|
||||
|
||||
Byte m_Buffer[kBlockSize];
|
||||
|
||||
void UpdatePhySize(UInt32 blockIndex, UInt64 size)
|
||||
{
|
||||
const UInt64 alignedSize = (size + kBlockSize - 1) & ~((UInt64)kBlockSize - 1);
|
||||
const UInt64 end = (UInt64)blockIndex * kBlockSize + alignedSize;
|
||||
if (PhySize < end)
|
||||
PhySize = end;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool IsSusp;
|
||||
unsigned SuspSkipSize;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,321 +1,321 @@
|
||||
// Archive/IsoItem.h
|
||||
|
||||
#ifndef __ARCHIVE_ISO_ITEM_H
|
||||
#define __ARCHIVE_ISO_ITEM_H
|
||||
|
||||
#include "../../../../C/CpuArch.h"
|
||||
|
||||
#include "../../../Common/MyString.h"
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
|
||||
#include "IsoHeader.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
struct CRecordingDateTime
|
||||
{
|
||||
Byte Year;
|
||||
Byte Month;
|
||||
Byte Day;
|
||||
Byte Hour;
|
||||
Byte Minute;
|
||||
Byte Second;
|
||||
signed char GmtOffset; // min intervals from -48 (West) to +52 (East) recorded.
|
||||
|
||||
bool GetFileTime(FILETIME &ft) const
|
||||
{
|
||||
UInt64 value;
|
||||
bool res = NWindows::NTime::GetSecondsSince1601(Year + 1900, Month, Day, Hour, Minute, Second, value);
|
||||
if (res)
|
||||
{
|
||||
value -= (Int64)((Int32)GmtOffset * 15 * 60);
|
||||
value *= 10000000;
|
||||
}
|
||||
ft.dwLowDateTime = (DWORD)value;
|
||||
ft.dwHighDateTime = (DWORD)(value >> 32);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
enum EPx
|
||||
{
|
||||
k_Px_Mode,
|
||||
k_Px_Links,
|
||||
k_Px_User,
|
||||
k_Px_Group,
|
||||
k_Px_SerialNumber
|
||||
|
||||
// k_Px_Num
|
||||
};
|
||||
|
||||
/*
|
||||
enum ETf
|
||||
{
|
||||
k_Tf_CTime,
|
||||
k_Tf_MTime,
|
||||
k_Tf_ATime,
|
||||
k_Tf_Attrib,
|
||||
k_Tf_Backup,
|
||||
k_Tf_Expiration,
|
||||
k_Tf_Effective
|
||||
|
||||
// k_Tf_Num
|
||||
};
|
||||
*/
|
||||
|
||||
struct CDirRecord
|
||||
{
|
||||
UInt32 ExtentLocation;
|
||||
UInt32 Size;
|
||||
CRecordingDateTime DateTime;
|
||||
Byte FileFlags;
|
||||
Byte FileUnitSize;
|
||||
Byte InterleaveGapSize;
|
||||
Byte ExtendedAttributeRecordLen;
|
||||
UInt16 VolSequenceNumber;
|
||||
CByteBuffer FileId;
|
||||
CByteBuffer SystemUse;
|
||||
|
||||
bool AreMultiPartEqualWith(const CDirRecord &a) const
|
||||
{
|
||||
return FileId == a.FileId
|
||||
&& (FileFlags & (~NFileFlags::kNonFinalExtent)) ==
|
||||
(a.FileFlags & (~NFileFlags::kNonFinalExtent));
|
||||
}
|
||||
|
||||
bool IsDir() const { return (FileFlags & NFileFlags::kDirectory) != 0; }
|
||||
bool IsNonFinalExtent() const { return (FileFlags & NFileFlags::kNonFinalExtent) != 0; }
|
||||
|
||||
bool IsSystemItem() const
|
||||
{
|
||||
if (FileId.Size() != 1)
|
||||
return false;
|
||||
Byte b = *(const Byte *)FileId;
|
||||
return (b == 0 || b == 1);
|
||||
}
|
||||
|
||||
|
||||
const Byte* FindSuspRecord(unsigned skipSize, Byte id0, Byte id1, unsigned &lenRes) const
|
||||
{
|
||||
lenRes = 0;
|
||||
if (SystemUse.Size() < skipSize)
|
||||
return 0;
|
||||
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;
|
||||
if (p[0] == id0 && p[1] == id1 && p[3] == 1)
|
||||
{
|
||||
if (len < 4)
|
||||
return 0; // Check it
|
||||
lenRes = len - 4;
|
||||
return p + 4;
|
||||
}
|
||||
p += len;
|
||||
rem -= len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const Byte* GetNameCur(bool checkSusp, int skipSize, unsigned &nameLenRes) const
|
||||
{
|
||||
const Byte *res = NULL;
|
||||
unsigned len = 0;
|
||||
if (checkSusp)
|
||||
res = FindSuspRecord(skipSize, 'N', 'M', len);
|
||||
if (!res || len < 1)
|
||||
{
|
||||
res = (const Byte *)FileId;
|
||||
len = (unsigned)FileId.Size();
|
||||
}
|
||||
else
|
||||
{
|
||||
res++;
|
||||
len--;
|
||||
}
|
||||
unsigned i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (res[i] == 0)
|
||||
break;
|
||||
nameLenRes = i;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
const bool GetSymLink(int skipSize, AString &link) const
|
||||
{
|
||||
link.Empty();
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'S', 'L', len);
|
||||
if (!p || len < 1)
|
||||
return false;
|
||||
|
||||
if (*p != 0)
|
||||
return false;
|
||||
|
||||
p++;
|
||||
len--;
|
||||
|
||||
while (len != 0)
|
||||
{
|
||||
if (len < 2)
|
||||
return false;
|
||||
unsigned flags = p[0];
|
||||
unsigned cl = p[1];
|
||||
p += 2;
|
||||
len -= 2;
|
||||
|
||||
if (cl > len)
|
||||
return false;
|
||||
|
||||
bool needSlash = false;
|
||||
|
||||
if (flags & (1 << 1)) link += "./";
|
||||
else if (flags & (1 << 2)) link += "../";
|
||||
else if (flags & (1 << 3)) link += '/';
|
||||
else
|
||||
needSlash = true;
|
||||
|
||||
for (unsigned i = 0; i < cl; i++)
|
||||
{
|
||||
char c = p[i];
|
||||
if (c == 0)
|
||||
{
|
||||
break;
|
||||
// return false;
|
||||
}
|
||||
link += c;
|
||||
}
|
||||
|
||||
p += cl;
|
||||
len -= cl;
|
||||
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
if (needSlash)
|
||||
link += '/';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const bool GetLe32Be32(const Byte *p, UInt32 &dest)
|
||||
{
|
||||
UInt32 v1 = GetUi32(p);
|
||||
UInt32 v2 = GetBe32(p + 4);
|
||||
if (v1 == v2)
|
||||
{
|
||||
dest = v1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const bool GetPx(int skipSize, unsigned pxType, UInt32 &val) const
|
||||
{
|
||||
val = 0;
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'P', 'X', len);
|
||||
if (!p)
|
||||
return false;
|
||||
// px.Clear();
|
||||
if (len < ((unsigned)pxType + 1) * 8)
|
||||
return false;
|
||||
|
||||
return GetLe32Be32(p + pxType * 8, val);
|
||||
}
|
||||
|
||||
/*
|
||||
const bool GetTf(int skipSize, unsigned pxType, CRecordingDateTime &t) const
|
||||
{
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'T', 'F', len);
|
||||
if (!p)
|
||||
return false;
|
||||
if (len < 1)
|
||||
return false;
|
||||
Byte flags = *p++;
|
||||
len--;
|
||||
|
||||
unsigned step = 7;
|
||||
if (flags & 0x80)
|
||||
{
|
||||
step = 17;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & (1 << pxType)) == 0)
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < pxType; i++)
|
||||
{
|
||||
if (len < step)
|
||||
return false;
|
||||
if (flags & (1 << i))
|
||||
{
|
||||
p += step;
|
||||
len -= step;
|
||||
}
|
||||
}
|
||||
|
||||
if (len < step)
|
||||
return false;
|
||||
|
||||
t.Year = p[0];
|
||||
t.Month = p[1];
|
||||
t.Day = p[2];
|
||||
t.Hour = p[3];
|
||||
t.Minute = p[4];
|
||||
t.Second = p[5];
|
||||
t.GmtOffset = (signed char)p[6];
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
bool CheckSusp(const Byte *p, unsigned &startPos) const
|
||||
{
|
||||
if (p[0] == 'S' &&
|
||||
p[1] == 'P' &&
|
||||
p[2] == 0x7 &&
|
||||
p[3] == 0x1 &&
|
||||
p[4] == 0xBE &&
|
||||
p[5] == 0xEF)
|
||||
{
|
||||
startPos = p[6];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CheckSusp(unsigned &startPos) const
|
||||
{
|
||||
const Byte *p = (const Byte *)SystemUse;
|
||||
unsigned len = (int)SystemUse.Size();
|
||||
const unsigned kMinLen = 7;
|
||||
if (len < kMinLen)
|
||||
return false;
|
||||
if (CheckSusp(p, startPos))
|
||||
return true;
|
||||
const unsigned kOffset2 = 14;
|
||||
if (len < kOffset2 + kMinLen)
|
||||
return false;
|
||||
return CheckSusp(p + kOffset2, startPos);
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
// Archive/IsoItem.h
|
||||
|
||||
#ifndef __ARCHIVE_ISO_ITEM_H
|
||||
#define __ARCHIVE_ISO_ITEM_H
|
||||
|
||||
#include "../../../../C/CpuArch.h"
|
||||
|
||||
#include "../../../Common/MyString.h"
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
|
||||
#include "IsoHeader.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
struct CRecordingDateTime
|
||||
{
|
||||
Byte Year;
|
||||
Byte Month;
|
||||
Byte Day;
|
||||
Byte Hour;
|
||||
Byte Minute;
|
||||
Byte Second;
|
||||
signed char GmtOffset; // min intervals from -48 (West) to +52 (East) recorded.
|
||||
|
||||
bool GetFileTime(FILETIME &ft) const
|
||||
{
|
||||
UInt64 value;
|
||||
bool res = NWindows::NTime::GetSecondsSince1601(Year + 1900, Month, Day, Hour, Minute, Second, value);
|
||||
if (res)
|
||||
{
|
||||
value -= (Int64)((Int32)GmtOffset * 15 * 60);
|
||||
value *= 10000000;
|
||||
}
|
||||
ft.dwLowDateTime = (DWORD)value;
|
||||
ft.dwHighDateTime = (DWORD)(value >> 32);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
enum EPx
|
||||
{
|
||||
k_Px_Mode,
|
||||
k_Px_Links,
|
||||
k_Px_User,
|
||||
k_Px_Group,
|
||||
k_Px_SerialNumber
|
||||
|
||||
// k_Px_Num
|
||||
};
|
||||
|
||||
/*
|
||||
enum ETf
|
||||
{
|
||||
k_Tf_CTime,
|
||||
k_Tf_MTime,
|
||||
k_Tf_ATime,
|
||||
k_Tf_Attrib,
|
||||
k_Tf_Backup,
|
||||
k_Tf_Expiration,
|
||||
k_Tf_Effective
|
||||
|
||||
// k_Tf_Num
|
||||
};
|
||||
*/
|
||||
|
||||
struct CDirRecord
|
||||
{
|
||||
UInt32 ExtentLocation;
|
||||
UInt32 Size;
|
||||
CRecordingDateTime DateTime;
|
||||
Byte FileFlags;
|
||||
Byte FileUnitSize;
|
||||
Byte InterleaveGapSize;
|
||||
Byte ExtendedAttributeRecordLen;
|
||||
UInt16 VolSequenceNumber;
|
||||
CByteBuffer FileId;
|
||||
CByteBuffer SystemUse;
|
||||
|
||||
bool AreMultiPartEqualWith(const CDirRecord &a) const
|
||||
{
|
||||
return FileId == a.FileId
|
||||
&& (FileFlags & (~NFileFlags::kNonFinalExtent)) ==
|
||||
(a.FileFlags & (~NFileFlags::kNonFinalExtent));
|
||||
}
|
||||
|
||||
bool IsDir() const { return (FileFlags & NFileFlags::kDirectory) != 0; }
|
||||
bool IsNonFinalExtent() const { return (FileFlags & NFileFlags::kNonFinalExtent) != 0; }
|
||||
|
||||
bool IsSystemItem() const
|
||||
{
|
||||
if (FileId.Size() != 1)
|
||||
return false;
|
||||
Byte b = *(const Byte *)FileId;
|
||||
return (b == 0 || b == 1);
|
||||
}
|
||||
|
||||
|
||||
const Byte* FindSuspRecord(unsigned skipSize, Byte id0, Byte id1, unsigned &lenRes) const
|
||||
{
|
||||
lenRes = 0;
|
||||
if (SystemUse.Size() < skipSize)
|
||||
return 0;
|
||||
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;
|
||||
if (p[0] == id0 && p[1] == id1 && p[3] == 1)
|
||||
{
|
||||
if (len < 4)
|
||||
return 0; // Check it
|
||||
lenRes = len - 4;
|
||||
return p + 4;
|
||||
}
|
||||
p += len;
|
||||
rem -= len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const Byte* GetNameCur(bool checkSusp, int skipSize, unsigned &nameLenRes) const
|
||||
{
|
||||
const Byte *res = NULL;
|
||||
unsigned len = 0;
|
||||
if (checkSusp)
|
||||
res = FindSuspRecord(skipSize, 'N', 'M', len);
|
||||
if (!res || len < 1)
|
||||
{
|
||||
res = (const Byte *)FileId;
|
||||
len = (unsigned)FileId.Size();
|
||||
}
|
||||
else
|
||||
{
|
||||
res++;
|
||||
len--;
|
||||
}
|
||||
unsigned i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (res[i] == 0)
|
||||
break;
|
||||
nameLenRes = i;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
const bool GetSymLink(int skipSize, AString &link) const
|
||||
{
|
||||
link.Empty();
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'S', 'L', len);
|
||||
if (!p || len < 1)
|
||||
return false;
|
||||
|
||||
if (*p != 0)
|
||||
return false;
|
||||
|
||||
p++;
|
||||
len--;
|
||||
|
||||
while (len != 0)
|
||||
{
|
||||
if (len < 2)
|
||||
return false;
|
||||
unsigned flags = p[0];
|
||||
unsigned cl = p[1];
|
||||
p += 2;
|
||||
len -= 2;
|
||||
|
||||
if (cl > len)
|
||||
return false;
|
||||
|
||||
bool needSlash = false;
|
||||
|
||||
if (flags & (1 << 1)) link += "./";
|
||||
else if (flags & (1 << 2)) link += "../";
|
||||
else if (flags & (1 << 3)) link += '/';
|
||||
else
|
||||
needSlash = true;
|
||||
|
||||
for (unsigned i = 0; i < cl; i++)
|
||||
{
|
||||
char c = p[i];
|
||||
if (c == 0)
|
||||
{
|
||||
break;
|
||||
// return false;
|
||||
}
|
||||
link += c;
|
||||
}
|
||||
|
||||
p += cl;
|
||||
len -= cl;
|
||||
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
if (needSlash)
|
||||
link += '/';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const bool GetLe32Be32(const Byte *p, UInt32 &dest)
|
||||
{
|
||||
UInt32 v1 = GetUi32(p);
|
||||
UInt32 v2 = GetBe32(p + 4);
|
||||
if (v1 == v2)
|
||||
{
|
||||
dest = v1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const bool GetPx(int skipSize, unsigned pxType, UInt32 &val) const
|
||||
{
|
||||
val = 0;
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'P', 'X', len);
|
||||
if (!p)
|
||||
return false;
|
||||
// px.Clear();
|
||||
if (len < ((unsigned)pxType + 1) * 8)
|
||||
return false;
|
||||
|
||||
return GetLe32Be32(p + pxType * 8, val);
|
||||
}
|
||||
|
||||
/*
|
||||
const bool GetTf(int skipSize, unsigned pxType, CRecordingDateTime &t) const
|
||||
{
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'T', 'F', len);
|
||||
if (!p)
|
||||
return false;
|
||||
if (len < 1)
|
||||
return false;
|
||||
Byte flags = *p++;
|
||||
len--;
|
||||
|
||||
unsigned step = 7;
|
||||
if (flags & 0x80)
|
||||
{
|
||||
step = 17;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & (1 << pxType)) == 0)
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < pxType; i++)
|
||||
{
|
||||
if (len < step)
|
||||
return false;
|
||||
if (flags & (1 << i))
|
||||
{
|
||||
p += step;
|
||||
len -= step;
|
||||
}
|
||||
}
|
||||
|
||||
if (len < step)
|
||||
return false;
|
||||
|
||||
t.Year = p[0];
|
||||
t.Month = p[1];
|
||||
t.Day = p[2];
|
||||
t.Hour = p[3];
|
||||
t.Minute = p[4];
|
||||
t.Second = p[5];
|
||||
t.GmtOffset = (signed char)p[6];
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
bool CheckSusp(const Byte *p, unsigned &startPos) const
|
||||
{
|
||||
if (p[0] == 'S' &&
|
||||
p[1] == 'P' &&
|
||||
p[2] == 0x7 &&
|
||||
p[3] == 0x1 &&
|
||||
p[4] == 0xBE &&
|
||||
p[5] == 0xEF)
|
||||
{
|
||||
startPos = p[6];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CheckSusp(unsigned &startPos) const
|
||||
{
|
||||
const Byte *p = (const Byte *)SystemUse;
|
||||
unsigned len = (int)SystemUse.Size();
|
||||
const unsigned kMinLen = 7;
|
||||
if (len < kMinLen)
|
||||
return false;
|
||||
if (CheckSusp(p, startPos))
|
||||
return true;
|
||||
const unsigned kOffset2 = 14;
|
||||
if (len < kOffset2 + kMinLen)
|
||||
return false;
|
||||
return CheckSusp(p + kOffset2, startPos);
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
// IsoRegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterArc.h"
|
||||
|
||||
#include "IsoHandler.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
static const Byte k_Signature[] = { 'C', 'D', '0', '0', '1' };
|
||||
|
||||
REGISTER_ARC_I(
|
||||
"Iso", "iso img", 0, 0xE7,
|
||||
k_Signature,
|
||||
NArchive::NIso::kStartPos + 1,
|
||||
0,
|
||||
NULL)
|
||||
|
||||
}}
|
||||
// IsoRegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterArc.h"
|
||||
|
||||
#include "IsoHandler.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NIso {
|
||||
|
||||
static const Byte k_Signature[] = { 'C', 'D', '0', '0', '1' };
|
||||
|
||||
REGISTER_ARC_I(
|
||||
"Iso", "iso img", 0, 0xE7,
|
||||
k_Signature,
|
||||
NArchive::NIso::kStartPos + 1,
|
||||
0,
|
||||
NULL)
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
|
||||
#endif
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user