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"
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
42 #include "undocshell.h"
43 #include "shell32_main.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(pidl
);
52 WINE_DECLARE_DEBUG_CHANNEL(shell
);
54 /* from comctl32.dll */
55 extern LPVOID WINAPI
Alloc(INT
);
56 extern BOOL WINAPI
Free(LPVOID
);
58 /*************************************************************************
59 * ILGetDisplayNameEx [SHELL32.186]
61 * Retrieves the display name of an ItemIDList
64 * psf [I] Shell Folder to start with, if NULL the desktop is used
65 * pidl [I] ItemIDList relativ to the psf to get the display name for
66 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
67 * type [I] Type of display name to retrieve
68 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
69 * 1 = SHGDN_NORMAL relative to the root folder
70 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
73 * True if the display name could be retrieved successfully, False otherwise
75 BOOL WINAPI
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
78 WCHAR wPath
[MAX_PATH
];
80 TRACE("%p %p %p %ld\n", psf
, pidl
, path
, type
);
85 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
86 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
87 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
92 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
94 LPSHELLFOLDER psfParent
, lsf
= psf
;
95 HRESULT ret
= NO_ERROR
;
96 LPCITEMIDLIST pidllast
;
100 TRACE("%p %p %p %ld\n", psf
, pidl
, path
, type
);
107 ret
= SHGetDesktopFolder(&lsf
);
112 if (type
>= 0 && type
<= 2)
116 case ILGDN_FORPARSING
:
117 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
123 flag
= SHGDN_INFOLDER
;
126 FIXME("Unknown type parameter = %lx\n", type
);
127 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
130 if (!*(LPWORD
)pidl
|| type
== ILGDN_FORPARSING
)
132 ret
= IShellFolder_GetDisplayNameOf(lsf
, pidl
, flag
, &strret
);
135 ret
= StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
);
140 ret
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
143 ret
= IShellFolder_GetDisplayNameOf(psfParent
, pidllast
, flag
, &strret
);
146 ret
= StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
);
148 IShellFolder_Release(psfParent
);
153 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
156 IShellFolder_Release(lsf
);
157 return SUCCEEDED(ret
);
160 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
162 TRACE_(shell
)("%p %p %p %ld\n", psf
, pidl
, path
, type
);
163 if (SHELL_OsIsUnicode())
164 return ILGetDisplayNameExW(psf
, pidl
, path
, type
);
165 return ILGetDisplayNameExA(psf
, pidl
, path
, type
);
168 /*************************************************************************
169 * ILGetDisplayName [SHELL32.15]
171 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
173 TRACE_(shell
)("%p %p\n", pidl
, path
);
174 if (SHELL_OsIsUnicode())
175 return ILGetDisplayNameExW(NULL
, pidl
, path
, ILGDN_FORPARSING
);
176 return ILGetDisplayNameExA(NULL
, pidl
, path
, ILGDN_FORPARSING
);
179 /*************************************************************************
180 * ILFindLastID [SHELL32.16]
183 * observed: pidl=Desktop return=pidl
185 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
186 { LPCITEMIDLIST pidlLast
= pidl
;
188 TRACE("(pidl=%p)\n",pidl
);
190 while (pidl
->mkid
.cb
)
193 pidl
= ILGetNext(pidl
);
195 return (LPITEMIDLIST
)pidlLast
;
197 /*************************************************************************
198 * ILRemoveLastID [SHELL32.17]
201 * when pidl=Desktop return=FALSE
203 BOOL WINAPI
ILRemoveLastID(LPCITEMIDLIST pidl
)
205 TRACE_(shell
)("pidl=%p\n",pidl
);
207 if (!pidl
|| !pidl
->mkid
.cb
)
209 ILFindLastID(pidl
)->mkid
.cb
= 0;
213 /*************************************************************************
214 * ILClone [SHELL32.18]
217 * duplicate an idlist
219 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
221 LPITEMIDLIST newpidl
;
226 len
= ILGetSize(pidl
);
227 newpidl
= (LPITEMIDLIST
)SHAlloc(len
);
229 memcpy(newpidl
,pidl
,len
);
231 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
236 /*************************************************************************
237 * ILCloneFirst [SHELL32.19]
240 * duplicates the first idlist of a complex pidl
242 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
244 LPITEMIDLIST pidlNew
= NULL
;
246 TRACE("pidl=%p \n",pidl
);
252 pidlNew
= (LPITEMIDLIST
) SHAlloc (len
+2);
255 memcpy(pidlNew
,pidl
,len
+2); /* 2 -> mind a desktop pidl */
258 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
261 TRACE("-- newpidl=%p\n",pidlNew
);
266 /*************************************************************************
267 * ILLoadFromStream (SHELL32.26)
270 * the first two bytes are the len, the pidl is following then
272 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
275 HRESULT ret
= E_FAIL
;
278 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
285 IStream_AddRef (pStream
);
287 if (SUCCEEDED(IStream_Read(pStream
, (LPVOID
)&wLen
, 2, &dwBytesRead
)))
289 TRACE("PIDL length is %d\n", wLen
);
291 *ppPidl
= SHAlloc (wLen
);
292 if (SUCCEEDED(IStream_Read(pStream
, *ppPidl
, wLen
, &dwBytesRead
))) {
293 TRACE("Stream read OK\n");
296 WARN("reading pidl failed\n");
306 /* we are not yet fully compatible */
307 if (*ppPidl
&& !pcheck(*ppPidl
))
309 WARN("Check failed\n");
315 IStream_Release (pStream
);
320 /*************************************************************************
321 * ILSaveToStream (SHELL32.27)
324 * the first two bytes are the len, the pidl is following then
326 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
330 HRESULT ret
= E_FAIL
;
332 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
334 IStream_AddRef (pStream
);
337 while (pidl
->mkid
.cb
)
339 wLen
+= sizeof(WORD
) + pidl
->mkid
.cb
;
340 pidl
= ILGetNext(pidl
);
343 if (SUCCEEDED(IStream_Write(pStream
, (LPVOID
)&wLen
, 2, NULL
)))
345 if (SUCCEEDED(IStream_Write(pStream
, pPidl
, wLen
, NULL
)))
349 IStream_Release (pStream
);
354 /*************************************************************************
355 * SHILCreateFromPath [SHELL32.28]
357 * Create an ItemIDList from a path
362 * attributes [I/O] requested attributes on call and actual attributes when
363 * the function returns
366 * NO_ERROR if successful, or an OLE errer code otherwise
369 * Wrapper for IShellFolder_ParseDisplayName().
371 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
374 WCHAR lpszDisplayName
[MAX_PATH
];
376 HRESULT ret
= E_FAIL
;
378 TRACE_(shell
)("%s %p 0x%08lx\n", path
, ppidl
, attributes
? *attributes
: 0);
380 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
381 lpszDisplayName
[MAX_PATH
-1] = 0;
383 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
385 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, lpszDisplayName
, &pchEaten
, ppidl
, attributes
);
386 IShellFolder_Release(sf
);
391 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
395 HRESULT ret
= E_FAIL
;
397 TRACE_(shell
)("%s %p 0x%08lx\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
399 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
401 ret
= IShellFolder_ParseDisplayName(sf
, 0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
402 IShellFolder_Release(sf
);
407 HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
409 if ( SHELL_OsIsUnicode())
410 return SHILCreateFromPathW (path
, ppidl
, attributes
);
411 return SHILCreateFromPathA (path
, ppidl
, attributes
);
414 /*************************************************************************
415 * SHCloneSpecialIDList [SHELL32.89]
417 * Create an ItemIDList to one of the special folders.
421 * nFolder [in] CSIDL_xxxxx
422 * fCreate [in] Create folder if it does not exist
425 * Success: The newly created pidl
426 * Failure: NULL, if inputs are invalid.
429 * exported by ordinal.
430 * Caller is responsible for deallocating the returned ItemIDList with the
431 * shells IMalloc interface, aka ILFree.
433 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, DWORD nFolder
, BOOL fCreate
)
434 { LPITEMIDLIST ppidl
;
435 TRACE_(shell
)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
438 nFolder
|= CSIDL_FLAG_CREATE
;
440 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
444 /*************************************************************************
445 * ILGlobalClone [SHELL32.20]
447 * Clones an ItemIDList using Alloc.
450 * pidl [I] ItemIDList to clone
453 * Newly allocated ItemIDList.
456 * exported by ordinal.
458 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
460 LPITEMIDLIST newpidl
;
465 len
= ILGetSize(pidl
);
466 newpidl
= (LPITEMIDLIST
)Alloc(len
);
468 memcpy(newpidl
,pidl
,len
);
470 TRACE("pidl=%p newpidl=%p\n",pidl
, newpidl
);
476 /*************************************************************************
477 * ILIsEqual [SHELL32.21]
480 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
482 char szData1
[MAX_PATH
];
483 char szData2
[MAX_PATH
];
485 LPCITEMIDLIST pidltemp1
= pidl1
;
486 LPCITEMIDLIST pidltemp2
= pidl2
;
488 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
490 /* explorer reads from registry directly (StreamMRU),
491 so we can only check here */
492 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
))) return FALSE
;
497 if ( (!pidl1
) || (!pidl2
) ) return FALSE
;
499 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
501 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
502 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
504 if (strcasecmp ( szData1
, szData2
)!=0 )
507 pidltemp1
= ILGetNext(pidltemp1
);
508 pidltemp2
= ILGetNext(pidltemp2
);
511 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
518 /*************************************************************************
519 * ILIsParent [SHELL32.23]
521 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
526 * bImmediate [I] only return true if the parent is the direct parent
530 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
534 * parent = a/b, child = a/b/c -> true, c is in folder a/b
535 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
536 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
538 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
540 char szData1
[MAX_PATH
];
541 char szData2
[MAX_PATH
];
543 LPCITEMIDLIST pParent
= pidlParent
;
544 LPCITEMIDLIST pChild
= pidlChild
;
546 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
548 if (!pParent
|| !pChild
) return FALSE
;
550 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
552 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
553 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
555 if (strcasecmp ( szData1
, szData2
)!=0 )
558 pParent
= ILGetNext(pParent
);
559 pChild
= ILGetNext(pChild
);
562 if ( pParent
->mkid
.cb
|| ! pChild
->mkid
.cb
) /* child shorter or has equal length to parent */
565 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
) /* not immediate descent */
571 /*************************************************************************
572 * ILFindChild [SHELL32.24]
574 * Compares elements from pidl1 and pidl2.
581 * pidl1 is desktop pidl2
582 * pidl1 shorter pidl2 pointer to first different element of pidl2
583 * if there was at least one equal element
584 * pidl2 shorter pidl1 0
585 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
588 * exported by ordinal.
590 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
592 char szData1
[MAX_PATH
];
593 char szData2
[MAX_PATH
];
595 LPCITEMIDLIST pidltemp1
= pidl1
;
596 LPCITEMIDLIST pidltemp2
= pidl2
;
597 LPCITEMIDLIST ret
=NULL
;
599 TRACE("pidl1=%p pidl2=%p\n",pidl1
, pidl2
);
601 /* explorer reads from registry directly (StreamMRU),
602 so we can only check here */
603 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
609 if ( _ILIsDesktop(pidl1
) )
615 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
617 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
618 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
620 if (strcasecmp(szData1
,szData2
))
623 pidltemp1
= ILGetNext(pidltemp1
);
624 pidltemp2
= ILGetNext(pidltemp2
);
628 if (pidltemp1
->mkid
.cb
)
630 ret
= NULL
; /* elements of pidl1 left*/
633 TRACE_(shell
)("--- %p\n", ret
);
634 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
637 /*************************************************************************
638 * ILCombine [SHELL32.25]
640 * Concatenates two complex ItemIDLists.
643 * pidl1 [I] first complex ItemIDLists
644 * pidl2 [I] complex ItemIDLists to append
647 * if both pidl's == NULL NULL
648 * if pidl1 == NULL cloned pidl2
649 * if pidl2 == NULL cloned pidl1
650 * otherwise new pidl with pidl2 appended to pidl1
653 * exported by ordinal.
654 * Does not destroy the passed in ItemIDLists!
656 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
659 LPITEMIDLIST pidlNew
;
661 TRACE("pidl=%p pidl=%p\n",pidl1
,pidl2
);
663 if(!pidl1
&& !pidl2
) return NULL
;
670 pidlNew
= ILClone(pidl2
);
676 pidlNew
= ILClone(pidl1
);
680 len1
= ILGetSize(pidl1
)-2;
681 len2
= ILGetSize(pidl2
);
682 pidlNew
= SHAlloc(len1
+len2
);
686 memcpy(pidlNew
,pidl1
,len1
);
687 memcpy(((BYTE
*)pidlNew
)+len1
,pidl2
,len2
);
690 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
694 /*************************************************************************
695 * SHGetRealIDL [SHELL32.98]
699 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
701 IDataObject
* pDataObj
;
702 HRESULT hr
= IShellFolder_GetUIObjectOf(lpsf
, 0, 1, &pidlSimple
, &IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
708 fmt
.cfFormat
= RegisterClipboardFormatA(CFSTR_SHELLIDLIST
);
710 fmt
.dwAspect
= DVASPECT_CONTENT
;
712 fmt
.tymed
= TYMED_HGLOBAL
;
714 hr
= IDataObject_GetData(pDataObj
, &fmt
, &medium
);
716 IDataObject_Release(pDataObj
);
719 /*assert(pida->cidl==1);*/
720 LPIDA pida
= (LPIDA
)GlobalLock(medium
.u
.hGlobal
);
722 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
723 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]);
725 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
730 GlobalUnlock(medium
.u
.hGlobal
);
731 GlobalFree(medium
.u
.hGlobal
);
738 /*************************************************************************
739 * SHLogILFromFSIL [SHELL32.95]
742 * pild = CSIDL_DESKTOP ret = 0
743 * pild = CSIDL_DRIVES ret = 0
745 LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
747 FIXME("(pidl=%p)\n",pidl
);
754 /*************************************************************************
755 * ILGetSize [SHELL32.152]
757 * Gets the byte size of an ItemIDList including zero terminator
760 * pidl [I] ItemIDList
763 * size of pidl in bytes
766 * exported by ordinal
768 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
770 LPCSHITEMID si
= &(pidl
->mkid
);
776 si
= (LPSHITEMID
)(((LPBYTE
)si
)+si
->cb
);
780 TRACE("pidl=%p size=%u\n",pidl
, len
);
784 /*************************************************************************
785 * ILGetNext [SHELL32.153]
787 * Gets the next ItemID of an ItemIDList
790 * pidl [I] ItemIDList
795 * simple pidl -> pointer to 0x0000 element
798 * exported by ordinal.
800 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
811 pidl
= (LPITEMIDLIST
) (((LPBYTE
)pidl
)+len
);
812 TRACE("-- %p\n", pidl
);
813 return (LPITEMIDLIST
)pidl
;
819 /*************************************************************************
820 * ILAppend [SHELL32.154]
822 * Adds the single ItemID item to the ItemIDList indicated by pidl.
823 * If bEnd is FALSE, inserts the item in the front of the list,
824 * otherwise it adds the item to the end. (???)
827 * pidl [I] ItemIDList to extend
828 * item [I] ItemID to prepend/append
829 * bEnd [I] Indicates if the item should be appended
832 * Destroys the passed in idlist! (???)
834 LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
838 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl
,item
,bEnd
);
843 if (_ILIsDesktop(pidl
))
845 idlRet
= ILClone(item
);
853 idlRet
= ILCombine(pidl
, item
);
857 idlRet
= ILCombine(item
, pidl
);
864 /*************************************************************************
865 * ILFree [SHELL32.155]
867 * Frees memory (if not NULL) allocated by SHMalloc allocator
873 * exported by ordinal
875 void WINAPI
ILFree(LPITEMIDLIST pidl
)
877 TRACE("(pidl=%p)\n",pidl
);
878 if(pidl
) SHFree(pidl
);
881 /*************************************************************************
882 * ILGlobalFree [SHELL32.156]
884 * Frees memory (if not NULL) allocated by Alloc allocator
890 * exported by ordinal.
892 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
900 /*************************************************************************
901 * ILCreateFromPathA [SHELL32.189]
903 * Creates a complex ItemIDList from a path and returns it.
909 * the newly created complex ItemIDList or NULL if failed
912 * exported by ordinal.
915 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
917 LPITEMIDLIST pidlnew
= NULL
;
919 TRACE_(shell
)("%s\n", debugstr_a(path
));
921 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
926 /*************************************************************************
927 * ILCreateFromPathW [SHELL32.190]
929 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
931 LPITEMIDLIST pidlnew
= NULL
;
933 TRACE_(shell
)("%s\n", debugstr_w(path
));
935 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
940 /*************************************************************************
941 * ILCreateFromPath [SHELL32.157]
943 LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
945 if ( SHELL_OsIsUnicode())
946 return ILCreateFromPathW (path
);
947 return ILCreateFromPathA (path
);
950 /*************************************************************************
951 * _ILParsePathW [internal]
953 * Creates an ItemIDList from a path and returns it.
956 * path [I] path to parse and convert into an ItemIDList
957 * lpFindFile [I] pointer to buffer to initialize the FileSystem
958 * Bind Data object with
959 * bBindCtx [I] indicates to create a BindContext and assign a
960 * FileSystem Bind Data object
961 * ppidl [O] the newly create ItemIDList
962 * prgfInOut [I/O] requested attributes on input and actual
963 * attributes on return
966 * NO_ERROR on success or an OLE error code
969 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
970 * creates a BindContext object and assigns a FileSystem Bind Data object
971 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
972 * IShellFolder uses that FileSystem Bind Data object of the BindContext
973 * to pass data about the current path element to the next object. This
974 * is used to avoid having to verify the current path element on disk, so
975 * that creating an ItemIDList from a non-existent path still can work.
977 static HRESULT WINAPI
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
978 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
980 LPSHELLFOLDER pSF
= NULL
;
984 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
985 ppidl
, ppidl
? *ppidl
: NULL
,
986 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
988 ret
= SHGetDesktopFolder(&pSF
);
994 if (lpFindFile
|| bBindCtx
)
995 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
999 ret
= IShellFolder_ParseDisplayName(pSF
, 0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
1004 IBindCtx_Release(pBC
);
1008 IShellFolder_Release(pSF
);
1010 if (!SUCCEEDED(ret
) && ppidl
)
1013 TRACE("%s %p 0x%lx\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
1018 /*************************************************************************
1019 * SHSimpleIDListFromPath [SHELL32.162]
1021 * Creates a simple ItemIDList from a path and returns it. This function
1022 * does not fail on non-existent paths.
1025 * path [I] path to parse and convert into an ItemIDList
1028 * the newly created simple ItemIDList
1031 * Simple in the name does not mean a relative ItemIDList but rather a
1032 * fully qualified list, where only the file name is filled in and the
1033 * directory flag for those ItemID elements this is known about, eg.
1034 * it is not the last element in the ItemIDList or the actual directory
1036 * exported by ordinal.
1038 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1040 LPITEMIDLIST pidl
= NULL
;
1041 LPWSTR wPath
= NULL
;
1044 TRACE("%s\n", debugstr_a(lpszPath
));
1048 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1049 wPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1050 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1053 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1055 if (wPath
) HeapFree(GetProcessHeap(), 0, wPath
);
1056 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1060 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1062 LPITEMIDLIST pidl
= NULL
;
1064 TRACE("%s\n", debugstr_w(lpszPath
));
1066 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1067 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1071 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1073 if ( SHELL_OsIsUnicode())
1074 return SHSimpleIDListFromPathW (lpszPath
);
1075 return SHSimpleIDListFromPathA (lpszPath
);
1078 /*************************************************************************
1079 * SHGetSpecialFolderLocation [SHELL32.@]
1081 * gets the folder locations from the registry and creates a pidl
1082 * creates missing reg keys and directories
1086 * nFolder [I] CSIDL_xxxxx
1087 * ppidl [O] PIDL of a special folder
1090 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
1091 * directory. If the directory is missing it returns a x80070002.
1093 HRESULT WINAPI
SHGetSpecialFolderLocation(
1096 LPITEMIDLIST
* ppidl
)
1098 CHAR szPath
[MAX_PATH
];
1099 HRESULT hr
= E_INVALIDARG
;
1101 TRACE_(shell
)("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
1109 *ppidl
= _ILCreateDesktop();
1113 *ppidl
= _ILCreateMyComputer();
1117 *ppidl
= _ILCreateNetwork ();
1120 case CSIDL_CONTROLS
:
1121 *ppidl
= _ILCreateControl ();
1124 case CSIDL_PRINTERS
:
1125 *ppidl
= _ILCreatePrinter ();
1128 case CSIDL_BITBUCKET
:
1129 *ppidl
= _ILCreateBitBucket ();
1133 if (SHGetSpecialFolderPathA(hwndOwner
, szPath
, nFolder
, TRUE
))
1136 TRACE_(shell
)("Value=%s\n",szPath
);
1137 hr
= SHILCreateFromPathA(szPath
, ppidl
, &attributes
);
1140 if(*ppidl
) hr
= NOERROR
;
1143 TRACE_(shell
)("-- (new pidl %p)\n",*ppidl
);
1147 /*************************************************************************
1148 * SHGetFolderLocation [SHELL32.@]
1151 * the pidl can be a simple one. since we cant get the path out of the pidl
1152 * we have to take all data from the pidl
1154 HRESULT WINAPI
SHGetFolderLocation(
1159 LPITEMIDLIST
*ppidl
)
1161 FIXME("%p 0x%08x %p 0x%08lx %p\n",
1162 hwnd
, csidl
, hToken
, dwFlags
, ppidl
);
1163 return SHGetSpecialFolderLocation(hwnd
, csidl
, ppidl
);
1166 /*************************************************************************
1167 * SHGetDataFromIDListA [SHELL32.247]
1170 * the pidl can be a simple one. since we cant get the path out of the pidl
1171 * we have to take all data from the pidl
1173 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, int nFormat
, LPVOID dest
, int len
)
1175 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1178 if (!psf
|| !dest
) return E_INVALIDARG
;
1182 case SHGDFIL_FINDDATA
:
1184 LPSTR filename
, shortname
;
1185 WIN32_FIND_DATAA
* pfd
= dest
;
1187 if (_ILIsDrive(pidl
))
1188 return E_INVALIDARG
;
1190 if (len
< (int)sizeof(WIN32_FIND_DATAA
)) return E_INVALIDARG
;
1192 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1193 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1194 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1195 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1197 filename
= _ILGetTextPointer(pidl
);
1198 shortname
= _ILGetSTextPointer(pidl
);
1201 lstrcpynA(pfd
->cFileName
, filename
, MAX_PATH
);
1203 pfd
->cFileName
[0] = '\0';
1206 lstrcpynA(pfd
->cAlternateFileName
, shortname
, MAX_PATH
);
1208 pfd
->cAlternateFileName
[0] = '\0';
1212 case SHGDFIL_NETRESOURCE
:
1213 case SHGDFIL_DESCRIPTIONID
:
1214 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1218 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1221 return E_INVALIDARG
;
1224 /*************************************************************************
1225 * SHGetDataFromIDListW [SHELL32.248]
1228 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, int nFormat
, LPVOID dest
, int len
)
1230 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf
,pidl
,nFormat
,dest
,len
);
1234 if (! psf
|| !dest
) return E_INVALIDARG
;
1238 case SHGDFIL_FINDDATA
:
1240 LPSTR filename
, shortname
;
1241 WIN32_FIND_DATAW
* pfd
= dest
;
1243 if (_ILIsDrive(pidl
))
1244 return E_INVALIDARG
;
1246 if (len
< (int)sizeof(WIN32_FIND_DATAW
)) return E_INVALIDARG
;
1248 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1249 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1250 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1251 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1253 filename
= _ILGetTextPointer(pidl
);
1254 shortname
= _ILGetSTextPointer(pidl
);
1257 pfd
->cFileName
[0] = '\0';
1258 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1259 pfd
->cFileName
[MAX_PATH
-1] = 0;
1262 pfd
->cAlternateFileName
[0] = '\0';
1263 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1264 pfd
->cAlternateFileName
[13] = 0;
1267 case SHGDFIL_NETRESOURCE
:
1268 case SHGDFIL_DESCRIPTIONID
:
1269 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1273 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1276 return E_INVALIDARG
;
1279 /*************************************************************************
1280 * SHELL_GetPathFromIDListA
1282 HRESULT
SHELL_GetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
, UINT uOutSize
)
1288 /* One case is a PIDL rooted at desktop level */
1289 if (_ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1290 hr
= SHGetSpecialFolderPathA(0, pszPath
, CSIDL_DESKTOP
, FALSE
);
1293 PathAddBackslashA(pszPath
);
1295 /* The only other valid case is a item ID list beginning at "My Computer" */
1296 else if (_ILIsMyComputer(pidl
))
1297 pidl
= ILGetNext(pidl
);
1299 if (SUCCEEDED(hr
)) {
1302 while(pidl
&& pidl
->mkid
.cb
) {
1303 if (_ILIsSpecialFolder(pidl
))
1304 {hr
= E_INVALIDARG
; break;}
1306 txt
= _ILGetTextPointer(pidl
);
1308 {hr
= E_INVALIDARG
; break;}
1310 if (lstrlenA(txt
) > pidl
->mkid
.cb
)
1311 ERR("pidl %p is borked\n",pidl
);
1313 /* make sure there's enough space for the next segment */
1314 if ( (lstrlenA(txt
) + lstrlenA(pszPath
)) > uOutSize
)
1315 {hr
= E_INVALIDARG
; break;}
1316 lstrcatA( pszPath
, txt
);
1318 pidl
= ILGetNext(pidl
);
1320 {hr
= E_INVALIDARG
; break;}
1322 if (!pidl
->mkid
.cb
) {
1323 /* We are at the end and successfully converted the complete PIDL. */
1327 if( (lstrlenA(pszPath
) + 1) > uOutSize
)
1328 {hr
= E_INVALIDARG
; break;}
1329 if (!PathAddBackslashA(pszPath
))
1330 {hr
= E_INVALIDARG
; break;}
1335 TRACE_(shell
)("-- %s, 0x%08lx\n", pszPath
, hr
);
1339 /*************************************************************************
1340 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1344 * pszPath [OUT] path
1347 * path from a passed PIDL.
1350 * NULL returns FALSE
1351 * desktop pidl gives path to desktop directory back
1352 * special pidls returning FALSE
1354 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1358 TRACE_(shell
)("(pidl=%p,%p)\n",pidl
,pszPath
);
1364 hr
= SHELL_GetPathFromIDListA(pidl
, pszPath
, MAX_PATH
);
1366 return SUCCEEDED(hr
);
1369 /*************************************************************************
1370 * SHELL_GetPathFromIDListW
1372 HRESULT
SHELL_GetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
, UINT uOutSize
)
1379 /* One case is a PIDL rooted at desktop level */
1380 if (_ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1381 hr
= SHGetSpecialFolderPathW(0, pszPath
, CSIDL_DESKTOP
, FALSE
);
1384 PathAddBackslashW(pszPath
);
1386 /* The only other valid case is a item ID list beginning at "My Computer" */
1387 else if (_ILIsMyComputer(pidl
))
1388 pidl
= ILGetNext(pidl
);
1390 if (SUCCEEDED(hr
)) {
1393 while(pidl
&& pidl
->mkid
.cb
) {
1394 if (_ILIsSpecialFolder(pidl
))
1395 {hr
= E_INVALIDARG
; break;}
1397 txt
= _ILGetTextPointer(pidl
);
1399 {hr
= E_INVALIDARG
; break;}
1401 if (lstrlenA(txt
) > pidl
->mkid
.cb
)
1402 ERR("pidl %p is borked\n",pidl
);
1403 len
= MultiByteToWideChar(CP_ACP
, 0, txt
, -1, NULL
, 0);
1404 if ( (lstrlenW(pszPath
) + len
) > uOutSize
)
1405 {hr
= E_INVALIDARG
; break;}
1407 MultiByteToWideChar(CP_ACP
, 0, txt
, -1,
1408 &pszPath
[lstrlenW(pszPath
)], len
);
1410 pidl
= ILGetNext(pidl
);
1412 {hr
= E_INVALIDARG
; break;}
1414 if (!pidl
->mkid
.cb
) {
1415 /* We are at the end and successfully converted the complete PIDL. */
1419 if ( (lstrlenW(pszPath
) + 1) > uOutSize
)
1420 {hr
= E_INVALIDARG
; break;}
1421 if (!PathAddBackslashW(pszPath
))
1422 {hr
= E_INVALIDARG
; break;}
1427 TRACE_(shell
)("-- %s, 0x%08lx\n", debugstr_w(pszPath
), hr
);
1431 /*************************************************************************
1432 * SHGetPathFromIDListW [SHELL32.@]
1434 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1438 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, debugstr_w(pszPath
));
1444 hr
= SHELL_GetPathFromIDListW(pidl
, pszPath
, MAX_PATH
);
1446 TRACE_(shell
)("-- %s, 0x%08lx\n",debugstr_w(pszPath
), hr
);
1447 return SUCCEEDED(hr
);
1450 /*************************************************************************
1451 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1453 BOOL WINAPI
SHGetPathFromIDListAW(LPCITEMIDLIST pidl
,LPVOID pszPath
)
1455 TRACE_(shell
)("(pidl=%p,%p)\n",pidl
,pszPath
);
1457 if (SHELL_OsIsUnicode())
1458 return SHGetPathFromIDListW(pidl
,pszPath
);
1459 return SHGetPathFromIDListA(pidl
,pszPath
);
1462 /*************************************************************************
1463 * SHBindToParent [shell version 5.0]
1465 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1468 LPITEMIDLIST pidlChild
, pidlParent
;
1471 TRACE_(shell
)("pidl=%p\n", pidl
);
1475 if (ppidlLast
) *ppidlLast
= NULL
;
1477 if (_ILIsPidlSimple(pidl
))
1479 /* we are on desktop level */
1481 *ppidlLast
= ILClone(pidl
);
1482 hr
= SHGetDesktopFolder((IShellFolder
**)ppv
);
1486 pidlChild
= ILClone(ILFindLastID(pidl
));
1487 pidlParent
= ILClone(pidl
);
1488 ILRemoveLastID(pidlParent
);
1490 hr
= SHGetDesktopFolder(&psf
);
1493 hr
= IShellFolder_BindToObject(psf
, pidlParent
, NULL
, riid
, ppv
);
1495 if (SUCCEEDED(hr
) && ppidlLast
)
1496 *ppidlLast
= pidlChild
;
1500 SHFree (pidlParent
);
1501 if (psf
) IShellFolder_Release(psf
);
1505 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv
, (ppidlLast
)?*ppidlLast
:NULL
, hr
);
1509 /**************************************************************************
1511 * internal functions
1513 * ### 1. section creating pidls ###
1515 *************************************************************************
1516 * _ILCreateDesktop()
1517 * _ILCreateIExplore()
1518 * _ILCreateMyComputer()
1523 LPITEMIDLIST
_ILCreateDesktop()
1525 return _ILCreate(PT_DESKTOP
, NULL
, 0);
1528 LPITEMIDLIST
_ILCreateMyComputer()
1530 return _ILCreate(PT_MYCOMP
, &CLSID_MyComputer
, sizeof(GUID
));
1533 LPITEMIDLIST
_ILCreateIExplore()
1535 return _ILCreate(PT_MYCOMP
, &CLSID_Internet
, sizeof(GUID
));
1538 LPITEMIDLIST
_ILCreateControl()
1540 return _ILCreate(PT_SPECIAL
, &CLSID_ControlPanel
, sizeof(GUID
));
1543 LPITEMIDLIST
_ILCreatePrinter()
1545 return _ILCreate(PT_SPECIAL
, &CLSID_Printers
, sizeof(GUID
));
1548 LPITEMIDLIST
_ILCreateNetwork()
1550 return _ILCreate(PT_MYCOMP
, &CLSID_NetworkPlaces
, sizeof(GUID
));
1553 LPITEMIDLIST
_ILCreateBitBucket()
1555 return _ILCreate(PT_MYCOMP
, &CLSID_RecycleBin
, sizeof(GUID
));
1558 LPITEMIDLIST
_ILCreateDrive( LPCSTR lpszNew
)
1560 lstrcpynA (sTemp
,lpszNew
,4);
1563 TRACE("(%s)\n",sTemp
);
1564 return _ILCreate(PT_DRIVE
,(LPVOID
)&sTemp
[0],4);
1567 LPITEMIDLIST
_ILCreateFolder( WIN32_FIND_DATAA
* stffile
)
1569 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1570 char * pbuff
= buff
;
1574 TRACE("(%s, %s)\n",stffile
->cAlternateFileName
, stffile
->cFileName
);
1576 /* prepare buffer with both names */
1577 len
= strlen (stffile
->cFileName
) + 1;
1578 memcpy (pbuff
, stffile
->cFileName
, len
);
1581 if (stffile
->cAlternateFileName
)
1583 len1
= strlen (stffile
->cAlternateFileName
)+1;
1584 memcpy (pbuff
, stffile
->cAlternateFileName
, len1
);
1592 pidl
= _ILCreate(PT_FOLDER
, (LPVOID
)buff
, len
+ len1
);
1594 /* set attributes */
1598 pData
= _ILGetDataPointer(pidl
);
1599 FileTimeToDosDateTime(&(stffile
->ftLastWriteTime
),&pData
->u
.folder
.uFileDate
,&pData
->u
.folder
.uFileTime
);
1600 pData
->u
.folder
.dwFileSize
= stffile
->nFileSizeLow
;
1601 pData
->u
.folder
.uFileAttribs
= stffile
->dwFileAttributes
;
1607 LPITEMIDLIST
_ILCreateValue(WIN32_FIND_DATAA
* stffile
)
1609 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1610 char * pbuff
= buff
;
1614 TRACE("(%s, %s)\n",stffile
->cAlternateFileName
, stffile
->cFileName
);
1616 /* prepare buffer with both names */
1617 len
= strlen (stffile
->cFileName
) + 1;
1618 memcpy (pbuff
, stffile
->cFileName
, len
);
1621 if (stffile
->cAlternateFileName
)
1623 len1
= strlen (stffile
->cAlternateFileName
)+1;
1624 memcpy (pbuff
, stffile
->cAlternateFileName
, len1
);
1632 pidl
= _ILCreate(PT_VALUE
, (LPVOID
)buff
, len
+ len1
);
1634 /* set attributes */
1638 pData
= _ILGetDataPointer(pidl
);
1639 FileTimeToDosDateTime(&(stffile
->ftLastWriteTime
),&pData
->u
.folder
.uFileDate
,&pData
->u
.folder
.uFileTime
);
1640 pData
->u
.folder
.dwFileSize
= stffile
->nFileSizeLow
;
1641 pData
->u
.folder
.uFileAttribs
=stffile
->dwFileAttributes
;
1647 LPITEMIDLIST
_ILCreateFromPathA(LPCSTR szPath
)
1650 WIN32_FIND_DATAA stffile
;
1651 LPITEMIDLIST pidl
= NULL
;
1653 hFile
= FindFirstFileA(szPath
, &stffile
);
1654 if (hFile
!= INVALID_HANDLE_VALUE
)
1656 if (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
1657 pidl
= _ILCreateFolder(&stffile
);
1659 pidl
= _ILCreateValue(&stffile
);
1665 LPITEMIDLIST
_ILCreateSpecial(LPCSTR szGUID
)
1669 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID
, &iid
)))
1671 ERR("%s is not a GUID\n", szGUID
);
1674 return _ILCreate(PT_MYCOMP
, &iid
, sizeof(IID
));
1677 /**************************************************************************
1679 * Creates a new PIDL
1680 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1682 * uInSize = size of data (raw)
1685 LPITEMIDLIST
_ILCreate(PIDLTYPE type
, LPCVOID pIn
, UINT uInSize
)
1687 LPITEMIDLIST pidlOut
= NULL
, pidlTemp
= NULL
;
1692 TRACE("(0x%02x %p %i)\n",type
,pIn
,uInSize
);
1701 uSize
= 2 + 2 + sizeof(GUID
);
1708 uSize
= 2 + 12 + uInSize
;
1711 FIXME("can't create type: 0x%08x\n",type
);
1715 if(!(pidlOut
= SHAlloc(uSize
+ 2))) return NULL
;
1716 ZeroMemory(pidlOut
, uSize
+ 2);
1717 pidlOut
->mkid
.cb
= uSize
;
1722 TRACE("- create Desktop\n");
1727 pData
= _ILGetDataPointer(pidlOut
);
1729 memcpy(&(pData
->u
.mycomp
.guid
), pIn
, uInSize
);
1730 TRACE("-- create GUID-pidl %s\n", debugstr_guid(&(pData
->u
.mycomp
.guid
)));
1734 pData
= _ILGetDataPointer(pidlOut
);
1736 pszDest
= _ILGetTextPointer(pidlOut
);
1737 memcpy(pszDest
, pIn
, uInSize
);
1738 TRACE("-- create Drive: %s\n",debugstr_a(pszDest
));
1743 pData
= _ILGetDataPointer(pidlOut
);
1745 pszDest
= _ILGetTextPointer(pidlOut
);
1746 memcpy(pszDest
, pIn
, uInSize
);
1747 TRACE("-- create Value: %s\n",debugstr_a(pszDest
));
1751 pidlTemp
= ILGetNext(pidlOut
);
1753 pidlTemp
->mkid
.cb
= 0x00;
1755 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, uSize
);
1759 /**************************************************************************
1762 * Gets the text for the drive eg. 'c:\'
1767 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
,LPSTR pOut
, UINT uSize
)
1768 { TRACE("(%p,%p,%u)\n",pidl
,pOut
,uSize
);
1770 if(_ILIsMyComputer(pidl
))
1771 pidl
= ILGetNext(pidl
);
1773 if (pidl
&& _ILIsDrive(pidl
))
1774 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1779 /**************************************************************************
1781 * ### 2. section testing pidls ###
1783 **************************************************************************
1786 * _ILIsSpecialFolder()
1792 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1793 { TRACE("(%p)\n",pidl
);
1794 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1797 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1799 REFIID iid
= _ILGetGUIDPointer(pidl
);
1801 TRACE("(%p)\n",pidl
);
1804 return IsEqualIID(iid
, &CLSID_MyComputer
);
1808 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1810 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1811 TRACE("(%p)\n",pidl
);
1812 return (pidl
&& ( (lpPData
&& (PT_MYCOMP
== lpPData
->type
|| PT_SPECIAL
== lpPData
->type
)) ||
1813 (pidl
&& pidl
->mkid
.cb
== 0x00)
1817 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1818 { LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1819 TRACE("(%p)\n",pidl
);
1820 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1821 PT_DRIVE1
== lpPData
->type
||
1822 PT_DRIVE2
== lpPData
->type
||
1823 PT_DRIVE3
== lpPData
->type
));
1826 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1827 { LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1828 TRACE("(%p)\n",pidl
);
1829 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1832 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1833 { LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1834 TRACE("(%p)\n",pidl
);
1835 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1838 /**************************************************************************
1841 BOOL
_ILIsPidlSimple ( LPCITEMIDLIST pidl
)
1845 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1847 WORD len
= pidl
->mkid
.cb
;
1848 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((LPBYTE
)pidl
) + len
);
1849 if (pidlnext
->mkid
.cb
)
1853 TRACE("%s\n", ret
? "Yes" : "No");
1857 /**************************************************************************
1859 * ### 3. section getting values from pidls ###
1862 /**************************************************************************
1865 * gets the text for the first item in the pidl (eg. simple pidl)
1867 * returns the length of the string
1869 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1874 char szTemp
[MAX_PATH
];
1876 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1878 if (!pidl
) return 0;
1883 if (_ILIsDesktop(pidl
))
1886 if (HCR_GetClassNameA(&CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1889 lstrcpynA(szOut
, szTemp
, uOutSize
);
1891 dwReturn
= strlen (szTemp
);
1894 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1898 lstrcpynA(szOut
, szSrc
, uOutSize
);
1900 dwReturn
= strlen(szSrc
);
1902 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1904 /* special folder */
1905 if ( HCR_GetClassNameA(riid
, szTemp
, MAX_PATH
) )
1908 lstrcpynA(szOut
, szTemp
, uOutSize
);
1910 dwReturn
= strlen (szTemp
);
1915 ERR("-- no text\n");
1918 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_a(szOut
),dwReturn
);
1922 /**************************************************************************
1925 * gets the text for the first item in the pidl (eg. simple pidl)
1927 * returns the length of the string
1929 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1932 char szTemp
[MAX_PATH
];
1934 TRACE("(%p %p %x)\n",pidl
,szOut
,uOutSize
);
1936 dwReturn
= _ILSimpleGetText(pidl
, szTemp
, uOutSize
);
1938 if (!MultiByteToWideChar(CP_ACP
, 0, szTemp
, -1, szOut
, MAX_PATH
))
1941 TRACE("-- (%p=%s 0x%08lx)\n",szOut
,debugstr_w(szOut
),dwReturn
);
1945 /**************************************************************************
1947 * ### 4. getting pointers to parts of pidls ###
1949 **************************************************************************
1950 * _ILGetDataPointer()
1952 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1954 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1955 return (LPPIDLDATA
) &(pidl
->mkid
.abID
);
1959 /**************************************************************************
1960 * _ILGetTextPointer()
1961 * gets a pointer to the long filename string stored in the pidl
1963 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1964 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1966 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1970 switch (pdata
->type
)
1980 return (LPSTR
)&(pdata
->u
.drive
.szDriveName
);
1988 return (LPSTR
)&(pdata
->u
.file
.szNames
);
1993 case PT_NETPROVIDER
:
1995 return (LPSTR
)&(pdata
->u
.network
.szNames
);
2001 /**************************************************************************
2002 * _ILGetSTextPointer()
2003 * gets a pointer to the short filename string stored in the pidl
2005 LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2006 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
2008 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2012 switch (pdata
->type
)
2019 return (LPSTR
)(pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1);
2022 return (LPSTR
)(pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1);
2028 /**************************************************************************
2029 * _ILGetGUIDPointer()
2031 * returns reference to guid stored in some pidls
2033 REFIID
_ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2035 LPPIDLDATA pdata
=_ILGetDataPointer(pidl
);
2037 TRACE("%p\n", pidl
);
2041 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2042 switch (pdata
->type
)
2046 return (REFIID
) &(pdata
->u
.mycomp
.guid
);
2049 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2056 /*************************************************************************
2057 * _ILGetFileDateTime
2059 * Given the ItemIdList, get the FileTime
2062 * pidl [I] The ItemIDList
2063 * pFt [I] the resulted FILETIME of the file
2066 * True if Successful
2071 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2073 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2075 if(! pdata
) return FALSE
;
2077 switch (pdata
->type
)
2080 DosDateTimeToFileTime(pdata
->u
.folder
.uFileDate
, pdata
->u
.folder
.uFileTime
, pFt
);
2083 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2091 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2097 if (_ILGetFileDateTime( pidl
, &ft
)) {
2098 FileTimeToLocalFileTime(&ft
, &lft
);
2099 FileTimeToSystemTime (&lft
, &time
);
2100 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&time
, NULL
, pOut
, uOutSize
);
2109 /*************************************************************************
2112 * Given the ItemIdList, get the FileSize
2115 * pidl [I] The ItemIDList
2116 * pOut [I] The buffer to save the result
2117 * uOutsize [I] The size of the buffer
2123 * pOut can be null when no string is needed
2126 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2128 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2131 if(! pdata
) return 0;
2133 switch (pdata
->type
)
2136 dwSize
= pdata
->u
.file
.dwFileSize
;
2137 if (pOut
) StrFormatByteSizeA(dwSize
, pOut
, uOutSize
);
2140 if (pOut
) *pOut
= 0x00;
2144 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2146 char szTemp
[MAX_PATH
];
2147 const char * pPoint
;
2148 LPCITEMIDLIST pidlTemp
=pidl
;
2150 TRACE("pidl=%p\n",pidl
);
2152 if (!pidl
) return FALSE
;
2154 pidlTemp
= ILFindLastID(pidl
);
2156 if (!_ILIsValue(pidlTemp
)) return FALSE
;
2157 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
)) return FALSE
;
2159 pPoint
= PathFindExtensionA(szTemp
);
2161 if (! *pPoint
) return FALSE
;
2164 lstrcpynA(pOut
, pPoint
, uOutSize
);
2170 /*************************************************************************
2173 * Given the ItemIdList, get the file type description
2176 * pidl [I] The ItemIDList (simple)
2177 * pOut [I] The buffer to save the result
2178 * uOutsize [I] The size of the buffer
2184 * This function copies as much as possible into the buffer.
2186 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2188 if(_ILIsValue(pidl
))
2195 if (_ILGetExtension (pidl
, sTemp
, 64))
2197 if (!( HCR_MapTypeToValueA(sTemp
, sTemp
, 64, TRUE
)
2198 && HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
)))
2200 lstrcpynA (pOut
, sTemp
, uOutSize
- 6);
2201 strcat (pOut
, "-file");
2207 lstrcpynA(pOut
, "Folder", uOutSize
);
2211 /*************************************************************************
2212 * _ILGetFileAttributes
2214 * Given the ItemIdList, get the Attrib string format
2217 * pidl [I] The ItemIDList
2218 * pOut [I] The buffer to save the result
2219 * uOutsize [I] The size of the Buffer
2225 * return value 0 in case of error is a valid return value
2228 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2230 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2234 if(! pData
) return 0;
2239 wAttrib
= pData
->u
.folder
.uFileAttribs
;
2242 wAttrib
= pData
->u
.file
.uFileAttribs
;
2249 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2253 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2257 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2261 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2265 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2274 /*************************************************************************
2277 * free a aPidl struct
2279 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2285 for (i
= 0; i
< cidl
; i
++) SHFree(apidl
[i
]);
2290 /*************************************************************************
2293 * copies an aPidl struct
2295 LPITEMIDLIST
* _ILCopyaPidl(LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2298 LPITEMIDLIST
* apidldest
= (LPITEMIDLIST
*)SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2299 if(!apidlsrc
) return NULL
;
2301 for (i
= 0; i
< cidl
; i
++)
2302 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2307 /*************************************************************************
2308 * _ILCopyCidaToaPidl
2310 * creates aPidl from CIDA
2312 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, LPIDA cida
)
2315 LPITEMIDLIST
* dst
= (LPITEMIDLIST
*)SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2317 if(!dst
) return NULL
;
2320 *pidl
= ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[0]]));
2322 for (i
= 0; i
< cida
->cidl
; i
++)
2323 dst
[i
] = ILClone((LPITEMIDLIST
)(&((LPBYTE
)cida
)[cida
->aoffset
[i
+ 1]]));