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_C LPVOID WINAPI
Alloc(INT
);
32 EXTERN_C BOOL WINAPI
Free(LPVOID
);
34 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
);
35 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
);
37 /*************************************************************************
38 * ILGetDisplayNameExA [SHELL32.186]
40 * Retrieves the display name of an ItemIDList
43 * psf [I] Shell Folder to start with, if NULL the desktop is used
44 * pidl [I] ItemIDList relative to the psf to get the display name for
45 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
46 * type [I] Type of display name to retrieve
47 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
48 * 1 = SHGDN_NORMAL relative to the root folder
49 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
52 * True if the display name could be retrieved successfully, False otherwise
54 static BOOL
ILGetDisplayNameExA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPSTR path
, DWORD type
)
57 WCHAR wPath
[MAX_PATH
];
59 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
64 ret
= ILGetDisplayNameExW(psf
, pidl
, wPath
, type
);
65 WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
66 TRACE("%p %p %s\n", psf
, pidl
, debugstr_a(path
));
71 BOOL WINAPI
ILGetDisplayNameExW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPWSTR path
, DWORD type
)
73 CComPtr
<IShellFolder
> psfParent
;
74 LPSHELLFOLDER lsf
= psf
;
75 HRESULT ret
= NO_ERROR
;
76 LPCITEMIDLIST pidllast
;
80 TRACE("%p %p %p %d\n", psf
, pidl
, path
, type
);
87 ret
= SHGetDesktopFolder(&lsf
);
96 case ILGDN_FORPARSING
:
97 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
103 flag
= SHGDN_INFOLDER
;
106 FIXME("Unknown type parameter = %x\n", type
);
107 flag
= SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
;
110 if (!*(const WORD
*)pidl
|| type
== ILGDN_FORPARSING
)
112 ret
= lsf
->GetDisplayNameOf(pidl
, flag
, &strret
);
115 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidl
))
121 ret
= SHBindToParent(pidl
, IID_IShellFolder
, (LPVOID
*)&psfParent
, &pidllast
);
124 ret
= psfParent
->GetDisplayNameOf(pidllast
, flag
, &strret
);
127 if(!StrRetToStrNW(path
, MAX_PATH
, &strret
, pidllast
))
134 TRACE("%p %p %s\n", psf
, pidl
, debugstr_w(path
));
138 return SUCCEEDED(ret
);
141 /*************************************************************************
142 * ILGetDisplayNameEx [SHELL32.186]
144 BOOL WINAPI
ILGetDisplayNameEx(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
, LPVOID path
, DWORD type
)
146 TRACE_(shell
)("%p %p %p %d\n", psf
, pidl
, path
, type
);
148 if (SHELL_OsIsUnicode())
149 return ILGetDisplayNameExW(psf
, pidl
, (LPWSTR
)path
, type
);
150 return ILGetDisplayNameExA(psf
, pidl
, (LPSTR
)path
, type
);
153 /*************************************************************************
154 * ILGetDisplayName [SHELL32.15]
156 BOOL WINAPI
ILGetDisplayName(LPCITEMIDLIST pidl
, LPVOID path
)
158 TRACE_(shell
)("%p %p\n", pidl
, path
);
160 if (SHELL_OsIsUnicode())
161 return ILGetDisplayNameExW(NULL
, pidl
, (LPWSTR
)path
, ILGDN_FORPARSING
);
162 return ILGetDisplayNameExA(NULL
, pidl
, (LPSTR
)path
, ILGDN_FORPARSING
);
165 /*************************************************************************
166 * ILFindLastID [SHELL32.16]
169 * observed: pidl=Desktop return=pidl
171 LPITEMIDLIST WINAPI
ILFindLastID(LPCITEMIDLIST pidl
)
173 LPCITEMIDLIST pidlLast
= pidl
;
175 TRACE("(pidl=%p)\n", pidl
);
180 while (pidl
->mkid
.cb
)
183 pidl
= ILGetNext(pidl
);
185 return (LPITEMIDLIST
)pidlLast
;
188 /*************************************************************************
189 * ILRemoveLastID [SHELL32.17]
192 * when pidl=Desktop return=FALSE
194 BOOL WINAPI
ILRemoveLastID(LPITEMIDLIST pidl
)
196 TRACE_(shell
)("pidl=%p\n", pidl
);
198 if (!pidl
|| !pidl
->mkid
.cb
)
200 ILFindLastID(pidl
)->mkid
.cb
= 0;
204 /*************************************************************************
205 * ILClone [SHELL32.18]
208 * duplicate an idlist
210 LPITEMIDLIST WINAPI
ILClone (LPCITEMIDLIST pidl
)
213 LPITEMIDLIST newpidl
;
218 len
= ILGetSize(pidl
);
219 newpidl
= (LPITEMIDLIST
)SHAlloc(len
);
221 memcpy(newpidl
, pidl
, len
);
223 TRACE("pidl=%p newpidl=%p\n", pidl
, newpidl
);
229 /*************************************************************************
230 * ILCloneFirst [SHELL32.19]
233 * duplicates the first idlist of a complex pidl
235 LPITEMIDLIST WINAPI
ILCloneFirst(LPCITEMIDLIST pidl
)
238 LPITEMIDLIST pidlNew
= NULL
;
240 TRACE("pidl=%p\n", pidl
);
246 pidlNew
= (LPITEMIDLIST
)SHAlloc(len
+ 2);
249 memcpy(pidlNew
, pidl
, len
+ 2); /* 2 -> mind a desktop pidl */
252 ILGetNext(pidlNew
)->mkid
.cb
= 0x00;
255 TRACE("-- newpidl=%p\n", pidlNew
);
260 /*************************************************************************
261 * ILLoadFromStream (SHELL32.26)
264 * the first two bytes are the len, the pidl is following then
266 HRESULT WINAPI
ILLoadFromStream (IStream
* pStream
, LPITEMIDLIST
* ppPidl
)
270 HRESULT ret
= E_FAIL
;
273 TRACE_(shell
)("%p %p\n", pStream
, ppPidl
);
280 if (SUCCEEDED(pStream
->Read(&wLen
, 2, &dwBytesRead
)))
282 TRACE("PIDL length is %d\n", wLen
);
285 *ppPidl
= (LPITEMIDLIST
)SHAlloc(wLen
);
286 if (SUCCEEDED(pStream
->Read(*ppPidl
, wLen
, &dwBytesRead
)))
288 TRACE("Stream read OK\n");
293 WARN("reading pidl failed\n");
305 /* we are not yet fully compatible */
306 if (*ppPidl
&& !pcheck(*ppPidl
))
308 WARN("Check failed\n");
318 /*************************************************************************
319 * ILSaveToStream (SHELL32.27)
322 * the first two bytes are the len, the pidl is following then
324 HRESULT WINAPI
ILSaveToStream (IStream
* pStream
, LPCITEMIDLIST pPidl
)
327 HRESULT ret
= E_FAIL
;
329 TRACE_(shell
)("%p %p\n", pStream
, pPidl
);
333 wLen
= ILGetSize(pPidl
);
335 if (SUCCEEDED(pStream
->Write(&wLen
, 2, NULL
)))
337 if (SUCCEEDED(pStream
->Write(pPidl
, wLen
, NULL
)))
345 /*************************************************************************
346 * SHILCreateFromPath [SHELL32.28]
348 * Create an ItemIDList from a path
353 * attributes [I/O] requested attributes on call and actual attributes when
354 * the function returns
357 * NO_ERROR if successful, or an OLE errer code otherwise
360 * Wrapper for IShellFolder_ParseDisplayName().
362 HRESULT WINAPI
SHILCreateFromPathA(LPCSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
364 WCHAR lpszDisplayName
[MAX_PATH
];
366 TRACE_(shell
)("%s %p 0x%08x\n", path
, ppidl
, attributes
? *attributes
: 0);
368 if (!MultiByteToWideChar(CP_ACP
, 0, path
, -1, lpszDisplayName
, MAX_PATH
))
369 lpszDisplayName
[MAX_PATH
-1] = 0;
371 return SHILCreateFromPathW(lpszDisplayName
, ppidl
, attributes
);
374 HRESULT WINAPI
SHILCreateFromPathW(LPCWSTR path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
376 CComPtr
<IShellFolder
> sf
;
378 HRESULT ret
= E_FAIL
;
380 TRACE_(shell
)("%s %p 0x%08x\n", debugstr_w(path
), ppidl
, attributes
? *attributes
: 0);
382 if (SUCCEEDED (SHGetDesktopFolder(&sf
)))
383 ret
= sf
->ParseDisplayName(0, NULL
, (LPWSTR
)path
, &pchEaten
, ppidl
, attributes
);
387 EXTERN_C HRESULT WINAPI
SHILCreateFromPathAW (LPCVOID path
, LPITEMIDLIST
* ppidl
, DWORD
* attributes
)
389 if ( SHELL_OsIsUnicode())
390 return SHILCreateFromPathW ((LPCWSTR
)path
, ppidl
, attributes
);
391 return SHILCreateFromPathA ((LPCSTR
)path
, ppidl
, attributes
);
394 /*************************************************************************
395 * SHCloneSpecialIDList [SHELL32.89]
397 * Create an ItemIDList to one of the special folders.
401 * nFolder [in] CSIDL_xxxxx
402 * fCreate [in] Create folder if it does not exist
405 * Success: The newly created pidl
406 * Failure: NULL, if inputs are invalid.
409 * exported by ordinal.
410 * Caller is responsible for deallocating the returned ItemIDList with the
411 * shells IMalloc interface, aka ILFree.
413 LPITEMIDLIST WINAPI
SHCloneSpecialIDList(HWND hwndOwner
, int nFolder
, BOOL fCreate
)
416 TRACE_(shell
)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner
, nFolder
, fCreate
? "T" : "F");
419 nFolder
|= CSIDL_FLAG_CREATE
;
421 SHGetSpecialFolderLocation(hwndOwner
, nFolder
, &ppidl
);
425 /*************************************************************************
426 * ILGlobalClone [SHELL32.20]
428 * Clones an ItemIDList using Alloc.
431 * pidl [I] ItemIDList to clone
434 * Newly allocated ItemIDList.
437 * exported by ordinal.
439 LPITEMIDLIST WINAPI
ILGlobalClone(LPCITEMIDLIST pidl
)
442 LPITEMIDLIST newpidl
;
447 len
= ILGetSize(pidl
);
448 newpidl
= (LPITEMIDLIST
)Alloc(len
);
450 memcpy(newpidl
, pidl
, len
);
452 TRACE("pidl=%p newpidl=%p\n", pidl
, newpidl
);
458 /*************************************************************************
459 * ILIsEqual [SHELL32.21]
462 BOOL WINAPI
ILIsEqual(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
464 char szData1
[MAX_PATH
];
465 char szData2
[MAX_PATH
];
467 LPCITEMIDLIST pidltemp1
= pidl1
;
468 LPCITEMIDLIST pidltemp2
= pidl2
;
470 TRACE("pidl1=%p pidl2=%p\n", pidl1
, pidl2
);
473 * Explorer reads from registry directly (StreamMRU),
474 * so we can only check here
476 if (!pcheck(pidl1
) || !pcheck (pidl2
))
482 if (!pidl1
|| !pidl2
)
485 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
487 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
488 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
490 if (strcmp( szData1
, szData2
))
493 pidltemp1
= ILGetNext(pidltemp1
);
494 pidltemp2
= ILGetNext(pidltemp2
);
497 if (!pidltemp1
->mkid
.cb
&& !pidltemp2
->mkid
.cb
)
503 /*************************************************************************
504 * ILIsParent [SHELL32.23]
506 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
511 * bImmediate [I] only return true if the parent is the direct parent
515 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
519 * parent = a/b, child = a/b/c -> true, c is in folder a/b
520 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
521 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
523 BOOL WINAPI
ILIsParent(LPCITEMIDLIST pidlParent
, LPCITEMIDLIST pidlChild
, BOOL bImmediate
)
525 char szData1
[MAX_PATH
];
526 char szData2
[MAX_PATH
];
527 LPCITEMIDLIST pParent
= pidlParent
;
528 LPCITEMIDLIST pChild
= pidlChild
;
530 TRACE("%p %p %x\n", pidlParent
, pidlChild
, bImmediate
);
532 if (!pParent
|| !pChild
)
535 while (pParent
->mkid
.cb
&& pChild
->mkid
.cb
)
537 _ILSimpleGetText(pParent
, szData1
, MAX_PATH
);
538 _ILSimpleGetText(pChild
, szData2
, MAX_PATH
);
540 if (strcmp( szData1
, szData2
))
543 pParent
= ILGetNext(pParent
);
544 pChild
= ILGetNext(pChild
);
547 /* child shorter or has equal length to parent */
548 if (pParent
->mkid
.cb
|| !pChild
->mkid
.cb
)
551 /* not immediate descent */
552 if ( ILGetNext(pChild
)->mkid
.cb
&& bImmediate
)
558 /*************************************************************************
559 * ILFindChild [SHELL32.24]
561 * Compares elements from pidl1 and pidl2.
568 * pidl1 is desktop pidl2
569 * pidl1 shorter pidl2 pointer to first different element of pidl2
570 * if there was at least one equal element
571 * pidl2 shorter pidl1 0
572 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
575 * exported by ordinal.
577 LPITEMIDLIST WINAPI
ILFindChild(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
579 char szData1
[MAX_PATH
];
580 char szData2
[MAX_PATH
];
582 LPCITEMIDLIST pidltemp1
= pidl1
;
583 LPCITEMIDLIST pidltemp2
= pidl2
;
584 LPCITEMIDLIST ret
= NULL
;
586 TRACE("pidl1=%p pidl2=%p\n", pidl1
, pidl2
);
588 /* explorer reads from registry directly (StreamMRU),
589 so we can only check here */
590 if ((!pcheck (pidl1
)) || (!pcheck (pidl2
)))
596 if (_ILIsDesktop(pidl1
))
602 while (pidltemp1
->mkid
.cb
&& pidltemp2
->mkid
.cb
)
604 _ILSimpleGetText(pidltemp1
, szData1
, MAX_PATH
);
605 _ILSimpleGetText(pidltemp2
, szData2
, MAX_PATH
);
607 if (strcmp(szData1
, szData2
))
610 pidltemp1
= ILGetNext(pidltemp1
);
611 pidltemp2
= ILGetNext(pidltemp2
);
615 if (pidltemp1
->mkid
.cb
)
616 ret
= NULL
; /* elements of pidl1 left*/
618 TRACE_(shell
)("--- %p\n", ret
);
619 return (LPITEMIDLIST
)ret
; /* pidl 1 is shorter */
622 /*************************************************************************
623 * ILCombine [SHELL32.25]
625 * Concatenates two complex ItemIDLists.
628 * pidl1 [I] first complex ItemIDLists
629 * pidl2 [I] complex ItemIDLists to append
632 * if both pidl's == NULL NULL
633 * if pidl1 == NULL cloned pidl2
634 * if pidl2 == NULL cloned pidl1
635 * otherwise new pidl with pidl2 appended to pidl1
638 * exported by ordinal.
639 * Does not destroy the passed in ItemIDLists!
641 LPITEMIDLIST WINAPI
ILCombine(LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
644 LPITEMIDLIST pidlNew
;
646 TRACE("pidl=%p pidl=%p\n", pidl1
, pidl2
);
648 if (!pidl1
&& !pidl2
) return NULL
;
655 pidlNew
= ILClone(pidl2
);
661 pidlNew
= ILClone(pidl1
);
665 len1
= ILGetSize(pidl1
) - 2;
666 len2
= ILGetSize(pidl2
);
667 pidlNew
= (LPITEMIDLIST
)SHAlloc(len1
+ len2
);
671 memcpy(pidlNew
, pidl1
, len1
);
672 memcpy(((BYTE
*)pidlNew
) + len1
, pidl2
, len2
);
675 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
679 /*************************************************************************
680 * SHGetRealIDL [SHELL32.98]
684 HRESULT WINAPI
SHGetRealIDL(LPSHELLFOLDER lpsf
, LPCITEMIDLIST pidlSimple
, LPITEMIDLIST
*pidlReal
)
686 CComPtr
<IDataObject
> pDataObj
;
689 hr
= lpsf
->GetUIObjectOf(0, 1, &pidlSimple
,
690 IID_IDataObject
, 0, (LPVOID
*)&pDataObj
);
696 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLIST
);
698 fmt
.dwAspect
= DVASPECT_CONTENT
;
700 fmt
.tymed
= TYMED_HGLOBAL
;
702 hr
= pDataObj
->GetData(&fmt
, &medium
);
706 /*assert(pida->cidl==1);*/
707 LPIDA pida
= (LPIDA
)GlobalLock(medium
.hGlobal
);
709 LPCITEMIDLIST pidl_folder
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+ pida
->aoffset
[0]);
710 LPCITEMIDLIST pidl_child
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+ pida
->aoffset
[1]);
712 *pidlReal
= ILCombine(pidl_folder
, pidl_child
);
717 GlobalUnlock(medium
.hGlobal
);
718 GlobalFree(medium
.hGlobal
);
725 /*************************************************************************
726 * SHLogILFromFSIL [SHELL32.95]
729 * pild = CSIDL_DESKTOP ret = 0
730 * pild = CSIDL_DRIVES ret = 0
732 EXTERN_C LPITEMIDLIST WINAPI
SHLogILFromFSIL(LPITEMIDLIST pidl
)
734 FIXME("(pidl=%p)\n", pidl
);
741 /*************************************************************************
742 * ILGetSize [SHELL32.152]
744 * Gets the byte size of an ItemIDList including zero terminator
747 * pidl [I] ItemIDList
750 * size of pidl in bytes
753 * exported by ordinal
755 UINT WINAPI
ILGetSize(LPCITEMIDLIST pidl
)
757 LPCSHITEMID si
= &(pidl
->mkid
);
765 si
= (LPCSHITEMID
)(((const BYTE
*)si
) + si
->cb
);
769 TRACE("pidl=%p size=%u\n", pidl
, len
);
773 /*************************************************************************
774 * ILGetNext [SHELL32.153]
776 * Gets the next ItemID of an ItemIDList
779 * pidl [I] ItemIDList
784 * simple pidl -> pointer to 0x0000 element
787 * exported by ordinal.
789 LPITEMIDLIST WINAPI
ILGetNext(LPCITEMIDLIST pidl
)
800 pidl
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
801 TRACE("-- %p\n", pidl
);
802 return (LPITEMIDLIST
)pidl
;
808 /*************************************************************************
809 * ILAppend [SHELL32.154]
811 * Adds the single ItemID item to the ItemIDList indicated by pidl.
812 * If bEnd is FALSE, inserts the item in the front of the list,
813 * otherwise it adds the item to the end. (???)
816 * pidl [I] ItemIDList to extend
817 * item [I] ItemID to prepend/append
818 * bEnd [I] Indicates if the item should be appended
821 * Destroys the passed in idlist! (???)
823 EXTERN_C LPITEMIDLIST WINAPI
ILAppend(LPITEMIDLIST pidl
, LPCITEMIDLIST item
, BOOL bEnd
)
827 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n", pidl
, item
, bEnd
);
832 if (_ILIsDesktop(pidl
))
834 idlRet
= ILClone(item
);
840 idlRet
= ILCombine(pidl
, item
);
842 idlRet
= ILCombine(item
, pidl
);
848 /*************************************************************************
849 * ILFree [SHELL32.155]
851 * Frees memory (if not NULL) allocated by SHMalloc allocator
860 * exported by ordinal
862 void WINAPI
ILFree(LPITEMIDLIST pidl
)
864 TRACE("(pidl=%p)\n", pidl
);
868 /*************************************************************************
869 * ILGlobalFree [SHELL32.156]
871 * Frees memory (if not NULL) allocated by Alloc allocator
880 * exported by ordinal.
882 void WINAPI
ILGlobalFree( LPITEMIDLIST pidl
)
889 /*************************************************************************
890 * ILCreateFromPathA [SHELL32.189]
892 * Creates a complex ItemIDList from a path and returns it.
898 * the newly created complex ItemIDList or NULL if failed
901 * exported by ordinal.
903 LPITEMIDLIST WINAPI
ILCreateFromPathA (LPCSTR path
)
905 LPITEMIDLIST pidlnew
= NULL
;
907 TRACE_(shell
)("%s\n", debugstr_a(path
));
909 if (SUCCEEDED(SHILCreateFromPathA(path
, &pidlnew
, NULL
)))
914 /*************************************************************************
915 * ILCreateFromPathW [SHELL32.190]
917 * See ILCreateFromPathA.
919 LPITEMIDLIST WINAPI
ILCreateFromPathW (LPCWSTR path
)
921 LPITEMIDLIST pidlnew
= NULL
;
923 TRACE_(shell
)("%s\n", debugstr_w(path
));
925 if (SUCCEEDED(SHILCreateFromPathW(path
, &pidlnew
, NULL
)))
930 /*************************************************************************
931 * ILCreateFromPath [SHELL32.157]
933 EXTERN_C LPITEMIDLIST WINAPI
ILCreateFromPathAW (LPCVOID path
)
935 if ( SHELL_OsIsUnicode())
936 return ILCreateFromPathW ((LPCWSTR
)path
);
937 return ILCreateFromPathA ((LPCSTR
)path
);
940 /*************************************************************************
941 * _ILParsePathW [internal]
943 * Creates an ItemIDList from a path and returns it.
946 * path [I] path to parse and convert into an ItemIDList
947 * lpFindFile [I] pointer to buffer to initialize the FileSystem
948 * Bind Data object with
949 * bBindCtx [I] indicates to create a BindContext and assign a
950 * FileSystem Bind Data object
951 * ppidl [O] the newly create ItemIDList
952 * prgfInOut [I/O] requested attributes on input and actual
953 * attributes on return
956 * NO_ERROR on success or an OLE error code
959 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
960 * creates a BindContext object and assigns a FileSystem Bind Data object
961 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
962 * IShellFolder uses that FileSystem Bind Data object of the BindContext
963 * to pass data about the current path element to the next object. This
964 * is used to avoid having to verify the current path element on disk, so
965 * that creating an ItemIDList from a nonexistent path still can work.
967 static HRESULT
_ILParsePathW(LPCWSTR path
, LPWIN32_FIND_DATAW lpFindFile
,
968 BOOL bBindCtx
, LPITEMIDLIST
*ppidl
, LPDWORD prgfInOut
)
970 CComPtr
<IShellFolder
> pSF
;
971 CComPtr
<IBindCtx
> pBC
;
974 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path
), lpFindFile
, bBindCtx
,
975 ppidl
, ppidl
? *ppidl
: NULL
,
976 prgfInOut
, prgfInOut
? *prgfInOut
: 0);
978 ret
= SHGetDesktopFolder(&pSF
);
982 if (lpFindFile
|| bBindCtx
)
983 ret
= IFileSystemBindData_Constructor(lpFindFile
, &pBC
);
987 ret
= pSF
->ParseDisplayName(0, pBC
, (LPOLESTR
)path
, NULL
, ppidl
, prgfInOut
);
990 if (FAILED(ret
) && ppidl
)
993 TRACE("%s %p 0x%x\n", debugstr_w(path
), ppidl
? *ppidl
: NULL
, prgfInOut
? *prgfInOut
: 0);
998 /*************************************************************************
999 * SHSimpleIDListFromPath [SHELL32.162]
1001 * Creates a simple ItemIDList from a path and returns it. This function
1002 * does not fail on nonexistent paths.
1005 * path [I] path to parse and convert into an ItemIDList
1008 * the newly created simple ItemIDList
1011 * Simple in the name does not mean a relative ItemIDList but rather a
1012 * fully qualified list, where only the file name is filled in and the
1013 * directory flag for those ItemID elements this is known about, eg.
1014 * it is not the last element in the ItemIDList or the actual directory
1016 * exported by ordinal.
1018 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathA(LPCSTR lpszPath
)
1020 LPITEMIDLIST pidl
= NULL
;
1021 LPWSTR wPath
= NULL
;
1024 TRACE("%s\n", debugstr_a(lpszPath
));
1028 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, NULL
, 0);
1029 wPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1030 MultiByteToWideChar(CP_ACP
, 0, lpszPath
, -1, wPath
, len
);
1033 _ILParsePathW(wPath
, NULL
, TRUE
, &pidl
, NULL
);
1035 HeapFree(GetProcessHeap(), 0, wPath
);
1036 TRACE("%s %p\n", debugstr_a(lpszPath
), pidl
);
1040 LPITEMIDLIST WINAPI
SHSimpleIDListFromPathW(LPCWSTR lpszPath
)
1042 LPITEMIDLIST pidl
= NULL
;
1044 TRACE("%s\n", debugstr_w(lpszPath
));
1046 _ILParsePathW(lpszPath
, NULL
, TRUE
, &pidl
, NULL
);
1047 TRACE("%s %p\n", debugstr_w(lpszPath
), pidl
);
1051 EXTERN_C LPITEMIDLIST WINAPI
SHSimpleIDListFromPathAW(LPCVOID lpszPath
)
1053 if ( SHELL_OsIsUnicode())
1054 return SHSimpleIDListFromPathW ((LPCWSTR
)lpszPath
);
1055 return SHSimpleIDListFromPathA ((LPCSTR
)lpszPath
);
1058 /*************************************************************************
1059 * SHGetDataFromIDListA [SHELL32.247]
1062 * the pidl can be a simple one. since we can't get the path out of the pidl
1063 * we have to take all data from the pidl
1065 HRESULT WINAPI
SHGetDataFromIDListA(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1066 int nFormat
, LPVOID dest
, int len
)
1068 LPSTR filename
, shortname
;
1069 WIN32_FIND_DATAA
* pfd
;
1071 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n", psf
, pidl
, nFormat
, dest
, len
);
1075 return E_INVALIDARG
;
1079 case SHGDFIL_FINDDATA
:
1080 pfd
= (WIN32_FIND_DATAA
*)dest
;
1082 if (_ILIsDrive(pidl
) || _ILIsSpecialFolder(pidl
))
1083 return E_INVALIDARG
;
1085 if (len
< (int)sizeof(WIN32_FIND_DATAA
))
1086 return E_INVALIDARG
;
1088 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAA
));
1089 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1090 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1091 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1093 filename
= _ILGetTextPointer(pidl
);
1094 shortname
= _ILGetSTextPointer(pidl
);
1097 lstrcpynA(pfd
->cFileName
, filename
, sizeof(pfd
->cFileName
));
1099 pfd
->cFileName
[0] = '\0';
1102 lstrcpynA(pfd
->cAlternateFileName
, shortname
, sizeof(pfd
->cAlternateFileName
));
1104 pfd
->cAlternateFileName
[0] = '\0';
1107 case SHGDFIL_NETRESOURCE
:
1108 case SHGDFIL_DESCRIPTIONID
:
1109 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1113 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1116 return E_INVALIDARG
;
1119 /*************************************************************************
1120 * SHGetDataFromIDListW [SHELL32.248]
1123 HRESULT WINAPI
SHGetDataFromIDListW(LPSHELLFOLDER psf
, LPCITEMIDLIST pidl
,
1124 int nFormat
, LPVOID dest
, int len
)
1126 LPSTR filename
, shortname
;
1127 WIN32_FIND_DATAW
* pfd
= (WIN32_FIND_DATAW
*)dest
;
1129 TRACE_(shell
)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n", psf
, pidl
, nFormat
, dest
, len
);
1134 return E_INVALIDARG
;
1138 case SHGDFIL_FINDDATA
:
1139 pfd
= (WIN32_FIND_DATAW
*)dest
;
1141 if (_ILIsDrive(pidl
))
1142 return E_INVALIDARG
;
1144 if (len
< (int)sizeof(WIN32_FIND_DATAW
))
1145 return E_INVALIDARG
;
1147 ZeroMemory(pfd
, sizeof (WIN32_FIND_DATAW
));
1148 _ILGetFileDateTime( pidl
, &(pfd
->ftLastWriteTime
));
1149 pfd
->dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
1150 pfd
->nFileSizeLow
= _ILGetFileSize ( pidl
, NULL
, 0);
1152 filename
= _ILGetTextPointer(pidl
);
1153 shortname
= _ILGetSTextPointer(pidl
);
1156 pfd
->cFileName
[0] = '\0';
1157 else if (!MultiByteToWideChar(CP_ACP
, 0, filename
, -1, pfd
->cFileName
, MAX_PATH
))
1158 pfd
->cFileName
[MAX_PATH
-1] = 0;
1161 pfd
->cAlternateFileName
[0] = '\0';
1162 else if (!MultiByteToWideChar(CP_ACP
, 0, shortname
, -1, pfd
->cAlternateFileName
, 14))
1163 pfd
->cAlternateFileName
[13] = 0;
1166 case SHGDFIL_NETRESOURCE
:
1167 case SHGDFIL_DESCRIPTIONID
:
1168 FIXME_(shell
)("SHGDFIL %i stub\n", nFormat
);
1172 ERR_(shell
)("Unknown SHGDFIL %i, please report\n", nFormat
);
1175 return E_INVALIDARG
;
1178 /*************************************************************************
1179 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1183 * pszPath [OUT] path
1186 * path from a passed PIDL.
1189 * NULL returns FALSE
1190 * desktop pidl gives path to desktop directory back
1191 * special pidls returning FALSE
1193 BOOL WINAPI
SHGetPathFromIDListA(LPCITEMIDLIST pidl
, LPSTR pszPath
)
1195 WCHAR wszPath
[MAX_PATH
];
1198 bSuccess
= SHGetPathFromIDListW(pidl
, wszPath
);
1199 WideCharToMultiByte(CP_ACP
, 0, wszPath
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1204 /*************************************************************************
1205 * SHGetPathFromIDListW [SHELL32.@]
1207 * See SHGetPathFromIDListA.
1209 BOOL WINAPI
SHGetPathFromIDListW(LPCITEMIDLIST pidl
, LPWSTR pszPath
)
1212 LPCITEMIDLIST pidlLast
;
1213 CComPtr
<IShellFolder
> psfFolder
;
1217 TRACE_(shell
)("(pidl=%p,%p)\n", pidl
, pszPath
);
1224 hr
= SHBindToParent(pidl
, IID_IShellFolder
, (VOID
**)&psfFolder
, &pidlLast
);
1227 ERR("SHBindToParent failed: %x\n", hr
);
1231 dwAttributes
= SFGAO_FILESYSTEM
;
1232 hr
= psfFolder
->GetAttributesOf(1, &pidlLast
, &dwAttributes
);
1233 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
))
1235 WARN("Wrong dwAttributes or GetAttributesOf failed: %x\n", hr
);
1239 hr
= psfFolder
->GetDisplayNameOf(pidlLast
, SHGDN_FORPARSING
, &strret
);
1240 if (FAILED(hr
)) return FALSE
;
1242 hr
= StrRetToBufW(&strret
, pidlLast
, pszPath
, MAX_PATH
);
1244 TRACE_(shell
)("-- %s, 0x%08x\n", debugstr_w(pszPath
), hr
);
1245 return SUCCEEDED(hr
);
1248 /*************************************************************************
1249 * SHBindToParent [shell version 5.0]
1251 HRESULT WINAPI
SHBindToParent(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
, LPCITEMIDLIST
*ppidlLast
)
1253 CComPtr
<IShellFolder
> psfDesktop
;
1254 HRESULT hr
= E_FAIL
;
1256 TRACE_(shell
)("pidl=%p\n", pidl
);
1260 return E_INVALIDARG
;
1266 hr
= SHGetDesktopFolder(&psfDesktop
);
1270 if (_ILIsPidlSimple(pidl
))
1272 /* we are on desktop level */
1273 hr
= psfDesktop
->QueryInterface(riid
, ppv
);
1277 LPITEMIDLIST pidlParent
= ILClone(pidl
);
1278 ILRemoveLastID(pidlParent
);
1279 hr
= psfDesktop
->BindToObject(pidlParent
, NULL
, riid
, ppv
);
1280 SHFree (pidlParent
);
1283 if (SUCCEEDED(hr
) && ppidlLast
)
1284 *ppidlLast
= ILFindLastID(pidl
);
1286 TRACE_(shell
)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv
, (ppidlLast
) ? *ppidlLast
: NULL
, hr
);
1290 /**************************************************************************
1292 * internal functions
1294 * ### 1. section creating pidls ###
1296 *************************************************************************
1299 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1300 * - two bytes are SHITEMID.cb
1301 * - one byte is PIDLDATA.type
1302 * - two bytes are the NULL PIDL terminator
1303 * Sets type of the returned PIDL to type.
1305 static LPITEMIDLIST
_ILAlloc(PIDLTYPE type
, unsigned int size
)
1307 LPITEMIDLIST pidlOut
= NULL
;
1309 pidlOut
= (LPITEMIDLIST
)SHAlloc(size
+ 5);
1313 LPITEMIDLIST pidlNext
;
1315 ZeroMemory(pidlOut
, size
+ 5);
1316 pidlOut
->mkid
.cb
= size
+ 3;
1318 pData
= _ILGetDataPointer(pidlOut
);
1322 pidlNext
= ILGetNext(pidlOut
);
1324 pidlNext
->mkid
.cb
= 0x00;
1325 TRACE("-- (pidl=%p, size=%u)\n", pidlOut
, size
);
1331 LPITEMIDLIST
_ILCreateDesktop(void)
1336 ret
= (LPITEMIDLIST
)SHAlloc(2);
1342 LPITEMIDLIST
_ILCreateMyComputer(void)
1345 return _ILCreateGuid(PT_GUID
, CLSID_MyComputer
);
1348 LPITEMIDLIST
_ILCreateMyDocuments(void)
1351 return _ILCreateGuid(PT_GUID
, CLSID_MyDocuments
);
1354 LPITEMIDLIST
_ILCreateIExplore(void)
1357 return _ILCreateGuid(PT_GUID
, CLSID_Internet
);
1360 LPITEMIDLIST
_ILCreateControlPanel(void)
1362 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, CLSID_MyComputer
), ret
= NULL
;
1367 LPITEMIDLIST cpl
= _ILCreateGuid(PT_SHELLEXT
, CLSID_ControlPanel
);
1371 ret
= ILCombine(parent
, cpl
);
1379 LPITEMIDLIST
_ILCreatePrinters(void)
1381 LPITEMIDLIST parent
= _ILCreateGuid(PT_GUID
, CLSID_MyComputer
), ret
= NULL
;
1386 LPITEMIDLIST printers
= _ILCreateGuid(PT_YAGUID
, CLSID_Printers
);
1390 ret
= ILCombine(parent
, printers
);
1398 LPITEMIDLIST
_ILCreateNetwork(void)
1401 return _ILCreateGuid(PT_GUID
, CLSID_NetworkPlaces
);
1404 LPITEMIDLIST
_ILCreateBitBucket(void)
1407 return _ILCreateGuid(PT_GUID
, CLSID_RecycleBin
);
1410 LPITEMIDLIST
_ILCreateAdminTools(void)
1413 return _ILCreateGuid(PT_GUID
, CLSID_AdminFolderShortcut
); //FIXME
1416 LPITEMIDLIST
_ILCreateGuid(PIDLTYPE type
, REFIID guid
)
1418 LPITEMIDLIST pidlOut
;
1420 if (type
== PT_SHELLEXT
|| type
== PT_GUID
|| type
== PT_YAGUID
)
1422 pidlOut
= _ILAlloc(type
, sizeof(GUIDStruct
));
1425 LPPIDLDATA pData
= _ILGetDataPointer(pidlOut
);
1427 pData
->u
.guid
.guid
= guid
;
1428 TRACE("-- create GUID-pidl %s\n",
1429 debugstr_guid(&(pData
->u
.guid
.guid
)));
1434 WARN("%d: invalid type for GUID\n", type
);
1440 LPITEMIDLIST
_ILCreateGuidFromStrA(LPCSTR szGUID
)
1444 if (FAILED(SHCLSIDFromStringA(szGUID
, &iid
)))
1446 ERR("%s is not a GUID\n", szGUID
);
1449 return _ILCreateGuid(PT_GUID
, iid
);
1452 LPITEMIDLIST
_ILCreateGuidFromStrW(LPCWSTR szGUID
)
1456 if (FAILED(CLSIDFromString((LPOLESTR
)szGUID
, &iid
)))
1458 ERR("%s is not a GUID\n", debugstr_w(szGUID
));
1461 return _ILCreateGuid(PT_GUID
, iid
);
1464 LPITEMIDLIST
_ILCreateFromFindDataW( const WIN32_FIND_DATAW
*wfd
)
1466 char buff
[MAX_PATH
+ 14 +1]; /* see WIN32_FIND_DATA */
1467 DWORD len
, len1
, wlen
, alen
, cbData
;
1474 TRACE("(%s, %s)\n", debugstr_w(wfd
->cAlternateFileName
), debugstr_w(wfd
->cFileName
));
1476 /* prepare buffer with both names */
1477 len
= WideCharToMultiByte(CP_ACP
, 0, wfd
->cFileName
, -1, buff
, MAX_PATH
, NULL
, NULL
);
1478 len1
= WideCharToMultiByte(CP_ACP
, 0, wfd
->cAlternateFileName
, -1, buff
+ len
, sizeof(buff
) - len
, NULL
, NULL
);
1481 type
= (wfd
->dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? PT_FOLDER
: PT_VALUE
;
1483 wlen
= wcslen(wfd
->cFileName
) + 1;
1484 cbData
= sizeof(FileStruct
) - 1 + (alen
+ (alen
& 1)); // Note: szNames field is initially 1 byte long
1485 cbData
+= sizeof(FileStructW
) - 1 + wlen
* sizeof(WCHAR
); // Note: wszName field is initially 1 byte long
1486 cbData
+= sizeof(WORD
); // offset to FileStructW
1487 pidl
= _ILAlloc(type
, cbData
);
1490 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
1491 FileStruct
*fs
= &pData
->u
.file
;
1495 FileTimeToDosDateTime( &wfd
->ftLastWriteTime
, &fs
->uFileDate
, &fs
->uFileTime
);
1496 fs
->dwFileSize
= wfd
->nFileSizeLow
;
1497 fs
->uFileAttribs
= wfd
->dwFileAttributes
;
1498 memcpy(fs
->szNames
, buff
, alen
);
1500 fsw
= (FileStructW
*)(pData
->u
.file
.szNames
+ alen
+ (alen
& 0x1));
1501 fsw
->cbLen
= sizeof(FileStructW
) - 1 + wlen
* sizeof(WCHAR
) + sizeof(WORD
);
1502 FileTimeToDosDateTime( &wfd
->ftCreationTime
, &fsw
->uCreationDate
, &fsw
->uCreationTime
);
1503 FileTimeToDosDateTime( &wfd
->ftLastAccessTime
, &fsw
->uLastAccessDate
, &fsw
->uLastAccessTime
);
1504 memcpy(fsw
->wszName
, wfd
->cFileName
, wlen
* sizeof(WCHAR
));
1506 pOffsetW
= (WORD
*)((LPBYTE
)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
1507 *pOffsetW
= (LPBYTE
)fsw
- (LPBYTE
)pidl
;
1508 TRACE("-- Set Value: %s\n", debugstr_w(fsw
->wszName
));
1514 HRESULT
_ILCreateFromPathW(LPCWSTR szPath
, LPITEMIDLIST
* ppidl
)
1517 WIN32_FIND_DATAW stffile
;
1520 return E_INVALIDARG
;
1522 hFile
= FindFirstFileW(szPath
, &stffile
);
1523 if (hFile
== INVALID_HANDLE_VALUE
)
1524 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1528 *ppidl
= _ILCreateFromFindDataW(&stffile
);
1530 return *ppidl
? S_OK
: E_OUTOFMEMORY
;
1533 LPITEMIDLIST
_ILCreateDrive(LPCWSTR lpszNew
)
1535 LPITEMIDLIST pidlOut
;
1537 TRACE("(%s)\n", debugstr_w(lpszNew
));
1539 pidlOut
= _ILAlloc(PT_DRIVE
, sizeof(DriveStruct
));
1544 pszDest
= _ILGetTextPointer(pidlOut
);
1547 strcpy(pszDest
, "x:\\");
1548 pszDest
[0] = towupper(lpszNew
[0]);
1549 TRACE("-- create Drive: %s\n", debugstr_a(pszDest
));
1555 /**************************************************************************
1558 * Gets the text for the drive eg. 'c:\'
1563 DWORD
_ILGetDrive(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uSize
)
1565 TRACE("(%p,%p,%u)\n", pidl
, pOut
, uSize
);
1567 if(_ILIsMyComputer(pidl
))
1568 pidl
= ILGetNext(pidl
);
1570 if (pidl
&& _ILIsDrive(pidl
))
1571 return _ILSimpleGetText(pidl
, pOut
, uSize
);
1576 /**************************************************************************
1578 * ### 2. section testing pidls ###
1580 **************************************************************************
1584 * _ILIsSpecialFolder()
1590 BOOL
_ILIsUnicode(LPCITEMIDLIST pidl
)
1592 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1594 TRACE("(%p)\n", pidl
);
1596 return (pidl
&& lpPData
&& PT_VALUEW
== lpPData
->type
);
1599 BOOL
_ILIsDesktop(LPCITEMIDLIST pidl
)
1601 TRACE("(%p)\n", pidl
);
1603 return pidl
&& pidl
->mkid
.cb
? 0 : 1;
1606 BOOL
_ILIsMyDocuments(LPCITEMIDLIST pidl
)
1608 IID
*iid
= _ILGetGUIDPointer(pidl
);
1610 TRACE("(%p)\n", pidl
);
1613 return IsEqualIID(*iid
, CLSID_MyDocuments
);
1617 BOOL
_ILIsControlPanel(LPCITEMIDLIST pidl
)
1619 IID
*iid
= _ILGetGUIDPointer(pidl
);
1621 TRACE("(%p)\n", pidl
);
1624 return IsEqualIID(*iid
, CLSID_ControlPanel
);
1628 BOOL
_ILIsNetHood(LPCITEMIDLIST pidl
)
1630 IID
*iid
= _ILGetGUIDPointer(pidl
);
1632 TRACE("(%p)\n", pidl
);
1635 return IsEqualIID(*iid
, CLSID_NetworkPlaces
);
1640 LPITEMIDLIST
_ILCreateNetHood(void)
1642 return _ILCreateGuid(PT_GUID
, CLSID_NetworkPlaces
);
1645 LPITEMIDLIST
_ILCreateFont(void)
1647 return _ILCreateGuid(PT_GUID
, CLSID_FontsFolderShortcut
);
1650 BOOL
_ILIsMyComputer(LPCITEMIDLIST pidl
)
1652 IID
*iid
= _ILGetGUIDPointer(pidl
);
1654 TRACE("(%p)\n", pidl
);
1657 return IsEqualIID(*iid
, CLSID_MyComputer
);
1661 BOOL
_ILIsPrinter(LPCITEMIDLIST pidl
)
1663 IID
*iid
= _ILGetGUIDPointer(pidl
);
1665 TRACE("(%p)\n", pidl
);
1668 return IsEqualIID(*iid
, CLSID_Printers
);
1672 BOOL
_ILIsBitBucket(LPCITEMIDLIST pidl
)
1674 IID
*iid
= _ILGetGUIDPointer(pidl
);
1676 TRACE("(%p)\n", pidl
);
1679 return IsEqualIID(*iid
, CLSID_RecycleBin
);
1683 BOOL
_ILIsAdminTools(LPCITEMIDLIST pidl
)
1685 IID
*iid
= _ILGetGUIDPointer(pidl
);
1687 TRACE("(%p)\n", pidl
);
1690 return IsEqualIID(*iid
, CLSID_AdminFolderShortcut
);
1695 BOOL
_ILIsSpecialFolder (LPCITEMIDLIST pidl
)
1697 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1699 TRACE("(%p)\n", pidl
);
1701 return (pidl
&& ( (lpPData
&& (PT_GUID
== lpPData
->type
|| PT_SHELLEXT
== lpPData
->type
|| PT_YAGUID
== lpPData
->type
)) ||
1702 (pidl
&& pidl
->mkid
.cb
== 0x00)
1706 BOOL
_ILIsDrive(LPCITEMIDLIST pidl
)
1708 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1710 TRACE("(%p)\n", pidl
);
1712 return (pidl
&& lpPData
&& (PT_DRIVE
== lpPData
->type
||
1713 PT_DRIVE1
== lpPData
->type
||
1714 PT_DRIVE2
== lpPData
->type
||
1715 PT_DRIVE3
== lpPData
->type
));
1718 BOOL
_ILIsFolder(LPCITEMIDLIST pidl
)
1720 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1722 TRACE("(%p)\n", pidl
);
1724 return (pidl
&& lpPData
&& (PT_FOLDER
== lpPData
->type
|| PT_FOLDER1
== lpPData
->type
));
1727 BOOL
_ILIsValue(LPCITEMIDLIST pidl
)
1729 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1731 TRACE("(%p)\n", pidl
);
1733 return (pidl
&& lpPData
&& PT_VALUE
== lpPData
->type
);
1736 BOOL
_ILIsCPanelStruct(LPCITEMIDLIST pidl
)
1738 LPPIDLDATA lpPData
= _ILGetDataPointer(pidl
);
1740 TRACE("(%p)\n", pidl
);
1742 return (pidl
&& lpPData
&& (lpPData
->type
== 0));
1745 /**************************************************************************
1748 BOOL
_ILIsPidlSimple(LPCITEMIDLIST pidl
)
1752 if(! _ILIsDesktop(pidl
)) /* pidl=NULL or mkid.cb=0 */
1754 WORD len
= pidl
->mkid
.cb
;
1755 LPCITEMIDLIST pidlnext
= (LPCITEMIDLIST
) (((const BYTE
*)pidl
) + len
);
1757 if (pidlnext
->mkid
.cb
)
1761 TRACE("%s\n", ret
? "Yes" : "No");
1765 /**************************************************************************
1767 * ### 3. section getting values from pidls ###
1770 /**************************************************************************
1773 * gets the text for the first item in the pidl (eg. simple pidl)
1775 * returns the length of the string
1777 DWORD
_ILSimpleGetText (LPCITEMIDLIST pidl
, LPSTR szOut
, UINT uOutSize
)
1783 char szTemp
[MAX_PATH
];
1785 TRACE("(%p %p %x)\n", pidl
, szOut
, uOutSize
);
1793 if (_ILIsDesktop(pidl
))
1796 if (HCR_GetClassNameA(CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1799 lstrcpynA(szOut
, szTemp
, uOutSize
);
1801 dwReturn
= strlen (szTemp
);
1804 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1808 lstrcpynA(szOut
, szSrc
, uOutSize
);
1810 dwReturn
= strlen(szSrc
);
1812 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1814 /* unicode filesystem */
1815 WideCharToMultiByte(CP_ACP
, 0, szSrcW
, -1, szTemp
, MAX_PATH
, NULL
, NULL
);
1818 lstrcpynA(szOut
, szTemp
, uOutSize
);
1820 dwReturn
= strlen (szTemp
);
1822 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1824 /* special folder */
1825 if (HCR_GetClassNameA(*riid
, szTemp
, MAX_PATH
) )
1828 lstrcpynA(szOut
, szTemp
, uOutSize
);
1830 dwReturn
= strlen (szTemp
);
1835 ERR("-- no text\n");
1838 TRACE("-- (%p=%s 0x%08x)\n", szOut
, debugstr_a(szOut
), dwReturn
);
1842 /**************************************************************************
1845 * gets the text for the first item in the pidl (eg. simple pidl)
1847 * returns the length of the string
1849 DWORD
_ILSimpleGetTextW (LPCITEMIDLIST pidl
, LPWSTR szOut
, UINT uOutSize
)
1852 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
1854 TRACE("(%p %p %x)\n", pidl
, szOut
, uOutSize
);
1857 lstrcpynW(szOut
, pFileStructW
->wszName
, uOutSize
);
1858 dwReturn
= wcslen(pFileStructW
->wszName
);
1861 WCHAR szTemp
[MAX_PATH
];
1872 if (_ILIsDesktop(pidl
))
1875 if (HCR_GetClassNameW(CLSID_ShellDesktop
, szTemp
, MAX_PATH
))
1878 lstrcpynW(szOut
, szTemp
, uOutSize
);
1880 dwReturn
= wcslen (szTemp
);
1883 else if (( szSrcW
= _ILGetTextPointerW(pidl
) ))
1885 /* unicode filesystem */
1887 lstrcpynW(szOut
, szSrcW
, uOutSize
);
1889 dwReturn
= wcslen(szSrcW
);
1891 else if (( szSrc
= _ILGetTextPointer(pidl
) ))
1894 MultiByteToWideChar(CP_ACP
, 0, szSrc
, -1, szTemp
, MAX_PATH
);
1897 lstrcpynW(szOut
, szTemp
, uOutSize
);
1899 dwReturn
= wcslen (szTemp
);
1901 else if (( riid
= _ILGetGUIDPointer(pidl
) ))
1903 /* special folder */
1904 if ( HCR_GetClassNameW(*riid
, szTemp
, MAX_PATH
) )
1907 lstrcpynW(szOut
, szTemp
, uOutSize
);
1909 dwReturn
= wcslen (szTemp
);
1914 ERR("-- no text\n");
1918 TRACE("-- (%p=%s 0x%08x)\n", szOut
, debugstr_w(szOut
), dwReturn
);
1922 /**************************************************************************
1924 * ### 4. getting pointers to parts of pidls ###
1926 **************************************************************************
1927 * _ILGetDataPointer()
1929 LPPIDLDATA
_ILGetDataPointer(LPCITEMIDLIST pidl
)
1931 if(pidl
&& pidl
->mkid
.cb
!= 0x00)
1932 return (LPPIDLDATA
)pidl
->mkid
.abID
;
1936 /**************************************************************************
1937 * _ILGetTextPointerW()
1938 * gets a pointer to the unicode long filename string stored in the pidl
1940 static LPWSTR
_ILGetTextPointerW(LPCITEMIDLIST pidl
)
1942 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1944 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1949 switch (pdata
->type
)
1960 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1968 /*return (LPSTR)&(pdata->u.file.szNames);*/
1974 case PT_NETPROVIDER
:
1976 /*return (LPSTR)&(pdata->u.network.szNames);*/
1980 return (LPWSTR
)pdata
->u
.file
.szNames
;
1986 /**************************************************************************
1987 * _ILGetTextPointer()
1988 * gets a pointer to the long filename string stored in the pidl
1990 LPSTR
_ILGetTextPointer(LPCITEMIDLIST pidl
)
1992 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1994 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
1999 switch (pdata
->type
)
2010 return pdata
->u
.drive
.szDriveName
;
2017 return pdata
->u
.file
.szNames
;
2022 case PT_NETPROVIDER
:
2024 return pdata
->u
.network
.szNames
;
2027 return pdata
->u
.cpanel
.szName
;
2032 /**************************************************************************
2033 * _ILGetSTextPointer()
2034 * gets a pointer to the short filename string stored in the pidl
2036 static LPSTR
_ILGetSTextPointer(LPCITEMIDLIST pidl
)
2038 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2040 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2045 switch (pdata
->type
)
2051 return pdata
->u
.file
.szNames
+ strlen (pdata
->u
.file
.szNames
) + 1;
2054 return pdata
->u
.network
.szNames
+ strlen (pdata
->u
.network
.szNames
) + 1;
2059 /**************************************************************************
2060 * _ILGetGUIDPointer()
2062 * returns reference to guid stored in some pidls
2064 IID
* _ILGetGUIDPointer(LPCITEMIDLIST pidl
)
2066 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2068 TRACE("%p\n", pidl
);
2073 TRACE("pdata->type 0x%04x\n", pdata
->type
);
2074 switch (pdata
->type
)
2079 return &(pdata
->u
.guid
.guid
);
2082 TRACE("Unknown pidl type 0x%04x\n", pdata
->type
);
2088 /******************************************************************************
2089 * _ILGetFileStructW [Internal]
2091 * Get pointer the a SHITEMID's FileStructW field if present
2094 * pidl [I] The SHITEMID
2097 * Success: Pointer to pidl's FileStructW field.
2100 FileStructW
* _ILGetFileStructW(LPCITEMIDLIST pidl
) {
2101 FileStructW
*pFileStructW
;
2104 if (!(_ILIsValue(pidl
) || _ILIsFolder(pidl
)))
2107 cbOffset
= *(const WORD
*)((const BYTE
*)pidl
+ pidl
->mkid
.cb
- sizeof(WORD
));
2108 pFileStructW
= (FileStructW
*)((LPBYTE
)pidl
+ cbOffset
);
2110 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2111 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2112 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2113 if (cbOffset
& 0x1 || /* FileStructW member is word aligned in the pidl */
2114 /* FileStructW is positioned after FileStruct */
2115 cbOffset
< sizeof(pidl
->mkid
.cb
) + sizeof(PIDLTYPE
) + sizeof(FileStruct
) ||
2116 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2117 cbOffset
> pidl
->mkid
.cb
- sizeof(cbOffset
) - sizeof(FileStructW
) ||
2118 pidl
->mkid
.cb
!= cbOffset
+ pFileStructW
->cbLen
)
2120 ERR("Invalid pidl format (cbOffset = %d)!\n", cbOffset
);
2124 return pFileStructW
;
2127 /*************************************************************************
2128 * _ILGetFileDateTime
2130 * Given the ItemIdList, get the FileTime
2133 * pidl [I] The ItemIDList
2134 * pFt [I] the resulted FILETIME of the file
2137 * True if Successful
2142 BOOL
_ILGetFileDateTime(LPCITEMIDLIST pidl
, FILETIME
*pFt
)
2144 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2149 switch (pdata
->type
)
2153 DosDateTimeToFileTime(pdata
->u
.file
.uFileDate
, pdata
->u
.file
.uFileTime
, pFt
);
2161 BOOL
_ILGetFileDate (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2167 if (_ILGetFileDateTime( pidl
, &ft
))
2169 FileTimeToLocalFileTime(&ft
, &lft
);
2170 FileTimeToSystemTime (&lft
, &time
);
2172 ret
= GetDateFormatA(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &time
, NULL
, pOut
, uOutSize
);
2175 /* Append space + time without seconds */
2177 GetTimeFormatA(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &pOut
[ret
], uOutSize
- ret
);
2188 /*************************************************************************
2191 * Given the ItemIdList, get the FileSize
2194 * pidl [I] The ItemIDList
2195 * pOut [I] The buffer to save the result
2196 * uOutsize [I] The size of the buffer
2202 * pOut can be null when no string is needed
2205 DWORD
_ILGetFileSize (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2207 LPPIDLDATA pdata
= _ILGetDataPointer(pidl
);
2213 switch (pdata
->type
)
2216 dwSize
= pdata
->u
.file
.dwFileSize
;
2218 StrFormatKBSizeA(dwSize
, pOut
, uOutSize
);
2226 BOOL
_ILGetExtension (LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2228 char szTemp
[MAX_PATH
];
2229 const char * pPoint
;
2230 LPCITEMIDLIST pidlTemp
= pidl
;
2232 TRACE("pidl=%p\n", pidl
);
2237 pidlTemp
= ILFindLastID(pidl
);
2239 if (!_ILIsValue(pidlTemp
))
2241 if (!_ILSimpleGetText(pidlTemp
, szTemp
, MAX_PATH
))
2244 pPoint
= PathFindExtensionA(szTemp
);
2250 lstrcpynA(pOut
, pPoint
, uOutSize
);
2251 TRACE("%s\n", pOut
);
2256 /*************************************************************************
2259 * Given the ItemIdList, get the file type description
2262 * pidl [I] The ItemIDList (simple)
2263 * pOut [I] The buffer to save the result
2264 * uOutsize [I] The size of the buffer
2270 * This function copies as much as possible into the buffer.
2272 void _ILGetFileType(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2276 if(_ILIsValue(pidl
))
2282 if (_ILGetExtension (pidl
, sType
, 64))
2284 if (HCR_MapTypeToValueA(sType
, sTemp
, 64, TRUE
))
2286 /* retrieve description */
2287 if(HCR_MapTypeToValueA(sTemp
, pOut
, uOutSize
, FALSE
))
2290 /* display Ext-file as description */
2291 strcpy(pOut
, sType
);
2293 /* load localized file string */
2295 if(LoadStringA(shell32_hInstance
, IDS_SHV_COLUMN1
, sTemp
, 64))
2299 strcat(pOut
, sTemp
);
2306 LoadStringA(shell32_hInstance
, IDS_DIRECTORY
, pOut
, uOutSize
);
2307 /* make sure its null terminated */
2308 pOut
[uOutSize
-1] = '\0';
2312 /*************************************************************************
2313 * _ILGetFileAttributes
2315 * Given the ItemIdList, get the Attrib string format
2318 * pidl [I] The ItemIDList
2319 * pOut [I] The buffer to save the result
2320 * uOutsize [I] The size of the Buffer
2326 * return value 0 in case of error is a valid return value
2329 DWORD
_ILGetFileAttributes(LPCITEMIDLIST pidl
, LPSTR pOut
, UINT uOutSize
)
2331 LPPIDLDATA pData
= _ILGetDataPointer(pidl
);
2342 wAttrib
= pData
->u
.file
.uFileAttribs
;
2349 if(wAttrib
& FILE_ATTRIBUTE_READONLY
)
2351 if(wAttrib
& FILE_ATTRIBUTE_HIDDEN
)
2353 if(wAttrib
& FILE_ATTRIBUTE_SYSTEM
)
2355 if(wAttrib
& FILE_ATTRIBUTE_ARCHIVE
)
2357 if(wAttrib
& FILE_ATTRIBUTE_COMPRESSED
)
2364 /*************************************************************************
2367 * free a aPidl struct
2369 void _ILFreeaPidl(LPITEMIDLIST
* apidl
, UINT cidl
)
2375 for (i
= 0; i
< cidl
; i
++)
2381 /*************************************************************************
2384 * copies an aPidl struct
2386 LPITEMIDLIST
* _ILCopyaPidl(const LPCITEMIDLIST
* apidlsrc
, UINT cidl
)
2389 LPITEMIDLIST
*apidldest
;
2391 apidldest
= (LPITEMIDLIST
*)SHAlloc(cidl
* sizeof(LPITEMIDLIST
));
2395 for (i
= 0; i
< cidl
; i
++)
2396 apidldest
[i
] = ILClone(apidlsrc
[i
]);
2401 /*************************************************************************
2402 * _ILCopyCidaToaPidl
2404 * creates aPidl from CIDA
2406 LPITEMIDLIST
* _ILCopyCidaToaPidl(LPITEMIDLIST
* pidl
, const CIDA
* cida
)
2411 dst
= (LPITEMIDLIST
*)SHAlloc(cida
->cidl
* sizeof(LPITEMIDLIST
));
2416 *pidl
= ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[0]]));
2418 for (i
= 0; i
< cida
->cidl
; i
++)
2419 dst
[i
] = ILClone((LPCITEMIDLIST
)(&((const BYTE
*)cida
)[cida
->aoffset
[i
+ 1]]));