Add debug info for IExtractIconW.
[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 "pidl.h"
26 #include "shlguid.h"
27 #include "wine/debug.h"
28 #include "debughlp.h"
29 #include "docobj.h"
30 #include "shell32_main.h"
31
32
33 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
34
35 LPITEMIDLIST  _dbg_ILGetNext(LPITEMIDLIST pidl)
36 {
37         WORD len;
38
39         if(pidl)
40         {
41           len =  pidl->mkid.cb;
42           if (len)
43           {
44             pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
45             return pidl;
46           }
47         }
48         return NULL;
49 }
50
51 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
52 {
53         return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
54 }
55
56 LPPIDLDATA _dbg_ILGetDataPointer(LPITEMIDLIST pidl)
57 {
58         if(pidl && pidl->mkid.cb != 0x00)
59           return (LPPIDLDATA) &(pidl->mkid.abID);
60         return NULL;
61 }
62
63 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
64 {
65         LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
66
67         if (pdata)
68         {
69           switch (pdata->type)
70           {
71             case PT_MYCOMP:
72             case PT_SPECIAL:
73               return NULL;
74
75             case PT_DRIVE:
76             case PT_DRIVE1:
77             case PT_DRIVE2:
78             case PT_DRIVE3:
79               return (LPSTR)&(pdata->u.drive.szDriveName);
80
81             case PT_FOLDER:
82             case PT_FOLDER1:
83             case PT_VALUE:
84             case PT_IESPECIAL1:
85             case PT_IESPECIAL2:
86               return (LPSTR)&(pdata->u.file.szNames);
87
88             case PT_WORKGRP:
89             case PT_COMP:
90             case PT_NETWORK:
91             case PT_SHARE:
92               return (LPSTR)&(pdata->u.network.szNames);
93           }
94         }
95         return NULL;
96 }
97
98 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
99 {
100         LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
101
102         if (pdata)
103         {
104           switch (pdata->type)
105           {
106             case PT_FOLDER:
107             case PT_VALUE:
108             case PT_IESPECIAL1:
109             case PT_IESPECIAL2:
110               return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
111
112             case PT_WORKGRP:
113               return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
114           }
115         }
116         return NULL;
117 }
118
119 REFIID _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
120 {
121         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
122
123         if (pdata)
124         {
125           switch (pdata->type)
126           {
127             case PT_SPECIAL:
128             case PT_MYCOMP:
129               return (REFIID) &(pdata->u.mycomp.guid);
130           }
131         }
132         return NULL;
133 }
134
135 DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
136 {
137         DWORD           dwReturn=0;
138         LPSTR           szSrc;
139         GUID const *    riid;
140         char szTemp[MAX_PATH];
141
142         if (!pidl) return 0;
143
144         if (szOut)
145           *szOut = 0;
146
147         if (_dbg_ILIsDesktop(pidl))
148         {
149          /* desktop */
150           if (szOut) strncpy(szOut, "Desktop", uOutSize);
151           dwReturn = strlen ("Desktop");
152         }
153         else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
154         {
155           /* filesystem */
156           if (szOut) strncpy(szOut, szSrc, uOutSize);
157           dwReturn = strlen(szSrc);
158         }
159         else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
160         {
161           if (szOut)
162             sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
163                  riid->Data1, riid->Data2, riid->Data3,
164                  riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
165                  riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
166           dwReturn = strlen (szTemp);
167         }
168         return dwReturn;
169 }
170
171
172
173
174 void pdump (LPCITEMIDLIST pidl)
175 {
176         LPITEMIDLIST pidltemp = pidl;
177
178         if (!TRACE_ON(pidl)) return;
179
180         if (! pidltemp)
181         {
182           MESSAGE ("-------- pidl=NULL (Desktop)\n");
183         }
184         else
185         {
186           MESSAGE ("-------- pidl=%p\n", pidl);
187           if (pidltemp->mkid.cb)
188           {
189             do
190             {
191               DWORD dwAttrib = 0;
192               LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
193               DWORD type         = pData->type;
194               LPSTR szLongName   = _dbg_ILGetTextPointer(pidltemp);
195               LPSTR szShortName  = _dbg_ILGetSTextPointer(pidltemp);
196               char szName[MAX_PATH];
197
198               _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
199               if( PT_FOLDER == type)
200                 dwAttrib = pData->u.folder.uFileAttribs;
201               else if( PT_VALUE == type)
202                 dwAttrib = pData->u.file.uFileAttribs;
203
204               MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
205                        pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
206
207               pidltemp = _dbg_ILGetNext(pidltemp);
208
209             } while (pidltemp->mkid.cb);
210           }
211           else
212           {
213             MESSAGE ("empty pidl (Desktop)\n");
214           }
215           pcheck(pidl);
216         }
217 }
218 #define BYTES_PRINTED 32
219 BOOL pcheck (LPCITEMIDLIST pidl)
220 {
221         DWORD type, ret=TRUE;
222         LPITEMIDLIST pidltemp = pidl;
223
224         if (pidltemp && pidltemp->mkid.cb)
225         { do
226           { type   = _dbg_ILGetDataPointer(pidltemp)->type;
227             switch (type)
228             { case PT_DESKTOP:
229               case PT_MYCOMP:
230               case PT_SPECIAL:
231               case PT_DRIVE:
232               case PT_DRIVE1:
233               case PT_DRIVE2:
234               case PT_DRIVE3:
235               case PT_FOLDER:
236               case PT_VALUE:
237               case PT_FOLDER1:
238               case PT_WORKGRP:
239               case PT_COMP:
240               case PT_NETWORK:
241               case PT_IESPECIAL1:
242               case PT_IESPECIAL2:
243               case PT_SHARE:
244                 break;
245               default:
246               {
247                 char szTemp[BYTES_PRINTED*4 + 1];
248                 int i;
249                 unsigned char c;
250
251                 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
252                 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
253                 {
254                   c = ((unsigned char *)pidltemp)[i];
255
256                   szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
257                   szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
258                   szTemp[i*3+2] = ' ';
259                   szTemp[i+BYTES_PRINTED*3]  =  (c>=0x20 && c <=0x80) ? c : '.';
260                 }
261                 szTemp[BYTES_PRINTED*4] = 0x00;
262                 ERR("unknown IDLIST %p [%p] size=%u type=%lx\n%s\n",pidl, pidltemp, pidltemp->mkid.cb,type, szTemp);
263                 ret = FALSE;
264               }
265             }
266             pidltemp = _dbg_ILGetNext(pidltemp);
267           } while (pidltemp->mkid.cb);
268         }
269         return ret;
270 }
271
272 static char shdebugstr_buf1[100];
273 static char shdebugstr_buf2[100];
274 static char * shdebugstr_buf = shdebugstr_buf1;
275
276 static struct {
277         REFIID  riid;
278         char    *name;
279 } InterfaceDesc[] = {
280         {&IID_IUnknown,                 "IID_IUnknown"},
281         {&IID_IClassFactory,            "IID_IClassFactory"},
282         {&IID_IShellView,               "IID_IShellView"},
283         {&IID_IOleCommandTarget,        "IID_IOleCommandTarget"},
284         {&IID_IDropTarget,              "IID_IDropTarget"},
285         {&IID_IDropSource,              "IID_IDropSource"},
286         {&IID_IViewObject,              "IID_IViewObject"},
287         {&IID_IContextMenu,             "IID_IContextMenu"},
288         {&IID_IShellExtInit,            "IID_IShellExtInit"},
289         {&IID_IShellFolder,             "IID_IShellFolder"},
290         {&IID_IShellFolder2,            "IID_IShellFolder2"},
291         {&IID_IPersist,                 "IID_IPersist"},
292         {&IID_IPersistFolder,           "IID_IPersistFolder"},
293         {&IID_IPersistFolder2,          "IID_IPersistFolder2"},
294         {&IID_IPersistFolder3,          "IID_IPersistFolder3"},
295         {&IID_IExtractIconA,            "IID_IExtractIconA"},
296         {&IID_IExtractIconW,            "IID_IExtractIconW"},
297         {&IID_IDataObject,              "IID_IDataObject"},
298         {NULL,NULL}};
299
300 const char * shdebugstr_guid( const struct _GUID *id )
301 {
302         int i;
303         char* name = NULL;
304         char clsidbuf[100];
305
306         shdebugstr_buf = (shdebugstr_buf == shdebugstr_buf1) ? shdebugstr_buf2 : shdebugstr_buf1;
307
308         if (!id) {
309           strcpy (shdebugstr_buf, "(null)");
310         } else {
311             for (i=0;InterfaceDesc[i].riid && !name;i++) {
312                 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
313             }
314             if (!name) {
315                 if (HCR_GetClassNameA(id, clsidbuf, 100))
316                     name = clsidbuf;
317             }
318
319             sprintf( shdebugstr_buf, "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
320                  id->Data1, id->Data2, id->Data3,
321                  id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
322                  id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
323         }
324         return shdebugstr_buf;
325 }