OLD | NEW |
| (Empty) |
1 // LoadCodecs.cpp | |
2 | |
3 #include "StdAfx.h" | |
4 | |
5 #include "LoadCodecs.h" | |
6 | |
7 #include "../../../Common/MyCom.h" | |
8 #ifdef NEW_FOLDER_INTERFACE | |
9 #include "../../../Common/StringToInt.h" | |
10 #endif | |
11 #include "../../../Windows/PropVariant.h" | |
12 | |
13 #include "../../ICoder.h" | |
14 #include "../../Common/RegisterArc.h" | |
15 | |
16 #ifdef EXTERNAL_CODECS | |
17 #include "../../../Windows/FileFind.h" | |
18 #include "../../../Windows/DLL.h" | |
19 #ifdef NEW_FOLDER_INTERFACE | |
20 #include "../../../Windows/ResourceString.h" | |
21 static const UINT kIconTypesResId = 100; | |
22 #endif | |
23 | |
24 #ifdef _WIN32 | |
25 #include "Windows/Registry.h" | |
26 #endif | |
27 | |
28 using namespace NWindows; | |
29 using namespace NFile; | |
30 | |
31 #ifdef _WIN32 | |
32 extern HINSTANCE g_hInstance; | |
33 #endif | |
34 | |
35 static CSysString GetLibraryFolderPrefix() | |
36 { | |
37 #ifdef _WIN32 | |
38 TCHAR fullPath[MAX_PATH + 1]; | |
39 ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH); | |
40 CSysString path = fullPath; | |
41 int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR)); | |
42 return path.Left(pos + 1); | |
43 #else | |
44 return CSysString(); // FIX IT | |
45 #endif | |
46 } | |
47 | |
48 #define kCodecsFolderName TEXT("Codecs") | |
49 #define kFormatsFolderName TEXT("Formats") | |
50 static const TCHAR *kMainDll = TEXT("7z.dll"); | |
51 | |
52 #ifdef _WIN32 | |
53 static LPCTSTR kRegistryPath = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT
("7-zip"); | |
54 static LPCTSTR kProgramPathValue = TEXT("Path"); | |
55 static bool ReadPathFromRegistry(HKEY baseKey, CSysString &path) | |
56 { | |
57 NRegistry::CKey key; | |
58 if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS) | |
59 if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS) | |
60 { | |
61 NName::NormalizeDirPathPrefix(path); | |
62 return true; | |
63 } | |
64 return false; | |
65 } | |
66 | |
67 #endif | |
68 | |
69 CSysString GetBaseFolderPrefixFromRegistry() | |
70 { | |
71 CSysString moduleFolderPrefix = GetLibraryFolderPrefix(); | |
72 NFind::CFileInfo fi; | |
73 if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi)) | |
74 if (!fi.IsDir()) | |
75 return moduleFolderPrefix; | |
76 if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi)) | |
77 if (fi.IsDir()) | |
78 return moduleFolderPrefix; | |
79 if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi)) | |
80 if (fi.IsDir()) | |
81 return moduleFolderPrefix; | |
82 #ifdef _WIN32 | |
83 CSysString path; | |
84 if (ReadPathFromRegistry(HKEY_CURRENT_USER, path)) | |
85 return path; | |
86 if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path)) | |
87 return path; | |
88 #endif | |
89 return moduleFolderPrefix; | |
90 } | |
91 | |
92 typedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods); | |
93 typedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats); | |
94 typedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *valu
e); | |
95 typedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PR
OPVARIANT *value); | |
96 typedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, vo
id **outObject); | |
97 typedef UInt32 (WINAPI *SetLargePageModeFunc)(); | |
98 | |
99 | |
100 static HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 ind
ex, | |
101 PROPID propId, CLSID &clsId, bool &isAssigned) | |
102 { | |
103 NWindows::NCOM::CPropVariant prop; | |
104 isAssigned = false; | |
105 RINOK(getMethodProperty(index, propId, &prop)); | |
106 if (prop.vt == VT_BSTR) | |
107 { | |
108 isAssigned = true; | |
109 clsId = *(const GUID *)prop.bstrVal; | |
110 } | |
111 else if (prop.vt != VT_EMPTY) | |
112 return E_FAIL; | |
113 return S_OK; | |
114 } | |
115 | |
116 HRESULT CCodecs::LoadCodecs() | |
117 { | |
118 CCodecLib &lib = Libs.Back(); | |
119 lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress("GetMeth
odProperty"); | |
120 if (lib.GetMethodProperty == NULL) | |
121 return S_OK; | |
122 | |
123 UInt32 numMethods = 1; | |
124 GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Li
b.GetProcAddress("GetNumberOfMethods"); | |
125 if (getNumberOfMethodsFunc != NULL) | |
126 { | |
127 RINOK(getNumberOfMethodsFunc(&numMethods)); | |
128 } | |
129 | |
130 for(UInt32 i = 0; i < numMethods; i++) | |
131 { | |
132 CDllCodecInfo info; | |
133 info.LibIndex = Libs.Size() - 1; | |
134 info.CodecIndex = i; | |
135 | |
136 RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.
Encoder, info.EncoderIsAssigned)); | |
137 RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.
Decoder, info.DecoderIsAssigned)); | |
138 | |
139 Codecs.Add(info); | |
140 } | |
141 return S_OK; | |
142 } | |
143 | |
144 static HRESULT ReadProp( | |
145 GetHandlerPropertyFunc getProp, | |
146 GetHandlerPropertyFunc2 getProp2, | |
147 UInt32 index, PROPID propID, NCOM::CPropVariant &prop) | |
148 { | |
149 if (getProp2) | |
150 return getProp2(index, propID, &prop);; | |
151 return getProp(propID, &prop); | |
152 } | |
153 | |
154 static HRESULT ReadBoolProp( | |
155 GetHandlerPropertyFunc getProp, | |
156 GetHandlerPropertyFunc2 getProp2, | |
157 UInt32 index, PROPID propID, bool &res) | |
158 { | |
159 NCOM::CPropVariant prop; | |
160 RINOK(ReadProp(getProp, getProp2, index, propID, prop)); | |
161 if (prop.vt == VT_BOOL) | |
162 res = VARIANT_BOOLToBool(prop.boolVal); | |
163 else if (prop.vt != VT_EMPTY) | |
164 return E_FAIL; | |
165 return S_OK; | |
166 } | |
167 | |
168 static HRESULT ReadStringProp( | |
169 GetHandlerPropertyFunc getProp, | |
170 GetHandlerPropertyFunc2 getProp2, | |
171 UInt32 index, PROPID propID, UString &res) | |
172 { | |
173 NCOM::CPropVariant prop; | |
174 RINOK(ReadProp(getProp, getProp2, index, propID, prop)); | |
175 if (prop.vt == VT_BSTR) | |
176 res = prop.bstrVal; | |
177 else if (prop.vt != VT_EMPTY) | |
178 return E_FAIL; | |
179 return S_OK; | |
180 } | |
181 | |
182 #endif | |
183 | |
184 static const unsigned int kNumArcsMax = 32; | |
185 static unsigned int g_NumArcs = 0; | |
186 static const CArcInfo *g_Arcs[kNumArcsMax]; | |
187 void RegisterArc(const CArcInfo *arcInfo) | |
188 { | |
189 if (g_NumArcs < kNumArcsMax) | |
190 g_Arcs[g_NumArcs++] = arcInfo; | |
191 } | |
192 | |
193 static void SplitString(const UString &srcString, UStringVector &destStrings) | |
194 { | |
195 destStrings.Clear(); | |
196 UString s; | |
197 int len = srcString.Length(); | |
198 if (len == 0) | |
199 return; | |
200 for (int i = 0; i < len; i++) | |
201 { | |
202 wchar_t c = srcString[i]; | |
203 if (c == L' ') | |
204 { | |
205 if (!s.IsEmpty()) | |
206 { | |
207 destStrings.Add(s); | |
208 s.Empty(); | |
209 } | |
210 } | |
211 else | |
212 s += c; | |
213 } | |
214 if (!s.IsEmpty()) | |
215 destStrings.Add(s); | |
216 } | |
217 | |
218 void CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt) | |
219 { | |
220 UStringVector exts, addExts; | |
221 SplitString(ext, exts); | |
222 if (addExt != 0) | |
223 SplitString(addExt, addExts); | |
224 for (int i = 0; i < exts.Size(); i++) | |
225 { | |
226 CArcExtInfo extInfo; | |
227 extInfo.Ext = exts[i]; | |
228 if (i < addExts.Size()) | |
229 { | |
230 extInfo.AddExt = addExts[i]; | |
231 if (extInfo.AddExt == L"*") | |
232 extInfo.AddExt.Empty(); | |
233 } | |
234 Exts.Add(extInfo); | |
235 } | |
236 } | |
237 | |
238 #ifdef EXTERNAL_CODECS | |
239 | |
240 HRESULT CCodecs::LoadFormats() | |
241 { | |
242 const NDLL::CLibrary &lib = Libs.Back().Lib; | |
243 GetHandlerPropertyFunc getProp = 0; | |
244 GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2) | |
245 lib.GetProcAddress("GetHandlerProperty2"); | |
246 if (getProp2 == NULL) | |
247 { | |
248 getProp = (GetHandlerPropertyFunc) | |
249 lib.GetProcAddress("GetHandlerProperty"); | |
250 if (getProp == NULL) | |
251 return S_OK; | |
252 } | |
253 | |
254 UInt32 numFormats = 1; | |
255 GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc) | |
256 lib.GetProcAddress("GetNumberOfFormats"); | |
257 if (getNumberOfFormats != NULL) | |
258 { | |
259 RINOK(getNumberOfFormats(&numFormats)); | |
260 } | |
261 if (getProp2 == NULL) | |
262 numFormats = 1; | |
263 | |
264 for(UInt32 i = 0; i < numFormats; i++) | |
265 { | |
266 CArcInfoEx item; | |
267 item.LibIndex = Libs.Size() - 1; | |
268 item.FormatIndex = i; | |
269 | |
270 RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name)); | |
271 | |
272 NCOM::CPropVariant prop; | |
273 if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK) | |
274 continue; | |
275 if (prop.vt != VT_BSTR) | |
276 continue; | |
277 item.ClassID = *(const GUID *)prop.bstrVal; | |
278 prop.Clear(); | |
279 | |
280 UString ext, addExt; | |
281 RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext)); | |
282 RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt))
; | |
283 item.AddExts(ext, addExt); | |
284 | |
285 ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled); | |
286 if (item.UpdateEnabled) | |
287 ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName); | |
288 | |
289 if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK) | |
290 if (prop.vt == VT_BSTR) | |
291 { | |
292 UINT len = ::SysStringByteLen(prop.bstrVal); | |
293 item.StartSignature.SetCapacity(len); | |
294 memmove(item.StartSignature, prop.bstrVal, len); | |
295 } | |
296 Formats.Add(item); | |
297 } | |
298 return S_OK; | |
299 } | |
300 | |
301 #ifdef NEW_FOLDER_INTERFACE | |
302 void CCodecLib::LoadIcons() | |
303 { | |
304 UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId); | |
305 UStringVector pairs; | |
306 SplitString(iconTypes, pairs); | |
307 for (int i = 0; i < pairs.Size(); i++) | |
308 { | |
309 const UString &s = pairs[i]; | |
310 int pos = s.Find(L':'); | |
311 if (pos < 0) | |
312 continue; | |
313 CIconPair iconPair; | |
314 const wchar_t *end; | |
315 UString num = s.Mid(pos + 1); | |
316 iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end); | |
317 if (*end != L'\0') | |
318 continue; | |
319 iconPair.Ext = s.Left(pos); | |
320 IconPairs.Add(iconPair); | |
321 } | |
322 } | |
323 | |
324 int CCodecLib::FindIconIndex(const UString &ext) const | |
325 { | |
326 for (int i = 0; i < IconPairs.Size(); i++) | |
327 { | |
328 const CIconPair &pair = IconPairs[i]; | |
329 if (ext.CompareNoCase(pair.Ext) == 0) | |
330 return pair.IconIndex; | |
331 } | |
332 return -1; | |
333 } | |
334 #endif | |
335 | |
336 #ifdef _7ZIP_LARGE_PAGES | |
337 extern "C" | |
338 { | |
339 extern SIZE_T g_LargePageSize; | |
340 } | |
341 #endif | |
342 | |
343 HRESULT CCodecs::LoadDll(const CSysString &dllPath) | |
344 { | |
345 { | |
346 NDLL::CLibrary library; | |
347 if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE)) | |
348 return S_OK; | |
349 } | |
350 Libs.Add(CCodecLib()); | |
351 CCodecLib &lib = Libs.Back(); | |
352 #ifdef NEW_FOLDER_INTERFACE | |
353 lib.Path = dllPath; | |
354 #endif | |
355 bool used = false; | |
356 HRESULT res = S_OK; | |
357 if (lib.Lib.Load(dllPath)) | |
358 { | |
359 #ifdef NEW_FOLDER_INTERFACE | |
360 lib.LoadIcons(); | |
361 #endif | |
362 | |
363 #ifdef _7ZIP_LARGE_PAGES | |
364 if (g_LargePageSize != 0) | |
365 { | |
366 SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetP
rocAddress("SetLargePageMode"); | |
367 if (setLargePageMode != 0) | |
368 setLargePageMode(); | |
369 } | |
370 #endif | |
371 | |
372 lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress("CreateObject"); | |
373 if (lib.CreateObject != 0) | |
374 { | |
375 int startSize = Codecs.Size(); | |
376 res = LoadCodecs(); | |
377 used = (Codecs.Size() != startSize); | |
378 if (res == S_OK) | |
379 { | |
380 startSize = Formats.Size(); | |
381 res = LoadFormats(); | |
382 used = used || (Formats.Size() != startSize); | |
383 } | |
384 } | |
385 } | |
386 if (!used) | |
387 Libs.DeleteBack(); | |
388 return res; | |
389 } | |
390 | |
391 HRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix) | |
392 { | |
393 NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT("*"))); | |
394 NFile::NFind::CFileInfo fi; | |
395 while (enumerator.Next(fi)) | |
396 { | |
397 if (fi.IsDir()) | |
398 continue; | |
399 RINOK(LoadDll(folderPrefix + fi.Name)); | |
400 } | |
401 return S_OK; | |
402 } | |
403 | |
404 #endif | |
405 | |
406 #ifndef _SFX | |
407 static inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size) | |
408 { | |
409 bb.SetCapacity(size); | |
410 memmove((Byte *)bb, data, size); | |
411 } | |
412 #endif | |
413 | |
414 HRESULT CCodecs::Load() | |
415 { | |
416 Formats.Clear(); | |
417 #ifdef EXTERNAL_CODECS | |
418 Codecs.Clear(); | |
419 #endif | |
420 for (UInt32 i = 0; i < g_NumArcs; i++) | |
421 { | |
422 const CArcInfo &arc = *g_Arcs[i]; | |
423 CArcInfoEx item; | |
424 item.Name = arc.Name; | |
425 item.CreateInArchive = arc.CreateInArchive; | |
426 item.CreateOutArchive = arc.CreateOutArchive; | |
427 item.AddExts(arc.Ext, arc.AddExt); | |
428 item.UpdateEnabled = (arc.CreateOutArchive != 0); | |
429 item.KeepName = arc.KeepName; | |
430 | |
431 #ifndef _SFX | |
432 SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize); | |
433 #endif | |
434 Formats.Add(item); | |
435 } | |
436 #ifdef EXTERNAL_CODECS | |
437 const CSysString baseFolder = GetBaseFolderPrefixFromRegistry(); | |
438 RINOK(LoadDll(baseFolder + kMainDll)); | |
439 RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPAR
ATOR))); | |
440 RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPA
RATOR))); | |
441 #endif | |
442 return S_OK; | |
443 } | |
444 | |
445 #ifndef _SFX | |
446 | |
447 int CCodecs::FindFormatForArchiveName(const UString &arcPath) const | |
448 { | |
449 int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR); | |
450 int slashPos2 = arcPath.ReverseFind(L'.'); | |
451 int dotPos = arcPath.ReverseFind(L'.'); | |
452 if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2) | |
453 return -1; | |
454 UString ext = arcPath.Mid(dotPos + 1); | |
455 for (int i = 0; i < Formats.Size(); i++) | |
456 { | |
457 const CArcInfoEx &arc = Formats[i]; | |
458 if (!arc.UpdateEnabled) | |
459 continue; | |
460 // if (arc.FindExtension(ext) >= 0) | |
461 UString mainExt = arc.GetMainExt(); | |
462 if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0) | |
463 return i; | |
464 } | |
465 return -1; | |
466 } | |
467 | |
468 int CCodecs::FindFormatForExtension(const UString &ext) const | |
469 { | |
470 if (ext.IsEmpty()) | |
471 return -1; | |
472 for (int i = 0; i < Formats.Size(); i++) | |
473 if (Formats[i].FindExtension(ext) >= 0) | |
474 return i; | |
475 return -1; | |
476 } | |
477 | |
478 int CCodecs::FindFormatForArchiveType(const UString &arcType) const | |
479 { | |
480 for (int i = 0; i < Formats.Size(); i++) | |
481 if (Formats[i].Name.CompareNoCase(arcType) == 0) | |
482 return i; | |
483 return -1; | |
484 } | |
485 | |
486 bool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &forma
tIndices) const | |
487 { | |
488 formatIndices.Clear(); | |
489 for (int pos = 0; pos < arcType.Length();) | |
490 { | |
491 int pos2 = arcType.Find('.', pos); | |
492 if (pos2 < 0) | |
493 pos2 = arcType.Length(); | |
494 const UString name = arcType.Mid(pos, pos2 - pos); | |
495 int index = FindFormatForArchiveType(name); | |
496 if (index < 0 && name != L"*") | |
497 { | |
498 formatIndices.Clear(); | |
499 return false; | |
500 } | |
501 formatIndices.Add(index); | |
502 pos = pos2 + 1; | |
503 } | |
504 return true; | |
505 } | |
506 | |
507 #endif | |
508 | |
509 #ifdef EXTERNAL_CODECS | |
510 | |
511 #ifdef EXPORT_CODECS | |
512 extern unsigned int g_NumCodecs; | |
513 STDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject
); | |
514 STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value); | |
515 // STDAPI GetNumberOfMethods(UInt32 *numCodecs); | |
516 #endif | |
517 | |
518 STDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods) | |
519 { | |
520 *numMethods = | |
521 #ifdef EXPORT_CODECS | |
522 g_NumCodecs + | |
523 #endif | |
524 Codecs.Size(); | |
525 return S_OK; | |
526 } | |
527 | |
528 STDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *valu
e) | |
529 { | |
530 #ifdef EXPORT_CODECS | |
531 if (index < g_NumCodecs) | |
532 return GetMethodProperty(index, propID, value); | |
533 #endif | |
534 | |
535 const CDllCodecInfo &ci = Codecs[index | |
536 #ifdef EXPORT_CODECS | |
537 - g_NumCodecs | |
538 #endif | |
539 ]; | |
540 | |
541 if (propID == NMethodPropID::kDecoderIsAssigned) | |
542 { | |
543 NWindows::NCOM::CPropVariant propVariant; | |
544 propVariant = ci.DecoderIsAssigned; | |
545 propVariant.Detach(value); | |
546 return S_OK; | |
547 } | |
548 if (propID == NMethodPropID::kEncoderIsAssigned) | |
549 { | |
550 NWindows::NCOM::CPropVariant propVariant; | |
551 propVariant = ci.EncoderIsAssigned; | |
552 propVariant.Detach(value); | |
553 return S_OK; | |
554 } | |
555 return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value); | |
556 } | |
557 | |
558 STDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder) | |
559 { | |
560 #ifdef EXPORT_CODECS | |
561 if (index < g_NumCodecs) | |
562 return CreateCoder2(false, index, iid, coder); | |
563 #endif | |
564 const CDllCodecInfo &ci = Codecs[index | |
565 #ifdef EXPORT_CODECS | |
566 - g_NumCodecs | |
567 #endif | |
568 ]; | |
569 if (ci.DecoderIsAssigned) | |
570 return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder); | |
571 return S_OK; | |
572 } | |
573 | |
574 STDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder) | |
575 { | |
576 #ifdef EXPORT_CODECS | |
577 if (index < g_NumCodecs) | |
578 return CreateCoder2(true, index, iid, coder); | |
579 #endif | |
580 const CDllCodecInfo &ci = Codecs[index | |
581 #ifdef EXPORT_CODECS | |
582 - g_NumCodecs | |
583 #endif | |
584 ]; | |
585 if (ci.EncoderIsAssigned) | |
586 return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder); | |
587 return S_OK; | |
588 } | |
589 | |
590 HRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompre
ssCoder> &coder) const | |
591 { | |
592 for (int i = 0; i < Codecs.Size(); i++) | |
593 { | |
594 const CDllCodecInfo &codec = Codecs[i]; | |
595 if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigne
d) | |
596 continue; | |
597 const CCodecLib &lib = Libs[codec.LibIndex]; | |
598 UString res; | |
599 NWindows::NCOM::CPropVariant prop; | |
600 RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop)); | |
601 if (prop.vt == VT_BSTR) | |
602 res = prop.bstrVal; | |
603 else if (prop.vt != VT_EMPTY) | |
604 continue; | |
605 if (name.CompareNoCase(res) == 0) | |
606 return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICo
mpressCoder, (void **)&coder); | |
607 } | |
608 return CLASS_E_CLASSNOTAVAILABLE; | |
609 } | |
610 | |
611 int CCodecs::GetCodecLibIndex(UInt32 index) | |
612 { | |
613 #ifdef EXPORT_CODECS | |
614 if (index < g_NumCodecs) | |
615 return -1; | |
616 #endif | |
617 #ifdef EXTERNAL_CODECS | |
618 const CDllCodecInfo &ci = Codecs[index | |
619 #ifdef EXPORT_CODECS | |
620 - g_NumCodecs | |
621 #endif | |
622 ]; | |
623 return ci.LibIndex; | |
624 #else | |
625 return -1; | |
626 #endif | |
627 } | |
628 | |
629 bool CCodecs::GetCodecEncoderIsAssigned(UInt32 index) | |
630 { | |
631 #ifdef EXPORT_CODECS | |
632 if (index < g_NumCodecs) | |
633 { | |
634 NWindows::NCOM::CPropVariant prop; | |
635 if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK) | |
636 if (prop.vt != VT_EMPTY) | |
637 return true; | |
638 return false; | |
639 } | |
640 #endif | |
641 #ifdef EXTERNAL_CODECS | |
642 const CDllCodecInfo &ci = Codecs[index | |
643 #ifdef EXPORT_CODECS | |
644 - g_NumCodecs | |
645 #endif | |
646 ]; | |
647 return ci.EncoderIsAssigned; | |
648 #else | |
649 return false; | |
650 #endif | |
651 } | |
652 | |
653 HRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id) | |
654 { | |
655 UString s; | |
656 NWindows::NCOM::CPropVariant prop; | |
657 RINOK(GetProperty(index, NMethodPropID::kID, &prop)); | |
658 if (prop.vt != VT_UI8) | |
659 return E_INVALIDARG; | |
660 id = prop.uhVal.QuadPart; | |
661 return S_OK; | |
662 } | |
663 | |
664 UString CCodecs::GetCodecName(UInt32 index) | |
665 { | |
666 UString s; | |
667 NWindows::NCOM::CPropVariant prop; | |
668 if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK) | |
669 if (prop.vt == VT_BSTR) | |
670 s = prop.bstrVal; | |
671 return s; | |
672 } | |
673 | |
674 #endif | |
OLD | NEW |