@@ -80,31 +80,26 @@ class CDecoder Z7_final
80
80
{
81
81
CMyComPtr<ISequentialOutStream> _bcjStream;
82
82
CFilterCoder *_filterCoder;
83
- CMyComPtr<ICompressCoder> _lzmaDecoder;
84
83
public:
85
- NCompress::NLzma::CDecoder *_lzmaDecoderSpec ;
84
+ CMyComPtr2<ICompressCoder, NCompress::NLzma::CDecoder> _lzmaDecoder ;
86
85
87
86
~CDecoder ();
88
87
HRESULT Create (bool filtered, ISequentialInStream *inStream);
89
88
90
89
HRESULT Code (const CHeader &header, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
91
90
92
- UInt64 GetInputProcessedSize () const { return _lzmaDecoderSpec ->GetInputProcessedSize (); }
91
+ UInt64 GetInputProcessedSize () const { return _lzmaDecoder ->GetInputProcessedSize (); }
93
92
94
- void ReleaseInStream () { if (_lzmaDecoder) _lzmaDecoderSpec ->ReleaseInStream (); }
93
+ void ReleaseInStream () { if (_lzmaDecoder) _lzmaDecoder ->ReleaseInStream (); }
95
94
96
95
HRESULT ReadInput (Byte *data, UInt32 size, UInt32 *processedSize)
97
- { return _lzmaDecoderSpec ->ReadFromInputStream (data, size, processedSize); }
96
+ { return _lzmaDecoder ->ReadFromInputStream (data, size, processedSize); }
98
97
};
99
98
100
99
HRESULT CDecoder::Create (bool filteredMode, ISequentialInStream *inStream)
101
100
{
102
- if (!_lzmaDecoder)
103
- {
104
- _lzmaDecoderSpec = new NCompress::NLzma::CDecoder;
105
- _lzmaDecoderSpec->FinishStream = true ;
106
- _lzmaDecoder = _lzmaDecoderSpec;
107
- }
101
+ _lzmaDecoder.Create_if_Empty ();
102
+ _lzmaDecoder->FinishStream = true ;
108
103
109
104
if (filteredMode)
110
105
{
@@ -117,7 +112,7 @@ HRESULT CDecoder::Create(bool filteredMode, ISequentialInStream *inStream)
117
112
}
118
113
}
119
114
120
- return _lzmaDecoderSpec ->SetInStream (inStream);
115
+ return _lzmaDecoder ->SetInStream (inStream);
121
116
}
122
117
123
118
CDecoder::~CDecoder ()
@@ -131,7 +126,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
131
126
if (header.FilterID > 1 )
132
127
return E_NOTIMPL;
133
128
134
- RINOK (_lzmaDecoderSpec ->SetDecoderProperties2 (header.LzmaProps , 5 ))
129
+ RINOK (_lzmaDecoder ->SetDecoderProperties2 (header.LzmaProps , 5 ))
135
130
136
131
bool filteredMode = (header.FilterID == 1 );
137
132
@@ -143,7 +138,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
143
138
}
144
139
145
140
const UInt64 *Size = header.HasSize () ? &header.Size : NULL ;
146
- HRESULT res = _lzmaDecoderSpec ->CodeResume (outStream, Size, progress);
141
+ HRESULT res = _lzmaDecoder ->CodeResume (outStream, Size, progress);
147
142
148
143
if (filteredMode)
149
144
{
@@ -160,7 +155,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
160
155
RINOK (res)
161
156
162
157
if (header.HasSize ())
163
- if (_lzmaDecoderSpec ->GetOutputProcessedSize () != header.Size )
158
+ if (_lzmaDecoder ->GetOutputProcessedSize () != header.Size )
164
159
return S_FALSE;
165
160
166
161
return S_OK;
@@ -170,11 +165,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
170
165
Z7_CLASS_IMP_CHandler_IInArchive_1 (
171
166
IArchiveOpenSeq
172
167
)
173
- CHeader _header;
174
168
bool _lzma86;
175
- CMyComPtr<IInStream> _stream;
176
- CMyComPtr<ISequentialInStream> _seqStream;
177
-
178
169
bool _isArc;
179
170
bool _needSeekToStart;
180
171
bool _dataAfterEnd;
@@ -186,6 +177,10 @@ Z7_CLASS_IMP_CHandler_IInArchive_1(
186
177
bool _unpackSize_Defined;
187
178
bool _numStreams_Defined;
188
179
180
+ CHeader _header;
181
+ CMyComPtr<IInStream> _stream;
182
+ CMyComPtr<ISequentialInStream> _seqStream;
183
+
189
184
UInt64 _packSize;
190
185
UInt64 _unpackSize;
191
186
UInt64 _numStreams;
@@ -220,6 +215,7 @@ Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
220
215
prop = v;
221
216
break ;
222
217
}
218
+ default : break ;
223
219
}
224
220
prop.Detach (value);
225
221
return S_OK;
@@ -288,6 +284,7 @@ Z7_COM7F_IMF(CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIAN
288
284
case kpidSize: if (_stream && _header.HasSize ()) prop = _header.Size ; break ;
289
285
case kpidPackSize: if (_packSize_Defined) prop = _packSize; break ;
290
286
case kpidMethod: GetMethod (prop); break ;
287
+ default : break ;
291
288
}
292
289
prop.Detach (value);
293
290
return S_OK;
@@ -366,7 +363,6 @@ Z7_COM7F_IMF(CHandler::Open(IInStream *inStream, const UInt64 *, IArchiveOpenCal
366
363
)
367
364
return S_FALSE;
368
365
369
- CDecoder state;
370
366
const UInt32 outLimit = 1 << 11 ;
371
367
Byte outBuf[outLimit];
372
368
@@ -452,9 +448,10 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
452
448
return E_INVALIDARG;
453
449
454
450
if (_packSize_Defined)
455
- extractCallback->SetTotal (_packSize);
451
+ RINOK ( extractCallback->SetTotal (_packSize))
456
452
457
-
453
+ Int32 opResult;
454
+ {
458
455
CMyComPtr<ISequentialOutStream> realOutStream;
459
456
const Int32 askMode = testMode ?
460
457
NExtract::NAskMode::kTest :
@@ -463,16 +460,14 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
463
460
if (!testMode && !realOutStream)
464
461
return S_OK;
465
462
466
- extractCallback->PrepareOperation (askMode);
463
+ RINOK ( extractCallback->PrepareOperation (askMode))
467
464
468
- CDummyOutStream *outStreamSpec = new CDummyOutStream;
469
- CMyComPtr<ISequentialOutStream> outStream (outStreamSpec);
470
- outStreamSpec->SetStream (realOutStream);
471
- outStreamSpec->Init ();
465
+ CMyComPtr2_Create<ISequentialOutStream, CDummyOutStream> outStream;
466
+ outStream->SetStream (realOutStream);
467
+ outStream->Init ();
472
468
realOutStream.Release ();
473
469
474
- CLocalProgress *lps = new CLocalProgress;
475
- CMyComPtr<ICompressProgressInfo> progress = lps;
470
+ CMyComPtr2_Create<ICompressProgressInfo, CLocalProgress> lps;
476
471
lps->Init (extractCallback, true );
477
472
478
473
if (_needSeekToStart)
@@ -485,8 +480,7 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
485
480
_needSeekToStart = true ;
486
481
487
482
CDecoder decoder;
488
- HRESULT result = decoder.Create (_lzma86, _seqStream);
489
- RINOK (result)
483
+ RINOK (decoder.Create (_lzma86, _seqStream))
490
484
491
485
bool firstItem = true ;
492
486
@@ -496,6 +490,8 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
496
490
497
491
bool dataAfterEnd = false ;
498
492
493
+ HRESULT hres = S_OK;
494
+
499
495
for (;;)
500
496
{
501
497
lps->InSize = packSize;
@@ -523,32 +519,32 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
523
519
numStreams++;
524
520
firstItem = false ;
525
521
526
- result = decoder.Code (st, outStream, progress );
522
+ hres = decoder.Code (st, outStream, lps );
527
523
528
524
packSize = decoder.GetInputProcessedSize ();
529
- unpackSize = outStreamSpec ->GetSize ();
525
+ unpackSize = outStream ->GetSize ();
530
526
531
- if (result == E_NOTIMPL)
527
+ if (hres == E_NOTIMPL)
532
528
{
533
529
_unsupported = true ;
534
- result = S_FALSE;
530
+ hres = S_FALSE;
535
531
break ;
536
532
}
537
- if (result == S_FALSE)
533
+ if (hres == S_FALSE)
538
534
break ;
539
- RINOK (result )
535
+ RINOK (hres )
540
536
}
541
537
542
538
if (firstItem)
543
539
{
544
540
_isArc = false ;
545
- result = S_FALSE;
541
+ hres = S_FALSE;
546
542
}
547
- else if (result == S_OK || result == S_FALSE)
543
+ else if (hres == S_OK || hres == S_FALSE)
548
544
{
549
545
if (dataAfterEnd)
550
546
_dataAfterEnd = true ;
551
- else if (decoder._lzmaDecoderSpec ->NeedsMoreInput ())
547
+ else if (decoder._lzmaDecoder ->NeedsMoreInput ())
552
548
_needMoreInput = true ;
553
549
554
550
_packSize = packSize;
@@ -560,7 +556,7 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
560
556
_numStreams_Defined = true ;
561
557
}
562
558
563
- Int32 opResult = NExtract::NOperationResult::kOK ;
559
+ opResult = NExtract::NOperationResult::kOK ;
564
560
565
561
if (!_isArc)
566
562
opResult = NExtract::NOperationResult::kIsNotArc ;
@@ -570,14 +566,15 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
570
566
opResult = NExtract::NOperationResult::kUnsupportedMethod ;
571
567
else if (_dataAfterEnd)
572
568
opResult = NExtract::NOperationResult::kDataAfterEnd ;
573
- else if (result == S_FALSE)
569
+ else if (hres == S_FALSE)
574
570
opResult = NExtract::NOperationResult::kDataError ;
575
- else if (result == S_OK)
571
+ else if (hres == S_OK)
576
572
opResult = NExtract::NOperationResult::kOK ;
577
573
else
578
- return result ;
574
+ return hres ;
579
575
580
- outStream.Release ();
576
+ // outStream.Release();
577
+ }
581
578
return extractCallback->SetOperationResult (opResult);
582
579
583
580
COM_TRY_END
0 commit comments