xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/FileManager/FilePlugins.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // FilePlugins.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../Agent/Agent.h"
6 
7 #include "FilePlugins.h"
8 #include "PluginLoader.h"
9 #include "StringUtils.h"
10 
FindExt(const UString & ext) const11 int CExtDatabase::FindExt(const UString &ext) const
12 {
13   FOR_VECTOR (i, Exts)
14     if (Exts[i].Ext.IsEqualTo_NoCase(ext))
15       return (int)i;
16   return -1;
17 }
18 
Read()19 void CExtDatabase::Read()
20 {
21   /*
22   ReadFileFolderPluginInfoList(Plugins);
23   FOR_VECTOR (pluginIndex, Plugins)
24   */
25   {
26     // const CPluginInfo &plugin = Plugins[pluginIndex];
27 
28     CPluginLibrary pluginLib;
29     CMyComPtr<IFolderManager> folderManager;
30 
31     // if (plugin.FilePath.IsEmpty())
32       folderManager = new CArchiveFolderManager;
33     /*
34     else
35     {
36       if (!plugin.ClassID_Defined)
37         continue;
38       if (pluginLib.LoadAndCreateManager(plugin.FilePath, plugin.ClassID, &folderManager) != S_OK)
39         continue;
40     }
41     */
42     CMyComBSTR extBSTR;
43     if (folderManager->GetExtensions(&extBSTR) != S_OK)
44       return;
45     UStringVector exts;
46     SplitString((const wchar_t *)extBSTR, exts);
47     FOR_VECTOR (i, exts)
48     {
49       const UString &ext = exts[i];
50       #ifdef UNDER_CE
51       if (ext == L"cab")
52         continue;
53       #endif
54 
55       Int32 iconIndex;
56       CMyComBSTR iconPath;
57       CPluginToIcon plugPair;
58       // plugPair.PluginIndex = pluginIndex;
59       if (folderManager->GetIconPath(ext, &iconPath, &iconIndex) == S_OK)
60         if (iconPath)
61         {
62           plugPair.IconPath = (const wchar_t *)iconPath;
63           plugPair.IconIndex = iconIndex;
64         }
65 
66       const int index = FindExt(ext);
67       if (index >= 0)
68         Exts[index].Plugins.Add(plugPair);
69       else
70       {
71         CExtPlugins extInfo;
72         extInfo.Plugins.Add(plugPair);
73         extInfo.Ext = ext;
74         Exts.Add(extInfo);
75       }
76     }
77   }
78 }
79