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"
28 #include "wine/debug.h"
33 #include "shell32_main.h"
37 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 #define MAX_EXTENSION_LENGTH 20
43 BOOL HCR_MapTypeToValueW(LPCWSTR szExtension, LPWSTR szFileType, DWORD len, BOOL bPrependDot)
46 WCHAR szTemp[MAX_EXTENSION_LENGTH + 2];
48 TRACE("%s %p\n", debugstr_w(szExtension), debugstr_w(szFileType));
50 /* added because we do not want to have double dots */
51 if (szExtension[0] == '.')
57 lstrcpynW(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
59 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
64 if (RegQueryValueW(hkey, NULL, szFileType, &len))
72 TRACE("--UE;\n} %s\n", debugstr_w(szFileType));
77 BOOL HCR_MapTypeToValueA(LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
80 char szTemp[MAX_EXTENSION_LENGTH + 2];
82 TRACE("%s %p\n", szExtension, szFileType);
84 /* added because we do not want to have double dots */
85 if (szExtension[0] == '.')
91 lstrcpynA(szTemp + (bPrependDot?1:0), szExtension, MAX_EXTENSION_LENGTH);
93 if (RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, 0x02000000, &hkey))
98 if (RegQueryValueA(hkey, NULL, szFileType, &len))
106 TRACE("--UE;\n} %s\n", szFileType);
112 BOOL HCR_GetExecuteCommandW(LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
114 static const WCHAR swShell[] = {'\\','s','h','e','l','l','\\',0};
115 static const WCHAR swCommand[] = {'\\','c','o','m','m','a','n','d',0};
116 WCHAR sTemp[MAX_PATH];
118 TRACE("%s %s %p\n",debugstr_w(szClass), debugstr_w(szVerb), szDest);
120 lstrcpyW(sTemp, szClass);
121 lstrcatW(sTemp, swShell);
122 lstrcatW(sTemp, szVerb);
123 lstrcatW(sTemp, swCommand);
125 if (ERROR_SUCCESS == SHGetValueW(HKEY_CLASSES_ROOT, sTemp, NULL, NULL, szDest, &len)) {
126 TRACE("-- %s\n", debugstr_w(szDest) );
132 BOOL HCR_GetExecuteCommandA(LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len)
134 char sTemp[MAX_PATH];
136 TRACE("%s %s\n",szClass, szVerb );
138 snprintf(sTemp, MAX_PATH, "%s\\shell\\%s\\command",szClass, szVerb);
140 if (ERROR_SUCCESS == SHGetValueA(HKEY_CLASSES_ROOT, sTemp, NULL, NULL, szDest, &len)) {
141 TRACE("-- %s\n", debugstr_a(szDest) );
147 BOOL HCR_GetExecuteCommandEx( HKEY hkeyClass, LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
151 TRACE("%p %s %s\n", hkeyClass, szClass, szVerb );
154 RegOpenKeyExA(hkeyClass,szClass,0,0x02000000,&hkeyClass);
158 char sTemp[MAX_PATH];
160 snprintf(sTemp, MAX_PATH, "shell\\%s\\command", szVerb);
162 ret = (ERROR_SUCCESS == SHGetValueA(hkeyClass, sTemp, NULL, NULL, szDest, &len));
165 RegCloseKey(hkeyClass);
168 TRACE("-- %s\n", szDest );
172 /***************************************************************************************
173 * HCR_GetDefaultIcon [internal]
175 * Gets the icon for a filetype
177 static BOOL HCR_RegOpenClassIDKey(REFIID riid, HKEY *hkey)
180 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
181 riid->Data1, riid->Data2, riid->Data3,
182 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
183 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
185 TRACE("%s\n",xriid );
187 return !RegOpenKeyExA(HKEY_CLASSES_ROOT, xriid, 0, KEY_READ, hkey);
190 static BOOL HCR_RegGetDefaultIconW(HKEY hkey, LPWSTR szDest, DWORD len, LPDWORD dwNr)
193 WCHAR sTemp[MAX_PATH];
196 if (!RegQueryValueExW(hkey, NULL, 0, &dwType, (LPBYTE)szDest, &len))
198 if (dwType == REG_EXPAND_SZ)
200 ExpandEnvironmentStringsW(szDest, sTemp, MAX_PATH);
201 lstrcpynW(szDest, sTemp, len);
203 if (ParseFieldW (szDest, 2, sNum, 5))
206 *dwNr=0; /* sometimes the icon number is missing */
207 ParseFieldW (szDest, 1, szDest, len);
213 static BOOL HCR_RegGetDefaultIconA(HKEY hkey, LPSTR szDest, DWORD len, LPDWORD dwNr)
216 char sTemp[MAX_PATH];
219 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
221 if (dwType == REG_EXPAND_SZ)
223 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
224 lstrcpynA(szDest, sTemp, len);
226 if (ParseFieldA (szDest, 2, sNum, 5))
229 *dwNr=0; /* sometimes the icon number is missing */
230 ParseFieldA (szDest, 1, szDest, len);
236 BOOL HCR_GetDefaultIconW(LPCWSTR szClass, LPWSTR szDest, DWORD len, LPDWORD dwNr)
238 static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0};
240 WCHAR sTemp[MAX_PATH];
243 TRACE("%s\n",debugstr_w(szClass) );
245 lstrcpynW(sTemp, szClass, MAX_PATH);
246 lstrcatW(sTemp, swDefaultIcon);
248 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
250 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
253 TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
257 BOOL HCR_GetDefaultIconA(LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
260 char sTemp[MAX_PATH];
263 TRACE("%s\n",szClass );
265 sprintf(sTemp, "%s\\DefaultIcon",szClass);
267 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT, sTemp, 0, 0x02000000, &hkey))
269 ret = HCR_RegGetDefaultIconA(hkey, szDest, len, dwNr);
272 TRACE("-- %s %li\n", szDest, *dwNr );
276 BOOL HCR_GetDefaultIconFromGUIDW(REFIID riid, LPWSTR szDest, DWORD len, LPDWORD dwNr)
281 if (HCR_RegOpenClassIDKey(riid, &hkey))
283 ret = HCR_RegGetDefaultIconW(hkey, szDest, len, dwNr);
286 TRACE("-- %s %li\n", debugstr_w(szDest), *dwNr );
290 /***************************************************************************************
291 * HCR_GetClassName [internal]
293 * Gets the name of a registred class
295 static WCHAR swEmpty[] = {0};
297 BOOL HCR_GetClassNameW(REFIID riid, LPWSTR szDest, DWORD len)
304 if (HCR_RegOpenClassIDKey(riid, &hkey))
306 if (!RegQueryValueExW(hkey, swEmpty, 0, NULL, (LPBYTE)szDest, &len))
313 if (!ret || !szDest[0])
315 if(IsEqualIID(riid, &CLSID_ShellDesktop))
317 if (LoadStringW(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
320 else if (IsEqualIID(riid, &CLSID_MyComputer))
322 if(LoadStringW(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
326 TRACE("-- %s\n", debugstr_w(szDest));
330 BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
336 if (HCR_RegOpenClassIDKey(riid, &hkey))
338 if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
345 if (!ret || !szDest[0])
347 if(IsEqualIID(riid, &CLSID_ShellDesktop))
349 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
352 else if (IsEqualIID(riid, &CLSID_MyComputer))
354 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
359 TRACE("-- %s\n", szDest);
364 /***************************************************************************************
365 * HCR_GetFolderAttributes [internal]
367 * gets the folder attributes of a class
370 * verify the defaultvalue for *szDest
372 BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest)
378 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
379 riid->Data1, riid->Data2, riid->Data3,
380 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
381 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
382 TRACE("%s\n",xriid );
384 if (!szDest) return FALSE;
385 *szDest = SFGAO_FOLDER|SFGAO_FILESYSTEM;
387 strcat (xriid, "\\ShellFolder");
389 if (RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
394 if (RegQueryValueExA(hkey,"Attributes",0,NULL,(LPBYTE)&attributes,&len))
402 TRACE("-- 0x%08lx\n", attributes);
404 *szDest = attributes;
410 { ICOM_VFIELD(IQueryAssociations);
412 } IQueryAssociationsImpl;
414 static struct ICOM_VTABLE(IQueryAssociations) qavt;
416 /**************************************************************************
417 * IQueryAssociations_Constructor
419 IQueryAssociations* IQueryAssociations_Constructor(void)
421 IQueryAssociationsImpl* ei;
423 ei=(IQueryAssociationsImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
428 return (IQueryAssociations *)ei;
430 /**************************************************************************
431 * IQueryAssociations_QueryInterface
433 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
434 IQueryAssociations * iface,
438 ICOM_THIS(IQueryAssociationsImpl,iface);
440 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
444 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
448 else if(IsEqualIID(riid, &IID_IQueryAssociations)) /*IExtractIcon*/
450 *ppvObj = (IQueryAssociations*)This;
455 IQueryAssociations_AddRef((IQueryAssociations*) *ppvObj);
456 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
459 TRACE("-- Interface: E_NOINTERFACE\n");
460 return E_NOINTERFACE;
463 /**************************************************************************
464 * IQueryAssociations_AddRef
466 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations * iface)
468 ICOM_THIS(IQueryAssociationsImpl,iface);
470 TRACE("(%p)->(count=%lu)\n",This, This->ref );
472 return ++(This->ref);
474 /**************************************************************************
475 * IQueryAssociations_Release
477 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations * iface)
479 ICOM_THIS(IQueryAssociationsImpl,iface);
481 TRACE("(%p)->()\n",This);
485 TRACE(" destroying IExtractIcon(%p)\n",This);
486 HeapFree(GetProcessHeap(),0,This);
492 static HRESULT WINAPI IQueryAssociations_fnInit(
493 IQueryAssociations * iface,
502 static HRESULT WINAPI IQueryAssociations_fnGetString(
503 IQueryAssociations * iface,
513 static HRESULT WINAPI IQueryAssociations_fnGetKey(
514 IQueryAssociations * iface,
523 static HRESULT WINAPI IQueryAssociations_fnGetData(
524 IQueryAssociations * iface,
533 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
534 IQueryAssociations * iface,
544 static struct ICOM_VTABLE(IQueryAssociations) qavt =
546 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
547 IQueryAssociations_fnQueryInterface,
548 IQueryAssociations_fnAddRef,
549 IQueryAssociations_fnRelease,
550 IQueryAssociations_fnInit,
551 IQueryAssociations_fnGetString,
552 IQueryAssociations_fnGetKey,
553 IQueryAssociations_fnGetData,
554 IQueryAssociations_fnGetEnum