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
27 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
28 WINE_DECLARE_DEBUG_CHANNEL(shell
);
30 /* from comctl32.dll */
31 extern LPVOID WINAPI
Alloc(INT
);
32 extern BOOL WINAPI
Free(LPVOID
);
34 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
);
35 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
);
37 /*************************************************************************
38 * ILGetDisplayNameExA [SHELL32.186]
40 * Retrieves the display name of an ItemIDList
43 * psf [I] Shell Folder to start with, if NULL the desktop is used
44 * pidl [I] ItemIDList relative to the psf to get the display name for
45 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
46 * type [I] Type of display name to retrieve
47 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
48 * 1 = SHGDN_NORMAL relative to the root folder
49 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
52 * True if the display name could be retrieved successfully, False otherwise
54 static BOOL
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
57 WCHAR wPath
[MAX_PATH
];
59 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
64 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
65 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
66 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
71 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
73 LPSHELLFOLDER psfParent
, lsf
= psf
;
74 HRESULT ret
= NO_ERROR
;
75 LPCITEMIDLIST pidllast
;
79 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
86 ret
= SHGetDesktopFolder(&lsf
);
95 case ILGDN_FORPARSING
:
96 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
102 flag
= SHGDN_INFOLDER
;
105 FIXME("Unknown type parameter = %x\n", type
);
106 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
109 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
111 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
114 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
120 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
123 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
126 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
129 IShellFolder_Release(psfParent
);
134 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
137 IShellFolder_Release(lsf
);
138 return SUCCEEDED(ret
);
141 /*************************************************************************
142 * ILGetDisplayNameEx [SHELL32.186]
144 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
146 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
148 if (SHELL_OsIsUnicode())
149 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
150 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
153 /*************************************************************************
154 * ILGetDisplayName [SHELL32.15]
156 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
158 TRACE_(shell
)("%p %p\n", pidl
, path
);
160 if (SHELL_OsIsUnicode())
161 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
162 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
165 /*************************************************************************
166 * ILFindLastID [SHELL32.16]
169 * observed: pidl=Desktop return=pidl
171 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
173 LPCITEMIDLIST pidlLast
= pidl
;
175 TRACE("(pidl=%p)\n",pidl
);
180 while (pidl
->mkid
.cb
)
183 pidl
= ILGetNext(pidl
);
185 return (LPITEMIDLIST
)pidlLast
;
188 /*************************************************************************
189 * ILRemoveLastID [SHELL32.17]
192 * when pidl=Desktop return=FALSE
194 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
196 TRACE_(shell
)("pidl=%p\n",pidl
);
198 if (!pidl
|| !pidl
->mkid
.cb
)
200 ILFindLastID(pidl
)->mkid
.cb
= 0;
204 /*************************************************************************
205 * ILClone [SHELL32.18]
208 * duplicate an idlist
210 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
213 LPITEMIDLIST newpidl
;
218 len
= ILGetSize(pidl
);
219 newpidl
= SHAlloc(len
);
221 memcpy(newpidl
,pidl
,len
);
223 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
229 /*************************************************************************
230 * ILCloneFirst [SHELL32.19]
233 * duplicates the first idlist of a complex pidl
235 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
238 LPITEMIDLIST pidlNew
= NULL
;
240 TRACE("pidl=%p\n", pidl
);
246 pidlNew
= SHAlloc(len
+2);
249 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
252 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
255 TRACE("-- newpidl=%p\n",pidlNew
);
260 /*************************************************************************
261 * ILLoadFromStream (SHELL32.26)
264 * the first two bytes are the len, the pidl is following then
266 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
270 HRESULT ret
= E_FAIL
;
273 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
278 IStream_AddRef (pStream
);
280 if (SUCCEEDED(IStream_Read(pStream
, &wLen
, 2, &dwBytesRead
)))
282 TRACE("PIDL length is %d\n", wLen
);
285 *ppPidl
= SHAlloc (wLen
);
286 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
288 TRACE("Stream read OK\n");
293 WARN("reading pidl failed\n");
305 /* we are not yet fully compatible */
306 if (*ppPidl
&& !pcheck(*ppPidl
))
308 WARN("Check failed\n");
313 IStream_Release (pStream
);
318 /*************************************************************************
319 * ILSaveToStream (SHELL32.27)
322 * the first two bytes are the len, the pidl is following then
324 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
327 HRESULT ret
= E_FAIL
;
329 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
331 IStream_AddRef (pStream
);
333 wLen
= ILGetSize(pPidl
);
335 if (SUCCEEDED(IStream_Write(pStream
, &wLen
, 2, NULL
)))
337 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
340 IStream_Release (pStream
);
345 /*************************************************************************
346 * SHILCreateFromPath [SHELL32.28]
348 * Create an ItemIDList from a path
353 * attributes [I/O] requested attributes on call and actual attributes when
354 * the function returns
357 * NO_ERROR if successful, or an OLE errer code otherwise
360 * Wrapper for IShellFolder_ParseDisplayName().
362 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
364 WCHAR lpszDisplayName
[MAX_PATH
];
366 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
368 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
369 lpszDisplayName
[MAX_PATH
-1] = 0;
371 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
374 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
378 HRESULT ret
= E_FAIL
;
380 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
382 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
384 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
385 IShellFolder_Release(sf
);
390 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
392 if ( SHELL_OsIsUnicode())
393 return SHILCreateFromPathW (path
, ppidl
, attributes
);
394 return SHILCreateFromPathA (path
, ppidl
, attributes
);
397 /*************************************************************************
398 * SHCloneSpecialIDList [SHELL32.89]
400 * Create an ItemIDList to one of the special folders.
404 * nFolder [in] CSIDL_xxxxx
405 * fCreate [in] Create folder if it does not exist
408 * Success: The newly created pidl
409 * Failure: NULL, if inputs are invalid.
412 * exported by ordinal.
413 * Caller is responsible for deallocating the returned ItemIDList with the
414 * shells IMalloc interface, aka ILFree.
416 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, int nFolder
, BOOL fCreate
)
419 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
422 nFolder
|= CSIDL_FLAG_CREATE
;
424 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
428 /*************************************************************************
429 * ILGlobalClone [SHELL32.20]
431 * Clones an ItemIDList using Alloc.
434 * pidl [I] ItemIDList to clone
437 * Newly allocated ItemIDList.
440 * exported by ordinal.
442 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
445 LPITEMIDLIST newpidl
;
450 len
= ILGetSize(pidl
);
451 newpidl
= Alloc(len
);
453 memcpy(newpidl
,pidl
,len
);
455 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
461 /*************************************************************************
462 * ILIsEqual [SHELL32.21]
465 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
467 char szData1
[MAX_PATH
];
468 char szData2
[MAX_PATH
];
470 LPCITEMIDLIST pidltemp1
= pidl1
;
471 LPCITEMIDLIST pidltemp2
= pidl2
;
473 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
476 * Explorer reads from registry directly (StreamMRU),
477 * so we can only check here
479 if (!pcheck(pidl1
) || !pcheck (pidl2
))
485 if (!pidl1
|| !pidl2
)
488 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
490 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
491 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
493 if (strcmp( szData1
, szData2
))
496 pidltemp1
= ILGetNext(pidltemp1
);
497 pidltemp2
= ILGetNext(pidltemp2
);
500 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
506 /*************************************************************************
507 * ILIsParent [SHELL32.23]
509 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
514 * bImmediate [I] only return true if the parent is the direct parent
518 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
522 * parent = a/b, child = a/b/c -> true, c is in folder a/b
523 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
524 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
526 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
528 char szData1
[MAX_PATH
];
529 char szData2
[MAX_PATH
];
530 LPCITEMIDLIST pParent
= pidlParent
;
531 LPCITEMIDLIST pChild
= pidlChild
;
533 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
535 if (!pParent
|| !pChild
)
538 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
540 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
541 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
543 if (strcmp( szData1
, szData2
))
546 pParent
= ILGetNext(pParent
);
547 pChild
= ILGetNext(pChild
);
550 /* child shorter or has equal length to parent */
551 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
554 /* not immediate descent */
555 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
561 /*************************************************************************
562 * ILFindChild [SHELL32.24]
564 * Compares elements from pidl1 and pidl2.
571 * pidl1 is desktop pidl2
572 * pidl1 shorter pidl2 pointer to first different element of pidl2
573 * if there was at least one equal element
574 * pidl2 shorter pidl1 0
575 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
578 * exported by ordinal.
580 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
582 char szData1
[MAX_PATH
];
583 char szData2
[MAX_PATH
];
585 LPCITEMIDLIST pidltemp1
= pidl1
;
586 LPCITEMIDLIST pidltemp2
= pidl2
;
587 LPCITEMIDLIST ret
=NULL
;
589 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
591 /* explorer reads from registry directly (StreamMRU),
592 so we can only check here */
593 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
599 if (_ILIsDesktop(pidl1
))
605 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
607 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
608 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
610 if (strcmp(szData1
,szData2
))
613 pidltemp1
= ILGetNext(pidltemp1
);
614 pidltemp2
= ILGetNext(pidltemp2
);
618 if (pidltemp1
->mkid
.cb
)
619 ret
= NULL
; /* elements of pidl1 left*/
621 TRACE_(shell
)("--- %p\n", ret
);
622 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
625 /*************************************************************************
626 * ILCombine [SHELL32.25]
628 * Concatenates two complex ItemIDLists.
631 * pidl1 [I] first complex ItemIDLists
632 * pidl2 [I] complex ItemIDLists to append
635 * if both pidl's == NULL NULL
636 * if pidl1 == NULL cloned pidl2
637 * if pidl2 == NULL cloned pidl1
638 * otherwise new pidl with pidl2 appended to pidl1
641 * exported by ordinal.
642 * Does not destroy the passed in ItemIDLists!
644 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
647 LPITEMIDLIST pidlNew
;
649 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
651 if (!pidl1
&& !pidl2
) return NULL
;
658 pidlNew
= ILClone(pidl2
);
664 pidlNew
= ILClone(pidl1
);
668 len1
= ILGetSize(pidl1
)-2;
669 len2
= ILGetSize(pidl2
);
670 pidlNew
= SHAlloc(len1
+len2
);
674 memcpy(pidlNew
,pidl1
,len1
);
675 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
678 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
682 /*************************************************************************
683 * SHGetRealIDL [SHELL32.98]
687 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
689 IDataObject
* pDataObj
;
692 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
693 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
699 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLIST
);
701 fmt
.dwAspect
= DVASPECT_CONTENT
;
703 fmt
.tymed
= TYMED_HGLOBAL
;
705 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
707 IDataObject_Release(pDataObj
);
711 /*assert(pida->cidl==1);*/
712 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
714 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
715 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
717 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
722 GlobalUnlock(medium
.u
.hGlobal
);
723 GlobalFree(medium
.u
.hGlobal
);
730 /*************************************************************************
731 * SHLogILFromFSIL [SHELL32.95]
734 * pild = CSIDL_DESKTOP ret = 0
735 * pild = CSIDL_DRIVES ret = 0
737 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
739 FIXME("(pidl=%p)\n",pidl
);
746 /*************************************************************************
747 * ILGetSize [SHELL32.152]
749 * Gets the byte size of an ItemIDList including zero terminator
752 * pidl [I] ItemIDList
755 * size of pidl in bytes
758 * exported by ordinal
760 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
762 LPCSHITEMID si
= &(pidl
->mkid
);
770 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
774 TRACE("pidl=%p size=%u\n",pidl
, len
);
778 /*************************************************************************
779 * ILGetNext [SHELL32.153]
781 * Gets the next ItemID of an ItemIDList
784 * pidl [I] ItemIDList
789 * simple pidl -> pointer to 0x0000 element
792 * exported by ordinal.
794 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
805 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
806 TRACE("-- %p\n", pidl
);
807 return (LPITEMIDLIST
)pidl
;
813 /*************************************************************************
814 * ILAppend [SHELL32.154]
816 * Adds the single ItemID item to the ItemIDList indicated by pidl.
817 * If bEnd is FALSE, inserts the item in the front of the list,
818 * otherwise it adds the item to the end. (???)
821 * pidl [I] ItemIDList to extend
822 * item [I] ItemID to prepend/append
823 * bEnd [I] Indicates if the item should be appended
826 * Destroys the passed in idlist! (???)
828 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
832 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
837 if (_ILIsDesktop(pidl
))
839 idlRet
= ILClone(item
);
845 idlRet
= ILCombine(pidl
, item
);
847 idlRet
= ILCombine(item
, pidl
);
853 /*************************************************************************
854 * ILFree [SHELL32.155]
856 * Frees memory (if not NULL) allocated by SHMalloc allocator
865 * exported by ordinal
867 void WINAPI
ILFree(LPITEMIDLIST pidl
)
869 TRACE("(pidl=%p)\n",pidl
);
873 /*************************************************************************
874 * ILGlobalFree [SHELL32.156]
876 * Frees memory (if not NULL) allocated by Alloc allocator
885 * exported by ordinal.
887 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
894 /*************************************************************************
895 * ILCreateFromPathA [SHELL32.189]
897 * Creates a complex ItemIDList from a path and returns it.
903 * the newly created complex ItemIDList or NULL if failed
906 * exported by ordinal.
908 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
910 LPITEMIDLIST pidlnew
= NULL
;
912 TRACE_(shell
)("%s\n", debugstr_a(path
));
914 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
919 /*************************************************************************
920 * ILCreateFromPathW [SHELL32.190]
922 * See ILCreateFromPathA.
924 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
926 LPITEMIDLIST pidlnew
= NULL
;
928 TRACE_(shell
)("%s\n", debugstr_w(path
));
930 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
935 /*************************************************************************
936 * ILCreateFromPath [SHELL32.157]
938 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
940 if ( SHELL_OsIsUnicode())
941 return ILCreateFromPathW (path
);
942 return ILCreateFromPathA (path
);
945 /*************************************************************************
946 * _ILParsePathW [internal]
948 * Creates an ItemIDList from a path and returns it.
951 * path [I] path to parse and convert into an ItemIDList
952 * lpFindFile [I] pointer to buffer to initialize the FileSystem
953 * Bind Data object with
954 * bBindCtx [I] indicates to create a BindContext and assign a
955 * FileSystem Bind Data object
956 * ppidl [O] the newly create ItemIDList
957 * prgfInOut [I/O] requested attributes on input and actual
958 * attributes on return
961 * NO_ERROR on success or an OLE error code
964 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
965 * creates a BindContext object and assigns a FileSystem Bind Data object
966 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
967 * IShellFolder uses that FileSystem Bind Data object of the BindContext
968 * to pass data about the current path element to the next object. This
969 * is used to avoid having to verify the current path element on disk, so
970 * that creating an ItemIDList from a nonexistent path still can work.
972 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
973 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
975 LPSHELLFOLDER pSF
= NULL
;
979 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
980 ppidl
, ppidl
? *ppidl
: NULL
,
981 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
983 ret
= SHGetDesktopFolder(&pSF
);
987 if (lpFindFile
|| bBindCtx
)
988 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
992 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
997 IBindCtx_Release(pBC
);
1001 IShellFolder_Release(pSF
);
1003 if (FAILED(ret
) && ppidl
)
1006 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1011 /*************************************************************************
1012 * SHSimpleIDListFromPath [SHELL32.162]
1014 * Creates a simple ItemIDList from a path and returns it. This function
1015 * does not fail on nonexistent paths.
1018 * path [I] path to parse and convert into an ItemIDList
1021 * the newly created simple ItemIDList
1024 * Simple in the name does not mean a relative ItemIDList but rather a
1025 * fully qualified list, where only the file name is filled in and the
1026 * directory flag for those ItemID elements this is known about, eg.
1027 * it is not the last element in the ItemIDList or the actual directory
1029 * exported by ordinal.
1031 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1033 LPITEMIDLIST pidl
= NULL
;
1034 LPWSTR wPath
= NULL
;
1037 TRACE("%s\n", debugstr_a(lpszPath
));
1041 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1042 wPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1043 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1046 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1048 HeapFree(GetProcessHeap(), 0, wPath
);
1049 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1053 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1055 LPITEMIDLIST pidl
= NULL
;
1057 TRACE("%s\n", debugstr_w(lpszPath
));
1059 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1060 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1064 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1066 if ( SHELL_OsIsUnicode())
1067 return SHSimpleIDListFromPathW (lpszPath
);
1068 return SHSimpleIDListFromPathA (lpszPath
);
1071 /*************************************************************************
1072 * SHGetDataFromIDListA [SHELL32.247]
1075 * the pidl can be a simple one. since we can't get the path out of the pidl
1076 * we have to take all data from the pidl
1078 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1079 int nFormat
, LPVOID dest
, int len
)
1081 LPSTR filename
, shortname
;
1082 WIN32_FIND_DATAA
* pfd
;
1084 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1088 return E_INVALIDARG
;
1092 case SHGDFIL_FINDDATA
:
1095 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1096 return E_INVALIDARG
;
1098 if (len
< sizeof(WIN32_FIND_DATAA
))
1099 return E_INVALIDARG
;
1101 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1102 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1103 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1104 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1106 filename
= _ILGetTextPointer(pidl
);
1107 shortname
= _ILGetSTextPointer(pidl
);
1110 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1112 pfd
->cFileName
[0] = '\0';
1115 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1117 pfd
->cAlternateFileName
[0] = '\0';
1120 case SHGDFIL_NETRESOURCE
:
1121 case SHGDFIL_DESCRIPTIONID
:
1122 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1126 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1129 return E_INVALIDARG
;
1132 /*************************************************************************
1133 * SHGetDataFromIDListW [SHELL32.248]
1136 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1137 int nFormat
, LPVOID dest
, int len
)
1139 LPSTR filename
, shortname
;
1140 WIN32_FIND_DATAW
* pfd
= dest
;
1142 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1147 return E_INVALIDARG
;
1151 case SHGDFIL_FINDDATA
:
1154 if (_ILIsDrive(pidl
))
1155 return E_INVALIDARG
;
1157 if (len
< sizeof(WIN32_FIND_DATAW
))
1158 return E_INVALIDARG
;
1160 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1161 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1162 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1163 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1165 filename
= _ILGetTextPointer(pidl
);
1166 shortname
= _ILGetSTextPointer(pidl
);
1169 pfd
->cFileName
[0] = '\0';
1170 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1171 pfd
->cFileName
[MAX_PATH
-1] = 0;
1174 pfd
->cAlternateFileName
[0] = '\0';
1175 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1176 pfd
->cAlternateFileName
[13] = 0;
1179 case SHGDFIL_NETRESOURCE
:
1180 case SHGDFIL_DESCRIPTIONID
:
1181 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1185 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1188 return E_INVALIDARG
;
1191 /*************************************************************************
1192 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1196 * pszPath [OUT] path
1199 * path from a passed PIDL.
1202 * NULL returns FALSE
1203 * desktop pidl gives path to desktop directory back
1204 * special pidls returning FALSE
1206 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1208 WCHAR wszPath
[MAX_PATH
];
1211 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1212 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1217 /*************************************************************************
1218 * SHGetPathFromIDListW [SHELL32.@]
1220 * See SHGetPathFromIDListA.
1222 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1225 LPCITEMIDLIST pidlLast
;
1226 LPSHELLFOLDER psfFolder
;
1230 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, pszPath
);
1237 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1238 if (FAILED(hr
)) return FALSE
;
1240 dwAttributes
= SFGAO_FILESYSTEM
;
1241 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1242 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1243 IShellFolder_Release(psfFolder
);
1247 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1248 IShellFolder_Release(psfFolder
);
1249 if (FAILED(hr
)) return FALSE
;
1251 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1253 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(pszPath
), hr
);
1254 return SUCCEEDED(hr
);
1257 /*************************************************************************
1258 * SHBindToParent [shell version 5.0]
1260 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1262 IShellFolder
* psfDesktop
;
1265 TRACE_(shell
)("pidl=%p\n", pidl
);
1269 return E_INVALIDARG
;
1275 hr
= SHGetDesktopFolder(&psfDesktop
);
1279 if (_ILIsPidlSimple(pidl
))
1281 /* we are on desktop level */
1282 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1286 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1287 ILRemoveLastID(pidlParent
);
1288 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1289 SHFree (pidlParent
);
1292 IShellFolder_Release(psfDesktop
);
1294 if (SUCCEEDED(hr
) && ppidlLast
)
1295 *ppidlLast
= ILFindLastID(pidl
);
1297 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1301 /**************************************************************************
1303 * internal functions
1305 * ### 1. section creating pidls ###
1307 *************************************************************************
1310 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1311 * - two bytes are SHITEMID.cb
1312 * - one byte is PIDLDATA.type
1313 * - two bytes are the NULL PIDL terminator
1314 * Sets type of the returned PIDL to type.
1316 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1318 LPITEMIDLIST pidlOut
= NULL
;
1320 pidlOut
= SHAlloc(size
+ 5);
1324 LPITEMIDLIST pidlNext
;
1326 ZeroMemory(pidlOut
, size
+ 5);
1327 pidlOut
->mkid
.cb
= size
+ 3;
1329 pData
= _ILGetDataPointer(pidlOut
);
1333 pidlNext
= ILGetNext(pidlOut
);
1335 pidlNext
->mkid
.cb
= 0x00;
1336 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1342 LPITEMIDLIST
_ILCreateDesktop(void)
1353 LPITEMIDLIST
_ILCreateMyComputer(void)
1356 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1359 LPITEMIDLIST
_ILCreateMyDocuments(void)
1362 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1365 LPITEMIDLIST
_ILCreateIExplore(void)
1368 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1371 LPITEMIDLIST
_ILCreateControlPanel(void)
1373 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1378 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1382 ret
= ILCombine(parent
, cpl
);
1390 LPITEMIDLIST
_ILCreatePrinters(void)
1392 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1397 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1401 ret
= ILCombine(parent
, printers
);
1409 LPITEMIDLIST
_ILCreateNetwork(void)
1412 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1415 LPITEMIDLIST
_ILCreateBitBucket(void)
1418 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1421 LPITEMIDLIST
_ILCreateAdminTools(void)
1424 return _ILCreateGuid(PT_GUID
, &CLSID_AdminFolderShortcut
); //FIXME
1427 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1429 LPITEMIDLIST pidlOut
;
1431 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1433 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1436 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1438 pData
->u
.guid
.guid
= *guid
;
1439 TRACE("-- create GUID-pidl %s\n",
1440 debugstr_guid(&(pData
->u
.guid
.guid
)));
1445 WARN("%d: invalid type for GUID\n", type
);
1451 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1455 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1457 ERR("%s is not a GUID\n", szGUID
);
1460 return _ILCreateGuid(PT_GUID
, &iid
);
1463 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1467 if (FAILED(CLSIDFromString((LPOLESTR
)szGUID
, &iid
)))
1469 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1472 return _ILCreateGuid(PT_GUID
, &iid
);
1475 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1477 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1478 DWORD len
, len1
, wlen
, alen
;
1485 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1487 /* prepare buffer with both names */
1488 len
= WideCharToMultiByte(CP_ACP
,0,wfd
->cFileName
,-1,buff
,MAX_PATH
,NULL
,NULL
);
1489 len1
= WideCharToMultiByte(CP_ACP
,0,wfd
->cAlternateFileName
,-1, buff
+len
, sizeof(buff
)-len
, NULL
, NULL
);
1492 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1494 wlen
= wcslen(wfd
->cFileName
) + 1;
1495 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1496 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1499 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1500 FileStruct
*fs
= &pData
->u
.file
;
1504 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1505 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1506 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1507 memcpy(fs
->szNames
, buff
, alen
);
1509 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1510 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1511 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1512 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1513 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1515 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1516 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1517 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1523 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1526 WIN32_FIND_DATAW stffile
;
1529 return E_INVALIDARG
;
1531 hFile
= FindFirstFileW(szPath
, &stffile
);
1532 if (hFile
== INVALID_HANDLE_VALUE
)
1533 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1537 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1539 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1542 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1544 LPITEMIDLIST pidlOut
;
1546 TRACE("(%s)\n",debugstr_w(lpszNew
));
1548 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1553 pszDest
= _ILGetTextPointer(pidlOut
);
1556 strcpy(pszDest
, "x:\\");
1557 pszDest
[0]=towupper(lpszNew
[0]);
1558 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1564 /**************************************************************************
1567 * Gets the text for the drive eg. 'c:\'
1572 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1574 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1576 if(_ILIsMyComputer(pidl
))
1577 pidl
= ILGetNext(pidl
);
1579 if (pidl
&& _ILIsDrive(pidl
))
1580 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1585 /**************************************************************************
1587 * ### 2. section testing pidls ###
1589 **************************************************************************
1593 * _ILIsSpecialFolder()
1599 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1601 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1603 TRACE("(%p)\n",pidl
);
1605 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1608 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1610 TRACE("(%p)\n",pidl
);
1612 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1615 BOOL
_ILIsMyDocuments(LPCITEMIDLIST pidl
)
1617 REFIID iid
= _ILGetGUIDPointer(pidl
);
1619 TRACE("(%p)\n",pidl
);
1622 return IsEqualIID(iid
, &CLSID_MyDocuments
);
1626 BOOL
_ILIsControlPanel(LPCITEMIDLIST pidl
)
1628 REFIID iid
= _ILGetGUIDPointer(pidl
);
1630 TRACE("(%p)\n",pidl
);
1633 return IsEqualIID(iid
, &CLSID_ControlPanel
);
1637 BOOL
_ILIsNetHood(LPCITEMIDLIST pidl
)
1639 REFIID iid
= _ILGetGUIDPointer(pidl
);
1641 TRACE("(%p)\n",pidl
);
1644 return IsEqualIID(iid
, &CLSID_NetworkPlaces
);
1649 LPITEMIDLIST
_ILCreateNetHood(void)
1651 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1654 LPITEMIDLIST
_ILCreateFont(void)
1656 return _ILCreateGuid(PT_GUID
, &CLSID_FontsFolderShortcut
);
1659 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1661 REFIID iid
= _ILGetGUIDPointer(pidl
);
1663 TRACE("(%p)\n",pidl
);
1666 return IsEqualIID(iid
, &CLSID_MyComputer
);
1670 BOOL
_ILIsPrinter(LPCITEMIDLIST pidl
)
1672 REFIID iid
= _ILGetGUIDPointer(pidl
);
1674 TRACE("(%p)\n",pidl
);
1677 return IsEqualIID(iid
, &CLSID_Printers
);
1681 BOOL
_ILIsBitBucket(LPCITEMIDLIST pidl
)
1683 REFIID iid
= _ILGetGUIDPointer(pidl
);
1685 TRACE("(%p)\n",pidl
);
1688 return IsEqualIID(iid
, &CLSID_RecycleBin
);
1692 BOOL
_ILIsAdminTools(LPCITEMIDLIST pidl
)
1694 REFIID iid
= _ILGetGUIDPointer(pidl
);
1696 TRACE("(%p)\n",pidl
);
1699 return IsEqualIID(iid
, &CLSID_AdminFolderShortcut
);
1704 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1706 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1708 TRACE("(%p)\n",pidl
);
1710 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1711 (pidl
&& pidl
->mkid
.cb
== 0x00)
1715 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1717 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1719 TRACE("(%p)\n",pidl
);
1721 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1722 PT_DRIVE1
== lpPData
->type
||
1723 PT_DRIVE2
== lpPData
->type
||
1724 PT_DRIVE3
== lpPData
->type
));
1727 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1729 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1731 TRACE("(%p)\n",pidl
);
1733 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1736 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1738 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1740 TRACE("(%p)\n",pidl
);
1742 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1745 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1747 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1749 TRACE("(%p)\n",pidl
);
1751 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1754 /**************************************************************************
1757 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1761 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1763 WORD len
= pidl
->mkid
.cb
;
1764 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1766 if (pidlnext
->mkid
.cb
)
1770 TRACE("%s\n", ret
? "Yes" : "No");
1774 /**************************************************************************
1776 * ### 3. section getting values from pidls ###
1779 /**************************************************************************
1782 * gets the text for the first item in the pidl (eg. simple pidl)
1784 * returns the length of the string
1786 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1792 char szTemp
[MAX_PATH
];
1794 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1802 if (_ILIsDesktop(pidl
))
1805 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1808 lstrcpynA(szOut
, szTemp
, uOutSize
);
1810 dwReturn
= strlen (szTemp
);
1813 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1817 lstrcpynA(szOut
, szSrc
, uOutSize
);
1819 dwReturn
= strlen(szSrc
);
1821 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1823 /* unicode filesystem */
1824 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1827 lstrcpynA(szOut
, szTemp
, uOutSize
);
1829 dwReturn
= strlen (szTemp
);
1831 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1833 /* special folder */
1834 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1837 lstrcpynA(szOut
, szTemp
, uOutSize
);
1839 dwReturn
= strlen (szTemp
);
1844 ERR("-- no text\n");
1847 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1851 /**************************************************************************
1854 * gets the text for the first item in the pidl (eg. simple pidl)
1856 * returns the length of the string
1858 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1861 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
1863 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1866 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
1867 dwReturn
= wcslen(pFileStructW
->wszName
);
1870 WCHAR szTemp
[MAX_PATH
];
1881 if (_ILIsDesktop(pidl
))
1884 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1887 lstrcpynW(szOut
, szTemp
, uOutSize
);
1889 dwReturn
= wcslen (szTemp
);
1892 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1894 /* unicode filesystem */
1896 lstrcpynW(szOut
, szSrcW
, uOutSize
);
1898 dwReturn
= wcslen(szSrcW
);
1900 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1903 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
1906 lstrcpynW(szOut
, szTemp
, uOutSize
);
1908 dwReturn
= wcslen (szTemp
);
1910 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1912 /* special folder */
1913 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
1916 lstrcpynW(szOut
, szTemp
, uOutSize
);
1918 dwReturn
= wcslen (szTemp
);
1923 ERR("-- no text\n");
1927 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1931 /**************************************************************************
1933 * ### 4. getting pointers to parts of pidls ###
1935 **************************************************************************
1936 * _ILGetDataPointer()
1938 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1940 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1941 return (LPPIDLDATA
)pidl
->mkid
.abID
;
1945 /**************************************************************************
1946 * _ILGetTextPointerW()
1947 * gets a pointer to the unicode long filename string stored in the pidl
1949 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
1951 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1953 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1958 switch (pdata
->type
)
1969 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1977 /*return (LPSTR)&(pdata->u.file.szNames);*/
1983 case PT_NETPROVIDER
:
1985 /*return (LPSTR)&(pdata->u.network.szNames);*/
1989 return (LPWSTR
)pdata
->u
.file
.szNames
;
1995 /**************************************************************************
1996 * _ILGetTextPointer()
1997 * gets a pointer to the long filename string stored in the pidl
1999 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
2001 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2003 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2008 switch (pdata
->type
)
2019 return pdata
->u
.drive
.szDriveName
;
2026 return pdata
->u
.file
.szNames
;
2031 case PT_NETPROVIDER
:
2033 return pdata
->u
.network
.szNames
;
2038 /**************************************************************************
2039 * _ILGetSTextPointer()
2040 * gets a pointer to the short filename string stored in the pidl
2042 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2044 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2046 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2051 switch (pdata
->type
)
2057 return pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1;
2060 return pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1;
2065 /**************************************************************************
2066 * _ILGetGUIDPointer()
2068 * returns reference to guid stored in some pidls
2070 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2072 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2074 TRACE("%p\n", pidl
);
2079 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2080 switch (pdata
->type
)
2085 return &(pdata
->u
.guid
.guid
);
2088 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2094 /******************************************************************************
2095 * _ILGetFileStructW [Internal]
2097 * Get pointer the a SHITEMID's FileStructW field if present
2100 * pidl [I] The SHITEMID
2103 * Success: Pointer to pidl's FileStructW field.
2106 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2107 FileStructW
*pFileStructW
;
2110 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2113 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2114 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2116 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2117 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2118 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2119 if (cbOffset
& 0x1 || /* FileStructW member is word aligned in the pidl */
2120 /* FileStructW is positioned after FileStruct */
2121 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2122 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2123 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2124 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2126 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2130 return pFileStructW
;
2133 /*************************************************************************
2134 * _ILGetFileDateTime
2136 * Given the ItemIdList, get the FileTime
2139 * pidl [I] The ItemIDList
2140 * pFt [I] the resulted FILETIME of the file
2143 * True if Successful
2148 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2150 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2155 switch (pdata
->type
)
2159 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2167 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2173 if (_ILGetFileDateTime( pidl
, &ft
))
2175 FileTimeToLocalFileTime(&ft
, &lft
);
2176 FileTimeToSystemTime (&lft
, &time
);
2178 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2181 /* Append space + time without seconds */
2183 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2194 /*************************************************************************
2197 * Given the ItemIdList, get the FileSize
2200 * pidl [I] The ItemIDList
2201 * pOut [I] The buffer to save the result
2202 * uOutsize [I] The size of the buffer
2208 * pOut can be null when no string is needed
2211 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2213 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2219 switch (pdata
->type
)
2222 dwSize
= pdata
->u
.file
.dwFileSize
;
2224 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2232 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2234 char szTemp
[MAX_PATH
];
2235 const char * pPoint
;
2236 LPCITEMIDLIST pidlTemp
=pidl
;
2238 TRACE("pidl=%p\n",pidl
);
2243 pidlTemp
= ILFindLastID(pidl
);
2245 if (!_ILIsValue(pidlTemp
))
2247 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2250 pPoint
= PathFindExtensionA(szTemp
);
2256 lstrcpynA(pOut
, pPoint
, uOutSize
);
2262 /*************************************************************************
2265 * Given the ItemIdList, get the file type description
2268 * pidl [I] The ItemIDList (simple)
2269 * pOut [I] The buffer to save the result
2270 * uOutsize [I] The size of the buffer
2276 * This function copies as much as possible into the buffer.
2278 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2282 if(_ILIsValue(pidl
))
2288 if (_ILGetExtension (pidl
, sType
, 64))
2290 if (HCR_MapTypeToValueA(sType
, sTemp
, 64, TRUE
))
2292 /* retrieve description */
2293 if(HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2296 /* display Ext-file as description */
2297 strcpy(pOut
, sType
);
2299 /* load localized file string */
2301 if(LoadStringA(shell32_hInstance
, IDS_SHV_COLUMN1
, sTemp
, 64))
2305 strcat(pOut
, sTemp
);
2312 LoadStringA(shell32_hInstance
, IDS_DIRECTORY
, pOut
, uOutSize
);
2313 /* make sure its null terminated */
2314 pOut
[uOutSize
-1] = '\0';
2318 /*************************************************************************
2319 * _ILGetFileAttributes
2321 * Given the ItemIdList, get the Attrib string format
2324 * pidl [I] The ItemIDList
2325 * pOut [I] The buffer to save the result
2326 * uOutsize [I] The size of the Buffer
2332 * return value 0 in case of error is a valid return value
2335 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2337 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2348 wAttrib
= pData
->u
.file
.uFileAttribs
;
2355 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2357 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2359 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2361 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2363 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2370 /*************************************************************************
2373 * free a aPidl struct
2375 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2381 for (i
= 0; i
< cidl
; i
++)
2387 /*************************************************************************
2390 * copies an aPidl struct
2392 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2395 LPITEMIDLIST
*apidldest
;
2397 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2401 for (i
= 0; i
< cidl
; i
++)
2402 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2407 /*************************************************************************
2408 * _ILCopyCidaToaPidl
2410 * creates aPidl from CIDA
2412 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2417 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2422 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2424 for (i
= 0; i
< cida
->cidl
; i
++)
2425 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));