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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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);
120 static const WCHAR swShell[] = {'s','h','e','l','l','\\',0};
121 static const WCHAR swOpen[] = {'o','p','e','n',0};
122 static const WCHAR swCommand[] = {'\\','c','o','m','m','a','n','d',0};
124 BOOL HCR_GetDefaultVerbW( HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len )
126 WCHAR sTemp[MAX_PATH];
130 TRACE("%p %s %p\n", hkeyClass, debugstr_w(szVerb), szDest);
134 lstrcpynW(szDest, szVerb, len);
140 if (!RegQueryValueW(hkeyClass, swShell, szDest, &size) && *szDest)
142 /* The MSDN says to first try the default verb */
143 lstrcpyW(sTemp, swShell);
144 lstrcatW(sTemp, szDest);
145 lstrcatW(sTemp, swCommand);
146 if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey))
149 TRACE("default verb=%s\n", debugstr_w(szDest));
154 /* then fallback to 'open' */
155 lstrcpyW(sTemp, swShell);
156 lstrcatW(sTemp, swOpen);
157 lstrcatW(sTemp, swCommand);
158 if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey))
161 lstrcpynW(szDest, swOpen, len);
162 TRACE("default verb=open\n");
166 /* and then just use the first verb on Windows >= 2000 */
167 if (!RegEnumKeyW(hkeyClass, 0, szDest, len) && *szDest)
169 TRACE("default verb=first verb=%s\n", debugstr_w(szDest));
173 TRACE("no default verb!\n");
177 BOOL HCR_GetExecuteCommandW( HKEY hkeyClass, LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len )
179 WCHAR sTempVerb[MAX_PATH];
182 TRACE("%p %s %s %p\n", hkeyClass, debugstr_w(szClass), debugstr_w(szVerb), szDest);
185 RegOpenKeyExW(HKEY_CLASSES_ROOT, szClass, 0, 0x02000000, &hkeyClass);
190 if (HCR_GetDefaultVerbW(hkeyClass, szVerb, sTempVerb, sizeof(sTempVerb)))
192 WCHAR sTemp[MAX_PATH];
193 lstrcpyW(sTemp, swShell);
194 lstrcatW(sTemp, sTempVerb);
195 lstrcatW(sTemp, swCommand);
196 ret = (ERROR_SUCCESS == SHGetValueW(hkeyClass, sTemp, NULL, NULL, szDest, &len));
199 RegCloseKey(hkeyClass);
201 TRACE("-- %s\n", debugstr_w(szDest) );
205 /***************************************************************************************
206 * HCR_GetDefaultIcon [internal]
208 * Gets the icon for a filetype
210 static BOOL HCR_RegOpenClassIDKey(REFIID riid, HKEY *hkey)
213 sprintf( xriid, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
214 riid->Data1, riid->Data2, riid->Data3,
215 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
216 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
218 TRACE("%s\n",xriid );
220 return !RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey);
223 static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, int* picon_idx)
226 WCHAR sTemp[MAX_PATH];
229 if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
231 if (dwType == REG_EXPAND_SZ)
233 ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
234 lstrcpynW(szDest, sTemp, len);
236 if (ParseFieldW (szDest, 2, sNum, 5))
237 *picon_idx = atoiW(sNum);
239 *picon_idx=0; /* sometimes the icon number is missing */
240 ParseFieldW (szDest, 1, szDest, len);
241 PathUnquoteSpacesW(szDest);
247 static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, int* picon_idx)
250 char sTemp[MAX_PATH];
253 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
255 if (dwType == REG_EXPAND_SZ)
257 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
258 lstrcpynA(szDest, sTemp, len);
260 if (ParseFieldA (szDest, 2, sNum, 5))
261 *picon_idx=atoi(sNum);
263 *picon_idx=0; /* sometimes the icon number is missing */
264 ParseFieldA (szDest, 1, szDest, len);
265 PathUnquoteSpacesA(szDest);
271 BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, int* picon_idx)
273 static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0};
275 WCHAR sTemp[MAX_PATH];
278 TRACE("%s\n",debugstr_w(szClass) );
280 lstrcpynW(sTemp, szClass, MAX_PATH);
281 lstrcatW(sTemp, swDefaultIcon);
283 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
285 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx);
290 TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx);
292 TRACE("-- not found\n");
297 BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, int* picon_idx)
300 char sTemp[MAX_PATH];
303 TRACE("%s\n",szClass );
305 sprintf(sTemp, "%s\\DefaultIcon",szClass);
307 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
309 ret = HCR_RegGetDefaultIconA(hkey, szDest, len, picon_idx);
312 TRACE("-- %s %i\n", szDest, *picon_idx);
316 BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, int* picon_idx)
321 if (HCR_RegOpenClassIDKey(riid, &hkey))
323 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx);
326 TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx);
330 /***************************************************************************************
331 * HCR_GetClassName [internal]
333 * Gets the name of a registered class
335 static const WCHAR swEmpty[] = {0};
337 BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len)
344 if (HCR_RegOpenClassIDKey(riid, &hkey))
346 static const WCHAR wszLocalizedString[] =
347 { 'L','o','c','a','l','i','z','e','d','S','t','r','i','n','g', 0 };
348 if (!RegLoadMUIStringW(hkey, wszLocalizedString, szDest, len, NULL, 0, NULL) ||
349 !RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len))
356 if (!ret || !szDest[0])
358 if(IsEqualIID(riid, &CLSID_ShellDesktop))
360 if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
363 else if (IsEqualIID(riid, &CLSID_MyComputer))
365 if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
369 TRACE("-- %s\n", debugstr_w(szDest));
373 BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
379 if (HCR_RegOpenClassIDKey(riid, &hkey))
381 if (!RegLoadMUIStringA(hkey,"LocalizedString",szDest,len,NULL,0,NULL) ||
382 !RegQueryValueExA(hkey,"",0,NULL,(LPBYTE)szDest,&len))
389 if (!ret || !szDest[0])
391 if(IsEqualIID(riid, &CLSID_ShellDesktop))
393 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
396 else if (IsEqualIID(riid, &CLSID_MyComputer))
398 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
403 TRACE("-- %s\n", szDest);
408 /******************************************************************************
409 * HCR_GetFolderAttributes [Internal]
411 * Query the registry for a shell folders' attributes
414 * pidlFolder [I] A simple pidl of type PT_GUID.
415 * pdwAttributes [IO] In: Attributes to be queried, OUT: Resulting attributes.
418 * TRUE: Found information for the attributes in the registry
419 * FALSE: No attribute information found
422 * If queried for an attribute, which is set in the CallForAttributes registry
423 * value, the function binds to the shellfolder objects and queries it.
425 BOOL HCR_GetFolderAttributes(LPCITEMIDLIST pidlFolder, LPDWORD pdwAttributes)
431 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
432 static const WCHAR wszCallForAttributes[] = {
433 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
434 WCHAR wszShellFolderKey[] = { 'C','L','S','I','D','\\','{','0','0','0','2','1','4','0','0','-',
435 '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-','0','0','0','0','0','0','0',
436 '0','0','0','4','6','}','\\','S','h','e','l','l','F','o','l','d','e','r',0 };
438 TRACE("(pidlFolder=%p, pdwAttributes=%p)\n", pidlFolder, pdwAttributes);
440 if (!_ILIsPidlSimple(pidlFolder)) {
441 ERR("HCR_GetFolderAttributes should be called for simple PIDL's only!\n");
445 if (!_ILIsDesktop(pidlFolder)) {
446 if (FAILED(StringFromCLSID(_ILGetGUIDPointer(pidlFolder), &pwszCLSID))) return FALSE;
447 memcpy(&wszShellFolderKey[6], pwszCLSID, 38 * sizeof(WCHAR));
448 CoTaskMemFree(pwszCLSID);
451 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszShellFolderKey, 0, KEY_READ, &hSFKey);
452 if (lResult != ERROR_SUCCESS) return FALSE;
454 dwLen = sizeof(DWORD);
455 lResult = RegQueryValueExW(hSFKey, wszCallForAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen);
456 if ((lResult == ERROR_SUCCESS) && (dwTemp & *pdwAttributes)) {
457 LPSHELLFOLDER psfDesktop, psfFolder;
461 hr = SHGetDesktopFolder(&psfDesktop);
463 hr = IShellFolder_BindToObject(psfDesktop, pidlFolder, NULL, &IID_IShellFolder,
464 (LPVOID*)&psfFolder);
466 hr = IShellFolder_GetAttributesOf(psfFolder, 0, NULL, pdwAttributes);
467 IShellFolder_Release(psfFolder);
469 IShellFolder_Release(psfDesktop);
471 if (FAILED(hr)) return FALSE;
473 lResult = RegQueryValueExW(hSFKey, wszAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen);
475 if (lResult == ERROR_SUCCESS) {
476 *pdwAttributes &= dwTemp;
482 TRACE("-- *pdwAttributes == 0x%08x\n", *pdwAttributes);