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 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
143 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
145 if (SHELL_OsIsUnicode())
146 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
147 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
150 /*************************************************************************
151 * ILGetDisplayName [SHELL32.15]
153 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
155 TRACE_(shell
)("%p %p\n", pidl
, path
);
157 if (SHELL_OsIsUnicode())
158 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
159 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
162 /*************************************************************************
163 * ILFindLastID [SHELL32.16]
166 * observed: pidl=Desktop return=pidl
168 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
170 LPCITEMIDLIST pidlLast
= pidl
;
172 TRACE("(pidl=%p)\n",pidl
);
177 while (pidl
->mkid
.cb
)
180 pidl
= ILGetNext(pidl
);
182 return (LPITEMIDLIST
)pidlLast
;
185 /*************************************************************************
186 * ILRemoveLastID [SHELL32.17]
189 * when pidl=Desktop return=FALSE
191 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
193 TRACE_(shell
)("pidl=%p\n",pidl
);
195 if (!pidl
|| !pidl
->mkid
.cb
)
197 ILFindLastID(pidl
)->mkid
.cb
= 0;
201 /*************************************************************************
202 * ILClone [SHELL32.18]
205 * duplicate an idlist
207 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
210 LPITEMIDLIST newpidl
;
215 len
= ILGetSize(pidl
);
216 newpidl
= SHAlloc(len
);
218 memcpy(newpidl
,pidl
,len
);
220 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
226 /*************************************************************************
227 * ILCloneFirst [SHELL32.19]
230 * duplicates the first idlist of a complex pidl
232 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
235 LPITEMIDLIST pidlNew
= NULL
;
237 TRACE("pidl=%p\n", pidl
);
243 pidlNew
= SHAlloc(len
+2);
246 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
249 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
252 TRACE("-- newpidl=%p\n",pidlNew
);
257 /*************************************************************************
258 * ILLoadFromStream (SHELL32.26)
261 * the first two bytes are the len, the pidl is following then
263 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
267 HRESULT ret
= E_FAIL
;
270 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
275 IStream_AddRef (pStream
);
277 if (SUCCEEDED(IStream_Read(pStream
, &wLen
, 2, &dwBytesRead
)))
279 TRACE("PIDL length is %d\n", wLen
);
282 *ppPidl
= SHAlloc (wLen
);
283 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
285 TRACE("Stream read OK\n");
290 WARN("reading pidl failed\n");
302 /* we are not yet fully compatible */
303 if (*ppPidl
&& !pcheck(*ppPidl
))
305 WARN("Check failed\n");
310 IStream_Release (pStream
);
315 /*************************************************************************
316 * ILSaveToStream (SHELL32.27)
319 * the first two bytes are the len, the pidl is following then
321 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
324 HRESULT ret
= E_FAIL
;
326 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
328 IStream_AddRef (pStream
);
330 wLen
= ILGetSize(pPidl
);
332 if (SUCCEEDED(IStream_Write(pStream
, &wLen
, 2, NULL
)))
334 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
337 IStream_Release (pStream
);
342 /*************************************************************************
343 * SHILCreateFromPath [SHELL32.28]
345 * Create an ItemIDList from a path
350 * attributes [I/O] requested attributes on call and actual attributes when
351 * the function returns
354 * NO_ERROR if successful, or an OLE errer code otherwise
357 * Wrapper for IShellFolder_ParseDisplayName().
359 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
361 WCHAR lpszDisplayName
[MAX_PATH
];
363 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
365 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
366 lpszDisplayName
[MAX_PATH
-1] = 0;
368 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
371 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
375 HRESULT ret
= E_FAIL
;
377 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
379 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
381 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
382 IShellFolder_Release(sf
);
387 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
389 if ( SHELL_OsIsUnicode())
390 return SHILCreateFromPathW (path
, ppidl
, attributes
);
391 return SHILCreateFromPathA (path
, ppidl
, attributes
);
394 /*************************************************************************
395 * SHCloneSpecialIDList [SHELL32.89]
397 * Create an ItemIDList to one of the special folders.
401 * nFolder [in] CSIDL_xxxxx
402 * fCreate [in] Create folder if it does not exist
405 * Success: The newly created pidl
406 * Failure: NULL, if inputs are invalid.
409 * exported by ordinal.
410 * Caller is responsible for deallocating the returned ItemIDList with the
411 * shells IMalloc interface, aka ILFree.
413 PIDLIST_ABSOLUTE WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, int nFolder
, BOOL fCreate
)
416 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
419 nFolder
|= CSIDL_FLAG_CREATE
;
421 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
425 /*************************************************************************
426 * ILGlobalClone [SHELL32.20]
428 * Clones an ItemIDList using Alloc.
431 * pidl [I] ItemIDList to clone
434 * Newly allocated ItemIDList.
437 * exported by ordinal.
439 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
442 LPITEMIDLIST newpidl
;
447 len
= ILGetSize(pidl
);
448 newpidl
= Alloc(len
);
450 memcpy(newpidl
,pidl
,len
);
452 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
458 /*************************************************************************
459 * ILIsEqual [SHELL32.21]
462 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
464 char szData1
[MAX_PATH
];
465 char szData2
[MAX_PATH
];
467 LPCITEMIDLIST pidltemp1
= pidl1
;
468 LPCITEMIDLIST pidltemp2
= pidl2
;
470 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
473 * Explorer reads from registry directly (StreamMRU),
474 * so we can only check here
476 if (!pcheck(pidl1
) || !pcheck (pidl2
))
482 if (!pidl1
|| !pidl2
)
485 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
487 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
488 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
490 if (strcmp( szData1
, szData2
))
493 pidltemp1
= ILGetNext(pidltemp1
);
494 pidltemp2
= ILGetNext(pidltemp2
);
497 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
503 /*************************************************************************
504 * ILIsParent [SHELL32.23]
506 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
511 * bImmediate [I] only return true if the parent is the direct parent
515 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
519 * parent = a/b, child = a/b/c -> true, c is in folder a/b
520 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
521 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
523 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
525 char szData1
[MAX_PATH
];
526 char szData2
[MAX_PATH
];
527 LPCITEMIDLIST pParent
= pidlParent
;
528 LPCITEMIDLIST pChild
= pidlChild
;
530 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
532 if (!pParent
|| !pChild
)
535 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
537 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
538 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
540 if (strcmp( szData1
, szData2
))
543 pParent
= ILGetNext(pParent
);
544 pChild
= ILGetNext(pChild
);
547 /* child shorter or has equal length to parent */
548 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
551 /* not immediate descent */
552 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
558 /*************************************************************************
559 * ILFindChild [SHELL32.24]
561 * Compares elements from pidl1 and pidl2.
568 * pidl1 is desktop pidl2
569 * pidl1 shorter pidl2 pointer to first different element of pidl2
570 * if there was at least one equal element
571 * pidl2 shorter pidl1 0
572 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
575 * exported by ordinal.
577 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
579 char szData1
[MAX_PATH
];
580 char szData2
[MAX_PATH
];
582 LPCITEMIDLIST pidltemp1
= pidl1
;
583 LPCITEMIDLIST pidltemp2
= pidl2
;
584 LPCITEMIDLIST ret
=NULL
;
586 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
588 /* explorer reads from registry directly (StreamMRU),
589 so we can only check here */
590 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
596 if (_ILIsDesktop(pidl1
))
602 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
604 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
605 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
607 if (strcmp(szData1
,szData2
))
610 pidltemp1
= ILGetNext(pidltemp1
);
611 pidltemp2
= ILGetNext(pidltemp2
);
615 if (pidltemp1
->mkid
.cb
)
616 ret
= NULL
; /* elements of pidl1 left*/
618 TRACE_(shell
)("--- %p\n", ret
);
619 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
622 /*************************************************************************
623 * ILCombine [SHELL32.25]
625 * Concatenates two complex ItemIDLists.
628 * pidl1 [I] first complex ItemIDLists
629 * pidl2 [I] complex ItemIDLists to append
632 * if both pidl's == NULL NULL
633 * if pidl1 == NULL cloned pidl2
634 * if pidl2 == NULL cloned pidl1
635 * otherwise new pidl with pidl2 appended to pidl1
638 * exported by ordinal.
639 * Does not destroy the passed in ItemIDLists!
641 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
644 LPITEMIDLIST pidlNew
;
646 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
648 if (!pidl1
&& !pidl2
) return NULL
;
655 pidlNew
= ILClone(pidl2
);
661 pidlNew
= ILClone(pidl1
);
665 len1
= ILGetSize(pidl1
)-2;
666 len2
= ILGetSize(pidl2
);
667 pidlNew
= SHAlloc(len1
+len2
);
671 memcpy(pidlNew
,pidl1
,len1
);
672 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
675 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
679 /*************************************************************************
680 * SHGetRealIDL [SHELL32.98]
684 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
686 IDataObject
* pDataObj
;
689 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
690 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
696 fmt
.cfFormat
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
698 fmt
.dwAspect
= DVASPECT_CONTENT
;
700 fmt
.tymed
= TYMED_HGLOBAL
;
702 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
704 IDataObject_Release(pDataObj
);
708 /*assert(pida->cidl==1);*/
709 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
711 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
712 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
714 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
719 GlobalUnlock(medium
.u
.hGlobal
);
720 GlobalFree(medium
.u
.hGlobal
);
727 /*************************************************************************
728 * SHLogILFromFSIL [SHELL32.95]
731 * pild = CSIDL_DESKTOP ret = 0
732 * pild = CSIDL_DRIVES ret = 0
734 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
736 FIXME("(pidl=%p)\n",pidl
);
743 /*************************************************************************
744 * ILGetSize [SHELL32.152]
746 * Gets the byte size of an ItemIDList including zero terminator
749 * pidl [I] ItemIDList
752 * size of pidl in bytes
755 * exported by ordinal
757 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
759 LPCSHITEMID si
= &(pidl
->mkid
);
767 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
771 TRACE("pidl=%p size=%u\n",pidl
, len
);
775 /*************************************************************************
776 * ILGetNext [SHELL32.153]
778 * Gets the next ItemID of an ItemIDList
781 * pidl [I] ItemIDList
786 * simple pidl -> pointer to 0x0000 element
789 * exported by ordinal.
791 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
802 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
803 TRACE("-- %p\n", pidl
);
804 return (LPITEMIDLIST
)pidl
;
810 /*************************************************************************
811 * ILAppend [SHELL32.154]
813 * Adds the single ItemID item to the ItemIDList indicated by pidl.
814 * If bEnd is FALSE, inserts the item in the front of the list,
815 * otherwise it adds the item to the end. (???)
818 * pidl [I] ItemIDList to extend
819 * item [I] ItemID to prepend/append
820 * bEnd [I] Indicates if the item should be appended
823 * Destroys the passed in idlist! (???)
825 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
829 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
834 if (_ILIsDesktop(pidl
))
836 idlRet
= ILClone(item
);
842 idlRet
= ILCombine(pidl
, item
);
844 idlRet
= ILCombine(item
, pidl
);
850 /*************************************************************************
851 * ILFree [SHELL32.155]
853 * Frees memory (if not NULL) allocated by SHMalloc allocator
862 * exported by ordinal
864 void WINAPI
ILFree(LPITEMIDLIST pidl
)
866 TRACE("(pidl=%p)\n",pidl
);
870 /*************************************************************************
871 * ILGlobalFree [SHELL32.156]
873 * Frees memory (if not NULL) allocated by Alloc allocator
882 * exported by ordinal.
884 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
891 /*************************************************************************
892 * ILCreateFromPathA [SHELL32.189]
894 * Creates a complex ItemIDList from a path and returns it.
900 * the newly created complex ItemIDList or NULL if failed
903 * exported by ordinal.
905 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
907 LPITEMIDLIST pidlnew
= NULL
;
909 TRACE_(shell
)("%s\n", debugstr_a(path
));
911 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
916 /*************************************************************************
917 * ILCreateFromPathW [SHELL32.190]
919 * See ILCreateFromPathA.
921 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
923 LPITEMIDLIST pidlnew
= NULL
;
925 TRACE_(shell
)("%s\n", debugstr_w(path
));
927 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
932 /*************************************************************************
933 * ILCreateFromPath [SHELL32.157]
935 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
937 if ( SHELL_OsIsUnicode())
938 return ILCreateFromPathW (path
);
939 return ILCreateFromPathA (path
);
942 /*************************************************************************
943 * _ILParsePathW [internal]
945 * Creates an ItemIDList from a path and returns it.
948 * path [I] path to parse and convert into an ItemIDList
949 * lpFindFile [I] pointer to buffer to initialize the FileSystem
950 * Bind Data object with
951 * bBindCtx [I] indicates to create a BindContext and assign a
952 * FileSystem Bind Data object
953 * ppidl [O] the newly create ItemIDList
954 * prgfInOut [I/O] requested attributes on input and actual
955 * attributes on return
958 * NO_ERROR on success or an OLE error code
961 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
962 * creates a BindContext object and assigns a FileSystem Bind Data object
963 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
964 * IShellFolder uses that FileSystem Bind Data object of the BindContext
965 * to pass data about the current path element to the next object. This
966 * is used to avoid having to verify the current path element on disk, so
967 * that creating an ItemIDList from a nonexistent path still can work.
969 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
970 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
972 LPSHELLFOLDER pSF
= NULL
;
976 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
977 ppidl
, ppidl
? *ppidl
: NULL
,
978 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
980 ret
= SHGetDesktopFolder(&pSF
);
984 if (lpFindFile
|| bBindCtx
)
985 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
989 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
994 IBindCtx_Release(pBC
);
998 IShellFolder_Release(pSF
);
1000 if (FAILED(ret
) && ppidl
)
1003 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1008 /*************************************************************************
1009 * SHSimpleIDListFromPath [SHELL32.162]
1011 * Creates a simple ItemIDList from a path and returns it. This function
1012 * does not fail on nonexistent paths.
1015 * path [I] path to parse and convert into an ItemIDList
1018 * the newly created simple ItemIDList
1021 * Simple in the name does not mean a relative ItemIDList but rather a
1022 * fully qualified list, where only the file name is filled in and the
1023 * directory flag for those ItemID elements this is known about, eg.
1024 * it is not the last element in the ItemIDList or the actual directory
1026 * exported by ordinal.
1028 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1030 LPITEMIDLIST pidl
= NULL
;
1031 LPWSTR wPath
= NULL
;
1034 TRACE("%s\n", debugstr_a(lpszPath
));
1038 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1039 wPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1040 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1043 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1045 HeapFree(GetProcessHeap(), 0, wPath
);
1046 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1050 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1052 LPITEMIDLIST pidl
= NULL
;
1054 TRACE("%s\n", debugstr_w(lpszPath
));
1056 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1057 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1061 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1063 if ( SHELL_OsIsUnicode())
1064 return SHSimpleIDListFromPathW (lpszPath
);
1065 return SHSimpleIDListFromPathA (lpszPath
);
1068 /*************************************************************************
1069 * SHGetDataFromIDListA [SHELL32.247]
1072 * the pidl can be a simple one. since we can't get the path out of the pidl
1073 * we have to take all data from the pidl
1075 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1076 int nFormat
, LPVOID dest
, int len
)
1078 LPSTR filename
, shortname
;
1079 WIN32_FIND_DATAA
* pfd
;
1081 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1085 return E_INVALIDARG
;
1089 case SHGDFIL_FINDDATA
:
1092 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1093 return E_INVALIDARG
;
1095 if (len
< sizeof(WIN32_FIND_DATAA
))
1096 return E_INVALIDARG
;
1098 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1099 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1100 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1101 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1103 filename
= _ILGetTextPointer(pidl
);
1104 shortname
= _ILGetSTextPointer(pidl
);
1107 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1109 pfd
->cFileName
[0] = '\0';
1112 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1114 pfd
->cAlternateFileName
[0] = '\0';
1117 case SHGDFIL_NETRESOURCE
:
1118 case SHGDFIL_DESCRIPTIONID
:
1119 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1123 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1126 return E_INVALIDARG
;
1129 /*************************************************************************
1130 * SHGetDataFromIDListW [SHELL32.248]
1133 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1134 int nFormat
, LPVOID dest
, int len
)
1136 LPSTR filename
, shortname
;
1137 WIN32_FIND_DATAW
* pfd
= dest
;
1139 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1144 return E_INVALIDARG
;
1148 case SHGDFIL_FINDDATA
:
1151 if (_ILIsDrive(pidl
))
1152 return E_INVALIDARG
;
1154 if (len
< sizeof(WIN32_FIND_DATAW
))
1155 return E_INVALIDARG
;
1157 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1158 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1159 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1160 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1162 filename
= _ILGetTextPointer(pidl
);
1163 shortname
= _ILGetSTextPointer(pidl
);
1166 pfd
->cFileName
[0] = '\0';
1167 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1168 pfd
->cFileName
[MAX_PATH
-1] = 0;
1171 pfd
->cAlternateFileName
[0] = '\0';
1172 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1173 pfd
->cAlternateFileName
[13] = 0;
1176 case SHGDFIL_NETRESOURCE
:
1177 case SHGDFIL_DESCRIPTIONID
:
1178 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1182 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1185 return E_INVALIDARG
;
1188 /*************************************************************************
1189 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1193 * pszPath [OUT] path
1196 * path from a passed PIDL.
1199 * NULL returns FALSE
1200 * desktop pidl gives path to desktop directory back
1201 * special pidls returning FALSE
1203 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1205 WCHAR wszPath
[MAX_PATH
];
1208 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1209 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1214 /*************************************************************************
1215 * SHGetPathFromIDListW [SHELL32.@]
1217 * See SHGetPathFromIDListA.
1219 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1222 LPCITEMIDLIST pidlLast
;
1223 LPSHELLFOLDER psfFolder
;
1227 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, pszPath
);
1234 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1235 if (FAILED(hr
)) return FALSE
;
1237 dwAttributes
= SFGAO_FILESYSTEM
;
1238 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1239 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1240 IShellFolder_Release(psfFolder
);
1244 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1245 IShellFolder_Release(psfFolder
);
1246 if (FAILED(hr
)) return FALSE
;
1248 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1250 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(pszPath
), hr
);
1251 return SUCCEEDED(hr
);
1254 /*************************************************************************
1255 * SHBindToParent [shell version 5.0]
1257 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1259 IShellFolder
* psfDesktop
;
1262 TRACE_(shell
)("pidl=%p\n", pidl
);
1266 return E_INVALIDARG
;
1272 hr
= SHGetDesktopFolder(&psfDesktop
);
1276 if (_ILIsPidlSimple(pidl
))
1278 /* we are on desktop level */
1279 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1283 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1284 ILRemoveLastID(pidlParent
);
1285 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1286 SHFree (pidlParent
);
1289 IShellFolder_Release(psfDesktop
);
1291 if (SUCCEEDED(hr
) && ppidlLast
)
1292 *ppidlLast
= ILFindLastID(pidl
);
1294 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1298 /**************************************************************************
1300 * internal functions
1302 * ### 1. section creating pidls ###
1304 *************************************************************************
1307 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1308 * - two bytes are SHITEMID.cb
1309 * - one byte is PIDLDATA.type
1310 * - two bytes are the NULL PIDL terminator
1311 * Sets type of the returned PIDL to type.
1313 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1315 LPITEMIDLIST pidlOut
= NULL
;
1317 pidlOut
= SHAlloc(size
+ 5);
1321 LPITEMIDLIST pidlNext
;
1323 ZeroMemory(pidlOut
, size
+ 5);
1324 pidlOut
->mkid
.cb
= size
+ 3;
1326 pData
= _ILGetDataPointer(pidlOut
);
1330 pidlNext
= ILGetNext(pidlOut
);
1332 pidlNext
->mkid
.cb
= 0x00;
1333 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1339 LPITEMIDLIST
_ILCreateDesktop(void)
1350 LPITEMIDLIST
_ILCreateMyComputer(void)
1353 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1356 LPITEMIDLIST
_ILCreateMyDocuments(void)
1359 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1362 LPITEMIDLIST
_ILCreateIExplore(void)
1365 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1368 LPITEMIDLIST
_ILCreateControlPanel(void)
1370 LPITEMIDLIST ret
= NULL
;
1371 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1377 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_ControlPanel
);
1381 ret
= ILCombine(parent
, printers
);
1388 return _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1391 LPITEMIDLIST
_ILCreatePrinters(void)
1393 return _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1396 LPITEMIDLIST
_ILCreateNetwork(void)
1399 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1402 LPITEMIDLIST
_ILCreateBitBucket(void)
1405 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1408 LPITEMIDLIST
_ILCreateAdminTools(void)
1411 return _ILCreateGuid(PT_GUID
, &CLSID_AdminFolderShortcut
); //FIXME
1414 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1416 LPITEMIDLIST pidlOut
;
1418 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1420 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1423 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1425 pData
->u
.guid
.guid
= *guid
;
1426 TRACE("-- create GUID-pidl %s\n",
1427 debugstr_guid(&(pData
->u
.guid
.guid
)));
1432 WARN("%d: invalid type for GUID\n", type
);
1438 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1442 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1444 ERR("%s is not a GUID\n", szGUID
);
1447 return _ILCreateGuid(PT_GUID
, &iid
);
1450 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1454 if (FAILED(CLSIDFromString((LPOLESTR
)szGUID
, &iid
)))
1456 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1459 return _ILCreateGuid(PT_GUID
, &iid
);
1462 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1464 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1465 DWORD len
, len1
, wlen
, alen
;
1472 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1474 /* prepare buffer with both names */
1475 len
= WideCharToMultiByte(CP_ACP
,0,wfd
->cFileName
,-1,buff
,MAX_PATH
,NULL
,NULL
);
1476 len1
= WideCharToMultiByte(CP_ACP
,0,wfd
->cAlternateFileName
,-1, buff
+len
, sizeof(buff
)-len
, NULL
, NULL
);
1479 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1481 wlen
= wcslen(wfd
->cFileName
) + 1;
1482 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1483 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1486 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1487 FileStruct
*fs
= &pData
->u
.file
;
1491 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1492 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1493 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1494 memcpy(fs
->szNames
, buff
, alen
);
1496 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1497 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1498 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1499 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1500 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1502 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1503 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1504 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1510 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1513 WIN32_FIND_DATAW stffile
;
1516 return E_INVALIDARG
;
1518 hFile
= FindFirstFileW(szPath
, &stffile
);
1519 if (hFile
== INVALID_HANDLE_VALUE
)
1520 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1524 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1526 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1529 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1531 LPITEMIDLIST pidlOut
;
1533 TRACE("(%s)\n",debugstr_w(lpszNew
));
1535 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1540 pszDest
= _ILGetTextPointer(pidlOut
);
1543 strcpy(pszDest
, "x:\\");
1544 pszDest
[0]=towupper(lpszNew
[0]);
1545 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1551 /**************************************************************************
1554 * Gets the text for the drive eg. 'c:\'
1559 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1561 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1563 if(_ILIsMyComputer(pidl
))
1564 pidl
= ILGetNext(pidl
);
1566 if (pidl
&& _ILIsDrive(pidl
))
1567 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1572 /**************************************************************************
1574 * ### 2. section testing pidls ###
1576 **************************************************************************
1580 * _ILIsSpecialFolder()
1586 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1588 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1590 TRACE("(%p)\n",pidl
);
1592 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1595 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1597 TRACE("(%p)\n",pidl
);
1599 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1602 BOOL
_ILIsMyDocuments(LPCITEMIDLIST pidl
)
1604 REFIID iid
= _ILGetGUIDPointer(pidl
);
1606 TRACE("(%p)\n",pidl
);
1609 return IsEqualIID(iid
, &CLSID_MyDocuments
);
1613 BOOL
_ILIsControlPanel(LPCITEMIDLIST pidl
)
1615 REFIID iid
= _ILGetGUIDPointer(pidl
);
1617 TRACE("(%p)\n",pidl
);
1620 return IsEqualIID(iid
, &CLSID_ControlPanel
);
1624 BOOL
_ILIsNetHood(LPCITEMIDLIST pidl
)
1626 REFIID iid
= _ILGetGUIDPointer(pidl
);
1628 TRACE("(%p)\n",pidl
);
1631 return IsEqualIID(iid
, &CLSID_NetworkPlaces
);
1636 LPITEMIDLIST
_ILCreateNetHood(void)
1638 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1641 LPITEMIDLIST
_ILCreateFont(void)
1643 return _ILCreateGuid(PT_GUID
, &CLSID_FontsFolderShortcut
);
1646 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1648 REFIID iid
= _ILGetGUIDPointer(pidl
);
1650 TRACE("(%p)\n",pidl
);
1653 return IsEqualIID(iid
, &CLSID_MyComputer
);
1657 BOOL
_ILIsBitBucket(LPCITEMIDLIST pidl
)
1659 REFIID iid
= _ILGetGUIDPointer(pidl
);
1661 TRACE("(%p)\n",pidl
);
1664 return IsEqualIID(iid
, &CLSID_RecycleBin
);
1668 BOOL
_ILIsAdminTools(LPCITEMIDLIST pidl
)
1670 REFIID iid
= _ILGetGUIDPointer(pidl
);
1672 TRACE("(%p)\n",pidl
);
1675 return IsEqualIID(iid
, &CLSID_AdminFolderShortcut
);
1680 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1682 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1684 TRACE("(%p)\n",pidl
);
1686 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1687 (pidl
&& pidl
->mkid
.cb
== 0x00)
1691 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1693 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1695 TRACE("(%p)\n",pidl
);
1697 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1698 PT_DRIVE1
== lpPData
->type
||
1699 PT_DRIVE2
== lpPData
->type
||
1700 PT_DRIVE3
== lpPData
->type
));
1703 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1705 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1707 TRACE("(%p)\n",pidl
);
1709 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1712 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1714 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1716 TRACE("(%p)\n",pidl
);
1718 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1721 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1723 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1725 TRACE("(%p)\n",pidl
);
1727 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1730 /**************************************************************************
1733 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1737 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1739 WORD len
= pidl
->mkid
.cb
;
1740 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1742 if (pidlnext
->mkid
.cb
)
1746 TRACE("%s\n", ret
? "Yes" : "No");
1750 /**************************************************************************
1752 * ### 3. section getting values from pidls ###
1755 /**************************************************************************
1758 * gets the text for the first item in the pidl (eg. simple pidl)
1760 * returns the length of the string
1762 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1768 char szTemp
[MAX_PATH
];
1770 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1778 if (_ILIsDesktop(pidl
))
1781 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1784 lstrcpynA(szOut
, szTemp
, uOutSize
);
1786 dwReturn
= strlen (szTemp
);
1789 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1793 lstrcpynA(szOut
, szSrc
, uOutSize
);
1795 dwReturn
= strlen(szSrc
);
1797 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1799 /* unicode filesystem */
1800 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1803 lstrcpynA(szOut
, szTemp
, uOutSize
);
1805 dwReturn
= strlen (szTemp
);
1807 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1809 /* special folder */
1810 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1813 lstrcpynA(szOut
, szTemp
, uOutSize
);
1815 dwReturn
= strlen (szTemp
);
1820 ERR("-- no text\n");
1823 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1827 /**************************************************************************
1830 * gets the text for the first item in the pidl (eg. simple pidl)
1832 * returns the length of the string
1834 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1837 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
1839 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1842 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
1843 dwReturn
= wcslen(pFileStructW
->wszName
);
1846 WCHAR szTemp
[MAX_PATH
];
1857 if (_ILIsDesktop(pidl
))
1860 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1863 lstrcpynW(szOut
, szTemp
, uOutSize
);
1865 dwReturn
= wcslen (szTemp
);
1868 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1870 /* unicode filesystem */
1872 lstrcpynW(szOut
, szSrcW
, uOutSize
);
1874 dwReturn
= wcslen(szSrcW
);
1876 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1879 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
1882 lstrcpynW(szOut
, szTemp
, uOutSize
);
1884 dwReturn
= wcslen (szTemp
);
1886 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1888 /* special folder */
1889 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
1892 lstrcpynW(szOut
, szTemp
, uOutSize
);
1894 dwReturn
= wcslen (szTemp
);
1899 ERR("-- no text\n");
1903 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1907 /**************************************************************************
1909 * ### 4. getting pointers to parts of pidls ###
1911 **************************************************************************
1912 * _ILGetDataPointer()
1914 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1916 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1917 return (LPPIDLDATA
)pidl
->mkid
.abID
;
1921 /**************************************************************************
1922 * _ILGetTextPointerW()
1923 * gets a pointer to the unicode long filename string stored in the pidl
1925 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
1927 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1929 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1934 switch (pdata
->type
)
1945 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1953 /*return (LPSTR)&(pdata->u.file.szNames);*/
1959 case PT_NETPROVIDER
:
1961 /*return (LPSTR)&(pdata->u.network.szNames);*/
1965 return (LPWSTR
)pdata
->u
.file
.szNames
;
1971 /**************************************************************************
1972 * _ILGetTextPointer()
1973 * gets a pointer to the long filename string stored in the pidl
1975 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1977 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1979 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1984 switch (pdata
->type
)
1995 return pdata
->u
.drive
.szDriveName
;
2002 return pdata
->u
.file
.szNames
;
2007 case PT_NETPROVIDER
:
2009 return pdata
->u
.network
.szNames
;
2014 /**************************************************************************
2015 * _ILGetSTextPointer()
2016 * gets a pointer to the short filename string stored in the pidl
2018 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2020 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2022 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2027 switch (pdata
->type
)
2033 return pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1;
2036 return pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1;
2041 /**************************************************************************
2042 * _ILGetGUIDPointer()
2044 * returns reference to guid stored in some pidls
2046 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2048 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2050 TRACE("%p\n", pidl
);
2055 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2056 switch (pdata
->type
)
2061 return &(pdata
->u
.guid
.guid
);
2064 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2070 /******************************************************************************
2071 * _ILGetFileStructW [Internal]
2073 * Get pointer the a SHITEMID's FileStructW field if present
2076 * pidl [I] The SHITEMID
2079 * Success: Pointer to pidl's FileStructW field.
2082 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2083 FileStructW
*pFileStructW
;
2086 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2089 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2090 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2092 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2093 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2094 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2095 if (cbOffset
& 0x1 || /* FileStructW member is word aligned in the pidl */
2096 /* FileStructW is positioned after FileStruct */
2097 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2098 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2099 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2100 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2102 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2106 return pFileStructW
;
2109 /*************************************************************************
2110 * _ILGetFileDateTime
2112 * Given the ItemIdList, get the FileTime
2115 * pidl [I] The ItemIDList
2116 * pFt [I] the resulted FILETIME of the file
2119 * True if Successful
2124 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2126 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2131 switch (pdata
->type
)
2135 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2143 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2149 if (_ILGetFileDateTime( pidl
, &ft
))
2151 FileTimeToLocalFileTime(&ft
, &lft
);
2152 FileTimeToSystemTime (&lft
, &time
);
2154 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2157 /* Append space + time without seconds */
2159 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2170 /*************************************************************************
2173 * Given the ItemIdList, get the FileSize
2176 * pidl [I] The ItemIDList
2177 * pOut [I] The buffer to save the result
2178 * uOutsize [I] The size of the buffer
2184 * pOut can be null when no string is needed
2187 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2189 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2195 switch (pdata
->type
)
2198 dwSize
= pdata
->u
.file
.dwFileSize
;
2200 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2208 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2210 char szTemp
[MAX_PATH
];
2211 const char * pPoint
;
2212 LPCITEMIDLIST pidlTemp
=pidl
;
2214 TRACE("pidl=%p\n",pidl
);
2219 pidlTemp
= ILFindLastID(pidl
);
2221 if (!_ILIsValue(pidlTemp
))
2223 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2226 pPoint
= PathFindExtensionA(szTemp
);
2232 lstrcpynA(pOut
, pPoint
, uOutSize
);
2238 /*************************************************************************
2241 * Given the ItemIdList, get the file type description
2244 * pidl [I] The ItemIDList (simple)
2245 * pOut [I] The buffer to save the result
2246 * uOutsize [I] The size of the buffer
2252 * This function copies as much as possible into the buffer.
2254 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2258 if(_ILIsValue(pidl
))
2264 if (_ILGetExtension (pidl
, sType
, 64))
2266 if (HCR_MapTypeToValueA(sType
, sTemp
, 64, TRUE
))
2268 /* retrieve description */
2269 if(HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2272 /* display Ext-file as description */
2273 strcpy(pOut
, sType
);
2275 /* load localized file string */
2277 if(LoadStringA(shell32_hInstance
, IDS_SHV_COLUMN1
, sTemp
, 64))
2281 strcat(pOut
, sTemp
);
2288 LoadStringA(shell32_hInstance
, IDS_DIRECTORY
, pOut
, uOutSize
);
2289 /* make sure its null terminated */
2290 pOut
[uOutSize
-1] = '\0';
2294 /*************************************************************************
2295 * _ILGetFileAttributes
2297 * Given the ItemIdList, get the Attrib string format
2300 * pidl [I] The ItemIDList
2301 * pOut [I] The buffer to save the result
2302 * uOutsize [I] The size of the Buffer
2308 * return value 0 in case of error is a valid return value
2311 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2313 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2324 wAttrib
= pData
->u
.file
.uFileAttribs
;
2331 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2333 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2335 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2337 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2339 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2346 /*************************************************************************
2349 * free a aPidl struct
2351 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2357 for (i
= 0; i
< cidl
; i
++)
2363 /*************************************************************************
2366 * copies an aPidl struct
2368 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2371 LPITEMIDLIST
*apidldest
;
2373 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2377 for (i
= 0; i
< cidl
; i
++)
2378 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2383 /*************************************************************************
2384 * _ILCopyCidaToaPidl
2386 * creates aPidl from CIDA
2388 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2393 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2398 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2400 for (i
= 0; i
< cida
->cidl
; i
++)
2401 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));