[SHELL32] -Move CFSExtractIcon_CreateInstance to CFSFolder.cpp
[reactos.git] / reactos / dll / win32 / shell32 / folders.cpp
1 /*
2 * Copyright 1997 Marcus Meissner
3 * Copyright 1998 Juergen Schmied
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "precomp.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(shell);
23
24 WCHAR swShell32Name[MAX_PATH];
25
26 DWORD NumIconOverlayHandlers = 0;
27 IShellIconOverlayIdentifier ** Handlers = NULL;
28
29 static void InitIconOverlays(void)
30 {
31 HKEY hKey;
32 DWORD dwIndex, dwResult, dwSize;
33 WCHAR szName[MAX_PATH];
34 WCHAR szValue[100];
35 CLSID clsid;
36
37 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
38 return;
39
40 if (RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwResult, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
41 {
42 RegCloseKey(hKey);
43 return;
44 }
45
46 Handlers = (IShellIconOverlayIdentifier **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwResult * sizeof(IShellIconOverlayIdentifier*));
47 if (!Handlers)
48 {
49 RegCloseKey(hKey);
50 return;
51 }
52
53 dwIndex = 0;
54
55 CoInitialize(0);
56
57 do
58 {
59 dwSize = sizeof(szName) / sizeof(WCHAR);
60 dwResult = RegEnumKeyExW(hKey, dwIndex, szName, &dwSize, NULL, NULL, NULL, NULL);
61
62 if (dwResult == ERROR_NO_MORE_ITEMS)
63 break;
64
65 if (dwResult == ERROR_SUCCESS)
66 {
67 dwSize = sizeof(szValue) / sizeof(WCHAR);
68 if (RegGetValueW(hKey, szName, NULL, RRF_RT_REG_SZ, NULL, szValue, &dwSize) == ERROR_SUCCESS)
69 {
70 CComPtr<IShellIconOverlayIdentifier> Overlay;
71
72 CLSIDFromString(szValue, &clsid);
73 dwResult = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellIconOverlayIdentifier, &Overlay));
74 if (dwResult == S_OK)
75 {
76 Handlers[NumIconOverlayHandlers] = Overlay.Detach();
77 NumIconOverlayHandlers++;
78 }
79 }
80 }
81
82 dwIndex++;
83
84 } while(1);
85
86 RegCloseKey(hKey);
87 }
88
89 BOOL
90 GetIconOverlay(LPCITEMIDLIST pidl, WCHAR * wTemp, int* pIndex)
91 {
92 DWORD Index;
93 HRESULT hResult;
94 int Priority;
95 int HighestPriority;
96 ULONG IconIndex;
97 ULONG Flags;
98 WCHAR szPath[MAX_PATH];
99
100 if(!SHGetPathFromIDListW(pidl, szPath))
101 return FALSE;
102
103 if (!Handlers)
104 InitIconOverlays();
105
106 HighestPriority = 101;
107 IconIndex = NumIconOverlayHandlers;
108 for(Index = 0; Index < NumIconOverlayHandlers; Index++)
109 {
110 hResult = Handlers[Index]->IsMemberOf(szPath, SFGAO_FILESYSTEM);
111 if (hResult == S_OK)
112 {
113 hResult = Handlers[Index]->GetPriority(&Priority);
114 if (hResult == S_OK)
115 {
116 if (Priority < HighestPriority)
117 {
118 HighestPriority = Priority;
119 IconIndex = Index;
120 }
121 }
122 }
123 }
124
125 if (IconIndex == NumIconOverlayHandlers)
126 return FALSE;
127
128 hResult = Handlers[IconIndex]->GetOverlayInfo(wTemp, MAX_PATH, pIndex, &Flags);
129
130 if (hResult == S_OK)
131 return TRUE;
132 else
133 return FALSE;
134 }