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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * a pidl == NULL means desktop and is legal
26 #include "wine/port.h"
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
44 #include "undocshell.h"
45 #include "shell32_main.h"
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
53 WINE_DECLARE_DEBUG_CHANNEL(shell
);
55 /* from comctl32.dll */
56 extern LPVOID WINAPI
Alloc(INT
);
57 extern BOOL WINAPI
Free(LPVOID
);
59 /*************************************************************************
60 * ILGetDisplayNameEx [SHELL32.186]
62 * Retrieves the display name of an ItemIDList
65 * psf [I] Shell Folder to start with, if NULL the desktop is used
66 * pidl [I] ItemIDList relativ to the psf to get the display name for
67 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
68 * type [I] Type of display name to retrieve
69 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
70 * 1 = SHGDN_NORMAL relative to the root folder
71 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
74 * True if the display name could be retrieved successfully, False otherwise
76 BOOL WINAPI
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
79 WCHAR wPath
[MAX_PATH
];
81 TRACE("%p %p %p %ld\n", psf
, pidl
, path
, type
);
86 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
87 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
88 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
93 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
95 LPSHELLFOLDER psfParent
, lsf
= psf
;
96 HRESULT ret
= NO_ERROR
;
97 LPCITEMIDLIST pidllast
;
101 TRACE("%p %p %p %ld\n", psf
, pidl
, path
, type
);
108 ret
= SHGetDesktopFolder(&lsf
);
113 if (type
>= 0 && type
<= 2)
117 case ILGDN_FORPARSING
:
118 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
124 flag
= SHGDN_INFOLDER
;
127 FIXME("Unknown type parameter = %lx\n", type
);
128 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
131 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
133 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
136 ret
= StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
);
141 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
144 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
147 ret
= StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
);
149 IShellFolder_Release(psfParent
);
154 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
157 IShellFolder_Release(lsf
);
158 return SUCCEEDED(ret
);
161 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
163 TRACE_(shell
)("%p %p %p %ld\n", psf
, pidl
, path
, type
);
165 if (SHELL_OsIsUnicode())
166 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
167 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
170 /*************************************************************************
171 * ILGetDisplayName [SHELL32.15]
173 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
175 TRACE_(shell
)("%p %p\n", pidl
, path
);
177 if (SHELL_OsIsUnicode())
178 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
179 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
182 /*************************************************************************
183 * ILFindLastID [SHELL32.16]
186 * observed: pidl=Desktop return=pidl
188 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
190 LPCITEMIDLIST pidlLast
= pidl
;
192 TRACE("(pidl=%p)\n",pidl
);
197 while (pidl
->mkid
.cb
)
200 pidl
= ILGetNext(pidl
);
202 return (LPITEMIDLIST
)pidlLast
;
205 /*************************************************************************
206 * ILRemoveLastID [SHELL32.17]
209 * when pidl=Desktop return=FALSE
211 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
213 TRACE_(shell
)("pidl=%p\n",pidl
);
215 if (!pidl
|| !pidl
->mkid
.cb
)
217 ILFindLastID(pidl
)->mkid
.cb
= 0;
221 /*************************************************************************
222 * ILClone [SHELL32.18]
225 * duplicate an idlist
227 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
230 LPITEMIDLIST newpidl
;
235 len
= ILGetSize(pidl
);
236 newpidl
= (LPITEMIDLIST
)SHAlloc(len
);
238 memcpy(newpidl
,pidl
,len
);
240 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
246 /*************************************************************************
247 * ILCloneFirst [SHELL32.19]
250 * duplicates the first idlist of a complex pidl
252 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
255 LPITEMIDLIST pidlNew
= NULL
;
257 TRACE("pidl=%p \n",pidl
);
263 pidlNew
= (LPITEMIDLIST
) SHAlloc (len
+2);
266 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
269 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
272 TRACE("-- newpidl=%p\n",pidlNew
);
277 /*************************************************************************
278 * ILLoadFromStream (SHELL32.26)
281 * the first two bytes are the len, the pidl is following then
283 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
287 HRESULT ret
= E_FAIL
;
290 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
298 IStream_AddRef (pStream
);
300 if (SUCCEEDED(IStream_Read(pStream
, (LPVOID
)&wLen
, 2, &dwBytesRead
)))
302 TRACE("PIDL length is %d\n", wLen
);
305 *ppPidl
= SHAlloc (wLen
);
306 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
)))
308 TRACE("Stream read OK\n");
313 WARN("reading pidl failed\n");
325 /* we are not yet fully compatible */
326 if (*ppPidl
&& !pcheck(*ppPidl
))
328 WARN("Check failed\n");
333 IStream_Release (pStream
);
338 /*************************************************************************
339 * ILSaveToStream (SHELL32.27)
342 * the first two bytes are the len, the pidl is following then
344 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
348 HRESULT ret
= E_FAIL
;
350 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
352 IStream_AddRef (pStream
);
355 while (pidl
->mkid
.cb
)
357 wLen
+= sizeof(WORD
) + pidl
->mkid
.cb
;
358 pidl
= ILGetNext(pidl
);
361 if (SUCCEEDED(IStream_Write(pStream
, (LPVOID
)&wLen
, 2, NULL
)))
363 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
366 IStream_Release (pStream
);
371 /*************************************************************************
372 * SHILCreateFromPath [SHELL32.28]
374 * Create an ItemIDList from a path
379 * attributes [I/O] requested attributes on call and actual attributes when
380 * the function returns
383 * NO_ERROR if successful, or an OLE errer code otherwise
386 * Wrapper for IShellFolder_ParseDisplayName().
388 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
390 WCHAR lpszDisplayName
[MAX_PATH
];
392 TRACE_(shell
)("%s %p 0x%08lx\n", path
, ppidl
, attributes
? *attributes
: 0);
394 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
395 lpszDisplayName
[MAX_PATH
-1] = 0;
397 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
400 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
404 HRESULT ret
= E_FAIL
;
406 TRACE_(shell
)("%s %p 0x%08lx\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
408 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
410 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
411 IShellFolder_Release(sf
);
416 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
418 if ( SHELL_OsIsUnicode())
419 return SHILCreateFromPathW (path
, ppidl
, attributes
);
420 return SHILCreateFromPathA (path
, ppidl
, attributes
);
423 /*************************************************************************
424 * SHCloneSpecialIDList [SHELL32.89]
426 * Create an ItemIDList to one of the special folders.
430 * nFolder [in] CSIDL_xxxxx
431 * fCreate [in] Create folder if it does not exist
434 * Success: The newly created pidl
435 * Failure: NULL, if inputs are invalid.
438 * exported by ordinal.
439 * Caller is responsible for deallocating the returned ItemIDList with the
440 * shells IMalloc interface, aka ILFree.
442 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
445 TRACE_(shell
)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
448 nFolder
|= CSIDL_FLAG_CREATE
;
450 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
454 /*************************************************************************
455 * ILGlobalClone [SHELL32.20]
457 * Clones an ItemIDList using Alloc.
460 * pidl [I] ItemIDList to clone
463 * Newly allocated ItemIDList.
466 * exported by ordinal.
468 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
471 LPITEMIDLIST newpidl
;
476 len
= ILGetSize(pidl
);
477 newpidl
= (LPITEMIDLIST
)Alloc(len
);
479 memcpy(newpidl
,pidl
,len
);
481 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
487 /*************************************************************************
488 * ILIsEqual [SHELL32.21]
491 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
493 char szData1
[MAX_PATH
];
494 char szData2
[MAX_PATH
];
496 LPCITEMIDLIST pidltemp1
= pidl1
;
497 LPCITEMIDLIST pidltemp2
= pidl2
;
499 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
502 * Explorer reads from registry directly (StreamMRU),
503 * so we can only check here
505 if (!pcheck(pidl1
) || !pcheck (pidl2
))
511 if (!pidl1
|| !pidl2
)
514 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
516 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
517 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
519 if (strcasecmp( szData1
, szData2
))
522 pidltemp1
= ILGetNext(pidltemp1
);
523 pidltemp2
= ILGetNext(pidltemp2
);
526 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
532 /*************************************************************************
533 * ILIsParent [SHELL32.23]
535 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
540 * bImmediate [I] only return true if the parent is the direct parent
544 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
548 * parent = a/b, child = a/b/c -> true, c is in folder a/b
549 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
550 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
552 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
554 char szData1
[MAX_PATH
];
555 char szData2
[MAX_PATH
];
556 LPCITEMIDLIST pParent
= pidlParent
;
557 LPCITEMIDLIST pChild
= pidlChild
;
559 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
561 if (!pParent
|| !pChild
)
564 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
566 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
567 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
569 if (strcasecmp( szData1
, szData2
))
572 pParent
= ILGetNext(pParent
);
573 pChild
= ILGetNext(pChild
);
576 /* child shorter or has equal length to parent */
577 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
580 /* not immediate descent */
581 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
587 /*************************************************************************
588 * ILFindChild [SHELL32.24]
590 * Compares elements from pidl1 and pidl2.
597 * pidl1 is desktop pidl2
598 * pidl1 shorter pidl2 pointer to first different element of pidl2
599 * if there was at least one equal element
600 * pidl2 shorter pidl1 0
601 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
604 * exported by ordinal.
606 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
608 char szData1
[MAX_PATH
];
609 char szData2
[MAX_PATH
];
611 LPCITEMIDLIST pidltemp1
= pidl1
;
612 LPCITEMIDLIST pidltemp2
= pidl2
;
613 LPCITEMIDLIST ret
=NULL
;
615 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
617 /* explorer reads from registry directly (StreamMRU),
618 so we can only check here */
619 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
625 if (_ILIsDesktop(pidl1
))
631 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
633 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
634 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
636 if (strcasecmp(szData1
,szData2
))
639 pidltemp1
= ILGetNext(pidltemp1
);
640 pidltemp2
= ILGetNext(pidltemp2
);
644 if (pidltemp1
->mkid
.cb
)
645 ret
= NULL
; /* elements of pidl1 left*/
647 TRACE_(shell
)("--- %p\n", ret
);
648 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
651 /*************************************************************************
652 * ILCombine [SHELL32.25]
654 * Concatenates two complex ItemIDLists.
657 * pidl1 [I] first complex ItemIDLists
658 * pidl2 [I] complex ItemIDLists to append
661 * if both pidl's == NULL NULL
662 * if pidl1 == NULL cloned pidl2
663 * if pidl2 == NULL cloned pidl1
664 * otherwise new pidl with pidl2 appended to pidl1
667 * exported by ordinal.
668 * Does not destroy the passed in ItemIDLists!
670 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
673 LPITEMIDLIST pidlNew
;
675 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
677 if (!pidl1
&& !pidl2
) return NULL
;
684 pidlNew
= ILClone(pidl2
);
690 pidlNew
= ILClone(pidl1
);
694 len1
= ILGetSize(pidl1
)-2;
695 len2
= ILGetSize(pidl2
);
696 pidlNew
= SHAlloc(len1
+len2
);
700 memcpy(pidlNew
,pidl1
,len1
);
701 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
704 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
708 /*************************************************************************
709 * SHGetRealIDL [SHELL32.98]
713 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
715 IDataObject
* pDataObj
;
718 hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
,
719 &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
725 fmt
.cfFormat
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
727 fmt
.dwAspect
= DVASPECT_CONTENT
;
729 fmt
.tymed
= TYMED_HGLOBAL
;
731 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
733 IDataObject_Release(pDataObj
);
737 /*assert(pida->cidl==1);*/
738 LPIDA pida
= (LPIDA
)GlobalLock(medium
.u
.hGlobal
);
740 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
741 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
743 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
748 GlobalUnlock(medium
.u
.hGlobal
);
749 GlobalFree(medium
.u
.hGlobal
);
756 /*************************************************************************
757 * SHLogILFromFSIL [SHELL32.95]
760 * pild = CSIDL_DESKTOP ret = 0
761 * pild = CSIDL_DRIVES ret = 0
763 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
765 FIXME("(pidl=%p)\n",pidl
);
772 /*************************************************************************
773 * ILGetSize [SHELL32.152]
775 * Gets the byte size of an ItemIDList including zero terminator
778 * pidl [I] ItemIDList
781 * size of pidl in bytes
784 * exported by ordinal
786 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
788 LPCSHITEMID si
= &(pidl
->mkid
);
796 si
= (LPCSHITEMID
)(((const BYTE
*)si
)+si
->cb
);
800 TRACE("pidl=%p size=%u\n",pidl
, len
);
804 /*************************************************************************
805 * ILGetNext [SHELL32.153]
807 * Gets the next ItemID of an ItemIDList
810 * pidl [I] ItemIDList
815 * simple pidl -> pointer to 0x0000 element
818 * exported by ordinal.
820 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
831 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
)+len
);
832 TRACE("-- %p\n", pidl
);
833 return (LPITEMIDLIST
)pidl
;
839 /*************************************************************************
840 * ILAppend [SHELL32.154]
842 * Adds the single ItemID item to the ItemIDList indicated by pidl.
843 * If bEnd is FALSE, inserts the item in the front of the list,
844 * otherwise it adds the item to the end. (???)
847 * pidl [I] ItemIDList to extend
848 * item [I] ItemID to prepend/append
849 * bEnd [I] Indicates if the item should be appended
852 * Destroys the passed in idlist! (???)
854 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
858 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
863 if (_ILIsDesktop(pidl
))
865 idlRet
= ILClone(item
);
872 idlRet
= ILCombine(pidl
, item
);
874 idlRet
= ILCombine(item
, pidl
);
880 /*************************************************************************
881 * ILFree [SHELL32.155]
883 * Frees memory (if not NULL) allocated by SHMalloc allocator
889 * exported by ordinal
891 void WINAPI
ILFree(LPITEMIDLIST pidl
)
893 TRACE("(pidl=%p)\n",pidl
);
898 /*************************************************************************
899 * ILGlobalFree [SHELL32.156]
901 * Frees memory (if not NULL) allocated by Alloc allocator
907 * exported by ordinal.
909 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
917 /*************************************************************************
918 * ILCreateFromPathA [SHELL32.189]
920 * Creates a complex ItemIDList from a path and returns it.
926 * the newly created complex ItemIDList or NULL if failed
929 * exported by ordinal.
931 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
933 LPITEMIDLIST pidlnew
= NULL
;
935 TRACE_(shell
)("%s\n", debugstr_a(path
));
937 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
942 /*************************************************************************
943 * ILCreateFromPathW [SHELL32.190]
945 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
947 LPITEMIDLIST pidlnew
= NULL
;
949 TRACE_(shell
)("%s\n", debugstr_w(path
));
951 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
956 /*************************************************************************
957 * ILCreateFromPath [SHELL32.157]
959 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
961 if ( SHELL_OsIsUnicode())
962 return ILCreateFromPathW (path
);
963 return ILCreateFromPathA (path
);
966 /*************************************************************************
967 * _ILParsePathW [internal]
969 * Creates an ItemIDList from a path and returns it.
972 * path [I] path to parse and convert into an ItemIDList
973 * lpFindFile [I] pointer to buffer to initialize the FileSystem
974 * Bind Data object with
975 * bBindCtx [I] indicates to create a BindContext and assign a
976 * FileSystem Bind Data object
977 * ppidl [O] the newly create ItemIDList
978 * prgfInOut [I/O] requested attributes on input and actual
979 * attributes on return
982 * NO_ERROR on success or an OLE error code
985 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
986 * creates a BindContext object and assigns a FileSystem Bind Data object
987 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
988 * IShellFolder uses that FileSystem Bind Data object of the BindContext
989 * to pass data about the current path element to the next object. This
990 * is used to avoid having to verify the current path element on disk, so
991 * that creating an ItemIDList from a nonexistent path still can work.
993 static HRESULT WINAPI
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
994 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
996 LPSHELLFOLDER pSF
= NULL
;
1000 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
1001 ppidl
, ppidl
? *ppidl
: NULL
,
1002 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
1004 ret
= SHGetDesktopFolder(&pSF
);
1008 if (lpFindFile
|| bBindCtx
)
1009 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
1013 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
1018 IBindCtx_Release(pBC
);
1022 IShellFolder_Release(pSF
);
1024 if (!SUCCEEDED(ret
) && ppidl
)
1027 TRACE("%s %p 0x%lx\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1032 /*************************************************************************
1033 * SHSimpleIDListFromPath [SHELL32.162]
1035 * Creates a simple ItemIDList from a path and returns it. This function
1036 * does not fail on nonexistent paths.
1039 * path [I] path to parse and convert into an ItemIDList
1042 * the newly created simple ItemIDList
1045 * Simple in the name does not mean a relative ItemIDList but rather a
1046 * fully qualified list, where only the file name is filled in and the
1047 * directory flag for those ItemID elements this is known about, eg.
1048 * it is not the last element in the ItemIDList or the actual directory
1050 * exported by ordinal.
1052 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1054 LPITEMIDLIST pidl
= NULL
;
1055 LPWSTR wPath
= NULL
;
1058 TRACE("%s\n", debugstr_a(lpszPath
));
1062 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1063 wPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1064 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1067 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1069 HeapFree(GetProcessHeap(), 0, wPath
);
1070 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1074 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1076 LPITEMIDLIST pidl
= NULL
;
1078 TRACE("%s\n", debugstr_w(lpszPath
));
1080 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1081 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1085 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1087 if ( SHELL_OsIsUnicode())
1088 return SHSimpleIDListFromPathW (lpszPath
);
1089 return SHSimpleIDListFromPathA (lpszPath
);
1092 /*************************************************************************
1093 * SHGetDataFromIDListA [SHELL32.247]
1096 * the pidl can be a simple one. since we can't get the path out of the pidl
1097 * we have to take all data from the pidl
1099 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1100 int nFormat
, LPVOID dest
, int len
)
1102 LPSTR filename
, shortname
;
1103 WIN32_FIND_DATAA
* pfd
;
1105 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1109 return E_INVALIDARG
;
1113 case SHGDFIL_FINDDATA
:
1116 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1117 return E_INVALIDARG
;
1119 if (len
< sizeof(WIN32_FIND_DATAA
))
1120 return E_INVALIDARG
;
1122 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1123 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1124 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1125 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1127 filename
= _ILGetTextPointer(pidl
);
1128 shortname
= _ILGetSTextPointer(pidl
);
1131 lstrcpynA(pfd
->cFileName
, filename
, MAX_PATH
);
1133 pfd
->cFileName
[0] = '\0';
1136 lstrcpynA(pfd
->cAlternateFileName
, shortname
, MAX_PATH
);
1138 pfd
->cAlternateFileName
[0] = '\0';
1141 case SHGDFIL_NETRESOURCE
:
1142 case SHGDFIL_DESCRIPTIONID
:
1143 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1147 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1150 return E_INVALIDARG
;
1153 /*************************************************************************
1154 * SHGetDataFromIDListW [SHELL32.248]
1157 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1158 int nFormat
, LPVOID dest
, int len
)
1160 LPSTR filename
, shortname
;
1161 WIN32_FIND_DATAW
* pfd
= dest
;
1163 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1168 return E_INVALIDARG
;
1172 case SHGDFIL_FINDDATA
:
1175 if (_ILIsDrive(pidl
))
1176 return E_INVALIDARG
;
1178 if (len
< sizeof(WIN32_FIND_DATAW
))
1179 return E_INVALIDARG
;
1181 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1182 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1183 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1184 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1186 filename
= _ILGetTextPointer(pidl
);
1187 shortname
= _ILGetSTextPointer(pidl
);
1190 pfd
->cFileName
[0] = '\0';
1191 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1192 pfd
->cFileName
[MAX_PATH
-1] = 0;
1195 pfd
->cAlternateFileName
[0] = '\0';
1196 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1197 pfd
->cAlternateFileName
[13] = 0;
1200 case SHGDFIL_NETRESOURCE
:
1201 case SHGDFIL_DESCRIPTIONID
:
1202 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1206 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1209 return E_INVALIDARG
;
1212 /*************************************************************************
1213 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1217 * pszPath [OUT] path
1220 * path from a passed PIDL.
1223 * NULL returns FALSE
1224 * desktop pidl gives path to desktop directory back
1225 * special pidls returning FALSE
1227 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1229 WCHAR wszPath
[MAX_PATH
];
1232 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1234 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1239 /*************************************************************************
1240 * SHGetPathFromIDListW [SHELL32.@]
1242 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1245 LPCITEMIDLIST pidlLast
;
1246 LPSHELLFOLDER psfFolder
;
1250 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, debugstr_w(pszPath
));
1256 hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1257 if (FAILED(hr
)) return FALSE
;
1259 dwAttributes
= SFGAO_FILESYSTEM
;
1260 hr
= IShellFolder_GetAttributesOf(psfFolder
, 1, &pidlLast
, &dwAttributes
);
1261 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
)) {
1262 IShellFolder_Release(psfFolder
);
1266 hr
= IShellFolder_GetDisplayNameOf(psfFolder
, pidlLast
, SHGDN_FORPARSING
, &strret
);
1267 IShellFolder_Release(psfFolder
);
1268 if (FAILED(hr
)) return FALSE
;
1270 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1272 TRACE_(shell
)("-- %s, 0x%08lx\n",debugstr_w(pszPath
), hr
);
1273 return SUCCEEDED(hr
);
1276 /*************************************************************************
1277 * SHBindToParent [shell version 5.0]
1279 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1281 IShellFolder
* psfDesktop
;
1284 TRACE_(shell
)("pidl=%p\n", pidl
);
1288 return E_INVALIDARG
;
1294 hr
= SHGetDesktopFolder(&psfDesktop
);
1298 if (_ILIsPidlSimple(pidl
))
1300 /* we are on desktop level */
1301 hr
= IShellFolder_QueryInterface(psfDesktop
, riid
, ppv
);
1305 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1306 ILRemoveLastID(pidlParent
);
1307 hr
= IShellFolder_BindToObject(psfDesktop
, pidlParent
, NULL
, riid
, ppv
);
1308 SHFree (pidlParent
);
1311 IShellFolder_Release(psfDesktop
);
1313 if (SUCCEEDED(hr
) && ppidlLast
)
1314 *ppidlLast
= ILFindLastID(pidl
);
1316 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1320 /**************************************************************************
1322 * internal functions
1324 * ### 1. section creating pidls ###
1326 *************************************************************************
1328 LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1330 LPITEMIDLIST pidlOut
= NULL
;
1332 pidlOut
= SHAlloc(size
+ 5);
1336 LPITEMIDLIST pidlNext
;
1338 ZeroMemory(pidlOut
, size
+ 5);
1339 pidlOut
->mkid
.cb
= size
+ 3;
1341 pData
= _ILGetDataPointer(pidlOut
);
1345 pidlNext
= ILGetNext(pidlOut
);
1347 pidlNext
->mkid
.cb
= 0x00;
1348 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1354 LPITEMIDLIST
_ILCreateDesktop()
1365 LPITEMIDLIST
_ILCreateMyComputer()
1368 return _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
);
1371 LPITEMIDLIST
_ILCreateIExplore()
1374 return _ILCreateGuid(PT_GUID
, &CLSID_Internet
);
1377 LPITEMIDLIST
_ILCreateControlPanel()
1379 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1384 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, &CLSID_ControlPanel
);
1388 ret
= ILCombine(parent
, cpl
);
1396 LPITEMIDLIST
_ILCreatePrinters()
1398 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, &CLSID_MyComputer
), ret
= NULL
;
1403 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, &CLSID_Printers
);
1407 ret
= ILCombine(parent
, printers
);
1415 LPITEMIDLIST
_ILCreateNetwork()
1418 return _ILCreateGuid(PT_GUID
, &CLSID_NetworkPlaces
);
1421 LPITEMIDLIST
_ILCreateBitBucket()
1424 return _ILCreateGuid(PT_GUID
, &CLSID_RecycleBin
);
1427 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1429 LPITEMIDLIST pidlOut
;
1431 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1433 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1436 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1438 memcpy(&(pData
->u
.guid
.guid
), guid
, sizeof(GUID
));
1439 TRACE("-- create GUID-pidl %s\n",
1440 debugstr_guid(&(pData
->u
.guid
.guid
)));
1445 WARN("%d: invalid type for GUID\n", type
);
1451 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1455 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID
, &iid
)))
1457 ERR("%s is not a GUID\n", szGUID
);
1460 return _ILCreateGuid(PT_GUID
, &iid
);
1463 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1467 if (!SUCCEEDED(SHCLSIDFromStringW(szGUID
, &iid
)))
1469 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1472 return _ILCreateGuid(PT_GUID
, &iid
);
1475 LPITEMIDLIST
_ILCreateFromFindDataW( WIN32_FIND_DATAW
*wfd
)
1477 /* FIXME: should make unicode PIDLs */
1478 WIN32_FIND_DATAA fda
;
1480 memset( &fda
, 0, sizeof fda
);
1481 fda
.dwFileAttributes
= wfd
->dwFileAttributes
;
1482 fda
.ftCreationTime
= wfd
->ftCreationTime
;
1483 fda
.ftLastAccessTime
= wfd
->ftLastAccessTime
;
1484 fda
.ftLastWriteTime
= wfd
->ftLastWriteTime
;
1485 fda
.nFileSizeHigh
= wfd
->nFileSizeHigh
;
1486 fda
.nFileSizeLow
= wfd
->nFileSizeLow
;
1487 fda
.dwReserved0
= wfd
->dwReserved0
;
1488 fda
.dwReserved1
= wfd
->dwReserved1
;
1489 WideCharToMultiByte( CP_ACP
, 0, wfd
->cFileName
, -1,
1490 fda
.cFileName
, MAX_PATH
, NULL
, NULL
);
1491 return _ILCreateFromFindDataA( &fda
);
1494 LPITEMIDLIST
_ILCreateFromFindDataA(WIN32_FIND_DATAA
* stffile
)
1496 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1497 char * pbuff
= buff
;
1505 TRACE("(%s, %s)\n",stffile
->cAlternateFileName
, stffile
->cFileName
);
1507 /* prepare buffer with both names */
1508 len
= strlen (stffile
->cFileName
) + 1;
1509 memcpy (pbuff
, stffile
->cFileName
, len
);
1512 len1
= strlen (stffile
->cAlternateFileName
)+1;
1513 memcpy (pbuff
, stffile
->cAlternateFileName
, len1
);
1515 type
= (stffile
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1518 * FileStruct already has one byte for the first name, so use len - 1 in
1521 pidl
= _ILAlloc(type
, sizeof(FileStruct
) + (len
- 1) + len1
);
1527 /* set attributes */
1528 pData
= _ILGetDataPointer(pidl
);
1532 FileTimeToDosDateTime( &(stffile
->ftLastWriteTime
),
1533 &pData
->u
.file
.uFileDate
, &pData
->u
.file
.uFileTime
);
1534 pData
->u
.file
.dwFileSize
= stffile
->nFileSizeLow
;
1535 pData
->u
.file
.uFileAttribs
= (WORD
)stffile
->dwFileAttributes
;
1537 pszDest
= _ILGetTextPointer(pidl
);
1540 memcpy(pszDest
, buff
, len
+ len1
);
1541 TRACE("-- create Value: %s\n",debugstr_a(pszDest
));
1547 HRESULT
_ILCreateFromPathA(LPCSTR szPath
, LPITEMIDLIST
* ppidl
)
1550 WIN32_FIND_DATAA stffile
;
1553 return E_INVALIDARG
;
1555 hFile
= FindFirstFileA(szPath
, &stffile
);
1556 if (hFile
== INVALID_HANDLE_VALUE
)
1557 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1561 *ppidl
= _ILCreateFromFindDataA(&stffile
);
1563 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1566 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1569 WIN32_FIND_DATAW stffile
;
1572 return E_INVALIDARG
;
1574 hFile
= FindFirstFileW(szPath
, &stffile
);
1575 if (hFile
== INVALID_HANDLE_VALUE
)
1576 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1580 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1582 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1585 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1587 LPITEMIDLIST pidlOut
;
1589 TRACE("(%s)\n",debugstr_w(lpszNew
));
1591 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1596 pszDest
= _ILGetTextPointer(pidlOut
);
1599 strcpy(pszDest
, "x:\\");
1600 pszDest
[0]=toupperW(lpszNew
[0]);
1601 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1607 /**************************************************************************
1610 * Gets the text for the drive eg. 'c:\'
1615 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1617 TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1619 if(_ILIsMyComputer(pidl
))
1620 pidl
= ILGetNext(pidl
);
1622 if (pidl
&& _ILIsDrive(pidl
))
1623 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1628 /**************************************************************************
1630 * ### 2. section testing pidls ###
1632 **************************************************************************
1635 * _ILIsSpecialFolder()
1641 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1643 TRACE("(%p)\n",pidl
);
1645 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1648 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1650 REFIID iid
= _ILGetGUIDPointer(pidl
);
1652 TRACE("(%p)\n",pidl
);
1655 return IsEqualIID(iid
, &CLSID_MyComputer
);
1659 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1661 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1663 TRACE("(%p)\n",pidl
);
1665 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1666 (pidl
&& pidl
->mkid
.cb
== 0x00)
1670 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1672 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1674 TRACE("(%p)\n",pidl
);
1676 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1677 PT_DRIVE1
== lpPData
->type
||
1678 PT_DRIVE2
== lpPData
->type
||
1679 PT_DRIVE3
== lpPData
->type
));
1682 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1684 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1686 TRACE("(%p)\n",pidl
);
1688 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1691 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1693 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1695 TRACE("(%p)\n",pidl
);
1697 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1700 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1702 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1704 TRACE("(%p)\n",pidl
);
1706 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1709 /**************************************************************************
1712 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1716 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1718 WORD len
= pidl
->mkid
.cb
;
1719 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1721 if (pidlnext
->mkid
.cb
)
1725 TRACE("%s\n", ret
? "Yes" : "No");
1729 /**************************************************************************
1731 * ### 3. section getting values from pidls ###
1734 /**************************************************************************
1737 * gets the text for the first item in the pidl (eg. simple pidl)
1739 * returns the length of the string
1741 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1746 char szTemp
[MAX_PATH
];
1748 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1756 if (_ILIsDesktop(pidl
))
1759 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1762 lstrcpynA(szOut
, szTemp
, uOutSize
);
1764 dwReturn
= strlen (szTemp
);
1767 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1771 lstrcpynA(szOut
, szSrc
, uOutSize
);
1773 dwReturn
= strlen(szSrc
);
1775 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1777 /* special folder */
1778 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1781 lstrcpynA(szOut
, szTemp
, uOutSize
);
1783 dwReturn
= strlen (szTemp
);
1788 ERR("-- no text\n");
1791 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1795 /**************************************************************************
1798 * gets the text for the first item in the pidl (eg. simple pidl)
1800 * returns the length of the string
1802 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1805 char szTemp
[MAX_PATH
];
1807 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1809 dwReturn
= _ILSimpleGetText(pidl
, szTemp
, uOutSize
);
1811 if (!MultiByteToWideChar(CP_ACP
, 0, szTemp
, -1, szOut
, MAX_PATH
))
1814 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1818 /**************************************************************************
1820 * ### 4. getting pointers to parts of pidls ###
1822 **************************************************************************
1823 * _ILGetDataPointer()
1825 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1827 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1828 return (LPPIDLDATA
) &(pidl
->mkid
.abID
);
1832 /**************************************************************************
1833 * _ILGetTextPointer()
1834 * gets a pointer to the long filename string stored in the pidl
1836 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1838 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1840 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1845 switch (pdata
->type
)
1856 return (LPSTR
)&(pdata
->u
.drive
.szDriveName
);
1863 return (LPSTR
)&(pdata
->u
.file
.szNames
);
1868 case PT_NETPROVIDER
:
1870 return (LPSTR
)&(pdata
->u
.network
.szNames
);
1875 /**************************************************************************
1876 * _ILGetSTextPointer()
1877 * gets a pointer to the short filename string stored in the pidl
1879 LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
1881 /* TRACE(pidl,"(pidl%p)\n", pidl); */
1883 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1888 switch (pdata
->type
)
1894 return (LPSTR
)(pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1);
1897 return (LPSTR
)(pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1);
1902 /**************************************************************************
1903 * _ILGetGUIDPointer()
1905 * returns reference to guid stored in some pidls
1907 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
1909 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
1911 TRACE("%p\n", pidl
);
1916 TRACE("pdata->type 0x%04x\n", pdata
->type
);
1917 switch (pdata
->type
)
1922 return &(pdata
->u
.guid
.guid
);
1925 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
1931 /*************************************************************************
1932 * _ILGetFileDateTime
1934 * Given the ItemIdList, get the FileTime
1937 * pidl [I] The ItemIDList
1938 * pFt [I] the resulted FILETIME of the file
1941 * True if Successful
1946 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
1948 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1953 switch (pdata
->type
)
1957 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
1965 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
1971 if (_ILGetFileDateTime( pidl
, &ft
))
1973 FileTimeToLocalFileTime(&ft
, &lft
);
1974 FileTimeToSystemTime (&lft
, &time
);
1976 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
1979 /* Append space + time without seconds */
1981 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
1992 /*************************************************************************
1995 * Given the ItemIdList, get the FileSize
1998 * pidl [I] The ItemIDList
1999 * pOut [I] The buffer to save the result
2000 * uOutsize [I] The size of the buffer
2006 * pOut can be null when no string is needed
2009 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2011 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2017 switch (pdata
->type
)
2020 dwSize
= pdata
->u
.file
.dwFileSize
;
2022 StrFormatByteSizeA(dwSize
, pOut
, uOutSize
);
2030 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2032 char szTemp
[MAX_PATH
];
2033 const char * pPoint
;
2034 LPCITEMIDLIST pidlTemp
=pidl
;
2036 TRACE("pidl=%p\n",pidl
);
2041 pidlTemp
= ILFindLastID(pidl
);
2043 if (!_ILIsValue(pidlTemp
))
2045 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2048 pPoint
= PathFindExtensionA(szTemp
);
2054 lstrcpynA(pOut
, pPoint
, uOutSize
);
2060 /*************************************************************************
2063 * Given the ItemIdList, get the file type description
2066 * pidl [I] The ItemIDList (simple)
2067 * pOut [I] The buffer to save the result
2068 * uOutsize [I] The size of the buffer
2074 * This function copies as much as possible into the buffer.
2076 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2078 if(_ILIsValue(pidl
))
2084 if (_ILGetExtension (pidl
, sTemp
, 64))
2086 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2087 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
)))
2089 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2090 strcat (pOut
, "-file");
2095 lstrcpynA(pOut
, "Folder", uOutSize
);
2098 /*************************************************************************
2099 * _ILGetFileAttributes
2101 * Given the ItemIdList, get the Attrib string format
2104 * pidl [I] The ItemIDList
2105 * pOut [I] The buffer to save the result
2106 * uOutsize [I] The size of the Buffer
2112 * return value 0 in case of error is a valid return value
2115 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2117 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2128 wAttrib
= pData
->u
.file
.uFileAttribs
;
2135 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2137 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2139 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2141 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2143 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2150 /*************************************************************************
2153 * free a aPidl struct
2155 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2161 for (i
= 0; i
< cidl
; i
++)
2167 /*************************************************************************
2170 * copies an aPidl struct
2172 LPITEMIDLIST
* _ILCopyaPidl(LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2175 LPITEMIDLIST
*apidldest
;
2177 apidldest
= SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2181 for (i
= 0; i
< cidl
; i
++)
2182 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2187 /*************************************************************************
2188 * _ILCopyCidaToaPidl
2190 * creates aPidl from CIDA
2192 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, LPIDA cida
)
2197 dst
= SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2202 *pidl
= ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[0]]));
2204 for (i
= 0; i
< cida
->cidl
; i
++)
2205 dst
[i
] = ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[i
+ 1]]));