sync to trunk r38300
[reactos.git] / reactos / dll / win32 / shell32 / pidl.c
1 /*
2 * pidl Handling
3 *
4 * Copyright 1998 Juergen Schmied
5 *
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.
10 *
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.
15 *
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
19 *
20 * NOTES
21 * a pidl == NULL means desktop and is legal
22 *
23 */
24
25 #include <precomp.h>
26
27 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
28 WINE_DECLARE_DEBUG_CHANNEL(shell);
29
30 /* from comctl32.dll */
31 extern LPVOID WINAPI Alloc(INT);
32 extern BOOL WINAPI Free(LPVOID);
33
34 /*************************************************************************
35 * ILGetDisplayNameEx [SHELL32.186]
36 *
37 * Retrieves the display name of an ItemIDList
38 *
39 * PARAMS
40 * psf [I] Shell Folder to start with, if NULL the desktop is used
41 * pidl [I] ItemIDList relativ to the psf to get the display name for
42 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
43 * type [I] Type of display name to retrieve
44 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
45 * 1 = SHGDN_NORMAL relative to the root folder
46 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
47 *
48 * RETURNS
49 * True if the display name could be retrieved successfully, False otherwise
50 */
51 BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
52 {
53 BOOL ret = FALSE;
54 WCHAR wPath[MAX_PATH];
55
56 TRACE("%p %p %p %d\n", psf, pidl, path, type);
57
58 if (!pidl || !path)
59 return FALSE;
60
61 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
62 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
63 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
64
65 return ret;
66 }
67
68 BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
69 {
70 LPSHELLFOLDER psfParent, lsf = psf;
71 HRESULT ret = NO_ERROR;
72 LPCITEMIDLIST pidllast;
73 STRRET strret;
74 DWORD flag;
75
76 TRACE("%p %p %p %d\n", psf, pidl, path, type);
77
78 if (!pidl || !path)
79 return FALSE;
80
81 if (!lsf)
82 {
83 ret = SHGetDesktopFolder(&lsf);
84 if (FAILED(ret))
85 return FALSE;
86 }
87
88 if (type <= 2)
89 {
90 switch (type)
91 {
92 case ILGDN_FORPARSING:
93 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
94 break;
95 case ILGDN_NORMAL:
96 flag = SHGDN_NORMAL;
97 break;
98 case ILGDN_INFOLDER:
99 flag = SHGDN_INFOLDER;
100 break;
101 default:
102 FIXME("Unknown type parameter = %x\n", type);
103 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
104 break;
105 }
106 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
107 {
108 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
109 if (SUCCEEDED(ret))
110 {
111 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
112 ret = E_FAIL;
113 }
114 }
115 else
116 {
117 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
118 if (SUCCEEDED(ret))
119 {
120 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
121 if (SUCCEEDED(ret))
122 {
123 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
124 ret = E_FAIL;
125 }
126 IShellFolder_Release(psfParent);
127 }
128 }
129 }
130
131 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
132
133 if (!psf)
134 IShellFolder_Release(lsf);
135 return SUCCEEDED(ret);
136 }
137
138 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
139 {
140 TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
141
142 if (SHELL_OsIsUnicode())
143 return ILGetDisplayNameExW(psf, pidl, path, type);
144 return ILGetDisplayNameExA(psf, pidl, path, type);
145 }
146
147 /*************************************************************************
148 * ILGetDisplayName [SHELL32.15]
149 */
150 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
151 {
152 TRACE_(shell)("%p %p\n", pidl, path);
153
154 if (SHELL_OsIsUnicode())
155 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
156 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
157 }
158
159 /*************************************************************************
160 * ILFindLastID [SHELL32.16]
161 *
162 * NOTES
163 * observed: pidl=Desktop return=pidl
164 */
165 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
166 {
167 LPCITEMIDLIST pidlLast = pidl;
168
169 TRACE("(pidl=%p)\n",pidl);
170
171 if (!pidl)
172 return NULL;
173
174 while (pidl->mkid.cb)
175 {
176 pidlLast = pidl;
177 pidl = ILGetNext(pidl);
178 }
179 return (LPITEMIDLIST)pidlLast;
180 }
181
182 /*************************************************************************
183 * ILRemoveLastID [SHELL32.17]
184 *
185 * NOTES
186 * when pidl=Desktop return=FALSE
187 */
188 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
189 {
190 TRACE_(shell)("pidl=%p\n",pidl);
191
192 if (!pidl || !pidl->mkid.cb)
193 return 0;
194 ILFindLastID(pidl)->mkid.cb = 0;
195 return 1;
196 }
197
198 /*************************************************************************
199 * ILClone [SHELL32.18]
200 *
201 * NOTES
202 * duplicate an idlist
203 */
204 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
205 {
206 DWORD len;
207 LPITEMIDLIST newpidl;
208
209 if (!pidl)
210 return NULL;
211
212 len = ILGetSize(pidl);
213 newpidl = (LPITEMIDLIST)SHAlloc(len);
214 if (newpidl)
215 memcpy(newpidl,pidl,len);
216
217 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
218 pdump(pidl);
219
220 return newpidl;
221 }
222
223 /*************************************************************************
224 * ILCloneFirst [SHELL32.19]
225 *
226 * NOTES
227 * duplicates the first idlist of a complex pidl
228 */
229 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
230 {
231 DWORD len;
232 LPITEMIDLIST pidlNew = NULL;
233
234 TRACE("pidl=%p\n", pidl);
235 pdump(pidl);
236
237 if (pidl)
238 {
239 len = pidl->mkid.cb;
240 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
241 if (pidlNew)
242 {
243 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
244
245 if (len)
246 ILGetNext(pidlNew)->mkid.cb = 0x00;
247 }
248 }
249 TRACE("-- newpidl=%p\n",pidlNew);
250
251 return pidlNew;
252 }
253
254 /*************************************************************************
255 * ILLoadFromStream (SHELL32.26)
256 *
257 * NOTES
258 * the first two bytes are the len, the pidl is following then
259 */
260 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
261 {
262 WORD wLen = 0;
263 DWORD dwBytesRead;
264 HRESULT ret = E_FAIL;
265
266
267 TRACE_(shell)("%p %p\n", pStream , ppPidl);
268
269 SHFree(*ppPidl);
270 *ppPidl = NULL;
271
272 IStream_AddRef (pStream);
273
274 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
275 {
276 TRACE("PIDL length is %d\n", wLen);
277 if (wLen != 0)
278 {
279 *ppPidl = SHAlloc (wLen);
280 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
281 {
282 TRACE("Stream read OK\n");
283 ret = S_OK;
284 }
285 else
286 {
287 WARN("reading pidl failed\n");
288 SHFree(*ppPidl);
289 *ppPidl = NULL;
290 }
291 }
292 else
293 {
294 *ppPidl = NULL;
295 ret = S_OK;
296 }
297 }
298
299 /* we are not yet fully compatible */
300 if (*ppPidl && !pcheck(*ppPidl))
301 {
302 WARN("Check failed\n");
303 SHFree(*ppPidl);
304 *ppPidl = NULL;
305 }
306
307 IStream_Release (pStream);
308 TRACE("done\n");
309 return ret;
310 }
311
312 /*************************************************************************
313 * ILSaveToStream (SHELL32.27)
314 *
315 * NOTES
316 * the first two bytes are the len, the pidl is following then
317 */
318 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
319 {
320 WORD wLen = 0;
321 HRESULT ret = E_FAIL;
322
323 TRACE_(shell)("%p %p\n", pStream, pPidl);
324
325 IStream_AddRef (pStream);
326
327 wLen = ILGetSize(pPidl);
328
329 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
330 {
331 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
332 ret = S_OK;
333 }
334 IStream_Release (pStream);
335
336 return ret;
337 }
338
339 /*************************************************************************
340 * SHILCreateFromPath [SHELL32.28]
341 *
342 * Create an ItemIDList from a path
343 *
344 * PARAMS
345 * path [I]
346 * ppidl [O]
347 * attributes [I/O] requested attributes on call and actual attributes when
348 * the function returns
349 *
350 * RETURNS
351 * NO_ERROR if successful, or an OLE errer code otherwise
352 *
353 * NOTES
354 * Wrapper for IShellFolder_ParseDisplayName().
355 */
356 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
357 {
358 WCHAR lpszDisplayName[MAX_PATH];
359
360 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
361
362 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
363 lpszDisplayName[MAX_PATH-1] = 0;
364
365 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
366 }
367
368 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
369 {
370 LPSHELLFOLDER sf;
371 DWORD pchEaten;
372 HRESULT ret = E_FAIL;
373
374 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
375
376 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
377 {
378 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
379 IShellFolder_Release(sf);
380 }
381 return ret;
382 }
383
384 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
385 {
386 if ( SHELL_OsIsUnicode())
387 return SHILCreateFromPathW (path, ppidl, attributes);
388 return SHILCreateFromPathA (path, ppidl, attributes);
389 }
390
391 /*************************************************************************
392 * SHCloneSpecialIDList [SHELL32.89]
393 *
394 * Create an ItemIDList to one of the special folders.
395
396 * PARAMS
397 * hwndOwner [in]
398 * nFolder [in] CSIDL_xxxxx
399 * fCreate [in] Create folder if it does not exist
400 *
401 * RETURNS
402 * Success: The newly created pidl
403 * Failure: NULL, if inputs are invalid.
404 *
405 * NOTES
406 * exported by ordinal.
407 * Caller is responsible for deallocating the returned ItemIDList with the
408 * shells IMalloc interface, aka ILFree.
409 */
410 PIDLIST_ABSOLUTE WINAPI SHCloneSpecialIDList(HWND hwndOwner, int nFolder, BOOL fCreate)
411 {
412 LPITEMIDLIST ppidl;
413 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
414
415 if (fCreate)
416 nFolder |= CSIDL_FLAG_CREATE;
417
418 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
419 return ppidl;
420 }
421
422 /*************************************************************************
423 * ILGlobalClone [SHELL32.20]
424 *
425 * Clones an ItemIDList using Alloc.
426 *
427 * PARAMS
428 * pidl [I] ItemIDList to clone
429 *
430 * RETURNS
431 * Newly allocated ItemIDList.
432 *
433 * NOTES
434 * exported by ordinal.
435 */
436 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
437 {
438 DWORD len;
439 LPITEMIDLIST newpidl;
440
441 if (!pidl)
442 return NULL;
443
444 len = ILGetSize(pidl);
445 newpidl = (LPITEMIDLIST)Alloc(len);
446 if (newpidl)
447 memcpy(newpidl,pidl,len);
448
449 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
450 pdump(pidl);
451
452 return newpidl;
453 }
454
455 /*************************************************************************
456 * ILIsEqual [SHELL32.21]
457 *
458 */
459 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
460 {
461 char szData1[MAX_PATH];
462 char szData2[MAX_PATH];
463
464 LPCITEMIDLIST pidltemp1 = pidl1;
465 LPCITEMIDLIST pidltemp2 = pidl2;
466
467 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
468
469 /*
470 * Explorer reads from registry directly (StreamMRU),
471 * so we can only check here
472 */
473 if (!pcheck(pidl1) || !pcheck (pidl2))
474 return FALSE;
475
476 pdump (pidl1);
477 pdump (pidl2);
478
479 if (!pidl1 || !pidl2)
480 return FALSE;
481
482 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
483 {
484 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
485 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
486
487 if (strcmp( szData1, szData2 ))
488 return FALSE;
489
490 pidltemp1 = ILGetNext(pidltemp1);
491 pidltemp2 = ILGetNext(pidltemp2);
492 }
493
494 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
495 return TRUE;
496
497 return FALSE;
498 }
499
500 /*************************************************************************
501 * ILIsParent [SHELL32.23]
502 *
503 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
504 *
505 * PARAMS
506 * pidlParent [I]
507 * pidlChild [I]
508 * bImmediate [I] only return true if the parent is the direct parent
509 * of the child
510 *
511 * RETURNS
512 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
513 * False otherwise.
514 *
515 * NOTES
516 * parent = a/b, child = a/b/c -> true, c is in folder a/b
517 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
518 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
519 */
520 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
521 {
522 char szData1[MAX_PATH];
523 char szData2[MAX_PATH];
524 LPCITEMIDLIST pParent = pidlParent;
525 LPCITEMIDLIST pChild = pidlChild;
526
527 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
528
529 if (!pParent || !pChild)
530 return FALSE;
531
532 while (pParent->mkid.cb && pChild->mkid.cb)
533 {
534 _ILSimpleGetText(pParent, szData1, MAX_PATH);
535 _ILSimpleGetText(pChild, szData2, MAX_PATH);
536
537 if (strcmp( szData1, szData2 ))
538 return FALSE;
539
540 pParent = ILGetNext(pParent);
541 pChild = ILGetNext(pChild);
542 }
543
544 /* child shorter or has equal length to parent */
545 if (pParent->mkid.cb || !pChild->mkid.cb)
546 return FALSE;
547
548 /* not immediate descent */
549 if ( ILGetNext(pChild)->mkid.cb && bImmediate)
550 return FALSE;
551
552 return TRUE;
553 }
554
555 /*************************************************************************
556 * ILFindChild [SHELL32.24]
557 *
558 * Compares elements from pidl1 and pidl2.
559 *
560 * PARAMS
561 * pidl1 [I]
562 * pidl2 [I]
563 *
564 * RETURNS
565 * pidl1 is desktop pidl2
566 * pidl1 shorter pidl2 pointer to first different element of pidl2
567 * if there was at least one equal element
568 * pidl2 shorter pidl1 0
569 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
570 *
571 * NOTES
572 * exported by ordinal.
573 */
574 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
575 {
576 char szData1[MAX_PATH];
577 char szData2[MAX_PATH];
578
579 LPCITEMIDLIST pidltemp1 = pidl1;
580 LPCITEMIDLIST pidltemp2 = pidl2;
581 LPCITEMIDLIST ret=NULL;
582
583 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
584
585 /* explorer reads from registry directly (StreamMRU),
586 so we can only check here */
587 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
588 return FALSE;
589
590 pdump (pidl1);
591 pdump (pidl2);
592
593 if (_ILIsDesktop(pidl1))
594 {
595 ret = pidl2;
596 }
597 else
598 {
599 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
600 {
601 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
602 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
603
604 if (strcmp(szData1,szData2))
605 break;
606
607 pidltemp1 = ILGetNext(pidltemp1);
608 pidltemp2 = ILGetNext(pidltemp2);
609 ret = pidltemp2;
610 }
611
612 if (pidltemp1->mkid.cb)
613 ret = NULL; /* elements of pidl1 left*/
614 }
615 TRACE_(shell)("--- %p\n", ret);
616 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
617 }
618
619 /*************************************************************************
620 * ILCombine [SHELL32.25]
621 *
622 * Concatenates two complex ItemIDLists.
623 *
624 * PARAMS
625 * pidl1 [I] first complex ItemIDLists
626 * pidl2 [I] complex ItemIDLists to append
627 *
628 * RETURNS
629 * if both pidl's == NULL NULL
630 * if pidl1 == NULL cloned pidl2
631 * if pidl2 == NULL cloned pidl1
632 * otherwise new pidl with pidl2 appended to pidl1
633 *
634 * NOTES
635 * exported by ordinal.
636 * Does not destroy the passed in ItemIDLists!
637 */
638 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
639 {
640 DWORD len1,len2;
641 LPITEMIDLIST pidlNew;
642
643 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
644
645 if (!pidl1 && !pidl2) return NULL;
646
647 pdump (pidl1);
648 pdump (pidl2);
649
650 if (!pidl1)
651 {
652 pidlNew = ILClone(pidl2);
653 return pidlNew;
654 }
655
656 if (!pidl2)
657 {
658 pidlNew = ILClone(pidl1);
659 return pidlNew;
660 }
661
662 len1 = ILGetSize(pidl1)-2;
663 len2 = ILGetSize(pidl2);
664 pidlNew = SHAlloc(len1+len2);
665
666 if (pidlNew)
667 {
668 memcpy(pidlNew,pidl1,len1);
669 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
670 }
671
672 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
673 return pidlNew;
674 }
675
676 /*************************************************************************
677 * SHGetRealIDL [SHELL32.98]
678 *
679 * NOTES
680 */
681 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
682 {
683 IDataObject* pDataObj;
684 HRESULT hr;
685
686 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
687 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
688 if (SUCCEEDED(hr))
689 {
690 STGMEDIUM medium;
691 FORMATETC fmt;
692
693 fmt.cfFormat = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
694 fmt.ptd = NULL;
695 fmt.dwAspect = DVASPECT_CONTENT;
696 fmt.lindex = -1;
697 fmt.tymed = TYMED_HGLOBAL;
698
699 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
700
701 IDataObject_Release(pDataObj);
702
703 if (SUCCEEDED(hr))
704 {
705 /*assert(pida->cidl==1);*/
706 LPIDA pida = (LPIDA)GlobalLock(medium.u.hGlobal);
707
708 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
709 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
710
711 *pidlReal = ILCombine(pidl_folder, pidl_child);
712
713 if (!*pidlReal)
714 hr = E_OUTOFMEMORY;
715
716 GlobalUnlock(medium.u.hGlobal);
717 GlobalFree(medium.u.hGlobal);
718 }
719 }
720
721 return hr;
722 }
723
724 /*************************************************************************
725 * SHLogILFromFSIL [SHELL32.95]
726 *
727 * NOTES
728 * pild = CSIDL_DESKTOP ret = 0
729 * pild = CSIDL_DRIVES ret = 0
730 */
731 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
732 {
733 FIXME("(pidl=%p)\n",pidl);
734
735 pdump(pidl);
736
737 return 0;
738 }
739
740 /*************************************************************************
741 * ILGetSize [SHELL32.152]
742 *
743 * Gets the byte size of an ItemIDList including zero terminator
744 *
745 * PARAMS
746 * pidl [I] ItemIDList
747 *
748 * RETURNS
749 * size of pidl in bytes
750 *
751 * NOTES
752 * exported by ordinal
753 */
754 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
755 {
756 LPCSHITEMID si = &(pidl->mkid);
757 UINT len=0;
758
759 if (pidl)
760 {
761 while (si->cb)
762 {
763 len += si->cb;
764 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
765 }
766 len += 2;
767 }
768 TRACE("pidl=%p size=%u\n",pidl, len);
769 return len;
770 }
771
772 /*************************************************************************
773 * ILGetNext [SHELL32.153]
774 *
775 * Gets the next ItemID of an ItemIDList
776 *
777 * PARAMS
778 * pidl [I] ItemIDList
779 *
780 * RETURNS
781 * null -> null
782 * desktop -> null
783 * simple pidl -> pointer to 0x0000 element
784 *
785 * NOTES
786 * exported by ordinal.
787 */
788 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
789 {
790 WORD len;
791
792 TRACE("%p\n", pidl);
793
794 if (pidl)
795 {
796 len = pidl->mkid.cb;
797 if (len)
798 {
799 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
800 TRACE("-- %p\n", pidl);
801 return (LPITEMIDLIST)pidl;
802 }
803 }
804 return NULL;
805 }
806
807 /*************************************************************************
808 * ILAppend [SHELL32.154]
809 *
810 * Adds the single ItemID item to the ItemIDList indicated by pidl.
811 * If bEnd is FALSE, inserts the item in the front of the list,
812 * otherwise it adds the item to the end. (???)
813 *
814 * PARAMS
815 * pidl [I] ItemIDList to extend
816 * item [I] ItemID to prepend/append
817 * bEnd [I] Indicates if the item should be appended
818 *
819 * NOTES
820 * Destroys the passed in idlist! (???)
821 */
822 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl, LPCITEMIDLIST item, BOOL bEnd)
823 {
824 LPITEMIDLIST idlRet;
825
826 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
827
828 pdump (pidl);
829 pdump (item);
830
831 if (_ILIsDesktop(pidl))
832 {
833 idlRet = ILClone(item);
834 SHFree (pidl);
835 return idlRet;
836 }
837
838 if (bEnd)
839 idlRet = ILCombine(pidl, item);
840 else
841 idlRet = ILCombine(item, pidl);
842
843 SHFree(pidl);
844 return idlRet;
845 }
846
847 /*************************************************************************
848 * ILFree [SHELL32.155]
849 *
850 * Frees memory (if not NULL) allocated by SHMalloc allocator
851 *
852 * PARAMS
853 * pidl [I]
854 *
855 * RETURNS
856 * Nothing
857 *
858 * NOTES
859 * exported by ordinal
860 */
861 void WINAPI ILFree(LPITEMIDLIST pidl)
862 {
863 TRACE("(pidl=%p)\n",pidl);
864 SHFree(pidl);
865 }
866
867 /*************************************************************************
868 * ILGlobalFree [SHELL32.156]
869 *
870 * Frees memory (if not NULL) allocated by Alloc allocator
871 *
872 * PARAMS
873 * pidl [I]
874 *
875 * RETURNS
876 * Nothing
877 *
878 * NOTES
879 * exported by ordinal.
880 */
881 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
882 {
883 TRACE("%p\n", pidl);
884
885 Free(pidl);
886 }
887
888 /*************************************************************************
889 * ILCreateFromPathA [SHELL32.189]
890 *
891 * Creates a complex ItemIDList from a path and returns it.
892 *
893 * PARAMS
894 * path [I]
895 *
896 * RETURNS
897 * the newly created complex ItemIDList or NULL if failed
898 *
899 * NOTES
900 * exported by ordinal.
901 */
902 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
903 {
904 LPITEMIDLIST pidlnew = NULL;
905
906 TRACE_(shell)("%s\n", debugstr_a(path));
907
908 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
909 return pidlnew;
910 return NULL;
911 }
912
913 /*************************************************************************
914 * ILCreateFromPathW [SHELL32.190]
915 *
916 * See ILCreateFromPathA.
917 */
918 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
919 {
920 LPITEMIDLIST pidlnew = NULL;
921
922 TRACE_(shell)("%s\n", debugstr_w(path));
923
924 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
925 return pidlnew;
926 return NULL;
927 }
928
929 /*************************************************************************
930 * ILCreateFromPath [SHELL32.157]
931 */
932 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
933 {
934 if ( SHELL_OsIsUnicode())
935 return ILCreateFromPathW (path);
936 return ILCreateFromPathA (path);
937 }
938
939 /*************************************************************************
940 * _ILParsePathW [internal]
941 *
942 * Creates an ItemIDList from a path and returns it.
943 *
944 * PARAMS
945 * path [I] path to parse and convert into an ItemIDList
946 * lpFindFile [I] pointer to buffer to initialize the FileSystem
947 * Bind Data object with
948 * bBindCtx [I] indicates to create a BindContext and assign a
949 * FileSystem Bind Data object
950 * ppidl [O] the newly create ItemIDList
951 * prgfInOut [I/O] requested attributes on input and actual
952 * attributes on return
953 *
954 * RETURNS
955 * NO_ERROR on success or an OLE error code
956 *
957 * NOTES
958 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
959 * creates a BindContext object and assigns a FileSystem Bind Data object
960 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
961 * IShellFolder uses that FileSystem Bind Data object of the BindContext
962 * to pass data about the current path element to the next object. This
963 * is used to avoid having to verify the current path element on disk, so
964 * that creating an ItemIDList from a nonexistent path still can work.
965 */
966 static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
967 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
968 {
969 LPSHELLFOLDER pSF = NULL;
970 LPBC pBC = NULL;
971 HRESULT ret;
972
973 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
974 ppidl, ppidl ? *ppidl : NULL,
975 prgfInOut, prgfInOut ? *prgfInOut : 0);
976
977 ret = SHGetDesktopFolder(&pSF);
978 if (FAILED(ret))
979 return ret;
980
981 if (lpFindFile || bBindCtx)
982 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
983
984 if (SUCCEEDED(ret))
985 {
986 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
987 }
988
989 if (pBC)
990 {
991 IBindCtx_Release(pBC);
992 pBC = NULL;
993 }
994
995 IShellFolder_Release(pSF);
996
997 if (!SUCCEEDED(ret) && ppidl)
998 *ppidl = NULL;
999
1000 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1001
1002 return ret;
1003 }
1004
1005 /*************************************************************************
1006 * SHSimpleIDListFromPath [SHELL32.162]
1007 *
1008 * Creates a simple ItemIDList from a path and returns it. This function
1009 * does not fail on nonexistent paths.
1010 *
1011 * PARAMS
1012 * path [I] path to parse and convert into an ItemIDList
1013 *
1014 * RETURNS
1015 * the newly created simple ItemIDList
1016 *
1017 * NOTES
1018 * Simple in the name does not mean a relative ItemIDList but rather a
1019 * fully qualified list, where only the file name is filled in and the
1020 * directory flag for those ItemID elements this is known about, eg.
1021 * it is not the last element in the ItemIDList or the actual directory
1022 * exists on disk.
1023 * exported by ordinal.
1024 */
1025 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1026 {
1027 LPITEMIDLIST pidl = NULL;
1028 LPWSTR wPath = NULL;
1029 int len;
1030
1031 TRACE("%s\n", debugstr_a(lpszPath));
1032
1033 if (lpszPath)
1034 {
1035 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1036 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1037 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1038 }
1039
1040 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1041
1042 HeapFree(GetProcessHeap(), 0, wPath);
1043 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1044 return pidl;
1045 }
1046
1047 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1048 {
1049 LPITEMIDLIST pidl = NULL;
1050
1051 TRACE("%s\n", debugstr_w(lpszPath));
1052
1053 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1054 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1055 return pidl;
1056 }
1057
1058 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1059 {
1060 if ( SHELL_OsIsUnicode())
1061 return SHSimpleIDListFromPathW (lpszPath);
1062 return SHSimpleIDListFromPathA (lpszPath);
1063 }
1064
1065 /*************************************************************************
1066 * SHGetDataFromIDListA [SHELL32.247]
1067 *
1068 * NOTES
1069 * the pidl can be a simple one. since we can't get the path out of the pidl
1070 * we have to take all data from the pidl
1071 */
1072 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1073 int nFormat, LPVOID dest, int len)
1074 {
1075 LPSTR filename, shortname;
1076 WIN32_FIND_DATAA * pfd;
1077
1078 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1079
1080 pdump(pidl);
1081 if (!psf || !dest)
1082 return E_INVALIDARG;
1083
1084 switch (nFormat)
1085 {
1086 case SHGDFIL_FINDDATA:
1087 pfd = dest;
1088
1089 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1090 return E_INVALIDARG;
1091
1092 if (len < sizeof(WIN32_FIND_DATAA))
1093 return E_INVALIDARG;
1094
1095 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1096 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1097 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1098 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1099
1100 filename = _ILGetTextPointer(pidl);
1101 shortname = _ILGetSTextPointer(pidl);
1102
1103 if (filename)
1104 lstrcpynA(pfd->cFileName, filename, MAX_PATH);
1105 else
1106 pfd->cFileName[0] = '\0';
1107
1108 if (shortname)
1109 lstrcpynA(pfd->cAlternateFileName, shortname, MAX_PATH);
1110 else
1111 pfd->cAlternateFileName[0] = '\0';
1112 return NOERROR;
1113
1114 case SHGDFIL_NETRESOURCE:
1115 case SHGDFIL_DESCRIPTIONID:
1116 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1117 break;
1118
1119 default:
1120 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1121 }
1122
1123 return E_INVALIDARG;
1124 }
1125
1126 /*************************************************************************
1127 * SHGetDataFromIDListW [SHELL32.248]
1128 *
1129 */
1130 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1131 int nFormat, LPVOID dest, int len)
1132 {
1133 LPSTR filename, shortname;
1134 WIN32_FIND_DATAW * pfd = dest;
1135
1136 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1137
1138 pdump(pidl);
1139
1140 if (!psf || !dest)
1141 return E_INVALIDARG;
1142
1143 switch (nFormat)
1144 {
1145 case SHGDFIL_FINDDATA:
1146 pfd = dest;
1147
1148 if (_ILIsDrive(pidl))
1149 return E_INVALIDARG;
1150
1151 if (len < sizeof(WIN32_FIND_DATAW))
1152 return E_INVALIDARG;
1153
1154 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1155 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1156 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1157 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1158
1159 filename = _ILGetTextPointer(pidl);
1160 shortname = _ILGetSTextPointer(pidl);
1161
1162 if (!filename)
1163 pfd->cFileName[0] = '\0';
1164 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1165 pfd->cFileName[MAX_PATH-1] = 0;
1166
1167 if (!shortname)
1168 pfd->cAlternateFileName[0] = '\0';
1169 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1170 pfd->cAlternateFileName[13] = 0;
1171 return NOERROR;
1172
1173 case SHGDFIL_NETRESOURCE:
1174 case SHGDFIL_DESCRIPTIONID:
1175 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1176 break;
1177
1178 default:
1179 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1180 }
1181
1182 return E_INVALIDARG;
1183 }
1184
1185 /*************************************************************************
1186 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1187 *
1188 * PARAMETERS
1189 * pidl, [IN] pidl
1190 * pszPath [OUT] path
1191 *
1192 * RETURNS
1193 * path from a passed PIDL.
1194 *
1195 * NOTES
1196 * NULL returns FALSE
1197 * desktop pidl gives path to desktop directory back
1198 * special pidls returning FALSE
1199 */
1200 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1201 {
1202 WCHAR wszPath[MAX_PATH];
1203 BOOL bSuccess;
1204
1205 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1206 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1207
1208 return bSuccess;
1209 }
1210
1211 /*************************************************************************
1212 * SHGetPathFromIDListW [SHELL32.@]
1213 *
1214 * See SHGetPathFromIDListA.
1215 */
1216 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1217 {
1218 HRESULT hr;
1219 LPCITEMIDLIST pidlLast;
1220 LPSHELLFOLDER psfFolder;
1221 DWORD dwAttributes;
1222 STRRET strret;
1223
1224 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1225 pdump(pidl);
1226
1227 *pszPath = '\0';
1228 if (!pidl)
1229 return FALSE;
1230
1231 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1232 if (FAILED(hr)) return FALSE;
1233
1234 dwAttributes = SFGAO_FILESYSTEM;
1235 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1236 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1237 IShellFolder_Release(psfFolder);
1238 return FALSE;
1239 }
1240
1241 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1242 IShellFolder_Release(psfFolder);
1243 if (FAILED(hr)) return FALSE;
1244
1245 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1246
1247 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1248 return SUCCEEDED(hr);
1249 }
1250
1251 /*************************************************************************
1252 * SHBindToParent [shell version 5.0]
1253 */
1254 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1255 {
1256 IShellFolder * psfDesktop;
1257 HRESULT hr=E_FAIL;
1258
1259 TRACE_(shell)("pidl=%p\n", pidl);
1260 pdump(pidl);
1261
1262 if (!pidl || !ppv)
1263 return E_INVALIDARG;
1264
1265 *ppv = NULL;
1266 if (ppidlLast)
1267 *ppidlLast = NULL;
1268
1269 hr = SHGetDesktopFolder(&psfDesktop);
1270 if (FAILED(hr))
1271 return hr;
1272
1273 if (_ILIsPidlSimple(pidl))
1274 {
1275 /* we are on desktop level */
1276 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1277 }
1278 else
1279 {
1280 LPITEMIDLIST pidlParent = ILClone(pidl);
1281 ILRemoveLastID(pidlParent);
1282 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1283 SHFree (pidlParent);
1284 }
1285
1286 IShellFolder_Release(psfDesktop);
1287
1288 if (SUCCEEDED(hr) && ppidlLast)
1289 *ppidlLast = ILFindLastID(pidl);
1290
1291 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1292 return hr;
1293 }
1294
1295 /**************************************************************************
1296 *
1297 * internal functions
1298 *
1299 * ### 1. section creating pidls ###
1300 *
1301 *************************************************************************
1302 */
1303 LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1304 {
1305 LPITEMIDLIST pidlOut = NULL;
1306
1307 pidlOut = SHAlloc(size + 5);
1308 if(pidlOut)
1309 {
1310 LPPIDLDATA pData;
1311 LPITEMIDLIST pidlNext;
1312
1313 ZeroMemory(pidlOut, size + 5);
1314 pidlOut->mkid.cb = size + 3;
1315
1316 pData = _ILGetDataPointer(pidlOut);
1317 if (pData)
1318 pData->type = type;
1319
1320 pidlNext = ILGetNext(pidlOut);
1321 if (pidlNext)
1322 pidlNext->mkid.cb = 0x00;
1323 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1324 }
1325
1326 return pidlOut;
1327 }
1328
1329 LPITEMIDLIST _ILCreateDesktop(void)
1330 {
1331 LPITEMIDLIST ret;
1332
1333 TRACE("()\n");
1334 ret = SHAlloc(2);
1335 if (ret)
1336 ret->mkid.cb = 0;
1337 return ret;
1338 }
1339
1340 LPITEMIDLIST _ILCreateMyComputer(void)
1341 {
1342 TRACE("()\n");
1343 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1344 }
1345
1346 LPITEMIDLIST _ILCreateMyDocuments(void)
1347 {
1348 TRACE("()\n");
1349 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1350 }
1351
1352 LPITEMIDLIST _ILCreateIExplore(void)
1353 {
1354 TRACE("()\n");
1355 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1356 }
1357
1358 LPITEMIDLIST _ILCreateControlPanel(void)
1359 {
1360 LPITEMIDLIST ret = NULL;
1361 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1362
1363 TRACE("()\n");
1364
1365 if (parent)
1366 {
1367 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_ControlPanel);
1368
1369 if (printers)
1370 {
1371 ret = ILCombine(parent, printers);
1372 SHFree(printers);
1373 }
1374 SHFree(parent);
1375 }
1376 return ret;
1377
1378 return _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1379 }
1380
1381 LPITEMIDLIST _ILCreatePrinters(void)
1382 {
1383 return _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1384 }
1385
1386 LPITEMIDLIST _ILCreateNetwork(void)
1387 {
1388 TRACE("()\n");
1389 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1390 }
1391
1392 LPITEMIDLIST _ILCreateBitBucket(void)
1393 {
1394 TRACE("()\n");
1395 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1396 }
1397
1398 LPITEMIDLIST _ILCreateAdminTools(void)
1399 {
1400 TRACE("()\n");
1401 return _ILCreateGuid(PT_GUID, &CLSID_AdminFolderShortcut); //FIXME
1402 }
1403
1404 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1405 {
1406 LPITEMIDLIST pidlOut;
1407
1408 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1409 {
1410 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1411 if (pidlOut)
1412 {
1413 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1414
1415 memcpy(&(pData->u.guid.guid), guid, sizeof(GUID));
1416 TRACE("-- create GUID-pidl %s\n",
1417 debugstr_guid(&(pData->u.guid.guid)));
1418 }
1419 }
1420 else
1421 {
1422 WARN("%d: invalid type for GUID\n", type);
1423 pidlOut = NULL;
1424 }
1425 return pidlOut;
1426 }
1427
1428 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1429 {
1430 IID iid;
1431
1432 if (!SUCCEEDED(SHCLSIDFromStringA(szGUID, &iid)))
1433 {
1434 ERR("%s is not a GUID\n", szGUID);
1435 return NULL;
1436 }
1437 return _ILCreateGuid(PT_GUID, &iid);
1438 }
1439
1440 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1441 {
1442 IID iid;
1443
1444 if (FAILED(CLSIDFromString((LPOLESTR)szGUID, &iid)))
1445 {
1446 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1447 return NULL;
1448 }
1449 return _ILCreateGuid(PT_GUID, &iid);
1450 }
1451
1452 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1453 {
1454 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1455 DWORD len, len1, wlen, alen;
1456 LPITEMIDLIST pidl;
1457 PIDLTYPE type;
1458
1459 if (!wfd)
1460 return NULL;
1461
1462 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1463
1464 /* prepare buffer with both names */
1465 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1466 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1467 alen = len + len1;
1468
1469 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1470
1471 wlen = wcslen(wfd->cFileName) + 1;
1472 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1473 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1474 if (pidl)
1475 {
1476 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1477 FileStruct *fs = &pData->u.file;
1478 FileStructW *fsw;
1479 WORD *pOffsetW;
1480
1481 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1482 fs->dwFileSize = wfd->nFileSizeLow;
1483 fs->uFileAttribs = wfd->dwFileAttributes;
1484 memcpy(fs->szNames, buff, alen);
1485
1486 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1487 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1488 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1489 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1490 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1491
1492 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1493 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1494 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1495 }
1496 return pidl;
1497
1498 }
1499
1500 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1501 {
1502 HANDLE hFile;
1503 WIN32_FIND_DATAW stffile;
1504
1505 if (!ppidl)
1506 return E_INVALIDARG;
1507
1508 hFile = FindFirstFileW(szPath, &stffile);
1509 if (hFile == INVALID_HANDLE_VALUE)
1510 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1511
1512 FindClose(hFile);
1513
1514 *ppidl = _ILCreateFromFindDataW(&stffile);
1515
1516 return *ppidl ? S_OK : E_OUTOFMEMORY;
1517 }
1518
1519 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1520 {
1521 LPITEMIDLIST pidlOut;
1522
1523 TRACE("(%s)\n",debugstr_w(lpszNew));
1524
1525 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1526 if (pidlOut)
1527 {
1528 LPSTR pszDest;
1529
1530 pszDest = _ILGetTextPointer(pidlOut);
1531 if (pszDest)
1532 {
1533 strcpy(pszDest, "x:\\");
1534 pszDest[0]=towupper(lpszNew[0]);
1535 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1536 }
1537 }
1538 return pidlOut;
1539 }
1540
1541 /**************************************************************************
1542 * _ILGetDrive()
1543 *
1544 * Gets the text for the drive eg. 'c:\'
1545 *
1546 * RETURNS
1547 * strlen (lpszText)
1548 */
1549 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1550 {
1551 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1552
1553 if(_ILIsMyComputer(pidl))
1554 pidl = ILGetNext(pidl);
1555
1556 if (pidl && _ILIsDrive(pidl))
1557 return _ILSimpleGetText(pidl, pOut, uSize);
1558
1559 return 0;
1560 }
1561
1562 /**************************************************************************
1563 *
1564 * ### 2. section testing pidls ###
1565 *
1566 **************************************************************************
1567 * _ILIsUnicode()
1568 * _ILIsDesktop()
1569 * _ILIsMyComputer()
1570 * _ILIsSpecialFolder()
1571 * _ILIsDrive()
1572 * _ILIsFolder()
1573 * _ILIsValue()
1574 * _ILIsPidlSimple()
1575 */
1576 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1577 {
1578 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1579
1580 TRACE("(%p)\n",pidl);
1581
1582 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1583 }
1584
1585 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1586 {
1587 TRACE("(%p)\n",pidl);
1588
1589 return pidl && pidl->mkid.cb ? 0 : 1;
1590 }
1591
1592 BOOL _ILIsMyDocuments(LPCITEMIDLIST pidl)
1593 {
1594 REFIID iid = _ILGetGUIDPointer(pidl);
1595
1596 TRACE("(%p)\n",pidl);
1597
1598 if (iid)
1599 return IsEqualIID(iid, &CLSID_MyDocuments);
1600 return FALSE;
1601 }
1602
1603 BOOL _ILIsControlPanel(LPCITEMIDLIST pidl)
1604 {
1605 REFIID iid = _ILGetGUIDPointer(pidl);
1606
1607 TRACE("(%p)\n",pidl);
1608
1609 if (iid)
1610 return IsEqualIID(iid, &CLSID_ControlPanel);
1611 return FALSE;
1612 }
1613
1614 BOOL _ILIsNetHood(LPCITEMIDLIST pidl)
1615 {
1616 REFIID iid = _ILGetGUIDPointer(pidl);
1617
1618 TRACE("(%p)\n",pidl);
1619
1620 if (iid)
1621 return IsEqualIID(iid, &CLSID_NetworkPlaces);
1622 return FALSE;
1623 }
1624
1625
1626 LPITEMIDLIST _ILCreateNetHood(void)
1627 {
1628 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1629 }
1630
1631 LPITEMIDLIST _ILCreateFont(void)
1632 {
1633 return _ILCreateGuid(PT_GUID, &CLSID_FontsFolderShortcut);
1634 }
1635
1636 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1637 {
1638 REFIID iid = _ILGetGUIDPointer(pidl);
1639
1640 TRACE("(%p)\n",pidl);
1641
1642 if (iid)
1643 return IsEqualIID(iid, &CLSID_MyComputer);
1644 return FALSE;
1645 }
1646
1647 BOOL _ILIsBitBucket(LPCITEMIDLIST pidl)
1648 {
1649 REFIID iid = _ILGetGUIDPointer(pidl);
1650
1651 TRACE("(%p)\n",pidl);
1652
1653 if (iid)
1654 return IsEqualIID(iid, &CLSID_RecycleBin);
1655 return FALSE;
1656 }
1657
1658 BOOL _ILIsAdminTools(LPCITEMIDLIST pidl)
1659 {
1660 REFIID iid = _ILGetGUIDPointer(pidl);
1661
1662 TRACE("(%p)\n",pidl);
1663
1664 if (iid)
1665 return IsEqualIID(iid, &CLSID_AdminFolderShortcut);
1666 else
1667 return FALSE;
1668 }
1669
1670 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1671 {
1672 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1673
1674 TRACE("(%p)\n",pidl);
1675
1676 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1677 (pidl && pidl->mkid.cb == 0x00)
1678 ));
1679 }
1680
1681 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1682 {
1683 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1684
1685 TRACE("(%p)\n",pidl);
1686
1687 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1688 PT_DRIVE1 == lpPData->type ||
1689 PT_DRIVE2 == lpPData->type ||
1690 PT_DRIVE3 == lpPData->type));
1691 }
1692
1693 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1694 {
1695 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1696
1697 TRACE("(%p)\n",pidl);
1698
1699 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1700 }
1701
1702 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1703 {
1704 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1705
1706 TRACE("(%p)\n",pidl);
1707
1708 return (pidl && lpPData && PT_VALUE == lpPData->type);
1709 }
1710
1711 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1712 {
1713 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1714
1715 TRACE("(%p)\n",pidl);
1716
1717 return (pidl && lpPData && (lpPData->type == 0));
1718 }
1719
1720 /**************************************************************************
1721 * _ILIsPidlSimple
1722 */
1723 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1724 {
1725 BOOL ret = TRUE;
1726
1727 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1728 {
1729 WORD len = pidl->mkid.cb;
1730 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1731
1732 if (pidlnext->mkid.cb)
1733 ret = FALSE;
1734 }
1735
1736 TRACE("%s\n", ret ? "Yes" : "No");
1737 return ret;
1738 }
1739
1740 /**************************************************************************
1741 *
1742 * ### 3. section getting values from pidls ###
1743 */
1744
1745 /**************************************************************************
1746 * _ILSimpleGetText
1747 *
1748 * gets the text for the first item in the pidl (eg. simple pidl)
1749 *
1750 * returns the length of the string
1751 */
1752 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1753 {
1754 DWORD dwReturn=0;
1755 LPSTR szSrc;
1756 LPWSTR szSrcW;
1757 GUID const * riid;
1758 char szTemp[MAX_PATH];
1759
1760 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1761
1762 if (!pidl)
1763 return 0;
1764
1765 if (szOut)
1766 *szOut = 0;
1767
1768 if (_ILIsDesktop(pidl))
1769 {
1770 /* desktop */
1771 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1772 {
1773 if (szOut)
1774 lstrcpynA(szOut, szTemp, uOutSize);
1775
1776 dwReturn = strlen (szTemp);
1777 }
1778 }
1779 else if (( szSrc = _ILGetTextPointer(pidl) ))
1780 {
1781 /* filesystem */
1782 if (szOut)
1783 lstrcpynA(szOut, szSrc, uOutSize);
1784
1785 dwReturn = strlen(szSrc);
1786 }
1787 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1788 {
1789 /* unicode filesystem */
1790 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
1791
1792 if (szOut)
1793 lstrcpynA(szOut, szTemp, uOutSize);
1794
1795 dwReturn = strlen (szTemp);
1796 }
1797 else if (( riid = _ILGetGUIDPointer(pidl) ))
1798 {
1799 /* special folder */
1800 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
1801 {
1802 if (szOut)
1803 lstrcpynA(szOut, szTemp, uOutSize);
1804
1805 dwReturn = strlen (szTemp);
1806 }
1807 }
1808 else
1809 {
1810 ERR("-- no text\n");
1811 }
1812
1813 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
1814 return dwReturn;
1815 }
1816
1817 /**************************************************************************
1818 * _ILSimpleGetTextW
1819 *
1820 * gets the text for the first item in the pidl (eg. simple pidl)
1821 *
1822 * returns the length of the string
1823 */
1824 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
1825 {
1826 DWORD dwReturn;
1827 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
1828
1829 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1830
1831 if (pFileStructW) {
1832 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
1833 dwReturn = wcslen(pFileStructW->wszName);
1834 } else {
1835 GUID const * riid;
1836 WCHAR szTemp[MAX_PATH];
1837 LPSTR szSrc;
1838 LPWSTR szSrcW;
1839 dwReturn=0;
1840
1841 if (!pidl)
1842 return 0;
1843
1844 if (szOut)
1845 *szOut = 0;
1846
1847 if (_ILIsDesktop(pidl))
1848 {
1849 /* desktop */
1850 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1851 {
1852 if (szOut)
1853 lstrcpynW(szOut, szTemp, uOutSize);
1854
1855 dwReturn = wcslen (szTemp);
1856 }
1857 }
1858 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
1859 {
1860 /* unicode filesystem */
1861 if (szOut)
1862 lstrcpynW(szOut, szSrcW, uOutSize);
1863
1864 dwReturn = wcslen(szSrcW);
1865 }
1866 else if (( szSrc = _ILGetTextPointer(pidl) ))
1867 {
1868 /* filesystem */
1869 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
1870
1871 if (szOut)
1872 lstrcpynW(szOut, szTemp, uOutSize);
1873
1874 dwReturn = wcslen (szTemp);
1875 }
1876 else if (( riid = _ILGetGUIDPointer(pidl) ))
1877 {
1878 /* special folder */
1879 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
1880 {
1881 if (szOut)
1882 lstrcpynW(szOut, szTemp, uOutSize);
1883
1884 dwReturn = wcslen (szTemp);
1885 }
1886 }
1887 else
1888 {
1889 ERR("-- no text\n");
1890 }
1891 }
1892
1893 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
1894 return dwReturn;
1895 }
1896
1897 /**************************************************************************
1898 *
1899 * ### 4. getting pointers to parts of pidls ###
1900 *
1901 **************************************************************************
1902 * _ILGetDataPointer()
1903 */
1904 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
1905 {
1906 if(pidl && pidl->mkid.cb != 0x00)
1907 return (LPPIDLDATA) &(pidl->mkid.abID);
1908 return NULL;
1909 }
1910
1911 /**************************************************************************
1912 * _ILGetTextPointerW()
1913 * gets a pointer to the unicode long filename string stored in the pidl
1914 */
1915 LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
1916 {
1917 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1918
1919 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1920
1921 if (!pdata)
1922 return NULL;
1923
1924 switch (pdata->type)
1925 {
1926 case PT_GUID:
1927 case PT_SHELLEXT:
1928 case PT_YAGUID:
1929 return NULL;
1930
1931 case PT_DRIVE:
1932 case PT_DRIVE1:
1933 case PT_DRIVE2:
1934 case PT_DRIVE3:
1935 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
1936 return NULL;
1937
1938 case PT_FOLDER:
1939 case PT_FOLDER1:
1940 case PT_VALUE:
1941 case PT_IESPECIAL1:
1942 case PT_IESPECIAL2:
1943 /*return (LPSTR)&(pdata->u.file.szNames);*/
1944 return NULL;
1945
1946 case PT_WORKGRP:
1947 case PT_COMP:
1948 case PT_NETWORK:
1949 case PT_NETPROVIDER:
1950 case PT_SHARE:
1951 /*return (LPSTR)&(pdata->u.network.szNames);*/
1952 return NULL;
1953
1954 case PT_VALUEW:
1955 return (LPWSTR)&(pdata->u.file.szNames);
1956 }
1957 return NULL;
1958 }
1959
1960
1961 /**************************************************************************
1962 * _ILGetTextPointer()
1963 * gets a pointer to the long filename string stored in the pidl
1964 */
1965 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1966 {
1967 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
1968
1969 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
1970
1971 if (!pdata)
1972 return NULL;
1973
1974 switch (pdata->type)
1975 {
1976 case PT_GUID:
1977 case PT_SHELLEXT:
1978 case PT_YAGUID:
1979 return NULL;
1980
1981 case PT_DRIVE:
1982 case PT_DRIVE1:
1983 case PT_DRIVE2:
1984 case PT_DRIVE3:
1985 return (LPSTR)&(pdata->u.drive.szDriveName);
1986
1987 case PT_FOLDER:
1988 case PT_FOLDER1:
1989 case PT_VALUE:
1990 case PT_IESPECIAL1:
1991 case PT_IESPECIAL2:
1992 return (LPSTR)&(pdata->u.file.szNames);
1993
1994 case PT_WORKGRP:
1995 case PT_COMP:
1996 case PT_NETWORK:
1997 case PT_NETPROVIDER:
1998 case PT_SHARE:
1999 return (LPSTR)&(pdata->u.network.szNames);
2000 }
2001 return NULL;
2002 }
2003
2004 /**************************************************************************
2005 * _ILGetSTextPointer()
2006 * gets a pointer to the short filename string stored in the pidl
2007 */
2008 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2009 {
2010 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2011
2012 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2013
2014 if (!pdata)
2015 return NULL;
2016
2017 switch (pdata->type)
2018 {
2019 case PT_FOLDER:
2020 case PT_VALUE:
2021 case PT_IESPECIAL1:
2022 case PT_IESPECIAL2:
2023 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
2024
2025 case PT_WORKGRP:
2026 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
2027 }
2028 return NULL;
2029 }
2030
2031 /**************************************************************************
2032 * _ILGetGUIDPointer()
2033 *
2034 * returns reference to guid stored in some pidls
2035 */
2036 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2037 {
2038 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2039
2040 TRACE("%p\n", pidl);
2041
2042 if (!pdata)
2043 return NULL;
2044
2045 TRACE("pdata->type 0x%04x\n", pdata->type);
2046 switch (pdata->type)
2047 {
2048 case PT_SHELLEXT:
2049 case PT_GUID:
2050 case PT_YAGUID:
2051 return &(pdata->u.guid.guid);
2052
2053 default:
2054 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2055 break;
2056 }
2057 return NULL;
2058 }
2059
2060 /******************************************************************************
2061 * _ILGetFileStructW [Internal]
2062 *
2063 * Get pointer the a SHITEMID's FileStructW field if present
2064 *
2065 * PARAMS
2066 * pidl [I] The SHITEMID
2067 *
2068 * RETURNS
2069 * Success: Pointer to pidl's FileStructW field.
2070 * Failure: NULL
2071 */
2072 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2073 FileStructW *pFileStructW;
2074 WORD cbOffset;
2075
2076 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2077 return NULL;
2078
2079 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2080 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2081
2082 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2083 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2084 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2085 if (cbOffset & 0x1 || /* FileStructW member is word aligned in the pidl */
2086 /* FileStructW is positioned after FileStruct */
2087 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2088 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2089 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2090 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2091 {
2092 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2093 return NULL;
2094 }
2095
2096 return pFileStructW;
2097 }
2098
2099 /*************************************************************************
2100 * _ILGetFileDateTime
2101 *
2102 * Given the ItemIdList, get the FileTime
2103 *
2104 * PARAMS
2105 * pidl [I] The ItemIDList
2106 * pFt [I] the resulted FILETIME of the file
2107 *
2108 * RETURNS
2109 * True if Successful
2110 *
2111 * NOTES
2112 *
2113 */
2114 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2115 {
2116 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2117
2118 if (!pdata)
2119 return FALSE;
2120
2121 switch (pdata->type)
2122 {
2123 case PT_FOLDER:
2124 case PT_VALUE:
2125 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2126 break;
2127 default:
2128 return FALSE;
2129 }
2130 return TRUE;
2131 }
2132
2133 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2134 {
2135 FILETIME ft,lft;
2136 SYSTEMTIME time;
2137 BOOL ret;
2138
2139 if (_ILGetFileDateTime( pidl, &ft ))
2140 {
2141 FileTimeToLocalFileTime(&ft, &lft);
2142 FileTimeToSystemTime (&lft, &time);
2143
2144 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2145 if (ret)
2146 {
2147 /* Append space + time without seconds */
2148 pOut[ret-1] = ' ';
2149 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2150 }
2151 }
2152 else
2153 {
2154 pOut[0] = '\0';
2155 ret = FALSE;
2156 }
2157 return ret;
2158 }
2159
2160 /*************************************************************************
2161 * _ILGetFileSize
2162 *
2163 * Given the ItemIdList, get the FileSize
2164 *
2165 * PARAMS
2166 * pidl [I] The ItemIDList
2167 * pOut [I] The buffer to save the result
2168 * uOutsize [I] The size of the buffer
2169 *
2170 * RETURNS
2171 * The FileSize
2172 *
2173 * NOTES
2174 * pOut can be null when no string is needed
2175 *
2176 */
2177 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2178 {
2179 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2180 DWORD dwSize;
2181
2182 if (!pdata)
2183 return 0;
2184
2185 switch (pdata->type)
2186 {
2187 case PT_VALUE:
2188 dwSize = pdata->u.file.dwFileSize;
2189 if (pOut)
2190 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2191 return dwSize;
2192 }
2193 if (pOut)
2194 *pOut = 0x00;
2195 return 0;
2196 }
2197
2198 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2199 {
2200 char szTemp[MAX_PATH];
2201 const char * pPoint;
2202 LPCITEMIDLIST pidlTemp=pidl;
2203
2204 TRACE("pidl=%p\n",pidl);
2205
2206 if (!pidl)
2207 return FALSE;
2208
2209 pidlTemp = ILFindLastID(pidl);
2210
2211 if (!_ILIsValue(pidlTemp))
2212 return FALSE;
2213 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2214 return FALSE;
2215
2216 pPoint = PathFindExtensionA(szTemp);
2217
2218 if (!*pPoint)
2219 return FALSE;
2220
2221 pPoint++;
2222 lstrcpynA(pOut, pPoint, uOutSize);
2223 TRACE("%s\n",pOut);
2224
2225 return TRUE;
2226 }
2227
2228 /*************************************************************************
2229 * _ILGetFileType
2230 *
2231 * Given the ItemIdList, get the file type description
2232 *
2233 * PARAMS
2234 * pidl [I] The ItemIDList (simple)
2235 * pOut [I] The buffer to save the result
2236 * uOutsize [I] The size of the buffer
2237 *
2238 * RETURNS
2239 * nothing
2240 *
2241 * NOTES
2242 * This function copies as much as possible into the buffer.
2243 */
2244 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2245 {
2246 char sType[64];
2247
2248 if(_ILIsValue(pidl))
2249 {
2250 char sTemp[64];
2251
2252 if(uOutSize > 0)
2253 pOut[0] = 0;
2254 if (_ILGetExtension (pidl, sType, 64))
2255 {
2256 if (HCR_MapTypeToValueA(sType, sTemp, 64, TRUE))
2257 {
2258 /* retrieve description */
2259 if(HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE ))
2260 return;
2261 }
2262 /* display Ext-file as description */
2263 strcpy(pOut, sType);
2264 _strupr(pOut);
2265 /* load localized file string */
2266 sTemp[0] = '\0';
2267 if(LoadStringA(shell32_hInstance, IDS_SHV_COLUMN1, sTemp, 64))
2268 {
2269 sTemp[63] = '\0';
2270 strcat(pOut, "-");
2271 strcat(pOut, sTemp);
2272 }
2273 }
2274 }
2275 else
2276 {
2277 pOut[0] = '\0';
2278 LoadStringA(shell32_hInstance, IDS_DIRECTORY, pOut, uOutSize);
2279 /* make sure its null terminated */
2280 pOut[uOutSize-1] = '\0';
2281 }
2282 }
2283
2284 /*************************************************************************
2285 * _ILGetFileAttributes
2286 *
2287 * Given the ItemIdList, get the Attrib string format
2288 *
2289 * PARAMS
2290 * pidl [I] The ItemIDList
2291 * pOut [I] The buffer to save the result
2292 * uOutsize [I] The size of the Buffer
2293 *
2294 * RETURNS
2295 * Attributes
2296 *
2297 * FIXME
2298 * return value 0 in case of error is a valid return value
2299 *
2300 */
2301 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2302 {
2303 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2304 WORD wAttrib = 0;
2305 int i;
2306
2307 if (!pData)
2308 return 0;
2309
2310 switch(pData->type)
2311 {
2312 case PT_FOLDER:
2313 case PT_VALUE:
2314 wAttrib = pData->u.file.uFileAttribs;
2315 break;
2316 }
2317
2318 if(uOutSize >= 6)
2319 {
2320 i=0;
2321 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2322 pOut[i++] = 'R';
2323 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2324 pOut[i++] = 'H';
2325 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2326 pOut[i++] = 'S';
2327 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2328 pOut[i++] = 'A';
2329 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2330 pOut[i++] = 'C';
2331 pOut[i] = 0x00;
2332 }
2333 return wAttrib;
2334 }
2335
2336 /*************************************************************************
2337 * ILFreeaPidl
2338 *
2339 * free a aPidl struct
2340 */
2341 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2342 {
2343 UINT i;
2344
2345 if (apidl)
2346 {
2347 for (i = 0; i < cidl; i++)
2348 SHFree(apidl[i]);
2349 SHFree(apidl);
2350 }
2351 }
2352
2353 /*************************************************************************
2354 * ILCopyaPidl
2355 *
2356 * copies an aPidl struct
2357 */
2358 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2359 {
2360 UINT i;
2361 LPITEMIDLIST *apidldest;
2362
2363 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2364 if (!apidlsrc)
2365 return NULL;
2366
2367 for (i = 0; i < cidl; i++)
2368 apidldest[i] = ILClone(apidlsrc[i]);
2369
2370 return apidldest;
2371 }
2372
2373 /*************************************************************************
2374 * _ILCopyCidaToaPidl
2375 *
2376 * creates aPidl from CIDA
2377 */
2378 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2379 {
2380 UINT i;
2381 LPITEMIDLIST *dst;
2382
2383 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2384 if (!dst)
2385 return NULL;
2386
2387 if (pidl)
2388 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2389
2390 for (i = 0; i < cida->cidl; i++)
2391 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2392
2393 return dst;
2394 }