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
26 #include "wine/port.h"
34 #define NONAMELESSUNION
43 #include "undocshell.h"
44 #include "shell32_main.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
51 WINE_DECLARE_DEBUG_CHANNEL(shell
);
53 /* from comctl32.dll */
54 extern LPVOID WINAPI
Alloc(INT
);
55 extern BOOL WINAPI
Free(LPVOID
);
57 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
);
58 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
);
60 /*************************************************************************
63 * Retrieves the display name of an ItemIDList
66 * psf [I] Shell Folder to start with, if NULL the desktop is used
67 * pidl [I] ItemIDList relative to the psf to get the display name for
68 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
69 * type [I] Type of display name to retrieve
70 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
71 * 1 = SHGDN_NORMAL relative to the root folder
72 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
75 * True if the display name could be retrieved successfully, False otherwise
77 static BOOL
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
80 WCHAR wPath
[MAX_PATH
];
82 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
87 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
88 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
89 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
94 BOOL
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
96 LPSHELLFOLDER psfParent
, lsf
= psf
;
97 HRESULT ret
= NO_ERROR
;
98 LPCITEMIDLIST pidllast
;
102 TRACE("%p %p %p %x\n", psf
, pidl
, path
, type
);
109 ret
= SHGetDesktopFolder(&lsf
);
116 case ILGDN_FORPARSING
:
117 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
123 flag
= SHGDN_INFOLDER
;
126 FIXME("Unknown type parameter = %x\n", type
);
127 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
131 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
133 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
136 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
142 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
145 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
148 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
151 IShellFolder_Release(psfParent
);
155 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
158 IShellFolder_Release(lsf
);
159 return SUCCEEDED(ret
);
162 /*************************************************************************
163 * ILGetDisplayNameEx [SHELL32.186]
165 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
167 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
169 if (SHELL_OsIsUnicode())
170 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
171 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
174 /*************************************************************************
175 * ILGetDisplayName [SHELL32.15]
177 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
179 TRACE_(shell
)("%p %p\n", pidl
, path
);
181 if (SHELL_OsIsUnicode())
182 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
183 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
186 /*************************************************************************
187 * ILFindLastID [SHELL32.16]
190 * observed: pidl=Desktop return=pidl
192 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
194 LPCITEMIDLIST pidlLast
= pidl
;
196 TRACE("(pidl=%p)\n",pidl
);
201 while (pidl
->mkid
.cb
)
204 pidl
= ILGetNext(pidl
);
206 return (LPITEMIDLIST
)pidlLast
;
209 /*************************************************************************
210 * ILRemoveLastID [SHELL32.17]
213 * when pidl=Desktop return=FALSE
215 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
217 TRACE_(shell
)("pidl=%p\n",pidl
);
219 if (_ILIsEmpty(pidl
))
221 ILFindLastID(pidl
)->mkid
.cb
= 0;
225 /*************************************************************************
226 * ILClone [SHELL32.18]
229 * duplicate an idlist
231 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
234 LPITEMIDLIST newpidl
;
239 len
= ILGetSize(pidl
);
240 newpidl
= SHAlloc(len
);
242 memcpy(newpidl
,pidl
,len
);
244 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
250 /*************************************************************************
251 * ILCloneFirst [SHELL32.19]
254 * duplicates the first idlist of a complex pidl
256 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
259 LPITEMIDLIST pidlNew
= NULL
;
261 TRACE("pidl=%p\n", pidl
);
267 pidlNew
= SHAlloc(len
+2);
270 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
273 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
276 TRACE("-- newpidl=%p\n",pidlNew
);
281 /*************************************************************************
282 * ILLoadFromStream (SHELL32.26)
285 * the first two bytes are the len, the pidl is following then
287 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
291 HRESULT ret
= E_FAIL
;
294 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
299 IStream_AddRef (pStream
);
301 if (SUCCEEDED(IStream_Read(pStream
, &wLen
, 2, &dwBytesRead
)))
303 TRACE("PIDL length is %d\n", wLen
);
306 *ppPidl
= SHAlloc (wLen
);
307 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
309 TRACE("Stream read OK\n");
314 WARN("reading pidl failed\n");
326 /* we are not yet fully compatible */
327 if (*ppPidl
&& !pcheck(*ppPidl
))
329 WARN("Check failed\n");
334 IStream_Release (pStream
);
339 /*************************************************************************
340 * ILSaveToStream (SHELL32.27)
343 * the first two bytes are the len, the pidl is following then
345 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
348 HRESULT ret
= E_FAIL
;
350 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
352 IStream_AddRef (pStream
);
354 wLen
= ILGetSize(pPidl
);
356 if (SUCCEEDED(IStream_Write(pStream
, &wLen
, 2, NULL
)))
358 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
361 IStream_Release (pStream
);
366 /*************************************************************************
367 * SHILCreateFromPath [SHELL32.28]
369 * Create an ItemIDList from a path
374 * attributes [I/O] requested attributes on call and actual attributes when
375 * the function returns
378 * NO_ERROR if successful, or an OLE errer code otherwise
381 * Wrapper for IShellFolder_ParseDisplayName().
383 static HRESULT
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
385 WCHAR lpszDisplayName
[MAX_PATH
];
387 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
389 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
390 lpszDisplayName
[MAX_PATH
-1] = 0;
392 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
395 HRESULT
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
399 HRESULT ret
= E_FAIL
;
401 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
403 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
405 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
406 IShellFolder_Release(sf
);
411 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
413 if ( SHELL_OsIsUnicode())
414 return SHILCreateFromPathW (path
, ppidl
, attributes
);
415 return SHILCreateFromPathA (path
, ppidl
, attributes
);
418 /*************************************************************************
419 * SHCloneSpecialIDList [SHELL32.89]
421 * Create an ItemIDList to one of the special folders.
425 * nFolder [in] CSIDL_xxxxx
426 * fCreate [in] Create folder if it does not exist
429 * Success: The newly created pidl
430 * Failure: NULL, if inputs are invalid.
433 * exported by ordinal.
434 * Caller is responsible for deallocating the returned ItemIDList with the
435 * shells IMalloc interface, aka ILFree.
437 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
440 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
443 nFolder
|= CSIDL_FLAG_CREATE
;
445 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
449 /*************************************************************************
450 * ILGlobalClone [SHELL32.20]
452 * Clones an ItemIDList using Alloc.
455 * pidl [I] ItemIDList to clone
458 * Newly allocated ItemIDList.
461 * exported by ordinal.
463 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
466 LPITEMIDLIST newpidl
;
471 len
= ILGetSize(pidl
);
472 newpidl
= Alloc(len
);
474 memcpy(newpidl
,pidl
,len
);
476 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
482 /*************************************************************************
483 * ILIsEqual [SHELL32.21]
486 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
488 char szData1
[MAX_PATH
];
489 char szData2
[MAX_PATH
];
491 LPCITEMIDLIST pidltemp1
= pidl1
;
492 LPCITEMIDLIST pidltemp2
= pidl2
;
494 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
497 * Explorer reads from registry directly (StreamMRU),
498 * so we can only check here
500 if (!pcheck(pidl1
) || !pcheck (pidl2
))
506 if (!pidl1
|| !pidl2
)
509 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
511 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
512 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
514 if (lstrcmpiA( szData1
, szData2
))
517 pidltemp1
= ILGetNext(pidltemp1
);
518 pidltemp2
= ILGetNext(pidltemp2
);
521 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
527 /*************************************************************************
528 * ILIsParent [SHELL32.23]
530 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
535 * bImmediate [I] only return true if the parent is the direct parent
539 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
543 * parent = a/b, child = a/b/c -> true, c is in folder a/b
544 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
545 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
546 * child = a/b -> false if bImmediate is true
547 * child = a/b -> true if bImmediate is false
549 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
551 char szData1
[MAX_PATH
];
552 char szData2
[MAX_PATH
];
553 LPCITEMIDLIST pParent
= pidlParent
;
554 LPCITEMIDLIST pChild
= pidlChild
;
556 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
558 if (!pParent
|| !pChild
)
561 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
563 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
564 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
566 if (lstrcmpiA( szData1
, szData2
))
569 pParent
= ILGetNext(pParent
);
570 pChild
= ILGetNext(pChild
);
573 /* child has shorter name than parent */
574 if (pParent
->mkid
.cb
)
577 /* not immediate descent */
578 if ((!pChild
->mkid
.cb
|| ILGetNext(pChild
)->mkid
.cb
) && bImmediate
)
584 /*************************************************************************
585 * ILFindChild [SHELL32.24]
587 * Compares elements from pidl1 and pidl2.
594 * pidl1 is desktop pidl2
595 * pidl1 shorter pidl2 pointer to first different element of pidl2
596 * if there was at least one equal element
597 * pidl2 shorter pidl1 0
598 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
601 * exported by ordinal.
603 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
605 char szData1
[MAX_PATH
];
606 char szData2
[MAX_PATH
];
608 LPCITEMIDLIST pidltemp1
= pidl1
;
609 LPCITEMIDLIST pidltemp2
= pidl2
;
610 LPCITEMIDLIST ret
=NULL
;
612 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
614 /* explorer reads from registry directly (StreamMRU),
615 so we can only check here */
616 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
622 if (_ILIsDesktop(pidl1
))
628 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
630 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
631 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
633 if (lstrcmpiA(szData1
,szData2
))
636 pidltemp1
= ILGetNext(pidltemp1
);
637 pidltemp2
= ILGetNext(pidltemp2
);
641 if (pidltemp1
->mkid
.cb
)
642 ret
= NULL
; /* elements of pidl1 left*/
644 TRACE_(shell
)("--- %p\n", ret
);
645 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
648 /*************************************************************************
649 * ILCombine [SHELL32.25]
651 * Concatenates two complex ItemIDLists.
654 * pidl1 [I] first complex ItemIDLists
655 * pidl2 [I] complex ItemIDLists to append
658 * if both pidl's == NULL NULL
659 * if pidl1 == NULL cloned pidl2
660 * if pidl2 == NULL cloned pidl1
661 * otherwise new pidl with pidl2 appended to pidl1
664 * exported by ordinal.
665 * Does not destroy the passed in ItemIDLists!
667 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
670 LPITEMIDLIST pidlNew
;
672 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
674 if (!pidl1
&& !pidl2
) return NULL
;
681 pidlNew
= ILClone(pidl2
);
687 pidlNew
= ILClone(pidl1
);
691 len1
= ILGetSize(pidl1
)-2;
692 len2
= ILGetSize(pidl2
);
693 pidlNew
= SHAlloc(len1
+len2
);
697 memcpy(pidlNew
,pidl1
,len1
);
698 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
701 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
705 /*************************************************************************
706 * SHGetRealIDL [SHELL32.98]
710 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
712 IDataObject
* pDataObj
;
715 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
716 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
722 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
724 fmt
.dwAspect
= DVASPECT_CONTENT
;
726 fmt
.tymed
= TYMED_HGLOBAL
;
728 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
730 IDataObject_Release(pDataObj
);
734 /*assert(pida->cidl==1);*/
735 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
737 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
738 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
740 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
745 GlobalUnlock(medium
.u
.hGlobal
);
746 GlobalFree(medium
.u
.hGlobal
);
753 /*************************************************************************
754 * SHLogILFromFSIL [SHELL32.95]
757 * pild = CSIDL_DESKTOP ret = 0
758 * pild = CSIDL_DRIVES ret = 0
760 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
762 FIXME("(pidl=%p)\n",pidl
);
769 /*************************************************************************
770 * ILGetSize [SHELL32.152]
772 * Gets the byte size of an ItemIDList including zero terminator
775 * pidl [I] ItemIDList
778 * size of pidl in bytes
781 * exported by ordinal
783 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
785 LPCSHITEMID si
= &(pidl
->mkid
);
793 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
797 TRACE("pidl=%p size=%u\n",pidl
, len
);
801 /*************************************************************************
802 * ILGetNext [SHELL32.153]
804 * Gets the next ItemID of an ItemIDList
807 * pidl [I] ItemIDList
812 * simple pidl -> pointer to 0x0000 element
815 * exported by ordinal.
817 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
828 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
829 TRACE("-- %p\n", pidl
);
830 return (LPITEMIDLIST
)pidl
;
836 /*************************************************************************
837 * ILAppendID [SHELL32.154]
839 * Adds the single ItemID item to the ItemIDList indicated by pidl.
840 * If bEnd is FALSE, inserts the item in the front of the list,
841 * otherwise it adds the item to the end. (???)
844 * pidl [I] ItemIDList to extend
845 * item [I] ItemID to prepend/append
846 * bEnd [I] Indicates if the item should be appended
849 * Destroys the passed in idlist! (???)
851 LPITEMIDLIST WINAPI
ILAppendID(LPITEMIDLIST pidl
, LPCSHITEMID item
, BOOL bEnd
)
854 LPCITEMIDLIST itemid
= (LPCITEMIDLIST
)item
;
856 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
861 if (_ILIsDesktop(pidl
))
863 idlRet
= ILClone(itemid
);
869 idlRet
= ILCombine(pidl
, itemid
);
871 idlRet
= ILCombine(itemid
, pidl
);
877 /*************************************************************************
878 * ILFree [SHELL32.155]
880 * Frees memory (if not NULL) allocated by SHMalloc allocator
889 * exported by ordinal
891 void WINAPI
ILFree(LPITEMIDLIST pidl
)
893 TRACE("(pidl=%p)\n",pidl
);
897 /*************************************************************************
898 * ILGlobalFree [SHELL32.156]
900 * Frees memory (if not NULL) allocated by Alloc allocator
909 * exported by ordinal.
911 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
918 /*************************************************************************
919 * ILCreateFromPathA [SHELL32.189]
921 * Creates a complex ItemIDList from a path and returns it.
927 * the newly created complex ItemIDList or NULL if failed
930 * exported by ordinal.
932 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
934 LPITEMIDLIST pidlnew
= NULL
;
936 TRACE_(shell
)("%s\n", debugstr_a(path
));
938 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
943 /*************************************************************************
944 * ILCreateFromPathW [SHELL32.190]
946 * See ILCreateFromPathA.
948 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
950 LPITEMIDLIST pidlnew
= NULL
;
952 TRACE_(shell
)("%s\n", debugstr_w(path
));
954 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
959 /*************************************************************************
960 * ILCreateFromPath [SHELL32.157]
962 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
964 if ( SHELL_OsIsUnicode())
965 return ILCreateFromPathW (path
);
966 return ILCreateFromPathA (path
);
969 /*************************************************************************
970 * _ILParsePathW [internal]
972 * Creates an ItemIDList from a path and returns it.
975 * path [I] path to parse and convert into an ItemIDList
976 * lpFindFile [I] pointer to buffer to initialize the FileSystem
977 * Bind Data object with
978 * bBindCtx [I] indicates to create a BindContext and assign a
979 * FileSystem Bind Data object
980 * ppidl [O] the newly create ItemIDList
981 * prgfInOut [I/O] requested attributes on input and actual
982 * attributes on return
985 * NO_ERROR on success or an OLE error code
988 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
989 * creates a BindContext object and assigns a FileSystem Bind Data object
990 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
991 * IShellFolder uses that FileSystem Bind Data object of the BindContext
992 * to pass data about the current path element to the next object. This
993 * is used to avoid having to verify the current path element on disk, so
994 * that creating an ItemIDList from a nonexistent path still can work.
996 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
997 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
999 LPSHELLFOLDER pSF
= NULL
;
1003 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
1004 ppidl
, ppidl
? *ppidl
: NULL
,
1005 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
1007 ret
= SHGetDesktopFolder(&pSF
);
1011 if (lpFindFile
|| bBindCtx
)
1012 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
1016 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
1021 IBindCtx_Release(pBC
);
1025 IShellFolder_Release(pSF
);
1027 if (FAILED(ret
) && ppidl
)
1030 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1035 /*************************************************************************
1036 * SHSimpleIDListFromPath [SHELL32.162]
1038 * Creates a simple ItemIDList from a path and returns it. This function
1039 * does not fail on nonexistent paths.
1042 * path [I] path to parse and convert into an ItemIDList
1045 * the newly created simple ItemIDList
1048 * Simple in the name does not mean a relative ItemIDList but rather a
1049 * fully qualified list, where only the file name is filled in and the
1050 * directory flag for those ItemID elements this is known about, eg.
1051 * it is not the last element in the ItemIDList or the actual directory
1053 * exported by ordinal.
1055 LPITEMIDLIST
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1057 LPITEMIDLIST pidl
= NULL
;
1058 LPWSTR wPath
= NULL
;
1061 TRACE("%s\n", debugstr_a(lpszPath
));
1065 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1066 wPath
= heap_alloc(len
* sizeof(WCHAR
));
1067 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1070 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1073 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1077 LPITEMIDLIST
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1079 LPITEMIDLIST pidl
= NULL
;
1081 TRACE("%s\n", debugstr_w(lpszPath
));
1083 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1084 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1088 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1090 if ( SHELL_OsIsUnicode())
1091 return SHSimpleIDListFromPathW (lpszPath
);
1092 return SHSimpleIDListFromPathA (lpszPath
);
1095 /*************************************************************************
1096 * SHGetDataFromIDListA [SHELL32.247]
1099 * the pidl can be a simple one. since we can't get the path out of the pidl
1100 * we have to take all data from the pidl
1102 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1103 int nFormat
, LPVOID dest
, int len
)
1105 LPSTR filename
, shortname
;
1106 WIN32_FIND_DATAA
* pfd
;
1108 TRACE_(shell
)("%p, %p, %d, %p, %d.\n", psf
, pidl
, nFormat
, dest
, len
);
1112 return E_INVALIDARG
;
1116 case SHGDFIL_FINDDATA
:
1119 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1120 return E_INVALIDARG
;
1122 if (len
< sizeof(WIN32_FIND_DATAA
))
1123 return E_INVALIDARG
;
1125 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1126 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1127 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1128 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1130 filename
= _ILGetTextPointer(pidl
);
1131 shortname
= _ILGetSTextPointer(pidl
);
1134 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1136 pfd
->cFileName
[0] = '\0';
1139 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1141 pfd
->cAlternateFileName
[0] = '\0';
1144 case SHGDFIL_NETRESOURCE
:
1145 case SHGDFIL_DESCRIPTIONID
:
1146 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1150 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1153 return E_INVALIDARG
;
1156 /*************************************************************************
1157 * SHGetDataFromIDListW [SHELL32.248]
1160 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1161 int nFormat
, LPVOID dest
, int len
)
1163 LPSTR filename
, shortname
;
1164 WIN32_FIND_DATAW
* pfd
= dest
;
1166 TRACE_(shell
)("%p, %p, %d, %p, %d.\n", psf
, pidl
, nFormat
, dest
, len
);
1171 return E_INVALIDARG
;
1175 case SHGDFIL_FINDDATA
:
1178 if (_ILIsDrive(pidl
))
1179 return E_INVALIDARG
;
1181 if (len
< sizeof(WIN32_FIND_DATAW
))
1182 return E_INVALIDARG
;
1184 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAW
));
1185 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1186 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1187 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1189 filename
= _ILGetTextPointer(pidl
);
1190 shortname
= _ILGetSTextPointer(pidl
);
1193 pfd
->cFileName
[0] = '\0';
1194 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1195 pfd
->cFileName
[MAX_PATH
-1] = 0;
1198 pfd
->cAlternateFileName
[0] = '\0';
1199 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1200 pfd
->cAlternateFileName
[13] = 0;
1203 case SHGDFIL_NETRESOURCE
:
1204 case SHGDFIL_DESCRIPTIONID
:
1205 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1209 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1212 return E_INVALIDARG
;
1215 /*************************************************************************
1216 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1220 * pszPath [OUT] path
1223 * path from a passed PIDL.
1226 * NULL returns FALSE
1227 * desktop pidl gives path to desktop directory back
1228 * special pidls returning FALSE
1230 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1232 WCHAR wszPath
[MAX_PATH
];
1235 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1236 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1241 /*************************************************************************
1242 * SHGetPathFromIDListW [SHELL32.@]
1244 * See SHGetPathFromIDListA.
1246 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1248 return SHGetPathFromIDListEx(pidl
, pszPath
, MAX_PATH
, 0);
1251 /*************************************************************************
1252 * SHGetPathFromIDListEx [SHELL32.@]
1254 BOOL WINAPI
SHGetPathFromIDListEx(LPCITEMIDLIST pidl
, WCHAR
*path
, DWORD path_size
, GPFIDL_FLAGS flags
)
1257 LPCITEMIDLIST pidlLast
;
1258 LPSHELLFOLDER psfFolder
;
1262 TRACE_(shell
)("(pidl=%p,%p,%u,%x)\n", pidl
, path
, path_size
, flags
);
1265 if (flags
!= GPFIDL_DEFAULT
)
1266 FIXME("Unsupported flags %x\n", flags
);
1272 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1273 if (FAILED(hr
)) return FALSE
;
1275 dwAttributes
= SFGAO_FILESYSTEM
;
1276 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1277 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1278 IShellFolder_Release(psfFolder
);
1282 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1283 IShellFolder_Release(psfFolder
);
1284 if (FAILED(hr
)) return FALSE
;
1286 hr
= StrRetToBufW(&strret
, pidlLast
, path
, path_size
);
1288 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(path
), hr
);
1289 return SUCCEEDED(hr
);
1292 /*************************************************************************
1293 * SHBindToParent [shell version 5.0]
1295 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1297 IShellFolder
* psfDesktop
;
1300 TRACE_(shell
)("pidl=%p\n", pidl
);
1304 return E_INVALIDARG
;
1310 hr
= SHGetDesktopFolder(&psfDesktop
);
1314 if (_ILIsPidlSimple(pidl
))
1316 /* we are on desktop level */
1317 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1321 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1322 ILRemoveLastID(pidlParent
);
1323 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1324 SHFree (pidlParent
);
1327 IShellFolder_Release(psfDesktop
);
1329 if (SUCCEEDED(hr
) && ppidlLast
)
1330 *ppidlLast
= ILFindLastID(pidl
);
1332 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1336 /*************************************************************************
1337 * SHParseDisplayName [SHELL32.@]
1339 HRESULT WINAPI
SHParseDisplayName(LPCWSTR name
, IBindCtx
*bindctx
, LPITEMIDLIST
*pidlist
,
1340 SFGAOF attr_in
, SFGAOF
*attr_out
)
1342 IShellFolder
*desktop
;
1345 TRACE("%s %p %p %d %p\n", debugstr_w(name
), bindctx
, pidlist
, attr_in
, attr_out
);
1349 if (!name
) return E_INVALIDARG
;
1351 hr
= SHGetDesktopFolder(&desktop
);
1352 if (hr
!= S_OK
) return hr
;
1354 hr
= IShellFolder_ParseDisplayName(desktop
, NULL
, bindctx
, (LPWSTR
)name
, NULL
, pidlist
, &attr_in
);
1355 if (attr_out
) *attr_out
= attr_in
;
1357 IShellFolder_Release(desktop
);
1362 /*************************************************************************
1363 * SHGetNameFromIDList [SHELL32.@]
1365 HRESULT WINAPI
SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl
, SIGDN sigdnName
, PWSTR
*ppszName
)
1367 IShellFolder
*psfparent
;
1368 LPCITEMIDLIST child_pidl
;
1372 TRACE("%p 0x%08x %p\n", pidl
, sigdnName
, ppszName
);
1375 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (void**)&psfparent
, &child_pidl
);
1380 /* sigdnName & 0xffff */
1381 case SIGDN_NORMALDISPLAY
: /* SHGDN_NORMAL */
1382 case SIGDN_PARENTRELATIVEPARSING
: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1383 case SIGDN_PARENTRELATIVEEDITING
: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1384 case SIGDN_DESKTOPABSOLUTEPARSING
: /* SHGDN_FORPARSING */
1385 case SIGDN_DESKTOPABSOLUTEEDITING
: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1386 case SIGDN_PARENTRELATIVEFORADDRESSBAR
: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1387 case SIGDN_PARENTRELATIVE
: /* SIGDN_INFOLDER */
1389 disp_name
.uType
= STRRET_WSTR
;
1390 ret
= IShellFolder_GetDisplayNameOf(psfparent
, child_pidl
,
1394 ret
= StrRetToStrW(&disp_name
, pidl
, ppszName
);
1398 case SIGDN_FILESYSPATH
:
1399 *ppszName
= CoTaskMemAlloc(sizeof(WCHAR
)*MAX_PATH
);
1400 if(SHGetPathFromIDListW(pidl
, *ppszName
))
1402 TRACE("Got string %s\n", debugstr_w(*ppszName
));
1407 CoTaskMemFree(*ppszName
);
1414 FIXME("Unsupported SIGDN %x\n", sigdnName
);
1418 IShellFolder_Release(psfparent
);
1423 /*************************************************************************
1424 * SHGetIDListFromObject [SHELL32.@]
1426 HRESULT WINAPI
SHGetIDListFromObject(IUnknown
*punk
, PIDLIST_ABSOLUTE
*ppidl
)
1428 IPersistIDList
*ppersidl
;
1429 IPersistFolder2
*ppf2
;
1435 return E_NOINTERFACE
;
1439 /* Try IPersistIDList */
1440 ret
= IUnknown_QueryInterface(punk
, &IID_IPersistIDList
, (void**)&ppersidl
);
1443 TRACE("IPersistIDList (%p)\n", ppersidl
);
1444 ret
= IPersistIDList_GetIDList(ppersidl
, ppidl
);
1445 IPersistIDList_Release(ppersidl
);
1450 /* Try IPersistFolder2 */
1451 ret
= IUnknown_QueryInterface(punk
, &IID_IPersistFolder2
, (void**)&ppf2
);
1454 TRACE("IPersistFolder2 (%p)\n", ppf2
);
1455 ret
= IPersistFolder2_GetCurFolder(ppf2
, ppidl
);
1456 IPersistFolder2_Release(ppf2
);
1461 /* Try IDataObject */
1462 ret
= IUnknown_QueryInterface(punk
, &IID_IDataObject
, (void**)&pdo
);
1466 TRACE("IDataObject (%p)\n", pdo
);
1467 ret
= SHGetItemFromDataObject(pdo
, DOGIF_ONLY_IF_ONE
,
1468 &IID_IShellItem
, (void**)&psi
);
1471 ret
= SHGetIDListFromObject((IUnknown
*)psi
, ppidl
);
1472 IShellItem_Release(psi
);
1474 IDataObject_Release(pdo
);
1480 /* Try IFolderView */
1481 ret
= IUnknown_QueryInterface(punk
, &IID_IFolderView
, (void**)&pfv
);
1485 TRACE("IFolderView (%p)\n", pfv
);
1486 ret
= IFolderView_GetFolder(pfv
, &IID_IShellFolder
, (void**)&psf
);
1489 /* We might be able to get IPersistFolder2 from a shellfolder. */
1490 ret
= SHGetIDListFromObject((IUnknown
*)psf
, ppidl
);
1491 IShellFolder_Release(psf
);
1493 IFolderView_Release(pfv
);
1500 /**************************************************************************
1502 * internal functions
1504 * ### 1. section creating pidls ###
1506 *************************************************************************
1509 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1510 * - two bytes are SHITEMID.cb
1511 * - one byte is PIDLDATA.type
1512 * - two bytes are the NULL PIDL terminator
1513 * Sets type of the returned PIDL to type.
1515 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1517 LPITEMIDLIST pidlOut
= NULL
;
1519 pidlOut
= SHAlloc(size
+ 5);
1523 LPITEMIDLIST pidlNext
;
1525 ZeroMemory(pidlOut
, size
+ 5);
1526 pidlOut
->mkid
.cb
= size
+ 3;
1528 pData
= _ILGetDataPointer(pidlOut
);
1532 pidlNext
= ILGetNext(pidlOut
);
1534 pidlNext
->mkid
.cb
= 0x00;
1535 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1541 LPITEMIDLIST
_ILCreateDesktop(void)
1552 LPITEMIDLIST
_ILCreateMyComputer(void)
1555 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1558 LPITEMIDLIST
_ILCreateMyDocuments(void)
1561 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1564 LPITEMIDLIST
_ILCreateIExplore(void)
1567 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1570 LPITEMIDLIST
_ILCreateControlPanel(void)
1572 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1577 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1581 ret
= ILCombine(parent
, cpl
);
1589 LPITEMIDLIST
_ILCreatePrinters(void)
1591 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1596 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1600 ret
= ILCombine(parent
, printers
);
1608 LPITEMIDLIST
_ILCreateNetwork(void)
1611 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1614 LPITEMIDLIST
_ILCreateBitBucket(void)
1617 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1620 LPITEMIDLIST
_ILCreateNetHood(void)
1623 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1626 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1628 LPITEMIDLIST pidlOut
;
1630 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1632 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1635 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1637 pData
->u
.guid
.guid
= *guid
;
1638 TRACE("-- create GUID-pidl %s\n",
1639 debugstr_guid(&(pData
->u
.guid
.guid
)));
1644 WARN("%d: invalid type for GUID\n", type
);
1650 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1654 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1656 ERR("%s is not a GUID\n", szGUID
);
1659 return _ILCreateGuid(PT_GUID
, &iid
);
1662 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1666 if (FAILED(SHCLSIDFromStringW(szGUID
, &iid
)))
1668 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1671 return _ILCreateGuid(PT_GUID
, &iid
);
1674 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1676 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1677 DWORD len
, len1
, wlen
, alen
;
1684 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1686 /* prepare buffer with both names */
1687 len
= WideCharToMultiByte(CP_ACP
,0,wfd
->cFileName
,-1,buff
,MAX_PATH
,NULL
,NULL
);
1688 len1
= WideCharToMultiByte(CP_ACP
,0,wfd
->cAlternateFileName
,-1, buff
+len
, sizeof(buff
)-len
, NULL
, NULL
);
1691 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1693 wlen
= lstrlenW(wfd
->cFileName
) + 1;
1694 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1695 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1698 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1699 FileStruct
*fs
= &pData
->u
.file
;
1703 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1704 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1705 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1706 memcpy(fs
->szNames
, buff
, alen
);
1708 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1709 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1710 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1711 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1712 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1714 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1715 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1716 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1722 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1725 WIN32_FIND_DATAW stffile
;
1728 return E_INVALIDARG
;
1730 hFile
= FindFirstFileW(szPath
, &stffile
);
1731 if (hFile
== INVALID_HANDLE_VALUE
)
1732 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1736 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1738 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1741 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1743 LPITEMIDLIST pidlOut
;
1745 TRACE("(%s)\n",debugstr_w(lpszNew
));
1747 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1752 pszDest
= _ILGetTextPointer(pidlOut
);
1755 strcpy(pszDest
, "x:\\");
1756 pszDest
[0]=toupperW(lpszNew
[0]);
1757 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1763 LPITEMIDLIST
_ILCreateEntireNetwork(void)
1765 LPITEMIDLIST pidlOut
;
1769 pidlOut
= _ILAlloc(PT_NETWORK
, FIELD_OFFSET(PIDLDATA
, u
.network
.szNames
[sizeof("Entire Network")]));
1772 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1774 pData
->u
.network
.dummy
= 0;
1775 strcpy(pData
->u
.network
.szNames
, "Entire Network");
1780 /**************************************************************************
1783 * Gets the text for the drive eg. 'c:\'
1788 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1790 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1792 if(_ILIsMyComputer(pidl
))
1793 pidl
= ILGetNext(pidl
);
1795 if (pidl
&& _ILIsDrive(pidl
))
1796 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1801 /**************************************************************************
1803 * ### 2. section testing pidls ###
1805 **************************************************************************
1809 * _ILIsSpecialFolder()
1815 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1817 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1819 TRACE("(%p)\n",pidl
);
1821 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1824 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1826 TRACE("(%p)\n",pidl
);
1828 return !pidl
|| !pidl
->mkid
.cb
;
1831 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1833 REFIID iid
= _ILGetGUIDPointer(pidl
);
1835 TRACE("(%p)\n",pidl
);
1838 return IsEqualIID(iid
, &CLSID_MyComputer
);
1842 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1844 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1846 TRACE("(%p)\n",pidl
);
1848 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1849 (pidl
&& pidl
->mkid
.cb
== 0x00)
1853 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1855 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1857 TRACE("(%p)\n",pidl
);
1859 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1860 PT_DRIVE1
== lpPData
->type
||
1861 PT_DRIVE2
== lpPData
->type
||
1862 PT_DRIVE3
== lpPData
->type
));
1865 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1867 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1869 TRACE("(%p)\n",pidl
);
1871 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1874 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1876 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1878 TRACE("(%p)\n",pidl
);
1880 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1883 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1885 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1887 TRACE("(%p)\n",pidl
);
1889 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1892 /**************************************************************************
1895 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1899 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1901 WORD len
= pidl
->mkid
.cb
;
1902 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1904 if (pidlnext
->mkid
.cb
)
1908 TRACE("%s\n", ret
? "Yes" : "No");
1912 /**************************************************************************
1914 * ### 3. section getting values from pidls ###
1917 /**************************************************************************
1920 * gets the text for the first item in the pidl (eg. simple pidl)
1922 * returns the length of the string
1924 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1930 char szTemp
[MAX_PATH
];
1932 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1940 if (_ILIsDesktop(pidl
))
1943 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1946 lstrcpynA(szOut
, szTemp
, uOutSize
);
1948 dwReturn
= strlen (szTemp
);
1951 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1955 lstrcpynA(szOut
, szSrc
, uOutSize
);
1957 dwReturn
= strlen(szSrc
);
1959 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1961 /* unicode filesystem */
1962 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1965 lstrcpynA(szOut
, szTemp
, uOutSize
);
1967 dwReturn
= strlen (szTemp
);
1969 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1971 /* special folder */
1972 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1975 lstrcpynA(szOut
, szTemp
, uOutSize
);
1977 dwReturn
= strlen (szTemp
);
1982 ERR("-- no text\n");
1985 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1989 /**************************************************************************
1992 * gets the text for the first item in the pidl (eg. simple pidl)
1994 * returns the length of the string
1996 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1999 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
2001 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
2004 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
2005 dwReturn
= lstrlenW(pFileStructW
->wszName
);
2008 WCHAR szTemp
[MAX_PATH
];
2019 if (_ILIsDesktop(pidl
))
2022 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
2025 lstrcpynW(szOut
, szTemp
, uOutSize
);
2027 dwReturn
= lstrlenW (szTemp
);
2030 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
2032 /* unicode filesystem */
2034 lstrcpynW(szOut
, szSrcW
, uOutSize
);
2036 dwReturn
= lstrlenW(szSrcW
);
2038 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
2041 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
2044 lstrcpynW(szOut
, szTemp
, uOutSize
);
2046 dwReturn
= lstrlenW (szTemp
);
2048 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
2050 /* special folder */
2051 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
2054 lstrcpynW(szOut
, szTemp
, uOutSize
);
2056 dwReturn
= lstrlenW (szTemp
);
2061 ERR("-- no text\n");
2065 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
2069 /**************************************************************************
2071 * ### 4. getting pointers to parts of pidls ###
2073 **************************************************************************
2074 * _ILGetDataPointer()
2076 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
2078 if(!_ILIsEmpty(pidl
))
2079 return (LPPIDLDATA
)pidl
->mkid
.abID
;
2083 /**************************************************************************
2084 * _ILGetTextPointerW()
2085 * gets a pointer to the unicode long filename string stored in the pidl
2087 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
2089 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2091 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2096 switch (pdata
->type
)
2107 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2115 /*return (LPSTR)&(pdata->u.file.szNames);*/
2121 case PT_NETPROVIDER
:
2123 /*return (LPSTR)&(pdata->u.network.szNames);*/
2127 return (LPWSTR
)pdata
->u
.file
.szNames
;
2133 /**************************************************************************
2134 * _ILGetTextPointer()
2135 * gets a pointer to the long filename string stored in the pidl
2137 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
2139 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2141 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2146 switch (pdata
->type
)
2157 return pdata
->u
.drive
.szDriveName
;
2164 return pdata
->u
.file
.szNames
;
2169 case PT_NETPROVIDER
:
2171 return pdata
->u
.network
.szNames
;
2176 /**************************************************************************
2177 * _ILGetSTextPointer()
2178 * gets a pointer to the short filename string stored in the pidl
2180 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2182 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2184 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2189 switch (pdata
->type
)
2195 return pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1;
2198 return pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1;
2203 /**************************************************************************
2204 * _ILGetGUIDPointer()
2206 * returns reference to guid stored in some pidls
2208 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2210 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2212 TRACE("%p\n", pidl
);
2217 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2218 switch (pdata
->type
)
2223 return &(pdata
->u
.guid
.guid
);
2226 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2232 /******************************************************************************
2233 * _ILGetFileStructW [Internal]
2235 * Get pointer the a SHITEMID's FileStructW field if present
2238 * pidl [I] The SHITEMID
2241 * Success: Pointer to pidl's FileStructW field.
2244 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2245 FileStructW
*pFileStructW
;
2248 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2251 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2252 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2254 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2255 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2256 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2257 if ((cbOffset
& 0x1) || /* FileStructW member is word aligned in the pidl */
2258 /* FileStructW is positioned after FileStruct */
2259 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2260 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2261 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2262 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2264 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2268 return pFileStructW
;
2271 /*************************************************************************
2272 * _ILGetFileDateTime
2274 * Given the ItemIdList, get the FileTime
2277 * pidl [I] The ItemIDList
2278 * pFt [I] the resulted FILETIME of the file
2281 * True if Successful
2286 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2288 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2293 switch (pdata
->type
)
2297 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2305 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2311 if (_ILGetFileDateTime( pidl
, &ft
))
2313 FileTimeToLocalFileTime(&ft
, &lft
);
2314 FileTimeToSystemTime (&lft
, &time
);
2316 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2319 /* Append space + time without seconds */
2321 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2332 /*************************************************************************
2335 * Given the ItemIdList, get the FileSize
2338 * pidl [I] The ItemIDList
2339 * pOut [I] The buffer to save the result
2340 * uOutsize [I] The size of the buffer
2346 * pOut can be null when no string is needed
2349 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2351 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2357 switch (pdata
->type
)
2360 dwSize
= pdata
->u
.file
.dwFileSize
;
2362 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2370 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2372 char szTemp
[MAX_PATH
];
2373 const char * pPoint
;
2374 LPCITEMIDLIST pidlTemp
=pidl
;
2376 TRACE("pidl=%p\n",pidl
);
2381 pidlTemp
= ILFindLastID(pidl
);
2383 if (!_ILIsValue(pidlTemp
))
2385 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2388 pPoint
= PathFindExtensionA(szTemp
);
2394 lstrcpynA(pOut
, pPoint
, uOutSize
);
2400 /*************************************************************************
2403 * Given the ItemIdList, get the file type description
2406 * pidl [I] The ItemIDList (simple)
2407 * pOut [I] The buffer to save the result
2408 * uOutsize [I] The size of the buffer
2414 * This function copies as much as possible into the buffer.
2416 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2418 if(_ILIsValue(pidl
))
2422 /* "name" or "name." or any unhandled => "File" */
2423 lstrcpynA (pOut
, "File", uOutSize
);
2425 /* If there's space for more, try to get a better description. */
2426 if (uOutSize
> 6 && _ILGetExtension (pidl
, sTemp
, 64))
2428 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2429 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2432 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2433 strcat (pOut
, " file");
2438 lstrcpynA(pOut
, "Folder", uOutSize
);
2441 /*************************************************************************
2442 * _ILGetFileAttributes
2444 * Given the ItemIdList, get the Attrib string format
2447 * pidl [I] The ItemIDList
2448 * pOut [I] The buffer to save the result
2449 * uOutsize [I] The size of the Buffer
2455 * return value 0 in case of error is a valid return value
2458 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2460 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2471 wAttrib
= pData
->u
.file
.uFileAttribs
;
2478 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2480 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2482 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2484 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2486 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2493 /*************************************************************************
2496 * frees an aPidl struct
2498 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2504 for (i
= 0; i
< cidl
; i
++)
2510 /*************************************************************************
2513 * copies an aPidl struct
2515 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2518 LPITEMIDLIST
*apidldest
;
2523 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2525 for (i
= 0; i
< cidl
; i
++)
2526 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2531 /*************************************************************************
2532 * _ILCopyCidaToaPidl
2534 * creates aPidl from CIDA
2536 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2541 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2546 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2548 for (i
= 0; i
< cida
->cidl
; i
++)
2549 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));