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 /*************************************************************************
35 * ILGetDisplayNameEx [SHELL32.186]
37 * Retrieves the display name of an ItemIDList
40 * psf [I] Shell Folder to start with, if NULL the desktop is used
41 * pidl [I] ItemIDList relativ to the psf to get the display name for
42 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
43 * type [I] Type of display name to retrieve
44 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
45 * 1 = SHGDN_NORMAL relative to the root folder
46 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
49 * True if the display name could be retrieved successfully, False otherwise
51 BOOL WINAPI
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
54 WCHAR wPath
[MAX_PATH
];
56 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
61 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
62 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
63 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
68 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
70 LPSHELLFOLDER psfParent
, lsf
= psf
;
71 HRESULT ret
= NO_ERROR
;
72 LPCITEMIDLIST pidllast
;
76 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
83 ret
= SHGetDesktopFolder(&lsf
);
92 case ILGDN_FORPARSING
:
93 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
99 flag
= SHGDN_INFOLDER
;
102 FIXME("Unknown type parameter = %x\n", type
);
103 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
106 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
108 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
111 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
117 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
120 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
123 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
126 IShellFolder_Release(psfParent
);
131 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
134 IShellFolder_Release(lsf
);
135 return SUCCEEDED(ret
);
138 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
140 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
142 if (SHELL_OsIsUnicode())
143 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
144 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
147 /*************************************************************************
148 * ILGetDisplayName [SHELL32.15]
150 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
152 TRACE_(shell
)("%p %p\n", pidl
, path
);
154 if (SHELL_OsIsUnicode())
155 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
156 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
159 /*************************************************************************
160 * ILFindLastID [SHELL32.16]
163 * observed: pidl=Desktop return=pidl
165 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
167 LPCITEMIDLIST pidlLast
= pidl
;
169 TRACE("(pidl=%p)\n",pidl
);
174 while (pidl
->mkid
.cb
)
177 pidl
= ILGetNext(pidl
);
179 return (LPITEMIDLIST
)pidlLast
;
182 /*************************************************************************
183 * ILRemoveLastID [SHELL32.17]
186 * when pidl=Desktop return=FALSE
188 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
190 TRACE_(shell
)("pidl=%p\n",pidl
);
192 if (!pidl
|| !pidl
->mkid
.cb
)
194 ILFindLastID(pidl
)->mkid
.cb
= 0;
198 /*************************************************************************
199 * ILClone [SHELL32.18]
202 * duplicate an idlist
204 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
207 LPITEMIDLIST newpidl
;
212 len
= ILGetSize(pidl
);
213 newpidl
= (LPITEMIDLIST
)SHAlloc(len
);
215 memcpy(newpidl
,pidl
,len
);
217 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
223 /*************************************************************************
224 * ILCloneFirst [SHELL32.19]
227 * duplicates the first idlist of a complex pidl
229 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
232 LPITEMIDLIST pidlNew
= NULL
;
234 TRACE("pidl=%p\n", pidl
);
240 pidlNew
= (LPITEMIDLIST
) SHAlloc (len
+2);
243 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
246 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
249 TRACE("-- newpidl=%p\n",pidlNew
);
254 /*************************************************************************
255 * ILLoadFromStream (SHELL32.26)
258 * the first two bytes are the len, the pidl is following then
260 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
264 HRESULT ret
= E_FAIL
;
267 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
272 IStream_AddRef (pStream
);
274 if (SUCCEEDED(IStream_Read(pStream
, (LPVOID
)&wLen
, 2, &dwBytesRead
)))
276 TRACE("PIDL length is %d\n", wLen
);
279 *ppPidl
= SHAlloc (wLen
);
280 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
282 TRACE("Stream read OK\n");
287 WARN("reading pidl failed\n");
299 /* we are not yet fully compatible */
300 if (*ppPidl
&& !pcheck(*ppPidl
))
302 WARN("Check failed\n");
307 IStream_Release (pStream
);
312 /*************************************************************************
313 * ILSaveToStream (SHELL32.27)
316 * the first two bytes are the len, the pidl is following then
318 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
321 HRESULT ret
= E_FAIL
;
323 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
325 IStream_AddRef (pStream
);
327 wLen
= ILGetSize(pPidl
);
329 if (SUCCEEDED(IStream_Write(pStream
, (LPVOID
)&wLen
, 2, NULL
)))
331 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
334 IStream_Release (pStream
);
339 /*************************************************************************
340 * SHILCreateFromPath [SHELL32.28]
342 * Create an ItemIDList from a path
347 * attributes [I/O] requested attributes on call and actual attributes when
348 * the function returns
351 * NO_ERROR if successful, or an OLE errer code otherwise
354 * Wrapper for IShellFolder_ParseDisplayName().
356 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
358 WCHAR lpszDisplayName
[MAX_PATH
];
360 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
362 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
363 lpszDisplayName
[MAX_PATH
-1] = 0;
365 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
368 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
372 HRESULT ret
= E_FAIL
;
374 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
376 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
378 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
379 IShellFolder_Release(sf
);
384 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
386 if ( SHELL_OsIsUnicode())
387 return SHILCreateFromPathW (path
, ppidl
, attributes
);
388 return SHILCreateFromPathA (path
, ppidl
, attributes
);
391 /*************************************************************************
392 * SHCloneSpecialIDList [SHELL32.89]
394 * Create an ItemIDList to one of the special folders.
398 * nFolder [in] CSIDL_xxxxx
399 * fCreate [in] Create folder if it does not exist
402 * Success: The newly created pidl
403 * Failure: NULL, if inputs are invalid.
406 * exported by ordinal.
407 * Caller is responsible for deallocating the returned ItemIDList with the
408 * shells IMalloc interface, aka ILFree.
410 PIDLIST_ABSOLUTE WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, int nFolder
, BOOL fCreate
)
413 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
416 nFolder
|= CSIDL_FLAG_CREATE
;
418 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
422 /*************************************************************************
423 * ILGlobalClone [SHELL32.20]
425 * Clones an ItemIDList using Alloc.
428 * pidl [I] ItemIDList to clone
431 * Newly allocated ItemIDList.
434 * exported by ordinal.
436 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
439 LPITEMIDLIST newpidl
;
444 len
= ILGetSize(pidl
);
445 newpidl
= (LPITEMIDLIST
)Alloc(len
);
447 memcpy(newpidl
,pidl
,len
);
449 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
455 /*************************************************************************
456 * ILIsEqual [SHELL32.21]
459 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
461 char szData1
[MAX_PATH
];
462 char szData2
[MAX_PATH
];
464 LPCITEMIDLIST pidltemp1
= pidl1
;
465 LPCITEMIDLIST pidltemp2
= pidl2
;
467 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
470 * Explorer reads from registry directly (StreamMRU),
471 * so we can only check here
473 if (!pcheck(pidl1
) || !pcheck (pidl2
))
479 if (!pidl1
|| !pidl2
)
482 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
484 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
485 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
487 if (strcmp( szData1
, szData2
))
490 pidltemp1
= ILGetNext(pidltemp1
);
491 pidltemp2
= ILGetNext(pidltemp2
);
494 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
500 /*************************************************************************
501 * ILIsParent [SHELL32.23]
503 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
508 * bImmediate [I] only return true if the parent is the direct parent
512 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
516 * parent = a/b, child = a/b/c -> true, c is in folder a/b
517 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
518 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
520 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
522 char szData1
[MAX_PATH
];
523 char szData2
[MAX_PATH
];
524 LPCITEMIDLIST pParent
= pidlParent
;
525 LPCITEMIDLIST pChild
= pidlChild
;
527 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
529 if (!pParent
|| !pChild
)
532 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
534 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
535 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
537 if (strcmp( szData1
, szData2
))
540 pParent
= ILGetNext(pParent
);
541 pChild
= ILGetNext(pChild
);
544 /* child shorter or has equal length to parent */
545 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
548 /* not immediate descent */
549 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
555 /*************************************************************************
556 * ILFindChild [SHELL32.24]
558 * Compares elements from pidl1 and pidl2.
565 * pidl1 is desktop pidl2
566 * pidl1 shorter pidl2 pointer to first different element of pidl2
567 * if there was at least one equal element
568 * pidl2 shorter pidl1 0
569 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
572 * exported by ordinal.
574 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
576 char szData1
[MAX_PATH
];
577 char szData2
[MAX_PATH
];
579 LPCITEMIDLIST pidltemp1
= pidl1
;
580 LPCITEMIDLIST pidltemp2
= pidl2
;
581 LPCITEMIDLIST ret
=NULL
;
583 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
585 /* explorer reads from registry directly (StreamMRU),
586 so we can only check here */
587 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
593 if (_ILIsDesktop(pidl1
))
599 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
601 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
602 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
604 if (strcmp(szData1
,szData2
))
607 pidltemp1
= ILGetNext(pidltemp1
);
608 pidltemp2
= ILGetNext(pidltemp2
);
612 if (pidltemp1
->mkid
.cb
)
613 ret
= NULL
; /* elements of pidl1 left*/
615 TRACE_(shell
)("--- %p\n", ret
);
616 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
619 /*************************************************************************
620 * ILCombine [SHELL32.25]
622 * Concatenates two complex ItemIDLists.
625 * pidl1 [I] first complex ItemIDLists
626 * pidl2 [I] complex ItemIDLists to append
629 * if both pidl's == NULL NULL
630 * if pidl1 == NULL cloned pidl2
631 * if pidl2 == NULL cloned pidl1
632 * otherwise new pidl with pidl2 appended to pidl1
635 * exported by ordinal.
636 * Does not destroy the passed in ItemIDLists!
638 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
641 LPITEMIDLIST pidlNew
;
643 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
645 if (!pidl1
&& !pidl2
) return NULL
;
652 pidlNew
= ILClone(pidl2
);
658 pidlNew
= ILClone(pidl1
);
662 len1
= ILGetSize(pidl1
)-2;
663 len2
= ILGetSize(pidl2
);
664 pidlNew
= SHAlloc(len1
+len2
);
668 memcpy(pidlNew
,pidl1
,len1
);
669 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
672 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
676 /*************************************************************************
677 * SHGetRealIDL [SHELL32.98]
681 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
683 IDataObject
* pDataObj
;
686 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
687 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
693 fmt
.cfFormat
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
695 fmt
.dwAspect
= DVASPECT_CONTENT
;
697 fmt
.tymed
= TYMED_HGLOBAL
;
699 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
701 IDataObject_Release(pDataObj
);
705 /*assert(pida->cidl==1);*/
706 LPIDA pida
= (LPIDA
)GlobalLock(medium
.u
.hGlobal
);
708 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
709 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
711 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
716 GlobalUnlock(medium
.u
.hGlobal
);
717 GlobalFree(medium
.u
.hGlobal
);
724 /*************************************************************************
725 * SHLogILFromFSIL [SHELL32.95]
728 * pild = CSIDL_DESKTOP ret = 0
729 * pild = CSIDL_DRIVES ret = 0
731 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
733 FIXME("(pidl=%p)\n",pidl
);
740 /*************************************************************************
741 * ILGetSize [SHELL32.152]
743 * Gets the byte size of an ItemIDList including zero terminator
746 * pidl [I] ItemIDList
749 * size of pidl in bytes
752 * exported by ordinal
754 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
756 LPCSHITEMID si
= &(pidl
->mkid
);
764 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
768 TRACE("pidl=%p size=%u\n",pidl
, len
);
772 /*************************************************************************
773 * ILGetNext [SHELL32.153]
775 * Gets the next ItemID of an ItemIDList
778 * pidl [I] ItemIDList
783 * simple pidl -> pointer to 0x0000 element
786 * exported by ordinal.
788 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
799 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
800 TRACE("-- %p\n", pidl
);
801 return (LPITEMIDLIST
)pidl
;
807 /*************************************************************************
808 * ILAppend [SHELL32.154]
810 * Adds the single ItemID item to the ItemIDList indicated by pidl.
811 * If bEnd is FALSE, inserts the item in the front of the list,
812 * otherwise it adds the item to the end. (???)
815 * pidl [I] ItemIDList to extend
816 * item [I] ItemID to prepend/append
817 * bEnd [I] Indicates if the item should be appended
820 * Destroys the passed in idlist! (???)
822 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
826 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
831 if (_ILIsDesktop(pidl
))
833 idlRet
= ILClone(item
);
839 idlRet
= ILCombine(pidl
, item
);
841 idlRet
= ILCombine(item
, pidl
);
847 /*************************************************************************
848 * ILFree [SHELL32.155]
850 * Frees memory (if not NULL) allocated by SHMalloc allocator
859 * exported by ordinal
861 void WINAPI
ILFree(LPITEMIDLIST pidl
)
863 TRACE("(pidl=%p)\n",pidl
);
867 /*************************************************************************
868 * ILGlobalFree [SHELL32.156]
870 * Frees memory (if not NULL) allocated by Alloc allocator
879 * exported by ordinal.
881 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
888 /*************************************************************************
889 * ILCreateFromPathA [SHELL32.189]
891 * Creates a complex ItemIDList from a path and returns it.
897 * the newly created complex ItemIDList or NULL if failed
900 * exported by ordinal.
902 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
904 LPITEMIDLIST pidlnew
= NULL
;
906 TRACE_(shell
)("%s\n", debugstr_a(path
));
908 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
913 /*************************************************************************
914 * ILCreateFromPathW [SHELL32.190]
916 * See ILCreateFromPathA.
918 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
920 LPITEMIDLIST pidlnew
= NULL
;
922 TRACE_(shell
)("%s\n", debugstr_w(path
));
924 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
929 /*************************************************************************
930 * ILCreateFromPath [SHELL32.157]
932 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
934 if ( SHELL_OsIsUnicode())
935 return ILCreateFromPathW (path
);
936 return ILCreateFromPathA (path
);
939 /*************************************************************************
940 * _ILParsePathW [internal]
942 * Creates an ItemIDList from a path and returns it.
945 * path [I] path to parse and convert into an ItemIDList
946 * lpFindFile [I] pointer to buffer to initialize the FileSystem
947 * Bind Data object with
948 * bBindCtx [I] indicates to create a BindContext and assign a
949 * FileSystem Bind Data object
950 * ppidl [O] the newly create ItemIDList
951 * prgfInOut [I/O] requested attributes on input and actual
952 * attributes on return
955 * NO_ERROR on success or an OLE error code
958 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
959 * creates a BindContext object and assigns a FileSystem Bind Data object
960 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
961 * IShellFolder uses that FileSystem Bind Data object of the BindContext
962 * to pass data about the current path element to the next object. This
963 * is used to avoid having to verify the current path element on disk, so
964 * that creating an ItemIDList from a nonexistent path still can work.
966 static HRESULT WINAPI
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
967 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
969 LPSHELLFOLDER pSF
= NULL
;
973 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
974 ppidl
, ppidl
? *ppidl
: NULL
,
975 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
977 ret
= SHGetDesktopFolder(&pSF
);
981 if (lpFindFile
|| bBindCtx
)
982 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
986 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
991 IBindCtx_Release(pBC
);
995 IShellFolder_Release(pSF
);
997 if (!SUCCEEDED(ret
) && ppidl
)
1000 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1005 /*************************************************************************
1006 * SHSimpleIDListFromPath [SHELL32.162]
1008 * Creates a simple ItemIDList from a path and returns it. This function
1009 * does not fail on nonexistent paths.
1012 * path [I] path to parse and convert into an ItemIDList
1015 * the newly created simple ItemIDList
1018 * Simple in the name does not mean a relative ItemIDList but rather a
1019 * fully qualified list, where only the file name is filled in and the
1020 * directory flag for those ItemID elements this is known about, eg.
1021 * it is not the last element in the ItemIDList or the actual directory
1023 * exported by ordinal.
1025 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1027 LPITEMIDLIST pidl
= NULL
;
1028 LPWSTR wPath
= NULL
;
1031 TRACE("%s\n", debugstr_a(lpszPath
));
1035 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1036 wPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1037 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1040 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1042 HeapFree(GetProcessHeap(), 0, wPath
);
1043 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1047 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1049 LPITEMIDLIST pidl
= NULL
;
1051 TRACE("%s\n", debugstr_w(lpszPath
));
1053 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1054 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1058 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1060 if ( SHELL_OsIsUnicode())
1061 return SHSimpleIDListFromPathW (lpszPath
);
1062 return SHSimpleIDListFromPathA (lpszPath
);
1065 /*************************************************************************
1066 * SHGetDataFromIDListA [SHELL32.247]
1069 * the pidl can be a simple one. since we can't get the path out of the pidl
1070 * we have to take all data from the pidl
1072 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1073 int nFormat
, LPVOID dest
, int len
)
1075 LPSTR filename
, shortname
;
1076 WIN32_FIND_DATAA
* pfd
;
1078 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1082 return E_INVALIDARG
;
1086 case SHGDFIL_FINDDATA
:
1089 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1090 return E_INVALIDARG
;
1092 if (len
< sizeof(WIN32_FIND_DATAA
))
1093 return E_INVALIDARG
;
1095 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1096 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1097 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1098 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1100 filename
= _ILGetTextPointer(pidl
);
1101 shortname
= _ILGetSTextPointer(pidl
);
1104 lstrcpynA(pfd
->cFileName
, filename
, MAX_PATH
);
1106 pfd
->cFileName
[0] = '\0';
1109 lstrcpynA(pfd
->cAlternateFileName
, shortname
, MAX_PATH
);
1111 pfd
->cAlternateFileName
[0] = '\0';
1114 case SHGDFIL_NETRESOURCE
:
1115 case SHGDFIL_DESCRIPTIONID
:
1116 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1120 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1123 return E_INVALIDARG
;
1126 /*************************************************************************
1127 * SHGetDataFromIDListW [SHELL32.248]
1130 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1131 int nFormat
, LPVOID dest
, int len
)
1133 LPSTR filename
, shortname
;
1134 WIN32_FIND_DATAW
* pfd
= dest
;
1136 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1141 return E_INVALIDARG
;
1145 case SHGDFIL_FINDDATA
:
1148 if (_ILIsDrive(pidl
))
1149 return E_INVALIDARG
;
1151 if (len
< sizeof(WIN32_FIND_DATAW
))
1152 return E_INVALIDARG
;
1154 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1155 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1156 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1157 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1159 filename
= _ILGetTextPointer(pidl
);
1160 shortname
= _ILGetSTextPointer(pidl
);
1163 pfd
->cFileName
[0] = '\0';
1164 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1165 pfd
->cFileName
[MAX_PATH
-1] = 0;
1168 pfd
->cAlternateFileName
[0] = '\0';
1169 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1170 pfd
->cAlternateFileName
[13] = 0;
1173 case SHGDFIL_NETRESOURCE
:
1174 case SHGDFIL_DESCRIPTIONID
:
1175 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1179 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1182 return E_INVALIDARG
;
1185 /*************************************************************************
1186 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1190 * pszPath [OUT] path
1193 * path from a passed PIDL.
1196 * NULL returns FALSE
1197 * desktop pidl gives path to desktop directory back
1198 * special pidls returning FALSE
1200 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1202 WCHAR wszPath
[MAX_PATH
];
1205 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1206 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1211 /*************************************************************************
1212 * SHGetPathFromIDListW [SHELL32.@]
1214 * See SHGetPathFromIDListA.
1216 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1219 LPCITEMIDLIST pidlLast
;
1220 LPSHELLFOLDER psfFolder
;
1224 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, pszPath
);
1231 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1232 if (FAILED(hr
)) return FALSE
;
1234 dwAttributes
= SFGAO_FILESYSTEM
;
1235 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1236 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1237 IShellFolder_Release(psfFolder
);
1241 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1242 IShellFolder_Release(psfFolder
);
1243 if (FAILED(hr
)) return FALSE
;
1245 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1247 TRACE_(shell
)("-- %s, 0x%08x\n",debugstr_w(pszPath
), hr
);
1248 return SUCCEEDED(hr
);
1251 /*************************************************************************
1252 * SHBindToParent [shell version 5.0]
1254 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1256 IShellFolder
* psfDesktop
;
1259 TRACE_(shell
)("pidl=%p\n", pidl
);
1263 return E_INVALIDARG
;
1269 hr
= SHGetDesktopFolder(&psfDesktop
);
1273 if (_ILIsPidlSimple(pidl
))
1275 /* we are on desktop level */
1276 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1280 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1281 ILRemoveLastID(pidlParent
);
1282 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1283 SHFree (pidlParent
);
1286 IShellFolder_Release(psfDesktop
);
1288 if (SUCCEEDED(hr
) && ppidlLast
)
1289 *ppidlLast
= ILFindLastID(pidl
);
1291 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1295 /**************************************************************************
1297 * internal functions
1299 * ### 1. section creating pidls ###
1301 *************************************************************************
1303 LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1305 LPITEMIDLIST pidlOut
= NULL
;
1307 pidlOut
= SHAlloc(size
+ 5);
1311 LPITEMIDLIST pidlNext
;
1313 ZeroMemory(pidlOut
, size
+ 5);
1314 pidlOut
->mkid
.cb
= size
+ 3;
1316 pData
= _ILGetDataPointer(pidlOut
);
1320 pidlNext
= ILGetNext(pidlOut
);
1322 pidlNext
->mkid
.cb
= 0x00;
1323 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1329 LPITEMIDLIST
_ILCreateDesktop(void)
1340 LPITEMIDLIST
_ILCreateMyComputer(void)
1343 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1346 LPITEMIDLIST
_ILCreateMyDocuments(void)
1349 return _ILCreateGuid(PT_GUID
, &CLSID_MyDocuments
);
1352 LPITEMIDLIST
_ILCreateIExplore(void)
1355 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1358 LPITEMIDLIST
_ILCreateControlPanel(void)
1360 LPITEMIDLIST ret
= NULL
;
1361 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1367 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_ControlPanel
);
1371 ret
= ILCombine(parent
, printers
);
1378 return _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1381 LPITEMIDLIST
_ILCreatePrinters(void)
1383 return _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1386 LPITEMIDLIST
_ILCreateNetwork(void)
1389 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1392 LPITEMIDLIST
_ILCreateBitBucket(void)
1395 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1398 LPITEMIDLIST
_ILCreateAdminTools(void)
1401 return _ILCreateGuid(PT_GUID
, &CLSID_AdminFolderShortcut
); //FIXME
1404 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1406 LPITEMIDLIST pidlOut
;
1408 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1410 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1413 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1415 memcpy(&(pData
->u
.guid
.guid
), guid
, sizeof(GUID
));
1416 TRACE("-- create GUID-pidl %s\n",
1417 debugstr_guid(&(pData
->u
.guid
.guid
)));
1422 WARN("%d: invalid type for GUID\n", type
);
1428 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1432 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID
, &iid
)))
1434 ERR("%s is not a GUID\n", szGUID
);
1437 return _ILCreateGuid(PT_GUID
, &iid
);
1440 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1444 if (FAILED(CLSIDFromString((LPOLESTR
)szGUID
, &iid
)))
1446 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1449 return _ILCreateGuid(PT_GUID
, &iid
);
1452 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1454 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1455 DWORD len
, len1
, wlen
, alen
;
1462 TRACE("(%s, %s)\n",debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1464 /* prepare buffer with both names */
1465 len
= WideCharToMultiByte(CP_ACP
,0,wfd
->cFileName
,-1,buff
,MAX_PATH
,NULL
,NULL
);
1466 len1
= WideCharToMultiByte(CP_ACP
,0,wfd
->cAlternateFileName
,-1, buff
+len
, sizeof(buff
)-len
, NULL
, NULL
);
1469 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1471 wlen
= wcslen(wfd
->cFileName
) + 1;
1472 pidl
= _ILAlloc(type
, FIELD_OFFSET(FileStruct
, szNames
[alen
+ (alen
& 1)]) +
1473 FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
));
1476 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1477 FileStruct
*fs
= &pData
->u
.file
;
1481 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1482 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1483 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1484 memcpy(fs
->szNames
, buff
, alen
);
1486 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1487 fsw
->cbLen
= FIELD_OFFSET(FileStructW
, wszName
[wlen
]) + sizeof(WORD
);
1488 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1489 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1490 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1492 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1493 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1494 TRACE("-- Set Value: %s\n",debugstr_w(fsw
->wszName
));
1500 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1503 WIN32_FIND_DATAW stffile
;
1506 return E_INVALIDARG
;
1508 hFile
= FindFirstFileW(szPath
, &stffile
);
1509 if (hFile
== INVALID_HANDLE_VALUE
)
1510 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1514 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1516 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1519 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1521 LPITEMIDLIST pidlOut
;
1523 TRACE("(%s)\n",debugstr_w(lpszNew
));
1525 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1530 pszDest
= _ILGetTextPointer(pidlOut
);
1533 strcpy(pszDest
, "x:\\");
1534 pszDest
[0]=towupper(lpszNew
[0]);
1535 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1541 /**************************************************************************
1544 * Gets the text for the drive eg. 'c:\'
1549 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1551 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1553 if(_ILIsMyComputer(pidl
))
1554 pidl
= ILGetNext(pidl
);
1556 if (pidl
&& _ILIsDrive(pidl
))
1557 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1562 /**************************************************************************
1564 * ### 2. section testing pidls ###
1566 **************************************************************************
1570 * _ILIsSpecialFolder()
1576 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1578 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1580 TRACE("(%p)\n",pidl
);
1582 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1585 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1587 TRACE("(%p)\n",pidl
);
1589 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1592 BOOL
_ILIsMyDocuments(LPCITEMIDLIST pidl
)
1594 REFIID iid
= _ILGetGUIDPointer(pidl
);
1596 TRACE("(%p)\n",pidl
);
1599 return IsEqualIID(iid
, &CLSID_MyDocuments
);
1603 BOOL
_ILIsControlPanel(LPCITEMIDLIST pidl
)
1605 REFIID iid
= _ILGetGUIDPointer(pidl
);
1607 TRACE("(%p)\n",pidl
);
1610 return IsEqualIID(iid
, &CLSID_ControlPanel
);
1614 BOOL
_ILIsNetHood(LPCITEMIDLIST pidl
)
1616 REFIID iid
= _ILGetGUIDPointer(pidl
);
1618 TRACE("(%p)\n",pidl
);
1621 return IsEqualIID(iid
, &CLSID_NetworkPlaces
);
1626 LPITEMIDLIST
_ILCreateNetHood(void)
1628 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1631 LPITEMIDLIST
_ILCreateFont(void)
1633 return _ILCreateGuid(PT_GUID
, &CLSID_FontsFolderShortcut
);
1636 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1638 REFIID iid
= _ILGetGUIDPointer(pidl
);
1640 TRACE("(%p)\n",pidl
);
1643 return IsEqualIID(iid
, &CLSID_MyComputer
);
1647 BOOL
_ILIsBitBucket(LPCITEMIDLIST pidl
)
1649 REFIID iid
= _ILGetGUIDPointer(pidl
);
1651 TRACE("(%p)\n",pidl
);
1654 return IsEqualIID(iid
, &CLSID_RecycleBin
);
1658 BOOL
_ILIsAdminTools(LPCITEMIDLIST pidl
)
1660 REFIID iid
= _ILGetGUIDPointer(pidl
);
1662 TRACE("(%p)\n",pidl
);
1665 return IsEqualIID(iid
, &CLSID_AdminFolderShortcut
);
1670 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1672 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1674 TRACE("(%p)\n",pidl
);
1676 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1677 (pidl
&& pidl
->mkid
.cb
== 0x00)
1681 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1683 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1685 TRACE("(%p)\n",pidl
);
1687 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1688 PT_DRIVE1
== lpPData
->type
||
1689 PT_DRIVE2
== lpPData
->type
||
1690 PT_DRIVE3
== lpPData
->type
));
1693 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1695 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1697 TRACE("(%p)\n",pidl
);
1699 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1702 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1704 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1706 TRACE("(%p)\n",pidl
);
1708 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1711 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1713 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1715 TRACE("(%p)\n",pidl
);
1717 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1720 /**************************************************************************
1723 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1727 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1729 WORD len
= pidl
->mkid
.cb
;
1730 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1732 if (pidlnext
->mkid
.cb
)
1736 TRACE("%s\n", ret
? "Yes" : "No");
1740 /**************************************************************************
1742 * ### 3. section getting values from pidls ###
1745 /**************************************************************************
1748 * gets the text for the first item in the pidl (eg. simple pidl)
1750 * returns the length of the string
1752 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1758 char szTemp
[MAX_PATH
];
1760 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1768 if (_ILIsDesktop(pidl
))
1771 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1774 lstrcpynA(szOut
, szTemp
, uOutSize
);
1776 dwReturn
= strlen (szTemp
);
1779 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1783 lstrcpynA(szOut
, szSrc
, uOutSize
);
1785 dwReturn
= strlen(szSrc
);
1787 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1789 /* unicode filesystem */
1790 WideCharToMultiByte(CP_ACP
,0,szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1793 lstrcpynA(szOut
, szTemp
, uOutSize
);
1795 dwReturn
= strlen (szTemp
);
1797 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1799 /* special folder */
1800 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1803 lstrcpynA(szOut
, szTemp
, uOutSize
);
1805 dwReturn
= strlen (szTemp
);
1810 ERR("-- no text\n");
1813 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1817 /**************************************************************************
1820 * gets the text for the first item in the pidl (eg. simple pidl)
1822 * returns the length of the string
1824 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1827 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
1829 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1832 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
1833 dwReturn
= wcslen(pFileStructW
->wszName
);
1836 WCHAR szTemp
[MAX_PATH
];
1847 if (_ILIsDesktop(pidl
))
1850 if (HCR_GetClassNameW(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1853 lstrcpynW(szOut
, szTemp
, uOutSize
);
1855 dwReturn
= wcslen (szTemp
);
1858 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1860 /* unicode filesystem */
1862 lstrcpynW(szOut
, szSrcW
, uOutSize
);
1864 dwReturn
= wcslen(szSrcW
);
1866 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1869 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
1872 lstrcpynW(szOut
, szTemp
, uOutSize
);
1874 dwReturn
= wcslen (szTemp
);
1876 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1878 /* special folder */
1879 if ( HCR_GetClassNameW(riid
, szTemp
, MAX_PATH
) )
1882 lstrcpynW(szOut
, szTemp
, uOutSize
);
1884 dwReturn
= wcslen (szTemp
);
1889 ERR("-- no text\n");
1893 TRACE("-- (%p=%s 0x%08x)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1897 /**************************************************************************
1899 * ### 4. getting pointers to parts of pidls ###
1901 **************************************************************************
1902 * _ILGetDataPointer()
1904 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1906 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1907 return (LPPIDLDATA
) &(pidl
->mkid
.abID
);
1911 /**************************************************************************
1912 * _ILGetTextPointerW()
1913 * gets a pointer to the unicode long filename string stored in the pidl
1915 LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
1917 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1919 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1924 switch (pdata
->type
)
1935 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1943 /*return (LPSTR)&(pdata->u.file.szNames);*/
1949 case PT_NETPROVIDER
:
1951 /*return (LPSTR)&(pdata->u.network.szNames);*/
1955 return (LPWSTR
)&(pdata
->u
.file
.szNames
);
1961 /**************************************************************************
1962 * _ILGetTextPointer()
1963 * gets a pointer to the long filename string stored in the pidl
1965 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1967 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1969 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1974 switch (pdata
->type
)
1985 return (LPSTR
)&(pdata
->u
.drive
.szDriveName
);
1992 return (LPSTR
)&(pdata
->u
.file
.szNames
);
1997 case PT_NETPROVIDER
:
1999 return (LPSTR
)&(pdata
->u
.network
.szNames
);
2004 /**************************************************************************
2005 * _ILGetSTextPointer()
2006 * gets a pointer to the short filename string stored in the pidl
2008 LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2010 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2012 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2017 switch (pdata
->type
)
2023 return (LPSTR
)(pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1);
2026 return (LPSTR
)(pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1);
2031 /**************************************************************************
2032 * _ILGetGUIDPointer()
2034 * returns reference to guid stored in some pidls
2036 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2038 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2040 TRACE("%p\n", pidl
);
2045 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2046 switch (pdata
->type
)
2051 return &(pdata
->u
.guid
.guid
);
2054 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2060 /******************************************************************************
2061 * _ILGetFileStructW [Internal]
2063 * Get pointer the a SHITEMID's FileStructW field if present
2066 * pidl [I] The SHITEMID
2069 * Success: Pointer to pidl's FileStructW field.
2072 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2073 FileStructW
*pFileStructW
;
2076 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2079 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2080 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2082 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2083 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2084 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2085 if (cbOffset
& 0x1 || /* FileStructW member is word aligned in the pidl */
2086 /* FileStructW is positioned after FileStruct */
2087 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2088 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2089 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2090 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2092 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2096 return pFileStructW
;
2099 /*************************************************************************
2100 * _ILGetFileDateTime
2102 * Given the ItemIdList, get the FileTime
2105 * pidl [I] The ItemIDList
2106 * pFt [I] the resulted FILETIME of the file
2109 * True if Successful
2114 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2116 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2121 switch (pdata
->type
)
2125 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2133 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2139 if (_ILGetFileDateTime( pidl
, &ft
))
2141 FileTimeToLocalFileTime(&ft
, &lft
);
2142 FileTimeToSystemTime (&lft
, &time
);
2144 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2147 /* Append space + time without seconds */
2149 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2160 /*************************************************************************
2163 * Given the ItemIdList, get the FileSize
2166 * pidl [I] The ItemIDList
2167 * pOut [I] The buffer to save the result
2168 * uOutsize [I] The size of the buffer
2174 * pOut can be null when no string is needed
2177 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2179 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2185 switch (pdata
->type
)
2188 dwSize
= pdata
->u
.file
.dwFileSize
;
2190 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2198 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2200 char szTemp
[MAX_PATH
];
2201 const char * pPoint
;
2202 LPCITEMIDLIST pidlTemp
=pidl
;
2204 TRACE("pidl=%p\n",pidl
);
2209 pidlTemp
= ILFindLastID(pidl
);
2211 if (!_ILIsValue(pidlTemp
))
2213 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2216 pPoint
= PathFindExtensionA(szTemp
);
2222 lstrcpynA(pOut
, pPoint
, uOutSize
);
2228 /*************************************************************************
2231 * Given the ItemIdList, get the file type description
2234 * pidl [I] The ItemIDList (simple)
2235 * pOut [I] The buffer to save the result
2236 * uOutsize [I] The size of the buffer
2242 * This function copies as much as possible into the buffer.
2244 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2248 if(_ILIsValue(pidl
))
2254 if (_ILGetExtension (pidl
, sType
, 64))
2256 if (HCR_MapTypeToValueA(sType
, sTemp
, 64, TRUE
))
2258 /* retrieve description */
2259 if(HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2262 /* display Ext-file as description */
2263 strcpy(pOut
, sType
);
2265 /* load localized file string */
2267 if(LoadStringA(shell32_hInstance
, IDS_SHV_COLUMN1
, sTemp
, 64))
2271 strcat(pOut
, sTemp
);
2278 LoadStringA(shell32_hInstance
, IDS_DIRECTORY
, pOut
, uOutSize
);
2279 /* make sure its null terminated */
2280 pOut
[uOutSize
-1] = '\0';
2284 /*************************************************************************
2285 * _ILGetFileAttributes
2287 * Given the ItemIdList, get the Attrib string format
2290 * pidl [I] The ItemIDList
2291 * pOut [I] The buffer to save the result
2292 * uOutsize [I] The size of the Buffer
2298 * return value 0 in case of error is a valid return value
2301 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2303 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2314 wAttrib
= pData
->u
.file
.uFileAttribs
;
2321 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2323 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2325 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2327 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2329 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2336 /*************************************************************************
2339 * free a aPidl struct
2341 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2347 for (i
= 0; i
< cidl
; i
++)
2353 /*************************************************************************
2356 * copies an aPidl struct
2358 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2361 LPITEMIDLIST
*apidldest
;
2363 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2367 for (i
= 0; i
< cidl
; i
++)
2368 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2373 /*************************************************************************
2374 * _ILCopyCidaToaPidl
2376 * creates aPidl from CIDA
2378 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2383 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2388 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2390 for (i
= 0; i
< cida
->cidl
; i
++)
2391 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));