mpr: Don't succeed if drive is not remote in WNetGetUniversalName.
[wine/multimedia.git] / dlls / shell32 / pidl.c
blob2130b49ff99d411e759d82a047260bb0573d4d26
1 /*
2 * pidl Handling
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
20 * NOTES
21 * a pidl == NULL means desktop and is legal
25 #include "config.h"
26 #include "wine/port.h"
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winreg.h"
40 #include "objbase.h"
41 #include "shlguid.h"
42 #include "winerror.h"
43 #include "winnls.h"
44 #include "undocshell.h"
45 #include "shell32_main.h"
46 #include "shlwapi.h"
48 #include "pidl.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 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl);
59 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl);
61 /*************************************************************************
62 * ILGetDisplayNameExA
64 * Retrieves the display name of an ItemIDList
66 * PARAMS
67 * psf [I] Shell Folder to start with, if NULL the desktop is used
68 * pidl [I] ItemIDList relative to the psf to get the display name for
69 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
70 * type [I] Type of display name to retrieve
71 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
72 * 1 = SHGDN_NORMAL relative to the root folder
73 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
75 * RETURNS
76 * True if the display name could be retrieved successfully, False otherwise
78 static BOOL ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
80 BOOL ret = FALSE;
81 WCHAR wPath[MAX_PATH];
83 TRACE("%p %p %p %d\n", psf, pidl, path, type);
85 if (!pidl || !path)
86 return FALSE;
88 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
89 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
90 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
92 return ret;
95 BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
97 LPSHELLFOLDER psfParent, lsf = psf;
98 HRESULT ret = NO_ERROR;
99 LPCITEMIDLIST pidllast;
100 STRRET strret;
101 DWORD flag;
103 TRACE("%p %p %p %x\n", psf, pidl, path, type);
105 if (!pidl || !path)
106 return FALSE;
108 if (!lsf)
110 ret = SHGetDesktopFolder(&lsf);
111 if (FAILED(ret))
112 return FALSE;
115 switch (type)
117 case ILGDN_FORPARSING:
118 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
119 break;
120 case ILGDN_NORMAL:
121 flag = SHGDN_NORMAL;
122 break;
123 case ILGDN_INFOLDER:
124 flag = SHGDN_INFOLDER;
125 break;
126 default:
127 FIXME("Unknown type parameter = %x\n", type);
128 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
129 break;
132 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
134 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
135 if (SUCCEEDED(ret))
137 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
138 ret = E_FAIL;
141 else
143 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
144 if (SUCCEEDED(ret))
146 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
147 if (SUCCEEDED(ret))
149 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
150 ret = E_FAIL;
152 IShellFolder_Release(psfParent);
156 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
158 if (!psf)
159 IShellFolder_Release(lsf);
160 return SUCCEEDED(ret);
163 /*************************************************************************
164 * ILGetDisplayNameEx [SHELL32.186]
166 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
168 TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
170 if (SHELL_OsIsUnicode())
171 return ILGetDisplayNameExW(psf, pidl, path, type);
172 return ILGetDisplayNameExA(psf, pidl, path, type);
175 /*************************************************************************
176 * ILGetDisplayName [SHELL32.15]
178 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
180 TRACE_(shell)("%p %p\n", pidl, path);
182 if (SHELL_OsIsUnicode())
183 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
184 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
187 /*************************************************************************
188 * ILFindLastID [SHELL32.16]
190 * NOTES
191 * observed: pidl=Desktop return=pidl
193 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
195 LPCITEMIDLIST pidlLast = pidl;
197 TRACE("(pidl=%p)\n",pidl);
199 if (!pidl)
200 return NULL;
202 while (pidl->mkid.cb)
204 pidlLast = pidl;
205 pidl = ILGetNext(pidl);
207 return (LPITEMIDLIST)pidlLast;
210 /*************************************************************************
211 * ILRemoveLastID [SHELL32.17]
213 * NOTES
214 * when pidl=Desktop return=FALSE
216 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
218 TRACE_(shell)("pidl=%p\n",pidl);
220 if (_ILIsEmpty(pidl))
221 return FALSE;
222 ILFindLastID(pidl)->mkid.cb = 0;
223 return TRUE;
226 /*************************************************************************
227 * ILClone [SHELL32.18]
229 * NOTES
230 * duplicate an idlist
232 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
234 DWORD len;
235 LPITEMIDLIST newpidl;
237 if (!pidl)
238 return NULL;
240 len = ILGetSize(pidl);
241 newpidl = SHAlloc(len);
242 if (newpidl)
243 memcpy(newpidl,pidl,len);
245 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
246 pdump(pidl);
248 return newpidl;
251 /*************************************************************************
252 * ILCloneFirst [SHELL32.19]
254 * NOTES
255 * duplicates the first idlist of a complex pidl
257 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
259 DWORD len;
260 LPITEMIDLIST pidlNew = NULL;
262 TRACE("pidl=%p\n", pidl);
263 pdump(pidl);
265 if (pidl)
267 len = pidl->mkid.cb;
268 pidlNew = SHAlloc(len+2);
269 if (pidlNew)
271 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
273 if (len)
274 ILGetNext(pidlNew)->mkid.cb = 0x00;
277 TRACE("-- newpidl=%p\n",pidlNew);
279 return pidlNew;
282 /*************************************************************************
283 * ILLoadFromStream (SHELL32.26)
285 * NOTES
286 * the first two bytes are the len, the pidl is following then
288 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
290 WORD wLen = 0;
291 DWORD dwBytesRead;
292 HRESULT ret = E_FAIL;
295 TRACE_(shell)("%p %p\n", pStream , ppPidl);
297 SHFree(*ppPidl);
298 *ppPidl = NULL;
300 IStream_AddRef (pStream);
302 if (SUCCEEDED(IStream_Read(pStream, &wLen, 2, &dwBytesRead)))
304 TRACE("PIDL length is %d\n", wLen);
305 if (wLen != 0)
307 *ppPidl = SHAlloc (wLen);
308 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
310 TRACE("Stream read OK\n");
311 ret = S_OK;
313 else
315 WARN("reading pidl failed\n");
316 SHFree(*ppPidl);
317 *ppPidl = NULL;
320 else
322 *ppPidl = NULL;
323 ret = S_OK;
327 /* we are not yet fully compatible */
328 if (*ppPidl && !pcheck(*ppPidl))
330 WARN("Check failed\n");
331 SHFree(*ppPidl);
332 *ppPidl = NULL;
335 IStream_Release (pStream);
336 TRACE("done\n");
337 return ret;
340 /*************************************************************************
341 * ILSaveToStream (SHELL32.27)
343 * NOTES
344 * the first two bytes are the len, the pidl is following then
346 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
348 WORD wLen = 0;
349 HRESULT ret = E_FAIL;
351 TRACE_(shell)("%p %p\n", pStream, pPidl);
353 IStream_AddRef (pStream);
355 wLen = ILGetSize(pPidl);
357 if (SUCCEEDED(IStream_Write(pStream, &wLen, 2, NULL)))
359 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
360 ret = S_OK;
362 IStream_Release (pStream);
364 return ret;
367 /*************************************************************************
368 * SHILCreateFromPath [SHELL32.28]
370 * Create an ItemIDList from a path
372 * PARAMS
373 * path [I]
374 * ppidl [O]
375 * attributes [I/O] requested attributes on call and actual attributes when
376 * the function returns
378 * RETURNS
379 * NO_ERROR if successful, or an OLE errer code otherwise
381 * NOTES
382 * Wrapper for IShellFolder_ParseDisplayName().
384 static HRESULT SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
386 WCHAR lpszDisplayName[MAX_PATH];
388 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
390 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
391 lpszDisplayName[MAX_PATH-1] = 0;
393 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
396 HRESULT SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
398 LPSHELLFOLDER sf;
399 DWORD pchEaten;
400 HRESULT ret = E_FAIL;
402 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
404 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
406 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
407 IShellFolder_Release(sf);
409 return ret;
412 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
414 if ( SHELL_OsIsUnicode())
415 return SHILCreateFromPathW (path, ppidl, attributes);
416 return SHILCreateFromPathA (path, ppidl, attributes);
419 /*************************************************************************
420 * SHCloneSpecialIDList [SHELL32.89]
422 * Create an ItemIDList to one of the special folders.
424 * PARAMS
425 * hwndOwner [in]
426 * nFolder [in] CSIDL_xxxxx
427 * fCreate [in] Create folder if it does not exist
429 * RETURNS
430 * Success: The newly created pidl
431 * Failure: NULL, if inputs are invalid.
433 * NOTES
434 * exported by ordinal.
435 * Caller is responsible for deallocating the returned ItemIDList with the
436 * shells IMalloc interface, aka ILFree.
438 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, DWORD nFolder, BOOL fCreate)
440 LPITEMIDLIST ppidl;
441 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
443 if (fCreate)
444 nFolder |= CSIDL_FLAG_CREATE;
446 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
447 return ppidl;
450 /*************************************************************************
451 * ILGlobalClone [SHELL32.20]
453 * Clones an ItemIDList using Alloc.
455 * PARAMS
456 * pidl [I] ItemIDList to clone
458 * RETURNS
459 * Newly allocated ItemIDList.
461 * NOTES
462 * exported by ordinal.
464 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
466 DWORD len;
467 LPITEMIDLIST newpidl;
469 if (!pidl)
470 return NULL;
472 len = ILGetSize(pidl);
473 newpidl = Alloc(len);
474 if (newpidl)
475 memcpy(newpidl,pidl,len);
477 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
478 pdump(pidl);
480 return newpidl;
483 /*************************************************************************
484 * ILIsEqual [SHELL32.21]
487 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
489 char szData1[MAX_PATH];
490 char szData2[MAX_PATH];
492 LPCITEMIDLIST pidltemp1 = pidl1;
493 LPCITEMIDLIST pidltemp2 = pidl2;
495 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
498 * Explorer reads from registry directly (StreamMRU),
499 * so we can only check here
501 if (!pcheck(pidl1) || !pcheck (pidl2))
502 return FALSE;
504 pdump (pidl1);
505 pdump (pidl2);
507 if (!pidl1 || !pidl2)
508 return FALSE;
510 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
512 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
513 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
515 if (strcasecmp( szData1, szData2 ))
516 return FALSE;
518 pidltemp1 = ILGetNext(pidltemp1);
519 pidltemp2 = ILGetNext(pidltemp2);
522 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
523 return TRUE;
525 return FALSE;
528 /*************************************************************************
529 * ILIsParent [SHELL32.23]
531 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
533 * PARAMS
534 * pidlParent [I]
535 * pidlChild [I]
536 * bImmediate [I] only return true if the parent is the direct parent
537 * of the child
539 * RETURNS
540 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
541 * False otherwise.
543 * NOTES
544 * parent = a/b, child = a/b/c -> true, c is in folder a/b
545 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
546 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
547 * child = a/b -> false if bImmediate is true
548 * child = a/b -> true if bImmediate is false
550 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
552 char szData1[MAX_PATH];
553 char szData2[MAX_PATH];
554 LPCITEMIDLIST pParent = pidlParent;
555 LPCITEMIDLIST pChild = pidlChild;
557 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
559 if (!pParent || !pChild)
560 return FALSE;
562 while (pParent->mkid.cb && pChild->mkid.cb)
564 _ILSimpleGetText(pParent, szData1, MAX_PATH);
565 _ILSimpleGetText(pChild, szData2, MAX_PATH);
567 if (strcasecmp( szData1, szData2 ))
568 return FALSE;
570 pParent = ILGetNext(pParent);
571 pChild = ILGetNext(pChild);
574 /* child has shorter name than parent */
575 if (pParent->mkid.cb)
576 return FALSE;
578 /* not immediate descent */
579 if ((!pChild->mkid.cb || ILGetNext(pChild)->mkid.cb) && bImmediate)
580 return FALSE;
582 return TRUE;
585 /*************************************************************************
586 * ILFindChild [SHELL32.24]
588 * Compares elements from pidl1 and pidl2.
590 * PARAMS
591 * pidl1 [I]
592 * pidl2 [I]
594 * RETURNS
595 * pidl1 is desktop pidl2
596 * pidl1 shorter pidl2 pointer to first different element of pidl2
597 * if there was at least one equal element
598 * pidl2 shorter pidl1 0
599 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
601 * NOTES
602 * exported by ordinal.
604 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
606 char szData1[MAX_PATH];
607 char szData2[MAX_PATH];
609 LPCITEMIDLIST pidltemp1 = pidl1;
610 LPCITEMIDLIST pidltemp2 = pidl2;
611 LPCITEMIDLIST ret=NULL;
613 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
615 /* explorer reads from registry directly (StreamMRU),
616 so we can only check here */
617 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
618 return FALSE;
620 pdump (pidl1);
621 pdump (pidl2);
623 if (_ILIsDesktop(pidl1))
625 ret = pidl2;
627 else
629 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
631 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
632 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
634 if (strcasecmp(szData1,szData2))
635 break;
637 pidltemp1 = ILGetNext(pidltemp1);
638 pidltemp2 = ILGetNext(pidltemp2);
639 ret = pidltemp2;
642 if (pidltemp1->mkid.cb)
643 ret = NULL; /* elements of pidl1 left*/
645 TRACE_(shell)("--- %p\n", ret);
646 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
649 /*************************************************************************
650 * ILCombine [SHELL32.25]
652 * Concatenates two complex ItemIDLists.
654 * PARAMS
655 * pidl1 [I] first complex ItemIDLists
656 * pidl2 [I] complex ItemIDLists to append
658 * RETURNS
659 * if both pidl's == NULL NULL
660 * if pidl1 == NULL cloned pidl2
661 * if pidl2 == NULL cloned pidl1
662 * otherwise new pidl with pidl2 appended to pidl1
664 * NOTES
665 * exported by ordinal.
666 * Does not destroy the passed in ItemIDLists!
668 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
670 DWORD len1,len2;
671 LPITEMIDLIST pidlNew;
673 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
675 if (!pidl1 && !pidl2) return NULL;
677 pdump (pidl1);
678 pdump (pidl2);
680 if (!pidl1)
682 pidlNew = ILClone(pidl2);
683 return pidlNew;
686 if (!pidl2)
688 pidlNew = ILClone(pidl1);
689 return pidlNew;
692 len1 = ILGetSize(pidl1)-2;
693 len2 = ILGetSize(pidl2);
694 pidlNew = SHAlloc(len1+len2);
696 if (pidlNew)
698 memcpy(pidlNew,pidl1,len1);
699 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
702 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
703 return pidlNew;
706 /*************************************************************************
707 * SHGetRealIDL [SHELL32.98]
709 * NOTES
711 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
713 IDataObject* pDataObj;
714 HRESULT hr;
716 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
717 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
718 if (SUCCEEDED(hr))
720 STGMEDIUM medium;
721 FORMATETC fmt;
723 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
724 fmt.ptd = NULL;
725 fmt.dwAspect = DVASPECT_CONTENT;
726 fmt.lindex = -1;
727 fmt.tymed = TYMED_HGLOBAL;
729 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
731 IDataObject_Release(pDataObj);
733 if (SUCCEEDED(hr))
735 /*assert(pida->cidl==1);*/
736 LPIDA pida = GlobalLock(medium.u.hGlobal);
738 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
739 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
741 *pidlReal = ILCombine(pidl_folder, pidl_child);
743 if (!*pidlReal)
744 hr = E_OUTOFMEMORY;
746 GlobalUnlock(medium.u.hGlobal);
747 GlobalFree(medium.u.hGlobal);
751 return hr;
754 /*************************************************************************
755 * SHLogILFromFSIL [SHELL32.95]
757 * NOTES
758 * pild = CSIDL_DESKTOP ret = 0
759 * pild = CSIDL_DRIVES ret = 0
761 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
763 FIXME("(pidl=%p)\n",pidl);
765 pdump(pidl);
767 return 0;
770 /*************************************************************************
771 * ILGetSize [SHELL32.152]
773 * Gets the byte size of an ItemIDList including zero terminator
775 * PARAMS
776 * pidl [I] ItemIDList
778 * RETURNS
779 * size of pidl in bytes
781 * NOTES
782 * exported by ordinal
784 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
786 LPCSHITEMID si = &(pidl->mkid);
787 UINT len=0;
789 if (pidl)
791 while (si->cb)
793 len += si->cb;
794 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
796 len += 2;
798 TRACE("pidl=%p size=%u\n",pidl, len);
799 return len;
802 /*************************************************************************
803 * ILGetNext [SHELL32.153]
805 * Gets the next ItemID of an ItemIDList
807 * PARAMS
808 * pidl [I] ItemIDList
810 * RETURNS
811 * null -> null
812 * desktop -> null
813 * simple pidl -> pointer to 0x0000 element
815 * NOTES
816 * exported by ordinal.
818 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
820 WORD len;
822 TRACE("%p\n", pidl);
824 if (pidl)
826 len = pidl->mkid.cb;
827 if (len)
829 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
830 TRACE("-- %p\n", pidl);
831 return (LPITEMIDLIST)pidl;
834 return NULL;
837 /*************************************************************************
838 * ILAppendID [SHELL32.154]
840 * Adds the single ItemID item to the ItemIDList indicated by pidl.
841 * If bEnd is FALSE, inserts the item in the front of the list,
842 * otherwise it adds the item to the end. (???)
844 * PARAMS
845 * pidl [I] ItemIDList to extend
846 * item [I] ItemID to prepend/append
847 * bEnd [I] Indicates if the item should be appended
849 * NOTES
850 * Destroys the passed in idlist! (???)
852 LPITEMIDLIST WINAPI ILAppendID(LPITEMIDLIST pidl, LPCSHITEMID item, BOOL bEnd)
854 LPITEMIDLIST idlRet;
855 LPCITEMIDLIST itemid = (LPCITEMIDLIST)item;
857 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
859 pdump (pidl);
860 pdump (itemid);
862 if (_ILIsDesktop(pidl))
864 idlRet = ILClone(itemid);
865 SHFree (pidl);
866 return idlRet;
869 if (bEnd)
870 idlRet = ILCombine(pidl, itemid);
871 else
872 idlRet = ILCombine(itemid, pidl);
874 SHFree(pidl);
875 return idlRet;
878 /*************************************************************************
879 * ILFree [SHELL32.155]
881 * Frees memory (if not NULL) allocated by SHMalloc allocator
883 * PARAMS
884 * pidl [I]
886 * RETURNS
887 * Nothing
889 * NOTES
890 * exported by ordinal
892 void WINAPI ILFree(LPITEMIDLIST pidl)
894 TRACE("(pidl=%p)\n",pidl);
895 SHFree(pidl);
898 /*************************************************************************
899 * ILGlobalFree [SHELL32.156]
901 * Frees memory (if not NULL) allocated by Alloc allocator
903 * PARAMS
904 * pidl [I]
906 * RETURNS
907 * Nothing
909 * NOTES
910 * exported by ordinal.
912 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
914 TRACE("%p\n", pidl);
916 Free(pidl);
919 /*************************************************************************
920 * ILCreateFromPathA [SHELL32.189]
922 * Creates a complex ItemIDList from a path and returns it.
924 * PARAMS
925 * path [I]
927 * RETURNS
928 * the newly created complex ItemIDList or NULL if failed
930 * NOTES
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)))
940 return pidlnew;
941 return 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)))
956 return pidlnew;
957 return 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.
975 * PARAMS
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
985 * RETURNS
986 * NO_ERROR on success or an OLE error code
988 * NOTES
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 _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
998 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
1000 LPSHELLFOLDER pSF = NULL;
1001 LPBC pBC = NULL;
1002 HRESULT ret;
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);
1009 if (FAILED(ret))
1010 return ret;
1012 if (lpFindFile || bBindCtx)
1013 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1015 if (SUCCEEDED(ret))
1017 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1020 if (pBC)
1022 IBindCtx_Release(pBC);
1023 pBC = NULL;
1026 IShellFolder_Release(pSF);
1028 if (FAILED(ret) && ppidl)
1029 *ppidl = NULL;
1031 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1033 return ret;
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.
1042 * PARAMS
1043 * path [I] path to parse and convert into an ItemIDList
1045 * RETURNS
1046 * the newly created simple ItemIDList
1048 * NOTES
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
1053 * exists on disk.
1054 * exported by ordinal.
1056 LPITEMIDLIST SHSimpleIDListFromPathA(LPCSTR lpszPath)
1058 LPITEMIDLIST pidl = NULL;
1059 LPWSTR wPath = NULL;
1060 int len;
1062 TRACE("%s\n", debugstr_a(lpszPath));
1064 if (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);
1075 return pidl;
1078 LPITEMIDLIST 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);
1086 return pidl;
1089 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1091 if ( SHELL_OsIsUnicode())
1092 return SHSimpleIDListFromPathW (lpszPath);
1093 return SHSimpleIDListFromPathA (lpszPath);
1096 /*************************************************************************
1097 * SHGetDataFromIDListA [SHELL32.247]
1099 * NOTES
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);
1111 pdump(pidl);
1112 if (!psf || !dest)
1113 return E_INVALIDARG;
1115 switch (nFormat)
1117 case SHGDFIL_FINDDATA:
1118 pfd = dest;
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);
1134 if (filename)
1135 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1136 else
1137 pfd->cFileName[0] = '\0';
1139 if (shortname)
1140 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1141 else
1142 pfd->cAlternateFileName[0] = '\0';
1143 return S_OK;
1145 case SHGDFIL_NETRESOURCE:
1146 case SHGDFIL_DESCRIPTIONID:
1147 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1148 break;
1150 default:
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);
1169 pdump(pidl);
1171 if (!psf || !dest)
1172 return E_INVALIDARG;
1174 switch (nFormat)
1176 case SHGDFIL_FINDDATA:
1177 pfd = dest;
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);
1193 if (!filename)
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;
1198 if (!shortname)
1199 pfd->cAlternateFileName[0] = '\0';
1200 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1201 pfd->cAlternateFileName[13] = 0;
1202 return S_OK;
1204 case SHGDFIL_NETRESOURCE:
1205 case SHGDFIL_DESCRIPTIONID:
1206 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1207 break;
1209 default:
1210 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1213 return E_INVALIDARG;
1216 /*************************************************************************
1217 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1219 * PARAMETERS
1220 * pidl, [IN] pidl
1221 * pszPath [OUT] path
1223 * RETURNS
1224 * path from a passed PIDL.
1226 * NOTES
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];
1234 BOOL bSuccess;
1236 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1237 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1239 return bSuccess;
1242 /*************************************************************************
1243 * SHGetPathFromIDListW [SHELL32.@]
1245 * See SHGetPathFromIDListA.
1247 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1249 HRESULT hr;
1250 LPCITEMIDLIST pidlLast;
1251 LPSHELLFOLDER psfFolder;
1252 DWORD dwAttributes;
1253 STRRET strret;
1255 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1256 pdump(pidl);
1258 *pszPath = '\0';
1259 if (!pidl)
1260 return FALSE;
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);
1269 return FALSE;
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;
1288 HRESULT hr=E_FAIL;
1290 TRACE_(shell)("pidl=%p\n", pidl);
1291 pdump(pidl);
1293 if (!pidl || !ppv)
1294 return E_INVALIDARG;
1296 *ppv = NULL;
1297 if (ppidlLast)
1298 *ppidlLast = NULL;
1300 hr = SHGetDesktopFolder(&psfDesktop);
1301 if (FAILED(hr))
1302 return hr;
1304 if (_ILIsPidlSimple(pidl))
1306 /* we are on desktop level */
1307 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1309 else
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);
1323 return hr;
1326 /*************************************************************************
1327 * SHParseDisplayName [SHELL32.@]
1329 HRESULT WINAPI SHParseDisplayName(LPCWSTR name, IBindCtx *bindctx, LPITEMIDLIST *pidlist,
1330 SFGAOF attr_in, SFGAOF *attr_out)
1332 IShellFolder *desktop;
1333 HRESULT hr;
1335 TRACE("%s %p %p %d %p\n", debugstr_w(name), bindctx, pidlist, attr_in, attr_out);
1337 *pidlist = NULL;
1339 if (!name) return E_INVALIDARG;
1341 hr = SHGetDesktopFolder(&desktop);
1342 if (hr != S_OK) return hr;
1344 hr = IShellFolder_ParseDisplayName(desktop, NULL, bindctx, (LPWSTR)name, NULL, pidlist, &attr_in);
1345 if (attr_out) *attr_out = attr_in;
1347 IShellFolder_Release(desktop);
1349 return hr;
1352 /*************************************************************************
1353 * SHGetNameFromIDList [SHELL32.@]
1355 HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName)
1357 IShellFolder *psfparent;
1358 LPCITEMIDLIST child_pidl;
1359 STRRET disp_name;
1360 HRESULT ret;
1362 TRACE("%p 0x%08x %p\n", pidl, sigdnName, ppszName);
1364 *ppszName = NULL;
1365 ret = SHBindToParent(pidl, &IID_IShellFolder, (void**)&psfparent, &child_pidl);
1366 if(SUCCEEDED(ret))
1368 switch(sigdnName)
1370 /* sigdnName & 0xffff */
1371 case SIGDN_NORMALDISPLAY: /* SHGDN_NORMAL */
1372 case SIGDN_PARENTRELATIVEPARSING: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1373 case SIGDN_PARENTRELATIVEEDITING: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1374 case SIGDN_DESKTOPABSOLUTEPARSING: /* SHGDN_FORPARSING */
1375 case SIGDN_DESKTOPABSOLUTEEDITING: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1376 case SIGDN_PARENTRELATIVEFORADDRESSBAR: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1377 case SIGDN_PARENTRELATIVE: /* SIGDN_INFOLDER */
1379 disp_name.uType = STRRET_WSTR;
1380 ret = IShellFolder_GetDisplayNameOf(psfparent, child_pidl,
1381 sigdnName & 0xffff,
1382 &disp_name);
1383 if(SUCCEEDED(ret))
1384 ret = StrRetToStrW(&disp_name, pidl, ppszName);
1386 break;
1388 case SIGDN_FILESYSPATH:
1389 *ppszName = CoTaskMemAlloc(sizeof(WCHAR)*MAX_PATH);
1390 if(SHGetPathFromIDListW(pidl, *ppszName))
1392 TRACE("Got string %s\n", debugstr_w(*ppszName));
1393 ret = S_OK;
1395 else
1397 CoTaskMemFree(*ppszName);
1398 ret = E_INVALIDARG;
1400 break;
1402 case SIGDN_URL:
1403 default:
1404 FIXME("Unsupported SIGDN %x\n", sigdnName);
1405 ret = E_FAIL;
1408 IShellFolder_Release(psfparent);
1410 return ret;
1413 /*************************************************************************
1414 * SHGetIDListFromObject [SHELL32.@]
1416 HRESULT WINAPI SHGetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl)
1418 IPersistIDList *ppersidl;
1419 IPersistFolder2 *ppf2;
1420 IDataObject *pdo;
1421 IFolderView *pfv;
1422 HRESULT ret;
1424 if(!punk)
1425 return E_NOINTERFACE;
1427 *ppidl = NULL;
1429 /* Try IPersistIDList */
1430 ret = IUnknown_QueryInterface(punk, &IID_IPersistIDList, (void**)&ppersidl);
1431 if(SUCCEEDED(ret))
1433 TRACE("IPersistIDList (%p)\n", ppersidl);
1434 ret = IPersistIDList_GetIDList(ppersidl, ppidl);
1435 IPersistIDList_Release(ppersidl);
1436 if(SUCCEEDED(ret))
1437 return ret;
1440 /* Try IPersistFolder2 */
1441 ret = IUnknown_QueryInterface(punk, &IID_IPersistFolder2, (void**)&ppf2);
1442 if(SUCCEEDED(ret))
1444 TRACE("IPersistFolder2 (%p)\n", ppf2);
1445 ret = IPersistFolder2_GetCurFolder(ppf2, ppidl);
1446 IPersistFolder2_Release(ppf2);
1447 if(SUCCEEDED(ret))
1448 return ret;
1451 /* Try IDataObject */
1452 ret = IUnknown_QueryInterface(punk, &IID_IDataObject, (void**)&pdo);
1453 if(SUCCEEDED(ret))
1455 IShellItem *psi;
1456 TRACE("IDataObject (%p)\n", pdo);
1457 ret = SHGetItemFromDataObject(pdo, DOGIF_ONLY_IF_ONE,
1458 &IID_IShellItem, (void**)&psi);
1459 if(SUCCEEDED(ret))
1461 ret = SHGetIDListFromObject((IUnknown*)psi, ppidl);
1462 IShellItem_Release(psi);
1464 IDataObject_Release(pdo);
1466 if(SUCCEEDED(ret))
1467 return ret;
1470 /* Try IFolderView */
1471 ret = IUnknown_QueryInterface(punk, &IID_IFolderView, (void**)&pfv);
1472 if(SUCCEEDED(ret))
1474 IShellFolder *psf;
1475 TRACE("IFolderView (%p)\n", pfv);
1476 ret = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1477 if(SUCCEEDED(ret))
1479 /* We might be able to get IPersistFolder2 from a shellfolder. */
1480 ret = SHGetIDListFromObject((IUnknown*)psf, ppidl);
1482 IFolderView_Release(pfv);
1483 return ret;
1486 return ret;
1489 /**************************************************************************
1491 * internal functions
1493 * ### 1. section creating pidls ###
1495 *************************************************************************
1498 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1499 * - two bytes are SHITEMID.cb
1500 * - one byte is PIDLDATA.type
1501 * - two bytes are the NULL PIDL terminator
1502 * Sets type of the returned PIDL to type.
1504 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1506 LPITEMIDLIST pidlOut = NULL;
1508 pidlOut = SHAlloc(size + 5);
1509 if(pidlOut)
1511 LPPIDLDATA pData;
1512 LPITEMIDLIST pidlNext;
1514 ZeroMemory(pidlOut, size + 5);
1515 pidlOut->mkid.cb = size + 3;
1517 pData = _ILGetDataPointer(pidlOut);
1518 if (pData)
1519 pData->type = type;
1521 pidlNext = ILGetNext(pidlOut);
1522 if (pidlNext)
1523 pidlNext->mkid.cb = 0x00;
1524 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1527 return pidlOut;
1530 LPITEMIDLIST _ILCreateDesktop(void)
1532 LPITEMIDLIST ret;
1534 TRACE("()\n");
1535 ret = SHAlloc(2);
1536 if (ret)
1537 ret->mkid.cb = 0;
1538 return ret;
1541 LPITEMIDLIST _ILCreateMyComputer(void)
1543 TRACE("()\n");
1544 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1547 LPITEMIDLIST _ILCreateMyDocuments(void)
1549 TRACE("()\n");
1550 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1553 LPITEMIDLIST _ILCreateIExplore(void)
1555 TRACE("()\n");
1556 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1559 LPITEMIDLIST _ILCreateControlPanel(void)
1561 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1563 TRACE("()\n");
1564 if (parent)
1566 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1568 if (cpl)
1570 ret = ILCombine(parent, cpl);
1571 SHFree(cpl);
1573 SHFree(parent);
1575 return ret;
1578 LPITEMIDLIST _ILCreatePrinters(void)
1580 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1582 TRACE("()\n");
1583 if (parent)
1585 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1587 if (printers)
1589 ret = ILCombine(parent, printers);
1590 SHFree(printers);
1592 SHFree(parent);
1594 return ret;
1597 LPITEMIDLIST _ILCreateNetwork(void)
1599 TRACE("()\n");
1600 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1603 LPITEMIDLIST _ILCreateBitBucket(void)
1605 TRACE("()\n");
1606 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1609 LPITEMIDLIST _ILCreateNetHood(void)
1611 TRACE("()\n");
1612 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1615 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1617 LPITEMIDLIST pidlOut;
1619 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1621 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1622 if (pidlOut)
1624 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1626 pData->u.guid.guid = *guid;
1627 TRACE("-- create GUID-pidl %s\n",
1628 debugstr_guid(&(pData->u.guid.guid)));
1631 else
1633 WARN("%d: invalid type for GUID\n", type);
1634 pidlOut = NULL;
1636 return pidlOut;
1639 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1641 IID iid;
1643 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1645 ERR("%s is not a GUID\n", szGUID);
1646 return NULL;
1648 return _ILCreateGuid(PT_GUID, &iid);
1651 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1653 IID iid;
1655 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1657 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1658 return NULL;
1660 return _ILCreateGuid(PT_GUID, &iid);
1663 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1665 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1666 DWORD len, len1, wlen, alen;
1667 LPITEMIDLIST pidl;
1668 PIDLTYPE type;
1670 if (!wfd)
1671 return NULL;
1673 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1675 /* prepare buffer with both names */
1676 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1677 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1678 alen = len + len1;
1680 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1682 wlen = lstrlenW(wfd->cFileName) + 1;
1683 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1684 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1685 if (pidl)
1687 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1688 FileStruct *fs = &pData->u.file;
1689 FileStructW *fsw;
1690 WORD *pOffsetW;
1692 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1693 fs->dwFileSize = wfd->nFileSizeLow;
1694 fs->uFileAttribs = wfd->dwFileAttributes;
1695 memcpy(fs->szNames, buff, alen);
1697 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1698 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1699 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1700 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1701 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1703 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1704 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1705 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1707 return pidl;
1711 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1713 HANDLE hFile;
1714 WIN32_FIND_DATAW stffile;
1716 if (!ppidl)
1717 return E_INVALIDARG;
1719 hFile = FindFirstFileW(szPath, &stffile);
1720 if (hFile == INVALID_HANDLE_VALUE)
1721 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1723 FindClose(hFile);
1725 *ppidl = _ILCreateFromFindDataW(&stffile);
1727 return *ppidl ? S_OK : E_OUTOFMEMORY;
1730 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1732 LPITEMIDLIST pidlOut;
1734 TRACE("(%s)\n",debugstr_w(lpszNew));
1736 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1737 if (pidlOut)
1739 LPSTR pszDest;
1741 pszDest = _ILGetTextPointer(pidlOut);
1742 if (pszDest)
1744 strcpy(pszDest, "x:\\");
1745 pszDest[0]=toupperW(lpszNew[0]);
1746 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1749 return pidlOut;
1752 LPITEMIDLIST _ILCreateEntireNetwork(void)
1754 LPITEMIDLIST pidlOut;
1756 TRACE("\n");
1758 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1759 if (pidlOut)
1761 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1763 pData->u.network.dummy = 0;
1764 strcpy(pData->u.network.szNames, "Entire Network");
1766 return pidlOut;
1769 /**************************************************************************
1770 * _ILGetDrive()
1772 * Gets the text for the drive eg. 'c:\'
1774 * RETURNS
1775 * strlen (lpszText)
1777 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1779 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1781 if(_ILIsMyComputer(pidl))
1782 pidl = ILGetNext(pidl);
1784 if (pidl && _ILIsDrive(pidl))
1785 return _ILSimpleGetText(pidl, pOut, uSize);
1787 return 0;
1790 /**************************************************************************
1792 * ### 2. section testing pidls ###
1794 **************************************************************************
1795 * _ILIsUnicode()
1796 * _ILIsDesktop()
1797 * _ILIsMyComputer()
1798 * _ILIsSpecialFolder()
1799 * _ILIsDrive()
1800 * _ILIsFolder()
1801 * _ILIsValue()
1802 * _ILIsPidlSimple()
1804 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1806 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1808 TRACE("(%p)\n",pidl);
1810 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1813 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1815 TRACE("(%p)\n",pidl);
1817 return pidl && pidl->mkid.cb ? FALSE : TRUE;
1820 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1822 REFIID iid = _ILGetGUIDPointer(pidl);
1824 TRACE("(%p)\n",pidl);
1826 if (iid)
1827 return IsEqualIID(iid, &CLSID_MyComputer);
1828 return FALSE;
1831 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1833 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1835 TRACE("(%p)\n",pidl);
1837 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1838 (pidl && pidl->mkid.cb == 0x00)
1842 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1844 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1846 TRACE("(%p)\n",pidl);
1848 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1849 PT_DRIVE1 == lpPData->type ||
1850 PT_DRIVE2 == lpPData->type ||
1851 PT_DRIVE3 == lpPData->type));
1854 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1856 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1858 TRACE("(%p)\n",pidl);
1860 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1863 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1865 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1867 TRACE("(%p)\n",pidl);
1869 return (pidl && lpPData && PT_VALUE == lpPData->type);
1872 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1874 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1876 TRACE("(%p)\n",pidl);
1878 return (pidl && lpPData && (lpPData->type == 0));
1881 /**************************************************************************
1882 * _ILIsPidlSimple
1884 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1886 BOOL ret = TRUE;
1888 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1890 WORD len = pidl->mkid.cb;
1891 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1893 if (pidlnext->mkid.cb)
1894 ret = FALSE;
1897 TRACE("%s\n", ret ? "Yes" : "No");
1898 return ret;
1901 /**************************************************************************
1903 * ### 3. section getting values from pidls ###
1906 /**************************************************************************
1907 * _ILSimpleGetText
1909 * gets the text for the first item in the pidl (eg. simple pidl)
1911 * returns the length of the string
1913 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1915 DWORD dwReturn=0;
1916 LPSTR szSrc;
1917 LPWSTR szSrcW;
1918 GUID const * riid;
1919 char szTemp[MAX_PATH];
1921 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1923 if (!pidl)
1924 return 0;
1926 if (szOut)
1927 *szOut = 0;
1929 if (_ILIsDesktop(pidl))
1931 /* desktop */
1932 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1934 if (szOut)
1935 lstrcpynA(szOut, szTemp, uOutSize);
1937 dwReturn = strlen (szTemp);
1940 else if (( szSrc = _ILGetTextPointer(pidl) ))
1942 /* filesystem */
1943 if (szOut)
1944 lstrcpynA(szOut, szSrc, uOutSize);
1946 dwReturn = strlen(szSrc);
1948 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1950 /* unicode filesystem */
1951 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1953 if (szOut)
1954 lstrcpynA(szOut, szTemp, uOutSize);
1956 dwReturn = strlen (szTemp);
1958 else if (( riid = _ILGetGUIDPointer(pidl) ))
1960 /* special folder */
1961 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1963 if (szOut)
1964 lstrcpynA(szOut, szTemp, uOutSize);
1966 dwReturn = strlen (szTemp);
1969 else
1971 ERR("-- no text\n");
1974 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1975 return dwReturn;
1978 /**************************************************************************
1979 * _ILSimpleGetTextW
1981 * gets the text for the first item in the pidl (eg. simple pidl)
1983 * returns the length of the string
1985 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1987 DWORD dwReturn;
1988 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1990 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1992 if (pFileStructW) {
1993 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1994 dwReturn = lstrlenW(pFileStructW->wszName);
1995 } else {
1996 GUID const * riid;
1997 WCHAR szTemp[MAX_PATH];
1998 LPSTR szSrc;
1999 LPWSTR szSrcW;
2000 dwReturn=0;
2002 if (!pidl)
2003 return 0;
2005 if (szOut)
2006 *szOut = 0;
2008 if (_ILIsDesktop(pidl))
2010 /* desktop */
2011 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
2013 if (szOut)
2014 lstrcpynW(szOut, szTemp, uOutSize);
2016 dwReturn = lstrlenW (szTemp);
2019 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
2021 /* unicode filesystem */
2022 if (szOut)
2023 lstrcpynW(szOut, szSrcW, uOutSize);
2025 dwReturn = lstrlenW(szSrcW);
2027 else if (( szSrc = _ILGetTextPointer(pidl) ))
2029 /* filesystem */
2030 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
2032 if (szOut)
2033 lstrcpynW(szOut, szTemp, uOutSize);
2035 dwReturn = lstrlenW (szTemp);
2037 else if (( riid = _ILGetGUIDPointer(pidl) ))
2039 /* special folder */
2040 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
2042 if (szOut)
2043 lstrcpynW(szOut, szTemp, uOutSize);
2045 dwReturn = lstrlenW (szTemp);
2048 else
2050 ERR("-- no text\n");
2054 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
2055 return dwReturn;
2058 /**************************************************************************
2060 * ### 4. getting pointers to parts of pidls ###
2062 **************************************************************************
2063 * _ILGetDataPointer()
2065 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
2067 if(!_ILIsEmpty(pidl))
2068 return (LPPIDLDATA)pidl->mkid.abID;
2069 return NULL;
2072 /**************************************************************************
2073 * _ILGetTextPointerW()
2074 * gets a pointer to the unicode long filename string stored in the pidl
2076 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
2078 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2080 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2082 if (!pdata)
2083 return NULL;
2085 switch (pdata->type)
2087 case PT_GUID:
2088 case PT_SHELLEXT:
2089 case PT_YAGUID:
2090 return NULL;
2092 case PT_DRIVE:
2093 case PT_DRIVE1:
2094 case PT_DRIVE2:
2095 case PT_DRIVE3:
2096 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2097 return NULL;
2099 case PT_FOLDER:
2100 case PT_FOLDER1:
2101 case PT_VALUE:
2102 case PT_IESPECIAL1:
2103 case PT_IESPECIAL2:
2104 /*return (LPSTR)&(pdata->u.file.szNames);*/
2105 return NULL;
2107 case PT_WORKGRP:
2108 case PT_COMP:
2109 case PT_NETWORK:
2110 case PT_NETPROVIDER:
2111 case PT_SHARE:
2112 /*return (LPSTR)&(pdata->u.network.szNames);*/
2113 return NULL;
2115 case PT_VALUEW:
2116 return (LPWSTR)pdata->u.file.szNames;
2118 return NULL;
2122 /**************************************************************************
2123 * _ILGetTextPointer()
2124 * gets a pointer to the long filename string stored in the pidl
2126 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
2128 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2130 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2132 if (!pdata)
2133 return NULL;
2135 switch (pdata->type)
2137 case PT_GUID:
2138 case PT_SHELLEXT:
2139 case PT_YAGUID:
2140 return NULL;
2142 case PT_DRIVE:
2143 case PT_DRIVE1:
2144 case PT_DRIVE2:
2145 case PT_DRIVE3:
2146 return pdata->u.drive.szDriveName;
2148 case PT_FOLDER:
2149 case PT_FOLDER1:
2150 case PT_VALUE:
2151 case PT_IESPECIAL1:
2152 case PT_IESPECIAL2:
2153 return pdata->u.file.szNames;
2155 case PT_WORKGRP:
2156 case PT_COMP:
2157 case PT_NETWORK:
2158 case PT_NETPROVIDER:
2159 case PT_SHARE:
2160 return pdata->u.network.szNames;
2162 return NULL;
2165 /**************************************************************************
2166 * _ILGetSTextPointer()
2167 * gets a pointer to the short filename string stored in the pidl
2169 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2171 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2173 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2175 if (!pdata)
2176 return NULL;
2178 switch (pdata->type)
2180 case PT_FOLDER:
2181 case PT_VALUE:
2182 case PT_IESPECIAL1:
2183 case PT_IESPECIAL2:
2184 return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
2186 case PT_WORKGRP:
2187 return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
2189 return NULL;
2192 /**************************************************************************
2193 * _ILGetGUIDPointer()
2195 * returns reference to guid stored in some pidls
2197 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2199 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2201 TRACE("%p\n", pidl);
2203 if (!pdata)
2204 return NULL;
2206 TRACE("pdata->type 0x%04x\n", pdata->type);
2207 switch (pdata->type)
2209 case PT_SHELLEXT:
2210 case PT_GUID:
2211 case PT_YAGUID:
2212 return &(pdata->u.guid.guid);
2214 default:
2215 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2216 break;
2218 return NULL;
2221 /******************************************************************************
2222 * _ILGetFileStructW [Internal]
2224 * Get pointer the a SHITEMID's FileStructW field if present
2226 * PARAMS
2227 * pidl [I] The SHITEMID
2229 * RETURNS
2230 * Success: Pointer to pidl's FileStructW field.
2231 * Failure: NULL
2233 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2234 FileStructW *pFileStructW;
2235 WORD cbOffset;
2237 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2238 return NULL;
2240 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2241 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2243 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2244 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2245 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2246 if ((cbOffset & 0x1) || /* FileStructW member is word aligned in the pidl */
2247 /* FileStructW is positioned after FileStruct */
2248 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2249 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2250 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2251 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2253 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2254 return NULL;
2257 return pFileStructW;
2260 /*************************************************************************
2261 * _ILGetFileDateTime
2263 * Given the ItemIdList, get the FileTime
2265 * PARAMS
2266 * pidl [I] The ItemIDList
2267 * pFt [I] the resulted FILETIME of the file
2269 * RETURNS
2270 * True if Successful
2272 * NOTES
2275 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2277 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2279 if (!pdata)
2280 return FALSE;
2282 switch (pdata->type)
2284 case PT_FOLDER:
2285 case PT_VALUE:
2286 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2287 break;
2288 default:
2289 return FALSE;
2291 return TRUE;
2294 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2296 FILETIME ft,lft;
2297 SYSTEMTIME time;
2298 BOOL ret;
2300 if (_ILGetFileDateTime( pidl, &ft ))
2302 FileTimeToLocalFileTime(&ft, &lft);
2303 FileTimeToSystemTime (&lft, &time);
2305 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2306 if (ret)
2308 /* Append space + time without seconds */
2309 pOut[ret-1] = ' ';
2310 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2313 else
2315 pOut[0] = '\0';
2316 ret = FALSE;
2318 return ret;
2321 /*************************************************************************
2322 * _ILGetFileSize
2324 * Given the ItemIdList, get the FileSize
2326 * PARAMS
2327 * pidl [I] The ItemIDList
2328 * pOut [I] The buffer to save the result
2329 * uOutsize [I] The size of the buffer
2331 * RETURNS
2332 * The FileSize
2334 * NOTES
2335 * pOut can be null when no string is needed
2338 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2340 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2341 DWORD dwSize;
2343 if (!pdata)
2344 return 0;
2346 switch (pdata->type)
2348 case PT_VALUE:
2349 dwSize = pdata->u.file.dwFileSize;
2350 if (pOut)
2351 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2352 return dwSize;
2354 if (pOut)
2355 *pOut = 0x00;
2356 return 0;
2359 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2361 char szTemp[MAX_PATH];
2362 const char * pPoint;
2363 LPCITEMIDLIST pidlTemp=pidl;
2365 TRACE("pidl=%p\n",pidl);
2367 if (!pidl)
2368 return FALSE;
2370 pidlTemp = ILFindLastID(pidl);
2372 if (!_ILIsValue(pidlTemp))
2373 return FALSE;
2374 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2375 return FALSE;
2377 pPoint = PathFindExtensionA(szTemp);
2379 if (!*pPoint)
2380 return FALSE;
2382 pPoint++;
2383 lstrcpynA(pOut, pPoint, uOutSize);
2384 TRACE("%s\n",pOut);
2386 return TRUE;
2389 /*************************************************************************
2390 * _ILGetFileType
2392 * Given the ItemIdList, get the file type description
2394 * PARAMS
2395 * pidl [I] The ItemIDList (simple)
2396 * pOut [I] The buffer to save the result
2397 * uOutsize [I] The size of the buffer
2399 * RETURNS
2400 * nothing
2402 * NOTES
2403 * This function copies as much as possible into the buffer.
2405 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2407 if(_ILIsValue(pidl))
2409 char sTemp[64];
2411 if(uOutSize > 0)
2412 pOut[0] = 0;
2413 if (_ILGetExtension (pidl, sTemp, 64))
2415 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2416 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2418 lstrcpynA (pOut, sTemp, uOutSize - 6);
2419 strcat (pOut, "-file");
2423 else
2424 lstrcpynA(pOut, "Folder", uOutSize);
2427 /*************************************************************************
2428 * _ILGetFileAttributes
2430 * Given the ItemIdList, get the Attrib string format
2432 * PARAMS
2433 * pidl [I] The ItemIDList
2434 * pOut [I] The buffer to save the result
2435 * uOutsize [I] The size of the Buffer
2437 * RETURNS
2438 * Attributes
2440 * FIXME
2441 * return value 0 in case of error is a valid return value
2444 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2446 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2447 WORD wAttrib = 0;
2448 int i;
2450 if (!pData)
2451 return 0;
2453 switch(pData->type)
2455 case PT_FOLDER:
2456 case PT_VALUE:
2457 wAttrib = pData->u.file.uFileAttribs;
2458 break;
2461 if(uOutSize >= 6)
2463 i=0;
2464 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2465 pOut[i++] = 'R';
2466 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2467 pOut[i++] = 'H';
2468 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2469 pOut[i++] = 'S';
2470 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2471 pOut[i++] = 'A';
2472 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2473 pOut[i++] = 'C';
2474 pOut[i] = 0x00;
2476 return wAttrib;
2479 /*************************************************************************
2480 * ILFreeaPidl
2482 * free a aPidl struct
2484 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2486 UINT i;
2488 if (apidl)
2490 for (i = 0; i < cidl; i++)
2491 SHFree(apidl[i]);
2492 SHFree(apidl);
2496 /*************************************************************************
2497 * ILCopyaPidl
2499 * copies an aPidl struct
2501 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2503 UINT i;
2504 LPITEMIDLIST *apidldest;
2506 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2507 if (!apidlsrc)
2508 return NULL;
2510 for (i = 0; i < cidl; i++)
2511 apidldest[i] = ILClone(apidlsrc[i]);
2513 return apidldest;
2516 /*************************************************************************
2517 * _ILCopyCidaToaPidl
2519 * creates aPidl from CIDA
2521 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2523 UINT i;
2524 LPITEMIDLIST *dst;
2526 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2527 if (!dst)
2528 return NULL;
2530 if (pidl)
2531 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2533 for (i = 0; i < cida->cidl; i++)
2534 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2536 return dst;