Pass the main exe name in the CREATE_PROCESS debug event.
[wine.git] / dlls / shell32 / pidl.c
blob96ec11851b6a543977fd81e463ea2777c3428747
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 "shell.h"
17 #include "shlguid.h"
18 #include "winerror.h"
19 #include "winnls.h"
20 #include "winversion.h"
21 #include "shell32_main.h"
22 #include "shellapi.h"
24 #include "pidl.h"
25 #include "wine/undocshell.h"
27 DEFAULT_DEBUG_CHANNEL(pidl)
28 DECLARE_DEBUG_CHANNEL(shell)
30 void pdump (LPCITEMIDLIST pidl)
32 BOOL bIsShellDebug;
34 LPITEMIDLIST pidltemp = pidl;
35 if (!TRACE_ON(pidl))
36 return;
38 /* silence the sub-functions */
39 bIsShellDebug = TRACE_ON(shell);
40 __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, FALSE);
41 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
43 if (! pidltemp)
45 MESSAGE ("-------- pidl=NULL (Desktop)\n");
47 else
49 MESSAGE ("-------- pidl=%p\n", pidl);
50 if (pidltemp->mkid.cb)
54 DWORD dwAttrib = 0;
55 LPPIDLDATA pData = _ILGetDataPointer(pidltemp);
56 DWORD type = pData->type;
57 LPSTR szLongName = _ILGetTextPointer(pidltemp);
58 LPSTR szShortName = _ILGetSTextPointer(pidltemp);
59 char szName[MAX_PATH];
61 _ILSimpleGetText(pidltemp, szName, MAX_PATH);
62 if( PT_FOLDER == type)
63 dwAttrib = pData->u.folder.uFileAttribs;
64 else if( PT_VALUE == type)
65 dwAttrib = pData->u.file.uFileAttribs;
67 MESSAGE ("-- pidl=%p size=%u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
68 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
70 pidltemp = ILGetNext(pidltemp);
72 } while (pidltemp->mkid.cb);
74 else
76 MESSAGE ("empty pidl (Desktop)\n");
78 pcheck(pidl);
81 __SET_DEBUGGING(__DBCL_TRACE, dbch_shell, bIsShellDebug);
82 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, TRUE);
85 #define BYTES_PRINTED 32
86 BOOL pcheck (LPCITEMIDLIST pidl)
87 { DWORD type, ret=TRUE;
88 BOOL bIsPidlDebug;
90 LPITEMIDLIST pidltemp = pidl;
92 bIsPidlDebug = TRACE_ON(shell);
93 __SET_DEBUGGING(__DBCL_TRACE, dbch_pidl, FALSE);
95 if (pidltemp && pidltemp->mkid.cb)
96 { do
97 { type = _ILGetDataPointer(pidltemp)->type;
98 switch (type)
99 { case PT_DESKTOP:
100 case PT_MYCOMP:
101 case PT_SPECIAL:
102 case PT_DRIVE:
103 case PT_DRIVE1:
104 case PT_DRIVE2:
105 case PT_DRIVE3:
106 case PT_FOLDER:
107 case PT_VALUE:
108 case PT_FOLDER1:
109 case PT_WORKGRP:
110 case PT_COMP:
111 case PT_NETWORK:
112 case PT_SHARE:
113 case PT_IESPECIAL:
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, 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;
237 /*************************************************************************
238 * ILLoadFromStream
240 * NOTES
241 * the first two bytes are the len, the pidl is following then
243 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
244 { WORD wLen = 0;
245 DWORD dwBytesRead;
246 HRESULT ret = E_FAIL;
249 TRACE_(shell)("%p %p\n", pStream , ppPidl);
251 if (*ppPidl)
252 { SHFree(*ppPidl);
253 *ppPidl = NULL;
256 IStream_AddRef (pStream);
258 if (SUCCEEDED(IStream_Read(pStream, (LPVOID)&wLen, 2, &dwBytesRead)))
259 { *ppPidl = SHAlloc (wLen);
260 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
261 { ret = S_OK;
263 else
264 { SHFree(*ppPidl);
265 *ppPidl = NULL;
269 /* we are not jet fully compatible */
270 if (!pcheck(*ppPidl))
271 { SHFree(*ppPidl);
272 *ppPidl = NULL;
276 IStream_Release (pStream);
278 return ret;
280 /*************************************************************************
281 * SHILCreateFromPath [SHELL32.28]
283 * NOTES
284 * wraper for IShellFolder::ParseDisplayName()
286 HRESULT WINAPI SHILCreateFromPathA (LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
287 { LPSHELLFOLDER sf;
288 WCHAR lpszDisplayName[MAX_PATH];
289 DWORD pchEaten;
290 HRESULT ret = E_FAIL;
292 TRACE_(shell)("%s %p 0x%08lx\n",path,ppidl,attributes?*attributes:0);
294 lstrcpynAtoW(lpszDisplayName, path, MAX_PATH);
296 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
298 ret = IShellFolder_ParseDisplayName(sf,0, NULL,lpszDisplayName,&pchEaten,ppidl,attributes);
299 IShellFolder_Release(sf);
301 return ret;
303 HRESULT WINAPI SHILCreateFromPathW (LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
304 { LPSHELLFOLDER sf;
305 DWORD pchEaten;
306 HRESULT ret = E_FAIL;
308 TRACE_(shell)("%s %p 0x%08lx\n",debugstr_w(path),ppidl,attributes?*attributes:0);
310 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
312 ret = IShellFolder_ParseDisplayName(sf,0, NULL, (LPWSTR) path, &pchEaten, ppidl, attributes);
313 IShellFolder_Release(sf);
315 return ret;
317 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
319 if ( VERSION_OsIsUnicode())
320 return SHILCreateFromPathW (path, ppidl, attributes);
321 return SHILCreateFromPathA (path, ppidl, attributes);
324 /*************************************************************************
325 * SHCloneSpecialIDList [SHELL32.89]
327 * PARAMETERS
328 * hwndOwner [in]
329 * nFolder [in] CSIDL_xxxxx ??
331 * RETURNS
332 * pidl ??
333 * NOTES
334 * exported by ordinal
336 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner,DWORD nFolder,DWORD x3)
337 { LPITEMIDLIST ppidl;
338 WARN_(shell)("(hwnd=0x%x,csidl=0x%lx,0x%lx):semi-stub.\n",
339 hwndOwner,nFolder,x3);
341 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
343 return ppidl;
346 /*************************************************************************
347 * ILGlobalClone [SHELL32.97]
350 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
351 { DWORD len;
352 LPITEMIDLIST newpidl;
354 if (!pidl)
355 return NULL;
357 len = ILGetSize(pidl);
358 newpidl = (LPITEMIDLIST)pCOMCTL32_Alloc(len);
359 if (newpidl)
360 memcpy(newpidl,pidl,len);
362 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
363 pdump(pidl);
365 return newpidl;
368 /*************************************************************************
369 * ILIsEqual [SHELL32.21]
372 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
374 char szData1[MAX_PATH];
375 char szData2[MAX_PATH];
377 LPITEMIDLIST pidltemp1 = pidl1;
378 LPITEMIDLIST pidltemp2 = pidl2;
380 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
382 /* explorer reads from registry directly (StreamMRU),
383 so we can only check here */
384 if ((!pcheck (pidl1)) || (!pcheck (pidl2))) return FALSE;
386 pdump (pidl1);
387 pdump (pidl2);
389 if ( (!pidl1) || (!pidl2) ) return FALSE;
391 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
393 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
394 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
396 if (strcasecmp ( szData1, szData2 )!=0 )
397 return FALSE;
399 pidltemp1 = ILGetNext(pidltemp1);
400 pidltemp2 = ILGetNext(pidltemp2);
403 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
405 return TRUE;
408 return FALSE;
410 /*************************************************************************
411 * ILIsParent [SHELL32.23]
413 * parent=a/b child=a/b/c -> true, c is in folder a/b
414 * child=a/b/c/d -> false if bImmediate is true, d is not in folder a/b
415 * child=a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
417 BOOL WINAPI ILIsParent( LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
419 char szData1[MAX_PATH];
420 char szData2[MAX_PATH];
422 LPITEMIDLIST pParent = pidlParent;
423 LPITEMIDLIST pChild = pidlChild;
425 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
427 while (pParent->mkid.cb && pChild->mkid.cb)
429 _ILSimpleGetText(pParent, szData1, MAX_PATH);
430 _ILSimpleGetText(pChild, szData2, MAX_PATH);
432 if (strcasecmp ( szData1, szData2 )!=0 )
433 return FALSE;
435 pParent = ILGetNext(pParent);
436 pChild = ILGetNext(pChild);
439 if ( pParent->mkid.cb || ! pChild->mkid.cb) /* child shorter or has equal length to parent */
440 return FALSE;
442 if ( ILGetNext(pChild)->mkid.cb && bImmediate) /* not immediate descent */
443 return FALSE;
445 return TRUE;
448 /*************************************************************************
449 * ILFindChild [SHELL32.24]
451 * NOTES
452 * Compares elements from pidl1 and pidl2.
454 * pidl1 is desktop pidl2
455 * pidl1 shorter pidl2 pointer to first different element of pidl2
456 * if there was at least one equal element
457 * pidl2 shorter pidl1 0
458 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
460 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
462 char szData1[MAX_PATH];
463 char szData2[MAX_PATH];
465 LPITEMIDLIST pidltemp1 = pidl1;
466 LPITEMIDLIST pidltemp2 = pidl2;
467 LPITEMIDLIST ret=NULL;
469 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
471 /* explorer reads from registry directly (StreamMRU),
472 so we can only check here */
473 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
474 return FALSE;
476 pdump (pidl1);
477 pdump (pidl2);
479 if ( _ILIsDesktop(pidl1) )
481 ret = pidl2;
483 else
485 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
487 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
488 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
490 if (strcasecmp(szData1,szData2))
491 break;
493 pidltemp1 = ILGetNext(pidltemp1);
494 pidltemp2 = ILGetNext(pidltemp2);
495 ret = pidltemp2;
498 if (pidltemp1->mkid.cb)
500 ret = NULL; /* elements of pidl1 left*/
503 TRACE_(shell)("--- %p\n", ret);
504 return ret; /* pidl 1 is shorter */
507 /*************************************************************************
508 * ILCombine [SHELL32.25]
510 * NOTES
511 * Concatenates two complex idlists.
512 * The pidl is the first one, pidlsub the next one
513 * Does not destroy the passed in idlists!
515 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
517 DWORD len1,len2;
518 LPITEMIDLIST pidlNew;
520 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
522 if(!pidl1 && !pidl2) return NULL;
524 pdump (pidl1);
525 pdump (pidl2);
527 if(!pidl1)
529 pidlNew = ILClone(pidl2);
530 return pidlNew;
533 if(!pidl2)
535 pidlNew = ILClone(pidl1);
536 return pidlNew;
539 len1 = ILGetSize(pidl1)-2;
540 len2 = ILGetSize(pidl2);
541 pidlNew = SHAlloc(len1+len2);
543 if (pidlNew)
545 memcpy(pidlNew,pidl1,len1);
546 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
549 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
550 return pidlNew;
552 /*************************************************************************
553 * SHGetRealIDL [SHELL32.98]
555 * NOTES
557 LPITEMIDLIST WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl, DWORD z)
559 FIXME("sf=%p pidl=%p 0x%04lx\n",lpsf,pidl,z);
561 pdump (pidl);
562 return 0;
565 /*************************************************************************
566 * SHLogILFromFSIL [SHELL32.95]
568 * NOTES
569 * pild = CSIDL_DESKTOP ret = 0
570 * pild = CSIDL_DRIVES ret = 0
572 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
574 FIXME("(pidl=%p)\n",pidl);
576 pdump(pidl);
578 return 0;
581 /*************************************************************************
582 * ILGetSize [SHELL32.152]
583 * gets the byte size of an idlist including zero terminator (pidl)
585 * PARAMETERS
586 * pidl ITEMIDLIST
588 * RETURNS
589 * size of pidl
591 * NOTES
592 * exported by ordinal
594 DWORD WINAPI ILGetSize(LPITEMIDLIST pidl)
596 LPSHITEMID si = &(pidl->mkid);
597 DWORD len=0;
599 if (pidl)
600 { while (si->cb)
601 { len += si->cb;
602 si = (LPSHITEMID)(((LPBYTE)si)+si->cb);
604 len += 2;
606 TRACE("pidl=%p size=%lu\n",pidl, len);
607 return len;
610 /*************************************************************************
611 * ILGetNext [SHELL32.153]
612 * gets the next simple pidl of a complex pidl
614 * observed return values:
615 * null -> null
616 * desktop -> null
617 * simple pidl -> pointer to 0x0000 element
620 LPITEMIDLIST WINAPI ILGetNext(LPITEMIDLIST pidl)
622 WORD len;
624 TRACE("(pidl=%p)\n",pidl);
626 if(pidl)
628 len = pidl->mkid.cb;
629 if (len)
631 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
632 return pidl;
635 return NULL;
637 /*************************************************************************
638 * ILAppend [SHELL32.154]
640 * NOTES
641 * Adds the single item to the idlist indicated by pidl.
642 * if bEnd is 0, adds the item to the front of the list,
643 * otherwise adds the item to the end. (???)
644 * Destroys the passed in idlist! (???)
646 LPITEMIDLIST WINAPI ILAppend(LPITEMIDLIST pidl,LPCITEMIDLIST item,BOOL bEnd)
648 LPITEMIDLIST idlRet;
650 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
652 pdump (pidl);
653 pdump (item);
655 if (_ILIsDesktop(pidl))
657 idlRet = ILClone(item);
658 if (pidl)
659 SHFree (pidl);
660 return idlRet;
663 if (bEnd)
665 idlRet=ILCombine(pidl,item);
667 else
669 idlRet=ILCombine(item,pidl);
672 SHFree(pidl);
673 return idlRet;
675 /*************************************************************************
676 * ILFree [SHELL32.155]
678 * NOTES
679 * free_check_ptr - frees memory (if not NULL)
680 * allocated by SHMalloc allocator
681 * exported by ordinal
683 DWORD WINAPI ILFree(LPITEMIDLIST pidl)
685 TRACE("(pidl=0x%08lx)\n",(DWORD)pidl);
687 if(!pidl) return FALSE;
688 SHFree(pidl);
689 return TRUE;
691 /*************************************************************************
692 * ILGlobalFree [SHELL32.156]
695 void WINAPI ILGlobalFree( LPCITEMIDLIST pidl)
697 TRACE("%p\n",pidl);
699 if(!pidl) return;
700 pCOMCTL32_Free(pidl);
702 /*************************************************************************
703 * ILCreateFromPath [SHELL32.157]
706 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
708 LPITEMIDLIST pidlnew;
709 DWORD attributes = 0;
711 TRACE_(shell)("%s\n",path);
713 if (SUCCEEDED (SHILCreateFromPathA (path, &pidlnew, &attributes)))
714 return pidlnew;
715 return FALSE;
717 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
719 LPITEMIDLIST pidlnew;
720 DWORD attributes = 0;
722 TRACE_(shell)("%s\n",debugstr_w(path));
724 if (SUCCEEDED (SHILCreateFromPathW (path, &pidlnew, &attributes)))
725 return pidlnew;
726 return FALSE;
728 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
730 if ( VERSION_OsIsUnicode())
731 return ILCreateFromPathW (path);
732 return ILCreateFromPathA (path);
734 /*************************************************************************
735 * SHSimpleIDListFromPath [SHELL32.162]
737 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA (LPCSTR lpszPath)
739 LPITEMIDLIST pidl=NULL;
740 HANDLE hFile;
741 WIN32_FIND_DATAA stffile;
743 TRACE("path=%s\n", lpszPath);
745 if (!lpszPath) return NULL;
747 hFile = FindFirstFileA(lpszPath, &stffile);
749 if ( hFile != INVALID_HANDLE_VALUE )
751 if (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
753 pidl = _ILCreateFolder (&stffile);
755 else
757 pidl = _ILCreateValue (&stffile);
759 FindClose (hFile);
761 return pidl;
763 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW (LPCWSTR lpszPath)
765 char lpszTemp[MAX_PATH];
766 TRACE("path=%s\n",debugstr_w(lpszPath));
768 lstrcpynWtoA(lpszTemp, lpszPath, MAX_PATH);
770 return SHSimpleIDListFromPathA (lpszTemp);
773 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW (LPCVOID lpszPath)
775 if ( VERSION_OsIsUnicode())
776 return SHSimpleIDListFromPathW (lpszPath);
777 return SHSimpleIDListFromPathA (lpszPath);
780 /*************************************************************************
781 * SHGetSpecialFolderLocation [SHELL32.223]
783 * gets the folder locations from the registry and creates a pidl
784 * creates missing reg keys and directorys
786 * PARAMS
787 * hwndOwner [I]
788 * nFolder [I] CSIDL_xxxxx
789 * ppidl [O] PIDL of a special folder
792 HRESULT WINAPI SHGetSpecialFolderLocation(
793 HWND hwndOwner,
794 INT nFolder,
795 LPITEMIDLIST * ppidl)
797 CHAR szPath[MAX_PATH];
798 HRESULT hr = E_INVALIDARG;
800 TRACE_(shell)("(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
802 *ppidl = NULL;
804 if (ppidl)
806 switch (nFolder)
808 case CSIDL_DESKTOP:
809 *ppidl = _ILCreateDesktop();
810 hr = NOERROR;
811 break;
813 case CSIDL_DRIVES:
814 *ppidl = _ILCreateMyComputer();
815 hr = NOERROR;
816 break;
818 case CSIDL_NETWORK:
819 *ppidl = _ILCreateNetwork ();
820 hr = NOERROR;
821 break;
823 case CSIDL_CONTROLS:
824 *ppidl = _ILCreateControl ();
825 hr = NOERROR;
826 break;
828 case CSIDL_PRINTERS:
829 *ppidl = _ILCreatePrinter ();
830 hr = NOERROR;
831 break;
833 case CSIDL_BITBUCKET:
834 *ppidl = _ILCreateBitBucket ();
835 hr = NOERROR;
836 break;
838 default:
839 if (SHGetSpecialFolderPathA(hwndOwner, szPath, nFolder, TRUE))
841 DWORD attributes=0;
842 TRACE_(shell)("Value=%s\n",szPath);
843 hr = SHILCreateFromPathA(szPath, ppidl, &attributes);
848 TRACE_(shell)("-- (new pidl %p)\n",*ppidl);
849 return hr;
852 /*************************************************************************
853 * SHGetFolderLocation [SHELL32]
855 * NOTES
856 * the pidl can be a simple one. since we cant get the path out of the pidl
857 * we have to take all data from the pidl
859 HRESULT WINAPI SHGetFolderLocation(
860 HWND hwnd,
861 int csidl,
862 HANDLE hToken,
863 DWORD dwFlags,
864 LPITEMIDLIST *ppidl)
866 FIXME("0x%04x 0x%08x 0x%08x 0x%08lx %p\n",
867 hwnd, csidl, hToken, dwFlags, ppidl);
868 return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
871 /*************************************************************************
872 * SHGetDataFromIDListA [SHELL32.247]
874 * NOTES
875 * the pidl can be a simple one. since we cant get the path out of the pidl
876 * we have to take all data from the pidl
878 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
880 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
882 pdump(pidl);
883 if (!psf || !dest ) return E_INVALIDARG;
885 switch (nFormat)
887 case SHGDFIL_FINDDATA:
889 WIN32_FIND_DATAA * pfd = dest;
891 if ( len < sizeof (WIN32_FIND_DATAA)) return E_INVALIDARG;
893 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
894 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
895 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
896 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
897 lstrcpynA(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
898 lstrcpynA(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
900 return NOERROR;
902 case SHGDFIL_NETRESOURCE:
903 case SHGDFIL_DESCRIPTIONID:
904 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
905 break;
907 default:
908 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
911 return E_INVALIDARG;
913 /*************************************************************************
914 * SHGetDataFromIDListW [SHELL32.247]
917 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, LPVOID dest, int len)
919 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
921 pdump(pidl);
923 if (! psf || !dest ) return E_INVALIDARG;
925 switch (nFormat)
927 case SHGDFIL_FINDDATA:
929 WIN32_FIND_DATAW * pfd = dest;
931 if ( len < sizeof (WIN32_FIND_DATAW)) return E_INVALIDARG;
933 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
934 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
935 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
936 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
937 lstrcpynAtoW(pfd->cFileName,_ILGetTextPointer(pidl), MAX_PATH);
938 lstrcpynAtoW(pfd->cAlternateFileName,_ILGetSTextPointer(pidl), 14);
940 return NOERROR;
941 case SHGDFIL_NETRESOURCE:
942 case SHGDFIL_DESCRIPTIONID:
943 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
944 break;
946 default:
947 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
950 return E_INVALIDARG;
953 /*************************************************************************
954 * SHGetPathFromIDListA [SHELL32.261][NT 4.0: SHELL32.220]
956 * PARAMETERS
957 * pidl, [IN] pidl
958 * pszPath [OUT] path
960 * RETURNS
961 * path from a passed PIDL.
963 * NOTES
964 * NULL returns FALSE
965 * desktop pidl gives path to desktopdirectory back
966 * special pidls returning FALSE
968 * FIXME
969 * fnGetDisplayNameOf can return different types of OLEString
971 BOOL WINAPI SHGetPathFromIDListA (LPCITEMIDLIST pidl,LPSTR pszPath)
972 { STRRET str;
973 LPSHELLFOLDER shellfolder;
975 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
977 if (!pidl) return FALSE;
979 pdump(pidl);
981 if(_ILIsDesktop(pidl))
983 SHGetSpecialFolderPathA(0, pszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
985 else if (_ILIsSpecialFolder(ILFindLastID(pidl)))
987 /* we are somewhere in a special folder */
988 return FALSE;
990 else
992 if (SHGetDesktopFolder(&shellfolder)==S_OK)
994 IShellFolder_GetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&str);
995 StrRetToStrNA (pszPath, MAX_PATH, &str, pidl);
996 IShellFolder_Release(shellfolder);
999 TRACE_(shell)("-- (%s)\n",pszPath);
1001 return TRUE;
1003 /*************************************************************************
1004 * SHGetPathFromIDListW [SHELL32.262]
1006 BOOL WINAPI SHGetPathFromIDListW (LPCITEMIDLIST pidl,LPWSTR pszPath)
1007 { char sTemp[MAX_PATH];
1009 TRACE_(shell)("(pidl=%p)\n", pidl);
1011 SHGetPathFromIDListA (pidl, sTemp);
1012 lstrcpyAtoW(pszPath, sTemp);
1014 TRACE_(shell)("-- (%s)\n",debugstr_w(pszPath));
1016 return TRUE;
1019 /*************************************************************************
1020 * SHBindToParent [shell version 5.0]
1022 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1024 IShellFolder * psf;
1025 LPITEMIDLIST pidlChild, pidlParent;
1026 HRESULT hr=E_FAIL;
1028 TRACE_(shell)("pidl=%p\n", pidl);
1029 pdump(pidl);
1031 *ppv = NULL;
1032 if (ppidlLast) *ppidlLast = NULL;
1034 if (_ILIsPidlSimple(pidl))
1036 /* we are on desktop level */
1037 if (ppidlLast)
1038 *ppidlLast = ILClone(pidl);
1039 hr = SHGetDesktopFolder((IShellFolder**)ppv);
1041 else
1043 pidlChild = ILClone(ILFindLastID(pidl));
1044 pidlParent = ILClone(pidl);
1045 ILRemoveLastID(pidlParent);
1047 hr = SHGetDesktopFolder(&psf);
1049 if (SUCCEEDED(hr))
1050 hr = IShellFolder_BindToObject(psf, pidlParent, NULL, riid, ppv);
1052 if (SUCCEEDED(hr) && ppidlLast)
1053 *ppidlLast = pidlChild;
1054 else
1055 ILFree (pidlChild);
1057 SHFree (pidlParent);
1058 if (psf) IShellFolder_Release(psf);
1062 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08lx\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1063 return hr;
1066 /*************************************************************************
1067 * SHGetPathFromIDListAW [SHELL32.221][NT 4.0: SHELL32.219]
1069 BOOL WINAPI SHGetPathFromIDListAW(LPCITEMIDLIST pidl,LPVOID pszPath)
1071 TRACE_(shell)("(pidl=%p,%p)\n",pidl,pszPath);
1073 if (VERSION_OsIsUnicode())
1074 return SHGetPathFromIDListW(pidl,pszPath);
1075 return SHGetPathFromIDListA(pidl,pszPath);
1078 /**************************************************************************
1080 * internal functions
1082 * ### 1. section creating pidls ###
1084 *************************************************************************
1085 * _ILCreateDesktop()
1086 * _ILCreateIExplore()
1087 * _ILCreateMyComputer()
1088 * _ILCreateDrive()
1089 * _ILCreateFolder()
1090 * _ILCreateValue()
1092 LPITEMIDLIST _ILCreateDesktop()
1093 { TRACE("()\n");
1094 return _ILCreate(PT_DESKTOP, NULL, 0);
1097 LPITEMIDLIST _ILCreateMyComputer()
1098 { TRACE("()\n");
1099 return _ILCreate(PT_MYCOMP, &CLSID_MyComputer, sizeof(GUID));
1102 LPITEMIDLIST _ILCreateIExplore()
1103 { TRACE("()\n");
1104 return _ILCreate(PT_MYCOMP, &CLSID_Internet, sizeof(GUID));
1107 LPITEMIDLIST _ILCreateControl()
1108 { TRACE("()\n");
1109 return _ILCreate(PT_SPECIAL, &CLSID_ControlPanel, sizeof(GUID));
1112 LPITEMIDLIST _ILCreatePrinter()
1113 { TRACE("()\n");
1114 return _ILCreate(PT_SPECIAL, &CLSID_Printers, sizeof(GUID));
1117 LPITEMIDLIST _ILCreateNetwork()
1118 { TRACE("()\n");
1119 return _ILCreate(PT_MYCOMP, &CLSID_NetworkPlaces, sizeof(GUID));
1122 LPITEMIDLIST _ILCreateBitBucket()
1123 { TRACE("()\n");
1124 return _ILCreate(PT_MYCOMP, &CLSID_RecycleBin, sizeof(GUID));
1127 LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
1128 { char sTemp[4];
1129 lstrcpynA (sTemp,lpszNew,4);
1130 sTemp[2]='\\';
1131 sTemp[3]=0x00;
1132 TRACE("(%s)\n",sTemp);
1133 return _ILCreate(PT_DRIVE,(LPVOID)&sTemp[0],4);
1136 LPITEMIDLIST _ILCreateFolder( WIN32_FIND_DATAA * stffile )
1138 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1139 char * pbuff = buff;
1140 ULONG len, len1;
1141 LPITEMIDLIST pidl;
1143 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1145 /* prepare buffer with both names */
1146 len = strlen (stffile->cFileName) + 1;
1147 memcpy (pbuff, stffile->cFileName, len);
1148 pbuff += len;
1150 if (stffile->cAlternateFileName)
1152 len1 = strlen (stffile->cAlternateFileName)+1;
1153 memcpy (pbuff, stffile->cAlternateFileName, len1);
1155 else
1157 len1 = 1;
1158 *pbuff = 0x00;
1161 pidl = _ILCreate(PT_FOLDER, (LPVOID)buff, len + len1);
1163 /* set attributes */
1164 if (pidl)
1166 LPPIDLDATA pData;
1167 pData = _ILGetDataPointer(pidl);
1168 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1169 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1170 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1173 return pidl;
1176 LPITEMIDLIST _ILCreateValue(WIN32_FIND_DATAA * stffile)
1178 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1179 char * pbuff = buff;
1180 ULONG len, len1;
1181 LPITEMIDLIST pidl;
1183 TRACE("(%s, %s)\n",stffile->cAlternateFileName, stffile->cFileName);
1185 /* prepare buffer with both names */
1186 len = strlen (stffile->cFileName) + 1;
1187 memcpy (pbuff, stffile->cFileName, len);
1188 pbuff += len;
1190 if (stffile->cAlternateFileName)
1192 len1 = strlen (stffile->cAlternateFileName)+1;
1193 memcpy (pbuff, stffile->cAlternateFileName, len1);
1195 else
1197 len1 = 1;
1198 *pbuff = 0x00;
1201 pidl = _ILCreate(PT_VALUE, (LPVOID)buff, len + len1);
1203 /* set attributes */
1204 if (pidl)
1206 LPPIDLDATA pData;
1207 pData = _ILGetDataPointer(pidl);
1208 FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
1209 pData->u.folder.dwFileSize = stffile->nFileSizeLow;
1210 pData->u.folder.uFileAttribs=stffile->dwFileAttributes;
1213 return pidl;
1216 LPITEMIDLIST _ILCreateSpecial(LPCSTR szGUID)
1218 IID iid;
1219 CLSIDFromString16(szGUID,&iid);
1220 return _ILCreate(PT_MYCOMP, &iid, sizeof(IID));
1223 /**************************************************************************
1224 * _ILCreate()
1225 * Creates a new PIDL
1226 * type = PT_DESKTOP | PT_DRIVE | PT_FOLDER | PT_VALUE
1227 * pIn = data
1228 * uInSize = size of data (raw)
1231 LPITEMIDLIST _ILCreate(PIDLTYPE type, LPCVOID pIn, UINT16 uInSize)
1232 { LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
1233 LPPIDLDATA pData;
1234 UINT16 uSize = 0;
1235 LPSTR pszDest;
1237 TRACE("(0x%02x %p %i)\n",type,pIn,uInSize);
1239 switch (type)
1240 { case PT_DESKTOP:
1241 uSize = 0;
1242 pidlOut = SHAlloc(uSize + 2);
1243 pidlOut->mkid.cb = uSize;
1244 TRACE("- create Desktop\n");
1245 break;
1247 case PT_MYCOMP:
1248 uSize = 2 + 2 + sizeof(GUID);
1249 pidlOut = SHAlloc(uSize + 2);
1250 ZeroMemory(pidlOut, uSize + 2);
1251 pidlOut->mkid.cb = uSize;
1252 pData =_ILGetDataPointer(pidlOut);
1253 pData->type = type;
1254 memcpy(&(pData->u.mycomp.guid), pIn, uInSize);
1255 TRACE("- create GUID-pidl\n");
1256 break;
1258 case PT_DRIVE:
1259 uSize = 2 + 23;
1260 pidlOut = SHAlloc(uSize + 2);
1261 ZeroMemory(pidlOut, uSize + 2);
1262 pidlOut->mkid.cb = uSize;
1263 pData =_ILGetDataPointer(pidlOut);
1264 pData->type = type;
1265 pszDest = _ILGetTextPointer(pidlOut);
1266 memcpy(pszDest, pIn, uInSize);
1267 TRACE("- create Drive: %s\n",debugstr_a(pszDest));
1268 break;
1270 case PT_FOLDER:
1271 case PT_VALUE:
1272 uSize = 2 + 12 + uInSize;
1273 pidlOut = SHAlloc(uSize + 2);
1274 ZeroMemory(pidlOut, uSize + 2);
1275 pidlOut->mkid.cb = uSize;
1276 pData =_ILGetDataPointer(pidlOut);
1277 pData->type = type;
1278 pszDest = _ILGetTextPointer(pidlOut);
1279 memcpy(pszDest, pIn, uInSize);
1280 TRACE("- create Value: %s\n",debugstr_a(pszDest));
1281 break;
1284 pidlTemp = ILGetNext(pidlOut);
1285 if (pidlTemp)
1286 pidlTemp->mkid.cb = 0x00;
1288 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, uSize);
1289 return pidlOut;
1292 /**************************************************************************
1293 * _ILGetDrive()
1295 * Gets the text for the drive eg. 'c:\'
1297 * RETURNS
1298 * strlen (lpszText)
1300 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT16 uSize)
1301 { TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1303 if(_ILIsMyComputer(pidl))
1304 pidl = ILGetNext(pidl);
1306 if (pidl && _ILIsDrive(pidl))
1307 return _ILSimpleGetText(pidl, pOut, uSize);
1309 return 0;
1312 /**************************************************************************
1314 * ### 2. section testing pidls ###
1316 **************************************************************************
1317 * _ILIsDesktop()
1318 * _ILIsMyComputer()
1319 * _ILIsSpecialFolder()
1320 * _ILIsDrive()
1321 * _ILIsFolder()
1322 * _ILIsValue()
1323 * _ILIsPidlSimple()
1325 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1326 { TRACE("(%p)\n",pidl);
1327 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
1330 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1332 REFIID iid = _ILGetGUIDPointer(pidl);
1334 TRACE("(%p)\n",pidl);
1336 if (iid)
1337 return IsEqualIID(iid, &CLSID_MyComputer);
1338 return FALSE;
1341 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1343 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1344 TRACE("(%p)\n",pidl);
1345 return (pidl && ( (lpPData && (PT_MYCOMP== lpPData->type || PT_SPECIAL== lpPData->type)) ||
1346 (pidl && pidl->mkid.cb == 0x00)
1350 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1351 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1352 TRACE("(%p)\n",pidl);
1353 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1354 PT_DRIVE1 == lpPData->type ||
1355 PT_DRIVE2 == lpPData->type ||
1356 PT_DRIVE3 == lpPData->type));
1359 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1360 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1361 TRACE("(%p)\n",pidl);
1362 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1365 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1366 { LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1367 TRACE("(%p)\n",pidl);
1368 return (pidl && lpPData && PT_VALUE == lpPData->type);
1371 /**************************************************************************
1372 * _ILIsPidlSimple
1374 BOOL _ILIsPidlSimple ( LPCITEMIDLIST pidl)
1376 BOOL ret = TRUE;
1378 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1380 WORD len = pidl->mkid.cb;
1381 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((LPBYTE)pidl) + len );
1382 if (pidlnext->mkid.cb)
1383 ret = FALSE;
1386 TRACE("%s\n", ret ? "Yes" : "No");
1387 return ret;
1390 /**************************************************************************
1392 * ### 3. section getting values from pidls ###
1395 /**************************************************************************
1396 * _ILSimpleGetText
1398 * gets the text for the first item in the pidl (eg. simple pidl)
1400 * returns the lenght of the string
1402 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1404 DWORD dwReturn=0;
1405 LPSTR szSrc;
1406 GUID const * riid;
1407 char szTemp[MAX_PATH];
1409 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1411 if (!pidl) return 0;
1413 if (szOut)
1414 *szOut = 0;
1416 if (_ILIsDesktop(pidl))
1418 /* desktop */
1419 if (HCR_GetClassName(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1421 if (szOut)
1422 lstrcpynA(szOut, szTemp, uOutSize);
1424 dwReturn = strlen (szTemp);
1427 else if (( szSrc = _ILGetTextPointer(pidl) ))
1429 /* filesystem */
1430 if (szOut)
1431 lstrcpynA(szOut, szSrc, uOutSize);
1433 dwReturn = strlen(szSrc);
1435 else if (( riid = _ILGetGUIDPointer(pidl) ))
1437 /* special folder */
1438 if ( HCR_GetClassName(riid, szTemp, MAX_PATH) )
1440 if (szOut)
1441 lstrcpynA(szOut, szTemp, uOutSize);
1443 dwReturn = strlen (szTemp);
1446 else
1448 ERR("-- no text\n");
1451 TRACE("-- (%p=%s 0x%08lx)\n",szOut,(char*)szOut,dwReturn);
1452 return dwReturn;
1455 /**************************************************************************
1457 * ### 4. getting pointers to parts of pidls ###
1459 **************************************************************************
1460 * _ILGetDataPointer()
1462 LPPIDLDATA _ILGetDataPointer(LPITEMIDLIST pidl)
1464 if(pidl && pidl->mkid.cb != 0x00)
1465 return (LPPIDLDATA) &(pidl->mkid.abID);
1466 return NULL;
1469 /**************************************************************************
1470 * _ILGetTextPointer()
1471 * gets a pointer to the long filename string stored in the pidl
1473 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
1474 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1476 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1478 if (pdata)
1480 switch (pdata->type)
1482 case PT_MYCOMP:
1483 case PT_SPECIAL:
1484 return NULL;
1486 case PT_DRIVE:
1487 case PT_DRIVE1:
1488 case PT_DRIVE2:
1489 case PT_DRIVE3:
1490 return (LPSTR)&(pdata->u.drive.szDriveName);
1492 case PT_FOLDER:
1493 case PT_FOLDER1:
1494 case PT_VALUE:
1495 case PT_IESPECIAL:
1496 return (LPSTR)&(pdata->u.file.szNames);
1498 case PT_WORKGRP:
1499 case PT_COMP:
1500 case PT_NETWORK:
1501 case PT_SHARE:
1502 return (LPSTR)&(pdata->u.network.szNames);
1505 return NULL;
1508 /**************************************************************************
1509 * _ILGetSTextPointer()
1510 * gets a pointer to the short filename string stored in the pidl
1512 LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
1513 {/* TRACE(pidl,"(pidl%p)\n", pidl);*/
1515 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1517 if (pdata)
1519 switch (pdata->type)
1521 case PT_FOLDER:
1522 case PT_VALUE:
1523 case PT_IESPECIAL:
1524 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
1526 case PT_WORKGRP:
1527 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
1530 return NULL;
1533 /**************************************************************************
1534 * _ILGetGUIDPointer()
1536 * returns reference to guid stored in some pidls
1538 REFIID _ILGetGUIDPointer(LPCITEMIDLIST pidl)
1540 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1542 if (pdata)
1544 switch (pdata->type)
1546 case PT_SPECIAL:
1547 case PT_MYCOMP:
1548 return (REFIID) &(pdata->u.mycomp.guid);
1551 return NULL;
1554 /*************************************************************************
1555 * _ILGetFileDateTime
1557 * Given the ItemIdList, get the FileTime
1559 * PARAMS
1560 * pidl [I] The ItemIDList
1561 * pFt [I] the resulted FILETIME of the file
1563 * RETURNS
1564 * True if Successful
1566 * NOTES
1569 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
1571 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1573 if(! pdata) return FALSE;
1575 switch (pdata->type)
1577 case PT_FOLDER:
1578 DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
1579 break;
1580 case PT_VALUE:
1581 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
1582 break;
1583 default:
1584 return FALSE;
1586 return TRUE;
1589 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1591 FILETIME ft,lft;
1592 SYSTEMTIME time;
1594 if (! _ILGetFileDateTime( pidl, &ft )) return FALSE;
1596 FileTimeToLocalFileTime(&ft, &lft);
1597 FileTimeToSystemTime (&lft, &time);
1598 return GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
1601 /*************************************************************************
1602 * _ILGetFileSize
1604 * Given the ItemIdList, get the FileSize
1606 * PARAMS
1607 * pidl [I] The ItemIDList
1608 * pOut [I] The buffer to save the result
1609 * uOutsize [I] The size of the buffer
1611 * RETURNS
1612 * The FileSize
1614 * NOTES
1615 * pOut can be null when no string is needed
1618 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1620 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
1621 DWORD dwSize;
1623 if(! pdata) return 0;
1625 switch (pdata->type)
1627 case PT_VALUE:
1628 dwSize = pdata->u.file.dwFileSize;
1629 if (pOut) StrFormatByteSizeA(dwSize, pOut, uOutSize);
1630 return dwSize;
1632 if (pOut) *pOut = 0x00;
1633 return 0;
1636 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1638 char szTemp[MAX_PATH];
1639 const char * pPoint;
1640 LPITEMIDLIST pidlTemp=pidl;
1642 TRACE("pidl=%p\n",pidl);
1644 if (!pidl) return FALSE;
1646 pidlTemp = ILFindLastID(pidl);
1648 if (!_ILIsValue(pidlTemp)) return FALSE;
1649 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH)) return FALSE;
1651 pPoint = PathFindExtensionA(szTemp);
1653 if (! *pPoint) return FALSE;
1655 pPoint++;
1656 lstrcpynA(pOut, pPoint, uOutSize);
1657 TRACE("%s\n",pOut);
1659 return TRUE;
1662 /*************************************************************************
1663 * _ILGetFileType
1665 * Given the ItemIdList, get the file type description
1667 * PARAMS
1668 * pidl [I] The ItemIDList (simple)
1669 * pOut [I] The buffer to save the result
1670 * uOutsize [I] The size of the buffer
1672 * RETURNS
1673 * nothing
1675 * NOTES
1676 * This function copies as much as possible into the buffer.
1678 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1680 if(_ILIsValue(pidl))
1682 char sTemp[64];
1683 if(uOutSize > 0)
1685 pOut[0] = 0;
1687 if (_ILGetExtension (pidl, sTemp, 64))
1689 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
1690 && HCR_MapTypeToValue(sTemp, pOut, uOutSize, FALSE )))
1692 lstrcpynA (pOut, sTemp, uOutSize - 6);
1693 strcat (pOut, "-file");
1697 else
1699 lstrcpynA(pOut, "Folder", uOutSize);
1703 /*************************************************************************
1704 * _ILGetFileAttributes
1706 * Given the ItemIdList, get the Attrib string format
1708 * PARAMS
1709 * pidl [I] The ItemIDList
1710 * pOut [I] The buffer to save the result
1711 * uOutsize [I] The size of the Buffer
1713 * RETURNS
1714 * Attributes
1716 * FIXME
1717 * return value 0 in case of error is a valid return value
1720 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
1722 LPPIDLDATA pData =_ILGetDataPointer(pidl);
1723 WORD wAttrib = 0;
1724 int i;
1726 if(! pData) return 0;
1728 switch(pData->type)
1730 case PT_FOLDER:
1731 wAttrib = pData->u.folder.uFileAttribs;
1732 break;
1733 case PT_VALUE:
1734 wAttrib = pData->u.file.uFileAttribs;
1735 break;
1738 if(uOutSize >= 6)
1740 i=0;
1741 if(wAttrib & FILE_ATTRIBUTE_READONLY)
1743 pOut[i++] = 'R';
1745 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
1747 pOut[i++] = 'H';
1749 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
1751 pOut[i++] = 'S';
1753 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
1755 pOut[i++] = 'A';
1757 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
1759 pOut[i++] = 'C';
1761 pOut[i] = 0x00;
1763 return wAttrib;
1766 /*************************************************************************
1767 * ILFreeaPidl
1769 * free a aPidl struct
1771 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
1773 int i;
1775 if(apidl)
1777 for(i = 0; i < cidl; i++) SHFree(apidl[i]);
1778 SHFree(apidl);
1782 /*************************************************************************
1783 * ILCopyaPidl
1785 * copys a aPidl struct
1787 LPITEMIDLIST * _ILCopyaPidl(LPITEMIDLIST * apidlsrc, UINT cidl)
1789 int i;
1790 LPITEMIDLIST * apidldest = (LPITEMIDLIST*)SHAlloc(cidl * sizeof(LPITEMIDLIST));
1791 if(!apidlsrc) return NULL;
1793 for(i = 0; i < cidl; i++)
1794 apidldest[i] = ILClone(apidlsrc[i]);
1796 return apidldest;
1799 /*************************************************************************
1800 * _ILCopyCidaToaPidl
1802 * creates aPidl from CIDA
1804 LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPCIDA cida)
1806 int i;
1807 LPITEMIDLIST * dst = (LPITEMIDLIST*)SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
1809 if(!dst) return NULL;
1811 if (pidl)
1812 *pidl = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[0]]));
1814 for(i = 0; i < cida->cidl; i++)
1815 dst[i] = ILClone((LPITEMIDLIST)(&((LPBYTE)cida)[cida->aoffset[i + 1]]));
1817 return dst;