Make the Wine trace facilities accessible from Winelib applications.
[wine/gsoc_dplay.git] / dlls / shell32 / classes.c
blob2da88058c26d525d67bb7e72d677c161b7a58bd7
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 /* added because we do not want to have double dots */
31 if (szExtension[0]=='.')
32 bPrependDot=0;
34 if (bPrependDot)
35 strcpy(szTemp, ".");
37 lstrcpynA(szTemp+((bPrependDot)?1:0), szExtension, MAX_EXTENSION_LENGTH);
39 if (RegOpenKeyExA(HKEY_CLASSES_ROOT,szTemp,0,0x02000000,&hkey))
40 { return FALSE;
43 if (RegQueryValueA(hkey,NULL,szFileType,&len))
44 { RegCloseKey(hkey);
45 return FALSE;
48 RegCloseKey(hkey);
50 TRACE("-- %s\n", szFileType );
52 return TRUE;
54 BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
56 HKEY hkey;
57 char sTemp[MAX_PATH];
58 DWORD dwType;
59 BOOL ret = FALSE;
61 TRACE("%s %s\n",szClass, szVerb );
63 sprintf(sTemp, "%s\\shell\\%s\\command",szClass, szVerb);
65 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
67 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
69 if (dwType == REG_EXPAND_SZ)
71 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
72 strcpy(szDest, sTemp);
74 ret = TRUE;
76 RegCloseKey(hkey);
78 TRACE("-- %s\n", szDest );
79 return ret;
81 /***************************************************************************************
82 * HCR_GetDefaultIcon [internal]
84 * Gets the icon for a filetype
86 BOOL HCR_GetDefaultIcon (LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
88 HKEY hkey;
89 char sTemp[MAX_PATH];
90 char sNum[5];
91 DWORD dwType;
92 BOOL ret = FALSE;
94 TRACE("%s\n",szClass );
96 sprintf(sTemp, "%s\\DefaultIcon",szClass);
98 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
100 if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
102 if (dwType == REG_EXPAND_SZ)
104 ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
105 strcpy(szDest, sTemp);
107 if (ParseFieldA (szDest, 2, sNum, 5)) *dwNr=atoi(sNum);
108 ParseFieldA (szDest, 1, szDest, len);
109 ret = TRUE;
111 RegCloseKey(hkey);
113 TRACE("-- %s %li\n", szDest, *dwNr );
114 return ret;
117 /***************************************************************************************
118 * HCR_GetClassName [internal]
120 * Gets the name of a registred class
122 BOOL HCR_GetClassName (REFIID riid, LPSTR szDest, DWORD len)
123 { HKEY hkey;
124 char xriid[50];
125 BOOL ret = FALSE;
126 DWORD buflen = len;
128 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
129 riid->Data1, riid->Data2, riid->Data3,
130 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
131 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
133 TRACE("%s\n",xriid );
135 szDest[0] = 0;
136 if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
138 if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
140 ret = TRUE;
142 RegCloseKey(hkey);
145 if (!ret || !szDest[0])
147 if(IsEqualIID(riid, &CLSID_ShellDesktop))
149 if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
150 ret = TRUE;
152 else if (IsEqualIID(riid, &CLSID_MyComputer))
154 if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
155 ret = TRUE;
159 TRACE("-- %s\n", szDest);
161 return ret;
164 /***************************************************************************************
165 * HCR_GetFolderAttributes [internal]
167 * gets the folder attributes of a class
169 * FIXME
170 * verify the defaultvalue for *szDest
172 BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest)
173 { HKEY hkey;
174 char xriid[60];
175 DWORD attributes;
176 DWORD len = 4;
178 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
179 riid->Data1, riid->Data2, riid->Data3,
180 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
181 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
182 TRACE("%s\n",xriid );
184 if (!szDest) return FALSE;
185 *szDest = SFGAO_FOLDER|SFGAO_FILESYSTEM;
187 strcat (xriid, "\\ShellFolder");
189 if (RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
191 return FALSE;
194 if (RegQueryValueExA(hkey,"Attributes",0,NULL,(LPBYTE)&attributes,&len))
196 RegCloseKey(hkey);
197 return FALSE;
200 RegCloseKey(hkey);
202 TRACE("-- 0x%08lx\n", attributes);
204 *szDest = attributes;
206 return TRUE;
209 typedef struct
210 { ICOM_VFIELD(IQueryAssociations);
211 DWORD ref;
212 } IQueryAssociationsImpl;
214 static struct ICOM_VTABLE(IQueryAssociations) qavt;
216 /**************************************************************************
217 * IQueryAssociations_Constructor
219 IQueryAssociations* IQueryAssociations_Constructor(void)
221 IQueryAssociationsImpl* ei;
223 ei=(IQueryAssociationsImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
224 ei->ref=1;
225 ICOM_VTBL(ei) = &qavt;
227 TRACE("(%p)\n",ei);
228 shell32_ObjCount++;
229 return (IQueryAssociations *)ei;
231 /**************************************************************************
232 * IQueryAssociations_QueryInterface
234 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
235 IQueryAssociations * iface,
236 REFIID riid,
237 LPVOID *ppvObj)
239 ICOM_THIS(IQueryAssociationsImpl,iface);
241 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
243 *ppvObj = NULL;
245 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
247 *ppvObj = This;
249 else if(IsEqualIID(riid, &IID_IQueryAssociations)) /*IExtractIcon*/
251 *ppvObj = (IQueryAssociations*)This;
254 if(*ppvObj)
256 IQueryAssociations_AddRef((IQueryAssociations*) *ppvObj);
257 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
258 return S_OK;
260 TRACE("-- Interface: E_NOINTERFACE\n");
261 return E_NOINTERFACE;
264 /**************************************************************************
265 * IQueryAssociations_AddRef
267 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations * iface)
269 ICOM_THIS(IQueryAssociationsImpl,iface);
271 TRACE("(%p)->(count=%lu)\n",This, This->ref );
273 shell32_ObjCount++;
275 return ++(This->ref);
277 /**************************************************************************
278 * IQueryAssociations_Release
280 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations * iface)
282 ICOM_THIS(IQueryAssociationsImpl,iface);
284 TRACE("(%p)->()\n",This);
286 shell32_ObjCount--;
288 if (!--(This->ref))
290 TRACE(" destroying IExtractIcon(%p)\n",This);
291 HeapFree(GetProcessHeap(),0,This);
292 return 0;
294 return This->ref;
297 static HRESULT WINAPI IQueryAssociations_fnInit(
298 IQueryAssociations * iface,
299 ASSOCF flags,
300 LPCWSTR pszAssoc,
301 HKEY hkProgid,
302 HWND hwnd)
304 return E_NOTIMPL;
307 static HRESULT WINAPI IQueryAssociations_fnGetString(
308 IQueryAssociations * iface,
309 ASSOCF flags,
310 ASSOCSTR str,
311 LPCWSTR pszExtra,
312 LPWSTR pszOut,
313 DWORD *pcchOut)
315 return E_NOTIMPL;
318 static HRESULT WINAPI IQueryAssociations_fnGetKey(
319 IQueryAssociations * iface,
320 ASSOCF flags,
321 ASSOCKEY key,
322 LPCWSTR pszExtra,
323 HKEY *phkeyOut)
325 return E_NOTIMPL;
328 static HRESULT WINAPI IQueryAssociations_fnGetData(
329 IQueryAssociations * iface,
330 ASSOCF flags,
331 ASSOCDATA data,
332 LPCWSTR pszExtra,
333 LPVOID pvOut,
334 DWORD *pcbOut)
336 return E_NOTIMPL;
338 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
339 IQueryAssociations * iface,
340 ASSOCF flags,
341 ASSOCENUM assocenum,
342 LPCWSTR pszExtra,
343 REFIID riid,
344 LPVOID *ppvOut)
346 return E_NOTIMPL;
349 static struct ICOM_VTABLE(IQueryAssociations) qavt =
351 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
352 IQueryAssociations_fnQueryInterface,
353 IQueryAssociations_fnAddRef,
354 IQueryAssociations_fnRelease,
355 IQueryAssociations_fnInit,
356 IQueryAssociations_fnGetString,
357 IQueryAssociations_fnGetKey,
358 IQueryAssociations_fnGetData,
359 IQueryAssociations_fnGetEnum