aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Archive/Chm/ChmHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Archive/Chm/ChmHandler.cpp188
1 files changed, 79 insertions, 109 deletions
diff --git a/CPP/7zip/Archive/Chm/ChmHandler.cpp b/CPP/7zip/Archive/Chm/ChmHandler.cpp
index 03e7ddd..38e2543 100644
--- a/CPP/7zip/Archive/Chm/ChmHandler.cpp
+++ b/CPP/7zip/Archive/Chm/ChmHandler.cpp
@@ -27,9 +27,9 @@ using namespace NTime;
27namespace NArchive { 27namespace NArchive {
28namespace NChm { 28namespace NChm {
29 29
30// #define _CHM_DETAILS 30// #define CHM_DETAILS
31 31
32#ifdef _CHM_DETAILS 32#ifdef CHM_DETAILS
33 33
34enum 34enum
35{ 35{
@@ -45,7 +45,7 @@ static const Byte kProps[] =
45 kpidMethod, 45 kpidMethod,
46 kpidBlock 46 kpidBlock
47 47
48 #ifdef _CHM_DETAILS 48 #ifdef CHM_DETAILS
49 , 49 ,
50 L"Section", kpidSection, 50 L"Section", kpidSection,
51 kpidOffset 51 kpidOffset
@@ -63,7 +63,7 @@ IMP_IInArchive_Props
63 63
64IMP_IInArchive_ArcProps_NO_Table 64IMP_IInArchive_ArcProps_NO_Table
65 65
66STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) 66Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
67{ 67{
68 // COM_TRY_BEGIN 68 // COM_TRY_BEGIN
69 NCOM::CPropVariant prop; 69 NCOM::CPropVariant prop;
@@ -97,7 +97,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
97 // COM_TRY_END 97 // COM_TRY_END
98} 98}
99 99
100STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) 100Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
101{ 101{
102 COM_TRY_BEGIN 102 COM_TRY_BEGIN
103 NCOM::CPropVariant prop; 103 NCOM::CPropVariant prop;
@@ -160,7 +160,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
160 prop = m_Database.GetFolder(index); 160 prop = m_Database.GetFolder(index);
161 break; 161 break;
162 162
163 #ifdef _CHM_DETAILS 163 #ifdef CHM_DETAILS
164 164
165 case kpidSection: prop = (UInt32)item.Section; break; 165 case kpidSection: prop = (UInt32)item.Section; break;
166 case kpidOffset: prop = (UInt32)item.Offset; break; 166 case kpidOffset: prop = (UInt32)item.Offset; break;
@@ -173,34 +173,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
173 COM_TRY_END 173 COM_TRY_END
174} 174}
175 175
176/*
177class CProgressImp: public CProgressVirt
178{
179 CMyComPtr<IArchiveOpenCallback> _callback;
180public:
181 STDMETHOD(SetTotal)(const UInt64 *numFiles);
182 STDMETHOD(SetCompleted)(const UInt64 *numFiles);
183 CProgressImp(IArchiveOpenCallback *callback): _callback(callback) {};
184};
185
186STDMETHODIMP CProgressImp::SetTotal(const UInt64 *numFiles)
187{
188 if (_callback)
189 return _callback->SetCompleted(numFiles, NULL);
190 return S_OK;
191}
192 176
193STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles) 177Z7_COM7F_IMF(CHandler::Open(IInStream *inStream,
194{
195 if (_callback)
196 return _callback->SetCompleted(numFiles, NULL);
197 return S_OK;
198}
199*/
200
201STDMETHODIMP CHandler::Open(IInStream *inStream,
202 const UInt64 *maxCheckStartPosition, 178 const UInt64 *maxCheckStartPosition,
203 IArchiveOpenCallback * /* openArchiveCallback */) 179 IArchiveOpenCallback * /* openArchiveCallback */))
204{ 180{
205 COM_TRY_BEGIN 181 COM_TRY_BEGIN
206 Close(); 182 Close();
@@ -208,13 +184,13 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
208 { 184 {
209 CInArchive archive(_help2); 185 CInArchive archive(_help2);
210 // CProgressImp progressImp(openArchiveCallback); 186 // CProgressImp progressImp(openArchiveCallback);
211 HRESULT res = archive.Open(inStream, maxCheckStartPosition, m_Database); 187 const HRESULT res = archive.Open(inStream, maxCheckStartPosition, m_Database);
212 if (!archive.IsArc) m_ErrorFlags |= kpv_ErrorFlags_IsNotArc; 188 if (!archive.IsArc) m_ErrorFlags |= kpv_ErrorFlags_IsNotArc;
213 if (archive.HeadersError) m_ErrorFlags |= kpv_ErrorFlags_HeadersError; 189 if (archive.HeadersError) m_ErrorFlags |= kpv_ErrorFlags_HeadersError;
214 if (archive.UnexpectedEnd) m_ErrorFlags |= kpv_ErrorFlags_UnexpectedEnd; 190 if (archive.UnexpectedEnd) m_ErrorFlags |= kpv_ErrorFlags_UnexpectedEnd;
215 if (archive.UnsupportedFeature) m_ErrorFlags |= kpv_ErrorFlags_UnsupportedFeature; 191 if (archive.UnsupportedFeature) m_ErrorFlags |= kpv_ErrorFlags_UnsupportedFeature;
216 192
217 RINOK(res); 193 RINOK(res)
218 /* 194 /*
219 if (m_Database.LowLevel) 195 if (m_Database.LowLevel)
220 return S_FALSE; 196 return S_FALSE;
@@ -229,7 +205,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
229 COM_TRY_END 205 COM_TRY_END
230} 206}
231 207
232STDMETHODIMP CHandler::Close() 208Z7_COM7F_IMF(CHandler::Close())
233{ 209{
234 m_ErrorFlags = 0; 210 m_ErrorFlags = 0;
235 m_Database.Clear(); 211 m_Database.Clear();
@@ -237,15 +213,22 @@ STDMETHODIMP CHandler::Close()
237 return S_OK; 213 return S_OK;
238} 214}
239 215
240class CChmFolderOutStream: 216Z7_CLASS_IMP_NOQIB_1(
241 public ISequentialOutStream, 217 CChmFolderOutStream
242 public CMyUnknownImp 218 , ISequentialOutStream
243{ 219)
244public: 220 bool m_TestMode;
245 MY_UNKNOWN_IMP 221 bool m_IsOk;
222 bool m_FileIsOpen;
223 const CFilesDatabase *m_Database;
224 CMyComPtr<IArchiveExtractCallback> m_ExtractCallback;
225 CMyComPtr<ISequentialOutStream> m_RealOutStream;
226 UInt64 m_RemainFileSize;
246 227
228 HRESULT OpenFile();
229 HRESULT WriteEmptyFiles();
247 HRESULT Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK); 230 HRESULT Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK);
248 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 231public:
249 232
250 UInt64 m_FolderSize; 233 UInt64 m_FolderSize;
251 UInt64 m_PosInFolder; 234 UInt64 m_PosInFolder;
@@ -255,19 +238,6 @@ public:
255 unsigned m_CurrentIndex; 238 unsigned m_CurrentIndex;
256 unsigned m_NumFiles; 239 unsigned m_NumFiles;
257 240
258private:
259 const CFilesDatabase *m_Database;
260 CMyComPtr<IArchiveExtractCallback> m_ExtractCallback;
261 bool m_TestMode;
262
263 bool m_IsOk;
264 bool m_FileIsOpen;
265 UInt64 m_RemainFileSize;
266 CMyComPtr<ISequentialOutStream> m_RealOutStream;
267
268 HRESULT OpenFile();
269 HRESULT WriteEmptyFiles();
270public:
271 void Init( 241 void Init(
272 const CFilesDatabase *database, 242 const CFilesDatabase *database,
273 IArchiveExtractCallback *extractCallback, 243 IArchiveExtractCallback *extractCallback,
@@ -290,12 +260,12 @@ void CChmFolderOutStream::Init(
290 260
291HRESULT CChmFolderOutStream::OpenFile() 261HRESULT CChmFolderOutStream::OpenFile()
292{ 262{
293 Int32 askMode = (*m_ExtractStatuses)[m_CurrentIndex] ? (m_TestMode ? 263 Int32 askMode = (*m_ExtractStatuses)[m_CurrentIndex] ? m_TestMode ?
294 NExtract::NAskMode::kTest : 264 NExtract::NAskMode::kTest :
295 NExtract::NAskMode::kExtract) : 265 NExtract::NAskMode::kExtract :
296 NExtract::NAskMode::kSkip; 266 NExtract::NAskMode::kSkip;
297 m_RealOutStream.Release(); 267 m_RealOutStream.Release();
298 RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &m_RealOutStream, askMode)); 268 RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &m_RealOutStream, askMode))
299 if (!m_RealOutStream && !m_TestMode) 269 if (!m_RealOutStream && !m_TestMode)
300 askMode = NExtract::NAskMode::kSkip; 270 askMode = NExtract::NAskMode::kSkip;
301 return m_ExtractCallback->PrepareOperation(askMode); 271 return m_ExtractCallback->PrepareOperation(askMode);
@@ -307,13 +277,13 @@ HRESULT CChmFolderOutStream::WriteEmptyFiles()
307 return S_OK; 277 return S_OK;
308 for (; m_CurrentIndex < m_NumFiles; m_CurrentIndex++) 278 for (; m_CurrentIndex < m_NumFiles; m_CurrentIndex++)
309 { 279 {
310 UInt64 fileSize = m_Database->GetFileSize(m_StartIndex + m_CurrentIndex); 280 const UInt64 fileSize = m_Database->GetFileSize(m_StartIndex + m_CurrentIndex);
311 if (fileSize != 0) 281 if (fileSize != 0)
312 return S_OK; 282 return S_OK;
313 HRESULT result = OpenFile(); 283 const HRESULT result = OpenFile();
314 m_RealOutStream.Release(); 284 m_RealOutStream.Release();
315 RINOK(result); 285 RINOK(result)
316 RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); 286 RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
317 } 287 }
318 return S_OK; 288 return S_OK;
319} 289}
@@ -358,7 +328,7 @@ HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *proce
358 RINOK(m_ExtractCallback->SetOperationResult( 328 RINOK(m_ExtractCallback->SetOperationResult(
359 m_IsOk ? 329 m_IsOk ?
360 NExtract::NOperationResult::kOK: 330 NExtract::NOperationResult::kOK:
361 NExtract::NOperationResult::kDataError)); 331 NExtract::NOperationResult::kDataError))
362 m_FileIsOpen = false; 332 m_FileIsOpen = false;
363 } 333 }
364 if (realProcessed > 0) 334 if (realProcessed > 0)
@@ -395,7 +365,7 @@ HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *proce
395 365
396 if (fileOffset == m_PosInSection) 366 if (fileOffset == m_PosInSection)
397 { 367 {
398 RINOK(OpenFile()); 368 RINOK(OpenFile())
399 m_FileIsOpen = true; 369 m_FileIsOpen = true;
400 m_CurrentIndex++; 370 m_CurrentIndex++;
401 m_IsOk = true; 371 m_IsOk = true;
@@ -406,7 +376,7 @@ HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *proce
406 return WriteEmptyFiles(); 376 return WriteEmptyFiles();
407} 377}
408 378
409STDMETHODIMP CChmFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) 379Z7_COM7F_IMF(CChmFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize))
410{ 380{
411 return Write2(data, size, processedSize, true); 381 return Write2(data, size, processedSize, true);
412} 382}
@@ -423,7 +393,7 @@ HRESULT CChmFolderOutStream::FlushCorrupted(UInt64 maxSize)
423 { 393 {
424 UInt32 size = (UInt32)MyMin(maxSize - m_PosInFolder, (UInt64)kBufferSize); 394 UInt32 size = (UInt32)MyMin(maxSize - m_PosInFolder, (UInt64)kBufferSize);
425 UInt32 processedSizeLocal = 0; 395 UInt32 processedSizeLocal = 0;
426 RINOK(Write2(buffer, size, &processedSizeLocal, false)); 396 RINOK(Write2(buffer, size, &processedSizeLocal, false))
427 if (processedSizeLocal == 0) 397 if (processedSizeLocal == 0)
428 return S_OK; 398 return S_OK;
429 } 399 }
@@ -431,11 +401,11 @@ HRESULT CChmFolderOutStream::FlushCorrupted(UInt64 maxSize)
431} 401}
432 402
433 403
434STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, 404Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
435 Int32 testModeSpec, IArchiveExtractCallback *extractCallback) 405 Int32 testModeSpec, IArchiveExtractCallback *extractCallback))
436{ 406{
437 COM_TRY_BEGIN 407 COM_TRY_BEGIN
438 bool allFilesMode = (numItems == (UInt32)(Int32)-1); 408 const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
439 409
440 if (allFilesMode) 410 if (allFilesMode)
441 numItems = m_Database.NewFormat ? 1: 411 numItems = m_Database.NewFormat ? 1:
@@ -479,13 +449,13 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
479 lps->InSize = currentTotalSize; // Change it 449 lps->InSize = currentTotalSize; // Change it
480 lps->OutSize = currentTotalSize; 450 lps->OutSize = currentTotalSize;
481 451
482 RINOK(lps->SetCur()); 452 RINOK(lps->SetCur())
483 CMyComPtr<ISequentialOutStream> realOutStream; 453 CMyComPtr<ISequentialOutStream> realOutStream;
484 Int32 askMode= testMode ? 454 const Int32 askMode= testMode ?
485 NExtract::NAskMode::kTest : 455 NExtract::NAskMode::kTest :
486 NExtract::NAskMode::kExtract; 456 NExtract::NAskMode::kExtract;
487 Int32 index = allFilesMode ? i : indices[i]; 457 const UInt32 index = allFilesMode ? i : indices[i];
488 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 458 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
489 459
490 if (m_Database.NewFormat) 460 if (m_Database.NewFormat)
491 { 461 {
@@ -496,9 +466,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
496 if (!testMode) 466 if (!testMode)
497 { 467 {
498 UInt32 size = m_Database.NewFormatString.Len(); 468 UInt32 size = m_Database.NewFormatString.Len();
499 RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size)); 469 RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size))
500 } 470 }
501 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); 471 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
502 continue; 472 continue;
503 } 473 }
504 474
@@ -508,27 +478,27 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
508 478
509 if (!testMode && !realOutStream) 479 if (!testMode && !realOutStream)
510 continue; 480 continue;
511 RINOK(extractCallback->PrepareOperation(askMode)); 481 RINOK(extractCallback->PrepareOperation(askMode))
512 if (item.Section != 0) 482 if (item.Section != 0)
513 { 483 {
514 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnsupportedMethod)); 484 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnsupportedMethod))
515 continue; 485 continue;
516 } 486 }
517 487
518 if (testMode) 488 if (testMode)
519 { 489 {
520 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); 490 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
521 continue; 491 continue;
522 } 492 }
523 493
524 RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL)); 494 RINOK(InStream_SeekSet(m_Stream, m_Database.ContentOffset + item.Offset))
525 streamSpec->Init(item.Size); 495 streamSpec->Init(item.Size);
526 496
527 RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress)); 497 RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress))
528 realOutStream.Release(); 498 realOutStream.Release();
529 RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ? 499 RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
530 NExtract::NOperationResult::kOK: 500 NExtract::NOperationResult::kOK:
531 NExtract::NOperationResult::kDataError)); 501 NExtract::NOperationResult::kDataError))
532 } 502 }
533 return S_OK; 503 return S_OK;
534 } 504 }
@@ -537,7 +507,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
537 507
538 for (i = 0; i < numItems; i++) 508 for (i = 0; i < numItems; i++)
539 { 509 {
540 UInt32 index = allFilesMode ? i : indices[i]; 510 const UInt32 index = allFilesMode ? i : indices[i];
541 const CItem &item = m_Database.Items[m_Database.Indices[index]]; 511 const CItem &item = m_Database.Items[m_Database.Indices[index]];
542 const UInt64 sectionIndex = item.Section; 512 const UInt64 sectionIndex = item.Section;
543 if (item.IsDir() || item.Size == 0) 513 if (item.IsDir() || item.Size == 0)
@@ -564,11 +534,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
564 } 534 }
565 } 535 }
566 536
567 RINOK(extractCallback->SetTotal(currentTotalSize)); 537 RINOK(extractCallback->SetTotal(currentTotalSize))
568 538
569 NCompress::NLzx::CDecoder *lzxDecoderSpec = NULL; 539 NCompress::NLzx::CDecoder *lzxDecoderSpec = NULL;
570 CMyComPtr<IUnknown> lzxDecoder; 540 CMyComPtr<IUnknown> lzxDecoder;
571 CChmFolderOutStream *chmFolderOutStream = 0; 541 CChmFolderOutStream *chmFolderOutStream = NULL;
572 CMyComPtr<ISequentialOutStream> outStream; 542 CMyComPtr<ISequentialOutStream> outStream;
573 543
574 currentTotalSize = 0; 544 currentTotalSize = 0;
@@ -579,7 +549,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
579 549
580 for (i = 0;;) 550 for (i = 0;;)
581 { 551 {
582 RINOK(extractCallback->SetCompleted(&currentTotalSize)); 552 RINOK(extractCallback->SetCompleted(&currentTotalSize))
583 553
584 if (i >= numItems) 554 if (i >= numItems)
585 break; 555 break;
@@ -595,10 +565,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
595 if (item.IsDir()) 565 if (item.IsDir())
596 { 566 {
597 CMyComPtr<ISequentialOutStream> realOutStream; 567 CMyComPtr<ISequentialOutStream> realOutStream;
598 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 568 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
599 RINOK(extractCallback->PrepareOperation(askMode)); 569 RINOK(extractCallback->PrepareOperation(askMode))
600 realOutStream.Release(); 570 realOutStream.Release();
601 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); 571 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
602 continue; 572 continue;
603 } 573 }
604 574
@@ -608,21 +578,21 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
608 if (item.Size == 0 || sectionIndex == 0) 578 if (item.Size == 0 || sectionIndex == 0)
609 { 579 {
610 CMyComPtr<ISequentialOutStream> realOutStream; 580 CMyComPtr<ISequentialOutStream> realOutStream;
611 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 581 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
612 if (!testMode && !realOutStream) 582 if (!testMode && !realOutStream)
613 continue; 583 continue;
614 RINOK(extractCallback->PrepareOperation(askMode)); 584 RINOK(extractCallback->PrepareOperation(askMode))
615 Int32 opRes = NExtract::NOperationResult::kOK; 585 Int32 opRes = NExtract::NOperationResult::kOK;
616 if (!testMode && item.Size != 0) 586 if (!testMode && item.Size != 0)
617 { 587 {
618 RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL)); 588 RINOK(InStream_SeekSet(m_Stream, m_Database.ContentOffset + item.Offset))
619 streamSpec->Init(item.Size); 589 streamSpec->Init(item.Size);
620 RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress)); 590 RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress))
621 if (copyCoderSpec->TotalSize != item.Size) 591 if (copyCoderSpec->TotalSize != item.Size)
622 opRes = NExtract::NOperationResult::kDataError; 592 opRes = NExtract::NOperationResult::kDataError;
623 } 593 }
624 realOutStream.Release(); 594 realOutStream.Release();
625 RINOK(extractCallback->SetOperationResult(opRes)); 595 RINOK(extractCallback->SetOperationResult(opRes))
626 currentTotalSize += item.Size; 596 currentTotalSize += item.Size;
627 continue; 597 continue;
628 } 598 }
@@ -631,11 +601,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
631 { 601 {
632 // we must report error here; 602 // we must report error here;
633 CMyComPtr<ISequentialOutStream> realOutStream; 603 CMyComPtr<ISequentialOutStream> realOutStream;
634 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 604 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
635 if (!testMode && !realOutStream) 605 if (!testMode && !realOutStream)
636 continue; 606 continue;
637 RINOK(extractCallback->PrepareOperation(askMode)); 607 RINOK(extractCallback->PrepareOperation(askMode))
638 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kHeadersError)); 608 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kHeadersError))
639 continue; 609 continue;
640 } 610 }
641 611
@@ -644,11 +614,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
644 if (!section.IsLzx()) 614 if (!section.IsLzx())
645 { 615 {
646 CMyComPtr<ISequentialOutStream> realOutStream; 616 CMyComPtr<ISequentialOutStream> realOutStream;
647 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 617 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
648 if (!testMode && !realOutStream) 618 if (!testMode && !realOutStream)
649 continue; 619 continue;
650 RINOK(extractCallback->PrepareOperation(askMode)); 620 RINOK(extractCallback->PrepareOperation(askMode))
651 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnsupportedMethod)); 621 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnsupportedMethod))
652 continue; 622 continue;
653 } 623 }
654 624
@@ -671,7 +641,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
671 UInt64 folderIndex = m_Database.GetFolder(index); 641 UInt64 folderIndex = m_Database.GetFolder(index);
672 642
673 const UInt64 compressedPos = m_Database.ContentOffset + section.Offset; 643 const UInt64 compressedPos = m_Database.ContentOffset + section.Offset;
674 RINOK(lzxDecoderSpec->SetParams_and_Alloc(lzxInfo.GetNumDictBits())); 644 RINOK(lzxDecoderSpec->SetParams_and_Alloc(lzxInfo.GetNumDictBits()))
675 645
676 const CItem *lastItem = &item; 646 const CItem *lastItem = &item;
677 extractStatuses.Clear(); 647 extractStatuses.Clear();
@@ -679,7 +649,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
679 649
680 for (;; folderIndex++) 650 for (;; folderIndex++)
681 { 651 {
682 RINOK(extractCallback->SetCompleted(&currentTotalSize)); 652 RINOK(extractCallback->SetCompleted(&currentTotalSize))
683 653
684 UInt64 startPos = lzxInfo.GetFolderPos(folderIndex); 654 UInt64 startPos = lzxInfo.GetFolderPos(folderIndex);
685 UInt64 finishPos = lastItem->Offset + lastItem->Size; 655 UInt64 finishPos = lastItem->Offset + lastItem->Size;
@@ -702,7 +672,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
702 const CItem &nextItem = m_Database.Items[m_Database.Indices[nextIndex]]; 672 const CItem &nextItem = m_Database.Items[m_Database.Indices[nextIndex]];
703 if (nextItem.Section != sectionIndex) 673 if (nextItem.Section != sectionIndex)
704 break; 674 break;
705 UInt64 nextFolderIndex = m_Database.GetFolder(nextIndex); 675 const UInt64 nextFolderIndex = m_Database.GetFolder(nextIndex);
706 if (nextFolderIndex != folderIndex) 676 if (nextFolderIndex != folderIndex)
707 break; 677 break;
708 for (index++; index < nextIndex; index++) 678 for (index++; index < nextIndex; index++)
@@ -734,7 +704,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
734 for (UInt32 b = 0; b < numBlocks; b++) 704 for (UInt32 b = 0; b < numBlocks; b++)
735 { 705 {
736 UInt64 completedSize = currentTotalSize + chmFolderOutStream->m_PosInSection - startPos; 706 UInt64 completedSize = currentTotalSize + chmFolderOutStream->m_PosInSection - startPos;
737 RINOK(extractCallback->SetCompleted(&completedSize)); 707 RINOK(extractCallback->SetCompleted(&completedSize))
738 UInt64 bCur = startBlock + b; 708 UInt64 bCur = startBlock + b;
739 if (bCur >= rt.ResetOffsets.Size()) 709 if (bCur >= rt.ResetOffsets.Size())
740 return E_FAIL; 710 return E_FAIL;
@@ -744,7 +714,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
744 714
745 // chm writes full blocks. So we don't need to use reduced size for last block 715 // chm writes full blocks. So we don't need to use reduced size for last block
746 716
747 RINOK(m_Stream->Seek(compressedPos + offset, STREAM_SEEK_SET, NULL)); 717 RINOK(InStream_SeekSet(m_Stream, compressedPos + offset))
748 streamSpec->SetStream(m_Stream); 718 streamSpec->SetStream(m_Stream);
749 streamSpec->Init(compressedSize); 719 streamSpec->Init(compressedSize);
750 720
@@ -777,7 +747,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
777 } 747 }
778 catch(...) 748 catch(...)
779 { 749 {
780 RINOK(chmFolderOutStream->FlushCorrupted(unPackSize)); 750 RINOK(chmFolderOutStream->FlushCorrupted(unPackSize))
781 } 751 }
782 752
783 currentTotalSize += folderSize; 753 currentTotalSize += folderSize;
@@ -790,9 +760,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
790 COM_TRY_END 760 COM_TRY_END
791} 761}
792 762
793STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) 763Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
794{ 764{
795 *numItems = m_Database.NewFormat ? 1: 765 *numItems = m_Database.NewFormat ? 1:
796 (m_Database.LowLevel ? 766 (m_Database.LowLevel ?
797 m_Database.Items.Size(): 767 m_Database.Items.Size():
798 m_Database.Indices.Size()); 768 m_Database.Indices.Size());
@@ -805,7 +775,7 @@ static const Byte k_Signature[] = { 'I', 'T', 'S', 'F', 3, 0, 0, 0, 0x60, 0, 0,
805 775
806REGISTER_ARC_I_CLS( 776REGISTER_ARC_I_CLS(
807 CHandler(false), 777 CHandler(false),
808 "Chm", "chm chi chq chw", 0, 0xE9, 778 "Chm", "chm chi chq chw", NULL, 0xE9,
809 k_Signature, 779 k_Signature,
810 0, 780 0,
811 0, 781 0,
@@ -819,7 +789,7 @@ static const Byte k_Signature[] = { 'I', 'T', 'O', 'L', 'I', 'T', 'L', 'S', 1, 0
819 789
820REGISTER_ARC_I_CLS( 790REGISTER_ARC_I_CLS(
821 CHandler(true), 791 CHandler(true),
822 "Hxs", "hxs hxi hxr hxq hxw lit", 0, 0xCE, 792 "Hxs", "hxs hxi hxr hxq hxw lit", NULL, 0xCE,
823 k_Signature, 793 k_Signature,
824 0, 794 0,
825 NArcInfoFlags::kFindSignature, 795 NArcInfoFlags::kFindSignature,