ReactOS  0.4.14-dev-297-g23e575c
folders.cpp
Go to the documentation of this file.
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 
23 
25 IShellIconOverlayIdentifier ** Handlers = NULL;
26 
27 static void InitIconOverlays(void)
28 {
29  HKEY hKey;
30  DWORD dwIndex, dwResult, dwSize;
32  WCHAR szValue[100];
33  CLSID clsid;
34 
35  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
36  return;
37 
38  if (RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwResult, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
39  {
40  RegCloseKey(hKey);
41  return;
42  }
43 
44  Handlers = (IShellIconOverlayIdentifier **)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwResult * sizeof(IShellIconOverlayIdentifier*));
45  if (!Handlers)
46  {
47  RegCloseKey(hKey);
48  return;
49  }
50 
51  dwIndex = 0;
52 
53  CoInitialize(0);
54 
55  do
56  {
57  dwSize = sizeof(szName) / sizeof(WCHAR);
58  dwResult = RegEnumKeyExW(hKey, dwIndex, szName, &dwSize, NULL, NULL, NULL, NULL);
59 
60  if (dwResult == ERROR_NO_MORE_ITEMS)
61  break;
62 
63  if (dwResult == ERROR_SUCCESS)
64  {
65  dwSize = sizeof(szValue) / sizeof(WCHAR);
66  if (RegGetValueW(hKey, szName, NULL, RRF_RT_REG_SZ, NULL, szValue, &dwSize) == ERROR_SUCCESS)
67  {
69 
70  CLSIDFromString(szValue, &clsid);
71  dwResult = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellIconOverlayIdentifier, &Overlay));
72  if (dwResult == S_OK)
73  {
76  }
77  }
78  }
79 
80  dwIndex++;
81 
82  } while(1);
83 
84  RegCloseKey(hKey);
85 }
86 
87 BOOL
89 {
90  DWORD Index;
91  HRESULT hResult;
92  int Priority;
93  int HighestPriority;
95  ULONG Flags;
97 
98  if(!SHGetPathFromIDListW(pidl, szPath))
99  return FALSE;
100 
101  if (!Handlers)
103 
104  HighestPriority = 101;
106  for(Index = 0; Index < NumIconOverlayHandlers; Index++)
107  {
108  hResult = Handlers[Index]->IsMemberOf(szPath, SFGAO_FILESYSTEM);
109  if (hResult == S_OK)
110  {
111  hResult = Handlers[Index]->GetPriority(&Priority);
112  if (hResult == S_OK)
113  {
114  if (Priority < HighestPriority)
115  {
116  HighestPriority = Priority;
117  IconIndex = Index;
118  }
119  }
120  }
121  }
122 
124  return FALSE;
125 
126  hResult = Handlers[IconIndex]->GetOverlayInfo(wTemp, MAX_PATH, pIndex, &Flags);
127 
128  if (hResult == S_OK)
129  return TRUE;
130  else
131  return FALSE;
132 }
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1965
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
#define KEY_READ
Definition: nt_native.h:1023
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
WCHAR swShell32Name[MAX_PATH]
Definition: folders.cpp:22
#define RRF_RT_REG_SZ
Definition: driver.c:575
DWORD NumIconOverlayHandlers
Definition: folders.cpp:24
#define IID_PPV_ARG(Itype, ppType)
BOOL GetIconOverlay(LPCITEMIDLIST pidl, WCHAR *wTemp, int *pIndex)
Definition: folders.cpp:88
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
IShellIconOverlayIdentifier ** Handlers
Definition: folders.cpp:25
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
static const WCHAR IconIndex[]
Definition: install.c:52
REFCLSID clsid
Definition: msctf.c:82
static const WCHAR L[]
Definition: oid.c:1250
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:59
_Out_ PULONG _Out_ PULONG pIndex
Definition: ndis.h:4564
static void InitIconOverlays(void)
Definition: folders.cpp:27
LPCWSTR szPath
Definition: env.c:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
static const WCHAR szName[]
Definition: msipriv.h:1194
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
unsigned int ULONG
Definition: retypes.h:1
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
T * Detach()
Definition: atlcomcli.h:156
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12