Moved undocshell.h to dlls/shell32. Removed shell16.h.
[wine/multimedia.git] / dlls / shell32 / pidl.c
blob5df26c108bf2484e4b2dd0992e1e62ccea943893
1 /*
2 * pidl Handling
4 * Copyright 1998 Juergen Schmied
6 * NOTES
7 * a pidl == NULL means desktop and is legal
9 */
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "winbase.h"
15 #include "debugtools.h"
16 #include "shlguid.h"
17 #include "winerror.h"
18 #include "winnls.h"
19 #include "undocshell.h"
20 #include "shell32_main.h"
21 #include "shellapi.h"
22 #include "shlwapi.h"
24 #include "pidl.h"
26 DEFAULT_DEBUG_CHANNEL(pidl);
27 DECLARE_DEBUG_CHANNEL(shell);
29 void pdump (LPCITEMIDLIST pidl)
31 BOOL bIsShellDebug;
33 LPITEMIDLIST pidltemp = pidl;
34 if (!TRACE_ON(pidl))
35 return;
37 /* silence the sub-functions */
38 bIsShellDebug = TRACE_ON(shell);
39 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_shell, FALSE);
40 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, FALSE);
42 if (! pidltemp)
44 MESSAGE ("-------- pidl=NULL (Desktop)\n");
46 else
48 MESSAGE ("-------- pidl=%p\n", pidl);
49 if (pidltemp->mkid.cb)
53 DWORD dwAttrib = 0;
54 LPPIDLDATA pData = _ILGetDataPointer(pidltemp);
55 DWORD type = pData->type;
56 LPSTR szLongName = _ILGetTextPointer(pidltemp);
57 LPSTR szShortName = _ILGetSTextPointer(pidltemp);
58 char szName[MAX_PATH];
60 _ILSimpleGetText(pidltemp, szName, MAX_PATH);
61 if( PT_FOLDER == type)
62 dwAttrib = pData->u.folder.uFileAttribs;
63 else if( PT_VALUE == type)
64 dwAttrib = pData->u.file.uFileAttribs;
66 MESSAGE ("-- pidl=%p size=%u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
67 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
69 pidltemp = ILGetNext(pidltemp);
71 } while (pidltemp->mkid.cb);
73 else
75 MESSAGE ("empty pidl (Desktop)\n");
77 pcheck(pidl);
80 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_shell, bIsShellDebug);
81 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, TRUE);
84 #define BYTES_PRINTED 32
85 BOOL pcheck (LPCITEMIDLIST pidl)
86 { DWORD type, ret=TRUE;
87 BOOL bIsPidlDebug;
89 LPITEMIDLIST pidltemp = pidl;
91 bIsPidlDebug = TRACE_ON(shell);
92 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, FALSE);
94 if (pidltemp && pidltemp->mkid.cb)
95 { do
96 { type = _ILGetDataPointer(pidltemp)->type;
97 switch (type)
98 { case PT_DESKTOP:
99 case PT_MYCOMP:
100 case PT_SPECIAL:
101 case PT_DRIVE:
102 case PT_DRIVE1:
103 case PT_DRIVE2:
104 case PT_DRIVE3:
105 case PT_FOLDER:
106 case PT_VALUE:
107 case PT_FOLDER1:
108 case PT_WORKGRP:
109 case PT_COMP:
110 case PT_NETWORK:
111 case PT_IESPECIAL1:
112 case PT_IESPECIAL2:
113 case PT_SHARE:
114 break;
115 default:
117 char szTemp[BYTES_PRINTED*4 + 1];
118 int i;
119 unsigned char c;
121 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
122 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
124 c = ((unsigned char *)pidltemp)[i];
126 szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
127 szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
128 szTemp[i*3+2] = ' ';
129 szTemp[i+BYTES_PRINTED*3] = (c>=0x20 && c <=0x80) ? c : '.';
131 szTemp[BYTES_PRINTED*4] = 0x00;
132 ERR("unknown IDLIST type size=%u type=%lx\n%s\n",pidltemp->mkid.cb,type, szTemp);
133 ret = FALSE;
136 pidltemp = ILGetNext(pidltemp);
137 } while (pidltemp->mkid.cb);
139 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, bIsPidlDebug);
140 return ret;
143 /*************************************************************************
144 * ILGetDisplayName [SHELL32.15]
146 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl,LPSTR path)
148 TRACE_(shell)("pidl=%p %p semi-stub\n",pidl,path);
149 return SHGetPathFromIDListA(pidl, path);
151 /*************************************************************************
152 * ILFindLastID [SHELL32.16]
154 * NOTES
155 * observed: pidl=Desktop return=pidl
157 LPITEMIDLIST WINAPI ILFindLastID(LPITEMIDLIST pidl)
158 { LPITEMIDLIST pidlLast = pidl;
160 TRACE("(pidl=%p)\n",pidl);
162 while (pidl->mkid.cb)
164 pidlLast = pidl;
165 pidl = ILGetNext(pidl);
167 return pidlLast;
169 /*************************************************************************
170 * ILRemoveLastID [SHELL32.17]
172 * NOTES
173 * when pidl=Desktop return=FALSE
175 BOOL WINAPI ILRemoveLastID(LPCITEMIDLIST pidl)
177 TRACE_(shell)("pidl=%p\n",pidl);
179 if (!pidl || !pidl->mkid.cb)
180 return 0;
181 ILFindLastID(pidl)->mkid.cb = 0;
182 return 1;
185 /*************************************************************************
186 * ILClone [SHELL32.18]
188 * NOTES
189 * dupicate an idlist
191 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
192 { DWORD len;
193 LPITEMIDLIST newpidl;
195 if (!pidl)
196 return NULL;
198 len = ILGetSize(pidl);
199 newpidl = (LPITEMIDLIST)SHAlloc(len);
200 if (newpidl)
201 memcpy(newpidl,pidl,len);
203 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
204 pdump(pidl);
206 return newpidl;
208 /*************************************************************************
209 * ILCloneFirst [SHELL32.19]
211 * NOTES
212 * duplicates the first idlist of a complex pidl
214 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
215 { DWORD len;
216 LPITEMIDLIST pidlNew = NULL;
218 TRACE("pidl=%p \n",pidl);
219 pdump(pidl);
221 if (pidl)
223 len = pidl->mkid.cb;
224 pidlNew = (LPITEMIDLIST) SHAlloc (len+2);
225 if (pidlNew)
227 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
229 if (len)
230 ILGetNext(pidlNew)->mkid.cb = 0x00;
233 TRACE("-- newpidl=%p\n",pidlNew);
235 return pidlNew;
238 /*************************************************************************
239 * ILLoadFromStream (SHELL32.26)
241 * NOTES
242 * the first two bytes are the len, the pidl is following then
244 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
245 { WORD wLen = 0;
246 DWORD dwBytesRead;
247 HRESULT ret = E_FAIL;
250 TRACE_(shell)("%p %p\n", pStream , ppPidl);
252 if (*ppPidl)
253 { SHFree(*ppPidl);
254 *ppPidl = NULL;
257 IStream_AddRef (pStream);
259 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
260 { *ppPidl = SHAlloc (wLen);
261 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
262 { ret = S_OK;
264 else
265 { SHFree(*ppPidl);
266 *ppPidl = NULL;
270 /* we are not yet fully compatible */
271 if (!pcheck(*ppPidl))
272 { SHFree(*ppPidl);
273 *ppPidl = NULL;
277 IStream_Release (pStream);
279 return ret;
282 /*************************************************************************
283 * ILSaveToStream (SHELL32.27)
285 * NOTES
286 * the first two bytes are the len, the pidl is following then
288 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
290 LPITEMIDLIST pidl;
291 WORD wLen = 0;
292 HRESULT ret = E_FAIL;
294 TRACE_(shell)("%p %p\n", pStream, pPidl);
296 IStream_AddRef (pStream);
298 pidl = pPidl;
299 while (pidl->mkid.cb)
301 wLen += sizeof(WORD) + pidl->mkid.cb;
302 pidl = ILGetNext(pidl);
305 if (SUCCEEDED(IStream_Write(pStream, (LPVOID)&wLen, 2, NULL)))
307 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
308 { ret = S_OK;
313 IStream_Release (pStream);
315 return ret;
318 /*************************************************************************
319 * SHILCreateFromPath [SHELL32.28]
321 * NOTES
322 * wraper for IShellFolder::ParseDisplayName()
324 HRESULT WINAPI SHILCreateFromPathA (LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
325 { LPSHELLFOLDER sf;
326 WCHAR lpszDisplayName[MAX_PATH];
327 DWORD pchEaten;
328 HRESULT ret = E_FAIL;
330 TRACE_(shell)("%s %p 0x%08lx\n",path,ppidl,attributes?*attributes:0);
332 if (!MultiByteToWideChar( CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH ))
333 lpszDisplayName[MAX_PATH-1] = 0;
335 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
337 ret = IShellFolder_ParseDisplayName(sf,0, NULL,lpszDisplayName,&pchEaten,ppidl,attributes);
338 IShellFolder_Release(sf);
340 return ret;
342 HRESULT WINAPI SHILCreateFromPathW (LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
343 { LPSHELLFOLDER sf;
344 DWORD pchEaten;
345 HRESULT ret = E_FAIL;
347 TRACE_(shell)("%s %p 0x%08lx\n",debugstr_w(path),ppidl,attributes?*attributes:0);
349 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
351 ret = IShellFolder_ParseDisplayName(sf,0, NULL, (LPWSTR) path, &pchEaten, ppidl, attributes);
352 IShellFolder_Release(sf);
354 return ret;
356 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
358 if ( SHELL_OsIsUnicode())
359 return SHILCreateFromPathW (path, ppidl, attributes);
360 return SHILCreateFromPathA (path, ppidl, attributes);
363 /*************************************************************************
364 * SHCloneSpecialIDList [SHELL32.89]
366 * PARAMETERS
367 * hwndOwner [in]
368 * nFolder [in] CSIDL_xxxxx ??
370 * RETURNS
371 * pidl ??
372 * NOTES
373 * exported by ordinal
375 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner,DWORD nFolder,DWORD x3)
376 { LPITEMIDLIST ppidl;
377 WARN_(shell)("(hwnd=0x%x,csidl=0x%lx,0x%lx):semi-stub.\n",
378 hwndOwner,nFolder,x3);
380 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
382 return ppidl;
385 /*************************************************************************
386 * ILGlobalClone [SHELL32.20]
389 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
390 { DWORD len;
391 LPITEMIDLIST newpidl;
393 if (!pidl)
394 return NULL;
396 len = ILGetSize(pidl);
397 newpidl = (LPITEMIDLIST)pCOMCTL32_Alloc(len);
398 if (newpidl)
399 memcpy(newpidl,pidl,len);
401 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
402 pdump(pidl);
404 return newpidl;
407 /*************************************************************************
408 * ILIsEqual [SHELL32.21]
411 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
413 char szData1[MAX_PATH];
414 char szData2[MAX_PATH];
416 LPITEMIDLIST pidltemp1 = pidl1;
417 LPITEMIDLIST pidltemp2 = pidl2;
419 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
421 /* explorer reads from registry directly (StreamMRU),
422 so we can only check here */
423 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
425 pdump (pidl1);
426 pdump (pidl2);
428 if ( (!pidl1) || (!pidl2) ) return FALSE;
430 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
432 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
433 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
435 if (strcasecmp ( szData1, szData2 )!=0 )
436 return FALSE;
438 pidltemp1 = ILGetNext(pidltemp1);
439 pidltemp2 = ILGetNext(pidltemp2);
442 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
444 return TRUE;
447 return FALSE;
449 /*************************************************************************
450 * ILIsParent [SHELL32.23]
452 * parent=a/b child=a/b/c -> true, c is in folder a/b
453 * child=a/b/c/d -> false if bImmediate is true, d is not in folder a/b
454 * child=a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
456 BOOL WINAPI ILIsParent( LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
458 char szData1[MAX_PATH];
459 char szData2[MAX_PATH];
461 LPITEMIDLIST pParent = pidlParent;
462 LPITEMIDLIST pChild = pidlChild;
464 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
466 while (pParent->mkid.cb && pChild->mkid.cb)
468 _ILSimpleGetText(pParent, szData1, MAX_PATH);
469 _ILSimpleGetText(pChild, szData2, MAX_PATH);
471 if (strcasecmp ( szData1, szData2 )!=0 )
472 return FALSE;
474 pParent = ILGetNext(pParent);
475 pChild = ILGetNext(pChild);
478 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
479 return FALSE;
481 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
482 return FALSE;
484 return TRUE;
487 /*************************************************************************
488 * ILFindChild [SHELL32.24]
490 * NOTES
491 * Compares elements from pidl1 and pidl2.
493 * pidl1 is desktop pidl2
494 * pidl1 shorter pidl2 pointer to first different element of pidl2
495 * if there was at least one equal element
496 * pidl2 shorter pidl1 0
497 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
499 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
501 char szData1[MAX_PATH];
502 char szData2[MAX_PATH];
504 LPITEMIDLIST pidltemp1 = pidl1;
505 LPITEMIDLIST pidltemp2 = pidl2;
506 LPITEMIDLIST ret=NULL;
508 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
510 /* explorer reads from registry directly (StreamMRU),
511 so we can only check here */
512 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
513 return FALSE;
515 pdump (pidl1);
516 pdump (pidl2);
518 if ( _ILIsDesktop(pidl1) )
520 ret = pidl2;
522 else
524 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
526 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
527 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
529 if (strcasecmp(szData1,szData2))
530 break;
532 pidltemp1 = ILGetNext(pidltemp1);
533 pidltemp2 = ILGetNext(pidltemp2);
534 ret = pidltemp2;
537 if (pidltemp1->mkid.cb)
539 ret = NULL; /* elements of pidl1 left*/
542 TRACE_(shell)("--- %p\n", ret);
543 return ret; /* pidl 1 is shorter */
546 /*************************************************************************
547 * ILCombine [SHELL32.25]
549 * NOTES
550 * Concatenates two complex idlists.
551 * The pidl is the first one, pidlsub the next one
552 * Does not destroy the passed in idlists!
554 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
556 DWORD len1,len2;
557 LPITEMIDLIST pidlNew;
559 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
561 if(!pidl1 && !pidl2) return NULL;
563 pdump (pidl1);
564 pdump (pidl2);
566 if(!pidl1)
568 pidlNew = ILClone(pidl2);
569 return pidlNew;
572 if(!pidl2)
574 pidlNew = ILClone(pidl1);
575 return pidlNew;
578 len1 = ILGetSize(pidl1)-2;
579 len2 = ILGetSize(pidl2);
580 pidlNew = SHAlloc(len1+len2);
582 if (pidlNew)
584 memcpy(pidlNew,pidl1,len1);
585 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
588 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
589 return pidlNew;
591 /*************************************************************************
592 * SHGetRealIDL [SHELL32.98]
594 * NOTES
596 LPITEMIDLIST WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl, DWORD z)
598 FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf,pidl,z);
600 pdump (pidl);
601 return 0;
604 /*************************************************************************
605 * SHLogILFromFSIL [SHELL32.95]
607 * NOTES
608 * pild = CSIDL_DESKTOP ret = 0
609 * pild = CSIDL_DRIVES ret = 0
611 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
613 FIXME("(pidl=%p)\n",pidl);
615 pdump(pidl);
617 return 0;
620 /*************************************************************************
621 * ILGetSize [SHELL32.152]
622 * gets the byte size of an idlist including zero terminator (pidl)
624 * PARAMETERS
625 * pidl ITEMIDLIST
627 * RETURNS
628 * size of pidl
630 * NOTES
631 * exported by ordinal
633 DWORD WINAPI ILGetSize(LPITEMIDLIST pidl)
635 LPSHITEMID si = &(pidl->mkid);
636 DWORD len=0;
638 if (pidl)
639 { while (si->cb)
640 { len += si->cb;
641 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
643 len += 2;
645 TRACE("pidl=%p size=%lu\n",pidl, len);
646 return len;
649 /*************************************************************************
650 * ILGetNext [SHELL32.153]
651 * gets the next simple pidl of a complex pidl
653 * observed return values:
654 * null -> null
655 * desktop -> null
656 * simple pidl -> pointer to 0x0000 element
659 LPITEMIDLIST WINAPI ILGetNext(LPITEMIDLIST pidl)
661 WORD len;
663 TRACE("(pidl=%p)\n",pidl);
665 if(pidl)
667 len = pidl->mkid.cb;
668 if (len)
670 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
671 return pidl;
674 return NULL;
676 /*************************************************************************
677 * ILAppend [SHELL32.154]
679 * NOTES
680 * Adds the single item to the idlist indicated by pidl.
681 * if bEnd is 0, adds the item to the front of the list,
682 * otherwise adds the item to the end. (???)
683 * Destroys the passed in idlist! (???)
685 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl,LPCITEMIDLIST item,BOOL bEnd)
687 LPITEMIDLIST idlRet;
689 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
691 pdump (pidl);
692 pdump (item);
694 if (_ILIsDesktop(pidl))
696 idlRet = ILClone(item);
697 if (pidl)
698 SHFree (pidl);
699 return idlRet;
702 if (bEnd)
704 idlRet=ILCombine(pidl,item);
706 else
708 idlRet=ILCombine(item,pidl);
711 SHFree(pidl);
712 return idlRet;
714 /*************************************************************************
715 * ILFree [SHELL32.155]
717 * NOTES
718 * free_check_ptr - frees memory (if not NULL)
719 * allocated by SHMalloc allocator
720 * exported by ordinal
722 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
724 TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
726 if(!pidl) return FALSE;
727 SHFree(pidl);
728 return TRUE;
730 /*************************************************************************
731 * ILGlobalFree [SHELL32.156]
734 void WINAPI ILGlobalFree( LPCITEMIDLIST pidl)
736 TRACE("%p\n",pidl);
738 if(!pidl) return;
739 pCOMCTL32_Free(pidl);
741 /*************************************************************************
742 * ILCreateFromPath [SHELL32.157]
745 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
747 LPITEMIDLIST pidlnew;
748 DWORD attributes = 0;
750 TRACE_(shell)("%s\n",path);
752 if (SUCCEEDED (SHILCreateFromPathA (path, &pidlnew, &attributes)))
753 return pidlnew;
754 return FALSE;
756 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
758 LPITEMIDLIST pidlnew;
759 DWORD attributes = 0;
761 TRACE_(shell)("%s\n",debugstr_w(path));
763 if (SUCCEEDED (SHILCreateFromPathW (path, &pidlnew, &attributes)))
764 return pidlnew;
765 return FALSE;
767 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
769 if ( SHELL_OsIsUnicode())
770 return ILCreateFromPathW (path);
771 return ILCreateFromPathA (path);
773 /*************************************************************************
774 * SHSimpleIDListFromPath [SHELL32.162]
776 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPCSTR lpszPath)
778 LPITEMIDLIST pidl=NULL;
779 HANDLE hFile;
780 WIN32_FIND_DATAA stffile;
782 TRACE("path=%s\n", lpszPath);
784 if (!lpszPath) return NULL;
786 hFile = FindFirstFileA(lpszPath, &stffile);
788 if ( hFile != INVALID_HANDLE_VALUE )
790 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
792 pidl = _ILCreateFolder (&stffile);
794 else
796 pidl = _ILCreateValue (&stffile);
798 FindClose (hFile);
800 return pidl;
802 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPCWSTR lpszPath)
804 char lpszTemp[MAX_PATH];
805 TRACE("path=%s\n",debugstr_w(lpszPath));
807 if (!WideCharToMultiByte( CP_ACP, 0, lpszPath, -1, lpszTemp, sizeof(lpszTemp), NULL, NULL ))
808 lpszTemp[sizeof(lpszTemp)-1] = 0;
810 return SHSimpleIDListFromPathA (lpszTemp);
813 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW (LPCVOID lpszPath)
815 if ( SHELL_OsIsUnicode())
816 return SHSimpleIDListFromPathW (lpszPath);
817 return SHSimpleIDListFromPathA (lpszPath);
820 /*************************************************************************
821 * SHGetSpecialFolderLocation [SHELL32.@]
823 * gets the folder locations from the registry and creates a pidl
824 * creates missing reg keys and directorys
826 * PARAMS
827 * hwndOwner [I]
828 * nFolder [I] CSIDL_xxxxx
829 * ppidl [O] PIDL of a special folder
832 HRESULT WINAPI SHGetSpecialFolderLocation(
833 HWND hwndOwner,
834 INT nFolder,
835 LPITEMIDLIST * ppidl)
837 CHAR szPath[MAX_PATH];
838 HRESULT hr = E_INVALIDARG;
840 TRACE_(shell)("(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
842 if (ppidl)
844 *ppidl = NULL;
845 switch (nFolder)
847 case CSIDL_DESKTOP:
848 *ppidl = _ILCreateDesktop();
849 break;
851 case CSIDL_DRIVES:
852 *ppidl = _ILCreateMyComputer();
853 break;
855 case CSIDL_NETWORK:
856 *ppidl = _ILCreateNetwork ();
857 break;
859 case CSIDL_CONTROLS:
860 *ppidl = _ILCreateControl ();
861 break;
863 case CSIDL_PRINTERS:
864 *ppidl = _ILCreatePrinter ();
865 break;
867 case CSIDL_BITBUCKET:
868 *ppidl = _ILCreateBitBucket ();
869 break;
871 default:
872 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
874 DWORD attributes=0;
875 TRACE_(shell)("Value=%s\n",szPath);
876 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
879 if(*ppidl) hr = NOERROR;
882 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
883 return hr;
886 /*************************************************************************
887 * SHGetFolderLocation [SHELL32.@]
889 * NOTES
890 * the pidl can be a simple one. since we cant get the path out of the pidl
891 * we have to take all data from the pidl
893 HRESULT WINAPI SHGetFolderLocation(
894 HWND hwnd,
895 int csidl,
896 HANDLE hToken,
897 DWORD dwFlags,
898 LPITEMIDLIST *ppidl)
900 FIXME("0x%04x 0x%08x 0x%08x 0x%08lx %p\n",
901 hwnd, csidl, hToken, dwFlags, ppidl);
902 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
905 /*************************************************************************
906 * SHGetDataFromIDListA [SHELL32.247]
908 * NOTES
909 * the pidl can be a simple one. since we cant get the path out of the pidl
910 * we have to take all data from the pidl
912 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
914 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
916 pdump(pidl);
917 if (!psf || !dest ) return E_INVALIDARG;
919 switch (nFormat)
921 case SHGDFIL_FINDDATA:
923 WIN32_FIND_DATAA * pfd = dest;
925 if ( len < sizeof (WIN32_FIND_DATAA)) return E_INVALIDARG;
927 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
928 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
929 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
930 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
931 lstrcpynA(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
932 lstrcpynA(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
934 return NOERROR;
936 case SHGDFIL_NETRESOURCE:
937 case SHGDFIL_DESCRIPTIONID:
938 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
939 break;
941 default:
942 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
945 return E_INVALIDARG;
947 /*************************************************************************
948 * SHGetDataFromIDListW [SHELL32.248]
951 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
953 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
955 pdump(pidl);
957 if (! psf || !dest ) return E_INVALIDARG;
959 switch (nFormat)
961 case SHGDFIL_FINDDATA:
963 WIN32_FIND_DATAW * pfd = dest;
965 if ( len < sizeof (WIN32_FIND_DATAW)) return E_INVALIDARG;
967 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
968 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
969 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
970 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
971 if (!MultiByteToWideChar( CP_ACP, 0, _ILGetTextPointer(pidl), -1,
972 pfd->cFileName, MAX_PATH ))
973 pfd->cFileName[MAX_PATH-1] = 0;
974 if (!MultiByteToWideChar( CP_ACP, 0, _ILGetSTextPointer(pidl), -1,
975 pfd->cAlternateFileName, 14 ))
976 pfd->cFileName[13] = 0;
978 return NOERROR;
979 case SHGDFIL_NETRESOURCE:
980 case SHGDFIL_DESCRIPTIONID:
981 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
982 break;
984 default:
985 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
988 return E_INVALIDARG;
991 /*************************************************************************
992 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
994 * PARAMETERS
995 * pidl, [IN] pidl
996 * pszPath [OUT] path
998 * RETURNS
999 * path from a passed PIDL.
1001 * NOTES
1002 * NULL returns FALSE
1003 * desktop pidl gives path to desktopdirectory back
1004 * special pidls returning FALSE
1006 * FIXME
1007 * fnGetDisplayNameOf can return different types of OLEString
1009 BOOL WINAPI SHGetPathFromIDListA (LPCITEMIDLIST pidl,LPSTR pszPath)
1010 { STRRET str;
1011 LPSHELLFOLDER shellfolder;
1013 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1015 if (!pidl) return FALSE;
1017 pdump(pidl);
1019 if(_ILIsDesktop(pidl))
1021 SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1023 else if (_ILIsSpecialFolder(ILFindLastID(pidl)))
1025 /* we are somewhere in a special folder */
1026 return FALSE;
1028 else
1030 if (SHGetDesktopFolder(&shellfolder)==S_OK)
1032 IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
1033 StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
1034 IShellFolder_Release(shellfolder);
1037 TRACE_(shell)("-- (%s)\n",pszPath);
1039 return TRUE;
1041 /*************************************************************************
1042 * SHGetPathFromIDListW [SHELL32.@]
1044 BOOL WINAPI SHGetPathFromIDListW (LPCITEMIDLIST pidl,LPWSTR pszPath)
1045 { char sTemp[MAX_PATH];
1047 TRACE_(shell)("(pidl=%p)\n", pidl);
1049 SHGetPathFromIDListA (pidl, sTemp);
1050 MultiByteToWideChar( CP_ACP, 0, sTemp, -1, pszPath, MAX_PATH );
1052 TRACE_(shell)("-- (%s)\n",debugstr_w(pszPath));
1054 return TRUE;
1057 /*************************************************************************
1058 * SHBindToParent [shell version 5.0]
1060 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1062 IShellFolder * psf;
1063 LPITEMIDLIST pidlChild, pidlParent;
1064 HRESULT hr=E_FAIL;
1066 TRACE_(shell)("pidl=%p\n", pidl);
1067 pdump(pidl);
1069 *ppv = NULL;
1070 if (ppidlLast) *ppidlLast = NULL;
1072 if (_ILIsPidlSimple(pidl))
1074 /* we are on desktop level */
1075 if (ppidlLast)
1076 *ppidlLast = ILClone(pidl);
1077 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1079 else
1081 pidlChild = ILClone(ILFindLastID(pidl));
1082 pidlParent = ILClone(pidl);
1083 ILRemoveLastID(pidlParent);
1085 hr = SHGetDesktopFolder(&psf);
1087 if (SUCCEEDED(hr))
1088 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1090 if (SUCCEEDED(hr) && ppidlLast)
1091 *ppidlLast = pidlChild;
1092 else
1093 ILFree (pidlChild);
1095 SHFree (pidlParent);
1096 if (psf) IShellFolder_Release(psf);
1100 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1101 return hr;
1104 /*************************************************************************
1105 * SHGetPathFromIDList [SHELL32.@][NT 4.0: SHELL32.219]
1107 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1109 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1111 if (SHELL_OsIsUnicode())
1112 return SHGetPathFromIDListW(pidl,pszPath);
1113 return SHGetPathFromIDListA(pidl,pszPath);
1116 /**************************************************************************
1118 * internal functions
1120 * ### 1. section creating pidls ###
1122 *************************************************************************
1123 * _ILCreateDesktop()
1124 * _ILCreateIExplore()
1125 * _ILCreateMyComputer()
1126 * _ILCreateDrive()
1127 * _ILCreateFolder()
1128 * _ILCreateValue()
1130 LPITEMIDLIST _ILCreateDesktop()
1131 { TRACE("()\n");
1132 return _ILCreate(PT_DESKTOP, NULL, 0);
1135 LPITEMIDLIST _ILCreateMyComputer()
1136 { TRACE("()\n");
1137 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1140 LPITEMIDLIST _ILCreateIExplore()
1141 { TRACE("()\n");
1142 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1145 LPITEMIDLIST _ILCreateControl()
1146 { TRACE("()\n");
1147 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1150 LPITEMIDLIST _ILCreatePrinter()
1151 { TRACE("()\n");
1152 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1155 LPITEMIDLIST _ILCreateNetwork()
1156 { TRACE("()\n");
1157 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1160 LPITEMIDLIST _ILCreateBitBucket()
1161 { TRACE("()\n");
1162 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1165 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1166 { char sTemp[4];
1167 lstrcpynA (sTemp,lpszNew,4);
1168 sTemp[2]='\\';
1169 sTemp[3]=0x00;
1170 TRACE("(%s)\n",sTemp);
1171 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1174 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1176 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1177 char * pbuff = buff;
1178 ULONG len, len1;
1179 LPITEMIDLIST pidl;
1181 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1183 /* prepare buffer with both names */
1184 len = strlen (stffile->cFileName) + 1;
1185 memcpy (pbuff, stffile->cFileName, len);
1186 pbuff += len;
1188 if (stffile->cAlternateFileName)
1190 len1 = strlen (stffile->cAlternateFileName)+1;
1191 memcpy (pbuff, stffile->cAlternateFileName, len1);
1193 else
1195 len1 = 1;
1196 *pbuff = 0x00;
1199 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1201 /* set attributes */
1202 if (pidl)
1204 LPPIDLDATA pData;
1205 pData = _ILGetDataPointer(pidl);
1206 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1207 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1208 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1211 return pidl;
1214 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1216 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1217 char * pbuff = buff;
1218 ULONG len, len1;
1219 LPITEMIDLIST pidl;
1221 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1223 /* prepare buffer with both names */
1224 len = strlen (stffile->cFileName) + 1;
1225 memcpy (pbuff, stffile->cFileName, len);
1226 pbuff += len;
1228 if (stffile->cAlternateFileName)
1230 len1 = strlen (stffile->cAlternateFileName)+1;
1231 memcpy (pbuff, stffile->cAlternateFileName, len1);
1233 else
1235 len1 = 1;
1236 *pbuff = 0x00;
1239 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1241 /* set attributes */
1242 if (pidl)
1244 LPPIDLDATA pData;
1245 pData = _ILGetDataPointer(pidl);
1246 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1247 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1248 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1251 return pidl;
1254 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1256 IID iid;
1257 WCHAR buffer[40];
1259 if (!MultiByteToWideChar( CP_ACP, 0, szGUID, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1260 return NULL;
1261 CLSIDFromString( buffer, &iid );
1262 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1265 /**************************************************************************
1266 * _ILCreate()
1267 * Creates a new PIDL
1268 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1269 * pIn = data
1270 * uInSize = size of data (raw)
1273 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT uInSize)
1275 LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1276 LPPIDLDATA pData;
1277 UINT uSize = 0;
1278 LPSTR pszDest;
1280 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1282 switch (type)
1284 case PT_DESKTOP:
1285 uSize = 0;
1286 break;
1287 case PT_SPECIAL:
1288 case PT_MYCOMP:
1289 uSize = 2 + 2 + sizeof(GUID);
1290 break;
1291 case PT_DRIVE:
1292 uSize = 2 + 23;
1293 break;
1294 case PT_FOLDER:
1295 case PT_VALUE:
1296 uSize = 2 + 12 + uInSize;
1297 break;
1298 default:
1299 FIXME("can't create type: 0x%08x\n",type);
1300 return NULL;
1303 if(!(pidlOut = SHAlloc(uSize + 2))) return NULL;
1304 ZeroMemory(pidlOut, uSize + 2);
1305 pidlOut->mkid.cb = uSize;
1307 switch (type)
1309 case PT_DESKTOP:
1310 TRACE("- create Desktop\n");
1311 break;
1313 case PT_SPECIAL:
1314 case PT_MYCOMP:
1315 pData =_ILGetDataPointer(pidlOut);
1316 pData->type = type;
1317 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1318 TRACE("- create GUID-pidl\n");
1319 break;
1321 case PT_DRIVE:
1322 pData =_ILGetDataPointer(pidlOut);
1323 pData->type = type;
1324 pszDest = _ILGetTextPointer(pidlOut);
1325 memcpy(pszDest, pIn, uInSize);
1326 TRACE("- create Drive: %s\n",debugstr_a(pszDest));
1327 break;
1329 case PT_FOLDER:
1330 case PT_VALUE:
1331 pData =_ILGetDataPointer(pidlOut);
1332 pData->type = type;
1333 pszDest = _ILGetTextPointer(pidlOut);
1334 memcpy(pszDest, pIn, uInSize);
1335 TRACE("- create Value: %s\n",debugstr_a(pszDest));
1336 break;
1339 pidlTemp = ILGetNext(pidlOut);
1340 if (pidlTemp)
1341 pidlTemp->mkid.cb = 0x00;
1343 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1344 return pidlOut;
1347 /**************************************************************************
1348 * _ILGetDrive()
1350 * Gets the text for the drive eg. 'c:\'
1352 * RETURNS
1353 * strlen (lpszText)
1355 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1356 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1358 if(_ILIsMyComputer(pidl))
1359 pidl = ILGetNext(pidl);
1361 if (pidl && _ILIsDrive(pidl))
1362 return _ILSimpleGetText(pidl, pOut, uSize);
1364 return 0;
1367 /**************************************************************************
1369 * ### 2. section testing pidls ###
1371 **************************************************************************
1372 * _ILIsDesktop()
1373 * _ILIsMyComputer()
1374 * _ILIsSpecialFolder()
1375 * _ILIsDrive()
1376 * _ILIsFolder()
1377 * _ILIsValue()
1378 * _ILIsPidlSimple()
1380 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1381 { TRACE("(%p)\n",pidl);
1382 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
1385 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1387 REFIID iid = _ILGetGUIDPointer(pidl);
1389 TRACE("(%p)\n",pidl);
1391 if (iid)
1392 return IsEqualIID(iid, &CLSID_MyComputer);
1393 return FALSE;
1396 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1398 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1399 TRACE("(%p)\n",pidl);
1400 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1401 (pidl && pidl->mkid.cb == 0x00)
1405 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1406 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1407 TRACE("(%p)\n",pidl);
1408 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1409 PT_DRIVE1 == lpPData->type ||
1410 PT_DRIVE2 == lpPData->type ||
1411 PT_DRIVE3 == lpPData->type));
1414 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1415 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1416 TRACE("(%p)\n",pidl);
1417 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1420 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1421 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1422 TRACE("(%p)\n",pidl);
1423 return (pidl && lpPData && PT_VALUE == lpPData->type);
1426 /**************************************************************************
1427 * _ILIsPidlSimple
1429 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1431 BOOL ret = TRUE;
1433 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1435 WORD len = pidl->mkid.cb;
1436 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1437 if (pidlnext->mkid.cb)
1438 ret = FALSE;
1441 TRACE("%s\n", ret ? "Yes" : "No");
1442 return ret;
1445 /**************************************************************************
1447 * ### 3. section getting values from pidls ###
1450 /**************************************************************************
1451 * _ILSimpleGetText
1453 * gets the text for the first item in the pidl (eg. simple pidl)
1455 * returns the length of the string
1457 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1459 DWORD dwReturn=0;
1460 LPSTR szSrc;
1461 GUID const * riid;
1462 char szTemp[MAX_PATH];
1464 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1466 if (!pidl) return 0;
1468 if (szOut)
1469 *szOut = 0;
1471 if (_ILIsDesktop(pidl))
1473 /* desktop */
1474 if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1476 if (szOut)
1477 lstrcpynA(szOut, szTemp, uOutSize);
1479 dwReturn = strlen (szTemp);
1482 else if (( szSrc = _ILGetTextPointer(pidl) ))
1484 /* filesystem */
1485 if (szOut)
1486 lstrcpynA(szOut, szSrc, uOutSize);
1488 dwReturn = strlen(szSrc);
1490 else if (( riid = _ILGetGUIDPointer(pidl) ))
1492 /* special folder */
1493 if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
1495 if (szOut)
1496 lstrcpynA(szOut, szTemp, uOutSize);
1498 dwReturn = strlen (szTemp);
1501 else
1503 ERR("-- no text\n");
1506 TRACE("-- (%p=%s 0x%08lx)\n",szOut,(char*)szOut,dwReturn);
1507 return dwReturn;
1510 /**************************************************************************
1512 * ### 4. getting pointers to parts of pidls ###
1514 **************************************************************************
1515 * _ILGetDataPointer()
1517 LPPIDLDATA _ILGetDataPointer(LPITEMIDLIST pidl)
1519 if(pidl && pidl->mkid.cb != 0x00)
1520 return (LPPIDLDATA) &(pidl->mkid.abID);
1521 return NULL;
1524 /**************************************************************************
1525 * _ILGetTextPointer()
1526 * gets a pointer to the long filename string stored in the pidl
1528 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1529 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1531 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1533 if (pdata)
1535 switch (pdata->type)
1537 case PT_MYCOMP:
1538 case PT_SPECIAL:
1539 return NULL;
1541 case PT_DRIVE:
1542 case PT_DRIVE1:
1543 case PT_DRIVE2:
1544 case PT_DRIVE3:
1545 return (LPSTR)&(pdata->u.drive.szDriveName);
1547 case PT_FOLDER:
1548 case PT_FOLDER1:
1549 case PT_VALUE:
1550 case PT_IESPECIAL1:
1551 case PT_IESPECIAL2:
1552 return (LPSTR)&(pdata->u.file.szNames);
1554 case PT_WORKGRP:
1555 case PT_COMP:
1556 case PT_NETWORK:
1557 case PT_SHARE:
1558 return (LPSTR)&(pdata->u.network.szNames);
1561 return NULL;
1564 /**************************************************************************
1565 * _ILGetSTextPointer()
1566 * gets a pointer to the short filename string stored in the pidl
1568 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1569 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1571 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1573 if (pdata)
1575 switch (pdata->type)
1577 case PT_FOLDER:
1578 case PT_VALUE:
1579 case PT_IESPECIAL1:
1580 case PT_IESPECIAL2:
1581 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1583 case PT_WORKGRP:
1584 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1587 return NULL;
1590 /**************************************************************************
1591 * _ILGetGUIDPointer()
1593 * returns reference to guid stored in some pidls
1595 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1597 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1599 if (pdata)
1601 switch (pdata->type)
1603 case PT_SPECIAL:
1604 case PT_MYCOMP:
1605 return (REFIID) &(pdata->u.mycomp.guid);
1608 return NULL;
1611 /*************************************************************************
1612 * _ILGetFileDateTime
1614 * Given the ItemIdList, get the FileTime
1616 * PARAMS
1617 * pidl [I] The ItemIDList
1618 * pFt [I] the resulted FILETIME of the file
1620 * RETURNS
1621 * True if Successful
1623 * NOTES
1626 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1628 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1630 if(! pdata) return FALSE;
1632 switch (pdata->type)
1634 case PT_FOLDER:
1635 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1636 break;
1637 case PT_VALUE:
1638 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1639 break;
1640 default:
1641 return FALSE;
1643 return TRUE;
1646 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1648 FILETIME ft,lft;
1649 SYSTEMTIME time;
1651 if (! _ILGetFileDateTime( pidl, &ft )) return FALSE;
1653 FileTimeToLocalFileTime(&ft, &lft);
1654 FileTimeToSystemTime (&lft, &time);
1655 return GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
1658 /*************************************************************************
1659 * _ILGetFileSize
1661 * Given the ItemIdList, get the FileSize
1663 * PARAMS
1664 * pidl [I] The ItemIDList
1665 * pOut [I] The buffer to save the result
1666 * uOutsize [I] The size of the buffer
1668 * RETURNS
1669 * The FileSize
1671 * NOTES
1672 * pOut can be null when no string is needed
1675 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1677 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1678 DWORD dwSize;
1680 if(! pdata) return 0;
1682 switch (pdata->type)
1684 case PT_VALUE:
1685 dwSize = pdata->u.file.dwFileSize;
1686 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1687 return dwSize;
1689 if (pOut) *pOut = 0x00;
1690 return 0;
1693 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1695 char szTemp[MAX_PATH];
1696 const char * pPoint;
1697 LPITEMIDLIST pidlTemp=pidl;
1699 TRACE("pidl=%p\n",pidl);
1701 if (!pidl) return FALSE;
1703 pidlTemp = ILFindLastID(pidl);
1705 if (!_ILIsValue(pidlTemp)) return FALSE;
1706 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1708 pPoint = PathFindExtensionA(szTemp);
1710 if (! *pPoint) return FALSE;
1712 pPoint++;
1713 lstrcpynA(pOut, pPoint, uOutSize);
1714 TRACE("%s\n",pOut);
1716 return TRUE;
1719 /*************************************************************************
1720 * _ILGetFileType
1722 * Given the ItemIdList, get the file type description
1724 * PARAMS
1725 * pidl [I] The ItemIDList (simple)
1726 * pOut [I] The buffer to save the result
1727 * uOutsize [I] The size of the buffer
1729 * RETURNS
1730 * nothing
1732 * NOTES
1733 * This function copies as much as possible into the buffer.
1735 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1737 if(_ILIsValue(pidl))
1739 char sTemp[64];
1740 if(uOutSize > 0)
1742 pOut[0] = 0;
1744 if (_ILGetExtension (pidl, sTemp, 64))
1746 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1747 && HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
1749 lstrcpynA (pOut, sTemp, uOutSize - 6);
1750 strcat (pOut, "-file");
1754 else
1756 lstrcpynA(pOut, "Folder", uOutSize);
1760 /*************************************************************************
1761 * _ILGetFileAttributes
1763 * Given the ItemIdList, get the Attrib string format
1765 * PARAMS
1766 * pidl [I] The ItemIDList
1767 * pOut [I] The buffer to save the result
1768 * uOutsize [I] The size of the Buffer
1770 * RETURNS
1771 * Attributes
1773 * FIXME
1774 * return value 0 in case of error is a valid return value
1777 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1779 LPPIDLDATA pData =_ILGetDataPointer(pidl);
1780 WORD wAttrib = 0;
1781 int i;
1783 if(! pData) return 0;
1785 switch(pData->type)
1787 case PT_FOLDER:
1788 wAttrib = pData->u.folder.uFileAttribs;
1789 break;
1790 case PT_VALUE:
1791 wAttrib = pData->u.file.uFileAttribs;
1792 break;
1795 if(uOutSize >= 6)
1797 i=0;
1798 if(wAttrib & FILE_ATTRIBUTE_READONLY)
1800 pOut[i++] = 'R';
1802 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
1804 pOut[i++] = 'H';
1806 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
1808 pOut[i++] = 'S';
1810 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
1812 pOut[i++] = 'A';
1814 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
1816 pOut[i++] = 'C';
1818 pOut[i] = 0x00;
1820 return wAttrib;
1823 /*************************************************************************
1824 * ILFreeaPidl
1826 * free a aPidl struct
1828 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
1830 int i;
1832 if(apidl)
1834 for(i = 0; i < cidl; i++) SHFree(apidl[i]);
1835 SHFree(apidl);
1839 /*************************************************************************
1840 * ILCopyaPidl
1842 * copys a aPidl struct
1844 LPITEMIDLIST * _ILCopyaPidl(LPITEMIDLIST * apidlsrc, UINT cidl)
1846 int i;
1847 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
1848 if(!apidlsrc) return NULL;
1850 for(i = 0; i < cidl; i++)
1851 apidldest[i] = ILClone(apidlsrc[i]);
1853 return apidldest;
1856 /*************************************************************************
1857 * _ILCopyCidaToaPidl
1859 * creates aPidl from CIDA
1861 LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPCIDA cida)
1863 int i;
1864 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
1866 if(!dst) return NULL;
1868 if (pidl)
1869 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
1871 for(i = 0; i < cida->cidl; i++)
1872 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));
1874 return dst;