Added CSIDL_MYVIDEO|MYPICTURES|MYMUSIC to _SHRegisterUserShellFolders.
[wine] / dlls / shell32 / debughlp.c
1 /*
2  * Helper functions for debugging
3  *
4  * Copyright 1998, 2002 Juergen Schmied
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "pidl.h"
28 #include "shlguid.h"
29 #include "shldisp.h"
30 #include "wine/debug.h"
31 #include "debughlp.h"
32 #include "docobj.h"
33 #include "shell32_main.h"
34
35
36 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
37
38 static
39 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
40 {
41         WORD len;
42
43         if(pidl)
44         {
45           len =  pidl->mkid.cb;
46           if (len)
47           {
48             return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
49           }
50         }
51         return NULL;
52 }
53
54 static
55 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
56 {
57         return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
58 }
59
60 static
61 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
62 {
63         if(pidl && pidl->mkid.cb != 0x00)
64           return (LPPIDLDATA) &(pidl->mkid.abID);
65         return NULL;
66 }
67
68 static
69 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
70 {
71         LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
72
73         if (pdata)
74         {
75           switch (pdata->type)
76           {
77             case PT_GUID:
78             case PT_SHELLEXT:
79             case PT_YAGUID:
80               return NULL;
81
82             case PT_DRIVE:
83             case PT_DRIVE1:
84             case PT_DRIVE2:
85             case PT_DRIVE3:
86               return (LPSTR)&(pdata->u.drive.szDriveName);
87
88             case PT_FOLDER:
89             case PT_FOLDER1:
90             case PT_VALUE:
91             case PT_IESPECIAL1:
92             case PT_IESPECIAL2:
93               return (LPSTR)&(pdata->u.file.szNames);
94
95             case PT_WORKGRP:
96             case PT_COMP:
97             case PT_NETWORK:
98             case PT_NETPROVIDER:
99             case PT_SHARE:
100               return (LPSTR)&(pdata->u.network.szNames);
101           }
102         }
103         return NULL;
104 }
105
106 static
107 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
108 {
109         LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
110
111         if (pdata)
112         {
113           switch (pdata->type)
114           {
115             case PT_FOLDER:
116             case PT_VALUE:
117             case PT_IESPECIAL1:
118             case PT_IESPECIAL2:
119               return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
120
121             case PT_WORKGRP:
122               return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
123           }
124         }
125         return NULL;
126 }
127
128 static
129 IID* _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
130 {
131         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
132
133         if (pdata)
134         {
135           switch (pdata->type)
136           {
137             case PT_SHELLEXT:
138             case PT_GUID:
139             case PT_YAGUID:
140               return &(pdata->u.guid.guid);
141           }
142         }
143         return NULL;
144 }
145
146 static
147 void _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
148 {
149         LPSTR           szSrc;
150         GUID const *    riid;
151
152         if (!pidl) return;
153
154         if (szOut)
155           *szOut = 0;
156
157         if (_dbg_ILIsDesktop(pidl))
158         {
159          /* desktop */
160           if (szOut) lstrcpynA(szOut, "Desktop", uOutSize);
161         }
162         else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
163         {
164           /* filesystem */
165           if (szOut) lstrcpynA(szOut, szSrc, uOutSize);
166         }
167         else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
168         {
169           if (szOut)
170             sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
171                  riid->Data1, riid->Data2, riid->Data3,
172                  riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
173                  riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
174         }
175 }
176
177
178
179
180 void pdump (LPCITEMIDLIST pidl)
181 {
182         LPCITEMIDLIST pidltemp = pidl;
183
184         if (!TRACE_ON(pidl)) return;
185
186         if (! pidltemp)
187         {
188           MESSAGE ("-------- pidl=NULL (Desktop)\n");
189         }
190         else
191         {
192           MESSAGE ("-------- pidl=%p\n", pidl);
193           if (pidltemp->mkid.cb)
194           {
195             do
196             {
197               DWORD dwAttrib = 0;
198               LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
199               DWORD type = pData ? pData->type : 0;
200               LPSTR szLongName   = _dbg_ILGetTextPointer(pidltemp);
201               LPSTR szShortName  = _dbg_ILGetSTextPointer(pidltemp);
202               char szName[MAX_PATH];
203
204               _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
205               if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
206                 dwAttrib = pData->u.file.uFileAttribs;
207
208               MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
209                        pidltemp, pidltemp->mkid.cb, type, dwAttrib,
210                        debugstr_a(szName), debugstr_a(szLongName), debugstr_a(szShortName));
211
212               pidltemp = _dbg_ILGetNext(pidltemp);
213
214             } while (pidltemp && pidltemp->mkid.cb);
215           }
216           else
217           {
218             MESSAGE ("empty pidl (Desktop)\n");
219           }
220           pcheck(pidl);
221         }
222 }
223
224 static void dump_pidl_hex( LPCITEMIDLIST pidl )
225 {
226     const unsigned char *p = (const unsigned char *)pidl;
227     const int max_bytes = 0x80, max_line = 0x10;
228     char szHex[max_line*3+1], szAscii[max_line+1];
229     int i, n;
230
231     n = pidl->mkid.cb;
232     if( n>max_bytes )
233         n = max_bytes;
234     for( i=0; i<n; i++ )
235     {
236         sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
237         szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';
238
239         /* print out at the end of each line and when we're finished */
240         if( i!=(n-1) && (i%max_line) != (max_line-1) )
241             continue;
242         szAscii[ (i%max_line)+1 ] = 0;
243         ERR("%-*s   %s\n", max_line*3, szHex, szAscii );
244     }
245 }
246
247 BOOL pcheck( LPCITEMIDLIST pidl )
248 {
249     DWORD type;
250     LPCITEMIDLIST pidltemp = pidl;
251
252     while( pidltemp && pidltemp->mkid.cb )
253     {
254         type = _dbg_ILGetDataPointer(pidltemp)->type;
255         switch( type )
256         {
257         case PT_CPLAPPLET:
258         case PT_GUID:
259         case PT_SHELLEXT:
260         case PT_DRIVE:
261         case PT_DRIVE1:
262         case PT_DRIVE2:
263         case PT_DRIVE3:
264         case PT_FOLDER:
265         case PT_VALUE:
266         case PT_VALUEW:
267         case PT_FOLDER1:
268         case PT_WORKGRP:
269         case PT_COMP:
270         case PT_NETPROVIDER:
271         case PT_NETWORK:
272         case PT_IESPECIAL1:
273         case PT_YAGUID:
274         case PT_IESPECIAL2:
275         case PT_SHARE:
276             break;
277         default:
278             ERR("unknown IDLIST %p [%p] size=%u type=%lx\n",
279                 pidl, pidltemp, pidltemp->mkid.cb,type );
280             dump_pidl_hex( pidltemp );
281             return FALSE;
282         }
283         pidltemp = _dbg_ILGetNext(pidltemp);
284     }
285     return TRUE;
286 }
287
288 static const struct {
289         REFIID riid;
290         const char *name;
291 } InterfaceDesc[] = {
292         {&IID_IUnknown,                 "IID_IUnknown"},
293         {&IID_IClassFactory,            "IID_IClassFactory"},
294         {&IID_IShellView,               "IID_IShellView"},
295         {&IID_IOleCommandTarget,        "IID_IOleCommandTarget"},
296         {&IID_IDropTarget,              "IID_IDropTarget"},
297         {&IID_IDropSource,              "IID_IDropSource"},
298         {&IID_IViewObject,              "IID_IViewObject"},
299         {&IID_IContextMenu,             "IID_IContextMenu"},
300         {&IID_IShellExtInit,            "IID_IShellExtInit"},
301         {&IID_IShellFolder,             "IID_IShellFolder"},
302         {&IID_IShellFolder2,            "IID_IShellFolder2"},
303         {&IID_IPersist,                 "IID_IPersist"},
304         {&IID_IPersistFolder,           "IID_IPersistFolder"},
305         {&IID_IPersistFolder2,          "IID_IPersistFolder2"},
306         {&IID_IPersistFolder3,          "IID_IPersistFolder3"},
307         {&IID_IExtractIconA,            "IID_IExtractIconA"},
308         {&IID_IExtractIconW,            "IID_IExtractIconW"},
309         {&IID_IDataObject,              "IID_IDataObject"},
310         {&IID_IAutoComplete,            "IID_IAutoComplete"},
311         {&IID_IAutoComplete2,           "IID_IAutoComplete2"},
312         {&IID_IShellLinkA,              "IID_IShellLinkA"},
313         {&IID_IShellLinkW,              "IID_IShellLinkW"},
314         {NULL,NULL}};
315
316 const char * shdebugstr_guid( const struct _GUID *id )
317 {
318         int i;
319         const char* name = NULL;
320         char clsidbuf[100];
321
322         if (!id) return "(null)";
323
324             for (i=0;InterfaceDesc[i].riid && !name;i++) {
325                 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
326             }
327             if (!name) {
328                 if (HCR_GetClassNameA(id, clsidbuf, 100))
329                     name = clsidbuf;
330             }
331
332             return wine_dbg_sprintf( "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
333                  id->Data1, id->Data2, id->Data3,
334                  id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
335                  id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
336 }