Added *.spec.c, *.spec.glue.s, *.glue.c to .cvsignore that need them.
[wine] / dlls / shell32 / pidl.c
1 /*
2  *      pidl Handling
3  *
4  *      Copyright 1998  Juergen Schmied
5  *
6  * NOTES
7  *  a pidl == NULL means desktop and is legal
8  *
9  */
10
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <assert.h>
15 #include "winbase.h"
16 #include "debugtools.h"
17 #include "shell.h"
18 #include "shlguid.h"
19 #include "winerror.h"
20 #include "winnls.h"
21 #include "winversion.h"
22 #include "shell32_main.h"
23 #include "shellapi.h"
24
25 #include "pidl.h"
26 #include "wine/undocshell.h"
27
28 DEFAULT_DEBUG_CHANNEL(pidl)
29 DECLARE_DEBUG_CHANNEL(shell)
30
31 void pdump (LPCITEMIDLIST pidl)
32 {       DWORD type;
33         char * szData;
34         char * szShortName;
35         char szName[MAX_PATH];
36         BOOL bIsShellDebug;
37         
38         LPITEMIDLIST pidltemp = pidl;
39         if (!TRACE_ON(pidl))
40           return;
41
42         /* silence the sub-functions */
43         bIsShellDebug = TRACE_ON(shell);
44         __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, FALSE);
45         __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
46
47         if (! pidltemp)
48         {
49           MESSAGE ("-------- pidl=NULL (Desktop)\n");
50         }
51         else
52         {
53           MESSAGE ("-------- pidl=%p\n", pidl);
54           if (pidltemp->mkid.cb)
55           { 
56             do
57             {
58               type   = _ILGetDataPointer(pidltemp)->type;
59               szData = _ILGetTextPointer(pidltemp);
60               szShortName = _ILGetSTextPointer(pidltemp);
61               _ILSimpleGetText(pidltemp, szName, MAX_PATH);
62
63               MESSAGE ("-- pidl=%p size=%u type=%lx name=%s (%s,%s)\n",
64                        pidltemp, pidltemp->mkid.cb,type,szName,debugstr_a(szData), debugstr_a(szShortName));
65
66               pidltemp = ILGetNext(pidltemp);
67
68             } while (pidltemp->mkid.cb);
69           }
70           else
71           {
72             MESSAGE ("empty pidl (Desktop)\n");
73           }
74           pcheck(pidl);
75         }
76
77         __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, bIsShellDebug);
78         __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, TRUE);
79
80 }
81 #define BYTES_PRINTED 32
82 BOOL pcheck (LPCITEMIDLIST pidl)
83 {       DWORD type, ret=TRUE;
84         BOOL bIsPidlDebug;
85
86         LPITEMIDLIST pidltemp = pidl;
87
88         bIsPidlDebug = TRACE_ON(shell);
89         __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
90
91         if (pidltemp && pidltemp->mkid.cb)
92         { do
93           { type   = _ILGetDataPointer(pidltemp)->type;
94             switch (type)
95             { case PT_DESKTOP:
96               case PT_MYCOMP:
97               case PT_SPECIAL:
98               case PT_DRIVE:
99               case PT_DRIVE1:
100               case PT_DRIVE2:
101               case PT_DRIVE3:
102               case PT_FOLDER:
103               case PT_VALUE:
104               case PT_FOLDER1:
105               case PT_WORKGRP:
106               case PT_COMP:
107               case PT_NETWORK:
108               case PT_SHARE:
109               case PT_IESPECIAL:
110                 break;
111               default:
112               {
113                 char szTemp[BYTES_PRINTED*4 + 1];
114                 int i;
115                 unsigned char c;
116
117                 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
118                 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
119                 {
120                   c = ((unsigned char *)pidltemp)[i];
121
122                   szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
123                   szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
124                   szTemp[i*3+2] = ' ';
125                   szTemp[i+BYTES_PRINTED*3]  =  (c>=0x20 && c <=0x80) ? c : '.';
126                 }
127                 szTemp[BYTES_PRINTED*4] = 0x00;
128                 ERR("unknown IDLIST type size=%u type=%lx\n%s\n",pidltemp->mkid.cb,type, szTemp);
129                 ret = FALSE;
130               }
131             }
132             pidltemp = ILGetNext(pidltemp);
133           } while (pidltemp->mkid.cb);
134         }
135         __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, bIsPidlDebug);
136         return ret;
137 }
138
139 /*************************************************************************
140  * ILGetDisplayName                     [SHELL32.15]
141  */
142 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl,LPSTR path)
143 {
144         TRACE_(shell)("pidl=%p %p semi-stub\n",pidl,path);
145         return SHGetPathFromIDListA(pidl, path);
146 }
147 /*************************************************************************
148  * ILFindLastID [SHELL32.16]
149  *
150  * NOTES
151  *   observed: pidl=Desktop return=pidl
152  */
153 LPITEMIDLIST WINAPI ILFindLastID(LPITEMIDLIST pidl) 
154 {       LPITEMIDLIST   pidlLast = pidl;
155
156         TRACE("(pidl=%p)\n",pidl);
157
158         while (pidl->mkid.cb)
159         {
160           pidlLast = pidl;
161           pidl = ILGetNext(pidl);
162         }
163         return pidlLast;                
164 }
165 /*************************************************************************
166  * ILRemoveLastID [SHELL32.17]
167  *
168  * NOTES
169  *   when pidl=Desktop return=FALSE
170  */
171 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
172 {
173         TRACE_(shell)("pidl=%p\n",pidl);
174
175         if (!pidl || !pidl->mkid.cb)
176           return 0;
177         ILFindLastID(pidl)->mkid.cb = 0;
178         return 1;
179 }
180
181 /*************************************************************************
182  * ILClone [SHELL32.18]
183  *
184  * NOTES
185  *    dupicate an idlist
186  */
187 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
188 { DWORD    len;
189   LPITEMIDLIST  newpidl;
190
191   if (!pidl)
192     return NULL;
193     
194   len = ILGetSize(pidl);
195   newpidl = (LPITEMIDLIST)SHAlloc(len);
196   if (newpidl)
197     memcpy(newpidl,pidl,len);
198
199   TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
200   pdump(pidl);
201
202   return newpidl;
203 }
204 /*************************************************************************
205  * ILCloneFirst [SHELL32.19]
206  *
207  * NOTES
208  *  duplicates the first idlist of a complex pidl
209  */
210 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
211 {       DWORD len;
212         LPITEMIDLIST pidlNew = NULL;
213         
214         TRACE("pidl=%p \n",pidl);
215         pdump(pidl);
216         
217         if (pidl)
218         {
219           len = pidl->mkid.cb;  
220           pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
221           if (pidlNew)
222           {
223             memcpy(pidlNew,pidl,len+2);         /* 2 -> mind a desktop pidl */
224
225             if (len)
226               ILGetNext(pidlNew)->mkid.cb = 0x00;
227           }
228         }
229         TRACE("-- newpidl=%p\n",pidlNew);
230
231         return pidlNew;
232 }
233 /*************************************************************************
234  * ILLoadFromStream
235  *
236  * NOTES
237  *   the first two bytes are the len, the pidl is following then
238  */
239 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
240 {       WORD            wLen = 0;
241         DWORD           dwBytesRead;
242         HRESULT         ret = E_FAIL;
243         
244
245         TRACE_(shell)("%p %p\n", pStream ,  ppPidl);
246
247         if (*ppPidl)
248         { SHFree(*ppPidl);
249           *ppPidl = NULL;
250         }
251         
252         IStream_AddRef (pStream);
253
254         if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
255         { *ppPidl = SHAlloc (wLen);
256           if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
257           { ret = S_OK;
258           }
259           else
260           { SHFree(*ppPidl);
261             *ppPidl = NULL;
262           }
263         }
264         
265         /* we are not jet fully compatible */
266         if (!pcheck(*ppPidl))
267         { SHFree(*ppPidl);
268           *ppPidl = NULL;
269         }
270         
271
272         IStream_Release (pStream);
273
274         return ret;
275 }
276 /*************************************************************************
277  * SHILCreateFromPath   [SHELL32.28]
278  *
279  * NOTES
280  *   wraper for IShellFolder::ParseDisplayName()
281  */
282 HRESULT WINAPI SHILCreateFromPathA (LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
283 {       LPSHELLFOLDER sf;
284         WCHAR lpszDisplayName[MAX_PATH];
285         DWORD pchEaten;
286         HRESULT ret = E_FAIL;
287         
288         TRACE_(shell)("%s %p 0x%08lx\n",path,ppidl,attributes?*attributes:0);
289
290         lstrcpynAtoW(lpszDisplayName, path, MAX_PATH);
291
292         if (SUCCEEDED (SHGetDesktopFolder(&sf)))
293         {
294           ret = IShellFolder_ParseDisplayName(sf,0, NULL,lpszDisplayName,&pchEaten,ppidl,attributes);
295           IShellFolder_Release(sf);
296         }
297         return ret;
298 }
299 HRESULT WINAPI SHILCreateFromPathW (LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
300 {       LPSHELLFOLDER sf;
301         DWORD pchEaten;
302         HRESULT ret = E_FAIL;
303         
304         TRACE_(shell)("%s %p 0x%08lx\n",debugstr_w(path),ppidl,attributes?*attributes:0);
305
306         if (SUCCEEDED (SHGetDesktopFolder(&sf)))
307         {
308           ret = IShellFolder_ParseDisplayName(sf,0, NULL, (LPWSTR) path, &pchEaten, ppidl, attributes);
309           IShellFolder_Release(sf);
310         }
311         return ret;
312 }
313 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
314 {
315         if ( VERSION_OsIsUnicode())
316           return SHILCreateFromPathW (path, ppidl, attributes);
317         return SHILCreateFromPathA (path, ppidl, attributes);
318 }
319
320 /*************************************************************************
321  * SHCloneSpecialIDList [SHELL32.89]
322  * 
323  * PARAMETERS
324  *  hwndOwner   [in] 
325  *  nFolder     [in]    CSIDL_xxxxx ??
326  *
327  * RETURNS
328  *  pidl ??
329  * NOTES
330  *     exported by ordinal
331  */
332 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner,DWORD nFolder,DWORD x3)
333 {       LPITEMIDLIST ppidl;
334         WARN_(shell)("(hwnd=0x%x,csidl=0x%lx,0x%lx):semi-stub.\n",
335                                          hwndOwner,nFolder,x3);
336
337         SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
338
339         return ppidl;
340 }
341
342 /*************************************************************************
343  * ILGlobalClone [SHELL32.97]
344  *
345  */
346 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
347 {       DWORD    len;
348         LPITEMIDLIST  newpidl;
349
350         if (!pidl)
351           return NULL;
352     
353         len = ILGetSize(pidl);
354         newpidl = (LPITEMIDLIST)pCOMCTL32_Alloc(len);
355         if (newpidl)
356           memcpy(newpidl,pidl,len);
357
358         TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
359         pdump(pidl);
360
361         return newpidl;
362 }
363
364 /*************************************************************************
365  * ILIsEqual [SHELL32.21]
366  *
367  */
368 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
369 {
370         char    szData1[MAX_PATH];
371         char    szData2[MAX_PATH];
372
373         LPITEMIDLIST pidltemp1 = pidl1;
374         LPITEMIDLIST pidltemp2 = pidl2;
375
376         TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
377
378         /* explorer reads from registry directly (StreamMRU),
379            so we can only check here */
380         if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
381
382         pdump (pidl1);
383         pdump (pidl2);
384
385         if ( (!pidl1) || (!pidl2) ) return FALSE;
386         
387         while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
388         {
389             _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
390             _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
391
392             if (strcasecmp ( szData1, szData2 )!=0 )
393               return FALSE;
394
395             pidltemp1 = ILGetNext(pidltemp1);
396             pidltemp2 = ILGetNext(pidltemp2);
397         }       
398
399         if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
400         {
401           return TRUE;
402         }
403
404         return FALSE;
405 }
406 /*************************************************************************
407  * ILIsParent [SHELL32.23]
408  *
409  * parent=a/b   child=a/b/c -> true, c is in folder a/b
410  *              child=a/b/c/d -> false if bImmediate is true, d is not in folder a/b
411  *              child=a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
412  */
413 BOOL WINAPI ILIsParent( LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
414 {
415         char    szData1[MAX_PATH];
416         char    szData2[MAX_PATH];
417
418         LPITEMIDLIST pParent = pidlParent;
419         LPITEMIDLIST pChild = pidlChild;
420         
421         TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
422
423         while (pParent->mkid.cb && pChild->mkid.cb)
424         {
425           _ILSimpleGetText(pParent, szData1, MAX_PATH);
426           _ILSimpleGetText(pChild, szData2, MAX_PATH);
427
428           if (strcasecmp ( szData1, szData2 )!=0 )
429             return FALSE;
430
431           pParent = ILGetNext(pParent);
432           pChild = ILGetNext(pChild);
433         }       
434         
435         if ( pParent->mkid.cb || ! pChild->mkid.cb)     /* child shorter or has equal length to parent */
436           return FALSE;
437         
438         if ( ILGetNext(pChild)->mkid.cb && bImmediate)  /* not immediate descent */
439           return FALSE;
440         
441         return TRUE;
442 }
443
444 /*************************************************************************
445  * ILFindChild [SHELL32.24]
446  *
447  * NOTES
448  *  Compares elements from pidl1 and pidl2.
449  *
450  *  pidl1 is desktop            pidl2
451  *  pidl1 shorter pidl2         pointer to first different element of pidl2
452  *                              if there was at least one equal element
453  *  pidl2 shorter pidl1         0
454  *  pidl2 equal pidl1           pointer to last 0x00-element of pidl2
455  */
456 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
457 {
458         char    szData1[MAX_PATH];
459         char    szData2[MAX_PATH];
460
461         LPITEMIDLIST pidltemp1 = pidl1;
462         LPITEMIDLIST pidltemp2 = pidl2;
463         LPITEMIDLIST ret=NULL;
464
465         TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
466
467         /* explorer reads from registry directly (StreamMRU),
468            so we can only check here */
469         if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
470           return FALSE;
471
472         pdump (pidl1);
473         pdump (pidl2);
474
475         if ( _ILIsDesktop(pidl1) )
476         {
477           ret = pidl2;
478         }
479         else
480         {
481           while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
482           {
483             _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
484             _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
485
486             if (strcasecmp(szData1,szData2))
487               break;
488
489             pidltemp1 = ILGetNext(pidltemp1);
490             pidltemp2 = ILGetNext(pidltemp2);
491             ret = pidltemp2;    
492           }
493
494           if (pidltemp1->mkid.cb)
495           {
496             ret = NULL; /* elements of pidl1 left*/
497           }
498         }
499         TRACE_(shell)("--- %p\n", ret);
500         return ret; /* pidl 1 is shorter */
501 }
502
503 /*************************************************************************
504  * ILCombine [SHELL32.25]
505  *
506  * NOTES
507  *  Concatenates two complex idlists.
508  *  The pidl is the first one, pidlsub the next one
509  *  Does not destroy the passed in idlists!
510  */
511 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
512 {
513         DWORD    len1,len2;
514         LPITEMIDLIST  pidlNew;
515         
516         TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
517
518         if(!pidl1 && !pidl2) return NULL;
519
520         pdump (pidl1);
521         pdump (pidl2);
522
523         if(!pidl1)
524         {
525           pidlNew = ILClone(pidl2);
526           return pidlNew;
527         }
528
529         if(!pidl2)
530         {
531           pidlNew = ILClone(pidl1);
532           return pidlNew;
533         }
534
535         len1  = ILGetSize(pidl1)-2;
536         len2  = ILGetSize(pidl2);
537         pidlNew  = SHAlloc(len1+len2);
538
539         if (pidlNew)
540         {
541           memcpy(pidlNew,pidl1,len1);
542           memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
543         }
544
545         /*  TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
546         return pidlNew;
547 }
548 /*************************************************************************
549  *  SHGetRealIDL [SHELL32.98]
550  *
551  * NOTES
552  */
553 LPITEMIDLIST WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl, DWORD z)
554 {
555         FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf,pidl,z);
556
557         pdump (pidl);
558         return 0;
559 }
560
561 /*************************************************************************
562  *  SHLogILFromFSIL [SHELL32.95]
563  *
564  * NOTES
565  *  pild = CSIDL_DESKTOP        ret = 0
566  *  pild = CSIDL_DRIVES         ret = 0
567  */
568 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
569 {
570         FIXME("(pidl=%p)\n",pidl);
571
572         pdump(pidl);
573
574         return 0;
575 }
576
577 /*************************************************************************
578  * ILGetSize [SHELL32.152]
579  *  gets the byte size of an idlist including zero terminator (pidl)
580  *
581  * PARAMETERS
582  *  pidl ITEMIDLIST
583  *
584  * RETURNS
585  *  size of pidl
586  *
587  * NOTES
588  *  exported by ordinal
589  */
590 DWORD WINAPI ILGetSize(LPITEMIDLIST pidl)
591 {
592         LPSHITEMID si = &(pidl->mkid);
593         DWORD  len=0;
594
595         if (pidl)
596         { while (si->cb) 
597           { len += si->cb;
598             si  = (LPSHITEMID)(((LPBYTE)si)+si->cb);
599           }
600           len += 2;
601         }
602         TRACE("pidl=%p size=%lu\n",pidl, len);
603         return len;
604 }
605
606 /*************************************************************************
607  * ILGetNext [SHELL32.153]
608  *  gets the next simple pidl of a complex pidl
609  *
610  * observed return values:
611  *  null -> null
612  *  desktop -> null
613  *  simple pidl -> pointer to 0x0000 element
614  *
615  */
616 LPITEMIDLIST WINAPI ILGetNext(LPITEMIDLIST pidl)
617 {
618         WORD len;
619         
620         TRACE("(pidl=%p)\n",pidl);
621
622         if(pidl)
623         {
624           len =  pidl->mkid.cb;
625           if (len)
626           {
627             pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
628             return pidl;
629           }
630         }
631         return NULL;
632 }
633 /*************************************************************************
634  * ILAppend [SHELL32.154]
635  *
636  * NOTES
637  *  Adds the single item to the idlist indicated by pidl.
638  *  if bEnd is 0, adds the item to the front of the list,
639  *  otherwise adds the item to the end. (???)
640  *  Destroys the passed in idlist! (???)
641  */
642 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl,LPCITEMIDLIST item,BOOL bEnd)
643 {
644         LPITEMIDLIST idlRet;
645
646         WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
647
648         pdump (pidl);
649         pdump (item);
650         
651         if (_ILIsDesktop(pidl))
652         {
653            idlRet = ILClone(item);
654            if (pidl)
655              SHFree (pidl);
656            return idlRet;
657         }
658
659         if (bEnd)
660         {
661           idlRet=ILCombine(pidl,item);
662         }
663         else
664         {
665           idlRet=ILCombine(item,pidl);
666         }
667
668         SHFree(pidl);
669         return idlRet;
670 }
671 /*************************************************************************
672  * ILFree [SHELL32.155]
673  *
674  * NOTES
675  *     free_check_ptr - frees memory (if not NULL)
676  *     allocated by SHMalloc allocator
677  *     exported by ordinal
678  */
679 DWORD WINAPI ILFree(LPITEMIDLIST pidl) 
680 {       TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
681
682         if (!pidl)
683           return FALSE;
684
685         return SHFree(pidl);
686 }
687 /*************************************************************************
688  * ILGlobalFree [SHELL32.156]
689  *
690  */
691 DWORD WINAPI ILGlobalFree( LPITEMIDLIST pidl)
692 {
693         TRACE("%p\n",pidl);
694
695         if (!pidl)
696           return FALSE;
697
698         return pCOMCTL32_Free (pidl);
699 }
700 /*************************************************************************
701  * ILCreateFromPath [SHELL32.157]
702  *
703  */
704 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path) 
705 {
706         LPITEMIDLIST pidlnew;
707         DWORD attributes = 0;
708
709         TRACE_(shell)("%s\n",path);
710
711         if (SUCCEEDED (SHILCreateFromPathA (path, &pidlnew, &attributes)))
712           return pidlnew;
713         return FALSE;
714 }
715 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path) 
716 {
717         LPITEMIDLIST pidlnew;
718         DWORD attributes = 0;
719
720         TRACE_(shell)("%s\n",debugstr_w(path));
721
722         if (SUCCEEDED (SHILCreateFromPathW (path, &pidlnew, &attributes)))
723           return pidlnew;
724         return FALSE;
725 }
726 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path) 
727 {
728         if ( VERSION_OsIsUnicode())
729           return ILCreateFromPathW (path);
730         return ILCreateFromPathA (path);
731 }
732 /*************************************************************************
733  *  SHSimpleIDListFromPath [SHELL32.162]
734  */
735 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPSTR lpszPath)
736 {
737         LPITEMIDLIST    pidl=NULL;
738         HANDLE  hFile;
739         WIN32_FIND_DATAA        stffile;
740
741         TRACE("path=%s\n", lpszPath);
742
743         if (!lpszPath) return NULL;
744
745         hFile = FindFirstFileA(lpszPath, &stffile);
746
747         if ( hFile != INVALID_HANDLE_VALUE )
748         {
749           if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
750           {
751             pidl = _ILCreateFolder (&stffile);
752           }
753           else
754           {
755             pidl = _ILCreateValue (&stffile);
756           }
757           FindClose (hFile);
758         }
759         return pidl;
760 }
761 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPWSTR lpszPath)
762 {
763         char    lpszTemp[MAX_PATH];
764         TRACE("path=%s\n",debugstr_w(lpszPath));
765
766         lstrcpynWtoA(lpszTemp, lpszPath, MAX_PATH);     
767
768         return SHSimpleIDListFromPathA (lpszTemp);
769 }
770
771 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW (LPVOID lpszPath)
772 {
773         if ( VERSION_OsIsUnicode())
774           return SHSimpleIDListFromPathW (lpszPath);
775         return SHSimpleIDListFromPathA (lpszPath);
776 }
777
778 /*************************************************************************
779  * SHGetSpecialFolderLocation           [SHELL32.223]
780  *
781  * gets the folder locations from the registry and creates a pidl
782  * creates missing reg keys and directorys
783  * 
784  * PARAMS
785  *   hwndOwner [I]
786  *   nFolder   [I] CSIDL_xxxxx
787  *   ppidl     [O] PIDL of a special folder
788  *
789  */
790 HRESULT WINAPI SHGetSpecialFolderLocation(
791         HWND hwndOwner,
792         INT nFolder,
793         LPITEMIDLIST * ppidl)
794 {
795         CHAR            szPath[MAX_PATH];
796         HRESULT         hr = E_INVALIDARG;
797
798         TRACE_(shell)("(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
799
800         *ppidl = NULL;
801
802         if (ppidl)
803         {
804           switch (nFolder)
805           {
806             case CSIDL_DESKTOP:
807               *ppidl = _ILCreateDesktop();
808               hr = NOERROR;
809               break;
810
811             case CSIDL_DRIVES:
812               *ppidl = _ILCreateMyComputer();
813               hr = NOERROR;
814               break;
815
816             case CSIDL_NETWORK:
817               *ppidl = _ILCreateNetwork ();
818               hr = NOERROR;
819               break;
820
821             case CSIDL_CONTROLS:
822               *ppidl = _ILCreateControl ();
823               hr = NOERROR;
824               break;
825
826             case CSIDL_PRINTERS:
827               *ppidl = _ILCreatePrinter ();
828               hr = NOERROR;
829               break;
830
831             case CSIDL_BITBUCKET:
832               *ppidl = _ILCreateBitBucket ();
833               hr = NOERROR;
834               break;
835
836             default:
837               if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
838               {
839                 DWORD attributes=0;
840                 TRACE_(shell)("Value=%s\n",szPath);
841                 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
842               }
843           }
844         }
845
846         TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
847         return hr;
848 }
849
850 /*************************************************************************
851  * SHGetDataFromIDListA [SHELL32.247]
852  *
853  * NOTES
854  *  the pidl can be a simple one. since we cant get the path out of the pidl
855  *  we have to take all data from the pidl
856  */
857 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
858 {
859         TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
860         
861         if (! psf || !dest )  return E_INVALIDARG;
862
863         switch (nFormat)
864         {
865           case SHGDFIL_FINDDATA:
866             {
867                WIN32_FIND_DATAA * pfd = dest;
868
869                if ( len < sizeof (WIN32_FIND_DATAA)) return E_INVALIDARG;
870
871                ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
872                _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
873                pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
874                pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
875                lstrcpynA(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
876                lstrcpynA(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
877             }
878             return NOERROR;
879
880           case SHGDFIL_NETRESOURCE:
881           case SHGDFIL_DESCRIPTIONID:
882             FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
883             break;
884
885           default:
886             ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
887         }
888
889         return E_INVALIDARG;
890 }
891 /*************************************************************************
892  * SHGetDataFromIDListW [SHELL32.247]
893  *
894  */
895 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
896 {
897         if (! psf || !dest )  return E_INVALIDARG;
898
899         switch (nFormat)
900         {
901           case SHGDFIL_FINDDATA:
902             {
903                WIN32_FIND_DATAW * pfd = dest;
904
905                if ( len < sizeof (WIN32_FIND_DATAW)) return E_INVALIDARG;
906
907                ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
908                _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
909                pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
910                pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
911                lstrcpynAtoW(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
912                lstrcpynAtoW(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
913             }
914             return NOERROR;
915           case SHGDFIL_NETRESOURCE:
916           case SHGDFIL_DESCRIPTIONID:
917             FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
918             break;
919
920           default:
921             ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
922         }
923
924         return E_INVALIDARG;
925 }
926
927 /*************************************************************************
928  * SHGetPathFromIDListA         [SHELL32.261][NT 4.0: SHELL32.220]
929  *
930  * PARAMETERS
931  *  pidl,   [IN] pidl 
932  *  pszPath [OUT] path
933  *
934  * RETURNS 
935  *  path from a passed PIDL.
936  *
937  * NOTES
938  *      NULL returns FALSE
939  *      desktop pidl gives path to desktopdirectory back
940  *      special pidls returning FALSE
941  *
942  * FIXME
943  *  fnGetDisplayNameOf can return different types of OLEString
944  */
945 BOOL WINAPI SHGetPathFromIDListA (LPCITEMIDLIST pidl,LPSTR pszPath)
946 {       STRRET str;
947         LPSHELLFOLDER shellfolder;
948
949         TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
950
951         if (!pidl) return FALSE;
952
953         pdump(pidl);
954
955         if(_ILIsDesktop(pidl))
956         {
957            SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOPDIRECTORY, FALSE);  
958         }
959         else
960         {
961           if (SHGetDesktopFolder(&shellfolder)==S_OK)
962           {
963             IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
964             StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
965             IShellFolder_Release(shellfolder);
966           }
967         }
968         TRACE_(shell)("-- (%s)\n",pszPath);
969
970         return TRUE;
971 }
972 /*************************************************************************
973  * SHGetPathFromIDListW                         [SHELL32.262]
974  */
975 BOOL WINAPI SHGetPathFromIDListW (LPCITEMIDLIST pidl,LPWSTR pszPath)
976 {       char sTemp[MAX_PATH];
977
978         TRACE_(shell)("(pidl=%p)\n", pidl);
979
980         SHGetPathFromIDListA (pidl, sTemp);
981         lstrcpyAtoW(pszPath, sTemp);
982
983         TRACE_(shell)("-- (%s)\n",debugstr_w(pszPath));
984
985         return TRUE;
986 }
987
988 /*************************************************************************
989  *      SHBindToParent          [shell version 5.0]
990  */
991 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
992 {
993         IShellFolder    * psf;
994         LPITEMIDLIST    pidlChild, pidlParent;
995         HRESULT         hr=E_FAIL;
996         
997         TRACE_(shell)("pidl=%p\n", pidl);
998         pdump(pidl);
999         
1000         *ppv = NULL;
1001         if (ppidlLast) *ppidlLast = NULL;
1002
1003         if (_ILIsPidlSimple(pidl))
1004         {
1005           /* we are on desktop level */
1006           if (ppidlLast) 
1007             *ppidlLast = ILClone(pidl);
1008           hr = SHGetDesktopFolder((IShellFolder**)ppv);
1009         }
1010         else
1011         {
1012           pidlChild =  ILClone(ILFindLastID(pidl));
1013           pidlParent = ILClone(pidl);
1014           ILRemoveLastID(pidlParent);
1015
1016           hr = SHGetDesktopFolder(&psf);
1017
1018           if (SUCCEEDED(hr))
1019             hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1020
1021           if (SUCCEEDED(hr) && ppidlLast)
1022             *ppidlLast = pidlChild;
1023           else
1024             ILFree (pidlChild);
1025
1026           SHFree (pidlParent);
1027           if (psf) IShellFolder_Release(psf);
1028         }
1029
1030
1031         TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1032         return hr;
1033 }
1034
1035 /*************************************************************************
1036  * SHGetPathFromIDListAW                [SHELL32.221][NT 4.0: SHELL32.219]
1037  */
1038 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1039 {
1040         TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1041
1042         if (VERSION_OsIsUnicode())
1043           return SHGetPathFromIDListW(pidl,pszPath);
1044         return SHGetPathFromIDListA(pidl,pszPath);
1045 }
1046
1047 /**************************************************************************
1048  *
1049  *              internal functions
1050  *
1051  *      ### 1. section creating pidls ###
1052  *
1053  *************************************************************************
1054  *  _ILCreateDesktop()
1055  *  _ILCreateIExplore()
1056  *  _ILCreateMyComputer()
1057  *  _ILCreateDrive()
1058  *  _ILCreateFolder() 
1059  *  _ILCreateValue()
1060  */
1061 LPITEMIDLIST _ILCreateDesktop()
1062 {       TRACE("()\n");
1063         return _ILCreate(PT_DESKTOP, NULL, 0);
1064 }
1065
1066 LPITEMIDLIST _ILCreateMyComputer()
1067 {       TRACE("()\n");
1068         return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1069 }
1070
1071 LPITEMIDLIST _ILCreateIExplore()
1072 {       TRACE("()\n");
1073         return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1074 }
1075
1076 LPITEMIDLIST _ILCreateControl()
1077 {       TRACE("()\n");
1078         return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1079 }
1080
1081 LPITEMIDLIST _ILCreatePrinter()
1082 {       TRACE("()\n");
1083         return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1084 }
1085
1086 LPITEMIDLIST _ILCreateNetwork()
1087 {       TRACE("()\n");
1088         return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1089 }
1090
1091 LPITEMIDLIST _ILCreateBitBucket()
1092 {       TRACE("()\n");
1093         return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1094 }
1095
1096 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1097 {       char sTemp[4];
1098         lstrcpynA (sTemp,lpszNew,4);
1099         sTemp[2]='\\';
1100         sTemp[3]=0x00;
1101         TRACE("(%s)\n",sTemp);
1102         return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1103 }
1104
1105 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1106 {
1107         char    buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1108         char *  pbuff = buff;
1109         ULONG   len, len1;
1110         LPITEMIDLIST pidl;
1111         
1112         TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1113
1114         /* prepare buffer with both names */
1115         len = strlen (stffile->cFileName) + 1;
1116         memcpy (pbuff, stffile->cFileName, len);
1117         pbuff += len;
1118
1119         if (stffile->cAlternateFileName)
1120         {
1121           len1 = strlen (stffile->cAlternateFileName)+1;
1122           memcpy (pbuff, stffile->cAlternateFileName, len1);
1123         }
1124         else
1125         {
1126           len1 = 1;
1127           *pbuff = 0x00;
1128         }
1129
1130         pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1131         
1132         /* set attributes */
1133         if (pidl)
1134         {
1135           LPPIDLDATA pData;
1136           pData = _ILGetDataPointer(pidl);
1137           FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1138           pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1139           pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1140         }
1141
1142         return pidl;
1143 }
1144
1145 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1146 {
1147         char    buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1148         char *  pbuff = buff;
1149         ULONG   len, len1;
1150         LPITEMIDLIST pidl;
1151         
1152         TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1153
1154         /* prepare buffer with both names */
1155         len = strlen (stffile->cFileName) + 1;
1156         memcpy (pbuff, stffile->cFileName, len);
1157         pbuff += len;
1158
1159         if (stffile->cAlternateFileName)
1160         {
1161           len1 = strlen (stffile->cAlternateFileName)+1;
1162           memcpy (pbuff, stffile->cAlternateFileName, len1);
1163         }
1164         else
1165         {
1166           len1 = 1;
1167           *pbuff = 0x00;
1168         }
1169
1170         pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1171         
1172         /* set attributes */
1173         if (pidl)
1174         {
1175           LPPIDLDATA pData;
1176           pData = _ILGetDataPointer(pidl);
1177           FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1178           pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1179           pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1180         }
1181
1182         return pidl;
1183 }
1184
1185 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1186 {
1187         IID     iid;
1188         CLSIDFromString16(szGUID,&iid);
1189         return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1190 }
1191
1192 /**************************************************************************
1193  *  _ILCreate()
1194  *  Creates a new PIDL
1195  *  type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1196  *  pIn = data
1197  *  uInSize = size of data (raw)
1198  */
1199
1200 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT16 uInSize)
1201 {       LPITEMIDLIST   pidlOut = NULL, pidlTemp = NULL;
1202         LPPIDLDATA     pData;
1203         UINT16         uSize = 0;
1204         LPSTR   pszDest;
1205         
1206         TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1207
1208         switch (type)
1209         { case PT_DESKTOP:
1210             uSize = 0;
1211             pidlOut = SHAlloc(uSize + 2);
1212             pidlOut->mkid.cb = uSize;
1213             TRACE("- create Desktop\n");
1214             break;
1215
1216           case PT_MYCOMP:
1217             uSize = 2 + 2 + sizeof(GUID);
1218             pidlOut = SHAlloc(uSize + 2);
1219             ZeroMemory(pidlOut, uSize + 2);
1220             pidlOut->mkid.cb = uSize;
1221             pData =_ILGetDataPointer(pidlOut);
1222             pData->type = type;
1223             memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1224             TRACE("- create GUID-pidl\n");
1225             break;
1226
1227           case PT_DRIVE:
1228             uSize = 2 + 23;
1229             pidlOut = SHAlloc(uSize + 2);
1230             ZeroMemory(pidlOut, uSize + 2);
1231             pidlOut->mkid.cb = uSize;
1232             pData =_ILGetDataPointer(pidlOut);
1233             pData->type = type;
1234             pszDest = _ILGetTextPointer(pidlOut);
1235             memcpy(pszDest, pIn, uInSize);
1236             TRACE("- create Drive: %s\n",debugstr_a(pszDest));
1237             break;
1238
1239           case PT_FOLDER:
1240           case PT_VALUE:   
1241             uSize = 2 + 12 + uInSize;
1242             pidlOut = SHAlloc(uSize + 2);
1243             ZeroMemory(pidlOut, uSize + 2);
1244             pidlOut->mkid.cb = uSize;
1245             pData =_ILGetDataPointer(pidlOut);
1246             pData->type = type;
1247             pszDest =  _ILGetTextPointer(pidlOut);
1248             memcpy(pszDest, pIn, uInSize);
1249             TRACE("- create Value: %s\n",debugstr_a(pszDest));
1250             break;
1251         }
1252         
1253         pidlTemp = ILGetNext(pidlOut);
1254         if (pidlTemp)
1255           pidlTemp->mkid.cb = 0x00;
1256
1257         TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1258         return pidlOut;
1259 }
1260
1261 /**************************************************************************
1262  *  _ILGetDrive()
1263  *
1264  *  Gets the text for the drive eg. 'c:\'
1265  *
1266  * RETURNS
1267  *  strlen (lpszText)
1268  */
1269 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT16 uSize)
1270 {       TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1271
1272         if(_ILIsMyComputer(pidl))
1273           pidl = ILGetNext(pidl);
1274
1275         if (pidl && _ILIsDrive(pidl))
1276           return _ILSimpleGetText(pidl, pOut, uSize);
1277
1278         return 0;
1279 }
1280
1281 /**************************************************************************
1282  *
1283  *      ### 2. section testing pidls ###
1284  *
1285  **************************************************************************
1286  *  _ILIsDesktop()
1287  *  _ILIsMyComputer()
1288  *  _ILIsSpecialFolder()
1289  *  _ILIsDrive()
1290  *  _ILIsFolder()
1291  *  _ILIsValue()
1292  *  _ILIsPidlSimple()
1293  */
1294 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1295 {       TRACE("(%p)\n",pidl);
1296         return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
1297 }
1298
1299 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1300 {
1301         REFIID iid = _ILGetGUIDPointer(pidl);
1302
1303         TRACE("(%p)\n",pidl);
1304
1305         if (iid)
1306           return IsEqualIID(iid, &CLSID_MyComputer);
1307         return FALSE;
1308 }
1309
1310 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1311 {
1312         LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1313         TRACE("(%p)\n",pidl);
1314         return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) || 
1315                           (pidl && pidl->mkid.cb == 0x00)
1316                         ));
1317 }
1318
1319 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1320 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1321         TRACE("(%p)\n",pidl);
1322         return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1323                                     PT_DRIVE1 == lpPData->type ||
1324                                     PT_DRIVE2 == lpPData->type ||
1325                                     PT_DRIVE3 == lpPData->type));
1326 }
1327
1328 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1329 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1330         TRACE("(%p)\n",pidl);
1331         return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1332 }
1333
1334 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1335 {       LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1336         TRACE("(%p)\n",pidl);
1337         return (pidl && lpPData && PT_VALUE == lpPData->type);
1338 }
1339
1340 /**************************************************************************
1341  *      _ILIsPidlSimple
1342  */
1343 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1344 {
1345         BOOL ret = TRUE;
1346
1347         if(! _ILIsDesktop(pidl))        /* pidl=NULL or mkid.cb=0 */
1348         {
1349           WORD len = pidl->mkid.cb;
1350           LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1351           if (pidlnext->mkid.cb)
1352             ret = FALSE;
1353         }
1354
1355         TRACE("%s\n", ret ? "Yes" : "No");
1356         return ret;
1357 }
1358
1359 /**************************************************************************
1360  *
1361  *      ### 3. section getting values from pidls ###
1362  */
1363
1364  /**************************************************************************
1365  *  _ILSimpleGetText
1366  *
1367  * gets the text for the first item in the pidl (eg. simple pidl)
1368  *
1369  * returns the lenght of the string
1370  */
1371 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1372 {
1373         DWORD           dwReturn=0; 
1374         LPSTR           szSrc;
1375         GUID const *    riid;
1376         char szTemp[MAX_PATH];
1377         
1378         TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1379         
1380         if (!pidl) return 0;
1381
1382         if (szOut)
1383           *szOut = 0;
1384
1385         if (_ILIsDesktop(pidl))                                 
1386         {
1387          /* desktop */
1388           if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1389           {
1390             if (szOut)
1391               lstrcpynA(szOut, szTemp, uOutSize);
1392
1393             dwReturn = strlen (szTemp);
1394           }
1395         }
1396         else if (( szSrc = _ILGetTextPointer(pidl) ))
1397         {
1398           /* filesystem */
1399           if (szOut)
1400             lstrcpynA(szOut, szSrc, uOutSize);
1401
1402           dwReturn = strlen(szSrc);
1403         }
1404         else if (( riid = _ILGetGUIDPointer(pidl) ))
1405         {
1406           /* special folder */
1407           if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
1408           {
1409             if (szOut)
1410               lstrcpynA(szOut, szTemp, uOutSize);
1411
1412             dwReturn = strlen (szTemp);
1413           }
1414         }
1415         else
1416         {
1417           ERR("-- no text\n");
1418         }
1419
1420         TRACE("-- (%p=%s 0x%08lx)\n",szOut,(char*)szOut,dwReturn);
1421         return dwReturn;
1422 }
1423
1424 /**************************************************************************
1425  *
1426  *      ### 4. getting pointers to parts of pidls ###
1427  *
1428  **************************************************************************
1429  *  _ILGetDataPointer()
1430  */
1431 LPPIDLDATA _ILGetDataPointer(LPITEMIDLIST pidl)
1432 {
1433         if(pidl && pidl->mkid.cb != 0x00)
1434           return (LPPIDLDATA) &(pidl->mkid.abID);
1435         return NULL;
1436 }
1437
1438 /**************************************************************************
1439  *  _ILGetTextPointer()
1440  * gets a pointer to the long filename string stored in the pidl
1441  */
1442 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1443 {/*     TRACE(pidl,"(pidl%p)\n", pidl);*/
1444
1445         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1446
1447         if (pdata)
1448         {
1449           switch (pdata->type)
1450           {
1451             case PT_MYCOMP:
1452             case PT_SPECIAL:
1453               return NULL;
1454
1455             case PT_DRIVE:
1456             case PT_DRIVE1:
1457             case PT_DRIVE2:
1458             case PT_DRIVE3:
1459               return (LPSTR)&(pdata->u.drive.szDriveName);
1460
1461             case PT_FOLDER:
1462             case PT_FOLDER1:
1463             case PT_VALUE:
1464             case PT_IESPECIAL:
1465               return (LPSTR)&(pdata->u.file.szNames);
1466
1467             case PT_WORKGRP:
1468             case PT_COMP:
1469             case PT_NETWORK:
1470             case PT_SHARE:
1471               return (LPSTR)&(pdata->u.network.szNames);
1472           }
1473         }
1474         return NULL;
1475 }
1476
1477 /**************************************************************************
1478  *  _ILGetSTextPointer()
1479  * gets a pointer to the short filename string stored in the pidl
1480  */
1481 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1482 {/*     TRACE(pidl,"(pidl%p)\n", pidl);*/
1483
1484         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1485
1486         if (pdata)
1487         {
1488           switch (pdata->type)
1489           {
1490             case PT_FOLDER:
1491             case PT_VALUE:
1492             case PT_IESPECIAL:
1493               return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1494
1495             case PT_WORKGRP:
1496               return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1497           }
1498         }
1499         return NULL;
1500 }
1501
1502 /**************************************************************************
1503  * _ILGetGUIDPointer()
1504  *
1505  * returns reference to guid stored in some pidls
1506  */
1507 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1508 {
1509         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1510
1511         if (pdata)
1512         {
1513           switch (pdata->type)
1514           {
1515             case PT_SPECIAL:
1516             case PT_MYCOMP:
1517               return (REFIID) &(pdata->u.mycomp.guid);
1518           }
1519         }
1520         return NULL;
1521 }
1522
1523 /*************************************************************************
1524  * _ILGetFileDateTime
1525  *
1526  * Given the ItemIdList, get the FileTime
1527  *
1528  * PARAMS
1529  *      pidl        [I] The ItemIDList
1530  *      pFt         [I] the resulted FILETIME of the file
1531  *
1532  * RETURNS
1533  *     True if Successful
1534  *
1535  * NOTES
1536  *     
1537  */
1538 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1539 {
1540     LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1541
1542     switch (pdata->type)
1543     { 
1544         case PT_FOLDER:
1545             DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1546             break;          
1547         case PT_VALUE:
1548             DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1549             break;
1550         default:
1551             return FALSE;
1552     }
1553     return TRUE;
1554 }
1555
1556 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1557 {       
1558         FILETIME ft;
1559         SYSTEMTIME time;
1560
1561         if (! _ILGetFileDateTime( pidl, &ft )) return FALSE;
1562         
1563         FileTimeToSystemTime (&ft, &time);
1564         return GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL,  pOut, uOutSize);
1565 }
1566
1567 /*************************************************************************
1568  * _ILGetFileSize
1569  *
1570  * Given the ItemIdList, get the FileSize
1571  *
1572  * PARAMS
1573  *      pidl    [I] The ItemIDList
1574  *      pOut    [I] The buffer to save the result
1575  *      uOutsize [I] The size of the buffer
1576  *
1577  * RETURNS
1578  *     The FileSize
1579  *
1580  * NOTES
1581  *      pOut can be null when no string is needed
1582  *     
1583  */
1584 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1585 {
1586         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1587         DWORD dwSize;
1588         
1589         switch (pdata->type)
1590         {
1591           case PT_VALUE:
1592             dwSize = pdata->u.file.dwFileSize;
1593             if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1594             return dwSize;
1595         }
1596         if (pOut) *pOut = 0x00;
1597         return 0;
1598 }
1599
1600 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1601 {
1602         char szTemp[MAX_PATH];
1603         const char * pPoint;
1604         LPITEMIDLIST  pidlTemp=pidl;
1605         
1606         TRACE("pidl=%p\n",pidl);
1607
1608         if (!pidl) return FALSE;
1609         
1610         pidlTemp = ILFindLastID(pidl);
1611         
1612         if (!_ILIsValue(pidlTemp)) return FALSE;
1613         if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1614
1615         pPoint = PathFindExtensionA(szTemp);
1616
1617         if (! *pPoint) return FALSE;
1618
1619         pPoint++;
1620         lstrcpynA(pOut, pPoint, uOutSize);
1621         TRACE("%s\n",pOut);
1622
1623         return TRUE;
1624 }
1625
1626 /*************************************************************************
1627  * _ILGetFileType
1628  *
1629  * Given the ItemIdList, get the file type description
1630  *
1631  * PARAMS
1632  *      pidl        [I] The ItemIDList (simple)
1633  *      pOut        [I] The buffer to save the result
1634  *      uOutsize    [I] The size of the buffer
1635  *
1636  * RETURNS
1637  *      nothing
1638  *
1639  * NOTES
1640  *      This function copies as much as possible into the buffer. 
1641  */
1642 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1643 {
1644         if(_ILIsValue(pidl))
1645         {
1646           char sTemp[64];
1647           if(uOutSize > 0)
1648           {
1649             pOut[0] = 0;
1650           }
1651           if (_ILGetExtension (pidl, sTemp, 64))
1652           {
1653             if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1654                 && HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
1655             {
1656               lstrcpynA (pOut, sTemp, uOutSize - 6);
1657               strcat (pOut, "-file");
1658             }
1659           }
1660         }
1661         else
1662         {
1663           lstrcpynA(pOut, "Folder", uOutSize);
1664         }
1665 }
1666
1667 /*************************************************************************
1668  * _ILGetFileAttributes
1669  *
1670  * Given the ItemIdList, get the Attrib string format
1671  *
1672  * PARAMS
1673  *      pidl        [I] The ItemIDList
1674  *      pOut        [I] The buffer to save the result
1675  *      uOutsize    [I] The size of the Buffer
1676  *
1677  * RETURNS
1678  *     Attributes
1679  *
1680  * NOTES
1681  *     
1682  */
1683 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1684 {
1685         LPPIDLDATA pData =_ILGetDataPointer(pidl);
1686         WORD wAttrib = 0;
1687         int i;
1688
1689         switch(pData->type)
1690         {
1691           case PT_FOLDER:
1692             wAttrib = pData->u.folder.uFileAttribs;
1693             break;
1694           case PT_VALUE:
1695             wAttrib = pData->u.file.uFileAttribs;
1696             break;
1697         }
1698         
1699         if(uOutSize >= 6)
1700         {
1701           i=0;
1702           if(wAttrib & FILE_ATTRIBUTE_READONLY)
1703           {
1704             pOut[i++] = 'R';
1705           }
1706           if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
1707           {
1708             pOut[i++] = 'H';
1709           }
1710           if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
1711           {
1712             pOut[i++] = 'S';
1713           }
1714           if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
1715           {
1716             pOut[i++] = 'A';
1717           }
1718           if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
1719           {
1720             pOut[i++] = 'C';
1721           }
1722           pOut[i] = 0x00;
1723         }
1724         return wAttrib;
1725 }
1726