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"
29 #include "wine/debug.h"
38 #include "shell32_main.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shell);
46 #define MAX_EXTENSION_LENGTH 20
48 BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, DWORD len, BOOL bPrependDot)
51 WCHAR szTemp[MAX_EXTENSION_LENGTH + 2];
53 TRACE("%s %p\n", debugstr_w(szExtension), debugstr_w(szFileType));
55 /* added because we do not want to have double dots */
56 if (szExtension[0] == '.')
62 lstrcpynW(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
64 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
69 if (RegQueryValueW(hkey, NULL, szFileType, &len))
77 TRACE("--UE;\n} %s\n", debugstr_w(szFileType));
82 BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
85 char szTemp[MAX_EXTENSION_LENGTH + 2];
87 TRACE("%s %p\n", szExtension, szFileType);
89 /* added because we do not want to have double dots */
90 if (szExtension[0] == '.')
96 lstrcpynA(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
98 if (RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
103 if (RegQueryValueA(hkey, NULL, szFileType, &len))
111 TRACE("--UE;\n} %s\n", szFileType);
117 BOOL HCR_GetExecuteCommandW(LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
119 static const WCHAR swShell[] = {'\\','s','h','e','l','l','\\',0};
120 static const WCHAR swCommand[] = {'\\','c','o','m','m','a','n','d',0};
121 WCHAR sTemp[MAX_PATH];
123 TRACE("%s %s %p\n",debugstr_w(szClass), debugstr_w(szVerb), szDest);
125 lstrcpyW(sTemp, szClass);
126 lstrcatW(sTemp, swShell);
127 lstrcatW(sTemp, szVerb);
128 lstrcatW(sTemp, swCommand);
130 if (ERROR_SUCCESS == SHGetValueW(HKEY_CLASSES_ROOT, sTemp, NULL, NULL, szDest, &len)) {
131 TRACE("-- %s\n", debugstr_w(szDest) );
137 BOOL HCR_GetExecuteCommandA(LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len)
139 char sTemp[MAX_PATH];
141 TRACE("%s %s\n",szClass, szVerb );
143 snprintf(sTemp, MAX_PATH, "%s\\shell\\%s\\command",szClass, szVerb);
145 if (ERROR_SUCCESS == SHGetValueA(HKEY_CLASSES_ROOT, sTemp, NULL, NULL, szDest, &len)) {
146 TRACE("-- %s\n", debugstr_a(szDest) );
152 BOOL HCR_GetExecuteCommandEx( HKEY hkeyClass, LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
156 TRACE("%p %s %s\n", hkeyClass, szClass, szVerb );
159 RegOpenKeyExA(hkeyClass,szClass,0,0x02000000,&hkeyClass);
163 char sTemp[MAX_PATH];
165 snprintf(sTemp, MAX_PATH, "shell\\%s\\command", szVerb);
167 ret = (ERROR_SUCCESS == SHGetValueA(hkeyClass, sTemp, NULL, NULL, szDest, &len));
170 RegCloseKey(hkeyClass);
173 TRACE("-- %s\n", szDest );
177 /***************************************************************************************
178 * HCR_GetDefaultIcon [internal]
180 * Gets the icon for a filetype
182 static BOOL HCR_RegOpenClassIDKey(REFIID riid, HKEY *hkey)
185 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
186 riid->Data1, riid->Data2, riid->Data3,
187 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
188 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
190 TRACE("%s\n",xriid );
192 return !RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey);
195 static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, LPDWORD dwNr)
198 WCHAR sTemp[MAX_PATH];
201 if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
203 if (dwType == REG_EXPAND_SZ)
205 ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
206 lstrcpynW(szDest, sTemp, len);
208 if (ParseFieldW (szDest, 2, sNum, 5))
211 *dwNr=0; /* sometimes the icon number is missing */
212 ParseFieldW (szDest, 1, szDest, len);
218 static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, LPDWORD dwNr)
221 char sTemp[MAX_PATH];
224 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
226 if (dwType == REG_EXPAND_SZ)
228 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
229 lstrcpynA(szDest, sTemp, len);
231 if (ParseFieldA (szDest, 2, sNum, 5))
234 *dwNr=0; /* sometimes the icon number is missing */
235 ParseFieldA (szDest, 1, szDest, len);
241 BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr)
243 static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0};
245 WCHAR sTemp[MAX_PATH];
248 TRACE("%s\n",debugstr_w(szClass) );
250 lstrcpynW(sTemp, szClass, MAX_PATH);
251 lstrcatW(sTemp, swDefaultIcon);
253 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
255 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
258 TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
262 BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
265 char sTemp[MAX_PATH];
268 TRACE("%s\n",szClass );
270 sprintf(sTemp, "%s\\DefaultIcon",szClass);
272 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
274 ret = HCR_RegGetDefaultIconA(hkey, szDest, len, dwNr);
277 TRACE("-- %s %li\n", szDest, *dwNr );
281 BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr)
286 if (HCR_RegOpenClassIDKey(riid, &hkey))
288 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
291 TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
295 /***************************************************************************************
296 * HCR_GetClassName [internal]
298 * Gets the name of a registred class
300 static WCHAR swEmpty[] = {0};
302 BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len)
309 if (HCR_RegOpenClassIDKey(riid, &hkey))
311 if (!RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len))
318 if (!ret || !szDest[0])
320 if(IsEqualIID(riid, &CLSID_ShellDesktop))
322 if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
325 else if (IsEqualIID(riid, &CLSID_MyComputer))
327 if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
331 TRACE("-- %s\n", debugstr_w(szDest));
335 BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
341 if (HCR_RegOpenClassIDKey(riid, &hkey))
343 if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
350 if (!ret || !szDest[0])
352 if(IsEqualIID(riid, &CLSID_ShellDesktop))
354 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
357 else if (IsEqualIID(riid, &CLSID_MyComputer))
359 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
364 TRACE("-- %s\n", szDest);
369 /***************************************************************************************
370 * HCR_GetFolderAttributes [internal]
372 * gets the folder attributes of a class
375 * verify the defaultvalue for *szDest
377 BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest)
383 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
384 riid->Data1, riid->Data2, riid->Data3,
385 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
386 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
387 TRACE("%s\n",xriid );
389 if (!szDest) return FALSE;
390 *szDest = SFGAO_FOLDER|SFGAO_FILESYSTEM;
392 strcat (xriid, "\\ShellFolder");
394 if (RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
399 if (RegQueryValueExA(hkey,"Attributes",0,NULL,(LPBYTE)&attributes,&len))
407 TRACE("-- 0x%08lx\n", attributes);
409 *szDest = attributes;