4 * Copyright 1998 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * a pidl == NULL means desktop and is legal
33 #include "undocshell.h"
34 #include "shell32_main.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
43 WINE_DECLARE_DEBUG_CHANNEL(shell
);
46 /*************************************************************************
47 * ILGetDisplayName [SHELL32.15]
49 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
,LPSTR path
)
51 TRACE_(shell
)("pidl=%p %p semi-stub\n",pidl
,path
);
52 return SHGetPathFromIDListA(pidl
, path
);
54 /*************************************************************************
55 * ILFindLastID [SHELL32.16]
58 * observed: pidl=Desktop return=pidl
60 LPITEMIDLIST WINAPI
ILFindLastID(LPITEMIDLIST pidl
)
61 { LPITEMIDLIST pidlLast
= pidl
;
63 TRACE("(pidl=%p)\n",pidl
);
68 pidl
= ILGetNext(pidl
);
72 /*************************************************************************
73 * ILRemoveLastID [SHELL32.17]
76 * when pidl=Desktop return=FALSE
78 BOOL WINAPI
ILRemoveLastID(LPCITEMIDLIST pidl
)
80 TRACE_(shell
)("pidl=%p\n",pidl
);
82 if (!pidl
|| !pidl
->mkid
.cb
)
84 ILFindLastID(pidl
)->mkid
.cb
= 0;
88 /*************************************************************************
89 * ILClone [SHELL32.18]
94 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
101 len
= ILGetSize(pidl
);
102 newpidl
= (LPITEMIDLIST
)SHAlloc(len
);
104 memcpy(newpidl
,pidl
,len
);
106 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
111 /*************************************************************************
112 * ILCloneFirst [SHELL32.19]
115 * duplicates the first idlist of a complex pidl
117 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
119 LPITEMIDLIST pidlNew
= NULL
;
121 TRACE("pidl=%p \n",pidl
);
127 pidlNew
= (LPITEMIDLIST
) SHAlloc (len
+2);
130 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
133 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
136 TRACE("-- newpidl=%p\n",pidlNew
);
141 /*************************************************************************
142 * ILLoadFromStream (SHELL32.26)
145 * the first two bytes are the len, the pidl is following then
147 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
150 HRESULT ret
= E_FAIL
;
153 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
160 IStream_AddRef (pStream
);
162 if (SUCCEEDED(IStream_Read(pStream
, (LPVOID
)&wLen
, 2, &dwBytesRead
)))
163 { *ppPidl
= SHAlloc (wLen
);
164 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
173 /* we are not yet fully compatible */
174 if (!pcheck(*ppPidl
))
180 IStream_Release (pStream
);
185 /*************************************************************************
186 * ILSaveToStream (SHELL32.27)
189 * the first two bytes are the len, the pidl is following then
191 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
195 HRESULT ret
= E_FAIL
;
197 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
199 IStream_AddRef (pStream
);
202 while (pidl
->mkid
.cb
)
204 wLen
+= sizeof(WORD
) + pidl
->mkid
.cb
;
205 pidl
= ILGetNext(pidl
);
208 if (SUCCEEDED(IStream_Write(pStream
, (LPVOID
)&wLen
, 2, NULL
)))
210 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
216 IStream_Release (pStream
);
221 /*************************************************************************
222 * SHILCreateFromPath [SHELL32.28]
225 * wraper for IShellFolder::ParseDisplayName()
227 HRESULT WINAPI
SHILCreateFromPathA (LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
229 WCHAR lpszDisplayName
[MAX_PATH
];
231 HRESULT ret
= E_FAIL
;
233 TRACE_(shell
)("%s %p 0x%08lx\n",path
,ppidl
,attributes
?*attributes
:0);
235 if (!MultiByteToWideChar( CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
236 lpszDisplayName
[MAX_PATH
-1] = 0;
238 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
240 ret
= IShellFolder_ParseDisplayName(sf
,0, NULL
,lpszDisplayName
,&pchEaten
,ppidl
,attributes
);
241 IShellFolder_Release(sf
);
245 HRESULT WINAPI
SHILCreateFromPathW (LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
248 HRESULT ret
= E_FAIL
;
250 TRACE_(shell
)("%s %p 0x%08lx\n",debugstr_w(path
),ppidl
,attributes
?*attributes
:0);
252 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
254 ret
= IShellFolder_ParseDisplayName(sf
,0, NULL
, (LPWSTR
) path
, &pchEaten
, ppidl
, attributes
);
255 IShellFolder_Release(sf
);
259 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
261 if ( SHELL_OsIsUnicode())
262 return SHILCreateFromPathW (path
, ppidl
, attributes
);
263 return SHILCreateFromPathA (path
, ppidl
, attributes
);
266 /*************************************************************************
267 * SHCloneSpecialIDList [SHELL32.89]
271 * nFolder [in] CSIDL_xxxxx ??
276 * exported by ordinal
278 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
,DWORD nFolder
,DWORD x3
)
279 { LPITEMIDLIST ppidl
;
280 WARN_(shell
)("(hwnd=0x%x,csidl=0x%lx,0x%lx):semi-stub.\n",
281 hwndOwner
,nFolder
,x3
);
283 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
288 /*************************************************************************
289 * ILGlobalClone [SHELL32.20]
292 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
294 LPITEMIDLIST newpidl
;
299 len
= ILGetSize(pidl
);
300 newpidl
= (LPITEMIDLIST
)pCOMCTL32_Alloc(len
);
302 memcpy(newpidl
,pidl
,len
);
304 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
310 /*************************************************************************
311 * ILIsEqual [SHELL32.21]
314 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
316 char szData1
[MAX_PATH
];
317 char szData2
[MAX_PATH
];
319 LPITEMIDLIST pidltemp1
= pidl1
;
320 LPITEMIDLIST pidltemp2
= pidl2
;
322 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
324 /* explorer reads from registry directly (StreamMRU),
325 so we can only check here */
326 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
))) return FALSE
;
331 if ( (!pidl1
) || (!pidl2
) ) return FALSE
;
333 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
335 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
336 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
338 if (strcasecmp ( szData1
, szData2
)!=0 )
341 pidltemp1
= ILGetNext(pidltemp1
);
342 pidltemp2
= ILGetNext(pidltemp2
);
345 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
352 /*************************************************************************
353 * ILIsParent [SHELL32.23]
355 * parent=a/b child=a/b/c -> true, c is in folder a/b
356 * child=a/b/c/d -> false if bImmediate is true, d is not in folder a/b
357 * child=a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
359 BOOL WINAPI
ILIsParent( LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
361 char szData1
[MAX_PATH
];
362 char szData2
[MAX_PATH
];
364 LPITEMIDLIST pParent
= pidlParent
;
365 LPITEMIDLIST pChild
= pidlChild
;
367 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
369 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
371 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
372 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
374 if (strcasecmp ( szData1
, szData2
)!=0 )
377 pParent
= ILGetNext(pParent
);
378 pChild
= ILGetNext(pChild
);
381 if ( pParent
->mkid
.cb
|| ! pChild
->mkid
.cb
) /* child shorter or has equal length to parent */
384 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
) /* not immediate descent */
390 /*************************************************************************
391 * ILFindChild [SHELL32.24]
394 * Compares elements from pidl1 and pidl2.
396 * pidl1 is desktop pidl2
397 * pidl1 shorter pidl2 pointer to first different element of pidl2
398 * if there was at least one equal element
399 * pidl2 shorter pidl1 0
400 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
402 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
,LPCITEMIDLIST pidl2
)
404 char szData1
[MAX_PATH
];
405 char szData2
[MAX_PATH
];
407 LPITEMIDLIST pidltemp1
= pidl1
;
408 LPITEMIDLIST pidltemp2
= pidl2
;
409 LPITEMIDLIST ret
=NULL
;
411 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
413 /* explorer reads from registry directly (StreamMRU),
414 so we can only check here */
415 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
421 if ( _ILIsDesktop(pidl1
) )
427 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
429 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
430 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
432 if (strcasecmp(szData1
,szData2
))
435 pidltemp1
= ILGetNext(pidltemp1
);
436 pidltemp2
= ILGetNext(pidltemp2
);
440 if (pidltemp1
->mkid
.cb
)
442 ret
= NULL
; /* elements of pidl1 left*/
445 TRACE_(shell
)("--- %p\n", ret
);
446 return ret
; /* pidl 1 is shorter */
449 /*************************************************************************
450 * ILCombine [SHELL32.25]
453 * Concatenates two complex idlists.
454 * The pidl is the first one, pidlsub the next one
455 * Does not destroy the passed in idlists!
457 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
,LPCITEMIDLIST pidl2
)
460 LPITEMIDLIST pidlNew
;
462 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
464 if(!pidl1
&& !pidl2
) return NULL
;
471 pidlNew
= ILClone(pidl2
);
477 pidlNew
= ILClone(pidl1
);
481 len1
= ILGetSize(pidl1
)-2;
482 len2
= ILGetSize(pidl2
);
483 pidlNew
= SHAlloc(len1
+len2
);
487 memcpy(pidlNew
,pidl1
,len1
);
488 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
491 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
494 /*************************************************************************
495 * SHGetRealIDL [SHELL32.98]
499 LPITEMIDLIST WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPITEMIDLIST pidl
, DWORD z
)
501 FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf
,pidl
,z
);
507 /*************************************************************************
508 * SHLogILFromFSIL [SHELL32.95]
511 * pild = CSIDL_DESKTOP ret = 0
512 * pild = CSIDL_DRIVES ret = 0
514 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
516 FIXME("(pidl=%p)\n",pidl
);
523 /*************************************************************************
524 * ILGetSize [SHELL32.152]
525 * gets the byte size of an idlist including zero terminator (pidl)
534 * exported by ordinal
536 DWORD WINAPI
ILGetSize(LPITEMIDLIST pidl
)
538 LPSHITEMID si
= &(pidl
->mkid
);
544 si
= (LPSHITEMID
)(((LPBYTE
)si
)+si
->cb
);
548 TRACE("pidl=%p size=%lu\n",pidl
, len
);
552 /*************************************************************************
553 * ILGetNext [SHELL32.153]
554 * gets the next simple pidl of a complex pidl
556 * observed return values:
559 * simple pidl -> pointer to 0x0000 element
562 LPITEMIDLIST WINAPI
ILGetNext(LPITEMIDLIST pidl
)
571 pidl
= (LPITEMIDLIST
) (((LPBYTE
)pidl
)+len
);
577 /*************************************************************************
578 * ILAppend [SHELL32.154]
581 * Adds the single item to the idlist indicated by pidl.
582 * if bEnd is 0, adds the item to the front of the list,
583 * otherwise adds the item to the end. (???)
584 * Destroys the passed in idlist! (???)
586 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
,LPCITEMIDLIST item
,BOOL bEnd
)
590 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
595 if (_ILIsDesktop(pidl
))
597 idlRet
= ILClone(item
);
605 idlRet
=ILCombine(pidl
,item
);
609 idlRet
=ILCombine(item
,pidl
);
615 /*************************************************************************
616 * ILFree [SHELL32.155]
619 * free_check_ptr - frees memory (if not NULL)
620 * allocated by SHMalloc allocator
621 * exported by ordinal
623 DWORD WINAPI
ILFree(LPITEMIDLIST pidl
)
625 TRACE("(pidl=0x%08lx)\n",(DWORD
)pidl
);
627 if(!pidl
) return FALSE
;
631 /*************************************************************************
632 * ILGlobalFree [SHELL32.156]
635 void WINAPI
ILGlobalFree( LPCITEMIDLIST pidl
)
640 pCOMCTL32_Free(pidl
);
642 /*************************************************************************
643 * ILCreateFromPath [SHELL32.157]
646 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
648 LPITEMIDLIST pidlnew
;
649 DWORD attributes
= 0;
651 TRACE_(shell
)("%s\n",path
);
653 if (SUCCEEDED (SHILCreateFromPathA (path
, &pidlnew
, &attributes
)))
657 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
659 LPITEMIDLIST pidlnew
;
660 DWORD attributes
= 0;
662 TRACE_(shell
)("%s\n",debugstr_w(path
));
664 if (SUCCEEDED (SHILCreateFromPathW (path
, &pidlnew
, &attributes
)))
668 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
670 if ( SHELL_OsIsUnicode())
671 return ILCreateFromPathW (path
);
672 return ILCreateFromPathA (path
);
674 /*************************************************************************
675 * SHSimpleIDListFromPath [SHELL32.162]
677 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA (LPCSTR lpszPath
)
679 LPITEMIDLIST pidl
=NULL
;
681 WIN32_FIND_DATAA stffile
;
683 TRACE("path=%s\n", lpszPath
);
685 if (!lpszPath
) return NULL
;
687 hFile
= FindFirstFileA(lpszPath
, &stffile
);
689 if ( hFile
!= INVALID_HANDLE_VALUE
)
691 if (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
693 pidl
= _ILCreateFolder (&stffile
);
697 pidl
= _ILCreateValue (&stffile
);
703 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW (LPCWSTR lpszPath
)
705 char lpszTemp
[MAX_PATH
];
706 TRACE("path=%s\n",debugstr_w(lpszPath
));
708 if (!WideCharToMultiByte( CP_ACP
, 0, lpszPath
, -1, lpszTemp
, sizeof(lpszTemp
), NULL
, NULL
))
709 lpszTemp
[sizeof(lpszTemp
)-1] = 0;
711 return SHSimpleIDListFromPathA (lpszTemp
);
714 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW (LPCVOID lpszPath
)
716 if ( SHELL_OsIsUnicode())
717 return SHSimpleIDListFromPathW (lpszPath
);
718 return SHSimpleIDListFromPathA (lpszPath
);
721 /*************************************************************************
722 * SHGetSpecialFolderLocation [SHELL32.@]
724 * gets the folder locations from the registry and creates a pidl
725 * creates missing reg keys and directories
729 * nFolder [I] CSIDL_xxxxx
730 * ppidl [O] PIDL of a special folder
733 HRESULT WINAPI
SHGetSpecialFolderLocation(
736 LPITEMIDLIST
* ppidl
)
738 CHAR szPath
[MAX_PATH
];
739 HRESULT hr
= E_INVALIDARG
;
741 TRACE_(shell
)("(%04x,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
749 *ppidl
= _ILCreateDesktop();
753 *ppidl
= _ILCreateMyComputer();
757 *ppidl
= _ILCreateNetwork ();
761 *ppidl
= _ILCreateControl ();
765 *ppidl
= _ILCreatePrinter ();
768 case CSIDL_BITBUCKET
:
769 *ppidl
= _ILCreateBitBucket ();
773 if (SHGetSpecialFolderPathA(hwndOwner
, szPath
, nFolder
, TRUE
))
776 TRACE_(shell
)("Value=%s\n",szPath
);
777 hr
= SHILCreateFromPathA(szPath
, ppidl
, &attributes
);
780 if(*ppidl
) hr
= NOERROR
;
783 TRACE_(shell
)("-- (new pidl %p)\n",*ppidl
);
787 /*************************************************************************
788 * SHGetFolderLocation [SHELL32.@]
791 * the pidl can be a simple one. since we cant get the path out of the pidl
792 * we have to take all data from the pidl
794 HRESULT WINAPI
SHGetFolderLocation(
801 FIXME("0x%04x 0x%08x 0x%08x 0x%08lx %p\n",
802 hwnd
, csidl
, hToken
, dwFlags
, ppidl
);
803 return SHGetSpecialFolderLocation(hwnd
, csidl
, ppidl
);
806 /*************************************************************************
807 * SHGetDataFromIDListA [SHELL32.247]
810 * the pidl can be a simple one. since we cant get the path out of the pidl
811 * we have to take all data from the pidl
813 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, int nFormat
, LPVOID dest
, int len
)
815 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
818 if (!psf
|| !dest
) return E_INVALIDARG
;
822 case SHGDFIL_FINDDATA
:
824 WIN32_FIND_DATAA
* pfd
= dest
;
826 if ( len
< sizeof (WIN32_FIND_DATAA
)) return E_INVALIDARG
;
828 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
829 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
830 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
831 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
832 lstrcpynA(pfd
->cFileName
,_ILGetTextPointer(pidl
), MAX_PATH
);
833 lstrcpynA(pfd
->cAlternateFileName
,_ILGetSTextPointer(pidl
), 14);
837 case SHGDFIL_NETRESOURCE
:
838 case SHGDFIL_DESCRIPTIONID
:
839 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
843 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
848 /*************************************************************************
849 * SHGetDataFromIDListW [SHELL32.248]
852 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, int nFormat
, LPVOID dest
, int len
)
854 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
858 if (! psf
|| !dest
) return E_INVALIDARG
;
862 case SHGDFIL_FINDDATA
:
864 WIN32_FIND_DATAW
* pfd
= dest
;
866 if ( len
< sizeof (WIN32_FIND_DATAW
)) return E_INVALIDARG
;
868 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
869 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
870 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
871 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
872 if (!MultiByteToWideChar( CP_ACP
, 0, _ILGetTextPointer(pidl
), -1,
873 pfd
->cFileName
, MAX_PATH
))
874 pfd
->cFileName
[MAX_PATH
-1] = 0;
875 if (!MultiByteToWideChar( CP_ACP
, 0, _ILGetSTextPointer(pidl
), -1,
876 pfd
->cAlternateFileName
, 14 ))
877 pfd
->cFileName
[13] = 0;
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
);
892 /*************************************************************************
893 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
900 * path from a passed PIDL.
904 * desktop pidl gives path to desktopdirectory back
905 * special pidls returning FALSE
908 * fnGetDisplayNameOf can return different types of OLEString
910 BOOL WINAPI
SHGetPathFromIDListA (LPCITEMIDLIST pidl
,LPSTR pszPath
)
912 LPSHELLFOLDER shellfolder
;
914 TRACE_(shell
)("(pidl=%p,%p)\n",pidl
,pszPath
);
916 if (!pidl
) return FALSE
;
920 if(_ILIsDesktop(pidl
))
922 SHGetSpecialFolderPathA(0, pszPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
924 else if (_ILIsSpecialFolder(ILFindLastID(pidl
)))
926 /* we are somewhere in a special folder */
931 if (SHGetDesktopFolder(&shellfolder
)==S_OK
)
933 if(!SUCCEEDED(IShellFolder_GetDisplayNameOf(shellfolder
,pidl
,SHGDN_FORPARSING
,&str
))) {
934 IShellFolder_Release(shellfolder
);
937 StrRetToStrNA (pszPath
, MAX_PATH
, &str
, pidl
);
938 IShellFolder_Release(shellfolder
);
941 TRACE_(shell
)("-- (%s)\n",pszPath
);
945 /*************************************************************************
946 * SHGetPathFromIDListW [SHELL32.@]
948 BOOL WINAPI
SHGetPathFromIDListW (LPCITEMIDLIST pidl
,LPWSTR pszPath
)
949 { char sTemp
[MAX_PATH
];
951 TRACE_(shell
)("(pidl=%p)\n", pidl
);
953 SHGetPathFromIDListA (pidl
, sTemp
);
954 MultiByteToWideChar( CP_ACP
, 0, sTemp
, -1, pszPath
, MAX_PATH
);
956 TRACE_(shell
)("-- (%s)\n",debugstr_w(pszPath
));
961 /*************************************************************************
962 * SHBindToParent [shell version 5.0]
964 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
967 LPITEMIDLIST pidlChild
, pidlParent
;
970 TRACE_(shell
)("pidl=%p\n", pidl
);
974 if (ppidlLast
) *ppidlLast
= NULL
;
976 if (_ILIsPidlSimple(pidl
))
978 /* we are on desktop level */
980 *ppidlLast
= ILClone(pidl
);
981 hr
= SHGetDesktopFolder((IShellFolder
**)ppv
);
985 pidlChild
= ILClone(ILFindLastID(pidl
));
986 pidlParent
= ILClone(pidl
);
987 ILRemoveLastID(pidlParent
);
989 hr
= SHGetDesktopFolder(&psf
);
992 hr
= IShellFolder_BindToObject(psf
, pidlParent
, NULL
, riid
, ppv
);
994 if (SUCCEEDED(hr
) && ppidlLast
)
995 *ppidlLast
= pidlChild
;
1000 if (psf
) IShellFolder_Release(psf
);
1004 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1008 /*************************************************************************
1009 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1011 BOOL WINAPI
SHGetPathFromIDListAW(LPCITEMIDLIST pidl
,LPVOID pszPath
)
1013 TRACE_(shell
)("(pidl=%p,%p)\n",pidl
,pszPath
);
1015 if (SHELL_OsIsUnicode())
1016 return SHGetPathFromIDListW(pidl
,pszPath
);
1017 return SHGetPathFromIDListA(pidl
,pszPath
);
1020 /**************************************************************************
1022 * internal functions
1024 * ### 1. section creating pidls ###
1026 *************************************************************************
1027 * _ILCreateDesktop()
1028 * _ILCreateIExplore()
1029 * _ILCreateMyComputer()
1034 LPITEMIDLIST
_ILCreateDesktop()
1036 return _ILCreate(PT_DESKTOP
, NULL
, 0);
1039 LPITEMIDLIST
_ILCreateMyComputer()
1041 return _ILCreate(PT_MYCOMP
, &CLSID_MyComputer
, sizeof(GUID
));
1044 LPITEMIDLIST
_ILCreateIExplore()
1046 return _ILCreate(PT_MYCOMP
, &CLSID_Internet
, sizeof(GUID
));
1049 LPITEMIDLIST
_ILCreateControl()
1051 return _ILCreate(PT_SPECIAL
, &CLSID_ControlPanel
, sizeof(GUID
));
1054 LPITEMIDLIST
_ILCreatePrinter()
1056 return _ILCreate(PT_SPECIAL
, &CLSID_Printers
, sizeof(GUID
));
1059 LPITEMIDLIST
_ILCreateNetwork()
1061 return _ILCreate(PT_MYCOMP
, &CLSID_NetworkPlaces
, sizeof(GUID
));
1064 LPITEMIDLIST
_ILCreateBitBucket()
1066 return _ILCreate(PT_MYCOMP
, &CLSID_RecycleBin
, sizeof(GUID
));
1069 LPITEMIDLIST
_ILCreateDrive( LPCSTR lpszNew
)
1071 lstrcpynA (sTemp
,lpszNew
,4);
1074 TRACE("(%s)\n",sTemp
);
1075 return _ILCreate(PT_DRIVE
,(LPVOID
)&sTemp
[0],4);
1078 LPITEMIDLIST
_ILCreateFolder( WIN32_FIND_DATAA
* stffile
)
1080 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1081 char * pbuff
= buff
;
1085 TRACE("(%s, %s)\n",stffile
->cAlternateFileName
, stffile
->cFileName
);
1087 /* prepare buffer with both names */
1088 len
= strlen (stffile
->cFileName
) + 1;
1089 memcpy (pbuff
, stffile
->cFileName
, len
);
1092 if (stffile
->cAlternateFileName
)
1094 len1
= strlen (stffile
->cAlternateFileName
)+1;
1095 memcpy (pbuff
, stffile
->cAlternateFileName
, len1
);
1103 pidl
= _ILCreate(PT_FOLDER
, (LPVOID
)buff
, len
+ len1
);
1105 /* set attributes */
1109 pData
= _ILGetDataPointer(pidl
);
1110 FileTimeToDosDateTime(&(stffile
->ftLastWriteTime
),&pData
->u
.folder
.uFileDate
,&pData
->u
.folder
.uFileTime
);
1111 pData
->u
.folder
.dwFileSize
= stffile
->nFileSizeLow
;
1112 pData
->u
.folder
.uFileAttribs
=stffile
->dwFileAttributes
;
1118 LPITEMIDLIST
_ILCreateValue(WIN32_FIND_DATAA
* stffile
)
1120 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1121 char * pbuff
= buff
;
1125 TRACE("(%s, %s)\n",stffile
->cAlternateFileName
, stffile
->cFileName
);
1127 /* prepare buffer with both names */
1128 len
= strlen (stffile
->cFileName
) + 1;
1129 memcpy (pbuff
, stffile
->cFileName
, len
);
1132 if (stffile
->cAlternateFileName
)
1134 len1
= strlen (stffile
->cAlternateFileName
)+1;
1135 memcpy (pbuff
, stffile
->cAlternateFileName
, len1
);
1143 pidl
= _ILCreate(PT_VALUE
, (LPVOID
)buff
, len
+ len1
);
1145 /* set attributes */
1149 pData
= _ILGetDataPointer(pidl
);
1150 FileTimeToDosDateTime(&(stffile
->ftLastWriteTime
),&pData
->u
.folder
.uFileDate
,&pData
->u
.folder
.uFileTime
);
1151 pData
->u
.folder
.dwFileSize
= stffile
->nFileSizeLow
;
1152 pData
->u
.folder
.uFileAttribs
=stffile
->dwFileAttributes
;
1158 LPITEMIDLIST
_ILCreateSpecial(LPCSTR szGUID
)
1163 if (!MultiByteToWideChar( CP_ACP
, 0, szGUID
, -1, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1165 CLSIDFromString( buffer
, &iid
);
1166 return _ILCreate(PT_MYCOMP
, &iid
, sizeof(IID
));
1169 /**************************************************************************
1171 * Creates a new PIDL
1172 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1174 * uInSize = size of data (raw)
1177 LPITEMIDLIST
_ILCreate(PIDLTYPE type
, LPCVOID pIn
, UINT uInSize
)
1179 LPITEMIDLIST pidlOut
= NULL
, pidlTemp
= NULL
;
1184 TRACE("(0x%02x %p %i)\n",type
,pIn
,uInSize
);
1193 uSize
= 2 + 2 + sizeof(GUID
);
1200 uSize
= 2 + 12 + uInSize
;
1203 FIXME("can't create type: 0x%08x\n",type
);
1207 if(!(pidlOut
= SHAlloc(uSize
+ 2))) return NULL
;
1208 ZeroMemory(pidlOut
, uSize
+ 2);
1209 pidlOut
->mkid
.cb
= uSize
;
1214 TRACE("- create Desktop\n");
1219 pData
=_ILGetDataPointer(pidlOut
);
1221 memcpy(&(pData
->u
.mycomp
.guid
), pIn
, uInSize
);
1222 TRACE("- create GUID-pidl\n");
1226 pData
=_ILGetDataPointer(pidlOut
);
1228 pszDest
= _ILGetTextPointer(pidlOut
);
1229 memcpy(pszDest
, pIn
, uInSize
);
1230 TRACE("- create Drive: %s\n",debugstr_a(pszDest
));
1235 pData
=_ILGetDataPointer(pidlOut
);
1237 pszDest
= _ILGetTextPointer(pidlOut
);
1238 memcpy(pszDest
, pIn
, uInSize
);
1239 TRACE("- create Value: %s\n",debugstr_a(pszDest
));
1243 pidlTemp
= ILGetNext(pidlOut
);
1245 pidlTemp
->mkid
.cb
= 0x00;
1247 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, uSize
);
1251 /**************************************************************************
1254 * Gets the text for the drive eg. 'c:\'
1259 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1260 { TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1262 if(_ILIsMyComputer(pidl
))
1263 pidl
= ILGetNext(pidl
);
1265 if (pidl
&& _ILIsDrive(pidl
))
1266 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1271 /**************************************************************************
1273 * ### 2. section testing pidls ###
1275 **************************************************************************
1278 * _ILIsSpecialFolder()
1284 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1285 { TRACE("(%p)\n",pidl
);
1286 return ( !pidl
|| (pidl
&& pidl
->mkid
.cb
== 0x00) );
1289 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1291 REFIID iid
= _ILGetGUIDPointer(pidl
);
1293 TRACE("(%p)\n",pidl
);
1296 return IsEqualIID(iid
, &CLSID_MyComputer
);
1300 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1302 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1303 TRACE("(%p)\n",pidl
);
1304 return (pidl
&& ( (lpPData
&& (PT_MYCOMP
== lpPData
->type
|| PT_SPECIAL
== lpPData
->type
)) ||
1305 (pidl
&& pidl
->mkid
.cb
== 0x00)
1309 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1310 { LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1311 TRACE("(%p)\n",pidl
);
1312 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1313 PT_DRIVE1
== lpPData
->type
||
1314 PT_DRIVE2
== lpPData
->type
||
1315 PT_DRIVE3
== lpPData
->type
));
1318 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1319 { LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1320 TRACE("(%p)\n",pidl
);
1321 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1324 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1325 { LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1326 TRACE("(%p)\n",pidl
);
1327 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1330 /**************************************************************************
1333 BOOL
_ILIsPidlSimple ( LPCITEMIDLIST pidl
)
1337 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1339 WORD len
= pidl
->mkid
.cb
;
1340 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((LPBYTE
)pidl
) + len
);
1341 if (pidlnext
->mkid
.cb
)
1345 TRACE("%s\n", ret
? "Yes" : "No");
1349 /**************************************************************************
1351 * ### 3. section getting values from pidls ###
1354 /**************************************************************************
1357 * gets the text for the first item in the pidl (eg. simple pidl)
1359 * returns the length of the string
1361 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1366 char szTemp
[MAX_PATH
];
1368 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1370 if (!pidl
) return 0;
1375 if (_ILIsDesktop(pidl
))
1378 if (HCR_GetClassName(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1381 lstrcpynA(szOut
, szTemp
, uOutSize
);
1383 dwReturn
= strlen (szTemp
);
1386 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1390 lstrcpynA(szOut
, szSrc
, uOutSize
);
1392 dwReturn
= strlen(szSrc
);
1394 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1396 /* special folder */
1397 if ( HCR_GetClassName(riid
, szTemp
, MAX_PATH
) )
1400 lstrcpynA(szOut
, szTemp
, uOutSize
);
1402 dwReturn
= strlen (szTemp
);
1407 ERR("-- no text\n");
1410 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1414 /**************************************************************************
1416 * ### 4. getting pointers to parts of pidls ###
1418 **************************************************************************
1419 * _ILGetDataPointer()
1421 LPPIDLDATA
_ILGetDataPointer(LPITEMIDLIST pidl
)
1423 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1424 return (LPPIDLDATA
) &(pidl
->mkid
.abID
);
1428 /**************************************************************************
1429 * _ILGetTextPointer()
1430 * gets a pointer to the long filename string stored in the pidl
1432 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1433 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1435 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1439 switch (pdata
->type
)
1449 return (LPSTR
)&(pdata
->u
.drive
.szDriveName
);
1456 return (LPSTR
)&(pdata
->u
.file
.szNames
);
1462 return (LPSTR
)&(pdata
->u
.network
.szNames
);
1468 /**************************************************************************
1469 * _ILGetSTextPointer()
1470 * gets a pointer to the short filename string stored in the pidl
1472 LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
1473 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1475 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1479 switch (pdata
->type
)
1485 return (LPSTR
)(pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1);
1488 return (LPSTR
)(pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1);
1494 /**************************************************************************
1495 * _ILGetGUIDPointer()
1497 * returns reference to guid stored in some pidls
1499 REFIID
_ILGetGUIDPointer(LPCITEMIDLIST pidl
)
1501 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1503 TRACE("%p\n", pidl
);
1507 TRACE("pdata->type 0x%04x\n", pdata
->type
);
1508 switch (pdata
->type
)
1512 return (REFIID
) &(pdata
->u
.mycomp
.guid
);
1515 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
1522 /*************************************************************************
1523 * _ILGetFileDateTime
1525 * Given the ItemIdList, get the FileTime
1528 * pidl [I] The ItemIDList
1529 * pFt [I] the resulted FILETIME of the file
1532 * True if Successful
1537 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
1539 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1541 if(! pdata
) return FALSE
;
1543 switch (pdata
->type
)
1546 DosDateTimeToFileTime(pdata
->u
.folder
.uFileDate
, pdata
->u
.folder
.uFileTime
, pFt
);
1549 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
1557 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
1562 if (! _ILGetFileDateTime( pidl
, &ft
)) return FALSE
;
1564 FileTimeToLocalFileTime(&ft
, &lft
);
1565 FileTimeToSystemTime (&lft
, &time
);
1566 return GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
1569 /*************************************************************************
1572 * Given the ItemIdList, get the FileSize
1575 * pidl [I] The ItemIDList
1576 * pOut [I] The buffer to save the result
1577 * uOutsize [I] The size of the buffer
1583 * pOut can be null when no string is needed
1586 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
1588 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1591 if(! pdata
) return 0;
1593 switch (pdata
->type
)
1596 dwSize
= pdata
->u
.file
.dwFileSize
;
1597 if (pOut
) StrFormatByteSizeA(dwSize
, pOut
, uOutSize
);
1600 if (pOut
) *pOut
= 0x00;
1604 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
1606 char szTemp
[MAX_PATH
];
1607 const char * pPoint
;
1608 LPITEMIDLIST pidlTemp
=pidl
;
1610 TRACE("pidl=%p\n",pidl
);
1612 if (!pidl
) return FALSE
;
1614 pidlTemp
= ILFindLastID(pidl
);
1616 if (!_ILIsValue(pidlTemp
)) return FALSE
;
1617 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
)) return FALSE
;
1619 pPoint
= PathFindExtensionA(szTemp
);
1621 if (! *pPoint
) return FALSE
;
1624 lstrcpynA(pOut
, pPoint
, uOutSize
);
1630 /*************************************************************************
1633 * Given the ItemIdList, get the file type description
1636 * pidl [I] The ItemIDList (simple)
1637 * pOut [I] The buffer to save the result
1638 * uOutsize [I] The size of the buffer
1644 * This function copies as much as possible into the buffer.
1646 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
1648 if(_ILIsValue(pidl
))
1655 if (_ILGetExtension (pidl
, sTemp
, 64))
1657 if (!( HCR_MapTypeToValue(sTemp
, sTemp
, 64, TRUE
)
1658 && HCR_MapTypeToValue(sTemp
, pOut
, uOutSize
, FALSE
)))
1660 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
1661 strcat (pOut
, "-file");
1667 lstrcpynA(pOut
, "Folder", uOutSize
);
1671 /*************************************************************************
1672 * _ILGetFileAttributes
1674 * Given the ItemIdList, get the Attrib string format
1677 * pidl [I] The ItemIDList
1678 * pOut [I] The buffer to save the result
1679 * uOutsize [I] The size of the Buffer
1685 * return value 0 in case of error is a valid return value
1688 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
1690 LPPIDLDATA pData
=_ILGetDataPointer(pidl
);
1694 if(! pData
) return 0;
1699 wAttrib
= pData
->u
.folder
.uFileAttribs
;
1702 wAttrib
= pData
->u
.file
.uFileAttribs
;
1709 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
1713 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
1717 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
1721 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
1725 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
1734 /*************************************************************************
1737 * free a aPidl struct
1739 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
1745 for(i
= 0; i
< cidl
; i
++) SHFree(apidl
[i
]);
1750 /*************************************************************************
1753 * copies an aPidl struct
1755 LPITEMIDLIST
* _ILCopyaPidl(LPITEMIDLIST
* apidlsrc
, UINT cidl
)
1758 LPITEMIDLIST
* apidldest
= (LPITEMIDLIST
*)SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
1759 if(!apidlsrc
) return NULL
;
1761 for(i
= 0; i
< cidl
; i
++)
1762 apidldest
[i
] = ILClone(apidlsrc
[i
]);
1767 /*************************************************************************
1768 * _ILCopyCidaToaPidl
1770 * creates aPidl from CIDA
1772 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, LPCIDA cida
)
1775 LPITEMIDLIST
* dst
= (LPITEMIDLIST
*)SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
1777 if(!dst
) return NULL
;
1780 *pidl
= ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[0]]));
1782 for(i
= 0; i
< cida
->cidl
; i
++)
1783 dst
[i
] = ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[i
+ 1]]));