Removed shell.h. Cleaned up the nested includes mess in wine/obj_*.h.
[wine.git] / dlls / shell32 / classes.c
blob85cfd591a4e97af517a3d2be9886ff2041081e52
1 /*
2 * file type mapping
3 * (HKEY_CLASSES_ROOT - Stuff)
6 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include "debugtools.h"
11 #include "winerror.h"
12 #include "winreg.h"
14 #include "shlobj.h"
15 #include "shell32_main.h"
16 #include "shlguid.h"
17 #include "shresdef.h"
18 #include "wine/obj_queryassociations.h"
20 DEFAULT_DEBUG_CHANNEL(shell);
22 #define MAX_EXTENSION_LENGTH 20
24 BOOL HCR_MapTypeToValue ( LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
25 { HKEY hkey;
26 char szTemp[MAX_EXTENSION_LENGTH + 2];
28 TRACE("%s %p\n",szExtension, szFileType );
30 if (bPrependDot)
31 strcpy(szTemp, ".");
33 lstrcpynA(szTemp+((bPrependDot)?1:0), szExtension, MAX_EXTENSION_LENGTH);
35 if (RegOpenKeyExA(HKEY_CLASSES_ROOT,szTemp,0,0x02000000,&hkey))
36 { return FALSE;
39 if (RegQueryValueA(hkey,NULL,szFileType,&len))
40 { RegCloseKey(hkey);
41 return FALSE;
44 RegCloseKey(hkey);
46 TRACE("-- %s\n", szFileType );
48 return TRUE;
50 BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
52 HKEY hkey;
53 char sTemp[MAX_PATH];
54 DWORD dwType;
55 BOOL ret = FALSE;
57 TRACE("%s %s\n",szClass, szVerb );
59 sprintf(sTemp, "%s\\shell\\%s\\command",szClass, szVerb);
61 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
63 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
65 if (dwType == REG_EXPAND_SZ)
67 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
68 strcpy(szDest, sTemp);
70 ret = TRUE;
72 RegCloseKey(hkey);
74 TRACE("-- %s\n", szDest );
75 return ret;
77 /***************************************************************************************
78 * HCR_GetDefaultIcon [internal]
80 * Gets the icon for a filetype
82 BOOL HCR_GetDefaultIcon (LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
84 HKEY hkey;
85 char sTemp[MAX_PATH];
86 char sNum[5];
87 DWORD dwType;
88 BOOL ret = FALSE;
90 TRACE("%s\n",szClass );
92 sprintf(sTemp, "%s\\DefaultIcon",szClass);
94 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
96 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
98 if (dwType == REG_EXPAND_SZ)
100 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
101 strcpy(szDest, sTemp);
103 if (ParseFieldA (szDest, 2, sNum, 5)) *dwNr=atoi(sNum);
104 ParseFieldA (szDest, 1, szDest, len);
105 ret = TRUE;
107 RegCloseKey(hkey);
109 TRACE("-- %s %li\n", szDest, *dwNr );
110 return ret;
113 /***************************************************************************************
114 * HCR_GetClassName [internal]
116 * Gets the name of a registred class
118 BOOL HCR_GetClassName (REFIID riid, LPSTR szDest, DWORD len)
119 { HKEY hkey;
120 char xriid[50];
121 BOOL ret = FALSE;
122 DWORD buflen = len;
124 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
125 riid->Data1, riid->Data2, riid->Data3,
126 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
127 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
129 TRACE("%s\n",xriid );
131 szDest[0] = 0;
132 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
134 if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
136 ret = TRUE;
138 RegCloseKey(hkey);
141 if (!ret || !szDest[0])
143 if(IsEqualIID(riid, &CLSID_ShellDesktop))
145 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
146 ret = TRUE;
148 else if (IsEqualIID(riid, &CLSID_MyComputer))
150 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
151 ret = TRUE;
155 TRACE("-- %s\n", szDest);
157 return ret;
160 /***************************************************************************************
161 * HCR_GetFolderAttributes [internal]
163 * gets the folder attributes of a class
165 * FIXME
166 * verify the defaultvalue for *szDest
168 BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest)
169 { HKEY hkey;
170 char xriid[60];
171 DWORD attributes;
172 DWORD len = 4;
174 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
175 riid->Data1, riid->Data2, riid->Data3,
176 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
177 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
178 TRACE("%s\n",xriid );
180 if (!szDest) return FALSE;
181 *szDest = SFGAO_FOLDER|SFGAO_FILESYSTEM;
183 strcat (xriid, "\\ShellFolder");
185 if (RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
187 return FALSE;
190 if (RegQueryValueExA(hkey,"Attributes",0,NULL,(LPBYTE)&attributes,&len))
192 RegCloseKey(hkey);
193 return FALSE;
196 RegCloseKey(hkey);
198 TRACE("-- 0x%08lx\n", attributes);
200 *szDest = attributes;
202 return TRUE;
205 typedef struct
206 { ICOM_VFIELD(IQueryAssociations);
207 DWORD ref;
208 } IQueryAssociationsImpl;
210 static struct ICOM_VTABLE(IQueryAssociations) qavt;
212 /**************************************************************************
213 * IQueryAssociations_Constructor
215 IQueryAssociations* IQueryAssociations_Constructor(void)
217 IQueryAssociationsImpl* ei;
219 ei=(IQueryAssociationsImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
220 ei->ref=1;
221 ICOM_VTBL(ei) = &qavt;
223 TRACE("(%p)\n",ei);
224 shell32_ObjCount++;
225 return (IQueryAssociations *)ei;
227 /**************************************************************************
228 * IQueryAssociations_QueryInterface
230 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
231 IQueryAssociations * iface,
232 REFIID riid,
233 LPVOID *ppvObj)
235 ICOM_THIS(IQueryAssociationsImpl,iface);
237 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
239 *ppvObj = NULL;
241 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
243 *ppvObj = This;
245 else if(IsEqualIID(riid, &IID_IQueryAssociations)) /*IExtractIcon*/
247 *ppvObj = (IQueryAssociations*)This;
250 if(*ppvObj)
252 IQueryAssociations_AddRef((IQueryAssociations*) *ppvObj);
253 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
254 return S_OK;
256 TRACE("-- Interface: E_NOINTERFACE\n");
257 return E_NOINTERFACE;
260 /**************************************************************************
261 * IQueryAssociations_AddRef
263 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations * iface)
265 ICOM_THIS(IQueryAssociationsImpl,iface);
267 TRACE("(%p)->(count=%lu)\n",This, This->ref );
269 shell32_ObjCount++;
271 return ++(This->ref);
273 /**************************************************************************
274 * IQueryAssociations_Release
276 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations * iface)
278 ICOM_THIS(IQueryAssociationsImpl,iface);
280 TRACE("(%p)->()\n",This);
282 shell32_ObjCount--;
284 if (!--(This->ref))
286 TRACE(" destroying IExtractIcon(%p)\n",This);
287 HeapFree(GetProcessHeap(),0,This);
288 return 0;
290 return This->ref;
293 static HRESULT WINAPI IQueryAssociations_fnInit(
294 IQueryAssociations * iface,
295 ASSOCF flags,
296 LPCWSTR pszAssoc,
297 HKEY hkProgid,
298 HWND hwnd)
300 return E_NOTIMPL;
303 static HRESULT WINAPI IQueryAssociations_fnGetString(
304 IQueryAssociations * iface,
305 ASSOCF flags,
306 ASSOCSTR str,
307 LPCWSTR pszExtra,
308 LPWSTR pszOut,
309 DWORD *pcchOut)
311 return E_NOTIMPL;
314 static HRESULT WINAPI IQueryAssociations_fnGetKey(
315 IQueryAssociations * iface,
316 ASSOCF flags,
317 ASSOCKEY key,
318 LPCWSTR pszExtra,
319 HKEY *phkeyOut)
321 return E_NOTIMPL;
324 static HRESULT WINAPI IQueryAssociations_fnGetData(
325 IQueryAssociations * iface,
326 ASSOCF flags,
327 ASSOCDATA data,
328 LPCWSTR pszExtra,
329 LPVOID pvOut,
330 DWORD *pcbOut)
332 return E_NOTIMPL;
334 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
335 IQueryAssociations * iface,
336 ASSOCF flags,
337 ASSOCENUM assocenum,
338 LPCWSTR pszExtra,
339 REFIID riid,
340 LPVOID *ppvOut)
342 return E_NOTIMPL;
345 static struct ICOM_VTABLE(IQueryAssociations) qavt =
347 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
348 IQueryAssociations_fnQueryInterface,
349 IQueryAssociations_fnAddRef,
350 IQueryAssociations_fnRelease,
351 IQueryAssociations_fnInit,
352 IQueryAssociations_fnGetString,
353 IQueryAssociations_fnGetKey,
354 IQueryAssociations_fnGetData,
355 IQueryAssociations_fnGetEnum