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