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
31 #define NONAMELESSUNION
40 #include "shell32_main.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
47 WINE_DECLARE_DEBUG_CHANNEL(shell
);
49 /* from comctl32.dll */
50 extern LPVOID WINAPI
Alloc(INT
);
51 extern BOOL WINAPI
Free(LPVOID
);
53 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
);
54 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
);
56 /*************************************************************************
59 * Retrieves the display name of an ItemIDList
62 * psf [I] Shell Folder to start with, if NULL the desktop is used
63 * pidl [I] ItemIDList relative to the psf to get the display name for
64 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
65 * type [I] Type of display name to retrieve
66 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
67 * 1 = SHGDN_NORMAL relative to the root folder
68 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
71 * True if the display name could be retrieved successfully, False otherwise
73 static BOOL
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
76 WCHAR wPath
[MAX_PATH
];
78 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
83 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
84 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
85 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
90 BOOL
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
92 LPSHELLFOLDER psfParent
, lsf
= psf
;
93 HRESULT ret
= NO_ERROR
;
94 LPCITEMIDLIST pidllast
;
98 TRACE("%p %p %p %x\n", psf
, pidl
, path
, type
);
105 ret
= SHGetDesktopFolder(&lsf
);
112 case ILGDN_FORPARSING
:
113 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
119 flag
= SHGDN_INFOLDER
;
122 FIXME("Unknown type parameter = %x\n", type
);
123 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
127 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
129 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
132 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
138 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
141 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
144 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
147 IShellFolder_Release(psfParent
);
151 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
154 IShellFolder_Release(lsf
);
155 return SUCCEEDED(ret
);
158 /*************************************************************************
159 * ILGetDisplayNameEx [SHELL32.186]
161 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
163 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
165 if (SHELL_OsIsUnicode())
166 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
167 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
170 /*************************************************************************
171 * ILGetDisplayName [SHELL32.15]
173 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
175 TRACE_(shell
)("%p %p\n", pidl
, path
);
177 if (SHELL_OsIsUnicode())
178 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
179 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
182 /*************************************************************************
183 * ILFindLastID [SHELL32.16]
186 * observed: pidl=Desktop return=pidl
188 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
190 LPCITEMIDLIST pidlLast
= pidl
;
192 TRACE("(pidl=%p)\n",pidl
);
197 while (pidl
->mkid
.cb
)
200 pidl
= ILGetNext(pidl
);
202 return (LPITEMIDLIST
)pidlLast
;
205 /*************************************************************************
206 * ILRemoveLastID [SHELL32.17]
209 * when pidl=Desktop return=FALSE
211 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
213 TRACE_(shell
)("pidl=%p\n",pidl
);
215 if (_ILIsEmpty(pidl
))
217 ILFindLastID(pidl
)->mkid
.cb
= 0;
221 /*************************************************************************
222 * ILClone [SHELL32.18]
225 * duplicate an idlist
227 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
230 LPITEMIDLIST newpidl
;
235 len
= ILGetSize(pidl
);
236 newpidl
= SHAlloc(len
);
238 memcpy(newpidl
,pidl
,len
);
240 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
246 /*************************************************************************
247 * ILCloneFirst [SHELL32.19]
250 * duplicates the first idlist of a complex pidl
252 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
255 LPITEMIDLIST pidlNew
= NULL
;
257 TRACE("pidl=%p\n", pidl
);
263 pidlNew
= SHAlloc(len
+2);
266 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
269 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
272 TRACE("-- newpidl=%p\n",pidlNew
);
277 /*************************************************************************
278 * ILLoadFromStream (SHELL32.26)
281 * the first two bytes are the len, the pidl is following then
283 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
287 HRESULT ret
= E_FAIL
;
290 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
295 IStream_AddRef (pStream
);
297 if (SUCCEEDED(IStream_Read(pStream
, &wLen
, 2, &dwBytesRead
)))
299 TRACE("PIDL length is %d\n", wLen
);
302 *ppPidl
= SHAlloc (wLen
);
303 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
305 TRACE("Stream read OK\n");
310 WARN("reading pidl failed\n");
322 /* we are not yet fully compatible */
323 if (*ppPidl
&& !pcheck(*ppPidl
))
325 WARN("Check failed\n");
330 IStream_Release (pStream
);
335 /*************************************************************************
336 * ILSaveToStream (SHELL32.27)
339 * the first two bytes are the len, the pidl is following then
341 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
344 HRESULT ret
= E_FAIL
;
346 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
348 IStream_AddRef (pStream
);
350 wLen
= ILGetSize(pPidl
);
352 if (SUCCEEDED(IStream_Write(pStream
, &wLen
, 2, NULL
)))
354 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
357 IStream_Release (pStream
);
362 /*************************************************************************
363 * SHILCreateFromPath [SHELL32.28]
365 * Create an ItemIDList from a path
370 * attributes [I/O] requested attributes on call and actual attributes when
371 * the function returns
374 * NO_ERROR if successful, or an OLE errer code otherwise
377 * Wrapper for IShellFolder_ParseDisplayName().
379 static HRESULT
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
381 WCHAR lpszDisplayName
[MAX_PATH
];
383 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
385 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
386 lpszDisplayName
[MAX_PATH
-1] = 0;
388 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
391 HRESULT
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
395 HRESULT ret
= E_FAIL
;
397 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
399 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
401 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
402 IShellFolder_Release(sf
);
407 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
409 if ( SHELL_OsIsUnicode())
410 return SHILCreateFromPathW (path
, ppidl
, attributes
);
411 return SHILCreateFromPathA (path
, ppidl
, attributes
);
414 /*************************************************************************
415 * SHCloneSpecialIDList [SHELL32.89]
417 * Create an ItemIDList to one of the special folders.
421 * nFolder [in] CSIDL_xxxxx
422 * fCreate [in] Create folder if it does not exist
425 * Success: The newly created pidl
426 * Failure: NULL, if inputs are invalid.
429 * exported by ordinal.
430 * Caller is responsible for deallocating the returned ItemIDList with the
431 * shells IMalloc interface, aka ILFree.
433 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
436 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
439 nFolder
|= CSIDL_FLAG_CREATE
;
441 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
445 /*************************************************************************
446 * ILGlobalClone [SHELL32.20]
448 * Clones an ItemIDList using Alloc.
451 * pidl [I] ItemIDList to clone
454 * Newly allocated ItemIDList.
457 * exported by ordinal.
459 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
462 LPITEMIDLIST newpidl
;
467 len
= ILGetSize(pidl
);
468 newpidl
= Alloc(len
);
470 memcpy(newpidl
,pidl
,len
);
472 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
478 /*************************************************************************
479 * ILIsEqual [SHELL32.21]
482 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
484 char szData1
[MAX_PATH
];
485 char szData2
[MAX_PATH
];
487 LPCITEMIDLIST pidltemp1
= pidl1
;
488 LPCITEMIDLIST pidltemp2
= pidl2
;
490 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
493 * Explorer reads from registry directly (StreamMRU),
494 * so we can only check here
496 if (!pcheck(pidl1
) || !pcheck (pidl2
))
502 if (!pidl1
|| !pidl2
)
505 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
507 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
508 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
510 if (lstrcmpiA( szData1
, szData2
))
513 pidltemp1
= ILGetNext(pidltemp1
);
514 pidltemp2
= ILGetNext(pidltemp2
);
517 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
523 /*************************************************************************
524 * ILIsParent [SHELL32.23]
526 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
531 * bImmediate [I] only return true if the parent is the direct parent
535 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
539 * parent = a/b, child = a/b/c -> true, c is in folder a/b
540 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
541 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
542 * child = a/b -> false if bImmediate is true
543 * child = a/b -> true if bImmediate is false
545 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
547 char szData1
[MAX_PATH
];
548 char szData2
[MAX_PATH
];
549 LPCITEMIDLIST pParent
= pidlParent
;
550 LPCITEMIDLIST pChild
= pidlChild
;
552 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
554 if (!pParent
|| !pChild
)
557 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
559 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
560 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
562 if (lstrcmpiA( szData1
, szData2
))
565 pParent
= ILGetNext(pParent
);
566 pChild
= ILGetNext(pChild
);
569 /* child has shorter name than parent */
570 if (pParent
->mkid
.cb
)
573 /* not immediate descent */
574 if ((!pChild
->mkid
.cb
|| ILGetNext(pChild
)->mkid
.cb
) && bImmediate
)
580 /*************************************************************************
581 * ILFindChild [SHELL32.24]
583 * Compares elements from pidl1 and pidl2.
590 * pidl1 is desktop pidl2
591 * pidl1 shorter pidl2 pointer to first different element of pidl2
592 * if there was at least one equal element
593 * pidl2 shorter pidl1 0
594 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
597 * exported by ordinal.
599 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
601 char szData1
[MAX_PATH
];
602 char szData2
[MAX_PATH
];
604 LPCITEMIDLIST pidltemp1
= pidl1
;
605 LPCITEMIDLIST pidltemp2
= pidl2
;
606 LPCITEMIDLIST ret
=NULL
;
608 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
610 /* explorer reads from registry directly (StreamMRU),
611 so we can only check here */
612 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
618 if (_ILIsDesktop(pidl1
))
624 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
626 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
627 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
629 if (lstrcmpiA(szData1
,szData2
))
632 pidltemp1
= ILGetNext(pidltemp1
);
633 pidltemp2
= ILGetNext(pidltemp2
);
637 if (pidltemp1
->mkid
.cb
)
638 ret
= NULL
; /* elements of pidl1 left*/
640 TRACE_(shell
)("--- %p\n", ret
);
641 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
644 /*************************************************************************
645 * ILCombine [SHELL32.25]
647 * Concatenates two complex ItemIDLists.
650 * pidl1 [I] first complex ItemIDLists
651 * pidl2 [I] complex ItemIDLists to append
654 * if both pidl's == NULL NULL
655 * if pidl1 == NULL cloned pidl2
656 * if pidl2 == NULL cloned pidl1
657 * otherwise new pidl with pidl2 appended to pidl1
660 * exported by ordinal.
661 * Does not destroy the passed in ItemIDLists!
663 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
666 LPITEMIDLIST pidlNew
;
668 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
670 if (!pidl1
&& !pidl2
) return NULL
;
677 pidlNew
= ILClone(pidl2
);
683 pidlNew
= ILClone(pidl1
);
687 len1
= ILGetSize(pidl1
)-2;
688 len2
= ILGetSize(pidl2
);
689 pidlNew
= SHAlloc(len1
+len2
);
693 memcpy(pidlNew
,pidl1
,len1
);
694 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
697 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
701 /*************************************************************************
702 * SHGetRealIDL [SHELL32.98]
706 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
708 IDataObject
* pDataObj
;
711 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
712 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
718 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
720 fmt
.dwAspect
= DVASPECT_CONTENT
;
722 fmt
.tymed
= TYMED_HGLOBAL
;
724 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
726 IDataObject_Release(pDataObj
);
730 /*assert(pida->cidl==1);*/
731 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
733 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
734 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
736 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
741 GlobalUnlock(medium
.u
.hGlobal
);
742 GlobalFree(medium
.u
.hGlobal
);
749 /*************************************************************************
750 * SHLogILFromFSIL [SHELL32.95]
753 * pild = CSIDL_DESKTOP ret = 0
754 * pild = CSIDL_DRIVES ret = 0
756 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
758 FIXME("(pidl=%p)\n",pidl
);
765 /*************************************************************************
766 * ILGetSize [SHELL32.152]
768 * Gets the byte size of an ItemIDList including zero terminator
771 * pidl [I] ItemIDList
774 * size of pidl in bytes
777 * exported by ordinal
779 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
781 LPCSHITEMID si
= &(pidl
->mkid
);
789 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
793 TRACE("pidl=%p size=%u\n",pidl
, len
);
797 /*************************************************************************
798 * ILGetNext [SHELL32.153]
800 * Gets the next ItemID of an ItemIDList
803 * pidl [I] ItemIDList
808 * simple pidl -> pointer to 0x0000 element
811 * exported by ordinal.
813 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
824 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
825 TRACE("-- %p\n", pidl
);
826 return (LPITEMIDLIST
)pidl
;
832 /*************************************************************************
833 * ILAppendID [SHELL32.154]
835 * Adds the single ItemID item to the ItemIDList indicated by pidl.
836 * If bEnd is FALSE, inserts the item in the front of the list,
837 * otherwise it adds the item to the end. (???)
840 * pidl [I] ItemIDList to extend
841 * item [I] ItemID to prepend/append
842 * bEnd [I] Indicates if the item should be appended
845 * Destroys the passed in idlist! (???)
847 LPITEMIDLIST WINAPI
ILAppendID(LPITEMIDLIST pidl
, LPCSHITEMID item
, BOOL bEnd
)
850 LPCITEMIDLIST itemid
= (LPCITEMIDLIST
)item
;
852 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
857 if (_ILIsDesktop(pidl
))
859 idlRet
= ILClone(itemid
);
865 idlRet
= ILCombine(pidl
, itemid
);
867 idlRet
= ILCombine(itemid
, pidl
);
873 /*************************************************************************
874 * ILFree [SHELL32.155]
876 * Frees memory (if not NULL) allocated by SHMalloc allocator
885 * exported by ordinal
887 void WINAPI
ILFree(LPITEMIDLIST pidl
)
889 TRACE("(pidl=%p)\n",pidl
);
893 /*************************************************************************
894 * ILGlobalFree [SHELL32.156]
896 * Frees memory (if not NULL) allocated by Alloc allocator
905 * exported by ordinal.
907 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
914 /*************************************************************************
915 * ILCreateFromPathA [SHELL32.189]
917 * Creates a complex ItemIDList from a path and returns it.
923 * the newly created complex ItemIDList or NULL if failed
926 * exported by ordinal.
928 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
930 LPITEMIDLIST pidlnew
= NULL
;
932 TRACE_(shell
)("%s\n", debugstr_a(path
));
934 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
939 /*************************************************************************
940 * ILCreateFromPathW [SHELL32.190]
942 * See ILCreateFromPathA.
944 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
946 LPITEMIDLIST pidlnew
= NULL
;
948 TRACE_(shell
)("%s\n", debugstr_w(path
));
950 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
955 /*************************************************************************
956 * ILCreateFromPath [SHELL32.157]
958 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
960 if ( SHELL_OsIsUnicode())
961 return ILCreateFromPathW (path
);
962 return ILCreateFromPathA (path
);
965 /*************************************************************************
966 * _ILParsePathW [internal]
968 * Creates an ItemIDList from a path and returns it.
971 * path [I] path to parse and convert into an ItemIDList
972 * lpFindFile [I] pointer to buffer to initialize the FileSystem
973 * Bind Data object with
974 * bBindCtx [I] indicates to create a BindContext and assign a
975 * FileSystem Bind Data object
976 * ppidl [O] the newly create ItemIDList
977 * prgfInOut [I/O] requested attributes on input and actual
978 * attributes on return
981 * NO_ERROR on success or an OLE error code
984 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
985 * creates a BindContext object and assigns a FileSystem Bind Data object
986 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
987 * IShellFolder uses that FileSystem Bind Data object of the BindContext
988 * to pass data about the current path element to the next object. This
989 * is used to avoid having to verify the current path element on disk, so
990 * that creating an ItemIDList from a nonexistent path still can work.
992 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
993 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
995 LPSHELLFOLDER pSF
= NULL
;
999 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
1000 ppidl
, ppidl
? *ppidl
: NULL
,
1001 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
1003 ret
= SHGetDesktopFolder(&pSF
);
1007 if (lpFindFile
|| bBindCtx
)
1008 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
1012 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
1017 IBindCtx_Release(pBC
);
1021 IShellFolder_Release(pSF
);
1023 if (FAILED(ret
) && ppidl
)
1026 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1031 /*************************************************************************
1032 * SHSimpleIDListFromPath [SHELL32.162]
1034 * Creates a simple ItemIDList from a path and returns it. This function
1035 * does not fail on nonexistent paths.
1038 * path [I] path to parse and convert into an ItemIDList
1041 * the newly created simple ItemIDList
1044 * Simple in the name does not mean a relative ItemIDList but rather a
1045 * fully qualified list, where only the file name is filled in and the
1046 * directory flag for those ItemID elements this is known about, eg.
1047 * it is not the last element in the ItemIDList or the actual directory
1049 * exported by ordinal.
1051 LPITEMIDLIST
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1053 LPITEMIDLIST pidl
= NULL
;
1054 LPWSTR wPath
= NULL
;
1057 TRACE("%s\n", debugstr_a(lpszPath
));
1061 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1062 wPath
= heap_alloc(len
* sizeof(WCHAR
));
1063 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1066 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1069 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1073 LPITEMIDLIST
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1075 LPITEMIDLIST pidl
= NULL
;
1077 TRACE("%s\n", debugstr_w(lpszPath
));
1079 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1080 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1084 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1086 if ( SHELL_OsIsUnicode())
1087 return SHSimpleIDListFromPathW (lpszPath
);
1088 return SHSimpleIDListFromPathA (lpszPath
);
1091 /*************************************************************************
1092 * SHGetDataFromIDListA [SHELL32.247]
1095 * the pidl can be a simple one. since we can't get the path out of the pidl
1096 * we have to take all data from the pidl
1098 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1099 int nFormat
, LPVOID dest
, int len
)
1101 LPSTR filename
, shortname
;
1102 WIN32_FIND_DATAA
* pfd
;
1104 TRACE_(shell
)("%p, %p, %d, %p, %d.\n", psf
, pidl
, nFormat
, dest
, len
);
1108 return E_INVALIDARG
;
1112 case SHGDFIL_FINDDATA
:
1115 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1116 return E_INVALIDARG
;
1118 if (len
< sizeof(WIN32_FIND_DATAA
))
1119 return E_INVALIDARG
;
1121 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1122 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1123 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1124 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1126 filename
= _ILGetTextPointer(pidl
);
1127 shortname
= _ILGetSTextPointer(pidl
);
1130 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1132 pfd
->cFileName
[0] = '\0';
1135 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1137 pfd
->cAlternateFileName
[0] = '\0';
1140 case SHGDFIL_NETRESOURCE
:
1141 case SHGDFIL_DESCRIPTIONID
:
1142 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1146 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1149 return E_INVALIDARG
;
1152 /*************************************************************************
1153 * SHGetDataFromIDListW [SHELL32.248]
1156 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1157 int nFormat
, LPVOID dest
, int len
)
1159 LPSTR filename
, shortname
;
1160 WIN32_FIND_DATAW
* pfd
= dest
;
1162 TRACE_(shell
)("%p, %p, %d, %p, %d.\n", psf
, pidl
, nFormat
, dest
, len
);
1167 return E_INVALIDARG
;
1171 case SHGDFIL_FINDDATA
:
1174 if (_ILIsDrive(pidl
))
1175 return E_INVALIDARG
;
1177 if (len
< sizeof(WIN32_FIND_DATAW
))
1178 return E_INVALIDARG
;
1180 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAW
));
1181 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1182 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1183 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1185 filename
= _ILGetTextPointer(pidl
);
1186 shortname
= _ILGetSTextPointer(pidl
);
1189 pfd
->cFileName
[0] = '\0';
1190 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1191 pfd
->cFileName
[MAX_PATH
-1] = 0;
1194 pfd
->cAlternateFileName
[0] = '\0';
1195 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1196 pfd
->cAlternateFileName
[13] = 0;
1199 case SHGDFIL_NETRESOURCE
:
1200 case SHGDFIL_DESCRIPTIONID
:
1201 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1205 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1208 return E_INVALIDARG
;
1211 /*************************************************************************
1212 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1216 * pszPath [OUT] path
1219 * path from a passed PIDL.
1222 * NULL returns FALSE
1223 * desktop pidl gives path to desktop directory back
1224 * special pidls returning FALSE
1226 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1228 WCHAR wszPath
[MAX_PATH
];
1231 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1232 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1237 /*************************************************************************
1238 * SHGetPathFromIDListW [SHELL32.@]
1240 * See SHGetPathFromIDListA.
1242 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1244 return SHGetPathFromIDListEx(pidl
, pszPath
, MAX_PATH
, 0);
1247 /*************************************************************************
1248 * SHGetPathFromIDListEx [SHELL32.@]
1250 BOOL WINAPI
SHGetPathFromIDListEx(LPCITEMIDLIST pidl
, WCHAR
*path
, DWORD path_size
, GPFIDL_FLAGS flags
)
1253 LPCITEMIDLIST pidlLast
;
1254 LPSHELLFOLDER psfFolder
;
1258 TRACE_(shell
)("(pidl=%p,%p,%u,%x)\n", pidl
, path
, path_size
, flags
);
1261 if (flags
!= GPFIDL_DEFAULT
)
1262 FIXME("Unsupported flags %x\n", flags
);
1268 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1269 if (FAILED(hr
)) return FALSE
;
1271 dwAttributes
= SFGAO_FILESYSTEM
;
1272 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1273 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1274 IShellFolder_Release(psfFolder
);
1278 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1279 IShellFolder_Release(psfFolder
);
1280 if (FAILED(hr
)) return FALSE
;
1282 hr
= StrRetToBufW(&strret
, pidlLast
, path
, path_size
);
1284 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(path
), hr
);
1285 return SUCCEEDED(hr
);
1288 /*************************************************************************
1289 * SHBindToParent [shell version 5.0]
1291 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1293 IShellFolder
* psfDesktop
;
1296 TRACE_(shell
)("pidl=%p\n", pidl
);
1300 return E_INVALIDARG
;
1306 hr
= SHGetDesktopFolder(&psfDesktop
);
1310 if (_ILIsPidlSimple(pidl
))
1312 /* we are on desktop level */
1313 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1317 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1318 ILRemoveLastID(pidlParent
);
1319 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1320 SHFree (pidlParent
);
1323 IShellFolder_Release(psfDesktop
);
1325 if (SUCCEEDED(hr
) && ppidlLast
)
1326 *ppidlLast
= ILFindLastID(pidl
);
1328 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1332 HRESULT WINAPI
SHBindToObject(IShellFolder
*psf
, LPCITEMIDLIST pidl
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
1334 IShellFolder
*psfDesktop
= NULL
;
1337 TRACE_(shell
)("%p,%p,%p,%s,%p\n", psf
, pidl
, pbc
, debugstr_guid(riid
), ppv
);
1341 return E_INVALIDARG
;
1347 hr
= SHGetDesktopFolder(&psfDesktop
);
1353 if (_ILIsPidlSimple(pidl
))
1354 /* we are on desktop level */
1355 hr
= IShellFolder_QueryInterface(psf
, riid
, ppv
);
1357 hr
= IShellFolder_BindToObject(psf
, pidl
, pbc
, riid
, ppv
);
1360 IShellFolder_Release(psfDesktop
);
1362 TRACE_(shell
)("-- ppv=%p ret=0x%08x\n", *ppv
, hr
);
1367 /*************************************************************************
1368 * SHParseDisplayName [SHELL32.@]
1370 HRESULT WINAPI
SHParseDisplayName(LPCWSTR name
, IBindCtx
*bindctx
, LPITEMIDLIST
*pidlist
,
1371 SFGAOF attr_in
, SFGAOF
*attr_out
)
1373 IShellFolder
*desktop
;
1376 TRACE("%s %p %p %d %p\n", debugstr_w(name
), bindctx
, pidlist
, attr_in
, attr_out
);
1380 if (!name
) return E_INVALIDARG
;
1382 hr
= SHGetDesktopFolder(&desktop
);
1383 if (hr
!= S_OK
) return hr
;
1385 hr
= IShellFolder_ParseDisplayName(desktop
, NULL
, bindctx
, (LPWSTR
)name
, NULL
, pidlist
, &attr_in
);
1386 if (attr_out
) *attr_out
= attr_in
;
1388 IShellFolder_Release(desktop
);
1393 /*************************************************************************
1394 * SHGetNameFromIDList [SHELL32.@]
1396 HRESULT WINAPI
SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl
, SIGDN sigdnName
, PWSTR
*ppszName
)
1398 IShellFolder
*psfparent
;
1399 LPCITEMIDLIST child_pidl
;
1403 TRACE("%p 0x%08x %p\n", pidl
, sigdnName
, ppszName
);
1406 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (void**)&psfparent
, &child_pidl
);
1411 /* sigdnName & 0xffff */
1412 case SIGDN_NORMALDISPLAY
: /* SHGDN_NORMAL */
1413 case SIGDN_PARENTRELATIVEPARSING
: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1414 case SIGDN_PARENTRELATIVEEDITING
: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1415 case SIGDN_DESKTOPABSOLUTEPARSING
: /* SHGDN_FORPARSING */
1416 case SIGDN_DESKTOPABSOLUTEEDITING
: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1417 case SIGDN_PARENTRELATIVEFORADDRESSBAR
: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1418 case SIGDN_PARENTRELATIVE
: /* SIGDN_INFOLDER */
1420 disp_name
.uType
= STRRET_WSTR
;
1421 ret
= IShellFolder_GetDisplayNameOf(psfparent
, child_pidl
,
1425 ret
= StrRetToStrW(&disp_name
, pidl
, ppszName
);
1429 case SIGDN_FILESYSPATH
:
1430 *ppszName
= CoTaskMemAlloc(sizeof(WCHAR
)*MAX_PATH
);
1431 if(SHGetPathFromIDListW(pidl
, *ppszName
))
1433 TRACE("Got string %s\n", debugstr_w(*ppszName
));
1438 CoTaskMemFree(*ppszName
);
1445 FIXME("Unsupported SIGDN %x\n", sigdnName
);
1449 IShellFolder_Release(psfparent
);
1454 /*************************************************************************
1455 * SHGetIDListFromObject [SHELL32.@]
1457 HRESULT WINAPI
SHGetIDListFromObject(IUnknown
*punk
, PIDLIST_ABSOLUTE
*ppidl
)
1459 IPersistIDList
*ppersidl
;
1460 IPersistFolder2
*ppf2
;
1466 return E_NOINTERFACE
;
1470 /* Try IPersistIDList */
1471 ret
= IUnknown_QueryInterface(punk
, &IID_IPersistIDList
, (void**)&ppersidl
);
1474 TRACE("IPersistIDList (%p)\n", ppersidl
);
1475 ret
= IPersistIDList_GetIDList(ppersidl
, ppidl
);
1476 IPersistIDList_Release(ppersidl
);
1481 /* Try IPersistFolder2 */
1482 ret
= IUnknown_QueryInterface(punk
, &IID_IPersistFolder2
, (void**)&ppf2
);
1485 TRACE("IPersistFolder2 (%p)\n", ppf2
);
1486 ret
= IPersistFolder2_GetCurFolder(ppf2
, ppidl
);
1487 IPersistFolder2_Release(ppf2
);
1492 /* Try IDataObject */
1493 ret
= IUnknown_QueryInterface(punk
, &IID_IDataObject
, (void**)&pdo
);
1497 TRACE("IDataObject (%p)\n", pdo
);
1498 ret
= SHGetItemFromDataObject(pdo
, DOGIF_ONLY_IF_ONE
,
1499 &IID_IShellItem
, (void**)&psi
);
1502 ret
= SHGetIDListFromObject((IUnknown
*)psi
, ppidl
);
1503 IShellItem_Release(psi
);
1505 IDataObject_Release(pdo
);
1511 /* Try IFolderView */
1512 ret
= IUnknown_QueryInterface(punk
, &IID_IFolderView
, (void**)&pfv
);
1516 TRACE("IFolderView (%p)\n", pfv
);
1517 ret
= IFolderView_GetFolder(pfv
, &IID_IShellFolder
, (void**)&psf
);
1520 /* We might be able to get IPersistFolder2 from a shellfolder. */
1521 ret
= SHGetIDListFromObject((IUnknown
*)psf
, ppidl
);
1522 IShellFolder_Release(psf
);
1524 IFolderView_Release(pfv
);
1531 /**************************************************************************
1533 * internal functions
1535 * ### 1. section creating pidls ###
1537 *************************************************************************
1540 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1541 * - two bytes are SHITEMID.cb
1542 * - one byte is PIDLDATA.type
1543 * - two bytes are the NULL PIDL terminator
1544 * Sets type of the returned PIDL to type.
1546 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1548 LPITEMIDLIST pidlOut
= NULL
;
1550 pidlOut
= SHAlloc(size
+ 5);
1554 LPITEMIDLIST pidlNext
;
1556 ZeroMemory(pidlOut
, size
+ 5);
1557 pidlOut
->mkid
.cb
= size
+ 3;
1559 pData
= _ILGetDataPointer(pidlOut
);
1563 pidlNext
= ILGetNext(pidlOut
);
1565 pidlNext
->mkid
.cb
= 0x00;
1566 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1572 LPITEMIDLIST
_ILCreateDesktop(void)
1583 LPITEMIDLIST
_ILCreateMyComputer(void)
1586 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1589 LPITEMIDLIST
_ILCreateMyDocuments(void)
1592 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1595 LPITEMIDLIST
_ILCreateIExplore(void)
1598 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1601 LPITEMIDLIST
_ILCreateControlPanel(void)
1603 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1608 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1612 ret
= ILCombine(parent
, cpl
);
1620 LPITEMIDLIST
_ILCreatePrinters(void)
1622 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1627 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1631 ret
= ILCombine(parent
, printers
);
1639 LPITEMIDLIST
_ILCreateNetwork(void)
1642 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1645 LPITEMIDLIST
_ILCreateBitBucket(void)
1648 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1651 LPITEMIDLIST
_ILCreateNetHood(void)
1654 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1657 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1659 LPITEMIDLIST pidlOut
;
1661 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1663 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1666 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1668 pData
->u
.guid
.guid
= *guid
;
1669 TRACE("-- create GUID-pidl %s\n",
1670 debugstr_guid(&(pData
->u
.guid
.guid
)));
1675 WARN("%d: invalid type for GUID\n", type
);
1681 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1685 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1687 ERR("%s is not a GUID\n", szGUID
);
1690 return _ILCreateGuid(PT_GUID
, &iid
);
1693 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1697 if (FAILED(SHCLSIDFromStringW(szGUID
, &iid
)))
1699 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1702 return _ILCreateGuid(PT_GUID
, &iid
);
1705 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1714 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1716 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1718 alen
= WideCharToMultiByte( CP_ACP
, 0, wfd
->cFileName
, -1, NULL
, 0, NULL
, NULL
);
1719 wlen
= lstrlenW(wfd
->cFileName
) + 1;
1720 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1721 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1724 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1725 FileStruct
*fs
= &pData
->u
.file
;
1729 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1730 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1731 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1732 WideCharToMultiByte( CP_ACP
, 0, wfd
->cFileName
, -1, fs
->szNames
, alen
, NULL
, NULL
);
1734 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1735 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1736 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1737 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1738 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1740 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1741 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1742 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1748 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1751 WIN32_FIND_DATAW stffile
;
1754 return E_INVALIDARG
;
1756 hFile
= FindFirstFileW(szPath
, &stffile
);
1757 if (hFile
== INVALID_HANDLE_VALUE
)
1758 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1762 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1764 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1767 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1769 LPITEMIDLIST pidlOut
;
1771 TRACE("(%s)\n",debugstr_w(lpszNew
));
1773 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1778 pszDest
= _ILGetTextPointer(pidlOut
);
1781 strcpy(pszDest
, "x:\\");
1782 pszDest
[0]=towupper(lpszNew
[0]);
1783 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1789 LPITEMIDLIST
_ILCreateEntireNetwork(void)
1791 LPITEMIDLIST pidlOut
;
1795 pidlOut
= _ILAlloc(PT_NETWORK
, FIELD_OFFSET(PIDLDATA
, u
.network
.szNames
[sizeof("Entire Network")]));
1798 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1800 pData
->u
.network
.dummy
= 0;
1801 strcpy(pData
->u
.network
.szNames
, "Entire Network");
1806 /**************************************************************************
1809 * Gets the text for the drive eg. 'c:\'
1814 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1816 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1818 if(_ILIsMyComputer(pidl
))
1819 pidl
= ILGetNext(pidl
);
1821 if (pidl
&& _ILIsDrive(pidl
))
1822 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1827 /**************************************************************************
1829 * ### 2. section testing pidls ###
1831 **************************************************************************
1835 * _ILIsSpecialFolder()
1841 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1843 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1845 TRACE("(%p)\n",pidl
);
1847 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1850 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1852 TRACE("(%p)\n",pidl
);
1854 return !pidl
|| !pidl
->mkid
.cb
;
1857 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1859 REFIID iid
= _ILGetGUIDPointer(pidl
);
1861 TRACE("(%p)\n",pidl
);
1864 return IsEqualIID(iid
, &CLSID_MyComputer
);
1868 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1870 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1872 TRACE("(%p)\n",pidl
);
1874 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1875 (pidl
&& pidl
->mkid
.cb
== 0x00)
1879 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1881 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1883 TRACE("(%p)\n",pidl
);
1885 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1886 PT_DRIVE1
== lpPData
->type
||
1887 PT_DRIVE2
== lpPData
->type
||
1888 PT_DRIVE3
== lpPData
->type
));
1891 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1893 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1895 TRACE("(%p)\n",pidl
);
1897 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1900 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1902 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1904 TRACE("(%p)\n",pidl
);
1906 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1909 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1911 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1913 TRACE("(%p)\n",pidl
);
1915 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1918 /**************************************************************************
1921 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1925 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1927 WORD len
= pidl
->mkid
.cb
;
1928 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1930 if (pidlnext
->mkid
.cb
)
1934 TRACE("%s\n", ret
? "Yes" : "No");
1938 /**************************************************************************
1940 * ### 3. section getting values from pidls ###
1943 /**************************************************************************
1946 * gets the text for the first item in the pidl (eg. simple pidl)
1948 * returns the length of the string
1950 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1956 char szTemp
[MAX_PATH
];
1958 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1966 if (_ILIsDesktop(pidl
))
1969 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1972 lstrcpynA(szOut
, szTemp
, uOutSize
);
1974 dwReturn
= strlen (szTemp
);
1977 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1981 lstrcpynA(szOut
, szSrc
, uOutSize
);
1983 dwReturn
= strlen(szSrc
);
1985 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1987 /* unicode filesystem */
1988 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1991 lstrcpynA(szOut
, szTemp
, uOutSize
);
1993 dwReturn
= strlen (szTemp
);
1995 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1997 /* special folder */
1998 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
2001 lstrcpynA(szOut
, szTemp
, uOutSize
);
2003 dwReturn
= strlen (szTemp
);
2008 ERR("-- no text\n");
2011 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
2015 /**************************************************************************
2018 * gets the text for the first item in the pidl (eg. simple pidl)
2020 * returns the length of the string
2022 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
2025 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
2027 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
2030 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
2031 dwReturn
= lstrlenW(pFileStructW
->wszName
);
2034 WCHAR szTemp
[MAX_PATH
];
2045 if (_ILIsDesktop(pidl
))
2048 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
2051 lstrcpynW(szOut
, szTemp
, uOutSize
);
2053 dwReturn
= lstrlenW (szTemp
);
2056 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
2058 /* unicode filesystem */
2060 lstrcpynW(szOut
, szSrcW
, uOutSize
);
2062 dwReturn
= lstrlenW(szSrcW
);
2064 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
2067 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
2070 lstrcpynW(szOut
, szTemp
, uOutSize
);
2072 dwReturn
= lstrlenW (szTemp
);
2074 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
2076 /* special folder */
2077 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
2080 lstrcpynW(szOut
, szTemp
, uOutSize
);
2082 dwReturn
= lstrlenW (szTemp
);
2087 ERR("-- no text\n");
2091 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
2095 /**************************************************************************
2097 * ### 4. getting pointers to parts of pidls ###
2099 **************************************************************************
2100 * _ILGetDataPointer()
2102 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
2104 if(!_ILIsEmpty(pidl
))
2105 return (LPPIDLDATA
)pidl
->mkid
.abID
;
2109 /**************************************************************************
2110 * _ILGetTextPointerW()
2111 * gets a pointer to the unicode long filename string stored in the pidl
2113 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
2115 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2117 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2122 switch (pdata
->type
)
2133 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2141 /*return (LPSTR)&(pdata->u.file.szNames);*/
2147 case PT_NETPROVIDER
:
2149 /*return (LPSTR)&(pdata->u.network.szNames);*/
2153 return (LPWSTR
)pdata
->u
.file
.szNames
;
2159 /**************************************************************************
2160 * _ILGetTextPointer()
2161 * gets a pointer to the long filename string stored in the pidl
2163 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
2165 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2167 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2172 switch (pdata
->type
)
2183 return pdata
->u
.drive
.szDriveName
;
2190 return pdata
->u
.file
.szNames
;
2195 case PT_NETPROVIDER
:
2197 return pdata
->u
.network
.szNames
;
2202 /**************************************************************************
2203 * _ILGetSTextPointer()
2204 * gets a pointer to the short filename string stored in the pidl
2206 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2208 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2210 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2215 switch (pdata
->type
)
2221 return pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1;
2224 return pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1;
2229 /**************************************************************************
2230 * _ILGetGUIDPointer()
2232 * returns reference to guid stored in some pidls
2234 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2236 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2238 TRACE("%p\n", pidl
);
2243 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2244 switch (pdata
->type
)
2249 return &(pdata
->u
.guid
.guid
);
2252 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2258 /******************************************************************************
2259 * _ILGetFileStructW [Internal]
2261 * Get pointer the a SHITEMID's FileStructW field if present
2264 * pidl [I] The SHITEMID
2267 * Success: Pointer to pidl's FileStructW field.
2270 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2271 FileStructW
*pFileStructW
;
2274 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2277 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2278 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2280 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2281 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2282 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2283 if ((cbOffset
& 0x1) || /* FileStructW member is word aligned in the pidl */
2284 /* FileStructW is positioned after FileStruct */
2285 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2286 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2287 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2288 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2290 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2294 return pFileStructW
;
2297 /*************************************************************************
2298 * _ILGetFileDateTime
2300 * Given the ItemIdList, get the FileTime
2303 * pidl [I] The ItemIDList
2304 * pFt [I] the resulted FILETIME of the file
2307 * True if Successful
2312 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2314 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2319 switch (pdata
->type
)
2323 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2331 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2337 if (_ILGetFileDateTime( pidl
, &ft
))
2339 FileTimeToLocalFileTime(&ft
, &lft
);
2340 FileTimeToSystemTime (&lft
, &time
);
2342 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2345 /* Append space + time without seconds */
2347 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2358 /*************************************************************************
2361 * Given the ItemIdList, get the FileSize
2364 * pidl [I] The ItemIDList
2365 * pOut [I] The buffer to save the result
2366 * uOutsize [I] The size of the buffer
2372 * pOut can be null when no string is needed
2375 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2377 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2383 switch (pdata
->type
)
2386 dwSize
= pdata
->u
.file
.dwFileSize
;
2388 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2396 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2398 char szTemp
[MAX_PATH
];
2399 const char * pPoint
;
2400 LPCITEMIDLIST pidlTemp
=pidl
;
2402 TRACE("pidl=%p\n",pidl
);
2407 pidlTemp
= ILFindLastID(pidl
);
2409 if (!_ILIsValue(pidlTemp
))
2411 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2414 pPoint
= PathFindExtensionA(szTemp
);
2420 lstrcpynA(pOut
, pPoint
, uOutSize
);
2426 /*************************************************************************
2429 * Given the ItemIdList, get the file type description
2432 * pidl [I] The ItemIDList (simple)
2433 * pOut [I] The buffer to save the result
2434 * uOutsize [I] The size of the buffer
2440 * This function copies as much as possible into the buffer.
2442 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2444 if(_ILIsValue(pidl
))
2448 /* "name" or "name." or any unhandled => "File" */
2449 lstrcpynA (pOut
, "File", uOutSize
);
2451 /* If there's space for more, try to get a better description. */
2452 if (uOutSize
> 6 && _ILGetExtension (pidl
, sTemp
, 64))
2454 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2455 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2458 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2459 strcat (pOut
, " file");
2464 lstrcpynA(pOut
, "Folder", uOutSize
);
2467 /*************************************************************************
2468 * _ILGetFileAttributes
2470 * Given the ItemIdList, get the Attrib string format
2473 * pidl [I] The ItemIDList
2474 * pOut [I] The buffer to save the result
2475 * uOutsize [I] The size of the Buffer
2481 * return value 0 in case of error is a valid return value
2484 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2486 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2497 wAttrib
= pData
->u
.file
.uFileAttribs
;
2504 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2506 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2508 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2510 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2512 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2519 /*************************************************************************
2522 * frees an aPidl struct
2524 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2530 for (i
= 0; i
< cidl
; i
++)
2536 /*************************************************************************
2539 * copies an aPidl struct
2541 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2544 LPITEMIDLIST
*apidldest
;
2549 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2551 for (i
= 0; i
< cidl
; i
++)
2552 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2557 /*************************************************************************
2558 * _ILCopyCidaToaPidl
2560 * creates aPidl from CIDA
2562 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2567 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2572 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2574 for (i
= 0; i
< cida
->cidl
; i
++)
2575 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));