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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * a pidl == NULL means desktop and is legal
38 #include "shell32_main.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
45 WINE_DECLARE_DEBUG_CHANNEL(shell
);
47 /* from comctl32.dll */
48 extern LPVOID WINAPI
Alloc(INT
);
49 extern BOOL WINAPI
Free(LPVOID
);
51 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
);
52 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
);
54 /*************************************************************************
57 * Retrieves the display name of an ItemIDList
60 * psf [I] Shell Folder to start with, if NULL the desktop is used
61 * pidl [I] ItemIDList relative to the psf to get the display name for
62 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
63 * type [I] Type of display name to retrieve
64 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
65 * 1 = SHGDN_NORMAL relative to the root folder
66 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
69 * True if the display name could be retrieved successfully, False otherwise
71 static BOOL
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
74 WCHAR wPath
[MAX_PATH
];
76 TRACE("%p %p %p %ld\n", psf
, pidl
, path
, type
);
81 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
82 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
83 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
88 BOOL
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
90 LPSHELLFOLDER psfParent
, lsf
= psf
;
91 HRESULT ret
= NO_ERROR
;
92 LPCITEMIDLIST pidllast
;
96 TRACE("%p %p %p %lx\n", psf
, pidl
, path
, type
);
103 ret
= SHGetDesktopFolder(&lsf
);
110 case ILGDN_FORPARSING
:
111 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
117 flag
= SHGDN_INFOLDER
;
120 FIXME("Unknown type parameter = %lx\n", type
);
121 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
125 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
127 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
130 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
136 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
139 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
142 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
145 IShellFolder_Release(psfParent
);
149 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
152 IShellFolder_Release(lsf
);
153 return SUCCEEDED(ret
);
156 /*************************************************************************
157 * ILGetDisplayNameEx [SHELL32.186]
159 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
161 TRACE_(shell
)("%p %p %p %ld\n", psf
, pidl
, path
, type
);
163 if (SHELL_OsIsUnicode())
164 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
165 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
168 /*************************************************************************
169 * ILGetDisplayName [SHELL32.15]
171 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
173 TRACE_(shell
)("%p %p\n", pidl
, path
);
175 if (SHELL_OsIsUnicode())
176 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
177 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
180 /*************************************************************************
181 * ILFindLastID [SHELL32.16]
184 * observed: pidl=Desktop return=pidl
186 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
188 LPCITEMIDLIST pidlLast
= pidl
;
190 TRACE("(pidl=%p)\n",pidl
);
195 while (pidl
->mkid
.cb
)
198 pidl
= ILGetNext(pidl
);
200 return (LPITEMIDLIST
)pidlLast
;
203 /*************************************************************************
204 * ILRemoveLastID [SHELL32.17]
207 * when pidl=Desktop return=FALSE
209 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
211 TRACE_(shell
)("pidl=%p\n",pidl
);
213 if (_ILIsEmpty(pidl
))
215 ILFindLastID(pidl
)->mkid
.cb
= 0;
219 /*************************************************************************
220 * ILClone [SHELL32.18]
223 * duplicate an idlist
225 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
228 LPITEMIDLIST newpidl
;
233 len
= ILGetSize(pidl
);
234 newpidl
= SHAlloc(len
);
236 memcpy(newpidl
,pidl
,len
);
238 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
244 /*************************************************************************
245 * ILCloneFirst [SHELL32.19]
248 * duplicates the first idlist of a complex pidl
250 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
253 LPITEMIDLIST pidlNew
= NULL
;
255 TRACE("pidl=%p\n", pidl
);
261 pidlNew
= SHAlloc(len
+2);
264 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
267 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
270 TRACE("-- newpidl=%p\n",pidlNew
);
275 /*************************************************************************
276 * ILLoadFromStream (SHELL32.26)
279 * the first two bytes are the len, the pidl is following then
281 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
285 HRESULT ret
= E_FAIL
;
288 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
293 IStream_AddRef (pStream
);
295 if (SUCCEEDED(IStream_Read(pStream
, &wLen
, 2, &dwBytesRead
)))
297 TRACE("PIDL length is %d\n", wLen
);
300 *ppPidl
= SHAlloc (wLen
);
301 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
303 TRACE("Stream read OK\n");
308 WARN("reading pidl failed\n");
320 /* we are not yet fully compatible */
321 if (*ppPidl
&& !pcheck(*ppPidl
))
323 WARN("Check failed\n");
328 IStream_Release (pStream
);
333 /*************************************************************************
334 * ILSaveToStream (SHELL32.27)
337 * the first two bytes are the len, the pidl is following then
339 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
342 HRESULT ret
= E_FAIL
;
344 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
346 IStream_AddRef (pStream
);
348 wLen
= ILGetSize(pPidl
);
350 if (SUCCEEDED(IStream_Write(pStream
, &wLen
, 2, NULL
)))
352 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
355 IStream_Release (pStream
);
360 /*************************************************************************
361 * SHILCreateFromPath [SHELL32.28]
363 * Create an ItemIDList from a path
368 * attributes [I/O] requested attributes on call and actual attributes when
369 * the function returns
372 * NO_ERROR if successful, or an OLE errer code otherwise
375 * Wrapper for IShellFolder_ParseDisplayName().
377 static HRESULT
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
379 WCHAR lpszDisplayName
[MAX_PATH
];
381 TRACE_(shell
)("%s %p 0x%08lx\n", path
, ppidl
, attributes
? *attributes
: 0);
383 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
384 lpszDisplayName
[MAX_PATH
-1] = 0;
386 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
389 HRESULT
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
393 HRESULT ret
= E_FAIL
;
395 TRACE_(shell
)("%s %p 0x%08lx\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
397 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
399 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
400 IShellFolder_Release(sf
);
405 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
407 if ( SHELL_OsIsUnicode())
408 return SHILCreateFromPathW (path
, ppidl
, attributes
);
409 return SHILCreateFromPathA (path
, ppidl
, attributes
);
412 /*************************************************************************
413 * SHCloneSpecialIDList [SHELL32.89]
415 * Create an ItemIDList to one of the special folders.
419 * nFolder [in] CSIDL_xxxxx
420 * fCreate [in] Create folder if it does not exist
423 * Success: The newly created pidl
424 * Failure: NULL, if inputs are invalid.
427 * exported by ordinal.
428 * Caller is responsible for deallocating the returned ItemIDList with the
429 * shells IMalloc interface, aka ILFree.
431 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
434 TRACE_(shell
)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
437 nFolder
|= CSIDL_FLAG_CREATE
;
439 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
443 /*************************************************************************
444 * ILGlobalClone [SHELL32.20]
446 * Clones an ItemIDList using Alloc.
449 * pidl [I] ItemIDList to clone
452 * Newly allocated ItemIDList.
455 * exported by ordinal.
457 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
460 LPITEMIDLIST newpidl
;
465 len
= ILGetSize(pidl
);
466 newpidl
= Alloc(len
);
468 memcpy(newpidl
,pidl
,len
);
470 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
476 /*************************************************************************
477 * ILIsEqual [SHELL32.21]
480 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
482 char szData1
[MAX_PATH
];
483 char szData2
[MAX_PATH
];
485 LPCITEMIDLIST pidltemp1
= pidl1
;
486 LPCITEMIDLIST pidltemp2
= pidl2
;
488 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
491 * Explorer reads from registry directly (StreamMRU),
492 * so we can only check here
494 if (!pcheck(pidl1
) || !pcheck (pidl2
))
500 if (!pidl1
|| !pidl2
)
503 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
505 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
506 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
508 if (lstrcmpiA( szData1
, szData2
))
511 pidltemp1
= ILGetNext(pidltemp1
);
512 pidltemp2
= ILGetNext(pidltemp2
);
515 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
521 /*************************************************************************
522 * ILIsParent [SHELL32.23]
524 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
529 * bImmediate [I] only return true if the parent is the direct parent
533 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
537 * parent = a/b, child = a/b/c -> true, c is in folder a/b
538 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
539 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
540 * child = a/b -> false if bImmediate is true
541 * child = a/b -> true if bImmediate is false
543 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
545 char szData1
[MAX_PATH
];
546 char szData2
[MAX_PATH
];
547 LPCITEMIDLIST pParent
= pidlParent
;
548 LPCITEMIDLIST pChild
= pidlChild
;
550 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
552 if (!pParent
|| !pChild
)
555 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
557 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
558 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
560 if (lstrcmpiA( szData1
, szData2
))
563 pParent
= ILGetNext(pParent
);
564 pChild
= ILGetNext(pChild
);
567 /* child has shorter name than parent */
568 if (pParent
->mkid
.cb
)
571 /* not immediate descent */
572 if ((!pChild
->mkid
.cb
|| ILGetNext(pChild
)->mkid
.cb
) && bImmediate
)
578 /*************************************************************************
579 * ILFindChild [SHELL32.24]
581 * Compares elements from pidl1 and pidl2.
588 * pidl1 is desktop pidl2
589 * pidl1 shorter pidl2 pointer to first different element of pidl2
590 * if there was at least one equal element
591 * pidl2 shorter pidl1 0
592 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
595 * exported by ordinal.
597 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
599 char szData1
[MAX_PATH
];
600 char szData2
[MAX_PATH
];
602 LPCITEMIDLIST pidltemp1
= pidl1
;
603 LPCITEMIDLIST pidltemp2
= pidl2
;
604 LPCITEMIDLIST ret
=NULL
;
606 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
608 /* explorer reads from registry directly (StreamMRU),
609 so we can only check here */
610 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
616 if (_ILIsDesktop(pidl1
))
622 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
624 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
625 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
627 if (lstrcmpiA(szData1
,szData2
))
630 pidltemp1
= ILGetNext(pidltemp1
);
631 pidltemp2
= ILGetNext(pidltemp2
);
635 if (pidltemp1
->mkid
.cb
)
636 ret
= NULL
; /* elements of pidl1 left*/
638 TRACE_(shell
)("--- %p\n", ret
);
639 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
642 /*************************************************************************
643 * ILCombine [SHELL32.25]
645 * Concatenates two complex ItemIDLists.
648 * pidl1 [I] first complex ItemIDLists
649 * pidl2 [I] complex ItemIDLists to append
652 * if both pidl's == NULL NULL
653 * if pidl1 == NULL cloned pidl2
654 * if pidl2 == NULL cloned pidl1
655 * otherwise new pidl with pidl2 appended to pidl1
658 * exported by ordinal.
659 * Does not destroy the passed in ItemIDLists!
661 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
664 LPITEMIDLIST pidlNew
;
666 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
668 if (!pidl1
&& !pidl2
) return NULL
;
675 pidlNew
= ILClone(pidl2
);
681 pidlNew
= ILClone(pidl1
);
685 len1
= ILGetSize(pidl1
)-2;
686 len2
= ILGetSize(pidl2
);
687 pidlNew
= SHAlloc(len1
+len2
);
691 memcpy(pidlNew
,pidl1
,len1
);
692 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
695 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
699 /*************************************************************************
700 * SHGetRealIDL [SHELL32.98]
704 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
706 IDataObject
* pDataObj
;
709 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
710 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
716 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
718 fmt
.dwAspect
= DVASPECT_CONTENT
;
720 fmt
.tymed
= TYMED_HGLOBAL
;
722 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
724 IDataObject_Release(pDataObj
);
728 /*assert(pida->cidl==1);*/
729 LPIDA pida
= GlobalLock(medium
.hGlobal
);
731 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
732 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
734 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
739 GlobalUnlock(medium
.hGlobal
);
740 GlobalFree(medium
.hGlobal
);
747 /*************************************************************************
748 * SHLogILFromFSIL [SHELL32.95]
751 * pild = CSIDL_DESKTOP ret = 0
752 * pild = CSIDL_DRIVES ret = 0
754 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
756 FIXME("(pidl=%p)\n",pidl
);
763 /*************************************************************************
764 * ILGetSize [SHELL32.152]
766 * Gets the byte size of an ItemIDList including zero terminator
769 * pidl [I] ItemIDList
772 * size of pidl in bytes
775 * exported by ordinal
777 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
779 LPCSHITEMID si
= &(pidl
->mkid
);
787 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
791 TRACE("pidl=%p size=%u\n",pidl
, len
);
795 /*************************************************************************
796 * ILGetNext [SHELL32.153]
798 * Gets the next ItemID of an ItemIDList
801 * pidl [I] ItemIDList
806 * simple pidl -> pointer to 0x0000 element
809 * exported by ordinal.
811 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
822 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
823 TRACE("-- %p\n", pidl
);
824 return (LPITEMIDLIST
)pidl
;
830 /*************************************************************************
831 * ILAppendID [SHELL32.154]
833 * Adds the single ItemID item to the ItemIDList indicated by pidl.
834 * If bEnd is FALSE, inserts the item in the front of the list,
835 * otherwise it adds the item to the end. (???)
838 * pidl [I] ItemIDList to extend
839 * item [I] ItemID to prepend/append
840 * bEnd [I] Indicates if the item should be appended
843 * Destroys the passed in idlist! (???)
845 LPITEMIDLIST WINAPI
ILAppendID(LPITEMIDLIST pidl
, LPCSHITEMID item
, BOOL bEnd
)
848 LPCITEMIDLIST itemid
= (LPCITEMIDLIST
)item
;
850 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
855 if (_ILIsDesktop(pidl
))
857 idlRet
= ILClone(itemid
);
863 idlRet
= ILCombine(pidl
, itemid
);
865 idlRet
= ILCombine(itemid
, pidl
);
871 /*************************************************************************
872 * ILFree [SHELL32.155]
874 * Frees memory (if not NULL) allocated by SHMalloc allocator
883 * exported by ordinal
885 void WINAPI
ILFree(LPITEMIDLIST pidl
)
887 TRACE("(pidl=%p)\n",pidl
);
891 /*************************************************************************
892 * ILGlobalFree [SHELL32.156]
894 * Frees memory (if not NULL) allocated by Alloc allocator
903 * exported by ordinal.
905 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
912 /*************************************************************************
913 * ILCreateFromPathA [SHELL32.189]
915 * Creates a complex ItemIDList from a path and returns it.
921 * the newly created complex ItemIDList or NULL if failed
924 * exported by ordinal.
926 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
928 LPITEMIDLIST pidlnew
= NULL
;
930 TRACE_(shell
)("%s\n", debugstr_a(path
));
932 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
937 /*************************************************************************
938 * ILCreateFromPathW [SHELL32.190]
940 * See ILCreateFromPathA.
942 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
944 LPITEMIDLIST pidlnew
= NULL
;
946 TRACE_(shell
)("%s\n", debugstr_w(path
));
948 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
953 /*************************************************************************
954 * ILCreateFromPath [SHELL32.157]
956 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
958 if ( SHELL_OsIsUnicode())
959 return ILCreateFromPathW (path
);
960 return ILCreateFromPathA (path
);
963 /*************************************************************************
964 * _ILParsePathW [internal]
966 * Creates an ItemIDList from a path and returns it.
969 * path [I] path to parse and convert into an ItemIDList
970 * lpFindFile [I] pointer to buffer to initialize the FileSystem
971 * Bind Data object with
972 * bBindCtx [I] indicates to create a BindContext and assign a
973 * FileSystem Bind Data object
974 * ppidl [O] the newly create ItemIDList
975 * prgfInOut [I/O] requested attributes on input and actual
976 * attributes on return
979 * NO_ERROR on success or an OLE error code
982 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
983 * creates a BindContext object and assigns a FileSystem Bind Data object
984 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
985 * IShellFolder uses that FileSystem Bind Data object of the BindContext
986 * to pass data about the current path element to the next object. This
987 * is used to avoid having to verify the current path element on disk, so
988 * that creating an ItemIDList from a nonexistent path still can work.
990 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
991 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
993 LPSHELLFOLDER pSF
= NULL
;
997 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
998 ppidl
, ppidl
? *ppidl
: NULL
,
999 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
1001 ret
= SHGetDesktopFolder(&pSF
);
1005 if (lpFindFile
|| bBindCtx
)
1006 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
1010 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
1015 IBindCtx_Release(pBC
);
1019 IShellFolder_Release(pSF
);
1021 if (FAILED(ret
) && ppidl
)
1024 TRACE("%s %p 0x%lx\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1029 /*************************************************************************
1030 * SHSimpleIDListFromPath [SHELL32.162]
1032 * Creates a simple ItemIDList from a path and returns it. This function
1033 * does not fail on nonexistent paths.
1036 * path [I] path to parse and convert into an ItemIDList
1039 * the newly created simple ItemIDList
1042 * Simple in the name does not mean a relative ItemIDList but rather a
1043 * fully qualified list, where only the file name is filled in and the
1044 * directory flag for those ItemID elements this is known about, eg.
1045 * it is not the last element in the ItemIDList or the actual directory
1047 * exported by ordinal.
1049 LPITEMIDLIST
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1051 LPITEMIDLIST pidl
= NULL
;
1052 LPWSTR wPath
= NULL
;
1055 TRACE("%s\n", debugstr_a(lpszPath
));
1059 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1060 wPath
= malloc(len
* sizeof(WCHAR
));
1061 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1064 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1067 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1071 LPITEMIDLIST
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1073 LPITEMIDLIST pidl
= NULL
;
1075 TRACE("%s\n", debugstr_w(lpszPath
));
1077 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1078 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1082 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1084 if ( SHELL_OsIsUnicode())
1085 return SHSimpleIDListFromPathW (lpszPath
);
1086 return SHSimpleIDListFromPathA (lpszPath
);
1089 /*************************************************************************
1090 * SHGetDataFromIDListA [SHELL32.247]
1093 * the pidl can be a simple one. since we can't get the path out of the pidl
1094 * we have to take all data from the pidl
1096 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1097 int nFormat
, LPVOID dest
, int len
)
1099 LPSTR filename
, shortname
;
1100 WIN32_FIND_DATAA
* pfd
;
1102 TRACE_(shell
)("%p, %p, %d, %p, %d.\n", psf
, pidl
, nFormat
, dest
, len
);
1106 return E_INVALIDARG
;
1110 case SHGDFIL_FINDDATA
:
1113 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1114 return E_INVALIDARG
;
1116 if (len
< sizeof(WIN32_FIND_DATAA
))
1117 return E_INVALIDARG
;
1119 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1120 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1121 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1122 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1124 filename
= _ILGetTextPointer(pidl
);
1125 shortname
= _ILGetSTextPointer(pidl
);
1128 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1130 pfd
->cFileName
[0] = '\0';
1133 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1135 pfd
->cAlternateFileName
[0] = '\0';
1138 case SHGDFIL_NETRESOURCE
:
1139 case SHGDFIL_DESCRIPTIONID
:
1140 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1144 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1147 return E_INVALIDARG
;
1150 /*************************************************************************
1151 * SHGetDataFromIDListW [SHELL32.248]
1154 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1155 int nFormat
, LPVOID dest
, int len
)
1157 LPSTR filename
, shortname
;
1158 WIN32_FIND_DATAW
* pfd
= dest
;
1160 TRACE_(shell
)("%p, %p, %d, %p, %d.\n", psf
, pidl
, nFormat
, dest
, len
);
1165 return E_INVALIDARG
;
1169 case SHGDFIL_FINDDATA
:
1172 if (_ILIsDrive(pidl
))
1173 return E_INVALIDARG
;
1175 if (len
< sizeof(WIN32_FIND_DATAW
))
1176 return E_INVALIDARG
;
1178 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAW
));
1179 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1180 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1181 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1183 filename
= _ILGetTextPointer(pidl
);
1184 shortname
= _ILGetSTextPointer(pidl
);
1187 pfd
->cFileName
[0] = '\0';
1188 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1189 pfd
->cFileName
[MAX_PATH
-1] = 0;
1192 pfd
->cAlternateFileName
[0] = '\0';
1193 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1194 pfd
->cAlternateFileName
[13] = 0;
1197 case SHGDFIL_NETRESOURCE
:
1198 case SHGDFIL_DESCRIPTIONID
:
1199 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1203 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1206 return E_INVALIDARG
;
1209 /*************************************************************************
1210 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1214 * pszPath [OUT] path
1217 * path from a passed PIDL.
1220 * NULL returns FALSE
1221 * desktop pidl gives path to desktop directory back
1222 * special pidls returning FALSE
1224 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1226 WCHAR wszPath
[MAX_PATH
];
1229 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1230 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1235 /*************************************************************************
1236 * SHGetPathFromIDListW [SHELL32.@]
1238 * See SHGetPathFromIDListA.
1240 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1242 return SHGetPathFromIDListEx(pidl
, pszPath
, MAX_PATH
, 0);
1245 /*************************************************************************
1246 * SHGetPathFromIDListEx [SHELL32.@]
1248 BOOL WINAPI
SHGetPathFromIDListEx(LPCITEMIDLIST pidl
, WCHAR
*path
, DWORD path_size
, GPFIDL_FLAGS flags
)
1251 LPCITEMIDLIST pidlLast
;
1252 LPSHELLFOLDER psfFolder
;
1256 TRACE_(shell
)("(pidl=%p,%p,%lu,%x)\n", pidl
, path
, path_size
, flags
);
1259 if (flags
!= GPFIDL_DEFAULT
)
1260 FIXME("Unsupported flags %x\n", flags
);
1266 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1267 if (FAILED(hr
)) return FALSE
;
1269 dwAttributes
= SFGAO_FILESYSTEM
;
1270 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1271 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1272 IShellFolder_Release(psfFolder
);
1276 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1277 IShellFolder_Release(psfFolder
);
1278 if (FAILED(hr
)) return FALSE
;
1280 hr
= StrRetToBufW(&strret
, pidlLast
, path
, path_size
);
1282 TRACE_(shell
)("-- %s, 0x%08lx\n",debugstr_w(path
), hr
);
1283 return SUCCEEDED(hr
);
1286 /*************************************************************************
1287 * SHBindToParent [shell version 5.0]
1289 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1291 return SHBindToFolderIDListParent(NULL
, pidl
, riid
, ppv
, ppidlLast
);
1294 /*************************************************************************
1295 * SHBindToFolderIDListParent [SHELL32.@]
1297 HRESULT WINAPI
SHBindToFolderIDListParent(IShellFolder
*psf
, LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1299 IShellFolder
*psfDesktop
= NULL
;
1302 TRACE_(shell
)("%p,%p,%s\n", psf
, pidl
, debugstr_guid(riid
));
1309 return E_INVALIDARG
;
1315 hr
= SHGetDesktopFolder(&psfDesktop
);
1321 if (_ILIsPidlSimple(pidl
))
1323 /* we are on desktop level */
1324 hr
= IShellFolder_QueryInterface(psf
, riid
, ppv
);
1328 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1329 ILRemoveLastID(pidlParent
);
1330 hr
= IShellFolder_BindToObject(psf
, pidlParent
, NULL
, riid
, ppv
);
1335 IShellFolder_Release(psfDesktop
);
1337 if (SUCCEEDED(hr
) && ppidlLast
)
1338 *ppidlLast
= ILFindLastID(pidl
);
1340 TRACE_(shell
)("-- ppv=%p pidl=%p ret=0x%08lx\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1344 HRESULT WINAPI
SHBindToObject(IShellFolder
*psf
, LPCITEMIDLIST pidl
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
1346 IShellFolder
*psfDesktop
= NULL
;
1349 TRACE_(shell
)("%p,%p,%p,%s,%p\n", psf
, pidl
, pbc
, debugstr_guid(riid
), ppv
);
1353 return E_INVALIDARG
;
1359 hr
= SHGetDesktopFolder(&psfDesktop
);
1365 if (_ILIsPidlSimple(pidl
))
1366 /* we are on desktop level */
1367 hr
= IShellFolder_QueryInterface(psf
, riid
, ppv
);
1369 hr
= IShellFolder_BindToObject(psf
, pidl
, pbc
, riid
, ppv
);
1372 IShellFolder_Release(psfDesktop
);
1374 TRACE_(shell
)("-- ppv=%p ret=0x%08lx\n", *ppv
, hr
);
1379 /*************************************************************************
1380 * SHParseDisplayName [SHELL32.@]
1382 HRESULT WINAPI
SHParseDisplayName(LPCWSTR name
, IBindCtx
*bindctx
, LPITEMIDLIST
*pidlist
,
1383 SFGAOF attr_in
, SFGAOF
*attr_out
)
1385 IShellFolder
*desktop
;
1388 TRACE("%s %p %p %ld %p\n", debugstr_w(name
), bindctx
, pidlist
, attr_in
, attr_out
);
1392 if (!name
) return E_INVALIDARG
;
1394 hr
= SHGetDesktopFolder(&desktop
);
1395 if (hr
!= S_OK
) return hr
;
1397 hr
= IShellFolder_ParseDisplayName(desktop
, NULL
, bindctx
, (LPWSTR
)name
, NULL
, pidlist
, &attr_in
);
1398 if (attr_out
) *attr_out
= attr_in
;
1400 IShellFolder_Release(desktop
);
1405 /*************************************************************************
1406 * SHGetNameFromIDList [SHELL32.@]
1408 HRESULT WINAPI
SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl
, SIGDN sigdnName
, PWSTR
*ppszName
)
1410 IShellFolder
*psfparent
;
1411 LPCITEMIDLIST child_pidl
;
1415 TRACE("%p 0x%08x %p\n", pidl
, sigdnName
, ppszName
);
1418 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (void**)&psfparent
, &child_pidl
);
1423 /* sigdnName & 0xffff */
1424 case SIGDN_NORMALDISPLAY
: /* SHGDN_NORMAL */
1425 case SIGDN_PARENTRELATIVEPARSING
: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1426 case SIGDN_PARENTRELATIVEEDITING
: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1427 case SIGDN_DESKTOPABSOLUTEPARSING
: /* SHGDN_FORPARSING */
1428 case SIGDN_DESKTOPABSOLUTEEDITING
: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1429 case SIGDN_PARENTRELATIVEFORADDRESSBAR
: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1430 case SIGDN_PARENTRELATIVE
: /* SIGDN_INFOLDER */
1432 disp_name
.uType
= STRRET_WSTR
;
1433 ret
= IShellFolder_GetDisplayNameOf(psfparent
, child_pidl
,
1437 ret
= StrRetToStrW(&disp_name
, pidl
, ppszName
);
1441 case SIGDN_FILESYSPATH
:
1442 *ppszName
= CoTaskMemAlloc(sizeof(WCHAR
)*MAX_PATH
);
1443 if(SHGetPathFromIDListW(pidl
, *ppszName
))
1445 TRACE("Got string %s\n", debugstr_w(*ppszName
));
1450 CoTaskMemFree(*ppszName
);
1457 FIXME("Unsupported SIGDN %x\n", sigdnName
);
1461 IShellFolder_Release(psfparent
);
1466 /*************************************************************************
1467 * SHGetIDListFromObject [SHELL32.@]
1469 HRESULT WINAPI
SHGetIDListFromObject(IUnknown
*punk
, PIDLIST_ABSOLUTE
*ppidl
)
1471 IPersistIDList
*ppersidl
;
1472 IPersistFolder2
*ppf2
;
1478 return E_NOINTERFACE
;
1482 /* Try IPersistIDList */
1483 ret
= IUnknown_QueryInterface(punk
, &IID_IPersistIDList
, (void**)&ppersidl
);
1486 TRACE("IPersistIDList (%p)\n", ppersidl
);
1487 ret
= IPersistIDList_GetIDList(ppersidl
, ppidl
);
1488 IPersistIDList_Release(ppersidl
);
1493 /* Try IPersistFolder2 */
1494 ret
= IUnknown_QueryInterface(punk
, &IID_IPersistFolder2
, (void**)&ppf2
);
1497 TRACE("IPersistFolder2 (%p)\n", ppf2
);
1498 ret
= IPersistFolder2_GetCurFolder(ppf2
, ppidl
);
1499 IPersistFolder2_Release(ppf2
);
1504 /* Try IDataObject */
1505 ret
= IUnknown_QueryInterface(punk
, &IID_IDataObject
, (void**)&pdo
);
1509 TRACE("IDataObject (%p)\n", pdo
);
1510 ret
= SHGetItemFromDataObject(pdo
, DOGIF_ONLY_IF_ONE
,
1511 &IID_IShellItem
, (void**)&psi
);
1514 ret
= SHGetIDListFromObject((IUnknown
*)psi
, ppidl
);
1515 IShellItem_Release(psi
);
1517 IDataObject_Release(pdo
);
1523 /* Try IFolderView */
1524 ret
= IUnknown_QueryInterface(punk
, &IID_IFolderView
, (void**)&pfv
);
1528 TRACE("IFolderView (%p)\n", pfv
);
1529 ret
= IFolderView_GetFolder(pfv
, &IID_IShellFolder
, (void**)&psf
);
1532 /* We might be able to get IPersistFolder2 from a shellfolder. */
1533 ret
= SHGetIDListFromObject((IUnknown
*)psf
, ppidl
);
1534 IShellFolder_Release(psf
);
1536 IFolderView_Release(pfv
);
1543 /**************************************************************************
1545 * internal functions
1547 * ### 1. section creating pidls ###
1549 *************************************************************************
1552 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1553 * - two bytes are SHITEMID.cb
1554 * - one byte is PIDLDATA.type
1555 * - two bytes are the NULL PIDL terminator
1556 * Sets type of the returned PIDL to type.
1558 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1560 LPITEMIDLIST pidlOut
= NULL
;
1562 pidlOut
= SHAlloc(size
+ 5);
1566 LPITEMIDLIST pidlNext
;
1568 ZeroMemory(pidlOut
, size
+ 5);
1569 pidlOut
->mkid
.cb
= size
+ 3;
1571 pData
= _ILGetDataPointer(pidlOut
);
1575 pidlNext
= ILGetNext(pidlOut
);
1577 pidlNext
->mkid
.cb
= 0x00;
1578 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1584 LPITEMIDLIST
_ILCreateDesktop(void)
1589 ret
= SHAlloc(sizeof(*ret
));
1595 LPITEMIDLIST
_ILCreateMyComputer(void)
1598 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1601 LPITEMIDLIST
_ILCreateMyDocuments(void)
1604 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1607 LPITEMIDLIST
_ILCreateIExplore(void)
1610 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1613 LPITEMIDLIST
_ILCreateControlPanel(void)
1615 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1620 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1624 ret
= ILCombine(parent
, cpl
);
1632 LPITEMIDLIST
_ILCreatePrinters(void)
1634 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1639 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1643 ret
= ILCombine(parent
, printers
);
1651 LPITEMIDLIST
_ILCreateNetwork(void)
1654 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1657 LPITEMIDLIST
_ILCreateBitBucket(void)
1660 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1663 LPITEMIDLIST
_ILCreateNetHood(void)
1666 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1669 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1671 LPITEMIDLIST pidlOut
;
1673 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1675 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1678 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1680 pData
->u
.guid
.guid
= *guid
;
1681 TRACE("-- create GUID-pidl %s\n",
1682 debugstr_guid(&(pData
->u
.guid
.guid
)));
1687 WARN("%d: invalid type for GUID\n", type
);
1693 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1697 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1699 ERR("%s is not a GUID\n", szGUID
);
1702 return _ILCreateGuid(PT_GUID
, &iid
);
1705 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1709 if (FAILED(SHCLSIDFromStringW(szGUID
, &iid
)))
1711 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1714 return _ILCreateGuid(PT_GUID
, &iid
);
1717 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1726 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1728 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1730 alen
= WideCharToMultiByte( CP_ACP
, 0, wfd
->cFileName
, -1, NULL
, 0, NULL
, NULL
);
1731 wlen
= lstrlenW(wfd
->cFileName
) + 1;
1732 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1733 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1736 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1737 FileStruct
*fs
= &pData
->u
.file
;
1741 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1742 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1743 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1744 WideCharToMultiByte( CP_ACP
, 0, wfd
->cFileName
, -1, fs
->szNames
, alen
, NULL
, NULL
);
1746 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1747 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1748 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1749 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1750 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1752 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1753 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1754 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1760 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1763 WIN32_FIND_DATAW stffile
;
1766 return E_INVALIDARG
;
1768 hFile
= FindFirstFileW(szPath
, &stffile
);
1769 if (hFile
== INVALID_HANDLE_VALUE
)
1770 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1774 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1776 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1779 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1781 LPITEMIDLIST pidlOut
;
1783 TRACE("(%s)\n",debugstr_w(lpszNew
));
1785 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1790 pszDest
= _ILGetTextPointer(pidlOut
);
1793 strcpy(pszDest
, "x:\\");
1794 pszDest
[0]=towupper(lpszNew
[0]);
1795 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1801 LPITEMIDLIST
_ILCreateEntireNetwork(void)
1803 LPITEMIDLIST pidlOut
;
1807 pidlOut
= _ILAlloc(PT_NETWORK
, FIELD_OFFSET(PIDLDATA
, u
.network
.szNames
[sizeof("Entire Network")]));
1810 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1812 pData
->u
.network
.dummy
= 0;
1813 strcpy(pData
->u
.network
.szNames
, "Entire Network");
1818 /**************************************************************************
1821 * Gets the text for the drive eg. 'c:\'
1826 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1828 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1830 if(_ILIsMyComputer(pidl
))
1831 pidl
= ILGetNext(pidl
);
1833 if (pidl
&& _ILIsDrive(pidl
))
1834 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1839 /**************************************************************************
1841 * ### 2. section testing pidls ###
1843 **************************************************************************
1847 * _ILIsSpecialFolder()
1853 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1855 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1857 TRACE("(%p)\n",pidl
);
1859 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1862 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1864 TRACE("(%p)\n",pidl
);
1866 return !pidl
|| !pidl
->mkid
.cb
;
1869 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1871 REFIID iid
= _ILGetGUIDPointer(pidl
);
1873 TRACE("(%p)\n",pidl
);
1876 return IsEqualIID(iid
, &CLSID_MyComputer
);
1880 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1882 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1884 TRACE("(%p)\n",pidl
);
1886 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1887 (pidl
&& pidl
->mkid
.cb
== 0x00)
1891 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1893 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1895 TRACE("(%p)\n",pidl
);
1897 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1898 PT_DRIVE1
== lpPData
->type
||
1899 PT_DRIVE2
== lpPData
->type
||
1900 PT_DRIVE3
== lpPData
->type
));
1903 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1905 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1907 TRACE("(%p)\n",pidl
);
1909 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1912 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1914 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1916 TRACE("(%p)\n",pidl
);
1918 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1921 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1923 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1925 TRACE("(%p)\n",pidl
);
1927 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1930 /**************************************************************************
1933 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1937 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1939 WORD len
= pidl
->mkid
.cb
;
1940 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1942 if (pidlnext
->mkid
.cb
)
1946 TRACE("%s\n", ret
? "Yes" : "No");
1950 /**************************************************************************
1952 * ### 3. section getting values from pidls ###
1955 /**************************************************************************
1958 * gets the text for the first item in the pidl (eg. simple pidl)
1960 * returns the length of the string
1962 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1968 char szTemp
[MAX_PATH
];
1970 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1978 if (_ILIsDesktop(pidl
))
1981 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1984 lstrcpynA(szOut
, szTemp
, uOutSize
);
1986 dwReturn
= strlen (szTemp
);
1989 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1993 lstrcpynA(szOut
, szSrc
, uOutSize
);
1995 dwReturn
= strlen(szSrc
);
1997 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1999 /* unicode filesystem */
2000 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
2003 lstrcpynA(szOut
, szTemp
, uOutSize
);
2005 dwReturn
= strlen (szTemp
);
2007 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
2009 /* special folder */
2010 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
2013 lstrcpynA(szOut
, szTemp
, uOutSize
);
2015 dwReturn
= strlen (szTemp
);
2020 ERR("-- no text\n");
2023 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_a(szOut
),dwReturn
);
2027 /**************************************************************************
2030 * gets the text for the first item in the pidl (eg. simple pidl)
2032 * returns the length of the string
2034 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
2037 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
2039 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
2042 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
2043 dwReturn
= lstrlenW(pFileStructW
->wszName
);
2046 WCHAR szTemp
[MAX_PATH
];
2057 if (_ILIsDesktop(pidl
))
2060 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
2063 lstrcpynW(szOut
, szTemp
, uOutSize
);
2065 dwReturn
= lstrlenW (szTemp
);
2068 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
2070 /* unicode filesystem */
2072 lstrcpynW(szOut
, szSrcW
, uOutSize
);
2074 dwReturn
= lstrlenW(szSrcW
);
2076 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
2079 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
2082 lstrcpynW(szOut
, szTemp
, uOutSize
);
2084 dwReturn
= lstrlenW (szTemp
);
2086 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
2088 /* special folder */
2089 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
2092 lstrcpynW(szOut
, szTemp
, uOutSize
);
2094 dwReturn
= lstrlenW (szTemp
);
2099 ERR("-- no text\n");
2103 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_w(szOut
),dwReturn
);
2107 /**************************************************************************
2109 * ### 4. getting pointers to parts of pidls ###
2111 **************************************************************************
2112 * _ILGetDataPointer()
2114 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
2116 if(!_ILIsEmpty(pidl
))
2117 return (LPPIDLDATA
)pidl
->mkid
.abID
;
2121 /**************************************************************************
2122 * _ILGetTextPointerW()
2123 * gets a pointer to the unicode long filename string stored in the pidl
2125 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
2127 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2129 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2134 switch (pdata
->type
)
2145 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2153 /*return (LPSTR)&(pdata->u.file.szNames);*/
2159 case PT_NETPROVIDER
:
2161 /*return (LPSTR)&(pdata->u.network.szNames);*/
2165 return (LPWSTR
)pdata
->u
.file
.szNames
;
2171 /**************************************************************************
2172 * _ILGetTextPointer()
2173 * gets a pointer to the long filename string stored in the pidl
2175 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
2177 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2179 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2184 switch (pdata
->type
)
2195 return pdata
->u
.drive
.szDriveName
;
2202 return pdata
->u
.file
.szNames
;
2207 case PT_NETPROVIDER
:
2209 return pdata
->u
.network
.szNames
;
2214 /**************************************************************************
2215 * _ILGetSTextPointer()
2216 * gets a pointer to the short filename string stored in the pidl
2218 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2220 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2222 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2227 switch (pdata
->type
)
2233 return pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1;
2236 return pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1;
2241 /**************************************************************************
2242 * _ILGetGUIDPointer()
2244 * returns reference to guid stored in some pidls
2246 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2248 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2250 TRACE("%p\n", pidl
);
2255 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2256 switch (pdata
->type
)
2261 return &(pdata
->u
.guid
.guid
);
2264 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2270 /******************************************************************************
2271 * _ILGetFileStructW [Internal]
2273 * Get pointer the a SHITEMID's FileStructW field if present
2276 * pidl [I] The SHITEMID
2279 * Success: Pointer to pidl's FileStructW field.
2282 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2283 FileStructW
*pFileStructW
;
2286 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2289 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2290 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2292 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2293 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2294 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2295 if ((cbOffset
& 0x1) || /* FileStructW member is word aligned in the pidl */
2296 /* FileStructW is positioned after FileStruct */
2297 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2298 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2299 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2300 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2302 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2306 return pFileStructW
;
2309 /*************************************************************************
2310 * _ILGetFileDateTime
2312 * Given the ItemIdList, get the FileTime
2315 * pidl [I] The ItemIDList
2316 * pFt [I] the resulted FILETIME of the file
2319 * True if Successful
2324 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2326 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2331 switch (pdata
->type
)
2335 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2343 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2349 if (_ILGetFileDateTime( pidl
, &ft
))
2351 FileTimeToLocalFileTime(&ft
, &lft
);
2352 FileTimeToSystemTime (&lft
, &time
);
2354 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2357 /* Append space + time without seconds */
2359 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2370 /*************************************************************************
2373 * Given the ItemIdList, get the FileSize
2376 * pidl [I] The ItemIDList
2377 * pOut [I] The buffer to save the result
2378 * uOutsize [I] The size of the buffer
2384 * pOut can be null when no string is needed
2387 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2389 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2395 switch (pdata
->type
)
2398 dwSize
= pdata
->u
.file
.dwFileSize
;
2400 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2408 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2410 char szTemp
[MAX_PATH
];
2411 const char * pPoint
;
2412 LPCITEMIDLIST pidlTemp
=pidl
;
2414 TRACE("pidl=%p\n",pidl
);
2419 pidlTemp
= ILFindLastID(pidl
);
2421 if (!_ILIsValue(pidlTemp
))
2423 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2426 pPoint
= PathFindExtensionA(szTemp
);
2432 lstrcpynA(pOut
, pPoint
, uOutSize
);
2438 /*************************************************************************
2441 * Given the ItemIdList, get the file type description
2444 * pidl [I] The ItemIDList (simple)
2445 * pOut [I] The buffer to save the result
2446 * uOutsize [I] The size of the buffer
2452 * This function copies as much as possible into the buffer.
2454 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2456 if(_ILIsValue(pidl
))
2460 /* "name" or "name." or any unhandled => "File" */
2461 lstrcpynA (pOut
, "File", uOutSize
);
2463 /* If there's space for more, try to get a better description. */
2464 if (uOutSize
> 6 && _ILGetExtension (pidl
, sTemp
, 64))
2466 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2467 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2470 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2471 strcat (pOut
, " file");
2476 lstrcpynA(pOut
, "Folder", uOutSize
);
2479 /*************************************************************************
2480 * _ILGetFileAttributes
2482 * Given the ItemIdList, get the Attrib string format
2485 * pidl [I] The ItemIDList
2486 * pOut [I] The buffer to save the result
2487 * uOutsize [I] The size of the Buffer
2493 * return value 0 in case of error is a valid return value
2496 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2498 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2509 wAttrib
= pData
->u
.file
.uFileAttribs
;
2516 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2518 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2520 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2522 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2524 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2531 /*************************************************************************
2534 * frees an aPidl struct
2536 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2542 for (i
= 0; i
< cidl
; i
++)
2548 /*************************************************************************
2551 * copies an aPidl struct
2553 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2556 LPITEMIDLIST
*apidldest
;
2561 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2563 for (i
= 0; i
< cidl
; i
++)
2564 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2569 /*************************************************************************
2570 * _ILCopyCidaToaPidl
2572 * creates aPidl from CIDA
2574 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2579 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2584 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2586 for (i
= 0; i
< cida
->cidl
; i
++)
2587 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));