LoadCodecs.cpp 16 KB

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