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", 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 DWORD WINAPI ILGetSize(LPCITEMIDLIST pidl)
770 LPCSHITEMID si = &(pidl->mkid);
776 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
780 TRACE("pidl=%p size=%lu\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 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
877 TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
879 if(!pidl) return FALSE;
884 /*************************************************************************
885 * ILGlobalFree [SHELL32.156]
887 * Frees memory (if not NULL) allocated by Alloc allocator
893 * exported by ordinal.
895 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
903 /*************************************************************************
904 * ILCreateFromPathA [SHELL32.189]
906 * Creates a complex ItemIDList from a path and returns it.
912 * the newly created complex ItemIDList or NULL if failed
915 * exported by ordinal.
918 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
920 LPITEMIDLIST pidlnew = NULL;
922 TRACE_(shell)("%s\n", debugstr_a(path));
924 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
929 /*************************************************************************
930 * ILCreateFromPathW [SHELL32.190]
932 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
934 LPITEMIDLIST pidlnew = NULL;
936 TRACE_(shell)("%s\n", debugstr_w(path));
938 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
943 /*************************************************************************
944 * ILCreateFromPath [SHELL32.157]
946 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
948 if ( SHELL_OsIsUnicode())
949 return ILCreateFromPathW (path);
950 return ILCreateFromPathA (path);
953 /*************************************************************************
954 * _ILParsePathW [internal]
956 * Creates an ItemIDList from a path and returns it.
959 * path [I] path to parse and convert into an ItemIDList
960 * lpFindFile [I] pointer to buffer to initialize the FileSystem
961 * Bind Data object with
962 * bBindCtx [I] indicates to create a BindContext and assign a
963 * FileSystem Bind Data object
964 * ppidl [O] the newly create ItemIDList
965 * prgfInOut [I/O] requested attributes on input and actual
966 * attributes on return
969 * NO_ERROR on success or an OLE error code
972 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
973 * creates a BindContext object and assigns a FileSystem Bind Data object
974 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
975 * IShellFolder uses that FileSystem Bind Data object of the BindContext
976 * to pass data about the current path element to the next object. This
977 * is used to avoid having to verify the current path element on disk, so
978 * that creating an ItemIDList from a non-existent path still can work.
980 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
981 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
983 LPSHELLFOLDER pSF = NULL;
987 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
988 ppidl, ppidl ? *ppidl : NULL,
989 prgfInOut, prgfInOut ? *prgfInOut : 0);
991 ret = SHGetDesktopFolder(&pSF);
997 if (lpFindFile || bBindCtx)
998 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1002 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1007 IBindCtx_Release(pBC);
1011 IShellFolder_Release(pSF);
1013 if (!SUCCEEDED(ret) && ppidl)
1016 TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1021 /*************************************************************************
1022 * SHSimpleIDListFromPath [SHELL32.162]
1024 * Creates a simple ItemIDList from a path and returns it. This function
1025 * does not fail on non-existent paths.
1028 * path [I] path to parse and convert into an ItemIDList
1031 * the newly created simple ItemIDList
1034 * Simple in the name does not mean a relative ItemIDList but rather a
1035 * fully qualified list, where only the file name is filled in and the
1036 * directory flag for those ItemID elements this is known about, eg.
1037 * it is not the last element in the ItemIDList or the actual directory
1039 * exported by ordinal.
1041 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1043 LPITEMIDLIST pidl = NULL;
1044 LPWSTR wPath = NULL;
1047 TRACE("%s\n", debugstr_a(lpszPath));
1051 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1052 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1053 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1056 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1058 if (wPath) HeapFree(GetProcessHeap(), 0, wPath);
1059 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1063 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1065 LPITEMIDLIST pidl = NULL;
1067 TRACE("%s\n", debugstr_w(lpszPath));
1069 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1070 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1074 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1076 if ( SHELL_OsIsUnicode())
1077 return SHSimpleIDListFromPathW (lpszPath);
1078 return SHSimpleIDListFromPathA (lpszPath);
1081 /*************************************************************************
1082 * SHGetSpecialFolderLocation [SHELL32.@]
1084 * gets the folder locations from the registry and creates a pidl
1085 * creates missing reg keys and directories
1089 * nFolder [I] CSIDL_xxxxx
1090 * ppidl [O] PIDL of a special folder
1093 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
1094 * directory. If the directory is missing it returns a x80070002.
1096 HRESULT WINAPI SHGetSpecialFolderLocation(
1099 LPITEMIDLIST * ppidl)
1101 CHAR szPath[MAX_PATH];
1102 HRESULT hr = E_INVALIDARG;
1104 TRACE_(shell)("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
1112 *ppidl = _ILCreateDesktop();
1116 *ppidl = _ILCreateMyComputer();
1120 *ppidl = _ILCreateNetwork ();
1123 case CSIDL_CONTROLS:
1124 *ppidl = _ILCreateControl ();
1127 case CSIDL_PRINTERS:
1128 *ppidl = _ILCreatePrinter ();
1131 case CSIDL_BITBUCKET:
1132 *ppidl = _ILCreateBitBucket ();
1136 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
1139 TRACE_(shell)("Value=%s\n",szPath);
1140 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
1143 if(*ppidl) hr = NOERROR;
1146 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
1150 /*************************************************************************
1151 * SHGetFolderLocation [SHELL32.@]
1154 * the pidl can be a simple one. since we cant get the path out of the pidl
1155 * we have to take all data from the pidl
1157 HRESULT WINAPI SHGetFolderLocation(
1162 LPITEMIDLIST *ppidl)
1164 FIXME("%p 0x%08x %p 0x%08lx %p\n",
1165 hwnd, csidl, hToken, dwFlags, ppidl);
1166 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
1169 /*************************************************************************
1170 * SHGetDataFromIDListA [SHELL32.247]
1173 * the pidl can be a simple one. since we cant get the path out of the pidl
1174 * we have to take all data from the pidl
1176 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1178 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1181 if (!psf || !dest ) return E_INVALIDARG;
1185 case SHGDFIL_FINDDATA:
1187 LPSTR filename, shortname;
1188 WIN32_FIND_DATAA * pfd = dest;
1190 if (_ILIsDrive(pidl))
1191 return E_INVALIDARG;
1193 if (len < (int)sizeof(WIN32_FIND_DATAA)) return E_INVALIDARG;
1195 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1196 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1197 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1198 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1200 filename = _ILGetTextPointer(pidl);
1201 shortname = _ILGetSTextPointer(pidl);
1204 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1206 pfd->cFileName[0] = '\0';
1209 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1211 pfd->cAlternateFileName[0] = '\0';
1215 case SHGDFIL_NETRESOURCE:
1216 case SHGDFIL_DESCRIPTIONID:
1217 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1221 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1224 return E_INVALIDARG;
1227 /*************************************************************************
1228 * SHGetDataFromIDListW [SHELL32.248]
1231 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1233 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1237 if (! psf || !dest ) return E_INVALIDARG;
1241 case SHGDFIL_FINDDATA:
1243 LPSTR filename, shortname;
1244 WIN32_FIND_DATAW * pfd = dest;
1246 if (_ILIsDrive(pidl))
1247 return E_INVALIDARG;
1249 if (len < (int)sizeof(WIN32_FIND_DATAW)) return E_INVALIDARG;
1251 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1252 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1253 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1254 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1256 filename = _ILGetTextPointer(pidl);
1257 shortname = _ILGetSTextPointer(pidl);
1260 pfd->cFileName[0] = '\0';
1261 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1262 pfd->cFileName[MAX_PATH-1] = 0;
1265 pfd->cAlternateFileName[0] = '\0';
1266 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1267 pfd->cAlternateFileName[13] = 0;
1270 case SHGDFIL_NETRESOURCE:
1271 case SHGDFIL_DESCRIPTIONID:
1272 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1276 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1279 return E_INVALIDARG;
1282 /*************************************************************************
1283 * SHELL_GetPathFromIDListA
1285 HRESULT SHELL_GetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
1287 LPSTR pstr = pszPath;
1288 LPSTR end = pszPath + uOutSize;
1291 /* One case is a PIDL rooted at desktop level */
1292 if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1293 hr = SHGetSpecialFolderPathA(0, pstr, CSIDL_DESKTOP, FALSE);
1296 pstr = PathAddBackslashA(pstr);
1298 /* The only other valid case is a item ID list beginning at "My Computer" */
1299 else if (_ILIsMyComputer(pidl))
1300 pidl = ILGetNext(pidl);
1302 if (SUCCEEDED(hr)) {
1305 while(pidl && pidl->mkid.cb && pstr<end) {
1306 if (_ILIsSpecialFolder(pidl))
1307 {hr = E_INVALIDARG; break;}
1309 txt = _ILGetTextPointer(pidl);
1311 {hr = E_INVALIDARG; break;}
1313 lstrcpynA(pstr, txt, end-pstr);
1315 pidl = ILGetNext(pidl);
1317 {hr = E_INVALIDARG; break;}
1319 if (!pidl->mkid.cb) {
1320 /* We are at the end and successfully converted the complete PIDL. */
1324 pstr = PathAddBackslashA(pstr);
1326 {hr = E_INVALIDARG; break;}
1331 TRACE_(shell)("-- %s, 0x%08lx\n", pszPath, hr);
1335 /*************************************************************************
1336 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1340 * pszPath [OUT] path
1343 * path from a passed PIDL.
1346 * NULL returns FALSE
1347 * desktop pidl gives path to desktop directory back
1348 * special pidls returning FALSE
1350 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1354 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1360 hr = SHELL_GetPathFromIDListA(pidl, pszPath, MAX_PATH);
1362 return SUCCEEDED(hr);
1365 /*************************************************************************
1366 * SHELL_GetPathFromIDListW
1368 HRESULT SHELL_GetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
1370 LPWSTR pstr = pszPath;
1371 LPWSTR end = pszPath + uOutSize;
1374 /* One case is a PIDL rooted at desktop level */
1375 if (_ILIsValue(pidl) || _ILIsFolder(pidl)) {
1376 hr = SHGetSpecialFolderPathW(0, pstr, CSIDL_DESKTOP, FALSE);
1379 pstr = PathAddBackslashW(pstr);
1381 /* The only other valid case is a item ID list beginning at "My Computer" */
1382 else if (_ILIsMyComputer(pidl))
1383 pidl = ILGetNext(pidl);
1385 if (SUCCEEDED(hr)) {
1388 while(pidl && pidl->mkid.cb && pstr<end) {
1389 if (_ILIsSpecialFolder(pidl))
1390 {hr = E_INVALIDARG; break;}
1392 txt = _ILGetTextPointer(pidl);
1394 {hr = E_INVALIDARG; break;}
1396 if (!MultiByteToWideChar(CP_ACP, 0, txt, -1, pstr, uOutSize))
1397 {hr = E_OUTOFMEMORY; break;}
1399 pidl = ILGetNext(pidl);
1401 {hr = E_INVALIDARG; break;}
1403 if (!pidl->mkid.cb) {
1404 /* We are at the end and successfully converted the complete PIDL. */
1408 pstr = PathAddBackslashW(pstr);
1410 {hr = E_INVALIDARG; break;}
1415 TRACE_(shell)("-- %s, 0x%08lx\n", debugstr_w(pszPath), hr);
1419 /*************************************************************************
1420 * SHGetPathFromIDListW [SHELL32.@]
1422 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1426 TRACE_(shell)("(pidl=%p,%p)\n", pidl, debugstr_w(pszPath));
1432 hr = SHELL_GetPathFromIDListW(pidl, pszPath, MAX_PATH);
1434 TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr);
1435 return SUCCEEDED(hr);
1438 /*************************************************************************
1439 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1441 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1443 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1445 if (SHELL_OsIsUnicode())
1446 return SHGetPathFromIDListW(pidl,pszPath);
1447 return SHGetPathFromIDListA(pidl,pszPath);
1450 /*************************************************************************
1451 * SHBindToParent [shell version 5.0]
1453 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1456 LPITEMIDLIST pidlChild, pidlParent;
1459 TRACE_(shell)("pidl=%p\n", pidl);
1463 if (ppidlLast) *ppidlLast = NULL;
1465 if (_ILIsPidlSimple(pidl))
1467 /* we are on desktop level */
1469 *ppidlLast = ILClone(pidl);
1470 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1474 pidlChild = ILClone(ILFindLastID(pidl));
1475 pidlParent = ILClone(pidl);
1476 ILRemoveLastID(pidlParent);
1478 hr = SHGetDesktopFolder(&psf);
1481 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1483 if (SUCCEEDED(hr) && ppidlLast)
1484 *ppidlLast = pidlChild;
1488 SHFree (pidlParent);
1489 if (psf) IShellFolder_Release(psf);
1493 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1497 /**************************************************************************
1499 * internal functions
1501 * ### 1. section creating pidls ###
1503 *************************************************************************
1504 * _ILCreateDesktop()
1505 * _ILCreateIExplore()
1506 * _ILCreateMyComputer()
1511 LPITEMIDLIST _ILCreateDesktop()
1513 return _ILCreate(PT_DESKTOP, NULL, 0);
1516 LPITEMIDLIST _ILCreateMyComputer()
1518 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1521 LPITEMIDLIST _ILCreateIExplore()
1523 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1526 LPITEMIDLIST _ILCreateControl()
1528 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1531 LPITEMIDLIST _ILCreatePrinter()
1533 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1536 LPITEMIDLIST _ILCreateNetwork()
1538 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1541 LPITEMIDLIST _ILCreateBitBucket()
1543 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1546 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1548 lstrcpynA (sTemp,lpszNew,4);
1551 TRACE("(%s)\n",sTemp);
1552 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1555 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1557 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1558 char * pbuff = buff;
1562 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1564 /* prepare buffer with both names */
1565 len = strlen (stffile->cFileName) + 1;
1566 memcpy (pbuff, stffile->cFileName, len);
1569 if (stffile->cAlternateFileName)
1571 len1 = strlen (stffile->cAlternateFileName)+1;
1572 memcpy (pbuff, stffile->cAlternateFileName, len1);
1580 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1582 /* set attributes */
1586 pData = _ILGetDataPointer(pidl);
1587 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1588 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1589 pData->u.folder.uFileAttribs = stffile->dwFileAttributes;
1595 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1597 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1598 char * pbuff = buff;
1602 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1604 /* prepare buffer with both names */
1605 len = strlen (stffile->cFileName) + 1;
1606 memcpy (pbuff, stffile->cFileName, len);
1609 if (stffile->cAlternateFileName)
1611 len1 = strlen (stffile->cAlternateFileName)+1;
1612 memcpy (pbuff, stffile->cAlternateFileName, len1);
1620 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1622 /* set attributes */
1626 pData = _ILGetDataPointer(pidl);
1627 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1628 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1629 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1635 LPITEMIDLIST _ILCreateFromPathA(LPCSTR szPath)
1638 WIN32_FIND_DATAA stffile;
1639 LPITEMIDLIST pidl = NULL;
1641 hFile = FindFirstFileA(szPath, &stffile);
1642 if (hFile != INVALID_HANDLE_VALUE)
1644 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1645 pidl = _ILCreateFolder(&stffile);
1647 pidl = _ILCreateValue(&stffile);
1653 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1657 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1659 ERR("%s is not a GUID\n", szGUID);
1662 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1665 /**************************************************************************
1667 * Creates a new PIDL
1668 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1670 * uInSize = size of data (raw)
1673 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT uInSize)
1675 LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1680 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1689 uSize = 2 + 2 + sizeof(GUID);
1696 uSize = 2 + 12 + uInSize;
1699 FIXME("can't create type: 0x%08x\n",type);
1703 if(!(pidlOut = SHAlloc(uSize + 2))) return NULL;
1704 ZeroMemory(pidlOut, uSize + 2);
1705 pidlOut->mkid.cb = uSize;
1710 TRACE("- create Desktop\n");
1715 pData = _ILGetDataPointer(pidlOut);
1717 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1718 TRACE("-- create GUID-pidl %s\n", debugstr_guid(&(pData->u.mycomp.guid)));
1722 pData = _ILGetDataPointer(pidlOut);
1724 pszDest = _ILGetTextPointer(pidlOut);
1725 memcpy(pszDest, pIn, uInSize);
1726 TRACE("-- create Drive: %s\n",debugstr_a(pszDest));
1731 pData = _ILGetDataPointer(pidlOut);
1733 pszDest = _ILGetTextPointer(pidlOut);
1734 memcpy(pszDest, pIn, uInSize);
1735 TRACE("-- create Value: %s\n",debugstr_a(pszDest));
1739 pidlTemp = ILGetNext(pidlOut);
1741 pidlTemp->mkid.cb = 0x00;
1743 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1747 /**************************************************************************
1750 * Gets the text for the drive eg. 'c:\'
1755 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1756 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1758 if(_ILIsMyComputer(pidl))
1759 pidl = ILGetNext(pidl);
1761 if (pidl && _ILIsDrive(pidl))
1762 return _ILSimpleGetText(pidl, pOut, uSize);
1767 /**************************************************************************
1769 * ### 2. section testing pidls ###
1771 **************************************************************************
1774 * _ILIsSpecialFolder()
1780 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1781 { TRACE("(%p)\n",pidl);
1782 return pidl && pidl->mkid.cb ? 0 : 1;
1785 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1787 REFIID iid = _ILGetGUIDPointer(pidl);
1789 TRACE("(%p)\n",pidl);
1792 return IsEqualIID(iid, &CLSID_MyComputer);
1796 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1798 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1799 TRACE("(%p)\n",pidl);
1800 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1801 (pidl && pidl->mkid.cb == 0x00)
1805 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1806 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1807 TRACE("(%p)\n",pidl);
1808 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1809 PT_DRIVE1 == lpPData->type ||
1810 PT_DRIVE2 == lpPData->type ||
1811 PT_DRIVE3 == lpPData->type));
1814 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1815 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1816 TRACE("(%p)\n",pidl);
1817 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1820 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1821 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1822 TRACE("(%p)\n",pidl);
1823 return (pidl && lpPData && PT_VALUE == lpPData->type);
1826 /**************************************************************************
1829 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1833 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1835 WORD len = pidl->mkid.cb;
1836 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1837 if (pidlnext->mkid.cb)
1841 TRACE("%s\n", ret ? "Yes" : "No");
1845 /**************************************************************************
1847 * ### 3. section getting values from pidls ###
1850 /**************************************************************************
1853 * gets the text for the first item in the pidl (eg. simple pidl)
1855 * returns the length of the string
1857 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1862 char szTemp[MAX_PATH];
1864 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1866 if (!pidl) return 0;
1871 if (_ILIsDesktop(pidl))
1874 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1877 lstrcpynA(szOut, szTemp, uOutSize);
1879 dwReturn = strlen (szTemp);
1882 else if (( szSrc = _ILGetTextPointer(pidl) ))
1886 lstrcpynA(szOut, szSrc, uOutSize);
1888 dwReturn = strlen(szSrc);
1890 else if (( riid = _ILGetGUIDPointer(pidl) ))
1892 /* special folder */
1893 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1896 lstrcpynA(szOut, szTemp, uOutSize);
1898 dwReturn = strlen (szTemp);
1903 ERR("-- no text\n");
1906 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
1910 /**************************************************************************
1913 * gets the text for the first item in the pidl (eg. simple pidl)
1915 * returns the length of the string
1917 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1920 char szTemp[MAX_PATH];
1922 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1924 dwReturn = _ILSimpleGetText(pidl, szTemp, uOutSize);
1926 if (!MultiByteToWideChar(CP_ACP, 0, szTemp, -1, szOut, MAX_PATH))
1929 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_w(szOut),dwReturn);
1933 /**************************************************************************
1935 * ### 4. getting pointers to parts of pidls ###
1937 **************************************************************************
1938 * _ILGetDataPointer()
1940 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1942 if(pidl && pidl->mkid.cb != 0x00)
1943 return (LPPIDLDATA) &(pidl->mkid.abID);
1947 /**************************************************************************
1948 * _ILGetTextPointer()
1949 * gets a pointer to the long filename string stored in the pidl
1951 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1952 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1954 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1958 switch (pdata->type)
1968 return (LPSTR)&(pdata->u.drive.szDriveName);
1976 return (LPSTR)&(pdata->u.file.szNames);
1981 case PT_NETPROVIDER:
1983 return (LPSTR)&(pdata->u.network.szNames);
1989 /**************************************************************************
1990 * _ILGetSTextPointer()
1991 * gets a pointer to the short filename string stored in the pidl
1993 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1994 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1996 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2000 switch (pdata->type)
2007 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
2010 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
2016 /**************************************************************************
2017 * _ILGetGUIDPointer()
2019 * returns reference to guid stored in some pidls
2021 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2023 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2025 TRACE("%p\n", pidl);
2029 TRACE("pdata->type 0x%04x\n", pdata->type);
2030 switch (pdata->type)
2034 return (REFIID) &(pdata->u.mycomp.guid);
2037 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2044 /*************************************************************************
2045 * _ILGetFileDateTime
2047 * Given the ItemIdList, get the FileTime
2050 * pidl [I] The ItemIDList
2051 * pFt [I] the resulted FILETIME of the file
2054 * True if Successful
2059 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2061 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2063 if(! pdata) return FALSE;
2065 switch (pdata->type)
2068 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
2071 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2079 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2085 if (_ILGetFileDateTime( pidl, &ft )) {
2086 FileTimeToLocalFileTime(&ft, &lft);
2087 FileTimeToSystemTime (&lft, &time);
2088 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2097 /*************************************************************************
2100 * Given the ItemIdList, get the FileSize
2103 * pidl [I] The ItemIDList
2104 * pOut [I] The buffer to save the result
2105 * uOutsize [I] The size of the buffer
2111 * pOut can be null when no string is needed
2114 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2116 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2119 if(! pdata) return 0;
2121 switch (pdata->type)
2124 dwSize = pdata->u.file.dwFileSize;
2125 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
2128 if (pOut) *pOut = 0x00;
2132 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2134 char szTemp[MAX_PATH];
2135 const char * pPoint;
2136 LPCITEMIDLIST pidlTemp=pidl;
2138 TRACE("pidl=%p\n",pidl);
2140 if (!pidl) return FALSE;
2142 pidlTemp = ILFindLastID(pidl);
2144 if (!_ILIsValue(pidlTemp)) return FALSE;
2145 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
2147 pPoint = PathFindExtensionA(szTemp);
2149 if (! *pPoint) return FALSE;
2152 lstrcpynA(pOut, pPoint, uOutSize);
2158 /*************************************************************************
2161 * Given the ItemIdList, get the file type description
2164 * pidl [I] The ItemIDList (simple)
2165 * pOut [I] The buffer to save the result
2166 * uOutsize [I] The size of the buffer
2172 * This function copies as much as possible into the buffer.
2174 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2176 if(_ILIsValue(pidl))
2183 if (_ILGetExtension (pidl, sTemp, 64))
2185 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2186 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2188 lstrcpynA (pOut, sTemp, uOutSize - 6);
2189 strcat (pOut, "-file");
2195 lstrcpynA(pOut, "Folder", uOutSize);
2199 /*************************************************************************
2200 * _ILGetFileAttributes
2202 * Given the ItemIdList, get the Attrib string format
2205 * pidl [I] The ItemIDList
2206 * pOut [I] The buffer to save the result
2207 * uOutsize [I] The size of the Buffer
2213 * return value 0 in case of error is a valid return value
2216 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2218 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2222 if(! pData) return 0;
2227 wAttrib = pData->u.folder.uFileAttribs;
2230 wAttrib = pData->u.file.uFileAttribs;
2237 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2241 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2245 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2249 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2253 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2262 /*************************************************************************
2265 * free a aPidl struct
2267 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2273 for (i = 0; i < cidl; i++) SHFree(apidl[i]);
2278 /*************************************************************************
2281 * copies an aPidl struct
2283 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2286 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
2287 if(!apidlsrc) return NULL;
2289 for (i = 0; i < cidl; i++)
2290 apidldest[i] = ILClone(apidlsrc[i]);
2295 /*************************************************************************
2296 * _ILCopyCidaToaPidl
2298 * creates aPidl from CIDA
2300 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2303 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2305 if(!dst) return NULL;
2308 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2310 for (i = 0; i < cida->cidl; i++)
2311 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));