4 * Copyright 1998 Juergen Schmied
7 * a pidl == NULL means desktop and is legal
19 #include "undocshell.h"
20 #include "shell32_main.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(pidl);
28 DECLARE_DEBUG_CHANNEL(shell);
30 void pdump (LPCITEMIDLIST pidl)
34 LPITEMIDLIST pidltemp = pidl;
38 /* silence the sub-functions */
39 bIsShellDebug = TRACE_ON(shell);
40 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_shell, FALSE);
41 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, FALSE);
45 MESSAGE ("-------- pidl=NULL (Desktop)\n");
49 MESSAGE ("-------- pidl=%p\n", pidl);
50 if (pidltemp->mkid.cb)
55 LPPIDLDATA pData = _ILGetDataPointer(pidltemp);
56 DWORD type = pData->type;
57 LPSTR szLongName = _ILGetTextPointer(pidltemp);
58 LPSTR szShortName = _ILGetSTextPointer(pidltemp);
59 char szName[MAX_PATH];
61 _ILSimpleGetText(pidltemp, szName, MAX_PATH);
62 if( PT_FOLDER == type)
63 dwAttrib = pData->u.folder.uFileAttribs;
64 else if( PT_VALUE == type)
65 dwAttrib = pData->u.file.uFileAttribs;
67 MESSAGE ("-- pidl=%p size=%u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
68 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
70 pidltemp = ILGetNext(pidltemp);
72 } while (pidltemp->mkid.cb);
76 MESSAGE ("empty pidl (Desktop)\n");
81 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_shell, bIsShellDebug);
82 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, TRUE);
85 #define BYTES_PRINTED 32
86 BOOL pcheck (LPCITEMIDLIST pidl)
87 { DWORD type, ret=TRUE;
90 LPITEMIDLIST pidltemp = pidl;
92 bIsPidlDebug = TRACE_ON(shell);
93 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, FALSE);
95 if (pidltemp && pidltemp->mkid.cb)
97 { type = _ILGetDataPointer(pidltemp)->type;
118 char szTemp[BYTES_PRINTED*4 + 1];
122 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
123 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
125 c = ((unsigned char *)pidltemp)[i];
127 szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
128 szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
130 szTemp[i+BYTES_PRINTED*3] = (c>=0x20 && c <=0x80) ? c : '.';
132 szTemp[BYTES_PRINTED*4] = 0x00;
133 ERR("unknown IDLIST type size=%u type=%lx\n%s\n",pidltemp->mkid.cb,type, szTemp);
137 pidltemp = ILGetNext(pidltemp);
138 } while (pidltemp->mkid.cb);
140 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, bIsPidlDebug);
144 /*************************************************************************
145 * ILGetDisplayName [SHELL32.15]
147 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl,LPSTR path)
149 TRACE_(shell)("pidl=%p %p semi-stub\n",pidl,path);
150 return SHGetPathFromIDListA(pidl, path);
152 /*************************************************************************
153 * ILFindLastID [SHELL32.16]
156 * observed: pidl=Desktop return=pidl
158 LPITEMIDLIST WINAPI ILFindLastID(LPITEMIDLIST pidl)
159 { LPITEMIDLIST pidlLast = pidl;
161 TRACE("(pidl=%p)\n",pidl);
163 while (pidl->mkid.cb)
166 pidl = ILGetNext(pidl);
170 /*************************************************************************
171 * ILRemoveLastID [SHELL32.17]
174 * when pidl=Desktop return=FALSE
176 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
178 TRACE_(shell)("pidl=%p\n",pidl);
180 if (!pidl || !pidl->mkid.cb)
182 ILFindLastID(pidl)->mkid.cb = 0;
186 /*************************************************************************
187 * ILClone [SHELL32.18]
192 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
194 LPITEMIDLIST newpidl;
199 len = ILGetSize(pidl);
200 newpidl = (LPITEMIDLIST)SHAlloc(len);
202 memcpy(newpidl,pidl,len);
204 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
209 /*************************************************************************
210 * ILCloneFirst [SHELL32.19]
213 * duplicates the first idlist of a complex pidl
215 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
217 LPITEMIDLIST pidlNew = NULL;
219 TRACE("pidl=%p \n",pidl);
225 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
228 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
231 ILGetNext(pidlNew)->mkid.cb = 0x00;
234 TRACE("-- newpidl=%p\n",pidlNew);
239 /*************************************************************************
240 * ILLoadFromStream (SHELL32.26)
243 * the first two bytes are the len, the pidl is following then
245 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
248 HRESULT ret = E_FAIL;
251 TRACE_(shell)("%p %p\n", pStream , ppPidl);
258 IStream_AddRef (pStream);
260 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
261 { *ppPidl = SHAlloc (wLen);
262 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
271 /* we are not yet fully compatible */
272 if (!pcheck(*ppPidl))
278 IStream_Release (pStream);
283 /*************************************************************************
284 * ILSaveToStream (SHELL32.27)
287 * the first two bytes are the len, the pidl is following then
289 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
293 HRESULT ret = E_FAIL;
295 TRACE_(shell)("%p %p\n", pStream, pPidl);
297 IStream_AddRef (pStream);
300 while (pidl->mkid.cb)
302 wLen += sizeof(WORD) + pidl->mkid.cb;
303 pidl = ILGetNext(pidl);
306 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
308 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
314 IStream_Release (pStream);
319 /*************************************************************************
320 * SHILCreateFromPath [SHELL32.28]
323 * wraper for IShellFolder::ParseDisplayName()
325 HRESULT WINAPI SHILCreateFromPathA (LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
327 WCHAR lpszDisplayName[MAX_PATH];
329 HRESULT ret = E_FAIL;
331 TRACE_(shell)("%s %p 0x%08lx\n",path,ppidl,attributes?*attributes:0);
333 if (!MultiByteToWideChar( CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH ))
334 lpszDisplayName[MAX_PATH-1] = 0;
336 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
338 ret = IShellFolder_ParseDisplayName(sf,0, NULL,lpszDisplayName,&pchEaten,ppidl,attributes);
339 IShellFolder_Release(sf);
343 HRESULT WINAPI SHILCreateFromPathW (LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
346 HRESULT ret = E_FAIL;
348 TRACE_(shell)("%s %p 0x%08lx\n",debugstr_w(path),ppidl,attributes?*attributes:0);
350 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
352 ret = IShellFolder_ParseDisplayName(sf,0, NULL, (LPWSTR) path, &pchEaten, ppidl, attributes);
353 IShellFolder_Release(sf);
357 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
359 if ( SHELL_OsIsUnicode())
360 return SHILCreateFromPathW (path, ppidl, attributes);
361 return SHILCreateFromPathA (path, ppidl, attributes);
364 /*************************************************************************
365 * SHCloneSpecialIDList [SHELL32.89]
369 * nFolder [in] CSIDL_xxxxx ??
374 * exported by ordinal
376 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner,DWORD nFolder,DWORD x3)
377 { LPITEMIDLIST ppidl;
378 WARN_(shell)("(hwnd=0x%x,csidl=0x%lx,0x%lx):semi-stub.\n",
379 hwndOwner,nFolder,x3);
381 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
386 /*************************************************************************
387 * ILGlobalClone [SHELL32.20]
390 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
392 LPITEMIDLIST newpidl;
397 len = ILGetSize(pidl);
398 newpidl = (LPITEMIDLIST)pCOMCTL32_Alloc(len);
400 memcpy(newpidl,pidl,len);
402 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
408 /*************************************************************************
409 * ILIsEqual [SHELL32.21]
412 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
414 char szData1[MAX_PATH];
415 char szData2[MAX_PATH];
417 LPITEMIDLIST pidltemp1 = pidl1;
418 LPITEMIDLIST pidltemp2 = pidl2;
420 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
422 /* explorer reads from registry directly (StreamMRU),
423 so we can only check here */
424 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
429 if ( (!pidl1) || (!pidl2) ) return FALSE;
431 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
433 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
434 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
436 if (strcasecmp ( szData1, szData2 )!=0 )
439 pidltemp1 = ILGetNext(pidltemp1);
440 pidltemp2 = ILGetNext(pidltemp2);
443 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
450 /*************************************************************************
451 * ILIsParent [SHELL32.23]
453 * parent=a/b child=a/b/c -> true, c is in folder a/b
454 * child=a/b/c/d -> false if bImmediate is true, d is not in folder a/b
455 * child=a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
457 BOOL WINAPI ILIsParent( LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
459 char szData1[MAX_PATH];
460 char szData2[MAX_PATH];
462 LPITEMIDLIST pParent = pidlParent;
463 LPITEMIDLIST pChild = pidlChild;
465 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
467 while (pParent->mkid.cb && pChild->mkid.cb)
469 _ILSimpleGetText(pParent, szData1, MAX_PATH);
470 _ILSimpleGetText(pChild, szData2, MAX_PATH);
472 if (strcasecmp ( szData1, szData2 )!=0 )
475 pParent = ILGetNext(pParent);
476 pChild = ILGetNext(pChild);
479 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
482 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
488 /*************************************************************************
489 * ILFindChild [SHELL32.24]
492 * Compares elements from pidl1 and pidl2.
494 * pidl1 is desktop pidl2
495 * pidl1 shorter pidl2 pointer to first different element of pidl2
496 * if there was at least one equal element
497 * pidl2 shorter pidl1 0
498 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
500 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
502 char szData1[MAX_PATH];
503 char szData2[MAX_PATH];
505 LPITEMIDLIST pidltemp1 = pidl1;
506 LPITEMIDLIST pidltemp2 = pidl2;
507 LPITEMIDLIST ret=NULL;
509 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
511 /* explorer reads from registry directly (StreamMRU),
512 so we can only check here */
513 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
519 if ( _ILIsDesktop(pidl1) )
525 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
527 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
528 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
530 if (strcasecmp(szData1,szData2))
533 pidltemp1 = ILGetNext(pidltemp1);
534 pidltemp2 = ILGetNext(pidltemp2);
538 if (pidltemp1->mkid.cb)
540 ret = NULL; /* elements of pidl1 left*/
543 TRACE_(shell)("--- %p\n", ret);
544 return ret; /* pidl 1 is shorter */
547 /*************************************************************************
548 * ILCombine [SHELL32.25]
551 * Concatenates two complex idlists.
552 * The pidl is the first one, pidlsub the next one
553 * Does not destroy the passed in idlists!
555 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
558 LPITEMIDLIST pidlNew;
560 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
562 if(!pidl1 && !pidl2) return NULL;
569 pidlNew = ILClone(pidl2);
575 pidlNew = ILClone(pidl1);
579 len1 = ILGetSize(pidl1)-2;
580 len2 = ILGetSize(pidl2);
581 pidlNew = SHAlloc(len1+len2);
585 memcpy(pidlNew,pidl1,len1);
586 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
589 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
592 /*************************************************************************
593 * SHGetRealIDL [SHELL32.98]
597 LPITEMIDLIST WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl, DWORD z)
599 FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf,pidl,z);
605 /*************************************************************************
606 * SHLogILFromFSIL [SHELL32.95]
609 * pild = CSIDL_DESKTOP ret = 0
610 * pild = CSIDL_DRIVES ret = 0
612 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
614 FIXME("(pidl=%p)\n",pidl);
621 /*************************************************************************
622 * ILGetSize [SHELL32.152]
623 * gets the byte size of an idlist including zero terminator (pidl)
632 * exported by ordinal
634 DWORD WINAPI ILGetSize(LPITEMIDLIST pidl)
636 LPSHITEMID si = &(pidl->mkid);
642 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
646 TRACE("pidl=%p size=%lu\n",pidl, len);
650 /*************************************************************************
651 * ILGetNext [SHELL32.153]
652 * gets the next simple pidl of a complex pidl
654 * observed return values:
657 * simple pidl -> pointer to 0x0000 element
660 LPITEMIDLIST WINAPI ILGetNext(LPITEMIDLIST pidl)
664 TRACE("(pidl=%p)\n",pidl);
671 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
677 /*************************************************************************
678 * ILAppend [SHELL32.154]
681 * Adds the single item to the idlist indicated by pidl.
682 * if bEnd is 0, adds the item to the front of the list,
683 * otherwise adds the item to the end. (???)
684 * Destroys the passed in idlist! (???)
686 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl,LPCITEMIDLIST item,BOOL bEnd)
690 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
695 if (_ILIsDesktop(pidl))
697 idlRet = ILClone(item);
705 idlRet=ILCombine(pidl,item);
709 idlRet=ILCombine(item,pidl);
715 /*************************************************************************
716 * ILFree [SHELL32.155]
719 * free_check_ptr - frees memory (if not NULL)
720 * allocated by SHMalloc allocator
721 * exported by ordinal
723 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
725 TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
727 if(!pidl) return FALSE;
731 /*************************************************************************
732 * ILGlobalFree [SHELL32.156]
735 void WINAPI ILGlobalFree( LPCITEMIDLIST pidl)
740 pCOMCTL32_Free(pidl);
742 /*************************************************************************
743 * ILCreateFromPath [SHELL32.157]
746 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
748 LPITEMIDLIST pidlnew;
749 DWORD attributes = 0;
751 TRACE_(shell)("%s\n",path);
753 if (SUCCEEDED (SHILCreateFromPathA (path, &pidlnew, &attributes)))
757 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
759 LPITEMIDLIST pidlnew;
760 DWORD attributes = 0;
762 TRACE_(shell)("%s\n",debugstr_w(path));
764 if (SUCCEEDED (SHILCreateFromPathW (path, &pidlnew, &attributes)))
768 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
770 if ( SHELL_OsIsUnicode())
771 return ILCreateFromPathW (path);
772 return ILCreateFromPathA (path);
774 /*************************************************************************
775 * SHSimpleIDListFromPath [SHELL32.162]
777 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPCSTR lpszPath)
779 LPITEMIDLIST pidl=NULL;
781 WIN32_FIND_DATAA stffile;
783 TRACE("path=%s\n", lpszPath);
785 if (!lpszPath) return NULL;
787 hFile = FindFirstFileA(lpszPath, &stffile);
789 if ( hFile != INVALID_HANDLE_VALUE )
791 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
793 pidl = _ILCreateFolder (&stffile);
797 pidl = _ILCreateValue (&stffile);
803 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPCWSTR lpszPath)
805 char lpszTemp[MAX_PATH];
806 TRACE("path=%s\n",debugstr_w(lpszPath));
808 if (!WideCharToMultiByte( CP_ACP, 0, lpszPath, -1, lpszTemp, sizeof(lpszTemp), NULL, NULL ))
809 lpszTemp[sizeof(lpszTemp)-1] = 0;
811 return SHSimpleIDListFromPathA (lpszTemp);
814 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW (LPCVOID lpszPath)
816 if ( SHELL_OsIsUnicode())
817 return SHSimpleIDListFromPathW (lpszPath);
818 return SHSimpleIDListFromPathA (lpszPath);
821 /*************************************************************************
822 * SHGetSpecialFolderLocation [SHELL32.@]
824 * gets the folder locations from the registry and creates a pidl
825 * creates missing reg keys and directories
829 * nFolder [I] CSIDL_xxxxx
830 * ppidl [O] PIDL of a special folder
833 HRESULT WINAPI SHGetSpecialFolderLocation(
836 LPITEMIDLIST * ppidl)
838 CHAR szPath[MAX_PATH];
839 HRESULT hr = E_INVALIDARG;
841 TRACE_(shell)("(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
849 *ppidl = _ILCreateDesktop();
853 *ppidl = _ILCreateMyComputer();
857 *ppidl = _ILCreateNetwork ();
861 *ppidl = _ILCreateControl ();
865 *ppidl = _ILCreatePrinter ();
868 case CSIDL_BITBUCKET:
869 *ppidl = _ILCreateBitBucket ();
873 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
876 TRACE_(shell)("Value=%s\n",szPath);
877 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
880 if(*ppidl) hr = NOERROR;
883 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
887 /*************************************************************************
888 * SHGetFolderLocation [SHELL32.@]
891 * the pidl can be a simple one. since we cant get the path out of the pidl
892 * we have to take all data from the pidl
894 HRESULT WINAPI SHGetFolderLocation(
901 FIXME("0x%04x 0x%08x 0x%08x 0x%08lx %p\n",
902 hwnd, csidl, hToken, dwFlags, ppidl);
903 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
906 /*************************************************************************
907 * SHGetDataFromIDListA [SHELL32.247]
910 * the pidl can be a simple one. since we cant get the path out of the pidl
911 * we have to take all data from the pidl
913 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
915 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
918 if (!psf || !dest ) return E_INVALIDARG;
922 case SHGDFIL_FINDDATA:
924 WIN32_FIND_DATAA * pfd = dest;
926 if ( len < sizeof (WIN32_FIND_DATAA)) return E_INVALIDARG;
928 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
929 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
930 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
931 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
932 lstrcpynA(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
933 lstrcpynA(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
937 case SHGDFIL_NETRESOURCE:
938 case SHGDFIL_DESCRIPTIONID:
939 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
943 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
948 /*************************************************************************
949 * SHGetDataFromIDListW [SHELL32.248]
952 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
954 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
958 if (! psf || !dest ) return E_INVALIDARG;
962 case SHGDFIL_FINDDATA:
964 WIN32_FIND_DATAW * pfd = dest;
966 if ( len < sizeof (WIN32_FIND_DATAW)) return E_INVALIDARG;
968 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
969 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
970 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
971 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
972 if (!MultiByteToWideChar( CP_ACP, 0, _ILGetTextPointer(pidl), -1,
973 pfd->cFileName, MAX_PATH ))
974 pfd->cFileName[MAX_PATH-1] = 0;
975 if (!MultiByteToWideChar( CP_ACP, 0, _ILGetSTextPointer(pidl), -1,
976 pfd->cAlternateFileName, 14 ))
977 pfd->cFileName[13] = 0;
980 case SHGDFIL_NETRESOURCE:
981 case SHGDFIL_DESCRIPTIONID:
982 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
986 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
992 /*************************************************************************
993 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1000 * path from a passed PIDL.
1003 * NULL returns FALSE
1004 * desktop pidl gives path to desktopdirectory back
1005 * special pidls returning FALSE
1008 * fnGetDisplayNameOf can return different types of OLEString
1010 BOOL WINAPI SHGetPathFromIDListA (LPCITEMIDLIST pidl,LPSTR pszPath)
1012 LPSHELLFOLDER shellfolder;
1014 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1016 if (!pidl) return FALSE;
1020 if(_ILIsDesktop(pidl))
1022 SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1024 else if (_ILIsSpecialFolder(ILFindLastID(pidl)))
1026 /* we are somewhere in a special folder */
1031 if (SHGetDesktopFolder(&shellfolder)==S_OK)
1033 IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
1034 StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
1035 IShellFolder_Release(shellfolder);
1038 TRACE_(shell)("-- (%s)\n",pszPath);
1042 /*************************************************************************
1043 * SHGetPathFromIDListW [SHELL32.@]
1045 BOOL WINAPI SHGetPathFromIDListW (LPCITEMIDLIST pidl,LPWSTR pszPath)
1046 { char sTemp[MAX_PATH];
1048 TRACE_(shell)("(pidl=%p)\n", pidl);
1050 SHGetPathFromIDListA (pidl, sTemp);
1051 MultiByteToWideChar( CP_ACP, 0, sTemp, -1, pszPath, MAX_PATH );
1053 TRACE_(shell)("-- (%s)\n",debugstr_w(pszPath));
1058 /*************************************************************************
1059 * SHBindToParent [shell version 5.0]
1061 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1064 LPITEMIDLIST pidlChild, pidlParent;
1067 TRACE_(shell)("pidl=%p\n", pidl);
1071 if (ppidlLast) *ppidlLast = NULL;
1073 if (_ILIsPidlSimple(pidl))
1075 /* we are on desktop level */
1077 *ppidlLast = ILClone(pidl);
1078 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1082 pidlChild = ILClone(ILFindLastID(pidl));
1083 pidlParent = ILClone(pidl);
1084 ILRemoveLastID(pidlParent);
1086 hr = SHGetDesktopFolder(&psf);
1089 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1091 if (SUCCEEDED(hr) && ppidlLast)
1092 *ppidlLast = pidlChild;
1096 SHFree (pidlParent);
1097 if (psf) IShellFolder_Release(psf);
1101 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1105 /*************************************************************************
1106 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1108 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1110 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1112 if (SHELL_OsIsUnicode())
1113 return SHGetPathFromIDListW(pidl,pszPath);
1114 return SHGetPathFromIDListA(pidl,pszPath);
1117 /**************************************************************************
1119 * internal functions
1121 * ### 1. section creating pidls ###
1123 *************************************************************************
1124 * _ILCreateDesktop()
1125 * _ILCreateIExplore()
1126 * _ILCreateMyComputer()
1131 LPITEMIDLIST _ILCreateDesktop()
1133 return _ILCreate(PT_DESKTOP, NULL, 0);
1136 LPITEMIDLIST _ILCreateMyComputer()
1138 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1141 LPITEMIDLIST _ILCreateIExplore()
1143 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1146 LPITEMIDLIST _ILCreateControl()
1148 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1151 LPITEMIDLIST _ILCreatePrinter()
1153 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1156 LPITEMIDLIST _ILCreateNetwork()
1158 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1161 LPITEMIDLIST _ILCreateBitBucket()
1163 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1166 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1168 lstrcpynA (sTemp,lpszNew,4);
1171 TRACE("(%s)\n",sTemp);
1172 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1175 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1177 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1178 char * pbuff = buff;
1182 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1184 /* prepare buffer with both names */
1185 len = strlen (stffile->cFileName) + 1;
1186 memcpy (pbuff, stffile->cFileName, len);
1189 if (stffile->cAlternateFileName)
1191 len1 = strlen (stffile->cAlternateFileName)+1;
1192 memcpy (pbuff, stffile->cAlternateFileName, len1);
1200 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1202 /* set attributes */
1206 pData = _ILGetDataPointer(pidl);
1207 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1208 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1209 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1215 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1217 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1218 char * pbuff = buff;
1222 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1224 /* prepare buffer with both names */
1225 len = strlen (stffile->cFileName) + 1;
1226 memcpy (pbuff, stffile->cFileName, len);
1229 if (stffile->cAlternateFileName)
1231 len1 = strlen (stffile->cAlternateFileName)+1;
1232 memcpy (pbuff, stffile->cAlternateFileName, len1);
1240 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1242 /* set attributes */
1246 pData = _ILGetDataPointer(pidl);
1247 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1248 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1249 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1255 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1260 if (!MultiByteToWideChar( CP_ACP, 0, szGUID, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1262 CLSIDFromString( buffer, &iid );
1263 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1266 /**************************************************************************
1268 * Creates a new PIDL
1269 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1271 * uInSize = size of data (raw)
1274 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT uInSize)
1276 LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1281 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1290 uSize = 2 + 2 + sizeof(GUID);
1297 uSize = 2 + 12 + uInSize;
1300 FIXME("can't create type: 0x%08x\n",type);
1304 if(!(pidlOut = SHAlloc(uSize + 2))) return NULL;
1305 ZeroMemory(pidlOut, uSize + 2);
1306 pidlOut->mkid.cb = uSize;
1311 TRACE("- create Desktop\n");
1316 pData =_ILGetDataPointer(pidlOut);
1318 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1319 TRACE("- create GUID-pidl\n");
1323 pData =_ILGetDataPointer(pidlOut);
1325 pszDest = _ILGetTextPointer(pidlOut);
1326 memcpy(pszDest, pIn, uInSize);
1327 TRACE("- create Drive: %s\n",debugstr_a(pszDest));
1332 pData =_ILGetDataPointer(pidlOut);
1334 pszDest = _ILGetTextPointer(pidlOut);
1335 memcpy(pszDest, pIn, uInSize);
1336 TRACE("- create Value: %s\n",debugstr_a(pszDest));
1340 pidlTemp = ILGetNext(pidlOut);
1342 pidlTemp->mkid.cb = 0x00;
1344 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1348 /**************************************************************************
1351 * Gets the text for the drive eg. 'c:\'
1356 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1357 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1359 if(_ILIsMyComputer(pidl))
1360 pidl = ILGetNext(pidl);
1362 if (pidl && _ILIsDrive(pidl))
1363 return _ILSimpleGetText(pidl, pOut, uSize);
1368 /**************************************************************************
1370 * ### 2. section testing pidls ###
1372 **************************************************************************
1375 * _ILIsSpecialFolder()
1381 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1382 { TRACE("(%p)\n",pidl);
1383 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
1386 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1388 REFIID iid = _ILGetGUIDPointer(pidl);
1390 TRACE("(%p)\n",pidl);
1393 return IsEqualIID(iid, &CLSID_MyComputer);
1397 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1399 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1400 TRACE("(%p)\n",pidl);
1401 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1402 (pidl && pidl->mkid.cb == 0x00)
1406 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1407 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1408 TRACE("(%p)\n",pidl);
1409 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1410 PT_DRIVE1 == lpPData->type ||
1411 PT_DRIVE2 == lpPData->type ||
1412 PT_DRIVE3 == lpPData->type));
1415 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1416 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1417 TRACE("(%p)\n",pidl);
1418 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1421 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1422 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1423 TRACE("(%p)\n",pidl);
1424 return (pidl && lpPData && PT_VALUE == lpPData->type);
1427 /**************************************************************************
1430 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1434 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1436 WORD len = pidl->mkid.cb;
1437 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1438 if (pidlnext->mkid.cb)
1442 TRACE("%s\n", ret ? "Yes" : "No");
1446 /**************************************************************************
1448 * ### 3. section getting values from pidls ###
1451 /**************************************************************************
1454 * gets the text for the first item in the pidl (eg. simple pidl)
1456 * returns the length of the string
1458 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1463 char szTemp[MAX_PATH];
1465 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1467 if (!pidl) return 0;
1472 if (_ILIsDesktop(pidl))
1475 if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1478 lstrcpynA(szOut, szTemp, uOutSize);
1480 dwReturn = strlen (szTemp);
1483 else if (( szSrc = _ILGetTextPointer(pidl) ))
1487 lstrcpynA(szOut, szSrc, uOutSize);
1489 dwReturn = strlen(szSrc);
1491 else if (( riid = _ILGetGUIDPointer(pidl) ))
1493 /* special folder */
1494 if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
1497 lstrcpynA(szOut, szTemp, uOutSize);
1499 dwReturn = strlen (szTemp);
1504 ERR("-- no text\n");
1507 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
1511 /**************************************************************************
1513 * ### 4. getting pointers to parts of pidls ###
1515 **************************************************************************
1516 * _ILGetDataPointer()
1518 LPPIDLDATA _ILGetDataPointer(LPITEMIDLIST pidl)
1520 if(pidl && pidl->mkid.cb != 0x00)
1521 return (LPPIDLDATA) &(pidl->mkid.abID);
1525 /**************************************************************************
1526 * _ILGetTextPointer()
1527 * gets a pointer to the long filename string stored in the pidl
1529 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1530 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1532 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1536 switch (pdata->type)
1546 return (LPSTR)&(pdata->u.drive.szDriveName);
1553 return (LPSTR)&(pdata->u.file.szNames);
1559 return (LPSTR)&(pdata->u.network.szNames);
1565 /**************************************************************************
1566 * _ILGetSTextPointer()
1567 * gets a pointer to the short filename string stored in the pidl
1569 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1570 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1572 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1576 switch (pdata->type)
1582 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1585 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1591 /**************************************************************************
1592 * _ILGetGUIDPointer()
1594 * returns reference to guid stored in some pidls
1596 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1598 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1602 switch (pdata->type)
1606 return (REFIID) &(pdata->u.mycomp.guid);
1612 /*************************************************************************
1613 * _ILGetFileDateTime
1615 * Given the ItemIdList, get the FileTime
1618 * pidl [I] The ItemIDList
1619 * pFt [I] the resulted FILETIME of the file
1622 * True if Successful
1627 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1629 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1631 if(! pdata) return FALSE;
1633 switch (pdata->type)
1636 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1639 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1647 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1652 if (! _ILGetFileDateTime( pidl, &ft )) return FALSE;
1654 FileTimeToLocalFileTime(&ft, &lft);
1655 FileTimeToSystemTime (&lft, &time);
1656 return GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
1659 /*************************************************************************
1662 * Given the ItemIdList, get the FileSize
1665 * pidl [I] The ItemIDList
1666 * pOut [I] The buffer to save the result
1667 * uOutsize [I] The size of the buffer
1673 * pOut can be null when no string is needed
1676 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1678 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1681 if(! pdata) return 0;
1683 switch (pdata->type)
1686 dwSize = pdata->u.file.dwFileSize;
1687 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1690 if (pOut) *pOut = 0x00;
1694 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1696 char szTemp[MAX_PATH];
1697 const char * pPoint;
1698 LPITEMIDLIST pidlTemp=pidl;
1700 TRACE("pidl=%p\n",pidl);
1702 if (!pidl) return FALSE;
1704 pidlTemp = ILFindLastID(pidl);
1706 if (!_ILIsValue(pidlTemp)) return FALSE;
1707 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1709 pPoint = PathFindExtensionA(szTemp);
1711 if (! *pPoint) return FALSE;
1714 lstrcpynA(pOut, pPoint, uOutSize);
1720 /*************************************************************************
1723 * Given the ItemIdList, get the file type description
1726 * pidl [I] The ItemIDList (simple)
1727 * pOut [I] The buffer to save the result
1728 * uOutsize [I] The size of the buffer
1734 * This function copies as much as possible into the buffer.
1736 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1738 if(_ILIsValue(pidl))
1745 if (_ILGetExtension (pidl, sTemp, 64))
1747 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1748 && HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
1750 lstrcpynA (pOut, sTemp, uOutSize - 6);
1751 strcat (pOut, "-file");
1757 lstrcpynA(pOut, "Folder", uOutSize);
1761 /*************************************************************************
1762 * _ILGetFileAttributes
1764 * Given the ItemIdList, get the Attrib string format
1767 * pidl [I] The ItemIDList
1768 * pOut [I] The buffer to save the result
1769 * uOutsize [I] The size of the Buffer
1775 * return value 0 in case of error is a valid return value
1778 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1780 LPPIDLDATA pData =_ILGetDataPointer(pidl);
1784 if(! pData) return 0;
1789 wAttrib = pData->u.folder.uFileAttribs;
1792 wAttrib = pData->u.file.uFileAttribs;
1799 if(wAttrib & FILE_ATTRIBUTE_READONLY)
1803 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
1807 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
1811 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
1815 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
1824 /*************************************************************************
1827 * free a aPidl struct
1829 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
1835 for(i = 0; i < cidl; i++) SHFree(apidl[i]);
1840 /*************************************************************************
1843 * copies an aPidl struct
1845 LPITEMIDLIST * _ILCopyaPidl(LPITEMIDLIST * apidlsrc, UINT cidl)
1848 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
1849 if(!apidlsrc) return NULL;
1851 for(i = 0; i < cidl; i++)
1852 apidldest[i] = ILClone(apidlsrc[i]);
1857 /*************************************************************************
1858 * _ILCopyCidaToaPidl
1860 * creates aPidl from CIDA
1862 LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPCIDA cida)
1865 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
1867 if(!dst) return NULL;
1870 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
1872 for(i = 0; i < cida->cidl; i++)
1873 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));