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, int* picon_idx)
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))
181 *picon_idx = atoiW(sNum);
183 *picon_idx=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, int* picon_idx)
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))
205 *picon_idx=atoi(sNum);
207 *picon_idx=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, int* picon_idx)
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, picon_idx);
234 TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx);
236 TRACE("-- not found\n");
241 BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, int* picon_idx)
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, picon_idx);
256 TRACE("-- %s %i\n", szDest, *picon_idx);
260 BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, int* picon_idx)
265 if (HCR_RegOpenClassIDKey(riid, &hkey))
267 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, picon_idx);
270 TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx);
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 static const WCHAR wszLocalizedString[] =
291 { 'L','o','c','a','l','i','z','e','d','S','t','r','i','n','g', 0 };
292 if (!RegLoadMUIStringW(hkey, wszLocalizedString, szDest, len, NULL, 0, NULL) ||
293 !RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len))
300 if (!ret || !szDest[0])
302 if(IsEqualIID(riid, &CLSID_ShellDesktop))
304 if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
307 else if (IsEqualIID(riid, &CLSID_MyComputer))
309 if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
313 TRACE("-- %s\n", debugstr_w(szDest));
317 BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
323 if (HCR_RegOpenClassIDKey(riid, &hkey))
325 if (!RegLoadMUIStringA(hkey,"LocalizedString",szDest,len,NULL,0,NULL) ||
326 !RegQueryValueExA(hkey,"",0,NULL,(LPBYTE)szDest,&len))
333 if (!ret || !szDest[0])
335 if(IsEqualIID(riid, &CLSID_ShellDesktop))
337 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
340 else if (IsEqualIID(riid, &CLSID_MyComputer))
342 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
347 TRACE("-- %s\n", szDest);
352 /******************************************************************************
353 * HCR_GetFolderAttributes [Internal]
355 * Query the registry for a shell folders' attributes
358 * pidlFolder [I] A simple pidl of type PT_GUID.
359 * pdwAttributes [IO] In: Attributes to be queried, OUT: Resulting attributes.
362 * TRUE: Found information for the attributes in the registry
363 * FALSE: No attribute information found
366 * If queried for an attribute, which is set in the CallForAttributes registry
367 * value, the function binds to the shellfolder objects and queries it.
369 BOOL HCR_GetFolderAttributes(LPCITEMIDLIST pidlFolder, LPDWORD pdwAttributes)
375 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
376 static const WCHAR wszCallForAttributes[] = {
377 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
378 WCHAR wszShellFolderKey[] = { 'C','L','S','I','D','\\','{','0','0','0','2','1','4','0','0','-',
379 '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-','0','0','0','0','0','0','0',
380 '0','0','0','4','6','}','\\','S','h','e','l','l','F','o','l','d','e','r',0 };
382 TRACE("(pidlFolder=%p, pdwAttributes=%p)\n", pidlFolder, pdwAttributes);
384 if (!_ILIsPidlSimple(pidlFolder)) {
385 ERR("HCR_GetFolderAttributes should be called for simple PIDL's only!\n");
389 if (!_ILIsDesktop(pidlFolder)) {
390 if (FAILED(StringFromCLSID(_ILGetGUIDPointer(pidlFolder), &pwszCLSID))) return FALSE;
391 memcpy(&wszShellFolderKey[6], pwszCLSID, 38 * sizeof(WCHAR));
392 CoTaskMemFree(pwszCLSID);
395 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszShellFolderKey, 0, KEY_READ, &hSFKey);
396 if (lResult != ERROR_SUCCESS) return FALSE;
398 dwLen = sizeof(DWORD);
399 lResult = RegQueryValueExW(hSFKey, wszCallForAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen);
400 if ((lResult == ERROR_SUCCESS) && (dwTemp & *pdwAttributes)) {
401 LPSHELLFOLDER psfDesktop, psfFolder;
405 hr = SHGetDesktopFolder(&psfDesktop);
407 hr = IShellFolder_BindToObject(psfDesktop, pidlFolder, NULL, &IID_IShellFolder,
408 (LPVOID*)&psfFolder);
410 hr = IShellFolder_GetAttributesOf(psfFolder, 0, NULL, pdwAttributes);
411 IShellFolder_Release(psfFolder);
413 IShellFolder_Release(psfDesktop);
415 if (FAILED(hr)) return FALSE;
417 lResult = RegQueryValueExW(hSFKey, wszAttributes, 0, NULL, (LPBYTE)&dwTemp, &dwLen);
419 if (lResult == ERROR_SUCCESS) {
420 *pdwAttributes &= dwTemp;
426 TRACE("-- *pdwAttributes == 0x%08lx\n", *pdwAttributes);