aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Common/CreateCoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Common/CreateCoder.cpp')
-rw-r--r--CPP/7zip/Common/CreateCoder.cpp113
1 files changed, 58 insertions, 55 deletions
diff --git a/CPP/7zip/Common/CreateCoder.cpp b/CPP/7zip/Common/CreateCoder.cpp
index 872f17f..bf7b04e 100644
--- a/CPP/7zip/Common/CreateCoder.cpp
+++ b/CPP/7zip/Common/CreateCoder.cpp
@@ -19,11 +19,11 @@ const CCodecInfo *g_Codecs[];
19const CCodecInfo *g_Codecs[kNumCodecsMax]; 19const CCodecInfo *g_Codecs[kNumCodecsMax];
20 20
21// We use g_ExternalCodecs in other stages. 21// We use g_ExternalCodecs in other stages.
22#ifdef EXTERNAL_CODECS 22#ifdef Z7_EXTERNAL_CODECS
23/* 23/*
24extern CExternalCodecs g_ExternalCodecs; 24extern CExternalCodecs g_ExternalCodecs;
25#define CHECK_GLOBAL_CODECS \ 25#define CHECK_GLOBAL_CODECS \
26 if (!__externalCodecs || !__externalCodecs->IsSet()) __externalCodecs = &g_ExternalCodecs; 26 if (!_externalCodecs || !_externalCodecs->IsSet()) _externalCodecs = &g_ExternalCodecs;
27*/ 27*/
28#define CHECK_GLOBAL_CODECS 28#define CHECK_GLOBAL_CODECS
29#endif 29#endif
@@ -50,12 +50,12 @@ void RegisterHasher(const CHasherInfo *hashInfo) throw()
50} 50}
51 51
52 52
53#ifdef EXTERNAL_CODECS 53#ifdef Z7_EXTERNAL_CODECS
54 54
55static HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res) 55static HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)
56{ 56{
57 NWindows::NCOM::CPropVariant prop; 57 NWindows::NCOM::CPropVariant prop;
58 RINOK(codecsInfo->GetProperty(index, propID, &prop)); 58 RINOK(codecsInfo->GetProperty(index, propID, &prop))
59 if (prop.vt == VT_EMPTY) 59 if (prop.vt == VT_EMPTY)
60 res = 1; 60 res = 1;
61 else if (prop.vt == VT_UI4) 61 else if (prop.vt == VT_UI4)
@@ -68,7 +68,7 @@ static HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index
68static HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res) 68static HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)
69{ 69{
70 NWindows::NCOM::CPropVariant prop; 70 NWindows::NCOM::CPropVariant prop;
71 RINOK(codecsInfo->GetProperty(index, propID, &prop)); 71 RINOK(codecsInfo->GetProperty(index, propID, &prop))
72 if (prop.vt == VT_EMPTY) 72 if (prop.vt == VT_EMPTY)
73 res = true; 73 res = true;
74 else if (prop.vt == VT_BOOL) 74 else if (prop.vt == VT_BOOL)
@@ -89,13 +89,13 @@ HRESULT CExternalCodecs::Load()
89 89
90 UString s; 90 UString s;
91 UInt32 num; 91 UInt32 num;
92 RINOK(GetCodecs->GetNumMethods(&num)); 92 RINOK(GetCodecs->GetNumMethods(&num))
93 93
94 for (UInt32 i = 0; i < num; i++) 94 for (UInt32 i = 0; i < num; i++)
95 { 95 {
96 NWindows::NCOM::CPropVariant prop; 96 NWindows::NCOM::CPropVariant prop;
97 97
98 RINOK(GetCodecs->GetProperty(i, NMethodPropID::kID, &prop)); 98 RINOK(GetCodecs->GetProperty(i, NMethodPropID::kID, &prop))
99 if (prop.vt != VT_UI8) 99 if (prop.vt != VT_UI8)
100 continue; // old Interface 100 continue; // old Interface
101 info.Id = prop.uhVal.QuadPart; 101 info.Id = prop.uhVal.QuadPart;
@@ -103,22 +103,22 @@ HRESULT CExternalCodecs::Load()
103 prop.Clear(); 103 prop.Clear();
104 104
105 info.Name.Empty(); 105 info.Name.Empty();
106 RINOK(GetCodecs->GetProperty(i, NMethodPropID::kName, &prop)); 106 RINOK(GetCodecs->GetProperty(i, NMethodPropID::kName, &prop))
107 if (prop.vt == VT_BSTR) 107 if (prop.vt == VT_BSTR)
108 info.Name.SetFromWStr_if_Ascii(prop.bstrVal); 108 info.Name.SetFromWStr_if_Ascii(prop.bstrVal);
109 else if (prop.vt != VT_EMPTY) 109 else if (prop.vt != VT_EMPTY)
110 continue; 110 continue;
111 111
112 RINOK(ReadNumberOfStreams(GetCodecs, i, NMethodPropID::kPackStreams, info.NumStreams)); 112 RINOK(ReadNumberOfStreams(GetCodecs, i, NMethodPropID::kPackStreams, info.NumStreams))
113 { 113 {
114 UInt32 numUnpackStreams = 1; 114 UInt32 numUnpackStreams = 1;
115 RINOK(ReadNumberOfStreams(GetCodecs, i, NMethodPropID::kUnpackStreams, numUnpackStreams)); 115 RINOK(ReadNumberOfStreams(GetCodecs, i, NMethodPropID::kUnpackStreams, numUnpackStreams))
116 if (numUnpackStreams != 1) 116 if (numUnpackStreams != 1)
117 continue; 117 continue;
118 } 118 }
119 RINOK(ReadIsAssignedProp(GetCodecs, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned)); 119 RINOK(ReadIsAssignedProp(GetCodecs, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned))
120 RINOK(ReadIsAssignedProp(GetCodecs, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned)); 120 RINOK(ReadIsAssignedProp(GetCodecs, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned))
121 RINOK(ReadIsAssignedProp(GetCodecs, i, NMethodPropID::kIsFilter, info.IsFilter)); 121 RINOK(ReadIsAssignedProp(GetCodecs, i, NMethodPropID::kIsFilter, info.IsFilter))
122 122
123 Codecs.Add(info); 123 Codecs.Add(info);
124 } 124 }
@@ -133,7 +133,7 @@ HRESULT CExternalCodecs::Load()
133 { 133 {
134 NWindows::NCOM::CPropVariant prop; 134 NWindows::NCOM::CPropVariant prop;
135 135
136 RINOK(GetHashers->GetHasherProp(i, NMethodPropID::kID, &prop)); 136 RINOK(GetHashers->GetHasherProp(i, NMethodPropID::kID, &prop))
137 if (prop.vt != VT_UI8) 137 if (prop.vt != VT_UI8)
138 continue; 138 continue;
139 info.Id = prop.uhVal.QuadPart; 139 info.Id = prop.uhVal.QuadPart;
@@ -141,7 +141,7 @@ HRESULT CExternalCodecs::Load()
141 prop.Clear(); 141 prop.Clear();
142 142
143 info.Name.Empty(); 143 info.Name.Empty();
144 RINOK(GetHashers->GetHasherProp(i, NMethodPropID::kName, &prop)); 144 RINOK(GetHashers->GetHasherProp(i, NMethodPropID::kName, &prop))
145 if (prop.vt == VT_BSTR) 145 if (prop.vt == VT_BSTR)
146 info.Name.SetFromWStr_if_Ascii(prop.bstrVal); 146 info.Name.SetFromWStr_if_Ascii(prop.bstrVal);
147 else if (prop.vt != VT_EMPTY) 147 else if (prop.vt != VT_EMPTY)
@@ -162,7 +162,8 @@ int FindMethod_Index(
162 const AString &name, 162 const AString &name,
163 bool encode, 163 bool encode,
164 CMethodId &methodId, 164 CMethodId &methodId,
165 UInt32 &numStreams) 165 UInt32 &numStreams,
166 bool &isFilter)
166{ 167{
167 unsigned i; 168 unsigned i;
168 for (i = 0; i < g_NumCodecs; i++) 169 for (i = 0; i < g_NumCodecs; i++)
@@ -173,23 +174,25 @@ int FindMethod_Index(
173 { 174 {
174 methodId = codec.Id; 175 methodId = codec.Id;
175 numStreams = codec.NumStreams; 176 numStreams = codec.NumStreams;
177 isFilter = codec.IsFilter;
176 return (int)i; 178 return (int)i;
177 } 179 }
178 } 180 }
179 181
180 #ifdef EXTERNAL_CODECS 182 #ifdef Z7_EXTERNAL_CODECS
181 183
182 CHECK_GLOBAL_CODECS 184 CHECK_GLOBAL_CODECS
183 185
184 if (__externalCodecs) 186 if (_externalCodecs)
185 for (i = 0; i < __externalCodecs->Codecs.Size(); i++) 187 for (i = 0; i < _externalCodecs->Codecs.Size(); i++)
186 { 188 {
187 const CCodecInfoEx &codec = __externalCodecs->Codecs[i]; 189 const CCodecInfoEx &codec = _externalCodecs->Codecs[i];
188 if ((encode ? codec.EncoderIsAssigned : codec.DecoderIsAssigned) 190 if ((encode ? codec.EncoderIsAssigned : codec.DecoderIsAssigned)
189 && StringsAreEqualNoCase_Ascii(name, codec.Name)) 191 && StringsAreEqualNoCase_Ascii(name, codec.Name))
190 { 192 {
191 methodId = codec.Id; 193 methodId = codec.Id;
192 numStreams = codec.NumStreams; 194 numStreams = codec.NumStreams;
195 isFilter = codec.IsFilter;
193 return (int)(g_NumCodecs + i); 196 return (int)(g_NumCodecs + i);
194 } 197 }
195 } 198 }
@@ -212,14 +215,14 @@ static int FindMethod_Index(
212 return (int)i; 215 return (int)i;
213 } 216 }
214 217
215 #ifdef EXTERNAL_CODECS 218 #ifdef Z7_EXTERNAL_CODECS
216 219
217 CHECK_GLOBAL_CODECS 220 CHECK_GLOBAL_CODECS
218 221
219 if (__externalCodecs) 222 if (_externalCodecs)
220 for (i = 0; i < __externalCodecs->Codecs.Size(); i++) 223 for (i = 0; i < _externalCodecs->Codecs.Size(); i++)
221 { 224 {
222 const CCodecInfoEx &codec = __externalCodecs->Codecs[i]; 225 const CCodecInfoEx &codec = _externalCodecs->Codecs[i];
223 if (codec.Id == methodId && (encode ? codec.EncoderIsAssigned : codec.DecoderIsAssigned)) 226 if (codec.Id == methodId && (encode ? codec.EncoderIsAssigned : codec.DecoderIsAssigned))
224 return (int)(g_NumCodecs + i); 227 return (int)(g_NumCodecs + i);
225 } 228 }
@@ -248,14 +251,14 @@ bool FindMethod(
248 } 251 }
249 } 252 }
250 253
251 #ifdef EXTERNAL_CODECS 254 #ifdef Z7_EXTERNAL_CODECS
252 255
253 CHECK_GLOBAL_CODECS 256 CHECK_GLOBAL_CODECS
254 257
255 if (__externalCodecs) 258 if (_externalCodecs)
256 for (i = 0; i < __externalCodecs->Codecs.Size(); i++) 259 for (i = 0; i < _externalCodecs->Codecs.Size(); i++)
257 { 260 {
258 const CCodecInfoEx &codec = __externalCodecs->Codecs[i]; 261 const CCodecInfoEx &codec = _externalCodecs->Codecs[i];
259 if (methodId == codec.Id) 262 if (methodId == codec.Id)
260 { 263 {
261 name = codec.Name; 264 name = codec.Name;
@@ -284,14 +287,14 @@ bool FindHashMethod(
284 } 287 }
285 } 288 }
286 289
287 #ifdef EXTERNAL_CODECS 290 #ifdef Z7_EXTERNAL_CODECS
288 291
289 CHECK_GLOBAL_CODECS 292 CHECK_GLOBAL_CODECS
290 293
291 if (__externalCodecs) 294 if (_externalCodecs)
292 for (i = 0; i < __externalCodecs->Hashers.Size(); i++) 295 for (i = 0; i < _externalCodecs->Hashers.Size(); i++)
293 { 296 {
294 const CHasherInfoEx &codec = __externalCodecs->Hashers[i]; 297 const CHasherInfoEx &codec = _externalCodecs->Hashers[i];
295 if (StringsAreEqualNoCase_Ascii(name, codec.Name)) 298 if (StringsAreEqualNoCase_Ascii(name, codec.Name))
296 { 299 {
297 methodId = codec.Id; 300 methodId = codec.Id;
@@ -313,13 +316,13 @@ void GetHashMethods(
313 for (i = 0; i < g_NumHashers; i++) 316 for (i = 0; i < g_NumHashers; i++)
314 methods[i] = (*g_Hashers[i]).Id; 317 methods[i] = (*g_Hashers[i]).Id;
315 318
316 #ifdef EXTERNAL_CODECS 319 #ifdef Z7_EXTERNAL_CODECS
317 320
318 CHECK_GLOBAL_CODECS 321 CHECK_GLOBAL_CODECS
319 322
320 if (__externalCodecs) 323 if (_externalCodecs)
321 for (i = 0; i < __externalCodecs->Hashers.Size(); i++) 324 for (i = 0; i < _externalCodecs->Hashers.Size(); i++)
322 methods.Add(__externalCodecs->Hashers[i].Id); 325 methods.Add(_externalCodecs->Hashers[i].Id);
323 326
324 #endif 327 #endif
325} 328}
@@ -364,17 +367,17 @@ HRESULT CreateCoder_Index(
364 } 367 }
365 } 368 }
366 369
367 #ifdef EXTERNAL_CODECS 370 #ifdef Z7_EXTERNAL_CODECS
368 371
369 CHECK_GLOBAL_CODECS 372 CHECK_GLOBAL_CODECS
370 373
371 if (__externalCodecs) 374 if (_externalCodecs)
372 { 375 {
373 i -= g_NumCodecs; 376 i -= g_NumCodecs;
374 cod.IsExternal = true; 377 cod.IsExternal = true;
375 if (i < __externalCodecs->Codecs.Size()) 378 if (i < _externalCodecs->Codecs.Size())
376 { 379 {
377 const CCodecInfoEx &codec = __externalCodecs->Codecs[i]; 380 const CCodecInfoEx &codec = _externalCodecs->Codecs[i];
378 // if (codec.Id == methodId) 381 // if (codec.Id == methodId)
379 { 382 {
380 if (encode) 383 if (encode)
@@ -383,15 +386,15 @@ HRESULT CreateCoder_Index(
383 { 386 {
384 if (codec.NumStreams == 1) 387 if (codec.NumStreams == 1)
385 { 388 {
386 HRESULT res = __externalCodecs->GetCodecs->CreateEncoder(i, &IID_ICompressCoder, (void **)&cod.Coder); 389 const HRESULT res = _externalCodecs->GetCodecs->CreateEncoder(i, &IID_ICompressCoder, (void **)&cod.Coder);
387 if (res != S_OK && res != E_NOINTERFACE && res != CLASS_E_CLASSNOTAVAILABLE) 390 if (res != S_OK && res != E_NOINTERFACE && res != CLASS_E_CLASSNOTAVAILABLE)
388 return res; 391 return res;
389 if (cod.Coder) 392 if (cod.Coder)
390 return res; 393 return res;
391 return __externalCodecs->GetCodecs->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter); 394 return _externalCodecs->GetCodecs->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter);
392 } 395 }
393 cod.NumStreams = codec.NumStreams; 396 cod.NumStreams = codec.NumStreams;
394 return __externalCodecs->GetCodecs->CreateEncoder(i, &IID_ICompressCoder2, (void **)&cod.Coder2); 397 return _externalCodecs->GetCodecs->CreateEncoder(i, &IID_ICompressCoder2, (void **)&cod.Coder2);
395 } 398 }
396 } 399 }
397 else 400 else
@@ -399,15 +402,15 @@ HRESULT CreateCoder_Index(
399 { 402 {
400 if (codec.NumStreams == 1) 403 if (codec.NumStreams == 1)
401 { 404 {
402 HRESULT res = __externalCodecs->GetCodecs->CreateDecoder(i, &IID_ICompressCoder, (void **)&cod.Coder); 405 const HRESULT res = _externalCodecs->GetCodecs->CreateDecoder(i, &IID_ICompressCoder, (void **)&cod.Coder);
403 if (res != S_OK && res != E_NOINTERFACE && res != CLASS_E_CLASSNOTAVAILABLE) 406 if (res != S_OK && res != E_NOINTERFACE && res != CLASS_E_CLASSNOTAVAILABLE)
404 return res; 407 return res;
405 if (cod.Coder) 408 if (cod.Coder)
406 return res; 409 return res;
407 return __externalCodecs->GetCodecs->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter); 410 return _externalCodecs->GetCodecs->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter);
408 } 411 }
409 cod.NumStreams = codec.NumStreams; 412 cod.NumStreams = codec.NumStreams;
410 return __externalCodecs->GetCodecs->CreateDecoder(i, &IID_ICompressCoder2, (void **)&cod.Coder2); 413 return _externalCodecs->GetCodecs->CreateDecoder(i, &IID_ICompressCoder2, (void **)&cod.Coder2);
411 } 414 }
412 } 415 }
413 } 416 }
@@ -424,7 +427,7 @@ HRESULT CreateCoder_Index(
424 CCreatedCoder &cod) 427 CCreatedCoder &cod)
425{ 428{
426 CMyComPtr<ICompressFilter> filter; 429 CMyComPtr<ICompressFilter> filter;
427 HRESULT res = CreateCoder_Index( 430 const HRESULT res = CreateCoder_Index(
428 EXTERNAL_CODECS_LOC_VARS 431 EXTERNAL_CODECS_LOC_VARS
429 index, encode, 432 index, encode,
430 filter, cod); 433 filter, cod);
@@ -447,7 +450,7 @@ HRESULT CreateCoder_Id(
447 CMyComPtr<ICompressFilter> &filter, 450 CMyComPtr<ICompressFilter> &filter,
448 CCreatedCoder &cod) 451 CCreatedCoder &cod)
449{ 452{
450 int index = FindMethod_Index(EXTERNAL_CODECS_LOC_VARS methodId, encode); 453 const int index = FindMethod_Index(EXTERNAL_CODECS_LOC_VARS methodId, encode);
451 if (index < 0) 454 if (index < 0)
452 return S_OK; 455 return S_OK;
453 return CreateCoder_Index(EXTERNAL_CODECS_LOC_VARS (unsigned)index, encode, filter, cod); 456 return CreateCoder_Index(EXTERNAL_CODECS_LOC_VARS (unsigned)index, encode, filter, cod);
@@ -460,7 +463,7 @@ HRESULT CreateCoder_Id(
460 CCreatedCoder &cod) 463 CCreatedCoder &cod)
461{ 464{
462 CMyComPtr<ICompressFilter> filter; 465 CMyComPtr<ICompressFilter> filter;
463 HRESULT res = CreateCoder_Id( 466 const HRESULT res = CreateCoder_Id(
464 EXTERNAL_CODECS_LOC_VARS 467 EXTERNAL_CODECS_LOC_VARS
465 methodId, encode, 468 methodId, encode,
466 filter, cod); 469 filter, cod);
@@ -483,7 +486,7 @@ HRESULT CreateCoder_Id(
483 CMyComPtr<ICompressCoder> &coder) 486 CMyComPtr<ICompressCoder> &coder)
484{ 487{
485 CCreatedCoder cod; 488 CCreatedCoder cod;
486 HRESULT res = CreateCoder_Id( 489 const HRESULT res = CreateCoder_Id(
487 EXTERNAL_CODECS_LOC_VARS 490 EXTERNAL_CODECS_LOC_VARS
488 methodId, encode, 491 methodId, encode,
489 cod); 492 cod);
@@ -524,18 +527,18 @@ HRESULT CreateHasher(
524 } 527 }
525 } 528 }
526 529
527 #ifdef EXTERNAL_CODECS 530 #ifdef Z7_EXTERNAL_CODECS
528 531
529 CHECK_GLOBAL_CODECS 532 CHECK_GLOBAL_CODECS
530 533
531 if (!hasher && __externalCodecs) 534 if (!hasher && _externalCodecs)
532 for (i = 0; i < __externalCodecs->Hashers.Size(); i++) 535 for (i = 0; i < _externalCodecs->Hashers.Size(); i++)
533 { 536 {
534 const CHasherInfoEx &codec = __externalCodecs->Hashers[i]; 537 const CHasherInfoEx &codec = _externalCodecs->Hashers[i];
535 if (codec.Id == methodId) 538 if (codec.Id == methodId)
536 { 539 {
537 name = codec.Name; 540 name = codec.Name;
538 return __externalCodecs->GetHashers->CreateHasher((UInt32)i, &hasher); 541 return _externalCodecs->GetHashers->CreateHasher((UInt32)i, &hasher);
539 } 542 }
540 } 543 }
541 544