msxml3: Stub domdoc_get_readyState().
[wine/multimedia.git] / dlls / shell32 / pidl.c
blob1c9cf22546d8c2ebd8a953d832a72fe7418546ee
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
548 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
550 char szData1[MAX_PATH];
551 char szData2[MAX_PATH];
552 LPCITEMIDLIST pParent = pidlParent;
553 LPCITEMIDLIST pChild = pidlChild;
555 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
557 if (!pParent || !pChild)
558 return FALSE;
560 while (pParent->mkid.cb && pChild->mkid.cb)
562 _ILSimpleGetText(pParent, szData1, MAX_PATH);
563 _ILSimpleGetText(pChild, szData2, MAX_PATH);
565 if (strcasecmp( szData1, szData2 ))
566 return FALSE;
568 pParent = ILGetNext(pParent);
569 pChild = ILGetNext(pChild);
572 /* child shorter or has equal length to parent */
573 if (pParent->mkid.cb || !pChild->mkid.cb)
574 return FALSE;
576 /* not immediate descent */
577 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
578 return FALSE;
580 return TRUE;
583 /*************************************************************************
584 * ILFindChild [SHELL32.24]
586 * Compares elements from pidl1 and pidl2.
588 * PARAMS
589 * pidl1 [I]
590 * pidl2 [I]
592 * RETURNS
593 * pidl1 is desktop pidl2
594 * pidl1 shorter pidl2 pointer to first different element of pidl2
595 * if there was at least one equal element
596 * pidl2 shorter pidl1 0
597 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
599 * NOTES
600 * exported by ordinal.
602 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
604 char szData1[MAX_PATH];
605 char szData2[MAX_PATH];
607 LPCITEMIDLIST pidltemp1 = pidl1;
608 LPCITEMIDLIST pidltemp2 = pidl2;
609 LPCITEMIDLIST ret=NULL;
611 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
613 /* explorer reads from registry directly (StreamMRU),
614 so we can only check here */
615 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
616 return FALSE;
618 pdump (pidl1);
619 pdump (pidl2);
621 if (_ILIsDesktop(pidl1))
623 ret = pidl2;
625 else
627 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
629 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
630 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
632 if (strcasecmp(szData1,szData2))
633 break;
635 pidltemp1 = ILGetNext(pidltemp1);
636 pidltemp2 = ILGetNext(pidltemp2);
637 ret = pidltemp2;
640 if (pidltemp1->mkid.cb)
641 ret = NULL; /* elements of pidl1 left*/
643 TRACE_(shell)("--- %p\n", ret);
644 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
647 /*************************************************************************
648 * ILCombine [SHELL32.25]
650 * Concatenates two complex ItemIDLists.
652 * PARAMS
653 * pidl1 [I] first complex ItemIDLists
654 * pidl2 [I] complex ItemIDLists to append
656 * RETURNS
657 * if both pidl's == NULL NULL
658 * if pidl1 == NULL cloned pidl2
659 * if pidl2 == NULL cloned pidl1
660 * otherwise new pidl with pidl2 appended to pidl1
662 * NOTES
663 * exported by ordinal.
664 * Does not destroy the passed in ItemIDLists!
666 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
668 DWORD len1,len2;
669 LPITEMIDLIST pidlNew;
671 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
673 if (!pidl1 && !pidl2) return NULL;
675 pdump (pidl1);
676 pdump (pidl2);
678 if (!pidl1)
680 pidlNew = ILClone(pidl2);
681 return pidlNew;
684 if (!pidl2)
686 pidlNew = ILClone(pidl1);
687 return pidlNew;
690 len1 = ILGetSize(pidl1)-2;
691 len2 = ILGetSize(pidl2);
692 pidlNew = SHAlloc(len1+len2);
694 if (pidlNew)
696 memcpy(pidlNew,pidl1,len1);
697 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
700 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
701 return pidlNew;
704 /*************************************************************************
705 * SHGetRealIDL [SHELL32.98]
707 * NOTES
709 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
711 IDataObject* pDataObj;
712 HRESULT hr;
714 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
715 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
716 if (SUCCEEDED(hr))
718 STGMEDIUM medium;
719 FORMATETC fmt;
721 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
722 fmt.ptd = NULL;
723 fmt.dwAspect = DVASPECT_CONTENT;
724 fmt.lindex = -1;
725 fmt.tymed = TYMED_HGLOBAL;
727 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
729 IDataObject_Release(pDataObj);
731 if (SUCCEEDED(hr))
733 /*assert(pida->cidl==1);*/
734 LPIDA pida = GlobalLock(medium.u.hGlobal);
736 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
737 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
739 *pidlReal = ILCombine(pidl_folder, pidl_child);
741 if (!*pidlReal)
742 hr = E_OUTOFMEMORY;
744 GlobalUnlock(medium.u.hGlobal);
745 GlobalFree(medium.u.hGlobal);
749 return hr;
752 /*************************************************************************
753 * SHLogILFromFSIL [SHELL32.95]
755 * NOTES
756 * pild = CSIDL_DESKTOP ret = 0
757 * pild = CSIDL_DRIVES ret = 0
759 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
761 FIXME("(pidl=%p)\n",pidl);
763 pdump(pidl);
765 return 0;
768 /*************************************************************************
769 * ILGetSize [SHELL32.152]
771 * Gets the byte size of an ItemIDList including zero terminator
773 * PARAMS
774 * pidl [I] ItemIDList
776 * RETURNS
777 * size of pidl in bytes
779 * NOTES
780 * exported by ordinal
782 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
784 LPCSHITEMID si = &(pidl->mkid);
785 UINT len=0;
787 if (pidl)
789 while (si->cb)
791 len += si->cb;
792 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
794 len += 2;
796 TRACE("pidl=%p size=%u\n",pidl, len);
797 return len;
800 /*************************************************************************
801 * ILGetNext [SHELL32.153]
803 * Gets the next ItemID of an ItemIDList
805 * PARAMS
806 * pidl [I] ItemIDList
808 * RETURNS
809 * null -> null
810 * desktop -> null
811 * simple pidl -> pointer to 0x0000 element
813 * NOTES
814 * exported by ordinal.
816 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
818 WORD len;
820 TRACE("%p\n", pidl);
822 if (pidl)
824 len = pidl->mkid.cb;
825 if (len)
827 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
828 TRACE("-- %p\n", pidl);
829 return (LPITEMIDLIST)pidl;
832 return NULL;
835 /*************************************************************************
836 * ILAppendID [SHELL32.154]
838 * Adds the single ItemID item to the ItemIDList indicated by pidl.
839 * If bEnd is FALSE, inserts the item in the front of the list,
840 * otherwise it adds the item to the end. (???)
842 * PARAMS
843 * pidl [I] ItemIDList to extend
844 * item [I] ItemID to prepend/append
845 * bEnd [I] Indicates if the item should be appended
847 * NOTES
848 * Destroys the passed in idlist! (???)
850 LPITEMIDLIST WINAPI ILAppendID(LPITEMIDLIST pidl, LPCSHITEMID item, BOOL bEnd)
852 LPITEMIDLIST idlRet;
853 LPCITEMIDLIST itemid = (LPCITEMIDLIST)item;
855 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
857 pdump (pidl);
858 pdump (itemid);
860 if (_ILIsDesktop(pidl))
862 idlRet = ILClone(itemid);
863 SHFree (pidl);
864 return idlRet;
867 if (bEnd)
868 idlRet = ILCombine(pidl, itemid);
869 else
870 idlRet = ILCombine(itemid, pidl);
872 SHFree(pidl);
873 return idlRet;
876 /*************************************************************************
877 * ILFree [SHELL32.155]
879 * Frees memory (if not NULL) allocated by SHMalloc allocator
881 * PARAMS
882 * pidl [I]
884 * RETURNS
885 * Nothing
887 * NOTES
888 * exported by ordinal
890 void WINAPI ILFree(LPITEMIDLIST pidl)
892 TRACE("(pidl=%p)\n",pidl);
893 SHFree(pidl);
896 /*************************************************************************
897 * ILGlobalFree [SHELL32.156]
899 * Frees memory (if not NULL) allocated by Alloc allocator
901 * PARAMS
902 * pidl [I]
904 * RETURNS
905 * Nothing
907 * NOTES
908 * exported by ordinal.
910 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
912 TRACE("%p\n", pidl);
914 Free(pidl);
917 /*************************************************************************
918 * ILCreateFromPathA [SHELL32.189]
920 * Creates a complex ItemIDList from a path and returns it.
922 * PARAMS
923 * path [I]
925 * RETURNS
926 * the newly created complex ItemIDList or NULL if failed
928 * NOTES
929 * exported by ordinal.
931 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
933 LPITEMIDLIST pidlnew = NULL;
935 TRACE_(shell)("%s\n", debugstr_a(path));
937 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
938 return pidlnew;
939 return NULL;
942 /*************************************************************************
943 * ILCreateFromPathW [SHELL32.190]
945 * See ILCreateFromPathA.
947 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
949 LPITEMIDLIST pidlnew = NULL;
951 TRACE_(shell)("%s\n", debugstr_w(path));
953 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
954 return pidlnew;
955 return NULL;
958 /*************************************************************************
959 * ILCreateFromPath [SHELL32.157]
961 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
963 if ( SHELL_OsIsUnicode())
964 return ILCreateFromPathW (path);
965 return ILCreateFromPathA (path);
968 /*************************************************************************
969 * _ILParsePathW [internal]
971 * Creates an ItemIDList from a path and returns it.
973 * PARAMS
974 * path [I] path to parse and convert into an ItemIDList
975 * lpFindFile [I] pointer to buffer to initialize the FileSystem
976 * Bind Data object with
977 * bBindCtx [I] indicates to create a BindContext and assign a
978 * FileSystem Bind Data object
979 * ppidl [O] the newly create ItemIDList
980 * prgfInOut [I/O] requested attributes on input and actual
981 * attributes on return
983 * RETURNS
984 * NO_ERROR on success or an OLE error code
986 * NOTES
987 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
988 * creates a BindContext object and assigns a FileSystem Bind Data object
989 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
990 * IShellFolder uses that FileSystem Bind Data object of the BindContext
991 * to pass data about the current path element to the next object. This
992 * is used to avoid having to verify the current path element on disk, so
993 * that creating an ItemIDList from a nonexistent path still can work.
995 static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
996 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
998 LPSHELLFOLDER pSF = NULL;
999 LPBC pBC = NULL;
1000 HRESULT ret;
1002 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
1003 ppidl, ppidl ? *ppidl : NULL,
1004 prgfInOut, prgfInOut ? *prgfInOut : 0);
1006 ret = SHGetDesktopFolder(&pSF);
1007 if (FAILED(ret))
1008 return ret;
1010 if (lpFindFile || bBindCtx)
1011 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1013 if (SUCCEEDED(ret))
1015 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1018 if (pBC)
1020 IBindCtx_Release(pBC);
1021 pBC = NULL;
1024 IShellFolder_Release(pSF);
1026 if (FAILED(ret) && ppidl)
1027 *ppidl = NULL;
1029 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1031 return ret;
1034 /*************************************************************************
1035 * SHSimpleIDListFromPath [SHELL32.162]
1037 * Creates a simple ItemIDList from a path and returns it. This function
1038 * does not fail on nonexistent paths.
1040 * PARAMS
1041 * path [I] path to parse and convert into an ItemIDList
1043 * RETURNS
1044 * the newly created simple ItemIDList
1046 * NOTES
1047 * Simple in the name does not mean a relative ItemIDList but rather a
1048 * fully qualified list, where only the file name is filled in and the
1049 * directory flag for those ItemID elements this is known about, eg.
1050 * it is not the last element in the ItemIDList or the actual directory
1051 * exists on disk.
1052 * exported by ordinal.
1054 LPITEMIDLIST SHSimpleIDListFromPathA(LPCSTR lpszPath)
1056 LPITEMIDLIST pidl = NULL;
1057 LPWSTR wPath = NULL;
1058 int len;
1060 TRACE("%s\n", debugstr_a(lpszPath));
1062 if (lpszPath)
1064 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1065 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1066 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1069 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1071 HeapFree(GetProcessHeap(), 0, wPath);
1072 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1073 return pidl;
1076 LPITEMIDLIST SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1078 LPITEMIDLIST pidl = NULL;
1080 TRACE("%s\n", debugstr_w(lpszPath));
1082 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1083 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1084 return pidl;
1087 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1089 if ( SHELL_OsIsUnicode())
1090 return SHSimpleIDListFromPathW (lpszPath);
1091 return SHSimpleIDListFromPathA (lpszPath);
1094 /*************************************************************************
1095 * SHGetDataFromIDListA [SHELL32.247]
1097 * NOTES
1098 * the pidl can be a simple one. since we can't get the path out of the pidl
1099 * we have to take all data from the pidl
1101 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1102 int nFormat, LPVOID dest, int len)
1104 LPSTR filename, shortname;
1105 WIN32_FIND_DATAA * pfd;
1107 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1109 pdump(pidl);
1110 if (!psf || !dest)
1111 return E_INVALIDARG;
1113 switch (nFormat)
1115 case SHGDFIL_FINDDATA:
1116 pfd = dest;
1118 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1119 return E_INVALIDARG;
1121 if (len < sizeof(WIN32_FIND_DATAA))
1122 return E_INVALIDARG;
1124 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1125 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1126 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1127 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1129 filename = _ILGetTextPointer(pidl);
1130 shortname = _ILGetSTextPointer(pidl);
1132 if (filename)
1133 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1134 else
1135 pfd->cFileName[0] = '\0';
1137 if (shortname)
1138 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1139 else
1140 pfd->cAlternateFileName[0] = '\0';
1141 return NOERROR;
1143 case SHGDFIL_NETRESOURCE:
1144 case SHGDFIL_DESCRIPTIONID:
1145 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1146 break;
1148 default:
1149 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1152 return E_INVALIDARG;
1155 /*************************************************************************
1156 * SHGetDataFromIDListW [SHELL32.248]
1159 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1160 int nFormat, LPVOID dest, int len)
1162 LPSTR filename, shortname;
1163 WIN32_FIND_DATAW * pfd = dest;
1165 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1167 pdump(pidl);
1169 if (!psf || !dest)
1170 return E_INVALIDARG;
1172 switch (nFormat)
1174 case SHGDFIL_FINDDATA:
1175 pfd = dest;
1177 if (_ILIsDrive(pidl))
1178 return E_INVALIDARG;
1180 if (len < sizeof(WIN32_FIND_DATAW))
1181 return E_INVALIDARG;
1183 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1184 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1185 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1186 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1188 filename = _ILGetTextPointer(pidl);
1189 shortname = _ILGetSTextPointer(pidl);
1191 if (!filename)
1192 pfd->cFileName[0] = '\0';
1193 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1194 pfd->cFileName[MAX_PATH-1] = 0;
1196 if (!shortname)
1197 pfd->cAlternateFileName[0] = '\0';
1198 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1199 pfd->cAlternateFileName[13] = 0;
1200 return NOERROR;
1202 case SHGDFIL_NETRESOURCE:
1203 case SHGDFIL_DESCRIPTIONID:
1204 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1205 break;
1207 default:
1208 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1211 return E_INVALIDARG;
1214 /*************************************************************************
1215 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1217 * PARAMETERS
1218 * pidl, [IN] pidl
1219 * pszPath [OUT] path
1221 * RETURNS
1222 * path from a passed PIDL.
1224 * NOTES
1225 * NULL returns FALSE
1226 * desktop pidl gives path to desktop directory back
1227 * special pidls returning FALSE
1229 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1231 WCHAR wszPath[MAX_PATH];
1232 BOOL bSuccess;
1234 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1235 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1237 return bSuccess;
1240 /*************************************************************************
1241 * SHGetPathFromIDListW [SHELL32.@]
1243 * See SHGetPathFromIDListA.
1245 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1247 HRESULT hr;
1248 LPCITEMIDLIST pidlLast;
1249 LPSHELLFOLDER psfFolder;
1250 DWORD dwAttributes;
1251 STRRET strret;
1253 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1254 pdump(pidl);
1256 *pszPath = '\0';
1257 if (!pidl)
1258 return FALSE;
1260 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1261 if (FAILED(hr)) return FALSE;
1263 dwAttributes = SFGAO_FILESYSTEM;
1264 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1265 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1266 IShellFolder_Release(psfFolder);
1267 return FALSE;
1270 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1271 IShellFolder_Release(psfFolder);
1272 if (FAILED(hr)) return FALSE;
1274 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1276 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1277 return SUCCEEDED(hr);
1280 /*************************************************************************
1281 * SHBindToParent [shell version 5.0]
1283 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1285 IShellFolder * psfDesktop;
1286 HRESULT hr=E_FAIL;
1288 TRACE_(shell)("pidl=%p\n", pidl);
1289 pdump(pidl);
1291 if (!pidl || !ppv)
1292 return E_INVALIDARG;
1294 *ppv = NULL;
1295 if (ppidlLast)
1296 *ppidlLast = NULL;
1298 hr = SHGetDesktopFolder(&psfDesktop);
1299 if (FAILED(hr))
1300 return hr;
1302 if (_ILIsPidlSimple(pidl))
1304 /* we are on desktop level */
1305 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1307 else
1309 LPITEMIDLIST pidlParent = ILClone(pidl);
1310 ILRemoveLastID(pidlParent);
1311 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1312 SHFree (pidlParent);
1315 IShellFolder_Release(psfDesktop);
1317 if (SUCCEEDED(hr) && ppidlLast)
1318 *ppidlLast = ILFindLastID(pidl);
1320 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1321 return hr;
1324 /*************************************************************************
1325 * SHParseDisplayName [SHELL32.@]
1327 HRESULT WINAPI SHParseDisplayName(LPCWSTR name, IBindCtx *bindctx, LPITEMIDLIST *pidlist,
1328 SFGAOF attr_in, SFGAOF *attr_out)
1330 IShellFolder *desktop;
1331 HRESULT hr;
1333 TRACE("%s %p %p %d %p\n", debugstr_w(name), bindctx, pidlist, attr_in, attr_out);
1335 *pidlist = NULL;
1337 if (!name) return E_INVALIDARG;
1339 hr = SHGetDesktopFolder(&desktop);
1340 if (hr != S_OK) return hr;
1342 hr = IShellFolder_ParseDisplayName(desktop, NULL, bindctx, (LPWSTR)name, NULL, pidlist, &attr_in);
1343 if (attr_out) *attr_out = attr_in;
1345 IShellFolder_Release(desktop);
1347 return hr;
1350 /*************************************************************************
1351 * SHGetNameFromIDList [SHELL32.@]
1353 HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName)
1355 IShellFolder *psfparent;
1356 LPCITEMIDLIST child_pidl;
1357 STRRET disp_name;
1358 HRESULT ret;
1360 TRACE("%p %d %p\n", pidl, sigdnName, ppszName);
1362 *ppszName = NULL;
1363 ret = SHBindToParent(pidl, &IID_IShellFolder, (void**)&psfparent, &child_pidl);
1364 if(SUCCEEDED(ret))
1366 switch(sigdnName)
1368 /* sigdnName & 0xffff */
1369 case SIGDN_NORMALDISPLAY: /* SHGDN_NORMAL */
1370 case SIGDN_PARENTRELATIVEPARSING: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1371 case SIGDN_PARENTRELATIVEEDITING: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1372 case SIGDN_DESKTOPABSOLUTEPARSING: /* SHGDN_FORPARSING */
1373 case SIGDN_DESKTOPABSOLUTEEDITING: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1374 case SIGDN_PARENTRELATIVEFORADDRESSBAR: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1375 case SIGDN_PARENTRELATIVE: /* SIGDN_INFOLDER */
1377 disp_name.uType = STRRET_WSTR;
1378 ret = IShellFolder_GetDisplayNameOf(psfparent, child_pidl,
1379 sigdnName & 0xffff,
1380 &disp_name);
1381 if(SUCCEEDED(ret))
1382 ret = StrRetToStrW(&disp_name, pidl, ppszName);
1384 break;
1386 case SIGDN_FILESYSPATH:
1387 *ppszName = CoTaskMemAlloc(sizeof(WCHAR)*MAX_PATH);
1388 if(SHGetPathFromIDListW(pidl, *ppszName))
1390 TRACE("Got string %s\n", debugstr_w(*ppszName));
1391 ret = S_OK;
1393 else
1395 CoTaskMemFree(*ppszName);
1396 ret = E_INVALIDARG;
1398 break;
1400 case SIGDN_URL:
1401 default:
1402 FIXME("Unsupported SIGDN %x\n", sigdnName);
1403 ret = E_FAIL;
1406 IShellFolder_Release(psfparent);
1408 return ret;
1411 /*************************************************************************
1412 * SHGetIDListFromObject [SHELL32.@]
1414 HRESULT WINAPI SHGetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl)
1416 IPersistIDList *ppersidl;
1417 IPersistFolder2 *ppf2;
1418 IDataObject *pdo;
1419 IFolderView *pfv;
1420 HRESULT ret;
1422 if(!punk)
1423 return E_NOINTERFACE;
1425 *ppidl = NULL;
1427 /* Try IPersistIDList */
1428 ret = IUnknown_QueryInterface(punk, &IID_IPersistIDList, (void**)&ppersidl);
1429 if(SUCCEEDED(ret))
1431 TRACE("IPersistIDList (%p)\n", ppersidl);
1432 ret = IPersistIDList_GetIDList(ppersidl, ppidl);
1433 IPersistIDList_Release(ppersidl);
1434 if(SUCCEEDED(ret))
1435 return ret;
1438 /* Try IPersistFolder2 */
1439 ret = IUnknown_QueryInterface(punk, &IID_IPersistFolder2, (void**)&ppf2);
1440 if(SUCCEEDED(ret))
1442 TRACE("IPersistFolder2 (%p)\n", ppf2);
1443 ret = IPersistFolder2_GetCurFolder(ppf2, ppidl);
1444 IPersistFolder2_Release(ppf2);
1445 if(SUCCEEDED(ret))
1446 return ret;
1449 /* Try IDataObject */
1450 ret = IUnknown_QueryInterface(punk, &IID_IDataObject, (void**)&pdo);
1451 if(SUCCEEDED(ret))
1453 IShellItem *psi;
1454 TRACE("IDataObject (%p)\n", pdo);
1455 ret = SHGetItemFromDataObject(pdo, DOGIF_ONLY_IF_ONE,
1456 &IID_IShellItem, (void**)&psi);
1457 if(SUCCEEDED(ret))
1459 ret = SHGetIDListFromObject((IUnknown*)psi, ppidl);
1460 IShellItem_Release(psi);
1462 IDataObject_Release(pdo);
1464 if(SUCCEEDED(ret))
1465 return ret;
1468 /* Try IFolderView */
1469 ret = IUnknown_QueryInterface(punk, &IID_IFolderView, (void**)&pfv);
1470 if(SUCCEEDED(ret))
1472 IShellFolder *psf;
1473 TRACE("IFolderView (%p)\n", pfv);
1474 ret = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1475 if(SUCCEEDED(ret))
1477 /* We might be able to get IPersistFolder2 from a shellfolder. */
1478 ret = SHGetIDListFromObject((IUnknown*)psf, ppidl);
1480 IFolderView_Release(pfv);
1481 return ret;
1484 return ret;
1487 /**************************************************************************
1489 * internal functions
1491 * ### 1. section creating pidls ###
1493 *************************************************************************
1496 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1497 * - two bytes are SHITEMID.cb
1498 * - one byte is PIDLDATA.type
1499 * - two bytes are the NULL PIDL terminator
1500 * Sets type of the returned PIDL to type.
1502 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1504 LPITEMIDLIST pidlOut = NULL;
1506 pidlOut = SHAlloc(size + 5);
1507 if(pidlOut)
1509 LPPIDLDATA pData;
1510 LPITEMIDLIST pidlNext;
1512 ZeroMemory(pidlOut, size + 5);
1513 pidlOut->mkid.cb = size + 3;
1515 pData = _ILGetDataPointer(pidlOut);
1516 if (pData)
1517 pData->type = type;
1519 pidlNext = ILGetNext(pidlOut);
1520 if (pidlNext)
1521 pidlNext->mkid.cb = 0x00;
1522 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1525 return pidlOut;
1528 LPITEMIDLIST _ILCreateDesktop(void)
1530 LPITEMIDLIST ret;
1532 TRACE("()\n");
1533 ret = SHAlloc(2);
1534 if (ret)
1535 ret->mkid.cb = 0;
1536 return ret;
1539 LPITEMIDLIST _ILCreateMyComputer(void)
1541 TRACE("()\n");
1542 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1545 LPITEMIDLIST _ILCreateMyDocuments(void)
1547 TRACE("()\n");
1548 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1551 LPITEMIDLIST _ILCreateIExplore(void)
1553 TRACE("()\n");
1554 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1557 LPITEMIDLIST _ILCreateControlPanel(void)
1559 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1561 TRACE("()\n");
1562 if (parent)
1564 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1566 if (cpl)
1568 ret = ILCombine(parent, cpl);
1569 SHFree(cpl);
1571 SHFree(parent);
1573 return ret;
1576 LPITEMIDLIST _ILCreatePrinters(void)
1578 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1580 TRACE("()\n");
1581 if (parent)
1583 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1585 if (printers)
1587 ret = ILCombine(parent, printers);
1588 SHFree(printers);
1590 SHFree(parent);
1592 return ret;
1595 LPITEMIDLIST _ILCreateNetwork(void)
1597 TRACE("()\n");
1598 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1601 LPITEMIDLIST _ILCreateBitBucket(void)
1603 TRACE("()\n");
1604 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1607 LPITEMIDLIST _ILCreateNetHood(void)
1609 TRACE("()\n");
1610 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1613 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1615 LPITEMIDLIST pidlOut;
1617 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1619 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1620 if (pidlOut)
1622 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1624 pData->u.guid.guid = *guid;
1625 TRACE("-- create GUID-pidl %s\n",
1626 debugstr_guid(&(pData->u.guid.guid)));
1629 else
1631 WARN("%d: invalid type for GUID\n", type);
1632 pidlOut = NULL;
1634 return pidlOut;
1637 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1639 IID iid;
1641 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1643 ERR("%s is not a GUID\n", szGUID);
1644 return NULL;
1646 return _ILCreateGuid(PT_GUID, &iid);
1649 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1651 IID iid;
1653 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1655 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1656 return NULL;
1658 return _ILCreateGuid(PT_GUID, &iid);
1661 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1663 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1664 DWORD len, len1, wlen, alen;
1665 LPITEMIDLIST pidl;
1666 PIDLTYPE type;
1668 if (!wfd)
1669 return NULL;
1671 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1673 /* prepare buffer with both names */
1674 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1675 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1676 alen = len + len1;
1678 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1680 wlen = lstrlenW(wfd->cFileName) + 1;
1681 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1682 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1683 if (pidl)
1685 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1686 FileStruct *fs = &pData->u.file;
1687 FileStructW *fsw;
1688 WORD *pOffsetW;
1690 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1691 fs->dwFileSize = wfd->nFileSizeLow;
1692 fs->uFileAttribs = wfd->dwFileAttributes;
1693 memcpy(fs->szNames, buff, alen);
1695 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1696 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1697 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1698 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1699 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1701 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1702 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1703 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1705 return pidl;
1709 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1711 HANDLE hFile;
1712 WIN32_FIND_DATAW stffile;
1714 if (!ppidl)
1715 return E_INVALIDARG;
1717 hFile = FindFirstFileW(szPath, &stffile);
1718 if (hFile == INVALID_HANDLE_VALUE)
1719 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1721 FindClose(hFile);
1723 *ppidl = _ILCreateFromFindDataW(&stffile);
1725 return *ppidl ? S_OK : E_OUTOFMEMORY;
1728 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1730 LPITEMIDLIST pidlOut;
1732 TRACE("(%s)\n",debugstr_w(lpszNew));
1734 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1735 if (pidlOut)
1737 LPSTR pszDest;
1739 pszDest = _ILGetTextPointer(pidlOut);
1740 if (pszDest)
1742 strcpy(pszDest, "x:\\");
1743 pszDest[0]=toupperW(lpszNew[0]);
1744 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1747 return pidlOut;
1750 LPITEMIDLIST _ILCreateEntireNetwork(void)
1752 LPITEMIDLIST pidlOut;
1754 TRACE("\n");
1756 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1757 if (pidlOut)
1759 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1761 pData->u.network.dummy = 0;
1762 strcpy(pData->u.network.szNames, "Entire Network");
1764 return pidlOut;
1767 /**************************************************************************
1768 * _ILGetDrive()
1770 * Gets the text for the drive eg. 'c:\'
1772 * RETURNS
1773 * strlen (lpszText)
1775 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1777 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1779 if(_ILIsMyComputer(pidl))
1780 pidl = ILGetNext(pidl);
1782 if (pidl && _ILIsDrive(pidl))
1783 return _ILSimpleGetText(pidl, pOut, uSize);
1785 return 0;
1788 /**************************************************************************
1790 * ### 2. section testing pidls ###
1792 **************************************************************************
1793 * _ILIsUnicode()
1794 * _ILIsDesktop()
1795 * _ILIsMyComputer()
1796 * _ILIsSpecialFolder()
1797 * _ILIsDrive()
1798 * _ILIsFolder()
1799 * _ILIsValue()
1800 * _ILIsPidlSimple()
1802 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1804 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1806 TRACE("(%p)\n",pidl);
1808 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1811 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1813 TRACE("(%p)\n",pidl);
1815 return pidl && pidl->mkid.cb ? FALSE : TRUE;
1818 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1820 REFIID iid = _ILGetGUIDPointer(pidl);
1822 TRACE("(%p)\n",pidl);
1824 if (iid)
1825 return IsEqualIID(iid, &CLSID_MyComputer);
1826 return FALSE;
1829 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1831 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1833 TRACE("(%p)\n",pidl);
1835 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1836 (pidl && pidl->mkid.cb == 0x00)
1840 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1842 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1844 TRACE("(%p)\n",pidl);
1846 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1847 PT_DRIVE1 == lpPData->type ||
1848 PT_DRIVE2 == lpPData->type ||
1849 PT_DRIVE3 == lpPData->type));
1852 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1854 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1856 TRACE("(%p)\n",pidl);
1858 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1861 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1863 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1865 TRACE("(%p)\n",pidl);
1867 return (pidl && lpPData && PT_VALUE == lpPData->type);
1870 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1872 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1874 TRACE("(%p)\n",pidl);
1876 return (pidl && lpPData && (lpPData->type == 0));
1879 /**************************************************************************
1880 * _ILIsPidlSimple
1882 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1884 BOOL ret = TRUE;
1886 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1888 WORD len = pidl->mkid.cb;
1889 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1891 if (pidlnext->mkid.cb)
1892 ret = FALSE;
1895 TRACE("%s\n", ret ? "Yes" : "No");
1896 return ret;
1899 /**************************************************************************
1901 * ### 3. section getting values from pidls ###
1904 /**************************************************************************
1905 * _ILSimpleGetText
1907 * gets the text for the first item in the pidl (eg. simple pidl)
1909 * returns the length of the string
1911 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1913 DWORD dwReturn=0;
1914 LPSTR szSrc;
1915 LPWSTR szSrcW;
1916 GUID const * riid;
1917 char szTemp[MAX_PATH];
1919 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1921 if (!pidl)
1922 return 0;
1924 if (szOut)
1925 *szOut = 0;
1927 if (_ILIsDesktop(pidl))
1929 /* desktop */
1930 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1932 if (szOut)
1933 lstrcpynA(szOut, szTemp, uOutSize);
1935 dwReturn = strlen (szTemp);
1938 else if (( szSrc = _ILGetTextPointer(pidl) ))
1940 /* filesystem */
1941 if (szOut)
1942 lstrcpynA(szOut, szSrc, uOutSize);
1944 dwReturn = strlen(szSrc);
1946 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1948 /* unicode filesystem */
1949 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1951 if (szOut)
1952 lstrcpynA(szOut, szTemp, uOutSize);
1954 dwReturn = strlen (szTemp);
1956 else if (( riid = _ILGetGUIDPointer(pidl) ))
1958 /* special folder */
1959 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1961 if (szOut)
1962 lstrcpynA(szOut, szTemp, uOutSize);
1964 dwReturn = strlen (szTemp);
1967 else
1969 ERR("-- no text\n");
1972 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1973 return dwReturn;
1976 /**************************************************************************
1977 * _ILSimpleGetTextW
1979 * gets the text for the first item in the pidl (eg. simple pidl)
1981 * returns the length of the string
1983 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1985 DWORD dwReturn;
1986 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1988 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1990 if (pFileStructW) {
1991 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1992 dwReturn = lstrlenW(pFileStructW->wszName);
1993 } else {
1994 GUID const * riid;
1995 WCHAR szTemp[MAX_PATH];
1996 LPSTR szSrc;
1997 LPWSTR szSrcW;
1998 dwReturn=0;
2000 if (!pidl)
2001 return 0;
2003 if (szOut)
2004 *szOut = 0;
2006 if (_ILIsDesktop(pidl))
2008 /* desktop */
2009 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
2011 if (szOut)
2012 lstrcpynW(szOut, szTemp, uOutSize);
2014 dwReturn = lstrlenW (szTemp);
2017 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
2019 /* unicode filesystem */
2020 if (szOut)
2021 lstrcpynW(szOut, szSrcW, uOutSize);
2023 dwReturn = lstrlenW(szSrcW);
2025 else if (( szSrc = _ILGetTextPointer(pidl) ))
2027 /* filesystem */
2028 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
2030 if (szOut)
2031 lstrcpynW(szOut, szTemp, uOutSize);
2033 dwReturn = lstrlenW (szTemp);
2035 else if (( riid = _ILGetGUIDPointer(pidl) ))
2037 /* special folder */
2038 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
2040 if (szOut)
2041 lstrcpynW(szOut, szTemp, uOutSize);
2043 dwReturn = lstrlenW (szTemp);
2046 else
2048 ERR("-- no text\n");
2052 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
2053 return dwReturn;
2056 /**************************************************************************
2058 * ### 4. getting pointers to parts of pidls ###
2060 **************************************************************************
2061 * _ILGetDataPointer()
2063 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
2065 if(!_ILIsEmpty(pidl))
2066 return (LPPIDLDATA)pidl->mkid.abID;
2067 return NULL;
2070 /**************************************************************************
2071 * _ILGetTextPointerW()
2072 * gets a pointer to the unicode long filename string stored in the pidl
2074 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
2076 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2078 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2080 if (!pdata)
2081 return NULL;
2083 switch (pdata->type)
2085 case PT_GUID:
2086 case PT_SHELLEXT:
2087 case PT_YAGUID:
2088 return NULL;
2090 case PT_DRIVE:
2091 case PT_DRIVE1:
2092 case PT_DRIVE2:
2093 case PT_DRIVE3:
2094 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2095 return NULL;
2097 case PT_FOLDER:
2098 case PT_FOLDER1:
2099 case PT_VALUE:
2100 case PT_IESPECIAL1:
2101 case PT_IESPECIAL2:
2102 /*return (LPSTR)&(pdata->u.file.szNames);*/
2103 return NULL;
2105 case PT_WORKGRP:
2106 case PT_COMP:
2107 case PT_NETWORK:
2108 case PT_NETPROVIDER:
2109 case PT_SHARE:
2110 /*return (LPSTR)&(pdata->u.network.szNames);*/
2111 return NULL;
2113 case PT_VALUEW:
2114 return (LPWSTR)pdata->u.file.szNames;
2116 return NULL;
2120 /**************************************************************************
2121 * _ILGetTextPointer()
2122 * gets a pointer to the long filename string stored in the pidl
2124 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
2126 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2128 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2130 if (!pdata)
2131 return NULL;
2133 switch (pdata->type)
2135 case PT_GUID:
2136 case PT_SHELLEXT:
2137 case PT_YAGUID:
2138 return NULL;
2140 case PT_DRIVE:
2141 case PT_DRIVE1:
2142 case PT_DRIVE2:
2143 case PT_DRIVE3:
2144 return pdata->u.drive.szDriveName;
2146 case PT_FOLDER:
2147 case PT_FOLDER1:
2148 case PT_VALUE:
2149 case PT_IESPECIAL1:
2150 case PT_IESPECIAL2:
2151 return pdata->u.file.szNames;
2153 case PT_WORKGRP:
2154 case PT_COMP:
2155 case PT_NETWORK:
2156 case PT_NETPROVIDER:
2157 case PT_SHARE:
2158 return pdata->u.network.szNames;
2160 return NULL;
2163 /**************************************************************************
2164 * _ILGetSTextPointer()
2165 * gets a pointer to the short filename string stored in the pidl
2167 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2169 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2171 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2173 if (!pdata)
2174 return NULL;
2176 switch (pdata->type)
2178 case PT_FOLDER:
2179 case PT_VALUE:
2180 case PT_IESPECIAL1:
2181 case PT_IESPECIAL2:
2182 return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
2184 case PT_WORKGRP:
2185 return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
2187 return NULL;
2190 /**************************************************************************
2191 * _ILGetGUIDPointer()
2193 * returns reference to guid stored in some pidls
2195 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2197 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2199 TRACE("%p\n", pidl);
2201 if (!pdata)
2202 return NULL;
2204 TRACE("pdata->type 0x%04x\n", pdata->type);
2205 switch (pdata->type)
2207 case PT_SHELLEXT:
2208 case PT_GUID:
2209 case PT_YAGUID:
2210 return &(pdata->u.guid.guid);
2212 default:
2213 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2214 break;
2216 return NULL;
2219 /******************************************************************************
2220 * _ILGetFileStructW [Internal]
2222 * Get pointer the a SHITEMID's FileStructW field if present
2224 * PARAMS
2225 * pidl [I] The SHITEMID
2227 * RETURNS
2228 * Success: Pointer to pidl's FileStructW field.
2229 * Failure: NULL
2231 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2232 FileStructW *pFileStructW;
2233 WORD cbOffset;
2235 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2236 return NULL;
2238 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2239 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2241 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2242 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2243 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2244 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
2245 /* FileStructW is positioned after FileStruct */
2246 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2247 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2248 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2249 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2251 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2252 return NULL;
2255 return pFileStructW;
2258 /*************************************************************************
2259 * _ILGetFileDateTime
2261 * Given the ItemIdList, get the FileTime
2263 * PARAMS
2264 * pidl [I] The ItemIDList
2265 * pFt [I] the resulted FILETIME of the file
2267 * RETURNS
2268 * True if Successful
2270 * NOTES
2273 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2275 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2277 if (!pdata)
2278 return FALSE;
2280 switch (pdata->type)
2282 case PT_FOLDER:
2283 case PT_VALUE:
2284 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2285 break;
2286 default:
2287 return FALSE;
2289 return TRUE;
2292 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2294 FILETIME ft,lft;
2295 SYSTEMTIME time;
2296 BOOL ret;
2298 if (_ILGetFileDateTime( pidl, &ft ))
2300 FileTimeToLocalFileTime(&ft, &lft);
2301 FileTimeToSystemTime (&lft, &time);
2303 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2304 if (ret)
2306 /* Append space + time without seconds */
2307 pOut[ret-1] = ' ';
2308 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2311 else
2313 pOut[0] = '\0';
2314 ret = FALSE;
2316 return ret;
2319 /*************************************************************************
2320 * _ILGetFileSize
2322 * Given the ItemIdList, get the FileSize
2324 * PARAMS
2325 * pidl [I] The ItemIDList
2326 * pOut [I] The buffer to save the result
2327 * uOutsize [I] The size of the buffer
2329 * RETURNS
2330 * The FileSize
2332 * NOTES
2333 * pOut can be null when no string is needed
2336 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2338 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2339 DWORD dwSize;
2341 if (!pdata)
2342 return 0;
2344 switch (pdata->type)
2346 case PT_VALUE:
2347 dwSize = pdata->u.file.dwFileSize;
2348 if (pOut)
2349 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2350 return dwSize;
2352 if (pOut)
2353 *pOut = 0x00;
2354 return 0;
2357 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2359 char szTemp[MAX_PATH];
2360 const char * pPoint;
2361 LPCITEMIDLIST pidlTemp=pidl;
2363 TRACE("pidl=%p\n",pidl);
2365 if (!pidl)
2366 return FALSE;
2368 pidlTemp = ILFindLastID(pidl);
2370 if (!_ILIsValue(pidlTemp))
2371 return FALSE;
2372 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2373 return FALSE;
2375 pPoint = PathFindExtensionA(szTemp);
2377 if (!*pPoint)
2378 return FALSE;
2380 pPoint++;
2381 lstrcpynA(pOut, pPoint, uOutSize);
2382 TRACE("%s\n",pOut);
2384 return TRUE;
2387 /*************************************************************************
2388 * _ILGetFileType
2390 * Given the ItemIdList, get the file type description
2392 * PARAMS
2393 * pidl [I] The ItemIDList (simple)
2394 * pOut [I] The buffer to save the result
2395 * uOutsize [I] The size of the buffer
2397 * RETURNS
2398 * nothing
2400 * NOTES
2401 * This function copies as much as possible into the buffer.
2403 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2405 if(_ILIsValue(pidl))
2407 char sTemp[64];
2409 if(uOutSize > 0)
2410 pOut[0] = 0;
2411 if (_ILGetExtension (pidl, sTemp, 64))
2413 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2414 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2416 lstrcpynA (pOut, sTemp, uOutSize - 6);
2417 strcat (pOut, "-file");
2421 else
2422 lstrcpynA(pOut, "Folder", uOutSize);
2425 /*************************************************************************
2426 * _ILGetFileAttributes
2428 * Given the ItemIdList, get the Attrib string format
2430 * PARAMS
2431 * pidl [I] The ItemIDList
2432 * pOut [I] The buffer to save the result
2433 * uOutsize [I] The size of the Buffer
2435 * RETURNS
2436 * Attributes
2438 * FIXME
2439 * return value 0 in case of error is a valid return value
2442 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2444 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2445 WORD wAttrib = 0;
2446 int i;
2448 if (!pData)
2449 return 0;
2451 switch(pData->type)
2453 case PT_FOLDER:
2454 case PT_VALUE:
2455 wAttrib = pData->u.file.uFileAttribs;
2456 break;
2459 if(uOutSize >= 6)
2461 i=0;
2462 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2463 pOut[i++] = 'R';
2464 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2465 pOut[i++] = 'H';
2466 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2467 pOut[i++] = 'S';
2468 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2469 pOut[i++] = 'A';
2470 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2471 pOut[i++] = 'C';
2472 pOut[i] = 0x00;
2474 return wAttrib;
2477 /*************************************************************************
2478 * ILFreeaPidl
2480 * free a aPidl struct
2482 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2484 UINT i;
2486 if (apidl)
2488 for (i = 0; i < cidl; i++)
2489 SHFree(apidl[i]);
2490 SHFree(apidl);
2494 /*************************************************************************
2495 * ILCopyaPidl
2497 * copies an aPidl struct
2499 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2501 UINT i;
2502 LPITEMIDLIST *apidldest;
2504 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2505 if (!apidlsrc)
2506 return NULL;
2508 for (i = 0; i < cidl; i++)
2509 apidldest[i] = ILClone(apidlsrc[i]);
2511 return apidldest;
2514 /*************************************************************************
2515 * _ILCopyCidaToaPidl
2517 * creates aPidl from CIDA
2519 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2521 UINT i;
2522 LPITEMIDLIST *dst;
2524 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2525 if (!dst)
2526 return NULL;
2528 if (pidl)
2529 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2531 for (i = 0; i < cida->cidl; i++)
2532 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2534 return dst;