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