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
35 #define NONAMELESSSTRUCT
44 #include "undocshell.h"
45 #include "shell32_main.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
52 WINE_DECLARE_DEBUG_CHANNEL(shell
);
54 /* from comctl32.dll */
55 extern LPVOID WINAPI
Alloc(INT
);
56 extern BOOL WINAPI
Free(LPVOID
);
58 /*************************************************************************
59 * ILGetDisplayNameEx [SHELL32.186]
61 * Retrieves the display name of an ItemIDList
64 * psf [I] Shell Folder to start with, if NULL the desktop is used
65 * pidl [I] ItemIDList relativ to the psf to get the display name for
66 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
67 * type [I] Type of display name to retrieve
68 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
69 * 1 = SHGDN_NORMAL relative to the root folder
70 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
73 * True if the display name could be retrieved successfully, False otherwise
75 BOOL WINAPI
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
78 WCHAR wPath
[MAX_PATH
];
80 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
85 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
86 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
87 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
92 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
94 LPSHELLFOLDER psfParent
, lsf
= psf
;
95 HRESULT ret
= NO_ERROR
;
96 LPCITEMIDLIST pidllast
;
100 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
107 ret
= SHGetDesktopFolder(&lsf
);
112 if (type
>= 0 && type
<= 2)
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
;
130 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
132 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
135 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
141 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
144 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
147 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
150 IShellFolder_Release(psfParent
);
155 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
158 IShellFolder_Release(lsf
);
159 return SUCCEEDED(ret
);
162 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
164 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
166 if (SHELL_OsIsUnicode())
167 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
168 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
171 /*************************************************************************
172 * ILGetDisplayName [SHELL32.15]
174 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
176 TRACE_(shell
)("%p %p\n", pidl
, path
);
178 if (SHELL_OsIsUnicode())
179 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
180 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
183 /*************************************************************************
184 * ILFindLastID [SHELL32.16]
187 * observed: pidl=Desktop return=pidl
189 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
191 LPCITEMIDLIST pidlLast
= pidl
;
193 TRACE("(pidl=%p)\n",pidl
);
198 while (pidl
->mkid
.cb
)
201 pidl
= ILGetNext(pidl
);
203 return (LPITEMIDLIST
)pidlLast
;
206 /*************************************************************************
207 * ILRemoveLastID [SHELL32.17]
210 * when pidl=Desktop return=FALSE
212 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
214 TRACE_(shell
)("pidl=%p\n",pidl
);
216 if (!pidl
|| !pidl
->mkid
.cb
)
218 ILFindLastID(pidl
)->mkid
.cb
= 0;
222 /*************************************************************************
223 * ILClone [SHELL32.18]
226 * duplicate an idlist
228 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
231 LPITEMIDLIST newpidl
;
236 len
= ILGetSize(pidl
);
237 newpidl
= (LPITEMIDLIST
)SHAlloc(len
);
239 memcpy(newpidl
,pidl
,len
);
241 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
247 /*************************************************************************
248 * ILCloneFirst [SHELL32.19]
251 * duplicates the first idlist of a complex pidl
253 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
256 LPITEMIDLIST pidlNew
= NULL
;
258 TRACE("pidl=%p\n", pidl
);
264 pidlNew
= (LPITEMIDLIST
) SHAlloc (len
+2);
267 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
270 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
273 TRACE("-- newpidl=%p\n",pidlNew
);
278 /*************************************************************************
279 * ILLoadFromStream (SHELL32.26)
282 * the first two bytes are the len, the pidl is following then
284 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
288 HRESULT ret
= E_FAIL
;
291 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
296 IStream_AddRef (pStream
);
298 if (SUCCEEDED(IStream_Read(pStream
, (LPVOID
)&wLen
, 2, &dwBytesRead
)))
300 TRACE("PIDL length is %d\n", wLen
);
303 *ppPidl
= SHAlloc (wLen
);
304 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
306 TRACE("Stream read OK\n");
311 WARN("reading pidl failed\n");
323 /* we are not yet fully compatible */
324 if (*ppPidl
&& !pcheck(*ppPidl
))
326 WARN("Check failed\n");
331 IStream_Release (pStream
);
336 /*************************************************************************
337 * ILSaveToStream (SHELL32.27)
340 * the first two bytes are the len, the pidl is following then
342 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
346 HRESULT ret
= E_FAIL
;
348 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
350 IStream_AddRef (pStream
);
353 while (pidl
->mkid
.cb
)
355 wLen
+= sizeof(WORD
) + pidl
->mkid
.cb
;
356 pidl
= ILGetNext(pidl
);
359 if (SUCCEEDED(IStream_Write(pStream
, (LPVOID
)&wLen
, 2, NULL
)))
361 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
364 IStream_Release (pStream
);
369 /*************************************************************************
370 * SHILCreateFromPath [SHELL32.28]
372 * Create an ItemIDList from a path
377 * attributes [I/O] requested attributes on call and actual attributes when
378 * the function returns
381 * NO_ERROR if successful, or an OLE errer code otherwise
384 * Wrapper for IShellFolder_ParseDisplayName().
386 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
388 WCHAR lpszDisplayName
[MAX_PATH
];
390 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
392 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
393 lpszDisplayName
[MAX_PATH
-1] = 0;
395 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
398 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
402 HRESULT ret
= E_FAIL
;
404 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
406 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
408 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
409 IShellFolder_Release(sf
);
414 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
416 if ( SHELL_OsIsUnicode())
417 return SHILCreateFromPathW (path
, ppidl
, attributes
);
418 return SHILCreateFromPathA (path
, ppidl
, attributes
);
421 /*************************************************************************
422 * SHCloneSpecialIDList [SHELL32.89]
424 * Create an ItemIDList to one of the special folders.
428 * nFolder [in] CSIDL_xxxxx
429 * fCreate [in] Create folder if it does not exist
432 * Success: The newly created pidl
433 * Failure: NULL, if inputs are invalid.
436 * exported by ordinal.
437 * Caller is responsible for deallocating the returned ItemIDList with the
438 * shells IMalloc interface, aka ILFree.
440 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
443 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
446 nFolder
|= CSIDL_FLAG_CREATE
;
448 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
452 /*************************************************************************
453 * ILGlobalClone [SHELL32.20]
455 * Clones an ItemIDList using Alloc.
458 * pidl [I] ItemIDList to clone
461 * Newly allocated ItemIDList.
464 * exported by ordinal.
466 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
469 LPITEMIDLIST newpidl
;
474 len
= ILGetSize(pidl
);
475 newpidl
= (LPITEMIDLIST
)Alloc(len
);
477 memcpy(newpidl
,pidl
,len
);
479 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
485 /*************************************************************************
486 * ILIsEqual [SHELL32.21]
489 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
491 char szData1
[MAX_PATH
];
492 char szData2
[MAX_PATH
];
494 LPCITEMIDLIST pidltemp1
= pidl1
;
495 LPCITEMIDLIST pidltemp2
= pidl2
;
497 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
500 * Explorer reads from registry directly (StreamMRU),
501 * so we can only check here
503 if (!pcheck(pidl1
) || !pcheck (pidl2
))
509 if (!pidl1
|| !pidl2
)
512 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
514 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
515 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
517 if (strcasecmp( szData1
, szData2
))
520 pidltemp1
= ILGetNext(pidltemp1
);
521 pidltemp2
= ILGetNext(pidltemp2
);
524 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
530 /*************************************************************************
531 * ILIsParent [SHELL32.23]
533 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
538 * bImmediate [I] only return true if the parent is the direct parent
542 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
546 * parent = a/b, child = a/b/c -> true, c is in folder a/b
547 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
548 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
550 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
552 char szData1
[MAX_PATH
];
553 char szData2
[MAX_PATH
];
554 LPCITEMIDLIST pParent
= pidlParent
;
555 LPCITEMIDLIST pChild
= pidlChild
;
557 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
559 if (!pParent
|| !pChild
)
562 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
564 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
565 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
567 if (strcasecmp( szData1
, szData2
))
570 pParent
= ILGetNext(pParent
);
571 pChild
= ILGetNext(pChild
);
574 /* child shorter or has equal length to parent */
575 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
578 /* not immediate descent */
579 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
585 /*************************************************************************
586 * ILFindChild [SHELL32.24]
588 * Compares elements from pidl1 and pidl2.
595 * pidl1 is desktop pidl2
596 * pidl1 shorter pidl2 pointer to first different element of pidl2
597 * if there was at least one equal element
598 * pidl2 shorter pidl1 0
599 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
602 * exported by ordinal.
604 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
606 char szData1
[MAX_PATH
];
607 char szData2
[MAX_PATH
];
609 LPCITEMIDLIST pidltemp1
= pidl1
;
610 LPCITEMIDLIST pidltemp2
= pidl2
;
611 LPCITEMIDLIST ret
=NULL
;
613 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
615 /* explorer reads from registry directly (StreamMRU),
616 so we can only check here */
617 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
623 if (_ILIsDesktop(pidl1
))
629 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
631 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
632 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
634 if (strcasecmp(szData1
,szData2
))
637 pidltemp1
= ILGetNext(pidltemp1
);
638 pidltemp2
= ILGetNext(pidltemp2
);
642 if (pidltemp1
->mkid
.cb
)
643 ret
= NULL
; /* elements of pidl1 left*/
645 TRACE_(shell
)("--- %p\n", ret
);
646 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
649 /*************************************************************************
650 * ILCombine [SHELL32.25]
652 * Concatenates two complex ItemIDLists.
655 * pidl1 [I] first complex ItemIDLists
656 * pidl2 [I] complex ItemIDLists to append
659 * if both pidl's == NULL NULL
660 * if pidl1 == NULL cloned pidl2
661 * if pidl2 == NULL cloned pidl1
662 * otherwise new pidl with pidl2 appended to pidl1
665 * exported by ordinal.
666 * Does not destroy the passed in ItemIDLists!
668 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
671 LPITEMIDLIST pidlNew
;
673 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
675 if (!pidl1
&& !pidl2
) return NULL
;
682 pidlNew
= ILClone(pidl2
);
688 pidlNew
= ILClone(pidl1
);
692 len1
= ILGetSize(pidl1
)-2;
693 len2
= ILGetSize(pidl2
);
694 pidlNew
= SHAlloc(len1
+len2
);
698 memcpy(pidlNew
,pidl1
,len1
);
699 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
702 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
706 /*************************************************************************
707 * SHGetRealIDL [SHELL32.98]
711 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
713 IDataObject
* pDataObj
;
716 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
717 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
723 fmt
.cfFormat
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
725 fmt
.dwAspect
= DVASPECT_CONTENT
;
727 fmt
.tymed
= TYMED_HGLOBAL
;
729 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
731 IDataObject_Release(pDataObj
);
735 /*assert(pida->cidl==1);*/
736 LPIDA pida
= (LPIDA
)GlobalLock(medium
.u
.hGlobal
);
738 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
739 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
741 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
746 GlobalUnlock(medium
.u
.hGlobal
);
747 GlobalFree(medium
.u
.hGlobal
);
754 /*************************************************************************
755 * SHLogILFromFSIL [SHELL32.95]
758 * pild = CSIDL_DESKTOP ret = 0
759 * pild = CSIDL_DRIVES ret = 0
761 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
763 FIXME("(pidl=%p)\n",pidl
);
770 /*************************************************************************
771 * ILGetSize [SHELL32.152]
773 * Gets the byte size of an ItemIDList including zero terminator
776 * pidl [I] ItemIDList
779 * size of pidl in bytes
782 * exported by ordinal
784 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
786 LPCSHITEMID si
= &(pidl
->mkid
);
794 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
798 TRACE("pidl=%p size=%u\n",pidl
, len
);
802 /*************************************************************************
803 * ILGetNext [SHELL32.153]
805 * Gets the next ItemID of an ItemIDList
808 * pidl [I] ItemIDList
813 * simple pidl -> pointer to 0x0000 element
816 * exported by ordinal.
818 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
829 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
830 TRACE("-- %p\n", pidl
);
831 return (LPITEMIDLIST
)pidl
;
837 /*************************************************************************
838 * ILAppend [SHELL32.154]
840 * Adds the single ItemID item to the ItemIDList indicated by pidl.
841 * If bEnd is FALSE, inserts the item in the front of the list,
842 * otherwise it adds the item to the end. (???)
845 * pidl [I] ItemIDList to extend
846 * item [I] ItemID to prepend/append
847 * bEnd [I] Indicates if the item should be appended
850 * Destroys the passed in idlist! (???)
852 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
856 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
861 if (_ILIsDesktop(pidl
))
863 idlRet
= ILClone(item
);
869 idlRet
= ILCombine(pidl
, item
);
871 idlRet
= ILCombine(item
, 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 WINAPI
_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 (!SUCCEEDED(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 WINAPI
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
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1067 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1070 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1072 HeapFree(GetProcessHeap(), 0, wPath
);
1073 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1077 LPITEMIDLIST WINAPI
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
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\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
, MAX_PATH
);
1136 pfd
->cFileName
[0] = '\0';
1139 lstrcpynA(pfd
->cAlternateFileName
, shortname
, MAX_PATH
);
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
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\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_DATAA
));
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
)
1249 LPCITEMIDLIST pidlLast
;
1250 LPSHELLFOLDER psfFolder
;
1254 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, pszPath
);
1261 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1262 if (FAILED(hr
)) return FALSE
;
1264 dwAttributes
= SFGAO_FILESYSTEM
;
1265 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1266 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1267 IShellFolder_Release(psfFolder
);
1271 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1272 IShellFolder_Release(psfFolder
);
1273 if (FAILED(hr
)) return FALSE
;
1275 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1277 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(pszPath
), hr
);
1278 return SUCCEEDED(hr
);
1281 /*************************************************************************
1282 * SHBindToParent [shell version 5.0]
1284 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1286 IShellFolder
* psfDesktop
;
1289 TRACE_(shell
)("pidl=%p\n", pidl
);
1293 return E_INVALIDARG
;
1299 hr
= SHGetDesktopFolder(&psfDesktop
);
1303 if (_ILIsPidlSimple(pidl
))
1305 /* we are on desktop level */
1306 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1310 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1311 ILRemoveLastID(pidlParent
);
1312 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1313 SHFree (pidlParent
);
1316 IShellFolder_Release(psfDesktop
);
1318 if (SUCCEEDED(hr
) && ppidlLast
)
1319 *ppidlLast
= ILFindLastID(pidl
);
1321 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1325 /**************************************************************************
1327 * internal functions
1329 * ### 1. section creating pidls ###
1331 *************************************************************************
1333 LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1335 LPITEMIDLIST pidlOut
= NULL
;
1337 pidlOut
= SHAlloc(size
+ 5);
1341 LPITEMIDLIST pidlNext
;
1343 ZeroMemory(pidlOut
, size
+ 5);
1344 pidlOut
->mkid
.cb
= size
+ 3;
1346 pData
= _ILGetDataPointer(pidlOut
);
1350 pidlNext
= ILGetNext(pidlOut
);
1352 pidlNext
->mkid
.cb
= 0x00;
1353 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1359 LPITEMIDLIST
_ILCreateDesktop(void)
1370 LPITEMIDLIST
_ILCreateMyComputer(void)
1373 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1376 LPITEMIDLIST
_ILCreateMyDocuments(void)
1379 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1382 LPITEMIDLIST
_ILCreateIExplore(void)
1385 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1388 LPITEMIDLIST
_ILCreateControlPanel(void)
1390 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1395 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1399 ret
= ILCombine(parent
, cpl
);
1407 LPITEMIDLIST
_ILCreatePrinters(void)
1409 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1414 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1418 ret
= ILCombine(parent
, printers
);
1426 LPITEMIDLIST
_ILCreateNetwork(void)
1429 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1432 LPITEMIDLIST
_ILCreateBitBucket(void)
1435 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1438 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1440 LPITEMIDLIST pidlOut
;
1442 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1444 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1447 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1449 memcpy(&(pData
->u
.guid
.guid
), guid
, sizeof(GUID
));
1450 TRACE("-- create GUID-pidl %s\n",
1451 debugstr_guid(&(pData
->u
.guid
.guid
)));
1456 WARN("%d: invalid type for GUID\n", type
);
1462 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1466 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID
, &iid
)))
1468 ERR("%s is not a GUID\n", szGUID
);
1471 return _ILCreateGuid(PT_GUID
, &iid
);
1474 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1478 if (!SUCCEEDED(SHCLSIDFromStringW(szGUID
, &iid
)))
1480 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1483 return _ILCreateGuid(PT_GUID
, &iid
);
1486 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1488 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1489 DWORD len
, len1
, wlen
, alen
;
1496 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1498 /* prepare buffer with both names */
1499 len
= WideCharToMultiByte(CP_ACP
,0,wfd
->cFileName
,-1,buff
,MAX_PATH
,NULL
,NULL
);
1500 len1
= WideCharToMultiByte(CP_ACP
,0,wfd
->cAlternateFileName
,-1, buff
+len
, sizeof(buff
)-len
, NULL
, NULL
);
1503 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1505 wlen
= lstrlenW(wfd
->cFileName
) + 1;
1506 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1507 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1510 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1511 FileStruct
*fs
= &pData
->u
.file
;
1515 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1516 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1517 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1518 memcpy(fs
->szNames
, buff
, alen
);
1520 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1521 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1522 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1523 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1524 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1526 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1527 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1528 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1534 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1537 WIN32_FIND_DATAW stffile
;
1540 return E_INVALIDARG
;
1542 hFile
= FindFirstFileW(szPath
, &stffile
);
1543 if (hFile
== INVALID_HANDLE_VALUE
)
1544 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1548 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1550 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1553 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1555 LPITEMIDLIST pidlOut
;
1557 TRACE("(%s)\n",debugstr_w(lpszNew
));
1559 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1564 pszDest
= _ILGetTextPointer(pidlOut
);
1567 strcpy(pszDest
, "x:\\");
1568 pszDest
[0]=toupperW(lpszNew
[0]);
1569 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1575 /**************************************************************************
1578 * Gets the text for the drive eg. 'c:\'
1583 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1585 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1587 if(_ILIsMyComputer(pidl
))
1588 pidl
= ILGetNext(pidl
);
1590 if (pidl
&& _ILIsDrive(pidl
))
1591 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1596 /**************************************************************************
1598 * ### 2. section testing pidls ###
1600 **************************************************************************
1604 * _ILIsSpecialFolder()
1610 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1612 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1614 TRACE("(%p)\n",pidl
);
1616 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1619 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1621 TRACE("(%p)\n",pidl
);
1623 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1626 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1628 REFIID iid
= _ILGetGUIDPointer(pidl
);
1630 TRACE("(%p)\n",pidl
);
1633 return IsEqualIID(iid
, &CLSID_MyComputer
);
1637 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1639 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1641 TRACE("(%p)\n",pidl
);
1643 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1644 (pidl
&& pidl
->mkid
.cb
== 0x00)
1648 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1650 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1652 TRACE("(%p)\n",pidl
);
1654 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1655 PT_DRIVE1
== lpPData
->type
||
1656 PT_DRIVE2
== lpPData
->type
||
1657 PT_DRIVE3
== lpPData
->type
));
1660 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1662 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1664 TRACE("(%p)\n",pidl
);
1666 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1669 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1671 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1673 TRACE("(%p)\n",pidl
);
1675 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1678 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1680 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1682 TRACE("(%p)\n",pidl
);
1684 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1687 /**************************************************************************
1690 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1694 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1696 WORD len
= pidl
->mkid
.cb
;
1697 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1699 if (pidlnext
->mkid
.cb
)
1703 TRACE("%s\n", ret
? "Yes" : "No");
1707 /**************************************************************************
1709 * ### 3. section getting values from pidls ###
1712 /**************************************************************************
1715 * gets the text for the first item in the pidl (eg. simple pidl)
1717 * returns the length of the string
1719 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1725 char szTemp
[MAX_PATH
];
1727 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1735 if (_ILIsDesktop(pidl
))
1738 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1741 lstrcpynA(szOut
, szTemp
, uOutSize
);
1743 dwReturn
= strlen (szTemp
);
1746 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1750 lstrcpynA(szOut
, szSrc
, uOutSize
);
1752 dwReturn
= strlen(szSrc
);
1754 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1756 /* unicode filesystem */
1757 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1760 lstrcpynA(szOut
, szTemp
, uOutSize
);
1762 dwReturn
= strlen (szTemp
);
1764 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1766 /* special folder */
1767 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1770 lstrcpynA(szOut
, szTemp
, uOutSize
);
1772 dwReturn
= strlen (szTemp
);
1777 ERR("-- no text\n");
1780 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1784 /**************************************************************************
1787 * gets the text for the first item in the pidl (eg. simple pidl)
1789 * returns the length of the string
1791 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1794 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
1796 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1799 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
1800 dwReturn
= lstrlenW(pFileStructW
->wszName
);
1803 WCHAR szTemp
[MAX_PATH
];
1814 if (_ILIsDesktop(pidl
))
1817 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1820 lstrcpynW(szOut
, szTemp
, uOutSize
);
1822 dwReturn
= lstrlenW (szTemp
);
1825 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1827 /* unicode filesystem */
1829 lstrcpynW(szOut
, szSrcW
, uOutSize
);
1831 dwReturn
= lstrlenW(szSrcW
);
1833 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1836 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
1839 lstrcpynW(szOut
, szTemp
, uOutSize
);
1841 dwReturn
= lstrlenW (szTemp
);
1843 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1845 /* special folder */
1846 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
1849 lstrcpynW(szOut
, szTemp
, uOutSize
);
1851 dwReturn
= lstrlenW (szTemp
);
1856 ERR("-- no text\n");
1860 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1864 /**************************************************************************
1866 * ### 4. getting pointers to parts of pidls ###
1868 **************************************************************************
1869 * _ILGetDataPointer()
1871 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1873 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1874 return (LPPIDLDATA
) &(pidl
->mkid
.abID
);
1878 /**************************************************************************
1879 * _ILGetTextPointerW()
1880 * gets a pointer to the unicode long filename string stored in the pidl
1882 LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
1884 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1886 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1891 switch (pdata
->type
)
1902 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1910 /*return (LPSTR)&(pdata->u.file.szNames);*/
1916 case PT_NETPROVIDER
:
1918 /*return (LPSTR)&(pdata->u.network.szNames);*/
1922 return (LPWSTR
)&(pdata
->u
.file
.szNames
);
1928 /**************************************************************************
1929 * _ILGetTextPointer()
1930 * gets a pointer to the long filename string stored in the pidl
1932 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1934 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1936 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1941 switch (pdata
->type
)
1952 return (LPSTR
)&(pdata
->u
.drive
.szDriveName
);
1959 return (LPSTR
)&(pdata
->u
.file
.szNames
);
1964 case PT_NETPROVIDER
:
1966 return (LPSTR
)&(pdata
->u
.network
.szNames
);
1971 /**************************************************************************
1972 * _ILGetSTextPointer()
1973 * gets a pointer to the short filename string stored in the pidl
1975 LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
1977 /* TRACE(pidl,"(pidl%p)\n", pidl); */
1979 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1984 switch (pdata
->type
)
1990 return (LPSTR
)(pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1);
1993 return (LPSTR
)(pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1);
1998 /**************************************************************************
1999 * _ILGetGUIDPointer()
2001 * returns reference to guid stored in some pidls
2003 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2005 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2007 TRACE("%p\n", pidl
);
2012 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2013 switch (pdata
->type
)
2018 return &(pdata
->u
.guid
.guid
);
2021 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2027 /******************************************************************************
2028 * _ILGetFileStructW [Internal]
2030 * Get pointer the a SHITEMID's FileStructW field if present
2033 * pidl [I] The SHITEMID
2036 * Success: Pointer to pidl's FileStructW field.
2039 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2040 FileStructW
*pFileStructW
;
2043 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2046 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2047 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2049 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2050 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2051 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2052 if (cbOffset
& 0x1 || /* FileStructW member is word aligned in the pidl */
2053 /* FileStructW is positioned after FileStruct */
2054 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2055 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2056 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2057 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2059 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2063 return pFileStructW
;
2066 /*************************************************************************
2067 * _ILGetFileDateTime
2069 * Given the ItemIdList, get the FileTime
2072 * pidl [I] The ItemIDList
2073 * pFt [I] the resulted FILETIME of the file
2076 * True if Successful
2081 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2083 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2088 switch (pdata
->type
)
2092 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2100 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2106 if (_ILGetFileDateTime( pidl
, &ft
))
2108 FileTimeToLocalFileTime(&ft
, &lft
);
2109 FileTimeToSystemTime (&lft
, &time
);
2111 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2114 /* Append space + time without seconds */
2116 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2127 /*************************************************************************
2130 * Given the ItemIdList, get the FileSize
2133 * pidl [I] The ItemIDList
2134 * pOut [I] The buffer to save the result
2135 * uOutsize [I] The size of the buffer
2141 * pOut can be null when no string is needed
2144 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2146 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2152 switch (pdata
->type
)
2155 dwSize
= pdata
->u
.file
.dwFileSize
;
2157 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2165 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2167 char szTemp
[MAX_PATH
];
2168 const char * pPoint
;
2169 LPCITEMIDLIST pidlTemp
=pidl
;
2171 TRACE("pidl=%p\n",pidl
);
2176 pidlTemp
= ILFindLastID(pidl
);
2178 if (!_ILIsValue(pidlTemp
))
2180 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2183 pPoint
= PathFindExtensionA(szTemp
);
2189 lstrcpynA(pOut
, pPoint
, uOutSize
);
2195 /*************************************************************************
2198 * Given the ItemIdList, get the file type description
2201 * pidl [I] The ItemIDList (simple)
2202 * pOut [I] The buffer to save the result
2203 * uOutsize [I] The size of the buffer
2209 * This function copies as much as possible into the buffer.
2211 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2213 if(_ILIsValue(pidl
))
2219 if (_ILGetExtension (pidl
, sTemp
, 64))
2221 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2222 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
)))
2224 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2225 strcat (pOut
, "-file");
2230 lstrcpynA(pOut
, "Folder", uOutSize
);
2233 /*************************************************************************
2234 * _ILGetFileAttributes
2236 * Given the ItemIdList, get the Attrib string format
2239 * pidl [I] The ItemIDList
2240 * pOut [I] The buffer to save the result
2241 * uOutsize [I] The size of the Buffer
2247 * return value 0 in case of error is a valid return value
2250 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2252 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2263 wAttrib
= pData
->u
.file
.uFileAttribs
;
2270 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2272 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2274 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2276 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2278 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2285 /*************************************************************************
2288 * free a aPidl struct
2290 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2296 for (i
= 0; i
< cidl
; i
++)
2302 /*************************************************************************
2305 * copies an aPidl struct
2307 LPITEMIDLIST
* _ILCopyaPidl(LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2310 LPITEMIDLIST
*apidldest
;
2312 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2316 for (i
= 0; i
< cidl
; i
++)
2317 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2322 /*************************************************************************
2323 * _ILCopyCidaToaPidl
2325 * creates aPidl from CIDA
2327 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, LPIDA cida
)
2332 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2337 *pidl
= ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[0]]));
2339 for (i
= 0; i
< cida
->cidl
; i
++)
2340 dst
[i
] = ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[i
+ 1]]));