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"
40 #include "undocshell.h"
41 #include "shell32_main.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
50 WINE_DECLARE_DEBUG_CHANNEL(shell);
52 /* from comctl32.dll */
53 extern LPVOID WINAPI Alloc(INT);
54 extern BOOL WINAPI Free(LPVOID);
56 /*************************************************************************
57 * ILGetDisplayNameEx [SHELL32.186]
59 * Retrieves the display name of an ItemIDList
62 * psf [I] Shell Folder to start with, if NULL the desktop is used
63 * pidl [I] ItemIDList relativ to the psf to get the display name for
64 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
65 * type [I] Type of display name to retrieve
66 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
67 * 1 = SHGDN_NORMAL relative to the root folder
68 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
71 * True if the display name could be retrieved successfully, False otherwise
73 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
76 WCHAR wPath[MAX_PATH];
78 TRACE("%p %p %p %ld\n", psf, pidl, path, type);
83 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
84 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
85 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
90 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
92 LPSHELLFOLDER psfParent, lsf = psf;
93 HRESULT ret = NO_ERROR;
94 LPCITEMIDLIST pidllast;
98 TRACE("%p %p %p %ld\n", psf, pidl, path, type);
105 ret = SHGetDesktopFolder(&lsf);
110 if (type >= 0 && type <= 2)
114 case ILGDN_FORPARSING:
115 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
121 flag = SHGDN_INFOLDER;
124 FIXME("Unknown type parameter = %lx", type);
125 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
128 if (!*(LPWORD)pidl || type == ILGDN_FORPARSING)
130 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
133 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidl);
138 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
141 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
144 ret = StrRetToStrNW(path, MAX_PATH, &strret, pidllast);
146 IShellFolder_Release(psfParent);
151 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
154 IShellFolder_Release(lsf);
155 return SUCCEEDED(ret);
158 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
160 TRACE_(shell)("%p %p %p %ld\n", psf, pidl, path, type);
161 if (SHELL_OsIsUnicode())
162 return ILGetDisplayNameExW(psf, pidl, path, type);
163 return ILGetDisplayNameExA(psf, pidl, path, type);
166 /*************************************************************************
167 * ILGetDisplayName [SHELL32.15]
169 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
171 TRACE_(shell)("%p %p\n", pidl, path);
172 if (SHELL_OsIsUnicode())
173 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
174 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
177 /*************************************************************************
178 * ILFindLastID [SHELL32.16]
181 * observed: pidl=Desktop return=pidl
183 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
184 { LPCITEMIDLIST pidlLast = pidl;
186 TRACE("(pidl=%p)\n",pidl);
188 while (pidl->mkid.cb)
191 pidl = ILGetNext(pidl);
193 return (LPITEMIDLIST)pidlLast;
195 /*************************************************************************
196 * ILRemoveLastID [SHELL32.17]
199 * when pidl=Desktop return=FALSE
201 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
203 TRACE_(shell)("pidl=%p\n",pidl);
205 if (!pidl || !pidl->mkid.cb)
207 ILFindLastID(pidl)->mkid.cb = 0;
211 /*************************************************************************
212 * ILClone [SHELL32.18]
215 * duplicate an idlist
217 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
219 LPITEMIDLIST newpidl;
224 len = ILGetSize(pidl);
225 newpidl = (LPITEMIDLIST)SHAlloc(len);
227 memcpy(newpidl,pidl,len);
229 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
234 /*************************************************************************
235 * ILCloneFirst [SHELL32.19]
238 * duplicates the first idlist of a complex pidl
240 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
242 LPITEMIDLIST pidlNew = NULL;
244 TRACE("pidl=%p \n",pidl);
250 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
253 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
256 ILGetNext(pidlNew)->mkid.cb = 0x00;
259 TRACE("-- newpidl=%p\n",pidlNew);
264 /*************************************************************************
265 * ILLoadFromStream (SHELL32.26)
268 * the first two bytes are the len, the pidl is following then
270 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
273 HRESULT ret = E_FAIL;
276 TRACE_(shell)("%p %p\n", pStream , ppPidl);
283 IStream_AddRef (pStream);
285 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
287 TRACE("PIDL length is %d\n", wLen);
289 *ppPidl = SHAlloc (wLen);
290 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead))) {
291 TRACE("Stream read OK\n");
294 WARN("reading pidl failed\n");
304 /* we are not yet fully compatible */
305 if (*ppPidl && !pcheck(*ppPidl))
307 WARN("Check failed\n");
313 IStream_Release (pStream);
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)
328 HRESULT ret = E_FAIL;
330 TRACE_(shell)("%p %p\n", pStream, pPidl);
332 IStream_AddRef (pStream);
335 while (pidl->mkid.cb)
337 wLen += sizeof(WORD) + pidl->mkid.cb;
338 pidl = ILGetNext(pidl);
341 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
343 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
347 IStream_Release (pStream);
352 /*************************************************************************
353 * SHILCreateFromPath [SHELL32.28]
355 * Create an ItemIDList from a path
360 * attributes [I/O] requested attributes on call and actual attributes when
361 * the function returns
364 * NO_ERROR if successful, or an OLE errer code otherwise
367 * Wrapper for IShellFolder_ParseDisplayName().
369 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
372 WCHAR lpszDisplayName[MAX_PATH];
374 HRESULT ret = E_FAIL;
376 TRACE_(shell)("%s %p 0x%08lx\n", path, ppidl, attributes ? *attributes : 0);
378 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
379 lpszDisplayName[MAX_PATH-1] = 0;
381 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
383 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, lpszDisplayName, &pchEaten, ppidl, attributes);
384 IShellFolder_Release(sf);
389 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
393 HRESULT ret = E_FAIL;
395 TRACE_(shell)("%s %p 0x%08lx\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
397 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
399 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
400 IShellFolder_Release(sf);
405 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
407 if ( SHELL_OsIsUnicode())
408 return SHILCreateFromPathW (path, ppidl, attributes);
409 return SHILCreateFromPathA (path, ppidl, attributes);
412 /*************************************************************************
413 * SHCloneSpecialIDList [SHELL32.89]
415 * Create an ItemIDList to one of the special folders.
419 * nFolder [in] CSIDL_xxxxx
420 * fCreate [in] Create folder if it does not exist
423 * Success: The newly created pidl
424 * Failure: NULL, if inputs are invalid.
427 * exported by ordinal.
428 * Caller is responsible for deallocating the returned ItemIDList with the
429 * shells IMalloc interface, aka ILFree.
431 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
432 { LPITEMIDLIST ppidl;
433 TRACE_(shell)("(hwnd=%p,csidl=0x%lx,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
436 nFolder |= CSIDL_FLAG_CREATE;
438 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
442 /*************************************************************************
443 * ILGlobalClone [SHELL32.20]
445 * Clones an ItemIDList using Alloc.
448 * pidl [I] ItemIDList to clone
451 * Newly allocated ItemIDList.
454 * exported by ordinal.
456 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
458 LPITEMIDLIST newpidl;
463 len = ILGetSize(pidl);
464 newpidl = (LPITEMIDLIST)Alloc(len);
466 memcpy(newpidl,pidl,len);
468 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
474 /*************************************************************************
475 * ILIsEqual [SHELL32.21]
478 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
480 char szData1[MAX_PATH];
481 char szData2[MAX_PATH];
483 LPCITEMIDLIST pidltemp1 = pidl1;
484 LPCITEMIDLIST pidltemp2 = pidl2;
486 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
488 /* explorer reads from registry directly (StreamMRU),
489 so we can only check here */
490 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
495 if ( (!pidl1) || (!pidl2) ) return FALSE;
497 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
499 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
500 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
502 if (strcasecmp ( szData1, szData2 )!=0 )
505 pidltemp1 = ILGetNext(pidltemp1);
506 pidltemp2 = ILGetNext(pidltemp2);
509 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
516 /*************************************************************************
517 * ILIsParent [SHELL32.23]
519 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
524 * bImmediate [I] only return true if the parent is the direct parent
528 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
532 * parent = a/b, child = a/b/c -> true, c is in folder a/b
533 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
534 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
536 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
538 char szData1[MAX_PATH];
539 char szData2[MAX_PATH];
541 LPCITEMIDLIST pParent = pidlParent;
542 LPCITEMIDLIST pChild = pidlChild;
544 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
546 if (!pParent || !pChild) return FALSE;
548 while (pParent->mkid.cb && pChild->mkid.cb)
550 _ILSimpleGetText(pParent, szData1, MAX_PATH);
551 _ILSimpleGetText(pChild, szData2, MAX_PATH);
553 if (strcasecmp ( szData1, szData2 )!=0 )
556 pParent = ILGetNext(pParent);
557 pChild = ILGetNext(pChild);
560 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
563 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
569 /*************************************************************************
570 * ILFindChild [SHELL32.24]
572 * Compares elements from pidl1 and pidl2.
579 * pidl1 is desktop pidl2
580 * pidl1 shorter pidl2 pointer to first different element of pidl2
581 * if there was at least one equal element
582 * pidl2 shorter pidl1 0
583 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
586 * exported by ordinal.
588 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
590 char szData1[MAX_PATH];
591 char szData2[MAX_PATH];
593 LPCITEMIDLIST pidltemp1 = pidl1;
594 LPCITEMIDLIST pidltemp2 = pidl2;
595 LPCITEMIDLIST ret=NULL;
597 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
599 /* explorer reads from registry directly (StreamMRU),
600 so we can only check here */
601 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
607 if ( _ILIsDesktop(pidl1) )
613 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
615 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
616 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
618 if (strcasecmp(szData1,szData2))
621 pidltemp1 = ILGetNext(pidltemp1);
622 pidltemp2 = ILGetNext(pidltemp2);
626 if (pidltemp1->mkid.cb)
628 ret = NULL; /* elements of pidl1 left*/
631 TRACE_(shell)("--- %p\n", ret);
632 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
635 /*************************************************************************
636 * ILCombine [SHELL32.25]
638 * Concatenates two complex ItemIDLists.
641 * pidl1 [I] first complex ItemIDLists
642 * pidl2 [I] complex ItemIDLists to append
645 * if both pidl's == NULL NULL
646 * if pidl1 == NULL cloned pidl2
647 * if pidl2 == NULL cloned pidl1
648 * otherwise new pidl with pidl2 appended to pidl1
651 * exported by ordinal.
652 * Does not destroy the passed in ItemIDLists!
654 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
657 LPITEMIDLIST pidlNew;
659 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
661 if(!pidl1 && !pidl2) return NULL;
668 pidlNew = ILClone(pidl2);
674 pidlNew = ILClone(pidl1);
678 len1 = ILGetSize(pidl1)-2;
679 len2 = ILGetSize(pidl2);
680 pidlNew = SHAlloc(len1+len2);
684 memcpy(pidlNew,pidl1,len1);
685 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
688 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
691 /*************************************************************************
692 * SHGetRealIDL [SHELL32.98]
696 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
698 FIXME("sf=%p pidlSimple=%p pidlReal=%p\n", lpsf, pidlSimple, pidlReal);
704 /*************************************************************************
705 * SHLogILFromFSIL [SHELL32.95]
708 * pild = CSIDL_DESKTOP ret = 0
709 * pild = CSIDL_DRIVES ret = 0
711 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
713 FIXME("(pidl=%p)\n",pidl);
720 /*************************************************************************
721 * ILGetSize [SHELL32.152]
723 * Gets the byte size of an ItemIDList including zero terminator
726 * pidl [I] ItemIDList
729 * size of pidl in bytes
732 * exported by ordinal
734 DWORD WINAPI ILGetSize(LPCITEMIDLIST pidl)
736 LPCSHITEMID si = &(pidl->mkid);
742 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
746 TRACE("pidl=%p size=%lu\n",pidl, len);
750 /*************************************************************************
751 * ILGetNext [SHELL32.153]
753 * Gets the next ItemID of an ItemIDList
756 * pidl [I] ItemIDList
761 * simple pidl -> pointer to 0x0000 element
764 * exported by ordinal.
766 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
777 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
778 TRACE("-- %p\n", pidl);
779 return (LPITEMIDLIST)pidl;
785 /*************************************************************************
786 * ILAppend [SHELL32.154]
788 * Adds the single ItemID item to the ItemIDList indicated by pidl.
789 * If bEnd is FALSE, inserts the item in the front of the list,
790 * otherwise it adds the item to the end. (???)
793 * pidl [I] ItemIDList to extend
794 * item [I] ItemID to prepend/append
795 * bEnd [I] Indicates if the item should be appended
798 * Destroys the passed in idlist! (???)
800 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
804 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
809 if (_ILIsDesktop(pidl))
811 idlRet = ILClone(item);
819 idlRet = ILCombine(pidl, item);
823 idlRet = ILCombine(item, pidl);
830 /*************************************************************************
831 * ILFree [SHELL32.155]
833 * Frees memory (if not NULL) allocated by SHMalloc allocator
839 * exported by ordinal
841 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
843 TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
845 if(!pidl) return FALSE;
850 /*************************************************************************
851 * ILGlobalFree [SHELL32.156]
853 * Frees memory (if not NULL) allocated by Alloc allocator
859 * exported by ordinal.
861 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
869 /*************************************************************************
870 * ILCreateFromPathA [SHELL32.189]
872 * Creates a complex ItemIDList from a path and returns it.
878 * the newly created complex ItemIDList or NULL if failed
881 * exported by ordinal.
884 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
886 LPITEMIDLIST pidlnew = NULL;
888 TRACE_(shell)("%s\n", debugstr_a(path));
890 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
895 /*************************************************************************
896 * ILCreateFromPathW [SHELL32.190]
898 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
900 LPITEMIDLIST pidlnew = NULL;
902 TRACE_(shell)("%s\n", debugstr_w(path));
904 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
909 /*************************************************************************
910 * ILCreateFromPath [SHELL32.157]
912 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
914 if ( SHELL_OsIsUnicode())
915 return ILCreateFromPathW (path);
916 return ILCreateFromPathA (path);
919 /*************************************************************************
920 * _ILParsePathW [internal]
922 * Creates an ItemIDList from a path and returns it.
925 * path [I] path to parse and convert into an ItemIDList
926 * lpFindFile [I] pointer to buffer to initialize the FileSystem
927 * Bind Data object with
928 * bBindCtx [I] indicates to create a BindContext and assign a
929 * FileSystem Bind Data object
930 * ppidl [O] the newly create ItemIDList
931 * prgfInOut [I/O] requested attributes on input and actual
932 * attributes on return
935 * NO_ERROR on success or an OLE error code
938 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
939 * creates a BindContext object and assigns a FileSystem Bind Data object
940 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
941 * IShellFolder uses that FileSystem Bind Data object of the BindContext
942 * to pass data about the current path element to the next object. This
943 * is used to avoid having to verify the current path element on disk, so
944 * that creating an ItemIDList from a non-existent path still can work.
946 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
947 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
949 LPSHELLFOLDER pSF = NULL;
953 TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
954 ppidl, ppidl ? *ppidl : NULL,
955 prgfInOut, prgfInOut ? *prgfInOut : 0);
957 ret = SHGetDesktopFolder(&pSF);
963 if (lpFindFile || bBindCtx)
964 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
968 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
973 IBindCtx_Release(pBC);
977 IShellFolder_Release(pSF);
979 if (!SUCCEEDED(ret) && ppidl)
982 TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
987 /*************************************************************************
988 * SHSimpleIDListFromPath [SHELL32.162]
990 * Creates a simple ItemIDList from a path and returns it. This function
991 * does not fail on non-existent paths.
994 * path [I] path to parse and convert into an ItemIDList
997 * the newly created simple ItemIDList
1000 * Simple in the name does not mean a relative ItemIDList but rather a
1001 * fully qualified list, where only the file name is filled in and the
1002 * directory flag for those ItemID elements this is known about, eg.
1003 * it is not the last element in the ItemIDList or the actual directory
1005 * exported by ordinal.
1007 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1009 LPITEMIDLIST pidl = NULL;
1010 UNICODE_STRING wPath;
1012 TRACE("%s\n", debugstr_a(lpszPath));
1014 RtlCreateUnicodeStringFromAsciiz(&wPath, lpszPath);
1016 _ILParsePathW(wPath.Buffer, NULL, TRUE, &pidl, NULL);
1017 RtlFreeUnicodeString(&wPath);
1019 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1023 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1025 LPITEMIDLIST pidl = NULL;
1027 TRACE("%s\n", debugstr_w(lpszPath));
1029 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1030 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1034 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1036 if ( SHELL_OsIsUnicode())
1037 return SHSimpleIDListFromPathW (lpszPath);
1038 return SHSimpleIDListFromPathA (lpszPath);
1041 /*************************************************************************
1042 * SHGetSpecialFolderLocation [SHELL32.@]
1044 * gets the folder locations from the registry and creates a pidl
1045 * creates missing reg keys and directories
1049 * nFolder [I] CSIDL_xxxxx
1050 * ppidl [O] PIDL of a special folder
1053 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
1054 * directory. If the directory is missing it returns a x80070002.
1056 HRESULT WINAPI SHGetSpecialFolderLocation(
1059 LPITEMIDLIST * ppidl)
1061 CHAR szPath[MAX_PATH];
1062 HRESULT hr = E_INVALIDARG;
1064 TRACE_(shell)("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
1072 *ppidl = _ILCreateDesktop();
1076 *ppidl = _ILCreateMyComputer();
1080 *ppidl = _ILCreateNetwork ();
1083 case CSIDL_CONTROLS:
1084 *ppidl = _ILCreateControl ();
1087 case CSIDL_PRINTERS:
1088 *ppidl = _ILCreatePrinter ();
1091 case CSIDL_BITBUCKET:
1092 *ppidl = _ILCreateBitBucket ();
1096 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
1099 TRACE_(shell)("Value=%s\n",szPath);
1100 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
1103 if(*ppidl) hr = NOERROR;
1106 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
1110 /*************************************************************************
1111 * SHGetFolderLocation [SHELL32.@]
1114 * the pidl can be a simple one. since we cant get the path out of the pidl
1115 * we have to take all data from the pidl
1117 HRESULT WINAPI SHGetFolderLocation(
1122 LPITEMIDLIST *ppidl)
1124 FIXME("%p 0x%08x %p 0x%08lx %p\n",
1125 hwnd, csidl, hToken, dwFlags, ppidl);
1126 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
1129 /*************************************************************************
1130 * SHGetDataFromIDListA [SHELL32.247]
1133 * the pidl can be a simple one. since we cant get the path out of the pidl
1134 * we have to take all data from the pidl
1136 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1138 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1141 if (!psf || !dest ) return E_INVALIDARG;
1145 case SHGDFIL_FINDDATA:
1147 WIN32_FIND_DATAA * pfd = dest;
1149 if (len < (int)sizeof(WIN32_FIND_DATAA)) return E_INVALIDARG;
1151 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1152 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1153 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1154 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1155 lstrcpynA(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
1156 lstrcpynA(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
1160 case SHGDFIL_NETRESOURCE:
1161 case SHGDFIL_DESCRIPTIONID:
1162 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1166 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1169 return E_INVALIDARG;
1171 /*************************************************************************
1172 * SHGetDataFromIDListW [SHELL32.248]
1175 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
1177 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 WIN32_FIND_DATAW * pfd = dest;
1189 if (len < (int)sizeof(WIN32_FIND_DATAW)) return E_INVALIDARG;
1191 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1192 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1193 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1194 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1195 if (!MultiByteToWideChar( CP_ACP, 0, _ILGetTextPointer(pidl), -1,
1196 pfd->cFileName, MAX_PATH ))
1197 pfd->cFileName[MAX_PATH-1] = 0;
1198 if (!MultiByteToWideChar( CP_ACP, 0, _ILGetSTextPointer(pidl), -1,
1199 pfd->cAlternateFileName, 14 ))
1200 pfd->cFileName[13] = 0;
1203 case SHGDFIL_NETRESOURCE:
1204 case SHGDFIL_DESCRIPTIONID:
1205 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1209 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1212 return E_INVALIDARG;
1215 /*************************************************************************
1216 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1220 * pszPath [OUT] path
1223 * path from a passed PIDL.
1226 * NULL returns FALSE
1227 * desktop pidl gives path to desktopdirectory back
1228 * special pidls returning FALSE
1230 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1234 LPSHELLFOLDER shellfolder;
1236 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1239 if (!pidl) return FALSE;
1241 hr = SHGetDesktopFolder(&shellfolder);
1242 if (SUCCEEDED (hr)) {
1243 hr = IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
1245 StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
1247 IShellFolder_Release(shellfolder);
1250 TRACE_(shell)("-- %s, 0x%08lx\n",pszPath, hr);
1251 return SUCCEEDED(hr);
1253 /*************************************************************************
1254 * SHGetPathFromIDListW [SHELL32.@]
1256 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1260 LPSHELLFOLDER shellfolder;
1262 TRACE_(shell)("(pidl=%p,%p)\n", pidl, debugstr_w(pszPath));
1265 if (!pidl) return FALSE;
1267 hr = SHGetDesktopFolder(&shellfolder);
1268 if (SUCCEEDED(hr)) {
1269 hr = IShellFolder_GetDisplayNameOf(shellfolder, pidl, SHGDN_FORPARSING, &str);
1270 if (SUCCEEDED(hr)) {
1271 StrRetToStrNW(pszPath, MAX_PATH, &str, pidl);
1273 IShellFolder_Release(shellfolder);
1276 TRACE_(shell)("-- %s, 0x%08lx\n",debugstr_w(pszPath), hr);
1277 return SUCCEEDED(hr);
1280 /*************************************************************************
1281 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1283 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1285 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1287 if (SHELL_OsIsUnicode())
1288 return SHGetPathFromIDListW(pidl,pszPath);
1289 return SHGetPathFromIDListA(pidl,pszPath);
1292 /*************************************************************************
1293 * SHBindToParent [shell version 5.0]
1295 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1298 LPITEMIDLIST pidlChild, pidlParent;
1301 TRACE_(shell)("pidl=%p\n", pidl);
1305 if (ppidlLast) *ppidlLast = NULL;
1307 if (_ILIsPidlSimple(pidl))
1309 /* we are on desktop level */
1311 *ppidlLast = ILClone(pidl);
1312 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1316 pidlChild = ILClone(ILFindLastID(pidl));
1317 pidlParent = ILClone(pidl);
1318 ILRemoveLastID(pidlParent);
1320 hr = SHGetDesktopFolder(&psf);
1323 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1325 if (SUCCEEDED(hr) && ppidlLast)
1326 *ppidlLast = pidlChild;
1330 SHFree (pidlParent);
1331 if (psf) IShellFolder_Release(psf);
1335 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1339 /**************************************************************************
1341 * internal functions
1343 * ### 1. section creating pidls ###
1345 *************************************************************************
1346 * _ILCreateDesktop()
1347 * _ILCreateIExplore()
1348 * _ILCreateMyComputer()
1353 LPITEMIDLIST _ILCreateDesktop()
1355 return _ILCreate(PT_DESKTOP, NULL, 0);
1358 LPITEMIDLIST _ILCreateMyComputer()
1360 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1363 LPITEMIDLIST _ILCreateIExplore()
1365 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1368 LPITEMIDLIST _ILCreateControl()
1370 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1373 LPITEMIDLIST _ILCreatePrinter()
1375 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1378 LPITEMIDLIST _ILCreateNetwork()
1380 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1383 LPITEMIDLIST _ILCreateBitBucket()
1385 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1388 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1390 lstrcpynA (sTemp,lpszNew,4);
1393 TRACE("(%s)\n",sTemp);
1394 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1397 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1399 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1400 char * pbuff = buff;
1404 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1406 /* prepare buffer with both names */
1407 len = strlen (stffile->cFileName) + 1;
1408 memcpy (pbuff, stffile->cFileName, len);
1411 if (stffile->cAlternateFileName)
1413 len1 = strlen (stffile->cAlternateFileName)+1;
1414 memcpy (pbuff, stffile->cAlternateFileName, len1);
1422 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1424 /* set attributes */
1428 pData = _ILGetDataPointer(pidl);
1429 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1430 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1431 pData->u.folder.uFileAttribs = stffile->dwFileAttributes;
1437 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1439 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1440 char * pbuff = buff;
1444 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1446 /* prepare buffer with both names */
1447 len = strlen (stffile->cFileName) + 1;
1448 memcpy (pbuff, stffile->cFileName, len);
1451 if (stffile->cAlternateFileName)
1453 len1 = strlen (stffile->cAlternateFileName)+1;
1454 memcpy (pbuff, stffile->cAlternateFileName, len1);
1462 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1464 /* set attributes */
1468 pData = _ILGetDataPointer(pidl);
1469 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1470 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1471 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1477 LPITEMIDLIST _ILCreateFromPathA(LPCSTR szPath)
1480 WIN32_FIND_DATAA stffile;
1481 LPITEMIDLIST pidl = NULL;
1483 hFile = FindFirstFileA(szPath, &stffile);
1484 if (hFile != INVALID_HANDLE_VALUE)
1486 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1487 pidl = _ILCreateFolder(&stffile);
1489 pidl = _ILCreateValue(&stffile);
1495 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1499 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1501 ERR("%s is not a GUID\n", szGUID);
1504 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1507 /**************************************************************************
1509 * Creates a new PIDL
1510 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1512 * uInSize = size of data (raw)
1515 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT uInSize)
1517 LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1522 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1531 uSize = 2 + 2 + sizeof(GUID);
1538 uSize = 2 + 12 + uInSize;
1541 FIXME("can't create type: 0x%08x\n",type);
1545 if(!(pidlOut = SHAlloc(uSize + 2))) return NULL;
1546 ZeroMemory(pidlOut, uSize + 2);
1547 pidlOut->mkid.cb = uSize;
1552 TRACE("- create Desktop\n");
1557 pData = _ILGetDataPointer(pidlOut);
1559 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1560 TRACE("-- create GUID-pidl %s\n", debugstr_guid(&(pData->u.mycomp.guid)));
1564 pData = _ILGetDataPointer(pidlOut);
1566 pszDest = _ILGetTextPointer(pidlOut);
1567 memcpy(pszDest, pIn, uInSize);
1568 TRACE("-- create Drive: %s\n",debugstr_a(pszDest));
1573 pData = _ILGetDataPointer(pidlOut);
1575 pszDest = _ILGetTextPointer(pidlOut);
1576 memcpy(pszDest, pIn, uInSize);
1577 TRACE("-- create Value: %s\n",debugstr_a(pszDest));
1581 pidlTemp = ILGetNext(pidlOut);
1583 pidlTemp->mkid.cb = 0x00;
1585 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1589 /**************************************************************************
1592 * Gets the text for the drive eg. 'c:\'
1597 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1598 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1600 if(_ILIsMyComputer(pidl))
1601 pidl = ILGetNext(pidl);
1603 if (pidl && _ILIsDrive(pidl))
1604 return _ILSimpleGetText(pidl, pOut, uSize);
1609 /**************************************************************************
1611 * ### 2. section testing pidls ###
1613 **************************************************************************
1616 * _ILIsSpecialFolder()
1622 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1623 { TRACE("(%p)\n",pidl);
1624 return pidl && pidl->mkid.cb ? 0 : 1;
1627 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1629 REFIID iid = _ILGetGUIDPointer(pidl);
1631 TRACE("(%p)\n",pidl);
1634 return IsEqualIID(iid, &CLSID_MyComputer);
1638 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1640 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1641 TRACE("(%p)\n",pidl);
1642 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1643 (pidl && pidl->mkid.cb == 0x00)
1647 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1648 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1649 TRACE("(%p)\n",pidl);
1650 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1651 PT_DRIVE1 == lpPData->type ||
1652 PT_DRIVE2 == lpPData->type ||
1653 PT_DRIVE3 == lpPData->type));
1656 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1657 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1658 TRACE("(%p)\n",pidl);
1659 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1662 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1663 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1664 TRACE("(%p)\n",pidl);
1665 return (pidl && lpPData && PT_VALUE == lpPData->type);
1668 /**************************************************************************
1671 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1675 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1677 WORD len = pidl->mkid.cb;
1678 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1679 if (pidlnext->mkid.cb)
1683 TRACE("%s\n", ret ? "Yes" : "No");
1687 /**************************************************************************
1689 * ### 3. section getting values from pidls ###
1692 /**************************************************************************
1695 * gets the text for the first item in the pidl (eg. simple pidl)
1697 * returns the length of the string
1699 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1704 char szTemp[MAX_PATH];
1706 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1708 if (!pidl) return 0;
1713 if (_ILIsDesktop(pidl))
1716 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1719 lstrcpynA(szOut, szTemp, uOutSize);
1721 dwReturn = strlen (szTemp);
1724 else if (( szSrc = _ILGetTextPointer(pidl) ))
1728 lstrcpynA(szOut, szSrc, uOutSize);
1730 dwReturn = strlen(szSrc);
1732 else if (( riid = _ILGetGUIDPointer(pidl) ))
1734 /* special folder */
1735 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1738 lstrcpynA(szOut, szTemp, uOutSize);
1740 dwReturn = strlen (szTemp);
1745 ERR("-- no text\n");
1748 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_a(szOut),dwReturn);
1752 /**************************************************************************
1755 * gets the text for the first item in the pidl (eg. simple pidl)
1757 * returns the length of the string
1759 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1762 char szTemp[MAX_PATH];
1764 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1766 dwReturn = _ILSimpleGetText(pidl, szTemp, uOutSize);
1768 if (!MultiByteToWideChar(CP_ACP, 0, szTemp, -1, szOut, MAX_PATH))
1771 TRACE("-- (%p=%s 0x%08lx)\n",szOut,debugstr_w(szOut),dwReturn);
1775 /**************************************************************************
1777 * ### 4. getting pointers to parts of pidls ###
1779 **************************************************************************
1780 * _ILGetDataPointer()
1782 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1784 if(pidl && pidl->mkid.cb != 0x00)
1785 return (LPPIDLDATA) &(pidl->mkid.abID);
1789 /**************************************************************************
1790 * _ILGetTextPointer()
1791 * gets a pointer to the long filename string stored in the pidl
1793 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1794 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1796 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1800 switch (pdata->type)
1810 return (LPSTR)&(pdata->u.drive.szDriveName);
1817 return (LPSTR)&(pdata->u.file.szNames);
1822 case PT_NETPROVIDER:
1824 return (LPSTR)&(pdata->u.network.szNames);
1830 /**************************************************************************
1831 * _ILGetSTextPointer()
1832 * gets a pointer to the short filename string stored in the pidl
1834 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1835 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1837 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1841 switch (pdata->type)
1847 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1850 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1856 /**************************************************************************
1857 * _ILGetGUIDPointer()
1859 * returns reference to guid stored in some pidls
1861 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1863 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1865 TRACE("%p\n", pidl);
1869 TRACE("pdata->type 0x%04x\n", pdata->type);
1870 switch (pdata->type)
1874 return (REFIID) &(pdata->u.mycomp.guid);
1877 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
1884 /*************************************************************************
1885 * _ILGetFileDateTime
1887 * Given the ItemIdList, get the FileTime
1890 * pidl [I] The ItemIDList
1891 * pFt [I] the resulted FILETIME of the file
1894 * True if Successful
1899 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1901 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1903 if(! pdata) return FALSE;
1905 switch (pdata->type)
1908 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1911 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1919 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1925 if (_ILGetFileDateTime( pidl, &ft )) {
1926 FileTimeToLocalFileTime(&ft, &lft);
1927 FileTimeToSystemTime (&lft, &time);
1928 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
1937 /*************************************************************************
1940 * Given the ItemIdList, get the FileSize
1943 * pidl [I] The ItemIDList
1944 * pOut [I] The buffer to save the result
1945 * uOutsize [I] The size of the buffer
1951 * pOut can be null when no string is needed
1954 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1956 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1959 if(! pdata) return 0;
1961 switch (pdata->type)
1964 dwSize = pdata->u.file.dwFileSize;
1965 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1968 if (pOut) *pOut = 0x00;
1972 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1974 char szTemp[MAX_PATH];
1975 const char * pPoint;
1976 LPCITEMIDLIST pidlTemp=pidl;
1978 TRACE("pidl=%p\n",pidl);
1980 if (!pidl) return FALSE;
1982 pidlTemp = ILFindLastID(pidl);
1984 if (!_ILIsValue(pidlTemp)) return FALSE;
1985 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1987 pPoint = PathFindExtensionA(szTemp);
1989 if (! *pPoint) return FALSE;
1992 lstrcpynA(pOut, pPoint, uOutSize);
1998 /*************************************************************************
2001 * Given the ItemIdList, get the file type description
2004 * pidl [I] The ItemIDList (simple)
2005 * pOut [I] The buffer to save the result
2006 * uOutsize [I] The size of the buffer
2012 * This function copies as much as possible into the buffer.
2014 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2016 if(_ILIsValue(pidl))
2023 if (_ILGetExtension (pidl, sTemp, 64))
2025 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2026 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2028 lstrcpynA (pOut, sTemp, uOutSize - 6);
2029 strcat (pOut, "-file");
2035 lstrcpynA(pOut, "Folder", uOutSize);
2039 /*************************************************************************
2040 * _ILGetFileAttributes
2042 * Given the ItemIdList, get the Attrib string format
2045 * pidl [I] The ItemIDList
2046 * pOut [I] The buffer to save the result
2047 * uOutsize [I] The size of the Buffer
2053 * return value 0 in case of error is a valid return value
2056 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2058 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2062 if(! pData) return 0;
2067 wAttrib = pData->u.folder.uFileAttribs;
2070 wAttrib = pData->u.file.uFileAttribs;
2077 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2081 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2085 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2089 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2093 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2102 /*************************************************************************
2105 * free a aPidl struct
2107 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2113 for (i = 0; i < cidl; i++) SHFree(apidl[i]);
2118 /*************************************************************************
2121 * copies an aPidl struct
2123 LPITEMIDLIST* _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl)
2126 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
2127 if(!apidlsrc) return NULL;
2129 for (i = 0; i < cidl; i++)
2130 apidldest[i] = ILClone(apidlsrc[i]);
2135 /*************************************************************************
2136 * _ILCopyCidaToaPidl
2138 * creates aPidl from CIDA
2140 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida)
2143 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2145 if(!dst) return NULL;
2148 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
2150 for (i = 0; i < cida->cidl; i++)
2151 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));