Change the V86BASE macro to call DOSMEM_MemoryBase() instead of using
[wine] / dlls / shell32 / classes.c
1 /*
2  *      file type mapping 
3  *      (HKEY_CLASSES_ROOT - Stuff)
4  *
5  *
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"
13
14 #include "wine/obj_queryassociations.h"
15 #include "shlobj.h"
16 #include "shell32_main.h"
17 #include "shlguid.h"
18 #include "shresdef.h"
19
20 DEFAULT_DEBUG_CHANNEL(shell);
21
22 #define MAX_EXTENSION_LENGTH 20
23
24 BOOL HCR_MapTypeToValue ( LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
25 {       HKEY    hkey;
26         char    szTemp[MAX_EXTENSION_LENGTH + 2];
27
28         TRACE("%s %p\n",szExtension, szFileType );
29
30         if (bPrependDot)
31           strcpy(szTemp, ".");
32
33         lstrcpynA(szTemp+((bPrependDot)?1:0), szExtension, MAX_EXTENSION_LENGTH);
34         
35         if (RegOpenKeyExA(HKEY_CLASSES_ROOT,szTemp,0,0x02000000,&hkey))
36         { return FALSE;
37         }
38
39         if (RegQueryValueA(hkey,NULL,szFileType,&len))
40         { RegCloseKey(hkey);
41           return FALSE;
42         }       
43
44         RegCloseKey(hkey);
45
46         TRACE("-- %s\n", szFileType );
47
48         return TRUE;
49 }
50 BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
51 {
52         HKEY    hkey;
53         char    sTemp[MAX_PATH];
54         DWORD   dwType;
55         BOOL    ret = FALSE;
56         
57         TRACE("%s %s\n",szClass, szVerb );
58
59         sprintf(sTemp, "%s\\shell\\%s\\command",szClass, szVerb);
60
61         if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
62         {
63           if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
64           {
65             if (dwType == REG_EXPAND_SZ)
66             {
67               ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
68               strcpy(szDest, sTemp);
69             }
70             ret = TRUE;
71           }
72           RegCloseKey(hkey);
73         }
74         TRACE("-- %s\n", szDest );
75         return ret;
76 }
77 /***************************************************************************************
78 *       HCR_GetDefaultIcon      [internal]
79 *
80 * Gets the icon for a filetype
81 */
82 BOOL HCR_GetDefaultIcon (LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
83 {
84         HKEY    hkey;
85         char    sTemp[MAX_PATH];
86         char    sNum[5];
87         DWORD   dwType;
88         BOOL    ret = FALSE;
89
90         TRACE("%s\n",szClass );
91
92         sprintf(sTemp, "%s\\DefaultIcon",szClass);
93
94         if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
95         {
96           if (!RegQueryValueExA(hkey, NULL, 0, &dwType, szDest, &len))
97           {
98             if (dwType == REG_EXPAND_SZ)
99             {
100               ExpandEnvironmentStringsA(szDest, sTemp, MAX_PATH);
101               strcpy(szDest, sTemp);
102             }
103             if (ParseFieldA (szDest, 2, sNum, 5)) *dwNr=atoi(sNum);
104             ParseFieldA (szDest, 1, szDest, len);
105             ret = TRUE;
106           }     
107           RegCloseKey(hkey);
108         }
109         TRACE("-- %s %li\n", szDest, *dwNr );
110         return ret;
111 }
112
113 /***************************************************************************************
114 *       HCR_GetClassName        [internal]
115 *
116 * Gets the name of a registred class
117 */
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;
123
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] );
128
129         TRACE("%s\n",xriid );
130
131         szDest[0] = 0;
132         if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
133         {
134           if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
135           {
136             ret = TRUE;
137           }
138           RegCloseKey(hkey);
139         }
140
141         if (!ret || !szDest[0])
142         { 
143           if(IsEqualIID(riid, &CLSID_ShellDesktop))
144           {
145             if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
146               ret = TRUE;
147           }
148           else if (IsEqualIID(riid, &CLSID_MyComputer))
149           {
150             if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
151               ret = TRUE;
152           }     
153         }
154
155         TRACE("-- %s\n", szDest);
156
157         return ret;
158 }
159
160 /***************************************************************************************
161 *       HCR_GetFolderAttributes [internal]
162 *
163 * gets the folder attributes of a class
164 *
165 * FIXME
166 *       verify the defaultvalue for *szDest
167 */
168 BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest)
169 {       HKEY    hkey;
170         char    xriid[60];
171         DWORD   attributes;
172         DWORD   len = 4;
173
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 );
179
180         if (!szDest) return FALSE;
181         *szDest = SFGAO_FOLDER|SFGAO_FILESYSTEM;
182         
183         strcat (xriid, "\\ShellFolder");
184
185         if (RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
186         {
187           return FALSE;
188         }
189
190         if (RegQueryValueExA(hkey,"Attributes",0,NULL,(LPBYTE)&attributes,&len))
191         {
192           RegCloseKey(hkey);
193           return FALSE;
194         }
195
196         RegCloseKey(hkey);
197
198         TRACE("-- 0x%08lx\n", attributes);
199
200         *szDest = attributes;
201
202         return TRUE;
203 }
204
205 typedef struct 
206 {       ICOM_VFIELD(IQueryAssociations);
207         DWORD   ref;
208 } IQueryAssociationsImpl;
209
210 static struct ICOM_VTABLE(IQueryAssociations) qavt;
211
212 /**************************************************************************
213 *  IQueryAssociations_Constructor
214 */
215 IQueryAssociations* IQueryAssociations_Constructor(void)
216 {
217         IQueryAssociationsImpl* ei;
218
219         ei=(IQueryAssociationsImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
220         ei->ref=1;
221         ICOM_VTBL(ei) = &qavt;
222
223         TRACE("(%p)\n",ei);
224         shell32_ObjCount++;
225         return (IQueryAssociations *)ei;
226 }
227 /**************************************************************************
228  *  IQueryAssociations_QueryInterface
229  */
230 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
231         IQueryAssociations * iface,
232         REFIID riid,
233         LPVOID *ppvObj)
234 {
235         ICOM_THIS(IQueryAssociationsImpl,iface);
236
237          TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
238
239         *ppvObj = NULL;
240
241         if(IsEqualIID(riid, &IID_IUnknown))             /*IUnknown*/
242         {
243           *ppvObj = This; 
244         }
245         else if(IsEqualIID(riid, &IID_IQueryAssociations))      /*IExtractIcon*/
246         {
247           *ppvObj = (IQueryAssociations*)This;
248         }
249
250         if(*ppvObj)
251         {
252           IQueryAssociations_AddRef((IQueryAssociations*) *ppvObj);     
253           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
254           return S_OK;
255         }
256         TRACE("-- Interface: E_NOINTERFACE\n");
257         return E_NOINTERFACE;
258 }
259
260 /**************************************************************************
261 *  IQueryAssociations_AddRef
262 */
263 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations * iface)
264 {
265         ICOM_THIS(IQueryAssociationsImpl,iface);
266
267         TRACE("(%p)->(count=%lu)\n",This, This->ref );
268
269         shell32_ObjCount++;
270
271         return ++(This->ref);
272 }
273 /**************************************************************************
274 *  IQueryAssociations_Release
275 */
276 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations * iface)
277 {
278         ICOM_THIS(IQueryAssociationsImpl,iface);
279
280         TRACE("(%p)->()\n",This);
281
282         shell32_ObjCount--;
283
284         if (!--(This->ref)) 
285         {
286           TRACE(" destroying IExtractIcon(%p)\n",This);
287           HeapFree(GetProcessHeap(),0,This);
288           return 0;
289         }
290         return This->ref;
291 }
292
293 static HRESULT WINAPI IQueryAssociations_fnInit(
294         IQueryAssociations * iface,
295         ASSOCF flags,
296         LPCWSTR pszAssoc,
297         HKEY hkProgid,
298         HWND hwnd)
299 {
300         return E_NOTIMPL;
301 }
302
303 static HRESULT WINAPI IQueryAssociations_fnGetString(
304         IQueryAssociations * iface,
305         ASSOCF flags,
306         ASSOCSTR str,
307         LPCWSTR pszExtra,
308         LPWSTR pszOut,
309         DWORD *pcchOut)
310 {
311         return E_NOTIMPL;
312 }
313
314 static HRESULT WINAPI IQueryAssociations_fnGetKey(
315         IQueryAssociations * iface,
316         ASSOCF flags,
317         ASSOCKEY key,
318         LPCWSTR pszExtra,
319         HKEY *phkeyOut)
320 {
321         return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI IQueryAssociations_fnGetData(
325         IQueryAssociations * iface,
326         ASSOCF flags,
327         ASSOCDATA data,
328         LPCWSTR pszExtra,
329         LPVOID pvOut,
330         DWORD *pcbOut)
331 {
332         return E_NOTIMPL;
333 }
334 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
335         IQueryAssociations * iface,
336         ASSOCF flags,
337         ASSOCENUM assocenum,
338         LPCWSTR pszExtra,
339         REFIID riid,
340         LPVOID *ppvOut)
341 {
342         return E_NOTIMPL;
343 }
344
345 static struct ICOM_VTABLE(IQueryAssociations) qavt = 
346 {       
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
356 };