4 * Copyright 1998 Juergen Schmied
7 * a pidl == NULL means desktop and is legal
16 #include "debugtools.h"
21 #include "winversion.h"
22 #include "shell32_main.h"
26 #include "wine/undocshell.h"
28 DEFAULT_DEBUG_CHANNEL(pidl)
29 DECLARE_DEBUG_CHANNEL(shell)
31 void pdump (LPCITEMIDLIST pidl)
35 char szName[MAX_PATH];
38 LPITEMIDLIST pidltemp = pidl;
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);
49 MESSAGE ("-------- pidl=NULL (Desktop)\n");
53 MESSAGE ("-------- pidl=%p\n", pidl);
54 if (pidltemp->mkid.cb)
58 type = _ILGetDataPointer(pidltemp)->type;
59 szData = _ILGetTextPointer(pidltemp);
60 szShortName = _ILGetSTextPointer(pidltemp);
61 _ILSimpleGetText(pidltemp, szName, MAX_PATH);
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));
66 pidltemp = ILGetNext(pidltemp);
68 } while (pidltemp->mkid.cb);
72 MESSAGE ("empty pidl (Desktop)\n");
77 __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, bIsShellDebug);
78 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, TRUE);
81 #define BYTES_PRINTED 32
82 BOOL pcheck (LPCITEMIDLIST pidl)
83 { DWORD type, ret=TRUE;
86 LPITEMIDLIST pidltemp = pidl;
88 bIsPidlDebug = TRACE_ON(shell);
89 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
91 if (pidltemp && pidltemp->mkid.cb)
93 { type = _ILGetDataPointer(pidltemp)->type;
113 char szTemp[BYTES_PRINTED*4 + 1];
117 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
118 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
120 c = ((unsigned char *)pidltemp)[i];
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;
125 szTemp[i+BYTES_PRINTED*3] = (c>=0x20 && c <=0x80) ? c : '.';
127 szTemp[BYTES_PRINTED*4] = 0x00;
128 ERR("unknown IDLIST type size=%u type=%lx\n%s\n",pidltemp->mkid.cb,type, szTemp);
132 pidltemp = ILGetNext(pidltemp);
133 } while (pidltemp->mkid.cb);
135 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, bIsPidlDebug);
139 /*************************************************************************
140 * ILGetDisplayName [SHELL32.15]
142 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl,LPSTR path)
144 TRACE_(shell)("pidl=%p %p semi-stub\n",pidl,path);
145 return SHGetPathFromIDListA(pidl, path);
147 /*************************************************************************
148 * ILFindLastID [SHELL32.16]
151 * observed: pidl=Desktop return=pidl
153 LPITEMIDLIST WINAPI ILFindLastID(LPITEMIDLIST pidl)
154 { LPITEMIDLIST pidlLast = pidl;
156 TRACE("(pidl=%p)\n",pidl);
158 while (pidl->mkid.cb)
161 pidl = ILGetNext(pidl);
165 /*************************************************************************
166 * ILRemoveLastID [SHELL32.17]
169 * when pidl=Desktop return=FALSE
171 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
173 TRACE_(shell)("pidl=%p\n",pidl);
175 if (!pidl || !pidl->mkid.cb)
177 ILFindLastID(pidl)->mkid.cb = 0;
181 /*************************************************************************
182 * ILClone [SHELL32.18]
187 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
189 LPITEMIDLIST newpidl;
194 len = ILGetSize(pidl);
195 newpidl = (LPITEMIDLIST)SHAlloc(len);
197 memcpy(newpidl,pidl,len);
199 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
204 /*************************************************************************
205 * ILCloneFirst [SHELL32.19]
208 * duplicates the first idlist of a complex pidl
210 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
212 LPITEMIDLIST pidlNew = NULL;
214 TRACE("pidl=%p \n",pidl);
220 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
223 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
226 ILGetNext(pidlNew)->mkid.cb = 0x00;
229 TRACE("-- newpidl=%p\n",pidlNew);
233 /*************************************************************************
237 * the first two bytes are the len, the pidl is following then
239 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
242 HRESULT ret = E_FAIL;
245 TRACE_(shell)("%p %p\n", pStream , ppPidl);
252 IStream_AddRef (pStream);
254 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
255 { *ppPidl = SHAlloc (wLen);
256 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
265 /* we are not jet fully compatible */
266 if (!pcheck(*ppPidl))
272 IStream_Release (pStream);
276 /*************************************************************************
277 * SHILCreateFromPath [SHELL32.28]
280 * wraper for IShellFolder::ParseDisplayName()
282 HRESULT WINAPI SHILCreateFromPathA (LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
284 WCHAR lpszDisplayName[MAX_PATH];
286 HRESULT ret = E_FAIL;
288 TRACE_(shell)("%s %p 0x%08lx\n",path,ppidl,attributes?*attributes:0);
290 lstrcpynAtoW(lpszDisplayName, path, MAX_PATH);
292 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
294 ret = IShellFolder_ParseDisplayName(sf,0, NULL,lpszDisplayName,&pchEaten,ppidl,attributes);
295 IShellFolder_Release(sf);
299 HRESULT WINAPI SHILCreateFromPathW (LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
302 HRESULT ret = E_FAIL;
304 TRACE_(shell)("%s %p 0x%08lx\n",debugstr_w(path),ppidl,attributes?*attributes:0);
306 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
308 ret = IShellFolder_ParseDisplayName(sf,0, NULL, (LPWSTR) path, &pchEaten, ppidl, attributes);
309 IShellFolder_Release(sf);
313 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
315 if ( VERSION_OsIsUnicode())
316 return SHILCreateFromPathW (path, ppidl, attributes);
317 return SHILCreateFromPathA (path, ppidl, attributes);
320 /*************************************************************************
321 * SHCloneSpecialIDList [SHELL32.89]
325 * nFolder [in] CSIDL_xxxxx ??
330 * exported by ordinal
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);
337 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
342 /*************************************************************************
343 * ILGlobalClone [SHELL32.97]
346 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
348 LPITEMIDLIST newpidl;
353 len = ILGetSize(pidl);
354 newpidl = (LPITEMIDLIST)pCOMCTL32_Alloc(len);
356 memcpy(newpidl,pidl,len);
358 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
364 /*************************************************************************
365 * ILIsEqual [SHELL32.21]
368 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
370 char szData1[MAX_PATH];
371 char szData2[MAX_PATH];
373 LPITEMIDLIST pidltemp1 = pidl1;
374 LPITEMIDLIST pidltemp2 = pidl2;
376 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
378 /* explorer reads from registry directly (StreamMRU),
379 so we can only check here */
380 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
385 if ( (!pidl1) || (!pidl2) ) return FALSE;
387 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
389 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
390 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
392 if (strcasecmp ( szData1, szData2 )!=0 )
395 pidltemp1 = ILGetNext(pidltemp1);
396 pidltemp2 = ILGetNext(pidltemp2);
399 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
406 /*************************************************************************
407 * ILIsParent [SHELL32.23]
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
413 BOOL WINAPI ILIsParent( LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
415 char szData1[MAX_PATH];
416 char szData2[MAX_PATH];
418 LPITEMIDLIST pParent = pidlParent;
419 LPITEMIDLIST pChild = pidlChild;
421 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
423 while (pParent->mkid.cb && pChild->mkid.cb)
425 _ILSimpleGetText(pParent, szData1, MAX_PATH);
426 _ILSimpleGetText(pChild, szData2, MAX_PATH);
428 if (strcasecmp ( szData1, szData2 )!=0 )
431 pParent = ILGetNext(pParent);
432 pChild = ILGetNext(pChild);
435 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
438 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
444 /*************************************************************************
445 * ILFindChild [SHELL32.24]
448 * Compares elements from pidl1 and pidl2.
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
456 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
458 char szData1[MAX_PATH];
459 char szData2[MAX_PATH];
461 LPITEMIDLIST pidltemp1 = pidl1;
462 LPITEMIDLIST pidltemp2 = pidl2;
463 LPITEMIDLIST ret=NULL;
465 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
467 /* explorer reads from registry directly (StreamMRU),
468 so we can only check here */
469 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
475 if ( _ILIsDesktop(pidl1) )
481 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
483 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
484 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
486 if (strcasecmp(szData1,szData2))
489 pidltemp1 = ILGetNext(pidltemp1);
490 pidltemp2 = ILGetNext(pidltemp2);
494 if (pidltemp1->mkid.cb)
496 ret = NULL; /* elements of pidl1 left*/
499 TRACE_(shell)("--- %p\n", ret);
500 return ret; /* pidl 1 is shorter */
503 /*************************************************************************
504 * ILCombine [SHELL32.25]
507 * Concatenates two complex idlists.
508 * The pidl is the first one, pidlsub the next one
509 * Does not destroy the passed in idlists!
511 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
514 LPITEMIDLIST pidlNew;
516 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
518 if(!pidl1 && !pidl2) return NULL;
525 pidlNew = ILClone(pidl2);
531 pidlNew = ILClone(pidl1);
535 len1 = ILGetSize(pidl1)-2;
536 len2 = ILGetSize(pidl2);
537 pidlNew = SHAlloc(len1+len2);
541 memcpy(pidlNew,pidl1,len1);
542 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
545 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
548 /*************************************************************************
549 * SHGetRealIDL [SHELL32.98]
553 LPITEMIDLIST WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl, DWORD z)
555 FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf,pidl,z);
561 /*************************************************************************
562 * SHLogILFromFSIL [SHELL32.95]
565 * pild = CSIDL_DESKTOP ret = 0
566 * pild = CSIDL_DRIVES ret = 0
568 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
570 FIXME("(pidl=%p)\n",pidl);
577 /*************************************************************************
578 * ILGetSize [SHELL32.152]
579 * gets the byte size of an idlist including zero terminator (pidl)
588 * exported by ordinal
590 DWORD WINAPI ILGetSize(LPITEMIDLIST pidl)
592 LPSHITEMID si = &(pidl->mkid);
598 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
602 TRACE("pidl=%p size=%lu\n",pidl, len);
606 /*************************************************************************
607 * ILGetNext [SHELL32.153]
608 * gets the next simple pidl of a complex pidl
610 * observed return values:
613 * simple pidl -> pointer to 0x0000 element
616 LPITEMIDLIST WINAPI ILGetNext(LPITEMIDLIST pidl)
620 TRACE("(pidl=%p)\n",pidl);
627 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
633 /*************************************************************************
634 * ILAppend [SHELL32.154]
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! (???)
642 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl,LPCITEMIDLIST item,BOOL bEnd)
646 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
651 if (_ILIsDesktop(pidl))
653 idlRet = ILClone(item);
661 idlRet=ILCombine(pidl,item);
665 idlRet=ILCombine(item,pidl);
671 /*************************************************************************
672 * ILFree [SHELL32.155]
675 * free_check_ptr - frees memory (if not NULL)
676 * allocated by SHMalloc allocator
677 * exported by ordinal
679 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
680 { TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
687 /*************************************************************************
688 * ILGlobalFree [SHELL32.156]
691 DWORD WINAPI ILGlobalFree( LPITEMIDLIST pidl)
698 return pCOMCTL32_Free (pidl);
700 /*************************************************************************
701 * ILCreateFromPath [SHELL32.157]
704 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
706 LPITEMIDLIST pidlnew;
707 DWORD attributes = 0;
709 TRACE_(shell)("%s\n",path);
711 if (SUCCEEDED (SHILCreateFromPathA (path, &pidlnew, &attributes)))
715 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
717 LPITEMIDLIST pidlnew;
718 DWORD attributes = 0;
720 TRACE_(shell)("%s\n",debugstr_w(path));
722 if (SUCCEEDED (SHILCreateFromPathW (path, &pidlnew, &attributes)))
726 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
728 if ( VERSION_OsIsUnicode())
729 return ILCreateFromPathW (path);
730 return ILCreateFromPathA (path);
732 /*************************************************************************
733 * SHSimpleIDListFromPath [SHELL32.162]
735 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPCSTR lpszPath)
737 LPITEMIDLIST pidl=NULL;
739 WIN32_FIND_DATAA stffile;
741 TRACE("path=%s\n", lpszPath);
743 if (!lpszPath) return NULL;
745 hFile = FindFirstFileA(lpszPath, &stffile);
747 if ( hFile != INVALID_HANDLE_VALUE )
749 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
751 pidl = _ILCreateFolder (&stffile);
755 pidl = _ILCreateValue (&stffile);
761 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPCWSTR lpszPath)
763 char lpszTemp[MAX_PATH];
764 TRACE("path=%s\n",debugstr_w(lpszPath));
766 lstrcpynWtoA(lpszTemp, lpszPath, MAX_PATH);
768 return SHSimpleIDListFromPathA (lpszTemp);
771 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW (LPCVOID lpszPath)
773 if ( VERSION_OsIsUnicode())
774 return SHSimpleIDListFromPathW (lpszPath);
775 return SHSimpleIDListFromPathA (lpszPath);
778 /*************************************************************************
779 * SHGetSpecialFolderLocation [SHELL32.223]
781 * gets the folder locations from the registry and creates a pidl
782 * creates missing reg keys and directorys
786 * nFolder [I] CSIDL_xxxxx
787 * ppidl [O] PIDL of a special folder
790 HRESULT WINAPI SHGetSpecialFolderLocation(
793 LPITEMIDLIST * ppidl)
795 CHAR szPath[MAX_PATH];
796 HRESULT hr = E_INVALIDARG;
798 TRACE_(shell)("(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
807 *ppidl = _ILCreateDesktop();
812 *ppidl = _ILCreateMyComputer();
817 *ppidl = _ILCreateNetwork ();
822 *ppidl = _ILCreateControl ();
827 *ppidl = _ILCreatePrinter ();
831 case CSIDL_BITBUCKET:
832 *ppidl = _ILCreateBitBucket ();
837 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
840 TRACE_(shell)("Value=%s\n",szPath);
841 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
846 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
850 /*************************************************************************
851 * SHGetDataFromIDListA [SHELL32.247]
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
857 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
859 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
861 if (! psf || !dest ) return E_INVALIDARG;
865 case SHGDFIL_FINDDATA:
867 WIN32_FIND_DATAA * pfd = dest;
869 if ( len < sizeof (WIN32_FIND_DATAA)) return E_INVALIDARG;
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);
880 case SHGDFIL_NETRESOURCE:
881 case SHGDFIL_DESCRIPTIONID:
882 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
886 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
891 /*************************************************************************
892 * SHGetDataFromIDListW [SHELL32.247]
895 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
897 if (! psf || !dest ) return E_INVALIDARG;
901 case SHGDFIL_FINDDATA:
903 WIN32_FIND_DATAW * pfd = dest;
905 if ( len < sizeof (WIN32_FIND_DATAW)) return E_INVALIDARG;
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);
915 case SHGDFIL_NETRESOURCE:
916 case SHGDFIL_DESCRIPTIONID:
917 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
921 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
927 /*************************************************************************
928 * SHGetPathFromIDListA [SHELL32.261][NT 4.0: SHELL32.220]
935 * path from a passed PIDL.
939 * desktop pidl gives path to desktopdirectory back
940 * special pidls returning FALSE
943 * fnGetDisplayNameOf can return different types of OLEString
945 BOOL WINAPI SHGetPathFromIDListA (LPCITEMIDLIST pidl,LPSTR pszPath)
947 LPSHELLFOLDER shellfolder;
949 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
951 if (!pidl) return FALSE;
955 if(_ILIsDesktop(pidl))
957 SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
961 if (SHGetDesktopFolder(&shellfolder)==S_OK)
963 IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
964 StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
965 IShellFolder_Release(shellfolder);
968 TRACE_(shell)("-- (%s)\n",pszPath);
972 /*************************************************************************
973 * SHGetPathFromIDListW [SHELL32.262]
975 BOOL WINAPI SHGetPathFromIDListW (LPCITEMIDLIST pidl,LPWSTR pszPath)
976 { char sTemp[MAX_PATH];
978 TRACE_(shell)("(pidl=%p)\n", pidl);
980 SHGetPathFromIDListA (pidl, sTemp);
981 lstrcpyAtoW(pszPath, sTemp);
983 TRACE_(shell)("-- (%s)\n",debugstr_w(pszPath));
988 /*************************************************************************
989 * SHBindToParent [shell version 5.0]
991 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
994 LPITEMIDLIST pidlChild, pidlParent;
997 TRACE_(shell)("pidl=%p\n", pidl);
1001 if (ppidlLast) *ppidlLast = NULL;
1003 if (_ILIsPidlSimple(pidl))
1005 /* we are on desktop level */
1007 *ppidlLast = ILClone(pidl);
1008 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1012 pidlChild = ILClone(ILFindLastID(pidl));
1013 pidlParent = ILClone(pidl);
1014 ILRemoveLastID(pidlParent);
1016 hr = SHGetDesktopFolder(&psf);
1019 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1021 if (SUCCEEDED(hr) && ppidlLast)
1022 *ppidlLast = pidlChild;
1026 SHFree (pidlParent);
1027 if (psf) IShellFolder_Release(psf);
1031 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1035 /*************************************************************************
1036 * SHGetPathFromIDListAW [SHELL32.221][NT 4.0: SHELL32.219]
1038 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1040 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1042 if (VERSION_OsIsUnicode())
1043 return SHGetPathFromIDListW(pidl,pszPath);
1044 return SHGetPathFromIDListA(pidl,pszPath);
1047 /**************************************************************************
1049 * internal functions
1051 * ### 1. section creating pidls ###
1053 *************************************************************************
1054 * _ILCreateDesktop()
1055 * _ILCreateIExplore()
1056 * _ILCreateMyComputer()
1061 LPITEMIDLIST _ILCreateDesktop()
1063 return _ILCreate(PT_DESKTOP, NULL, 0);
1066 LPITEMIDLIST _ILCreateMyComputer()
1068 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1071 LPITEMIDLIST _ILCreateIExplore()
1073 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1076 LPITEMIDLIST _ILCreateControl()
1078 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1081 LPITEMIDLIST _ILCreatePrinter()
1083 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1086 LPITEMIDLIST _ILCreateNetwork()
1088 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1091 LPITEMIDLIST _ILCreateBitBucket()
1093 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1096 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1098 lstrcpynA (sTemp,lpszNew,4);
1101 TRACE("(%s)\n",sTemp);
1102 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1105 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1107 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1108 char * pbuff = buff;
1112 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1114 /* prepare buffer with both names */
1115 len = strlen (stffile->cFileName) + 1;
1116 memcpy (pbuff, stffile->cFileName, len);
1119 if (stffile->cAlternateFileName)
1121 len1 = strlen (stffile->cAlternateFileName)+1;
1122 memcpy (pbuff, stffile->cAlternateFileName, len1);
1130 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1132 /* set attributes */
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;
1145 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1147 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1148 char * pbuff = buff;
1152 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1154 /* prepare buffer with both names */
1155 len = strlen (stffile->cFileName) + 1;
1156 memcpy (pbuff, stffile->cFileName, len);
1159 if (stffile->cAlternateFileName)
1161 len1 = strlen (stffile->cAlternateFileName)+1;
1162 memcpy (pbuff, stffile->cAlternateFileName, len1);
1170 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1172 /* set attributes */
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;
1185 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1188 CLSIDFromString16(szGUID,&iid);
1189 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1192 /**************************************************************************
1194 * Creates a new PIDL
1195 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1197 * uInSize = size of data (raw)
1200 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT16 uInSize)
1201 { LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1206 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1211 pidlOut = SHAlloc(uSize + 2);
1212 pidlOut->mkid.cb = uSize;
1213 TRACE("- create Desktop\n");
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);
1223 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1224 TRACE("- create GUID-pidl\n");
1229 pidlOut = SHAlloc(uSize + 2);
1230 ZeroMemory(pidlOut, uSize + 2);
1231 pidlOut->mkid.cb = uSize;
1232 pData =_ILGetDataPointer(pidlOut);
1234 pszDest = _ILGetTextPointer(pidlOut);
1235 memcpy(pszDest, pIn, uInSize);
1236 TRACE("- create Drive: %s\n",debugstr_a(pszDest));
1241 uSize = 2 + 12 + uInSize;
1242 pidlOut = SHAlloc(uSize + 2);
1243 ZeroMemory(pidlOut, uSize + 2);
1244 pidlOut->mkid.cb = uSize;
1245 pData =_ILGetDataPointer(pidlOut);
1247 pszDest = _ILGetTextPointer(pidlOut);
1248 memcpy(pszDest, pIn, uInSize);
1249 TRACE("- create Value: %s\n",debugstr_a(pszDest));
1253 pidlTemp = ILGetNext(pidlOut);
1255 pidlTemp->mkid.cb = 0x00;
1257 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1261 /**************************************************************************
1264 * Gets the text for the drive eg. 'c:\'
1269 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT16 uSize)
1270 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1272 if(_ILIsMyComputer(pidl))
1273 pidl = ILGetNext(pidl);
1275 if (pidl && _ILIsDrive(pidl))
1276 return _ILSimpleGetText(pidl, pOut, uSize);
1281 /**************************************************************************
1283 * ### 2. section testing pidls ###
1285 **************************************************************************
1288 * _ILIsSpecialFolder()
1294 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1295 { TRACE("(%p)\n",pidl);
1296 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
1299 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1301 REFIID iid = _ILGetGUIDPointer(pidl);
1303 TRACE("(%p)\n",pidl);
1306 return IsEqualIID(iid, &CLSID_MyComputer);
1310 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
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)
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));
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));
1334 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1335 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1336 TRACE("(%p)\n",pidl);
1337 return (pidl && lpPData && PT_VALUE == lpPData->type);
1340 /**************************************************************************
1343 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1347 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1349 WORD len = pidl->mkid.cb;
1350 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1351 if (pidlnext->mkid.cb)
1355 TRACE("%s\n", ret ? "Yes" : "No");
1359 /**************************************************************************
1361 * ### 3. section getting values from pidls ###
1364 /**************************************************************************
1367 * gets the text for the first item in the pidl (eg. simple pidl)
1369 * returns the lenght of the string
1371 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1376 char szTemp[MAX_PATH];
1378 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1380 if (!pidl) return 0;
1385 if (_ILIsDesktop(pidl))
1388 if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1391 lstrcpynA(szOut, szTemp, uOutSize);
1393 dwReturn = strlen (szTemp);
1396 else if (( szSrc = _ILGetTextPointer(pidl) ))
1400 lstrcpynA(szOut, szSrc, uOutSize);
1402 dwReturn = strlen(szSrc);
1404 else if (( riid = _ILGetGUIDPointer(pidl) ))
1406 /* special folder */
1407 if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
1410 lstrcpynA(szOut, szTemp, uOutSize);
1412 dwReturn = strlen (szTemp);
1417 ERR("-- no text\n");
1420 TRACE("-- (%p=%s 0x%08lx)\n",szOut,(char*)szOut,dwReturn);
1424 /**************************************************************************
1426 * ### 4. getting pointers to parts of pidls ###
1428 **************************************************************************
1429 * _ILGetDataPointer()
1431 LPPIDLDATA _ILGetDataPointer(LPITEMIDLIST pidl)
1433 if(pidl && pidl->mkid.cb != 0x00)
1434 return (LPPIDLDATA) &(pidl->mkid.abID);
1438 /**************************************************************************
1439 * _ILGetTextPointer()
1440 * gets a pointer to the long filename string stored in the pidl
1442 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1443 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1445 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1449 switch (pdata->type)
1459 return (LPSTR)&(pdata->u.drive.szDriveName);
1465 return (LPSTR)&(pdata->u.file.szNames);
1471 return (LPSTR)&(pdata->u.network.szNames);
1477 /**************************************************************************
1478 * _ILGetSTextPointer()
1479 * gets a pointer to the short filename string stored in the pidl
1481 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1482 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1484 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1488 switch (pdata->type)
1493 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1496 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1502 /**************************************************************************
1503 * _ILGetGUIDPointer()
1505 * returns reference to guid stored in some pidls
1507 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1509 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1513 switch (pdata->type)
1517 return (REFIID) &(pdata->u.mycomp.guid);
1523 /*************************************************************************
1524 * _ILGetFileDateTime
1526 * Given the ItemIdList, get the FileTime
1529 * pidl [I] The ItemIDList
1530 * pFt [I] the resulted FILETIME of the file
1533 * True if Successful
1538 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1540 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1542 switch (pdata->type)
1545 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1548 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1556 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1561 if (! _ILGetFileDateTime( pidl, &ft )) return FALSE;
1563 FileTimeToLocalFileTime(&ft, &lft);
1564 FileTimeToSystemTime (&lft, &time);
1565 return GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
1568 /*************************************************************************
1571 * Given the ItemIdList, get the FileSize
1574 * pidl [I] The ItemIDList
1575 * pOut [I] The buffer to save the result
1576 * uOutsize [I] The size of the buffer
1582 * pOut can be null when no string is needed
1585 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1587 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1590 switch (pdata->type)
1593 dwSize = pdata->u.file.dwFileSize;
1594 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1597 if (pOut) *pOut = 0x00;
1601 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1603 char szTemp[MAX_PATH];
1604 const char * pPoint;
1605 LPITEMIDLIST pidlTemp=pidl;
1607 TRACE("pidl=%p\n",pidl);
1609 if (!pidl) return FALSE;
1611 pidlTemp = ILFindLastID(pidl);
1613 if (!_ILIsValue(pidlTemp)) return FALSE;
1614 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1616 pPoint = PathFindExtensionA(szTemp);
1618 if (! *pPoint) return FALSE;
1621 lstrcpynA(pOut, pPoint, uOutSize);
1627 /*************************************************************************
1630 * Given the ItemIdList, get the file type description
1633 * pidl [I] The ItemIDList (simple)
1634 * pOut [I] The buffer to save the result
1635 * uOutsize [I] The size of the buffer
1641 * This function copies as much as possible into the buffer.
1643 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1645 if(_ILIsValue(pidl))
1652 if (_ILGetExtension (pidl, sTemp, 64))
1654 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1655 && HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
1657 lstrcpynA (pOut, sTemp, uOutSize - 6);
1658 strcat (pOut, "-file");
1664 lstrcpynA(pOut, "Folder", uOutSize);
1668 /*************************************************************************
1669 * _ILGetFileAttributes
1671 * Given the ItemIdList, get the Attrib string format
1674 * pidl [I] The ItemIDList
1675 * pOut [I] The buffer to save the result
1676 * uOutsize [I] The size of the Buffer
1684 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1686 LPPIDLDATA pData =_ILGetDataPointer(pidl);
1693 wAttrib = pData->u.folder.uFileAttribs;
1696 wAttrib = pData->u.file.uFileAttribs;
1703 if(wAttrib & FILE_ATTRIBUTE_READONLY)
1707 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
1711 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
1715 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
1719 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
1728 /*************************************************************************
1731 * free a aPidl struct
1733 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
1739 for(i = 0; i < cidl; i++) SHFree(apidl[i]);
1744 /*************************************************************************
1747 * copys a aPidl struct
1749 LPITEMIDLIST * _ILCopyaPidl(LPITEMIDLIST * apidlsrc, UINT cidl)
1752 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
1753 if(!apidlsrc) return NULL;
1755 for(i = 0; i < cidl; i++)
1756 apidldest[i] = ILClone(apidlsrc[i]);
1761 /*************************************************************************
1762 * _ILCopyCidaToaPidl
1764 * creates aPidl from CIDA
1766 LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPCIDA cida)
1769 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
1771 if(!dst) return NULL;
1774 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
1776 for(i = 0; i < cida->cidl; i++)
1777 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));