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
26 #include "wine/port.h"
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
44 #include "undocshell.h"
45 #include "shell32_main.h"
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
53 WINE_DECLARE_DEBUG_CHANNEL(shell);
55 /* from comctl32.dll */
56 extern LPVOID WINAPI Alloc(INT);
57 extern BOOL WINAPI Free(LPVOID);
59 /*************************************************************************
60 * ILGetDisplayNameEx [SHELL32.186]
62 * Retrieves the display name of an ItemIDList
65 * psf [I] Shell Folder to start with, if NULL the desktop is used
66 * pidl [I] ItemIDList relativ to the psf to get the display name for
67 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
68 * type [I] Type of display name to retrieve
69 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
70 * 1 = SHGDN_NORMAL relative to the root folder
71 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
74 * True if the display name could be retrieved successfully, False otherwise
76 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
79 WCHAR wPath[MAX_PATH];
81 TRACE("%p %p %p %d\n", psf, pidl, path, type);
86 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
87 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
88 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
93 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
95 LPSHELLFOLDER psfParent, lsf = psf;
96 HRESULT ret = NO_ERROR;
97 LPCITEMIDLIST pidllast;
101 TRACE("%p %p %p %d\n", psf, pidl, path, type);
108 ret = SHGetDesktopFolder(&lsf);
113 if (type >= 0 && type <= 2)
117 case ILGDN_FORPARSING:
118 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
124 flag = SHGDN_INFOLDER;
127 FIXME("Unknown type parameter = %x\n", type);
128 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
131 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
133 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
136 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
142 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
145 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
148 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
151 IShellFolder_Release(psfParent);
156 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
159 IShellFolder_Release(lsf);
160 return SUCCEEDED(ret);
163 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
165 TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
167 if (SHELL_OsIsUnicode())
168 return ILGetDisplayNameExW(psf, pidl, path, type);
169 return ILGetDisplayNameExA(psf, pidl, path, type);
172 /*************************************************************************
173 * ILGetDisplayName [SHELL32.15]
175 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
177 TRACE_(shell)("%p %p\n", pidl, path);
179 if (SHELL_OsIsUnicode())
180 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
181 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
184 /*************************************************************************
185 * ILFindLastID [SHELL32.16]
188 * observed: pidl=Desktop return=pidl
190 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
192 LPCITEMIDLIST pidlLast = pidl;
194 TRACE("(pidl=%p)\n",pidl);
199 while (pidl->mkid.cb)
202 pidl = ILGetNext(pidl);
204 return (LPITEMIDLIST)pidlLast;
207 /*************************************************************************
208 * ILRemoveLastID [SHELL32.17]
211 * when pidl=Desktop return=FALSE
213 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
215 TRACE_(shell)("pidl=%p\n",pidl);
217 if (!pidl || !pidl->mkid.cb)
219 ILFindLastID(pidl)->mkid.cb = 0;
223 /*************************************************************************
224 * ILClone [SHELL32.18]
227 * duplicate an idlist
229 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
232 LPITEMIDLIST newpidl;
237 len = ILGetSize(pidl);
238 newpidl = (LPITEMIDLIST)SHAlloc(len);
240 memcpy(newpidl,pidl,len);
242 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
248 /*************************************************************************
249 * ILCloneFirst [SHELL32.19]
252 * duplicates the first idlist of a complex pidl
254 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
257 LPITEMIDLIST pidlNew = NULL;
259 TRACE("pidl=%p\n", pidl);
265 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
268 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
271 ILGetNext(pidlNew)->mkid.cb = 0x00;
274 TRACE("-- newpidl=%p\n",pidlNew);
279 /*************************************************************************
280 * ILLoadFromStream (SHELL32.26)
283 * the first two bytes are the len, the pidl is following then
285 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
289 HRESULT ret = E_FAIL;
292 TRACE_(shell)("%p %p\n", pStream , ppPidl);
297 IStream_AddRef (pStream);
299 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
301 TRACE("PIDL length is %d\n", wLen);
304 *ppPidl = SHAlloc (wLen);
305 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
307 TRACE("Stream read OK\n");
312 WARN("reading pidl failed\n");
324 /* we are not yet fully compatible */
325 if (*ppPidl && !pcheck(*ppPidl))
327 WARN("Check failed\n");
332 IStream_Release (pStream);
337 /*************************************************************************
338 * ILSaveToStream (SHELL32.27)
341 * the first two bytes are the len, the pidl is following then
343 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
347 HRESULT ret = E_FAIL;
349 TRACE_(shell)("%p %p\n", pStream, pPidl);
351 IStream_AddRef (pStream);
354 while (pidl->mkid.cb)
356 wLen += sizeof(WORD) + pidl->mkid.cb;
357 pidl = ILGetNext(pidl);
360 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
362 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
365 IStream_Release (pStream);
370 /*************************************************************************
371 * SHILCreateFromPath [SHELL32.28]
373 * Create an ItemIDList from a path
378 * attributes [I/O] requested attributes on call and actual attributes when
379 * the function returns
382 * NO_ERROR if successful, or an OLE errer code otherwise
385 * Wrapper for IShellFolder_ParseDisplayName().
387 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
389 WCHAR lpszDisplayName[MAX_PATH];
391 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
393 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
394 lpszDisplayName[MAX_PATH-1] = 0;
396 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
399 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
403 HRESULT ret = E_FAIL;
405 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
407 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
409 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
410 IShellFolder_Release(sf);
415 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
417 if ( SHELL_OsIsUnicode())
418 return SHILCreateFromPathW (path, ppidl, attributes);
419 return SHILCreateFromPathA (path, ppidl, attributes);
422 /*************************************************************************
423 * SHCloneSpecialIDList [SHELL32.89]
425 * Create an ItemIDList to one of the special folders.
429 * nFolder [in] CSIDL_xxxxx
430 * fCreate [in] Create folder if it does not exist
433 * Success: The newly created pidl
434 * Failure: NULL, if inputs are invalid.
437 * exported by ordinal.
438 * Caller is responsible for deallocating the returned ItemIDList with the
439 * shells IMalloc interface, aka ILFree.
441 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
444 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
447 nFolder |= CSIDL_FLAG_CREATE;
449 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
453 /*************************************************************************
454 * ILGlobalClone [SHELL32.20]
456 * Clones an ItemIDList using Alloc.
459 * pidl [I] ItemIDList to clone
462 * Newly allocated ItemIDList.
465 * exported by ordinal.
467 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
470 LPITEMIDLIST newpidl;
475 len = ILGetSize(pidl);
476 newpidl = (LPITEMIDLIST)Alloc(len);
478 memcpy(newpidl,pidl,len);
480 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
486 /*************************************************************************
487 * ILIsEqual [SHELL32.21]
490 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
492 char szData1[MAX_PATH];
493 char szData2[MAX_PATH];
495 LPCITEMIDLIST pidltemp1 = pidl1;
496 LPCITEMIDLIST pidltemp2 = pidl2;
498 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
501 * Explorer reads from registry directly (StreamMRU),
502 * so we can only check here
504 if (!pcheck(pidl1) || !pcheck (pidl2))
510 if (!pidl1 || !pidl2)
513 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
515 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
516 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
518 if (strcasecmp( szData1, szData2 ))
521 pidltemp1 = ILGetNext(pidltemp1);
522 pidltemp2 = ILGetNext(pidltemp2);
525 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
531 /*************************************************************************
532 * ILIsParent [SHELL32.23]
534 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
539 * bImmediate [I] only return true if the parent is the direct parent
543 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
547 * parent = a/b, child = a/b/c -> true, c is in folder a/b
548 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
549 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
551 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
553 char szData1[MAX_PATH];
554 char szData2[MAX_PATH];
555 LPCITEMIDLIST pParent = pidlParent;
556 LPCITEMIDLIST pChild = pidlChild;
558 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
560 if (!pParent || !pChild)
563 while (pParent->mkid.cb && pChild->mkid.cb)
565 _ILSimpleGetText(pParent, szData1, MAX_PATH);
566 _ILSimpleGetText(pChild, szData2, MAX_PATH);
568 if (strcasecmp( szData1, szData2 ))
571 pParent = ILGetNext(pParent);
572 pChild = ILGetNext(pChild);
575 /* child shorter or has equal length to parent */
576 if (pParent->mkid.cb || !pChild->mkid.cb)
579 /* not immediate descent */
580 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
586 /*************************************************************************
587 * ILFindChild [SHELL32.24]
589 * Compares elements from pidl1 and pidl2.
596 * pidl1 is desktop pidl2
597 * pidl1 shorter pidl2 pointer to first different element of pidl2
598 * if there was at least one equal element
599 * pidl2 shorter pidl1 0
600 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
603 * exported by ordinal.
605 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
607 char szData1[MAX_PATH];
608 char szData2[MAX_PATH];
610 LPCITEMIDLIST pidltemp1 = pidl1;
611 LPCITEMIDLIST pidltemp2 = pidl2;
612 LPCITEMIDLIST ret=NULL;
614 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
616 /* explorer reads from registry directly (StreamMRU),
617 so we can only check here */
618 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
624 if (_ILIsDesktop(pidl1))
630 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
632 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
633 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
635 if (strcasecmp(szData1,szData2))
638 pidltemp1 = ILGetNext(pidltemp1);
639 pidltemp2 = ILGetNext(pidltemp2);
643 if (pidltemp1->mkid.cb)
644 ret = NULL; /* elements of pidl1 left*/
646 TRACE_(shell)("--- %p\n", ret);
647 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
650 /*************************************************************************
651 * ILCombine [SHELL32.25]
653 * Concatenates two complex ItemIDLists.
656 * pidl1 [I] first complex ItemIDLists
657 * pidl2 [I] complex ItemIDLists to append
660 * if both pidl's == NULL NULL
661 * if pidl1 == NULL cloned pidl2
662 * if pidl2 == NULL cloned pidl1
663 * otherwise new pidl with pidl2 appended to pidl1
666 * exported by ordinal.
667 * Does not destroy the passed in ItemIDLists!
669 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
672 LPITEMIDLIST pidlNew;
674 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
676 if (!pidl1 && !pidl2) return NULL;
683 pidlNew = ILClone(pidl2);
689 pidlNew = ILClone(pidl1);
693 len1 = ILGetSize(pidl1)-2;
694 len2 = ILGetSize(pidl2);
695 pidlNew = SHAlloc(len1+len2);
699 memcpy(pidlNew,pidl1,len1);
700 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
703 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
707 /*************************************************************************
708 * SHGetRealIDL [SHELL32.98]
712 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
714 IDataObject* pDataObj;
717 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
718 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
724 fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
726 fmt.dwAspect = DVASPECT_CONTENT;
728 fmt.tymed = TYMED_HGLOBAL;
730 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
732 IDataObject_Release(pDataObj);
736 /*assert(pida->cidl==1);*/
737 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
739 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
740 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
742 *pidlReal = ILCombine(pidl_folder, pidl_child);
747 GlobalUnlock(medium.u.hGlobal);
748 GlobalFree(medium.u.hGlobal);
755 /*************************************************************************
756 * SHLogILFromFSIL [SHELL32.95]
759 * pild = CSIDL_DESKTOP ret = 0
760 * pild = CSIDL_DRIVES ret = 0
762 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
764 FIXME("(pidl=%p)\n",pidl);
771 /*************************************************************************
772 * ILGetSize [SHELL32.152]
774 * Gets the byte size of an ItemIDList including zero terminator
777 * pidl [I] ItemIDList
780 * size of pidl in bytes
783 * exported by ordinal
785 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
787 LPCSHITEMID si = &(pidl->mkid);
795 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
799 TRACE("pidl=%p size=%u\n",pidl, len);
803 /*************************************************************************
804 * ILGetNext [SHELL32.153]
806 * Gets the next ItemID of an ItemIDList
809 * pidl [I] ItemIDList
814 * simple pidl -> pointer to 0x0000 element
817 * exported by ordinal.
819 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
830 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
831 TRACE("-- %p\n", pidl);
832 return (LPITEMIDLIST)pidl;
838 /*************************************************************************
839 * ILAppend [SHELL32.154]
841 * Adds the single ItemID item to the ItemIDList indicated by pidl.
842 * If bEnd is FALSE, inserts the item in the front of the list,
843 * otherwise it adds the item to the end. (???)
846 * pidl [I] ItemIDList to extend
847 * item [I] ItemID to prepend/append
848 * bEnd [I] Indicates if the item should be appended
851 * Destroys the passed in idlist! (???)
853 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
857 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
862 if (_ILIsDesktop(pidl))
864 idlRet = ILClone(item);
870 idlRet = ILCombine(pidl, item);
872 idlRet = ILCombine(item, pidl);
878 /*************************************************************************
879 * ILFree [SHELL32.155]
881 * Frees memory (if not NULL) allocated by SHMalloc allocator
890 * exported by ordinal
892 void WINAPI ILFree(LPITEMIDLIST pidl)
894 TRACE("(pidl=%p)\n",pidl);
898 /*************************************************************************
899 * ILGlobalFree [SHELL32.156]
901 * Frees memory (if not NULL) allocated by Alloc allocator
910 * exported by ordinal.
912 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
919 /*************************************************************************
920 * ILCreateFromPathA [SHELL32.189]
922 * Creates a complex ItemIDList from a path and returns it.
928 * the newly created complex ItemIDList or NULL if failed
931 * exported by ordinal.
933 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
935 LPITEMIDLIST pidlnew = NULL;
937 TRACE_(shell)("%s\n", debugstr_a(path));
939 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
944 /*************************************************************************
945 * ILCreateFromPathW [SHELL32.190]
947 * See ILCreateFromPathA.
949 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
951 LPITEMIDLIST pidlnew = NULL;
953 TRACE_(shell)("%s\n", debugstr_w(path));
955 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
960 /*************************************************************************
961 * ILCreateFromPath [SHELL32.157]
963 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
965 if ( SHELL_OsIsUnicode())
966 return ILCreateFromPathW (path);
967 return ILCreateFromPathA (path);
970 /*************************************************************************
971 * _ILParsePathW [internal]
973 * Creates an ItemIDList from a path and returns it.
976 * path [I] path to parse and convert into an ItemIDList
977 * lpFindFile [I] pointer to buffer to initialize the FileSystem
978 * Bind Data object with
979 * bBindCtx [I] indicates to create a BindContext and assign a
980 * FileSystem Bind Data object
981 * ppidl [O] the newly create ItemIDList
982 * prgfInOut [I/O] requested attributes on input and actual
983 * attributes on return
986 * NO_ERROR on success or an OLE error code
989 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
990 * creates a BindContext object and assigns a FileSystem Bind Data object
991 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
992 * IShellFolder uses that FileSystem Bind Data object of the BindContext
993 * to pass data about the current path element to the next object. This
994 * is used to avoid having to verify the current path element on disk, so
995 * that creating an ItemIDList from a nonexistent path still can work.
997 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
998 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
1000 LPSHELLFOLDER pSF = NULL;
1004 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
1005 ppidl, ppidl ? *ppidl : NULL,
1006 prgfInOut, prgfInOut ? *prgfInOut : 0);
1008 ret = SHGetDesktopFolder(&pSF);
1012 if (lpFindFile || bBindCtx)
1013 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1017 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1022 IBindCtx_Release(pBC);
1026 IShellFolder_Release(pSF);
1028 if (!SUCCEEDED(ret) && ppidl)
1031 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1036 /*************************************************************************
1037 * SHSimpleIDListFromPath [SHELL32.162]
1039 * Creates a simple ItemIDList from a path and returns it. This function
1040 * does not fail on nonexistent paths.
1043 * path [I] path to parse and convert into an ItemIDList
1046 * the newly created simple ItemIDList
1049 * Simple in the name does not mean a relative ItemIDList but rather a
1050 * fully qualified list, where only the file name is filled in and the
1051 * directory flag for those ItemID elements this is known about, eg.
1052 * it is not the last element in the ItemIDList or the actual directory
1054 * exported by ordinal.
1056 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1058 LPITEMIDLIST pidl = NULL;
1059 LPWSTR wPath = NULL;
1062 TRACE("%s\n", debugstr_a(lpszPath));
1066 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1067 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1068 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1071 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1073 HeapFree(GetProcessHeap(), 0, wPath);
1074 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1078 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1080 LPITEMIDLIST pidl = NULL;
1082 TRACE("%s\n", debugstr_w(lpszPath));
1084 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1085 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1089 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1091 if ( SHELL_OsIsUnicode())
1092 return SHSimpleIDListFromPathW (lpszPath);
1093 return SHSimpleIDListFromPathA (lpszPath);
1096 /*************************************************************************
1097 * SHGetDataFromIDListA [SHELL32.247]
1100 * the pidl can be a simple one. since we can't get the path out of the pidl
1101 * we have to take all data from the pidl
1103 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1104 int nFormat, LPVOID dest, int len)
1106 LPSTR filename, shortname;
1107 WIN32_FIND_DATAA * pfd;
1109 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1113 return E_INVALIDARG;
1117 case SHGDFIL_FINDDATA:
1120 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1121 return E_INVALIDARG;
1123 if (len < sizeof(WIN32_FIND_DATAA))
1124 return E_INVALIDARG;
1126 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1127 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1128 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1129 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1131 filename = _ILGetTextPointer(pidl);
1132 shortname = _ILGetSTextPointer(pidl);
1135 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1137 pfd->cFileName[0] = '\0';
1140 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1142 pfd->cAlternateFileName[0] = '\0';
1145 case SHGDFIL_NETRESOURCE:
1146 case SHGDFIL_DESCRIPTIONID:
1147 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1151 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1154 return E_INVALIDARG;
1157 /*************************************************************************
1158 * SHGetDataFromIDListW [SHELL32.248]
1161 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1162 int nFormat, LPVOID dest, int len)
1164 LPSTR filename, shortname;
1165 WIN32_FIND_DATAW * pfd = dest;
1167 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1172 return E_INVALIDARG;
1176 case SHGDFIL_FINDDATA:
1179 if (_ILIsDrive(pidl))
1180 return E_INVALIDARG;
1182 if (len < sizeof(WIN32_FIND_DATAW))
1183 return E_INVALIDARG;
1185 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1186 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1187 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1188 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1190 filename = _ILGetTextPointer(pidl);
1191 shortname = _ILGetSTextPointer(pidl);
1194 pfd->cFileName[0] = '\0';
1195 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1196 pfd->cFileName[MAX_PATH-1] = 0;
1199 pfd->cAlternateFileName[0] = '\0';
1200 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1201 pfd->cAlternateFileName[13] = 0;
1204 case SHGDFIL_NETRESOURCE:
1205 case SHGDFIL_DESCRIPTIONID:
1206 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1210 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1213 return E_INVALIDARG;
1216 /*************************************************************************
1217 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1221 * pszPath [OUT] path
1224 * path from a passed PIDL.
1227 * NULL returns FALSE
1228 * desktop pidl gives path to desktop directory back
1229 * special pidls returning FALSE
1231 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1233 WCHAR wszPath[MAX_PATH];
1236 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1237 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1242 /*************************************************************************
1243 * SHGetPathFromIDListW [SHELL32.@]
1245 * See SHGetPathFromIDListA.
1247 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1250 LPCITEMIDLIST pidlLast;
1251 LPSHELLFOLDER psfFolder;
1255 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1262 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1263 if (FAILED(hr)) return FALSE;
1265 dwAttributes = SFGAO_FILESYSTEM;
1266 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1267 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1268 IShellFolder_Release(psfFolder);
1272 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1273 IShellFolder_Release(psfFolder);
1274 if (FAILED(hr)) return FALSE;
1276 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1278 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1279 return SUCCEEDED(hr);
1282 /*************************************************************************
1283 * SHBindToParent [shell version 5.0]
1285 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1287 IShellFolder * psfDesktop;
1290 TRACE_(shell)("pidl=%p\n", pidl);
1294 return E_INVALIDARG;
1300 hr = SHGetDesktopFolder(&psfDesktop);
1304 if (_ILIsPidlSimple(pidl))
1306 /* we are on desktop level */
1307 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1311 LPITEMIDLIST pidlParent = ILClone(pidl);
1312 ILRemoveLastID(pidlParent);
1313 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1314 SHFree (pidlParent);
1317 IShellFolder_Release(psfDesktop);
1319 if (SUCCEEDED(hr) && ppidlLast)
1320 *ppidlLast = ILFindLastID(pidl);
1322 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1326 /**************************************************************************
1328 * internal functions
1330 * ### 1. section creating pidls ###
1332 *************************************************************************
1334 LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1336 LPITEMIDLIST pidlOut = NULL;
1338 pidlOut = SHAlloc(size + 5);
1342 LPITEMIDLIST pidlNext;
1344 ZeroMemory(pidlOut, size + 5);
1345 pidlOut->mkid.cb = size + 3;
1347 pData = _ILGetDataPointer(pidlOut);
1351 pidlNext = ILGetNext(pidlOut);
1353 pidlNext->mkid.cb = 0x00;
1354 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1360 LPITEMIDLIST _ILCreateDesktop(void)
1371 LPITEMIDLIST _ILCreateMyComputer(void)
1374 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1377 LPITEMIDLIST _ILCreateMyDocuments(void)
1380 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1383 LPITEMIDLIST _ILCreateIExplore(void)
1386 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1389 LPITEMIDLIST _ILCreateControlPanel(void)
1391 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1396 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1400 ret = ILCombine(parent, cpl);
1408 LPITEMIDLIST _ILCreatePrinters(void)
1410 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1415 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1419 ret = ILCombine(parent, printers);
1427 LPITEMIDLIST _ILCreateNetwork(void)
1430 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1433 LPITEMIDLIST _ILCreateBitBucket(void)
1436 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1439 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1441 LPITEMIDLIST pidlOut;
1443 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1445 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1448 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1450 memcpy(&(pData->u.guid.guid), guid, sizeof(GUID));
1451 TRACE("-- create GUID-pidl %s\n",
1452 debugstr_guid(&(pData->u.guid.guid)));
1457 WARN("%d: invalid type for GUID\n", type);
1463 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1467 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1469 ERR("%s is not a GUID\n", szGUID);
1472 return _ILCreateGuid(PT_GUID, &iid);
1475 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1479 if (!SUCCEEDED(SHCLSIDFromStringW(szGUID, &iid)))
1481 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1484 return _ILCreateGuid(PT_GUID, &iid);
1487 LPITEMIDLIST _ILCreateFromFindDataW( WIN32_FIND_DATAW *wfd )
1489 /* FIXME: should make unicode PIDLs */
1490 WIN32_FIND_DATAA fda;
1492 memset( &fda, 0, sizeof fda );
1493 fda.dwFileAttributes = wfd->dwFileAttributes;
1494 fda.ftCreationTime = wfd->ftCreationTime;
1495 fda.ftLastAccessTime = wfd->ftLastAccessTime;
1496 fda.ftLastWriteTime = wfd->ftLastWriteTime;
1497 fda.nFileSizeHigh = wfd->nFileSizeHigh;
1498 fda.nFileSizeLow = wfd->nFileSizeLow;
1499 fda.dwReserved0 = wfd->dwReserved0;
1500 fda.dwReserved1 = wfd->dwReserved1;
1501 WideCharToMultiByte( CP_ACP, 0, wfd->cFileName, -1,
1502 fda.cFileName, MAX_PATH, NULL, NULL );
1503 return _ILCreateFromFindDataA( &fda );
1506 LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
1508 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1509 char * pbuff = buff;
1517 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1519 /* prepare buffer with both names */
1520 len = strlen (stffile->cFileName) + 1;
1521 memcpy (pbuff, stffile->cFileName, len);
1524 len1 = strlen (stffile->cAlternateFileName)+1;
1525 memcpy (pbuff, stffile->cAlternateFileName, len1);
1527 type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1530 * FileStruct already has one byte for the first name, so use len - 1 in
1533 pidl = _ILAlloc(type, sizeof(FileStruct) + (len - 1) + len1);
1539 /* set attributes */
1540 pData = _ILGetDataPointer(pidl);
1544 FileTimeToDosDateTime( &(stffile->ftLastWriteTime),
1545 &pData->u.file.uFileDate, &pData->u.file.uFileTime);
1546 pData->u.file.dwFileSize = stffile->nFileSizeLow;
1547 pData->u.file.uFileAttribs = (WORD)stffile->dwFileAttributes;
1549 pszDest = _ILGetTextPointer(pidl);
1552 memcpy(pszDest, buff, len + len1);
1553 TRACE("-- create Value: %s\n",debugstr_a(pszDest));
1559 HRESULT _ILCreateFromPathA(LPCSTR szPath, LPITEMIDLIST* ppidl)
1562 WIN32_FIND_DATAA stffile;
1565 return E_INVALIDARG;
1567 hFile = FindFirstFileA(szPath, &stffile);
1568 if (hFile == INVALID_HANDLE_VALUE)
1569 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1573 *ppidl = _ILCreateFromFindDataA(&stffile);
1575 return *ppidl ? S_OK : E_OUTOFMEMORY;
1578 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1581 WIN32_FIND_DATAW stffile;
1584 return E_INVALIDARG;
1586 hFile = FindFirstFileW(szPath, &stffile);
1587 if (hFile == INVALID_HANDLE_VALUE)
1588 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1592 *ppidl = _ILCreateFromFindDataW(&stffile);
1594 return *ppidl ? S_OK : E_OUTOFMEMORY;
1597 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1599 LPITEMIDLIST pidlOut;
1601 TRACE("(%s)\n",debugstr_w(lpszNew));
1603 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1608 pszDest = _ILGetTextPointer(pidlOut);
1611 strcpy(pszDest, "x:\\");
1612 pszDest[0]=toupperW(lpszNew[0]);
1613 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1619 /**************************************************************************
1622 * Gets the text for the drive eg. 'c:\'
1627 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1629 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1631 if(_ILIsMyComputer(pidl))
1632 pidl = ILGetNext(pidl);
1634 if (pidl && _ILIsDrive(pidl))
1635 return _ILSimpleGetText(pidl, pOut, uSize);
1640 /**************************************************************************
1642 * ### 2. section testing pidls ###
1644 **************************************************************************
1647 * _ILIsSpecialFolder()
1653 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1655 TRACE("(%p)\n",pidl);
1657 return pidl && pidl->mkid.cb ? 0 : 1;
1660 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1662 REFIID iid = _ILGetGUIDPointer(pidl);
1664 TRACE("(%p)\n",pidl);
1667 return IsEqualIID(iid, &CLSID_MyComputer);
1671 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1673 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1675 TRACE("(%p)\n",pidl);
1677 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1678 (pidl && pidl->mkid.cb == 0x00)
1682 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1684 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1686 TRACE("(%p)\n",pidl);
1688 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1689 PT_DRIVE1 == lpPData->type ||
1690 PT_DRIVE2 == lpPData->type ||
1691 PT_DRIVE3 == lpPData->type));
1694 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1696 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1698 TRACE("(%p)\n",pidl);
1700 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1703 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1705 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1707 TRACE("(%p)\n",pidl);
1709 return (pidl && lpPData && PT_VALUE == lpPData->type);
1712 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1714 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1716 TRACE("(%p)\n",pidl);
1718 return (pidl && lpPData && (lpPData->type == 0));
1721 /**************************************************************************
1724 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1728 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1730 WORD len = pidl->mkid.cb;
1731 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1733 if (pidlnext->mkid.cb)
1737 TRACE("%s\n", ret ? "Yes" : "No");
1741 /**************************************************************************
1743 * ### 3. section getting values from pidls ###
1746 /**************************************************************************
1749 * gets the text for the first item in the pidl (eg. simple pidl)
1751 * returns the length of the string
1753 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1758 char szTemp[MAX_PATH];
1760 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1768 if (_ILIsDesktop(pidl))
1771 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1774 lstrcpynA(szOut, szTemp, uOutSize);
1776 dwReturn = strlen (szTemp);
1779 else if (( szSrc = _ILGetTextPointer(pidl) ))
1783 lstrcpynA(szOut, szSrc, uOutSize);
1785 dwReturn = strlen(szSrc);
1787 else if (( riid = _ILGetGUIDPointer(pidl) ))
1789 /* special folder */
1790 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1793 lstrcpynA(szOut, szTemp, uOutSize);
1795 dwReturn = strlen (szTemp);
1800 ERR("-- no text\n");
1803 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1807 /**************************************************************************
1810 * gets the text for the first item in the pidl (eg. simple pidl)
1812 * returns the length of the string
1814 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1817 char szTemp[MAX_PATH];
1818 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1820 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1823 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1824 dwReturn = lstrlenW(pFileStructW->wszName);
1826 dwReturn = _ILSimpleGetText(pidl, szTemp, MAX_PATH);
1828 if (!MultiByteToWideChar(CP_ACP, 0, szTemp, -1, szOut, uOutSize))
1832 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1836 /**************************************************************************
1838 * ### 4. getting pointers to parts of pidls ###
1840 **************************************************************************
1841 * _ILGetDataPointer()
1843 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1845 if(pidl && pidl->mkid.cb != 0x00)
1846 return (LPPIDLDATA) &(pidl->mkid.abID);
1850 /**************************************************************************
1851 * _ILGetTextPointer()
1852 * gets a pointer to the long filename string stored in the pidl
1854 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1856 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1858 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1863 switch (pdata->type)
1874 return (LPSTR)&(pdata->u.drive.szDriveName);
1881 return (LPSTR)&(pdata->u.file.szNames);
1886 case PT_NETPROVIDER:
1888 return (LPSTR)&(pdata->u.network.szNames);
1893 /**************************************************************************
1894 * _ILGetSTextPointer()
1895 * gets a pointer to the short filename string stored in the pidl
1897 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1899 /* TRACE(pidl,"(pidl%p)\n", pidl); */
1901 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1906 switch (pdata->type)
1912 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1915 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1920 /**************************************************************************
1921 * _ILGetGUIDPointer()
1923 * returns reference to guid stored in some pidls
1925 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1927 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1929 TRACE("%p\n", pidl);
1934 TRACE("pdata->type 0x%04x\n", pdata->type);
1935 switch (pdata->type)
1940 return &(pdata->u.guid.guid);
1943 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
1949 /******************************************************************************
1950 * _ILGetFileStructW [Internal]
1952 * Get pointer the a SHITEMID's FileStructW field if present
1955 * pidl [I] The SHITEMID
1958 * Success: Pointer to pidl's FileStructW field.
1961 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
1962 FileStructW *pFileStructW;
1965 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
1968 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
1969 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
1971 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
1972 * style with a FileStructW member. If we switch all our shellfolder-implementations to
1973 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
1974 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
1975 /* FileStructW is positioned after FileStruct */
1976 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
1977 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
1978 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
1979 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
1981 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
1985 return pFileStructW;
1988 /*************************************************************************
1989 * _ILGetFileDateTime
1991 * Given the ItemIdList, get the FileTime
1994 * pidl [I] The ItemIDList
1995 * pFt [I] the resulted FILETIME of the file
1998 * True if Successful
2003 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2005 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2010 switch (pdata->type)
2014 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2022 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2028 if (_ILGetFileDateTime( pidl, &ft ))
2030 FileTimeToLocalFileTime(&ft, &lft);
2031 FileTimeToSystemTime (&lft, &time);
2033 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2036 /* Append space + time without seconds */
2038 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2049 /*************************************************************************
2052 * Given the ItemIdList, get the FileSize
2055 * pidl [I] The ItemIDList
2056 * pOut [I] The buffer to save the result
2057 * uOutsize [I] The size of the buffer
2063 * pOut can be null when no string is needed
2066 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2068 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2074 switch (pdata->type)
2077 dwSize = pdata->u.file.dwFileSize;
2079 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2087 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2089 char szTemp[MAX_PATH];
2090 const char * pPoint;
2091 LPCITEMIDLIST pidlTemp=pidl;
2093 TRACE("pidl=%p\n",pidl);
2098 pidlTemp = ILFindLastID(pidl);
2100 if (!_ILIsValue(pidlTemp))
2102 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2105 pPoint = PathFindExtensionA(szTemp);
2111 lstrcpynA(pOut, pPoint, uOutSize);
2117 /*************************************************************************
2120 * Given the ItemIdList, get the file type description
2123 * pidl [I] The ItemIDList (simple)
2124 * pOut [I] The buffer to save the result
2125 * uOutsize [I] The size of the buffer
2131 * This function copies as much as possible into the buffer.
2133 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2135 if(_ILIsValue(pidl))
2141 if (_ILGetExtension (pidl, sTemp, 64))
2143 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2144 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2146 lstrcpynA (pOut, sTemp, uOutSize - 6);
2147 strcat (pOut, "-file");
2152 lstrcpynA(pOut, "Folder", uOutSize);
2155 /*************************************************************************
2156 * _ILGetFileAttributes
2158 * Given the ItemIdList, get the Attrib string format
2161 * pidl [I] The ItemIDList
2162 * pOut [I] The buffer to save the result
2163 * uOutsize [I] The size of the Buffer
2169 * return value 0 in case of error is a valid return value
2172 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2174 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2185 wAttrib = pData->u.file.uFileAttribs;
2192 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2194 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2196 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2198 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2200 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2207 /*************************************************************************
2210 * free a aPidl struct
2212 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2218 for (i = 0; i < cidl; i++)
2224 /*************************************************************************
2227 * copies an aPidl struct
2229 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2232 LPITEMIDLIST *apidldest;
2234 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2238 for (i = 0; i < cidl; i++)
2239 apidldest[i] = ILClone(apidlsrc[i]);
2244 /*************************************************************************
2245 * _ILCopyCidaToaPidl
2247 * creates aPidl from CIDA
2249 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2254 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2259 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2261 for (i = 0; i < cida->cidl; i++)
2262 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));