3 * (HKEY_CLASSES_ROOT - Stuff)
5 * Copyright 1998, 1999, 2000 Juergen Schmied
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
32 #include "wine/debug.h"
41 #include "shell32_main.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 #define MAX_EXTENSION_LENGTH 20
52 BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, LONG len, BOOL bPrependDot)
55 WCHAR szTemp[MAX_EXTENSION_LENGTH + 2];
57 TRACE("%s %p\n", debugstr_w(szExtension), debugstr_w(szFileType));
59 /* added because we do not want to have double dots */
60 if (szExtension[0] == '.')
66 lstrcpynW(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
68 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
73 if (RegQueryValueW(hkey, NULL, szFileType, &len))
81 TRACE("--UE;\n} %s\n", debugstr_w(szFileType));
86 BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, LONG len, BOOL bPrependDot)
89 char szTemp[MAX_EXTENSION_LENGTH + 2];
91 TRACE("%s %p\n", szExtension, szFileType);
93 /* added because we do not want to have double dots */
94 if (szExtension[0] == '.')
100 lstrcpynA(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
102 if (RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
107 if (RegQueryValueA(hkey, NULL, szFileType, &len))
115 TRACE("--UE;\n} %s\n", szFileType);
121 BOOL HCR_GetExecuteCommandW( HKEY hkeyClass, LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len )
123 static const WCHAR swShell[] = {'s','h','e','l','l','\\',0};
124 static const WCHAR swCommand[] = {'\\','c','o','m','m','a','n','d',0};
127 TRACE("%p %s %s %p\n", hkeyClass, debugstr_w(szClass), debugstr_w(szVerb), szDest);
130 RegOpenKeyExW(HKEY_CLASSES_ROOT, szClass, 0, 0x02000000, &hkeyClass);
134 WCHAR sTemp[MAX_PATH];
135 lstrcpyW(sTemp, swShell);
136 lstrcatW(sTemp, szVerb);
137 lstrcatW(sTemp, swCommand);
139 ret = (ERROR_SUCCESS == SHGetValueW(hkeyClass, sTemp, NULL, NULL, szDest, &len));
142 RegCloseKey(hkeyClass);
145 TRACE("-- %s\n", debugstr_w(szDest) );
149 /***************************************************************************************
150 * HCR_GetDefaultIcon [internal]
152 * Gets the icon for a filetype
154 static BOOL HCR_RegOpenClassIDKey(REFIID riid, HKEY *hkey)
157 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
158 riid->Data1, riid->Data2, riid->Data3,
159 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
160 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
162 TRACE("%s\n",xriid );
164 return !RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey);
167 static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, LPDWORD dwNr)
170 WCHAR sTemp[MAX_PATH];
173 if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
175 if (dwType == REG_EXPAND_SZ)
177 ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
178 lstrcpynW(szDest, sTemp, len);
180 if (ParseFieldW (szDest, 2, sNum, 5))
183 *dwNr=0; /* sometimes the icon number is missing */
184 ParseFieldW (szDest, 1, szDest, len);
185 PathUnquoteSpacesW(szDest);
191 static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, LPDWORD dwNr)
194 char sTemp[MAX_PATH];
197 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
199 if (dwType == REG_EXPAND_SZ)
201 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
202 lstrcpynA(szDest, sTemp, len);
204 if (ParseFieldA (szDest, 2, sNum, 5))
207 *dwNr=0; /* sometimes the icon number is missing */
208 ParseFieldA (szDest, 1, szDest, len);
209 PathUnquoteSpacesA(szDest);
215 BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr)
217 static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0};
219 WCHAR sTemp[MAX_PATH];
222 TRACE("%s\n",debugstr_w(szClass) );
224 lstrcpynW(sTemp, szClass, MAX_PATH);
225 lstrcatW(sTemp, swDefaultIcon);
227 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
229 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
234 TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
236 TRACE("-- not found\n");
241 BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
244 char sTemp[MAX_PATH];
247 TRACE("%s\n",szClass );
249 sprintf(sTemp, "%s\\DefaultIcon",szClass);
251 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
253 ret = HCR_RegGetDefaultIconA(hkey, szDest, len, dwNr);
256 TRACE("-- %s %li\n", szDest, *dwNr );
260 BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr)
265 if (HCR_RegOpenClassIDKey(riid, &hkey))
267 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
270 TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
274 /***************************************************************************************
275 * HCR_GetClassName [internal]
277 * Gets the name of a registered class
279 static const WCHAR swEmpty[] = {0};
281 BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len)
288 if (HCR_RegOpenClassIDKey(riid, &hkey))
290 if (!RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len))
297 if (!ret || !szDest[0])
299 if(IsEqualIID(riid, &CLSID_ShellDesktop))
301 if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
304 else if (IsEqualIID(riid, &CLSID_MyComputer))
306 if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
310 TRACE("-- %s\n", debugstr_w(szDest));
314 BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
320 if (HCR_RegOpenClassIDKey(riid, &hkey))
322 if (!RegQueryValueExA(hkey,"",0,NULL,(LPBYTE)szDest,&len))
329 if (!ret || !szDest[0])
331 if(IsEqualIID(riid, &CLSID_ShellDesktop))
333 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
336 else if (IsEqualIID(riid, &CLSID_MyComputer))
338 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
343 TRACE("-- %s\n", szDest);
348 /******************************************************************************
349 * HCR_GetFolderAttributes [Internal]
351 * Query the registry for a shell folders' attributes
354 * pidlFolder [I] A simple pidl of type PT_GUID.
355 * pdwAttributes [IO] In: Attributes to be queried, OUT: Resulting attributes.
358 * TRUE: Found information for the attributes in the registry
359 * FALSE: No attribute information found
362 * If queried for an attribute, which is set in the CallForAttributes registry
363 * value, the function binds to the shellfolder objects and queries it.
365 BOOL HCR_GetFolderAttributes(LPCITEMIDLIST pidlFolder, LPDWORD pdwAttributes)
371 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
372 static const WCHAR wszCallForAttributes[] = {
373 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
374 WCHAR wszShellFolderKey[] = { 'C','L','S','I','D','\\','{','0','0','0','2','1','4','0','0','-',
375 '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-','0','0','0','0','0','0','0',
376 '0','0','0','4','6','}','\\','S','h','e','l','l','F','o','l','d','e','r',0 };
378 TRACE("(pidlFolder=%p, pdwAttributes=%p)\n", pidlFolder, pdwAttributes);
380 if (!_ILIsPidlSimple(pidlFolder)) {
381 ERR("HCR_GetFolderAttributes should be called for simple PIDL's only!\n");
385 if (!_ILIsDesktop(pidlFolder)) {
386 if (FAILED(StringFromCLSID(_ILGetGUIDPointer(pidlFolder), &pwszCLSID))) return FALSE;
387 memcpy(&wszShellFolderKey[6], pwszCLSID, 38 * sizeof(WCHAR));
388 CoTaskMemFree(pwszCLSID);
391 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszShellFolderKey, 0, KEY_READ, &hSFKey);
392 if (lResult != ERROR_SUCCESS) return FALSE;
394 dwLen = sizeof(DWORD);
395 lResult = RegQueryValueExW(hSFKey, wszCallForAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen);
396 if ((lResult == ERROR_SUCCESS) && (dwTemp & *pdwAttributes)) {
397 LPSHELLFOLDER psfDesktop, psfFolder;
401 hr = SHGetDesktopFolder(&psfDesktop);
403 hr = IShellFolder_BindToObject(psfDesktop, pidlFolder, NULL, &IID_IShellFolder,
404 (LPVOID*)&psfFolder);
406 hr = IShellFolder_GetAttributesOf(psfFolder, 0, NULL, pdwAttributes);
407 IShellFolder_Release(psfFolder);
409 IShellFolder_Release(psfDesktop);
411 if (FAILED(hr)) return FALSE;
413 lResult = RegQueryValueExW(hSFKey, wszAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen);
415 if (lResult == ERROR_SUCCESS) {
416 *pdwAttributes &= dwTemp;
422 TRACE("-- *pdwAttributes == 0x%08lx\n", *pdwAttributes);