aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Archive/DmgHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Archive/DmgHandler.cpp')
-rw-r--r--CPP/7zip/Archive/DmgHandler.cpp166
1 files changed, 75 insertions, 91 deletions
diff --git a/CPP/7zip/Archive/DmgHandler.cpp b/CPP/7zip/Archive/DmgHandler.cpp
index e6166f1..4bcb904 100644
--- a/CPP/7zip/Archive/DmgHandler.cpp
+++ b/CPP/7zip/Archive/DmgHandler.cpp
@@ -85,7 +85,7 @@ void CChecksum::Parse(const Byte *p)
85 Type = Get32(p); 85 Type = Get32(p);
86 NumBits = Get32(p + 4); 86 NumBits = Get32(p + 4);
87 memcpy(Data, p + 8, kChecksumSize_Max); 87 memcpy(Data, p + 8, kChecksumSize_Max);
88}; 88}
89 89
90struct CFile 90struct CFile
91{ 91{
@@ -132,11 +132,9 @@ struct CForkPair
132}; 132};
133 133
134 134
135class CHandler: 135Z7_CLASS_IMP_CHandler_IInArchive_1(
136 public IInArchive, 136 IInArchiveGetStream
137 public IInArchiveGetStream, 137)
138 public CMyUnknownImp
139{
140 CMyComPtr<IInStream> _inStream; 138 CMyComPtr<IInStream> _inStream;
141 CObjectVector<CFile> _files; 139 CObjectVector<CFile> _files;
142 bool _masterCrcError; 140 bool _masterCrcError;
@@ -156,10 +154,6 @@ class CHandler:
156 bool ParseBlob(const CByteBuffer &data); 154 bool ParseBlob(const CByteBuffer &data);
157 HRESULT Open2(IInStream *stream); 155 HRESULT Open2(IInStream *stream);
158 HRESULT Extract(IInStream *stream); 156 HRESULT Extract(IInStream *stream);
159public:
160 MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
161 INTERFACE_IInArchive(;)
162 STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
163}; 157};
164 158
165// that limit can be increased, if there are such dmg files 159// that limit can be increased, if there are such dmg files
@@ -248,7 +242,7 @@ static const CAppleName k_Names[] =
248 { false, NULL, "Patches" } 242 { false, NULL, "Patches" }
249}; 243};
250 244
251static const unsigned kNumAppleNames = ARRAY_SIZE(k_Names); 245static const unsigned kNumAppleNames = Z7_ARRAY_SIZE(k_Names);
252 246
253static const Byte kProps[] = 247static const Byte kProps[] =
254{ 248{
@@ -270,7 +264,7 @@ static const Byte kArcProps[] =
270 kpidComment 264 kpidComment
271}; 265};
272 266
273STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) 267Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
274{ 268{
275 COM_TRY_BEGIN 269 COM_TRY_BEGIN
276 NWindows::NCOM::CPropVariant prop; 270 NWindows::NCOM::CPropVariant prop;
@@ -313,19 +307,19 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
313 if (appleName.IsFs) 307 if (appleName.IsFs)
314 { 308 {
315 numFS++; 309 numFS++;
316 mainIndex = i; 310 mainIndex = (int)i;
317 } 311 }
318 break; 312 break;
319 } 313 }
320 } 314 }
321 if (n == kNumAppleNames) 315 if (n == kNumAppleNames)
322 { 316 {
323 mainIndex = i; 317 mainIndex = (int)i;
324 numUnknown++; 318 numUnknown++;
325 } 319 }
326 } 320 }
327 if (numFS + numUnknown == 1) 321 if (numFS + numUnknown == 1)
328 prop = (UInt32)mainIndex; 322 prop = (UInt32)(Int32)mainIndex;
329 break; 323 break;
330 } 324 }
331 case kpidWarning: 325 case kpidWarning:
@@ -448,7 +442,7 @@ static int FindKeyPair(const CXmlItem &item, const char *key, const char *nextTa
448 { 442 {
449 const CXmlItem &si = item.SubItems[i]; 443 const CXmlItem &si = item.SubItems[i];
450 if (si.IsTagged("key") && si.GetSubString() == key && item.SubItems[i + 1].IsTagged(nextTag)) 444 if (si.IsTagged("key") && si.GetSubString() == key && item.SubItems[i + 1].IsTagged(nextTag))
451 return i + 1; 445 return (int)(i + 1);
452 } 446 }
453 return -1; 447 return -1;
454} 448}
@@ -467,7 +461,7 @@ static const Byte k_Signature[] = { 'k','o','l','y', 0, 0, 0, 4, 0, 0, 2, 0 };
467 461
468static inline bool IsKoly(const Byte *p) 462static inline bool IsKoly(const Byte *p)
469{ 463{
470 return memcmp(p, k_Signature, ARRAY_SIZE(k_Signature)) == 0; 464 return memcmp(p, k_Signature, Z7_ARRAY_SIZE(k_Signature)) == 0;
471 /* 465 /*
472 if (Get32(p) != 0x6B6F6C79) // "koly" signature 466 if (Get32(p) != 0x6B6F6C79) // "koly" signature
473 return false; 467 return false;
@@ -486,7 +480,7 @@ HRESULT CHandler::ReadData(IInStream *stream, const CForkPair &pair, CByteBuffer
486 if (size != pair.Len) 480 if (size != pair.Len)
487 return E_OUTOFMEMORY; 481 return E_OUTOFMEMORY;
488 buf.Alloc(size); 482 buf.Alloc(size);
489 RINOK(stream->Seek(_startPos + pair.Offset, STREAM_SEEK_SET, NULL)); 483 RINOK(InStream_SeekSet(stream, _startPos + pair.Offset))
490 return ReadStream_FALSE(stream, buf, size); 484 return ReadStream_FALSE(stream, buf, size);
491} 485}
492 486
@@ -564,14 +558,11 @@ HRESULT CHandler::Open2(IInStream *stream)
564 */ 558 */
565 559
566 _dataStartOffset = 0; 560 _dataStartOffset = 0;
567 RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_startPos)); 561 UInt64 fileSize;
568 562 RINOK(InStream_GetPos_GetSize(stream, _startPos, fileSize))
569 UInt64 fileSize = 0;
570 RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
571 RINOK(stream->Seek(_startPos, STREAM_SEEK_SET, NULL));
572 563
573 Byte buf[HEADER_SIZE]; 564 Byte buf[HEADER_SIZE];
574 RINOK(ReadStream_FALSE(stream, buf, HEADER_SIZE)); 565 RINOK(ReadStream_FALSE(stream, buf, HEADER_SIZE))
575 566
576 UInt64 headerPos; 567 UInt64 headerPos;
577 bool startKolyMode = false; 568 bool startKolyMode = false;
@@ -595,8 +586,8 @@ HRESULT CHandler::Open2(IInStream *stream)
595 if (headerPos < HEADER_SIZE) 586 if (headerPos < HEADER_SIZE)
596 return S_FALSE; 587 return S_FALSE;
597 headerPos -= HEADER_SIZE; 588 headerPos -= HEADER_SIZE;
598 RINOK(stream->Seek(headerPos, STREAM_SEEK_SET, NULL)); 589 RINOK(InStream_SeekSet(stream, headerPos))
599 RINOK(ReadStream_FALSE(stream, buf, HEADER_SIZE)); 590 RINOK(ReadStream_FALSE(stream, buf, HEADER_SIZE))
600 if (!IsKoly(buf)) 591 if (!IsKoly(buf))
601 return S_FALSE; 592 return S_FALSE;
602 } 593 }
@@ -674,7 +665,7 @@ HRESULT CHandler::Open2(IInStream *stream)
674 #else 665 #else
675 CByteBuffer blobBuf; 666 CByteBuffer blobBuf;
676 #endif 667 #endif
677 RINOK(ReadData(stream, blobPair, blobBuf)); 668 RINOK(ReadData(stream, blobPair, blobBuf))
678 if (!ParseBlob(blobBuf)) 669 if (!ParseBlob(blobBuf))
679 _headersError = true; 670 _headersError = true;
680 } 671 }
@@ -704,7 +695,7 @@ HRESULT CHandler::Open2(IInStream *stream)
704 CByteBuffer rsrcBuf; 695 CByteBuffer rsrcBuf;
705 #endif 696 #endif
706 697
707 RINOK(ReadData(stream, rsrcPair, rsrcBuf)); 698 RINOK(ReadData(stream, rsrcPair, rsrcBuf))
708 699
709 const Byte *p = rsrcBuf; 700 const Byte *p = rsrcBuf;
710 UInt32 headSize = Get32(p + 0); 701 UInt32 headSize = Get32(p + 0);
@@ -803,7 +794,7 @@ HRESULT CHandler::Open2(IInStream *stream)
803 { 794 {
804 CFile &file = _files.AddNew(); 795 CFile &file = _files.AddNew();
805 file.Name = name; 796 file.Name = name;
806 RINOK(file.Parse(pBlock + 4, blockSize)); 797 RINOK(file.Parse(pBlock + 4, blockSize))
807 } 798 }
808 799
809 #ifdef DMG_SHOW_RAW 800 #ifdef DMG_SHOW_RAW
@@ -844,12 +835,12 @@ HRESULT CHandler::Open2(IInStream *stream)
844 if (size != xmlPair.Len) 835 if (size != xmlPair.Len)
845 return S_FALSE; 836 return S_FALSE;
846 837
847 RINOK(stream->Seek(_startPos + xmlPair.Offset, STREAM_SEEK_SET, NULL)); 838 RINOK(InStream_SeekSet(stream, _startPos + xmlPair.Offset))
848 839
849 CXml xml; 840 CXml xml;
850 { 841 {
851 CObjArray<char> xmlStr(size + 1); 842 CObjArray<char> xmlStr(size + 1);
852 RINOK(ReadStream_FALSE(stream, xmlStr, size)); 843 RINOK(ReadStream_FALSE(stream, xmlStr, size))
853 xmlStr[size] = 0; 844 xmlStr[size] = 0;
854 // if (strlen(xmlStr) != size) return S_FALSE; 845 // if (strlen(xmlStr) != size) return S_FALSE;
855 if (!xml.Parse(xmlStr)) 846 if (!xml.Parse(xmlStr))
@@ -916,7 +907,7 @@ HRESULT CHandler::Open2(IInStream *stream)
916 if (name) 907 if (name)
917 file.Name = *name; 908 file.Name = *name;
918 } 909 }
919 RINOK(file.Parse(rawBuf, destLen)); 910 RINOK(file.Parse(rawBuf, destLen))
920 } 911 }
921 } 912 }
922 913
@@ -941,9 +932,9 @@ HRESULT CHandler::Open2(IInStream *stream)
941 return S_OK; 932 return S_OK;
942} 933}
943 934
944STDMETHODIMP CHandler::Open(IInStream *stream, 935Z7_COM7F_IMF(CHandler::Open(IInStream *stream,
945 const UInt64 * /* maxCheckStartPosition */, 936 const UInt64 * /* maxCheckStartPosition */,
946 IArchiveOpenCallback * /* openArchiveCallback */) 937 IArchiveOpenCallback * /* openArchiveCallback */))
947{ 938{
948 COM_TRY_BEGIN 939 COM_TRY_BEGIN
949 { 940 {
@@ -956,7 +947,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
956 COM_TRY_END 947 COM_TRY_END
957} 948}
958 949
959STDMETHODIMP CHandler::Close() 950Z7_COM7F_IMF(CHandler::Close())
960{ 951{
961 _phySize = 0; 952 _phySize = 0;
962 _inStream.Release(); 953 _inStream.Release();
@@ -970,7 +961,7 @@ STDMETHODIMP CHandler::Close()
970 return S_OK; 961 return S_OK;
971} 962}
972 963
973STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) 964Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
974{ 965{
975 *numItems = _files.Size() 966 *numItems = _files.Size()
976 #ifdef DMG_SHOW_RAW 967 #ifdef DMG_SHOW_RAW
@@ -984,7 +975,7 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
984#define RAW_PREFIX "raw" STRING_PATH_SEPARATOR 975#define RAW_PREFIX "raw" STRING_PATH_SEPARATOR
985#endif 976#endif
986 977
987STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) 978Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
988{ 979{
989 COM_TRY_BEGIN 980 COM_TRY_BEGIN
990 NWindows::NCOM::CPropVariant prop; 981 NWindows::NCOM::CPropVariant prop;
@@ -1054,7 +1045,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
1054 if (pos1 >= 0) 1045 if (pos1 >= 0)
1055 { 1046 {
1056 pos1++; 1047 pos1++;
1057 int pos2 = item.Name.Find(')', pos1); 1048 const int pos2 = item.Name.Find(')', pos1);
1058 if (pos2 >= 0) 1049 if (pos2 >= 0)
1059 { 1050 {
1060 subName.SetFrom(item.Name.Ptr(pos1), pos2 - pos1); 1051 subName.SetFrom(item.Name.Ptr(pos1), pos2 - pos1);
@@ -1082,7 +1073,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
1082 } 1073 }
1083 UString name2; 1074 UString name2;
1084 ConvertUTF8ToUnicode(subName, name2); 1075 ConvertUTF8ToUnicode(subName, name2);
1085 name += '.'; 1076 name.Add_Dot();
1086 name += name2; 1077 name += name2;
1087 } 1078 }
1088 else 1079 else
@@ -1111,10 +1102,11 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
1111 COM_TRY_END 1102 COM_TRY_END
1112} 1103}
1113 1104
1114class CAdcDecoder: 1105
1115 public ICompressCoder, 1106Z7_CLASS_IMP_NOQIB_1(
1116 public CMyUnknownImp 1107 CAdcDecoder
1117{ 1108 , ICompressCoder
1109)
1118 CLzOutWindow m_OutWindowStream; 1110 CLzOutWindow m_OutWindowStream;
1119 CInBuffer m_InStream; 1111 CInBuffer m_InStream;
1120 1112
@@ -1126,7 +1118,7 @@ class CAdcDecoder:
1126 } 1118 }
1127 */ 1119 */
1128 1120
1129 class CCoderReleaser 1121 class CCoderReleaser Z7_final
1130 { 1122 {
1131 CAdcDecoder *m_Coder; 1123 CAdcDecoder *m_Coder;
1132 public: 1124 public:
@@ -1142,18 +1134,12 @@ class CAdcDecoder:
1142 friend class CCoderReleaser; 1134 friend class CCoderReleaser;
1143 1135
1144public: 1136public:
1145 MY_UNKNOWN_IMP 1137 HRESULT CodeReal(ISequentialInStream *inStream,
1146
1147 STDMETHOD(CodeReal)(ISequentialInStream *inStream,
1148 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
1149 ICompressProgressInfo *progress);
1150
1151 STDMETHOD(Code)(ISequentialInStream *inStream,
1152 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, 1138 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
1153 ICompressProgressInfo *progress); 1139 ICompressProgressInfo *progress);
1154}; 1140};
1155 1141
1156STDMETHODIMP CAdcDecoder::CodeReal(ISequentialInStream *inStream, 1142HRESULT CAdcDecoder::CodeReal(ISequentialInStream *inStream,
1157 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, 1143 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
1158 ICompressProgressInfo *progress) 1144 ICompressProgressInfo *progress)
1159{ 1145{
@@ -1178,7 +1164,7 @@ STDMETHODIMP CAdcDecoder::CodeReal(ISequentialInStream *inStream,
1178 if (pos > nextLimit && progress) 1164 if (pos > nextLimit && progress)
1179 { 1165 {
1180 UInt64 packSize = m_InStream.GetProcessedSize(); 1166 UInt64 packSize = m_InStream.GetProcessedSize();
1181 RINOK(progress->SetRatioInfo(&packSize, &pos)); 1167 RINOK(progress->SetRatioInfo(&packSize, &pos))
1182 nextLimit += kStep; 1168 nextLimit += kStep;
1183 } 1169 }
1184 Byte b; 1170 Byte b;
@@ -1231,9 +1217,9 @@ STDMETHODIMP CAdcDecoder::CodeReal(ISequentialInStream *inStream,
1231 return m_OutWindowStream.Flush(); 1217 return m_OutWindowStream.Flush();
1232} 1218}
1233 1219
1234STDMETHODIMP CAdcDecoder::Code(ISequentialInStream *inStream, 1220Z7_COM7F_IMF(CAdcDecoder::Code(ISequentialInStream *inStream,
1235 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, 1221 ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
1236 ICompressProgressInfo *progress) 1222 ICompressProgressInfo *progress))
1237{ 1223{
1238 try { return CodeReal(inStream, outStream, inSize, outSize, progress);} 1224 try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
1239 catch(const CInBufferException &e) { return e.ErrorCode; } 1225 catch(const CInBufferException &e) { return e.ErrorCode; }
@@ -1247,11 +1233,11 @@ STDMETHODIMP CAdcDecoder::Code(ISequentialInStream *inStream,
1247 1233
1248 1234
1249 1235
1250STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, 1236Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1251 Int32 testMode, IArchiveExtractCallback *extractCallback) 1237 Int32 testMode, IArchiveExtractCallback *extractCallback))
1252{ 1238{
1253 COM_TRY_BEGIN 1239 COM_TRY_BEGIN
1254 bool allFilesMode = (numItems == (UInt32)(Int32)-1); 1240 const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
1255 if (allFilesMode) 1241 if (allFilesMode)
1256 numItems = _files.Size(); 1242 numItems = _files.Size();
1257 if (numItems == 0) 1243 if (numItems == 0)
@@ -1309,17 +1295,17 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1309 lps->OutSize = currentUnpTotal; 1295 lps->OutSize = currentUnpTotal;
1310 currentPackSize = 0; 1296 currentPackSize = 0;
1311 currentUnpSize = 0; 1297 currentUnpSize = 0;
1312 RINOK(lps->SetCur()); 1298 RINOK(lps->SetCur())
1313 CMyComPtr<ISequentialOutStream> realOutStream; 1299 CMyComPtr<ISequentialOutStream> realOutStream;
1314 Int32 askMode = testMode ? 1300 const Int32 askMode = testMode ?
1315 NExtract::NAskMode::kTest : 1301 NExtract::NAskMode::kTest :
1316 NExtract::NAskMode::kExtract; 1302 NExtract::NAskMode::kExtract;
1317 UInt32 index = allFilesMode ? i : indices[i]; 1303 const UInt32 index = allFilesMode ? i : indices[i];
1318 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 1304 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
1319 1305
1320 if (!testMode && !realOutStream) 1306 if (!testMode && !realOutStream)
1321 continue; 1307 continue;
1322 RINOK(extractCallback->PrepareOperation(askMode)); 1308 RINOK(extractCallback->PrepareOperation(askMode))
1323 1309
1324 1310
1325 COutStreamWithCRC *outCrcStreamSpec = new COutStreamWithCRC; 1311 COutStreamWithCRC *outCrcStreamSpec = new COutStreamWithCRC;
@@ -1359,7 +1345,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1359 { 1345 {
1360 lps->InSize = currentPackTotal + packPos; 1346 lps->InSize = currentPackTotal + packPos;
1361 lps->OutSize = currentUnpTotal + unpPos; 1347 lps->OutSize = currentUnpTotal + unpPos;
1362 RINOK(lps->SetCur()); 1348 RINOK(lps->SetCur())
1363 1349
1364 const CBlock &block = item.Blocks[j]; 1350 const CBlock &block = item.Blocks[j];
1365 if (!block.ThereAreDataInBlock()) 1351 if (!block.ThereAreDataInBlock())
@@ -1372,7 +1358,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1372 break; 1358 break;
1373 } 1359 }
1374 1360
1375 RINOK(_inStream->Seek(_startPos + _dataStartOffset + item.StartPos + block.PackPos, STREAM_SEEK_SET, NULL)); 1361 RINOK(InStream_SeekSet(_inStream, _startPos + _dataStartOffset + item.StartPos + block.PackPos))
1376 streamSpec->Init(block.PackSize); 1362 streamSpec->Init(block.PackSize);
1377 bool realMethod = true; 1363 bool realMethod = true;
1378 outStreamSpec->Init(block.UnpSize); 1364 outStreamSpec->Init(block.UnpSize);
@@ -1453,7 +1439,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1453 { 1439 {
1454 UInt64 rem = outStreamSpec->GetRem(); 1440 UInt64 rem = outStreamSpec->GetRem();
1455 UInt32 size = (UInt32)MyMin(rem, (UInt64)kZeroBufSize); 1441 UInt32 size = (UInt32)MyMin(rem, (UInt64)kZeroBufSize);
1456 RINOK(WriteStream(outStream, zeroBuf, size)); 1442 RINOK(WriteStream(outStream, zeroBuf, size))
1457 } 1443 }
1458 } 1444 }
1459 } 1445 }
@@ -1466,7 +1452,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1466 } 1452 }
1467 } 1453 }
1468 outStream.Release(); 1454 outStream.Release();
1469 RINOK(extractCallback->SetOperationResult(opRes)); 1455 RINOK(extractCallback->SetOperationResult(opRes))
1470 } 1456 }
1471 1457
1472 return S_OK; 1458 return S_OK;
@@ -1480,10 +1466,13 @@ struct CChunk
1480 CByteBuffer Buf; 1466 CByteBuffer Buf;
1481}; 1467};
1482 1468
1483class CInStream: 1469
1484 public IInStream, 1470Z7_CLASS_IMP_COM_1(
1485 public CMyUnknownImp 1471 CInStream
1486{ 1472 , IInStream
1473)
1474 Z7_IFACE_COM7_IMP(ISequentialInStream)
1475
1487 UInt64 _virtPos; 1476 UInt64 _virtPos;
1488 int _latestChunk; 1477 int _latestChunk;
1489 int _latestBlock; 1478 int _latestBlock;
@@ -1530,11 +1519,6 @@ public:
1530 outStream = outStreamSpec; 1519 outStream = outStreamSpec;
1531 return S_OK; 1520 return S_OK;
1532 } 1521 }
1533
1534 MY_UNKNOWN_IMP1(IInStream)
1535
1536 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
1537 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
1538}; 1522};
1539 1523
1540 1524
@@ -1553,7 +1537,7 @@ static unsigned FindBlock(const CRecordVector<CBlock> &blocks, UInt64 pos)
1553 } 1537 }
1554} 1538}
1555 1539
1556STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize) 1540Z7_COM7F_IMF(CInStream::Read(void *data, UInt32 size, UInt32 *processedSize))
1557{ 1541{
1558 COM_TRY_BEGIN 1542 COM_TRY_BEGIN
1559 1543
@@ -1571,7 +1555,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
1571 1555
1572 if (_latestBlock >= 0) 1556 if (_latestBlock >= 0)
1573 { 1557 {
1574 const CBlock &block = File->Blocks[_latestBlock]; 1558 const CBlock &block = File->Blocks[(unsigned)_latestBlock];
1575 if (_virtPos < block.UnpPos || (_virtPos - block.UnpPos) >= block.UnpSize) 1559 if (_virtPos < block.UnpPos || (_virtPos - block.UnpPos) >= block.UnpSize)
1576 _latestBlock = -1; 1560 _latestBlock = -1;
1577 } 1561 }
@@ -1590,7 +1574,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
1590 break; 1574 break;
1591 1575
1592 if (i != _chunks.Size()) 1576 if (i != _chunks.Size())
1593 _latestChunk = i; 1577 _latestChunk = (int)i;
1594 else 1578 else
1595 { 1579 {
1596 const unsigned kNumChunksMax = 128; 1580 const unsigned kNumChunksMax = 128;
@@ -1620,7 +1604,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
1620 1604
1621 outStreamSpec->Init(chunk.Buf, (size_t)block.UnpSize); 1605 outStreamSpec->Init(chunk.Buf, (size_t)block.UnpSize);
1622 1606
1623 RINOK(Stream->Seek(_startPos + File->StartPos + block.PackPos, STREAM_SEEK_SET, NULL)); 1607 RINOK(InStream_SeekSet(Stream, _startPos + File->StartPos + block.PackPos))
1624 1608
1625 limitedStreamSpec->Init(block.PackSize); 1609 limitedStreamSpec->Init(block.PackSize);
1626 HRESULT res = S_OK; 1610 HRESULT res = S_OK;
@@ -1681,17 +1665,17 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
1681 return res; 1665 return res;
1682 if (block.Type != METHOD_COPY && outStreamSpec->GetPos() != block.UnpSize) 1666 if (block.Type != METHOD_COPY && outStreamSpec->GetPos() != block.UnpSize)
1683 return E_FAIL; 1667 return E_FAIL;
1684 chunk.BlockIndex = blockIndex; 1668 chunk.BlockIndex = (int)blockIndex;
1685 _latestChunk = chunkIndex; 1669 _latestChunk = (int)chunkIndex;
1686 } 1670 }
1687 1671
1688 _chunks[_latestChunk].AccessMark = _accessMark++; 1672 _chunks[_latestChunk].AccessMark = _accessMark++;
1689 } 1673 }
1690 1674
1691 _latestBlock = blockIndex; 1675 _latestBlock = (int)blockIndex;
1692 } 1676 }
1693 1677
1694 const CBlock &block = File->Blocks[_latestBlock]; 1678 const CBlock &block = File->Blocks[(unsigned)_latestBlock];
1695 const UInt64 offset = _virtPos - block.UnpPos; 1679 const UInt64 offset = _virtPos - block.UnpPos;
1696 const UInt64 rem = block.UnpSize - offset; 1680 const UInt64 rem = block.UnpSize - offset;
1697 if (size > rem) 1681 if (size > rem)
@@ -1701,7 +1685,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
1701 1685
1702 if (block.Type == METHOD_COPY) 1686 if (block.Type == METHOD_COPY)
1703 { 1687 {
1704 RINOK(Stream->Seek(_startPos + File->StartPos + block.PackPos + offset, STREAM_SEEK_SET, NULL)); 1688 RINOK(InStream_SeekSet(Stream, _startPos + File->StartPos + block.PackPos + offset))
1705 res = Stream->Read(data, size, &size); 1689 res = Stream->Read(data, size, &size);
1706 } 1690 }
1707 else if (block.IsZeroMethod()) 1691 else if (block.IsZeroMethod())
@@ -1717,7 +1701,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
1717 COM_TRY_END 1701 COM_TRY_END
1718} 1702}
1719 1703
1720STDMETHODIMP CInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) 1704Z7_COM7F_IMF(CInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
1721{ 1705{
1722 switch (seekOrigin) 1706 switch (seekOrigin)
1723 { 1707 {
@@ -1728,13 +1712,13 @@ STDMETHODIMP CInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPositio
1728 } 1712 }
1729 if (offset < 0) 1713 if (offset < 0)
1730 return HRESULT_WIN32_ERROR_NEGATIVE_SEEK; 1714 return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
1731 _virtPos = offset; 1715 _virtPos = (UInt64)offset;
1732 if (newPosition) 1716 if (newPosition)
1733 *newPosition = offset; 1717 *newPosition = (UInt64)offset;
1734 return S_OK; 1718 return S_OK;
1735} 1719}
1736 1720
1737STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream) 1721Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
1738{ 1722{
1739 COM_TRY_BEGIN 1723 COM_TRY_BEGIN
1740 1724
@@ -1769,7 +1753,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
1769 1753
1770 spec->Stream = _inStream; 1754 spec->Stream = _inStream;
1771 spec->Size = spec->File->Size; 1755 spec->Size = spec->File->Size;
1772 RINOK(spec->InitAndSeek(_startPos + _dataStartOffset)); 1756 RINOK(spec->InitAndSeek(_startPos + _dataStartOffset))
1773 *stream = specStream.Detach(); 1757 *stream = specStream.Detach();
1774 return S_OK; 1758 return S_OK;
1775 1759
@@ -1777,7 +1761,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
1777} 1761}
1778 1762
1779REGISTER_ARC_I( 1763REGISTER_ARC_I(
1780 "Dmg", "dmg", 0, 0xE4, 1764 "Dmg", "dmg", NULL, 0xE4,
1781 k_Signature, 1765 k_Signature,
1782 0, 1766 0,
1783 NArcInfoFlags::kBackwardOpen | 1767 NArcInfoFlags::kBackwardOpen |