push a1eb882dd4a6a88419e75ca032b34641780365a0
[wine/hacks.git] / dlls / shell32 / debughlp.c
blobb1e92381fbf67676804e6f73ec22ad1858f1d518
1 /*
2 * Helper functions for debugging
4 * Copyright 1998, 2002 Juergen Schmied
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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"
36 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
38 static
39 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
41 WORD len;
43 if(pidl)
45 len = pidl->mkid.cb;
46 if (len)
48 return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
51 return NULL;
54 static
55 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
57 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
60 static
61 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
63 if(pidl && pidl->mkid.cb != 0x00)
64 return (LPPIDLDATA) &(pidl->mkid.abID);
65 return NULL;
68 static
69 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
71 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
73 if (pdata)
75 switch (pdata->type)
77 case PT_GUID:
78 case PT_SHELLEXT:
79 case PT_YAGUID:
80 return NULL;
82 case PT_DRIVE:
83 case PT_DRIVE1:
84 case PT_DRIVE2:
85 case PT_DRIVE3:
86 return (LPSTR)&(pdata->u.drive.szDriveName);
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);
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);
103 return NULL;
106 static
107 LPWSTR _dbg_ILGetTextPointerW(LPCITEMIDLIST pidl)
109 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
111 if (pdata)
113 switch (pdata->type)
115 case PT_GUID:
116 case PT_SHELLEXT:
117 case PT_YAGUID:
118 return NULL;
120 case PT_DRIVE:
121 case PT_DRIVE1:
122 case PT_DRIVE2:
123 case PT_DRIVE3:
124 /* return (LPSTR)&(pdata->u.drive.szDriveName);*/
125 return NULL;
127 case PT_FOLDER:
128 case PT_FOLDER1:
129 case PT_VALUE:
130 case PT_IESPECIAL1:
131 case PT_IESPECIAL2:
132 /* return (LPSTR)&(pdata->u.file.szNames); */
133 return NULL;
135 case PT_WORKGRP:
136 case PT_COMP:
137 case PT_NETWORK:
138 case PT_NETPROVIDER:
139 case PT_SHARE:
140 /* return (LPSTR)&(pdata->u.network.szNames); */
141 return NULL;
143 case PT_VALUEW:
144 return (LPWSTR)&(pdata->u.file.szNames);
147 return NULL;
151 static
152 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
154 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
156 if (pdata)
158 switch (pdata->type)
160 case PT_FOLDER:
161 case PT_VALUE:
162 case PT_IESPECIAL1:
163 case PT_IESPECIAL2:
164 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
166 case PT_WORKGRP:
167 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
170 return NULL;
173 static
174 LPWSTR _dbg_ILGetSTextPointerW(LPCITEMIDLIST pidl)
176 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
178 if (pdata)
180 switch (pdata->type)
182 case PT_FOLDER:
183 case PT_VALUE:
184 case PT_IESPECIAL1:
185 case PT_IESPECIAL2:
186 /*return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1); */
187 return NULL;
189 case PT_WORKGRP:
190 /* return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1); */
191 return NULL;
193 case PT_VALUEW:
194 return (LPWSTR)(pdata->u.file.szNames + lstrlenW ((LPWSTR)pdata->u.file.szNames) + 1);
197 return NULL;
201 static
202 IID* _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
204 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
206 if (pdata)
208 switch (pdata->type)
210 case PT_SHELLEXT:
211 case PT_GUID:
212 case PT_YAGUID:
213 return &(pdata->u.guid.guid);
216 return NULL;
219 static
220 void _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
222 LPSTR szSrc;
223 LPWSTR szSrcW;
224 GUID const * riid;
226 if (!pidl) return;
228 if (szOut)
229 *szOut = 0;
231 if (_dbg_ILIsDesktop(pidl))
233 /* desktop */
234 if (szOut) lstrcpynA(szOut, "Desktop", uOutSize);
236 else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
238 /* filesystem */
239 if (szOut) lstrcpynA(szOut, szSrc, uOutSize);
241 else if (( szSrcW = _dbg_ILGetTextPointerW(pidl) ))
243 CHAR tmp[MAX_PATH];
244 /* unicode filesystem */
245 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, tmp, MAX_PATH, NULL, NULL);
246 if (szOut) lstrcpynA(szOut, tmp, uOutSize);
248 else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
250 if (szOut)
251 sprintf( szOut, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
252 riid->Data1, riid->Data2, riid->Data3,
253 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
254 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
261 void pdump (LPCITEMIDLIST pidl)
263 LPCITEMIDLIST pidltemp = pidl;
265 if (!TRACE_ON(pidl)) return;
267 if (! pidltemp)
269 MESSAGE ("-------- pidl=NULL (Desktop)\n");
271 else
273 MESSAGE ("-------- pidl=%p\n", pidl);
274 if (pidltemp->mkid.cb)
278 if (_ILIsUnicode(pidltemp))
280 DWORD dwAttrib = 0;
281 LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp);
282 DWORD type = pData ? pData->type : 0;
283 LPWSTR szLongName = _dbg_ILGetTextPointerW(pidltemp);
284 LPWSTR szShortName = _dbg_ILGetSTextPointerW(pidltemp);
285 char szName[MAX_PATH];
287 _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
288 if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
289 dwAttrib = pData->u.file.uFileAttribs;
291 MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
292 pidltemp, pidltemp->mkid.cb, type, dwAttrib,
293 debugstr_a(szName), debugstr_w(szLongName), debugstr_w(szShortName));
295 else
297 DWORD dwAttrib = 0;
298 LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp);
299 DWORD type = pData ? pData->type : 0;
300 LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp);
301 LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp);
302 char szName[MAX_PATH];
304 _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
305 if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
306 dwAttrib = pData->u.file.uFileAttribs;
308 MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
309 pidltemp, pidltemp->mkid.cb, type, dwAttrib,
310 debugstr_a(szName), debugstr_a(szLongName), debugstr_a(szShortName));
313 pidltemp = _dbg_ILGetNext(pidltemp);
315 } while (pidltemp && pidltemp->mkid.cb);
317 else
319 MESSAGE ("empty pidl (Desktop)\n");
321 pcheck(pidl);
325 static void dump_pidl_hex( LPCITEMIDLIST pidl )
327 const unsigned char *p = (const unsigned char *)pidl;
328 const int max_bytes = 0x80;
329 #define max_line 0x10
330 char szHex[max_line*3+1], szAscii[max_line+1];
331 int i, n;
333 n = pidl->mkid.cb;
334 if( n>max_bytes )
335 n = max_bytes;
336 for( i=0; i<n; i++ )
338 sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
339 szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';
341 /* print out at the end of each line and when we're finished */
342 if( i!=(n-1) && (i%max_line) != (max_line-1) )
343 continue;
344 szAscii[ (i%max_line)+1 ] = 0;
345 ERR("%-*s %s\n", max_line*3, szHex, szAscii );
349 BOOL pcheck( LPCITEMIDLIST pidl )
351 DWORD type;
352 LPCITEMIDLIST pidltemp = pidl;
354 while( pidltemp && pidltemp->mkid.cb )
356 type = _dbg_ILGetDataPointer(pidltemp)->type;
357 switch( type )
359 case PT_CPLAPPLET:
360 case PT_GUID:
361 case PT_SHELLEXT:
362 case PT_DRIVE:
363 case PT_DRIVE1:
364 case PT_DRIVE2:
365 case PT_DRIVE3:
366 case PT_FOLDER:
367 case PT_VALUE:
368 case PT_VALUEW:
369 case PT_FOLDER1:
370 case PT_WORKGRP:
371 case PT_COMP:
372 case PT_NETPROVIDER:
373 case PT_NETWORK:
374 case PT_IESPECIAL1:
375 case PT_YAGUID:
376 case PT_IESPECIAL2:
377 case PT_SHARE:
378 break;
379 default:
380 ERR("unknown IDLIST %p [%p] size=%u type=%x\n",
381 pidl, pidltemp, pidltemp->mkid.cb,type );
382 dump_pidl_hex( pidltemp );
383 return FALSE;
385 pidltemp = _dbg_ILGetNext(pidltemp);
387 return TRUE;
390 static const struct {
391 REFIID riid;
392 const char *name;
393 } InterfaceDesc[] = {
394 {&IID_IUnknown, "IID_IUnknown"},
395 {&IID_IClassFactory, "IID_IClassFactory"},
396 {&IID_IShellView, "IID_IShellView"},
397 {&IID_IOleCommandTarget, "IID_IOleCommandTarget"},
398 {&IID_IDropTarget, "IID_IDropTarget"},
399 {&IID_IDropSource, "IID_IDropSource"},
400 {&IID_IViewObject, "IID_IViewObject"},
401 {&IID_IContextMenu, "IID_IContextMenu"},
402 {&IID_IShellExtInit, "IID_IShellExtInit"},
403 {&IID_IShellFolder, "IID_IShellFolder"},
404 {&IID_IShellFolder2, "IID_IShellFolder2"},
405 {&IID_IPersist, "IID_IPersist"},
406 {&IID_IPersistFolder, "IID_IPersistFolder"},
407 {&IID_IPersistFolder2, "IID_IPersistFolder2"},
408 {&IID_IPersistFolder3, "IID_IPersistFolder3"},
409 {&IID_IExtractIconA, "IID_IExtractIconA"},
410 {&IID_IExtractIconW, "IID_IExtractIconW"},
411 {&IID_IDataObject, "IID_IDataObject"},
412 {&IID_IAutoComplete, "IID_IAutoComplete"},
413 {&IID_IAutoComplete2, "IID_IAutoComplete2"},
414 {&IID_IShellLinkA, "IID_IShellLinkA"},
415 {&IID_IShellLinkW, "IID_IShellLinkW"},
416 {NULL,NULL}};
418 const char * shdebugstr_guid( const struct _GUID *id )
420 int i;
421 const char* name = NULL;
422 char clsidbuf[100];
424 if (!id) return "(null)";
426 for (i=0;InterfaceDesc[i].riid && !name;i++) {
427 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
429 if (!name) {
430 if (HCR_GetClassNameA(id, clsidbuf, 100))
431 name = clsidbuf;
434 return wine_dbg_sprintf( "\n\t{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
435 id->Data1, id->Data2, id->Data3,
436 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
437 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );