4 * Copyright 1998 Juergen Schmied
7 * a pidl == NULL means desktop and is legal
15 #include "debugtools.h"
19 #include "wine/winestring.h"
20 #include "wine/undocshell.h"
21 #include "shell32_main.h"
26 DEFAULT_DEBUG_CHANNEL(pidl);
27 DECLARE_DEBUG_CHANNEL(shell);
29 void pdump (LPCITEMIDLIST pidl)
33 LPITEMIDLIST pidltemp = pidl;
37 /* silence the sub-functions */
38 bIsShellDebug = TRACE_ON(shell);
39 __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, FALSE);
40 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
44 MESSAGE ("-------- pidl=NULL (Desktop)\n");
48 MESSAGE ("-------- pidl=%p\n", pidl);
49 if (pidltemp->mkid.cb)
54 LPPIDLDATA pData = _ILGetDataPointer(pidltemp);
55 DWORD type = pData->type;
56 LPSTR szLongName = _ILGetTextPointer(pidltemp);
57 LPSTR szShortName = _ILGetSTextPointer(pidltemp);
58 char szName[MAX_PATH];
60 _ILSimpleGetText(pidltemp, szName, MAX_PATH);
61 if( PT_FOLDER == type)
62 dwAttrib = pData->u.folder.uFileAttribs;
63 else if( PT_VALUE == type)
64 dwAttrib = pData->u.file.uFileAttribs;
66 MESSAGE ("-- pidl=%p size=%u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
67 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
69 pidltemp = ILGetNext(pidltemp);
71 } while (pidltemp->mkid.cb);
75 MESSAGE ("empty pidl (Desktop)\n");
80 __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, bIsShellDebug);
81 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, TRUE);
84 #define BYTES_PRINTED 32
85 BOOL pcheck (LPCITEMIDLIST pidl)
86 { DWORD type, ret=TRUE;
89 LPITEMIDLIST pidltemp = pidl;
91 bIsPidlDebug = TRACE_ON(shell);
92 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
94 if (pidltemp && pidltemp->mkid.cb)
96 { type = _ILGetDataPointer(pidltemp)->type;
116 char szTemp[BYTES_PRINTED*4 + 1];
120 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
121 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
123 c = ((unsigned char *)pidltemp)[i];
125 szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
126 szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
128 szTemp[i+BYTES_PRINTED*3] = (c>=0x20 && c <=0x80) ? c : '.';
130 szTemp[BYTES_PRINTED*4] = 0x00;
131 ERR("unknown IDLIST type size=%u type=%lx\n%s\n",pidltemp->mkid.cb,type, szTemp);
135 pidltemp = ILGetNext(pidltemp);
136 } while (pidltemp->mkid.cb);
138 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, bIsPidlDebug);
142 /*************************************************************************
143 * ILGetDisplayName [SHELL32.15]
145 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl,LPSTR path)
147 TRACE_(shell)("pidl=%p %p semi-stub\n",pidl,path);
148 return SHGetPathFromIDListA(pidl, path);
150 /*************************************************************************
151 * ILFindLastID [SHELL32.16]
154 * observed: pidl=Desktop return=pidl
156 LPITEMIDLIST WINAPI ILFindLastID(LPITEMIDLIST pidl)
157 { LPITEMIDLIST pidlLast = pidl;
159 TRACE("(pidl=%p)\n",pidl);
161 while (pidl->mkid.cb)
164 pidl = ILGetNext(pidl);
168 /*************************************************************************
169 * ILRemoveLastID [SHELL32.17]
172 * when pidl=Desktop return=FALSE
174 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
176 TRACE_(shell)("pidl=%p\n",pidl);
178 if (!pidl || !pidl->mkid.cb)
180 ILFindLastID(pidl)->mkid.cb = 0;
184 /*************************************************************************
185 * ILClone [SHELL32.18]
190 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
192 LPITEMIDLIST newpidl;
197 len = ILGetSize(pidl);
198 newpidl = (LPITEMIDLIST)SHAlloc(len);
200 memcpy(newpidl,pidl,len);
202 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
207 /*************************************************************************
208 * ILCloneFirst [SHELL32.19]
211 * duplicates the first idlist of a complex pidl
213 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
215 LPITEMIDLIST pidlNew = NULL;
217 TRACE("pidl=%p \n",pidl);
223 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
226 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
229 ILGetNext(pidlNew)->mkid.cb = 0x00;
232 TRACE("-- newpidl=%p\n",pidlNew);
236 /*************************************************************************
240 * the first two bytes are the len, the pidl is following then
242 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
245 HRESULT ret = E_FAIL;
248 TRACE_(shell)("%p %p\n", pStream , ppPidl);
255 IStream_AddRef (pStream);
257 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
258 { *ppPidl = SHAlloc (wLen);
259 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
268 /* we are not jet fully compatible */
269 if (!pcheck(*ppPidl))
275 IStream_Release (pStream);
279 /*************************************************************************
280 * SHILCreateFromPath [SHELL32.28]
283 * wraper for IShellFolder::ParseDisplayName()
285 HRESULT WINAPI SHILCreateFromPathA (LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
287 WCHAR lpszDisplayName[MAX_PATH];
289 HRESULT ret = E_FAIL;
291 TRACE_(shell)("%s %p 0x%08lx\n",path,ppidl,attributes?*attributes:0);
293 lstrcpynAtoW(lpszDisplayName, path, MAX_PATH);
295 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
297 ret = IShellFolder_ParseDisplayName(sf,0, NULL,lpszDisplayName,&pchEaten,ppidl,attributes);
298 IShellFolder_Release(sf);
302 HRESULT WINAPI SHILCreateFromPathW (LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
305 HRESULT ret = E_FAIL;
307 TRACE_(shell)("%s %p 0x%08lx\n",debugstr_w(path),ppidl,attributes?*attributes:0);
309 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
311 ret = IShellFolder_ParseDisplayName(sf,0, NULL, (LPWSTR) path, &pchEaten, ppidl, attributes);
312 IShellFolder_Release(sf);
316 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
318 if ( SHELL_OsIsUnicode())
319 return SHILCreateFromPathW (path, ppidl, attributes);
320 return SHILCreateFromPathA (path, ppidl, attributes);
323 /*************************************************************************
324 * SHCloneSpecialIDList [SHELL32.89]
328 * nFolder [in] CSIDL_xxxxx ??
333 * exported by ordinal
335 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner,DWORD nFolder,DWORD x3)
336 { LPITEMIDLIST ppidl;
337 WARN_(shell)("(hwnd=0x%x,csidl=0x%lx,0x%lx):semi-stub.\n",
338 hwndOwner,nFolder,x3);
340 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
345 /*************************************************************************
346 * ILGlobalClone [SHELL32.97]
349 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
351 LPITEMIDLIST newpidl;
356 len = ILGetSize(pidl);
357 newpidl = (LPITEMIDLIST)pCOMCTL32_Alloc(len);
359 memcpy(newpidl,pidl,len);
361 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
367 /*************************************************************************
368 * ILIsEqual [SHELL32.21]
371 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
373 char szData1[MAX_PATH];
374 char szData2[MAX_PATH];
376 LPITEMIDLIST pidltemp1 = pidl1;
377 LPITEMIDLIST pidltemp2 = pidl2;
379 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
381 /* explorer reads from registry directly (StreamMRU),
382 so we can only check here */
383 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
388 if ( (!pidl1) || (!pidl2) ) return FALSE;
390 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
392 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
393 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
395 if (strcasecmp ( szData1, szData2 )!=0 )
398 pidltemp1 = ILGetNext(pidltemp1);
399 pidltemp2 = ILGetNext(pidltemp2);
402 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
409 /*************************************************************************
410 * ILIsParent [SHELL32.23]
412 * parent=a/b child=a/b/c -> true, c is in folder a/b
413 * child=a/b/c/d -> false if bImmediate is true, d is not in folder a/b
414 * child=a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
416 BOOL WINAPI ILIsParent( LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
418 char szData1[MAX_PATH];
419 char szData2[MAX_PATH];
421 LPITEMIDLIST pParent = pidlParent;
422 LPITEMIDLIST pChild = pidlChild;
424 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
426 while (pParent->mkid.cb && pChild->mkid.cb)
428 _ILSimpleGetText(pParent, szData1, MAX_PATH);
429 _ILSimpleGetText(pChild, szData2, MAX_PATH);
431 if (strcasecmp ( szData1, szData2 )!=0 )
434 pParent = ILGetNext(pParent);
435 pChild = ILGetNext(pChild);
438 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
441 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
447 /*************************************************************************
448 * ILFindChild [SHELL32.24]
451 * Compares elements from pidl1 and pidl2.
453 * pidl1 is desktop pidl2
454 * pidl1 shorter pidl2 pointer to first different element of pidl2
455 * if there was at least one equal element
456 * pidl2 shorter pidl1 0
457 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
459 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
461 char szData1[MAX_PATH];
462 char szData2[MAX_PATH];
464 LPITEMIDLIST pidltemp1 = pidl1;
465 LPITEMIDLIST pidltemp2 = pidl2;
466 LPITEMIDLIST ret=NULL;
468 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
470 /* explorer reads from registry directly (StreamMRU),
471 so we can only check here */
472 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
478 if ( _ILIsDesktop(pidl1) )
484 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
486 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
487 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
489 if (strcasecmp(szData1,szData2))
492 pidltemp1 = ILGetNext(pidltemp1);
493 pidltemp2 = ILGetNext(pidltemp2);
497 if (pidltemp1->mkid.cb)
499 ret = NULL; /* elements of pidl1 left*/
502 TRACE_(shell)("--- %p\n", ret);
503 return ret; /* pidl 1 is shorter */
506 /*************************************************************************
507 * ILCombine [SHELL32.25]
510 * Concatenates two complex idlists.
511 * The pidl is the first one, pidlsub the next one
512 * Does not destroy the passed in idlists!
514 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
517 LPITEMIDLIST pidlNew;
519 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
521 if(!pidl1 && !pidl2) return NULL;
528 pidlNew = ILClone(pidl2);
534 pidlNew = ILClone(pidl1);
538 len1 = ILGetSize(pidl1)-2;
539 len2 = ILGetSize(pidl2);
540 pidlNew = SHAlloc(len1+len2);
544 memcpy(pidlNew,pidl1,len1);
545 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
548 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
551 /*************************************************************************
552 * SHGetRealIDL [SHELL32.98]
556 LPITEMIDLIST WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl, DWORD z)
558 FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf,pidl,z);
564 /*************************************************************************
565 * SHLogILFromFSIL [SHELL32.95]
568 * pild = CSIDL_DESKTOP ret = 0
569 * pild = CSIDL_DRIVES ret = 0
571 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
573 FIXME("(pidl=%p)\n",pidl);
580 /*************************************************************************
581 * ILGetSize [SHELL32.152]
582 * gets the byte size of an idlist including zero terminator (pidl)
591 * exported by ordinal
593 DWORD WINAPI ILGetSize(LPITEMIDLIST pidl)
595 LPSHITEMID si = &(pidl->mkid);
601 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
605 TRACE("pidl=%p size=%lu\n",pidl, len);
609 /*************************************************************************
610 * ILGetNext [SHELL32.153]
611 * gets the next simple pidl of a complex pidl
613 * observed return values:
616 * simple pidl -> pointer to 0x0000 element
619 LPITEMIDLIST WINAPI ILGetNext(LPITEMIDLIST pidl)
623 TRACE("(pidl=%p)\n",pidl);
630 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
636 /*************************************************************************
637 * ILAppend [SHELL32.154]
640 * Adds the single item to the idlist indicated by pidl.
641 * if bEnd is 0, adds the item to the front of the list,
642 * otherwise adds the item to the end. (???)
643 * Destroys the passed in idlist! (???)
645 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl,LPCITEMIDLIST item,BOOL bEnd)
649 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
654 if (_ILIsDesktop(pidl))
656 idlRet = ILClone(item);
664 idlRet=ILCombine(pidl,item);
668 idlRet=ILCombine(item,pidl);
674 /*************************************************************************
675 * ILFree [SHELL32.155]
678 * free_check_ptr - frees memory (if not NULL)
679 * allocated by SHMalloc allocator
680 * exported by ordinal
682 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
684 TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
686 if(!pidl) return FALSE;
690 /*************************************************************************
691 * ILGlobalFree [SHELL32.156]
694 void WINAPI ILGlobalFree( LPCITEMIDLIST pidl)
699 pCOMCTL32_Free(pidl);
701 /*************************************************************************
702 * ILCreateFromPath [SHELL32.157]
705 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
707 LPITEMIDLIST pidlnew;
708 DWORD attributes = 0;
710 TRACE_(shell)("%s\n",path);
712 if (SUCCEEDED (SHILCreateFromPathA (path, &pidlnew, &attributes)))
716 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
718 LPITEMIDLIST pidlnew;
719 DWORD attributes = 0;
721 TRACE_(shell)("%s\n",debugstr_w(path));
723 if (SUCCEEDED (SHILCreateFromPathW (path, &pidlnew, &attributes)))
727 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
729 if ( SHELL_OsIsUnicode())
730 return ILCreateFromPathW (path);
731 return ILCreateFromPathA (path);
733 /*************************************************************************
734 * SHSimpleIDListFromPath [SHELL32.162]
736 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPCSTR lpszPath)
738 LPITEMIDLIST pidl=NULL;
740 WIN32_FIND_DATAA stffile;
742 TRACE("path=%s\n", lpszPath);
744 if (!lpszPath) return NULL;
746 hFile = FindFirstFileA(lpszPath, &stffile);
748 if ( hFile != INVALID_HANDLE_VALUE )
750 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
752 pidl = _ILCreateFolder (&stffile);
756 pidl = _ILCreateValue (&stffile);
762 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPCWSTR lpszPath)
764 char lpszTemp[MAX_PATH];
765 TRACE("path=%s\n",debugstr_w(lpszPath));
767 lstrcpynWtoA(lpszTemp, lpszPath, MAX_PATH);
769 return SHSimpleIDListFromPathA (lpszTemp);
772 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW (LPCVOID lpszPath)
774 if ( SHELL_OsIsUnicode())
775 return SHSimpleIDListFromPathW (lpszPath);
776 return SHSimpleIDListFromPathA (lpszPath);
779 /*************************************************************************
780 * SHGetSpecialFolderLocation [SHELL32.223]
782 * gets the folder locations from the registry and creates a pidl
783 * creates missing reg keys and directorys
787 * nFolder [I] CSIDL_xxxxx
788 * ppidl [O] PIDL of a special folder
791 HRESULT WINAPI SHGetSpecialFolderLocation(
794 LPITEMIDLIST * ppidl)
796 CHAR szPath[MAX_PATH];
797 HRESULT hr = E_INVALIDARG;
799 TRACE_(shell)("(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
807 *ppidl = _ILCreateDesktop();
811 *ppidl = _ILCreateMyComputer();
815 *ppidl = _ILCreateNetwork ();
819 *ppidl = _ILCreateControl ();
823 *ppidl = _ILCreatePrinter ();
826 case CSIDL_BITBUCKET:
827 *ppidl = _ILCreateBitBucket ();
831 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
834 TRACE_(shell)("Value=%s\n",szPath);
835 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
838 if(*ppidl) hr = NOERROR;
841 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
845 /*************************************************************************
846 * SHGetFolderLocation [SHELL32]
849 * the pidl can be a simple one. since we cant get the path out of the pidl
850 * we have to take all data from the pidl
852 HRESULT WINAPI SHGetFolderLocation(
859 FIXME("0x%04x 0x%08x 0x%08x 0x%08lx %p\n",
860 hwnd, csidl, hToken, dwFlags, ppidl);
861 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
864 /*************************************************************************
865 * SHGetDataFromIDListA [SHELL32.247]
868 * the pidl can be a simple one. since we cant get the path out of the pidl
869 * we have to take all data from the pidl
871 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
873 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
876 if (!psf || !dest ) return E_INVALIDARG;
880 case SHGDFIL_FINDDATA:
882 WIN32_FIND_DATAA * pfd = dest;
884 if ( len < sizeof (WIN32_FIND_DATAA)) return E_INVALIDARG;
886 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
887 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
888 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
889 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
890 lstrcpynA(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
891 lstrcpynA(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
895 case SHGDFIL_NETRESOURCE:
896 case SHGDFIL_DESCRIPTIONID:
897 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
901 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
906 /*************************************************************************
907 * SHGetDataFromIDListW [SHELL32.247]
910 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
912 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
916 if (! psf || !dest ) return E_INVALIDARG;
920 case SHGDFIL_FINDDATA:
922 WIN32_FIND_DATAW * pfd = dest;
924 if ( len < sizeof (WIN32_FIND_DATAW)) return E_INVALIDARG;
926 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
927 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
928 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
929 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
930 lstrcpynAtoW(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
931 lstrcpynAtoW(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
934 case SHGDFIL_NETRESOURCE:
935 case SHGDFIL_DESCRIPTIONID:
936 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
940 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
946 /*************************************************************************
947 * SHGetPathFromIDListA [SHELL32.261][NT 4.0: SHELL32.220]
954 * path from a passed PIDL.
958 * desktop pidl gives path to desktopdirectory back
959 * special pidls returning FALSE
962 * fnGetDisplayNameOf can return different types of OLEString
964 BOOL WINAPI SHGetPathFromIDListA (LPCITEMIDLIST pidl,LPSTR pszPath)
966 LPSHELLFOLDER shellfolder;
968 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
970 if (!pidl) return FALSE;
974 if(_ILIsDesktop(pidl))
976 SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
978 else if (_ILIsSpecialFolder(ILFindLastID(pidl)))
980 /* we are somewhere in a special folder */
985 if (SHGetDesktopFolder(&shellfolder)==S_OK)
987 IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
988 StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
989 IShellFolder_Release(shellfolder);
992 TRACE_(shell)("-- (%s)\n",pszPath);
996 /*************************************************************************
997 * SHGetPathFromIDListW [SHELL32.262]
999 BOOL WINAPI SHGetPathFromIDListW (LPCITEMIDLIST pidl,LPWSTR pszPath)
1000 { char sTemp[MAX_PATH];
1002 TRACE_(shell)("(pidl=%p)\n", pidl);
1004 SHGetPathFromIDListA (pidl, sTemp);
1005 lstrcpyAtoW(pszPath, sTemp);
1007 TRACE_(shell)("-- (%s)\n",debugstr_w(pszPath));
1012 /*************************************************************************
1013 * SHBindToParent [shell version 5.0]
1015 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1018 LPITEMIDLIST pidlChild, pidlParent;
1021 TRACE_(shell)("pidl=%p\n", pidl);
1025 if (ppidlLast) *ppidlLast = NULL;
1027 if (_ILIsPidlSimple(pidl))
1029 /* we are on desktop level */
1031 *ppidlLast = ILClone(pidl);
1032 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1036 pidlChild = ILClone(ILFindLastID(pidl));
1037 pidlParent = ILClone(pidl);
1038 ILRemoveLastID(pidlParent);
1040 hr = SHGetDesktopFolder(&psf);
1043 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1045 if (SUCCEEDED(hr) && ppidlLast)
1046 *ppidlLast = pidlChild;
1050 SHFree (pidlParent);
1051 if (psf) IShellFolder_Release(psf);
1055 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1059 /*************************************************************************
1060 * SHGetPathFromIDListAW [SHELL32.221][NT 4.0: SHELL32.219]
1062 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1064 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1066 if (SHELL_OsIsUnicode())
1067 return SHGetPathFromIDListW(pidl,pszPath);
1068 return SHGetPathFromIDListA(pidl,pszPath);
1071 /**************************************************************************
1073 * internal functions
1075 * ### 1. section creating pidls ###
1077 *************************************************************************
1078 * _ILCreateDesktop()
1079 * _ILCreateIExplore()
1080 * _ILCreateMyComputer()
1085 LPITEMIDLIST _ILCreateDesktop()
1087 return _ILCreate(PT_DESKTOP, NULL, 0);
1090 LPITEMIDLIST _ILCreateMyComputer()
1092 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1095 LPITEMIDLIST _ILCreateIExplore()
1097 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1100 LPITEMIDLIST _ILCreateControl()
1102 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1105 LPITEMIDLIST _ILCreatePrinter()
1107 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1110 LPITEMIDLIST _ILCreateNetwork()
1112 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1115 LPITEMIDLIST _ILCreateBitBucket()
1117 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1120 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1122 lstrcpynA (sTemp,lpszNew,4);
1125 TRACE("(%s)\n",sTemp);
1126 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1129 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1131 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1132 char * pbuff = buff;
1136 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1138 /* prepare buffer with both names */
1139 len = strlen (stffile->cFileName) + 1;
1140 memcpy (pbuff, stffile->cFileName, len);
1143 if (stffile->cAlternateFileName)
1145 len1 = strlen (stffile->cAlternateFileName)+1;
1146 memcpy (pbuff, stffile->cAlternateFileName, len1);
1154 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1156 /* set attributes */
1160 pData = _ILGetDataPointer(pidl);
1161 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1162 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1163 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1169 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1171 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1172 char * pbuff = buff;
1176 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1178 /* prepare buffer with both names */
1179 len = strlen (stffile->cFileName) + 1;
1180 memcpy (pbuff, stffile->cFileName, len);
1183 if (stffile->cAlternateFileName)
1185 len1 = strlen (stffile->cAlternateFileName)+1;
1186 memcpy (pbuff, stffile->cAlternateFileName, len1);
1194 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1196 /* set attributes */
1200 pData = _ILGetDataPointer(pidl);
1201 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1202 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1203 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1209 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1214 if (!MultiByteToWideChar( CP_ACP, 0, szGUID, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1216 CLSIDFromString( buffer, &iid );
1217 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1220 /**************************************************************************
1222 * Creates a new PIDL
1223 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1225 * uInSize = size of data (raw)
1228 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT uInSize)
1230 LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1235 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1244 uSize = 2 + 2 + sizeof(GUID);
1251 uSize = 2 + 12 + uInSize;
1254 FIXME("can't create type: 0x%08x\n",type);
1258 if(!(pidlOut = SHAlloc(uSize + 2))) return NULL;
1259 ZeroMemory(pidlOut, uSize + 2);
1260 pidlOut->mkid.cb = uSize;
1265 TRACE("- create Desktop\n");
1270 pData =_ILGetDataPointer(pidlOut);
1272 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1273 TRACE("- create GUID-pidl\n");
1277 pData =_ILGetDataPointer(pidlOut);
1279 pszDest = _ILGetTextPointer(pidlOut);
1280 memcpy(pszDest, pIn, uInSize);
1281 TRACE("- create Drive: %s\n",debugstr_a(pszDest));
1286 pData =_ILGetDataPointer(pidlOut);
1288 pszDest = _ILGetTextPointer(pidlOut);
1289 memcpy(pszDest, pIn, uInSize);
1290 TRACE("- create Value: %s\n",debugstr_a(pszDest));
1294 pidlTemp = ILGetNext(pidlOut);
1296 pidlTemp->mkid.cb = 0x00;
1298 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1302 /**************************************************************************
1305 * Gets the text for the drive eg. 'c:\'
1310 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1311 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1313 if(_ILIsMyComputer(pidl))
1314 pidl = ILGetNext(pidl);
1316 if (pidl && _ILIsDrive(pidl))
1317 return _ILSimpleGetText(pidl, pOut, uSize);
1322 /**************************************************************************
1324 * ### 2. section testing pidls ###
1326 **************************************************************************
1329 * _ILIsSpecialFolder()
1335 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1336 { TRACE("(%p)\n",pidl);
1337 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
1340 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1342 REFIID iid = _ILGetGUIDPointer(pidl);
1344 TRACE("(%p)\n",pidl);
1347 return IsEqualIID(iid, &CLSID_MyComputer);
1351 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1353 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1354 TRACE("(%p)\n",pidl);
1355 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1356 (pidl && pidl->mkid.cb == 0x00)
1360 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1361 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1362 TRACE("(%p)\n",pidl);
1363 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1364 PT_DRIVE1 == lpPData->type ||
1365 PT_DRIVE2 == lpPData->type ||
1366 PT_DRIVE3 == lpPData->type));
1369 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1370 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1371 TRACE("(%p)\n",pidl);
1372 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1375 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1376 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1377 TRACE("(%p)\n",pidl);
1378 return (pidl && lpPData && PT_VALUE == lpPData->type);
1381 /**************************************************************************
1384 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1388 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1390 WORD len = pidl->mkid.cb;
1391 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1392 if (pidlnext->mkid.cb)
1396 TRACE("%s\n", ret ? "Yes" : "No");
1400 /**************************************************************************
1402 * ### 3. section getting values from pidls ###
1405 /**************************************************************************
1408 * gets the text for the first item in the pidl (eg. simple pidl)
1410 * returns the lenght of the string
1412 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1417 char szTemp[MAX_PATH];
1419 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1421 if (!pidl) return 0;
1426 if (_ILIsDesktop(pidl))
1429 if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1432 lstrcpynA(szOut, szTemp, uOutSize);
1434 dwReturn = strlen (szTemp);
1437 else if (( szSrc = _ILGetTextPointer(pidl) ))
1441 lstrcpynA(szOut, szSrc, uOutSize);
1443 dwReturn = strlen(szSrc);
1445 else if (( riid = _ILGetGUIDPointer(pidl) ))
1447 /* special folder */
1448 if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
1451 lstrcpynA(szOut, szTemp, uOutSize);
1453 dwReturn = strlen (szTemp);
1458 ERR("-- no text\n");
1461 TRACE("-- (%p=%s 0x%08lx)\n",szOut,(char*)szOut,dwReturn);
1465 /**************************************************************************
1467 * ### 4. getting pointers to parts of pidls ###
1469 **************************************************************************
1470 * _ILGetDataPointer()
1472 LPPIDLDATA _ILGetDataPointer(LPITEMIDLIST pidl)
1474 if(pidl && pidl->mkid.cb != 0x00)
1475 return (LPPIDLDATA) &(pidl->mkid.abID);
1479 /**************************************************************************
1480 * _ILGetTextPointer()
1481 * gets a pointer to the long filename string stored in the pidl
1483 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1484 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1486 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1490 switch (pdata->type)
1500 return (LPSTR)&(pdata->u.drive.szDriveName);
1506 return (LPSTR)&(pdata->u.file.szNames);
1512 return (LPSTR)&(pdata->u.network.szNames);
1518 /**************************************************************************
1519 * _ILGetSTextPointer()
1520 * gets a pointer to the short filename string stored in the pidl
1522 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1523 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1525 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1529 switch (pdata->type)
1534 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1537 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1543 /**************************************************************************
1544 * _ILGetGUIDPointer()
1546 * returns reference to guid stored in some pidls
1548 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1550 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1554 switch (pdata->type)
1558 return (REFIID) &(pdata->u.mycomp.guid);
1564 /*************************************************************************
1565 * _ILGetFileDateTime
1567 * Given the ItemIdList, get the FileTime
1570 * pidl [I] The ItemIDList
1571 * pFt [I] the resulted FILETIME of the file
1574 * True if Successful
1579 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1581 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1583 if(! pdata) return FALSE;
1585 switch (pdata->type)
1588 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1591 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1599 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1604 if (! _ILGetFileDateTime( pidl, &ft )) return FALSE;
1606 FileTimeToLocalFileTime(&ft, &lft);
1607 FileTimeToSystemTime (&lft, &time);
1608 return GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
1611 /*************************************************************************
1614 * Given the ItemIdList, get the FileSize
1617 * pidl [I] The ItemIDList
1618 * pOut [I] The buffer to save the result
1619 * uOutsize [I] The size of the buffer
1625 * pOut can be null when no string is needed
1628 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1630 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1633 if(! pdata) return 0;
1635 switch (pdata->type)
1638 dwSize = pdata->u.file.dwFileSize;
1639 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1642 if (pOut) *pOut = 0x00;
1646 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1648 char szTemp[MAX_PATH];
1649 const char * pPoint;
1650 LPITEMIDLIST pidlTemp=pidl;
1652 TRACE("pidl=%p\n",pidl);
1654 if (!pidl) return FALSE;
1656 pidlTemp = ILFindLastID(pidl);
1658 if (!_ILIsValue(pidlTemp)) return FALSE;
1659 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1661 pPoint = PathFindExtensionA(szTemp);
1663 if (! *pPoint) return FALSE;
1666 lstrcpynA(pOut, pPoint, uOutSize);
1672 /*************************************************************************
1675 * Given the ItemIdList, get the file type description
1678 * pidl [I] The ItemIDList (simple)
1679 * pOut [I] The buffer to save the result
1680 * uOutsize [I] The size of the buffer
1686 * This function copies as much as possible into the buffer.
1688 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1690 if(_ILIsValue(pidl))
1697 if (_ILGetExtension (pidl, sTemp, 64))
1699 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1700 && HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
1702 lstrcpynA (pOut, sTemp, uOutSize - 6);
1703 strcat (pOut, "-file");
1709 lstrcpynA(pOut, "Folder", uOutSize);
1713 /*************************************************************************
1714 * _ILGetFileAttributes
1716 * Given the ItemIdList, get the Attrib string format
1719 * pidl [I] The ItemIDList
1720 * pOut [I] The buffer to save the result
1721 * uOutsize [I] The size of the Buffer
1727 * return value 0 in case of error is a valid return value
1730 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1732 LPPIDLDATA pData =_ILGetDataPointer(pidl);
1736 if(! pData) return 0;
1741 wAttrib = pData->u.folder.uFileAttribs;
1744 wAttrib = pData->u.file.uFileAttribs;
1751 if(wAttrib & FILE_ATTRIBUTE_READONLY)
1755 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
1759 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
1763 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
1767 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
1776 /*************************************************************************
1779 * free a aPidl struct
1781 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
1787 for(i = 0; i < cidl; i++) SHFree(apidl[i]);
1792 /*************************************************************************
1795 * copys a aPidl struct
1797 LPITEMIDLIST * _ILCopyaPidl(LPITEMIDLIST * apidlsrc, UINT cidl)
1800 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
1801 if(!apidlsrc) return NULL;
1803 for(i = 0; i < cidl; i++)
1804 apidldest[i] = ILClone(apidlsrc[i]);
1809 /*************************************************************************
1810 * _ILCopyCidaToaPidl
1812 * creates aPidl from CIDA
1814 LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPCIDA cida)
1817 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
1819 if(!dst) return NULL;
1822 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
1824 for(i = 0; i < cida->cidl; i++)
1825 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));