Implemented NtCreatelFile using the new symlink scheme.
[wine] / dlls / shell32 / shfldr_mycomp.c
1
2 /*
3  *      Virtual Workplace folder
4  *
5  *      Copyright 1997                  Marcus Meissner
6  *      Copyright 1998, 1999, 2002      Juergen Schmied
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
37
38 #include "wingdi.h"
39 #include "pidl.h"
40 #include "shlguid.h"
41 #include "enumidlist.h"
42 #include "undocshell.h"
43 #include "shell32_main.h"
44 #include "shresdef.h"
45 #include "shlwapi.h"
46 #include "shellfolder.h"
47 #include "wine/debug.h"
48 #include "debughlp.h"
49 #include "shfldr.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL (shell);
52
53 /***********************************************************************
54 *   IShellFolder implementation
55 */
56
57 typedef struct {
58     ICOM_VFIELD (IShellFolder2);
59     DWORD ref;
60       ICOM_VTABLE (IPersistFolder2) * lpVtblPersistFolder2;
61
62     /* both paths are parsible from the desktop */
63     LPITEMIDLIST pidlRoot;      /* absolute pidl */
64     int dwAttributes;           /* attributes returned by GetAttributesOf FIXME: use it */
65 } IGenericSFImpl;
66
67 static struct ICOM_VTABLE (IShellFolder2) vt_ShellFolder2;
68 static struct ICOM_VTABLE (IPersistFolder2) vt_PersistFolder2;
69
70 #define _IPersistFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpVtblPersistFolder2)))
71 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
72
73 /*
74   converts This to a interface pointer
75 */
76 #define _IUnknown_(This)        (IUnknown*)&(This->lpVtbl)
77 #define _IShellFolder_(This)    (IShellFolder*)&(This->lpVtbl)
78 #define _IShellFolder2_(This)   (IShellFolder2*)&(This->lpVtbl)
79
80 #define _IPersist_(This)        (IPersist*)&(This->lpVtblPersistFolder2)
81 #define _IPersistFolder_(This)  (IPersistFolder*)&(This->lpVtblPersistFolder2)
82 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
83
84 /***********************************************************************
85 *   IShellFolder [MyComputer] implementation
86 */
87
88 static shvheader MyComputerSFHeader[] = {
89     {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
90     {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
91     {IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
92     {IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
93 };
94
95 #define MYCOMPUTERSHELLVIEWCOLUMNS 4
96
97 /**************************************************************************
98 *       ISF_MyComputer_Constructor
99 */
100 HRESULT WINAPI ISF_MyComputer_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
101 {
102     IGenericSFImpl *sf;
103
104     TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
105
106     if (!ppv)
107         return E_POINTER;
108     if (pUnkOuter)
109         return CLASS_E_NOAGGREGATION;
110
111     sf = (IGenericSFImpl *) LocalAlloc (GMEM_ZEROINIT, sizeof (IGenericSFImpl));
112     if (!sf)
113         return E_OUTOFMEMORY;
114
115     sf->ref = 0;
116     sf->lpVtbl = &vt_ShellFolder2;
117     sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
118     sf->pidlRoot = _ILCreateMyComputer ();      /* my qualified pidl */
119
120     if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
121         IUnknown_Release (_IUnknown_ (sf));
122         return E_NOINTERFACE;
123     }
124
125     TRACE ("--(%p)\n", sf);
126     return S_OK;
127 }
128
129 /**************************************************************************
130  *      ISF_MyComputer_fnQueryInterface
131  *
132  * NOTES supports not IPersist/IPersistFolder
133  */
134 static HRESULT WINAPI ISF_MyComputer_fnQueryInterface (IShellFolder2 * iface, REFIID riid, LPVOID * ppvObj)
135 {
136     ICOM_THIS (IGenericSFImpl, iface);
137
138     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
139
140     *ppvObj = NULL;
141
142     if (IsEqualIID (riid, &IID_IUnknown) ||
143         IsEqualIID (riid, &IID_IShellFolder) || IsEqualIID (riid, &IID_IShellFolder2)) {
144         *ppvObj = This;
145     } else if (IsEqualIID (riid, &IID_IPersist) ||
146                IsEqualIID (riid, &IID_IPersistFolder) || IsEqualIID (riid, &IID_IPersistFolder2)) {
147         *ppvObj = _IPersistFolder2_ (This);
148     }
149
150     if (*ppvObj) {
151         IUnknown_AddRef ((IUnknown *) (*ppvObj));
152         TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
153         return S_OK;
154     }
155     TRACE ("-- Interface: E_NOINTERFACE\n");
156     return E_NOINTERFACE;
157 }
158
159 static ULONG WINAPI ISF_MyComputer_fnAddRef (IShellFolder2 * iface)
160 {
161     ICOM_THIS (IGenericSFImpl, iface);
162
163     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
164
165     return ++(This->ref);
166 }
167
168 static ULONG WINAPI ISF_MyComputer_fnRelease (IShellFolder2 * iface)
169 {
170     ICOM_THIS (IGenericSFImpl, iface);
171
172     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
173
174     if (!--(This->ref)) {
175         TRACE ("-- destroying IShellFolder(%p)\n", This);
176         if (This->pidlRoot)
177             SHFree (This->pidlRoot);
178         LocalFree ((HLOCAL) This);
179         return 0;
180     }
181     return This->ref;
182 }
183
184 /**************************************************************************
185 *       ISF_MyComputer_fnParseDisplayName
186 */
187 static HRESULT WINAPI
188 ISF_MyComputer_fnParseDisplayName (IShellFolder2 * iface,
189                                    HWND hwndOwner,
190                                    LPBC pbc,
191                                    LPOLESTR lpszDisplayName,
192                                    DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
193 {
194     ICOM_THIS (IGenericSFImpl, iface);
195
196     HRESULT hr = E_INVALIDARG;
197     LPCWSTR szNext = NULL;
198     WCHAR szElement[MAX_PATH];
199     CHAR szTempA[MAX_PATH];
200     LPITEMIDLIST pidlTemp = NULL;
201     CLSID clsid;
202
203     TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
204            This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes);
205
206     *ppidl = 0;
207     if (pchEaten)
208         *pchEaten = 0;          /* strange but like the original */
209
210     /* handle CLSID paths */
211     if (lpszDisplayName[0] == ':' && lpszDisplayName[1] == ':') {
212         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
213         TRACE ("-- element: %s\n", debugstr_w (szElement));
214         SHCLSIDFromStringW (szElement + 2, &clsid);
215         pidlTemp = _ILCreateGuid (PT_GUID, &clsid);
216     }
217     /* do we have an absolute path name ? */
218     else if (PathGetDriveNumberW (lpszDisplayName) >= 0 && lpszDisplayName[2] == (WCHAR) '\\') {
219         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
220         WideCharToMultiByte (CP_ACP, 0, szElement, -1, szTempA, MAX_PATH, NULL, NULL);
221         pidlTemp = _ILCreateDrive (szTempA);
222     }
223
224     if (szNext && *szNext) {
225         hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
226     } else {
227         if (pdwAttributes && *pdwAttributes) {
228             SHELL32_GetItemAttributes (_IShellFolder_ (This), pidlTemp, pdwAttributes);
229         }
230         hr = S_OK;
231     }
232
233     *ppidl = pidlTemp;
234
235     TRACE ("(%p)->(-- ret=0x%08lx)\n", This, hr);
236
237     return hr;
238 }
239
240 /**************************************************************************
241  *  CreateMyCompEnumList()
242  */
243 static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
244 {
245     BOOL ret = TRUE;
246
247     TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
248
249     /*enumerate the folders*/
250     if(dwFlags & SHCONTF_FOLDERS)
251     {
252         CHAR szDriveName[] = "A:\\";
253         DWORD dwDrivemap = GetLogicalDrives();
254         HKEY hkey;
255
256         while (ret && szDriveName[0]<='Z')
257         {
258             if(dwDrivemap & 0x00000001L)
259                 ret = AddToEnumList(list, _ILCreateDrive(szDriveName));
260             szDriveName[0]++;
261             dwDrivemap = dwDrivemap >> 1;
262         }
263
264         TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
265         if (ret && !RegOpenKeyExA(HKEY_LOCAL_MACHINE,
266          "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace",
267          0, KEY_READ, &hkey))
268         {
269             char iid[50];
270             int i=0;
271
272             while (ret)
273             {
274                 DWORD size = sizeof (iid);
275                 LONG apiRet = RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL,
276                  NULL);
277
278                 if (ERROR_SUCCESS == apiRet)
279                 {
280                     /* FIXME: shell extensions, shouldn't the type be
281                      * PT_SHELLEXT? */
282                     ret = AddToEnumList(list, _ILCreateGuidFromStrA(iid));
283                     i++;
284                 }
285                 else if (ERROR_NO_MORE_ITEMS == apiRet)
286                     break;
287                 else
288                     ret = FALSE;
289             }
290             RegCloseKey(hkey);
291         }
292     }
293     return ret;
294 }
295
296 /**************************************************************************
297 *               ISF_MyComputer_fnEnumObjects
298 */
299 static HRESULT WINAPI
300 ISF_MyComputer_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
301 {
302     ICOM_THIS (IGenericSFImpl, iface);
303
304     TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
305
306     *ppEnumIDList = IEnumIDList_Constructor();
307     if (*ppEnumIDList)
308         CreateMyCompEnumList(*ppEnumIDList, dwFlags);
309
310     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
311
312     return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
313 }
314
315 /**************************************************************************
316 *               ISF_MyComputer_fnBindToObject
317 */
318 static HRESULT WINAPI
319 ISF_MyComputer_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
320                                LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
321 {
322     ICOM_THIS (IGenericSFImpl, iface);
323
324     TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
325
326     return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
327 }
328
329 /**************************************************************************
330 *       ISF_MyComputer_fnBindToStorage
331 */
332 static HRESULT WINAPI
333 ISF_MyComputer_fnBindToStorage (IShellFolder2 * iface,
334                                 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
335 {
336     ICOM_THIS (IGenericSFImpl, iface);
337
338     FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
339
340     *ppvOut = NULL;
341     return E_NOTIMPL;
342 }
343
344 /**************************************************************************
345 *       ISF_MyComputer_fnCompareIDs
346 */
347
348 static HRESULT WINAPI
349 ISF_MyComputer_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
350 {
351     ICOM_THIS (IGenericSFImpl, iface);
352
353     int nReturn;
354
355     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
356     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
357     TRACE ("-- %i\n", nReturn);
358     return nReturn;
359 }
360
361 /**************************************************************************
362 *       ISF_MyComputer_fnCreateViewObject
363 */
364 static HRESULT WINAPI
365 ISF_MyComputer_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
366 {
367     ICOM_THIS (IGenericSFImpl, iface);
368
369     LPSHELLVIEW pShellView;
370     HRESULT hr = E_INVALIDARG;
371
372     TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid), ppvOut);
373
374     if (ppvOut) {
375         *ppvOut = NULL;
376
377         if (IsEqualIID (riid, &IID_IDropTarget)) {
378             WARN ("IDropTarget not implemented\n");
379             hr = E_NOTIMPL;
380         } else if (IsEqualIID (riid, &IID_IContextMenu)) {
381             WARN ("IContextMenu not implemented\n");
382             hr = E_NOTIMPL;
383         } else if (IsEqualIID (riid, &IID_IShellView)) {
384             pShellView = IShellView_Constructor ((IShellFolder *) iface);
385             if (pShellView) {
386                 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
387                 IShellView_Release (pShellView);
388             }
389         }
390     }
391     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
392     return hr;
393 }
394
395 /**************************************************************************
396 *  ISF_MyComputer_fnGetAttributesOf
397 */
398 static HRESULT WINAPI
399 ISF_MyComputer_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
400 {
401     ICOM_THIS (IGenericSFImpl, iface);
402
403     HRESULT hr = S_OK;
404
405     TRACE ("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
406
407     if ((!cidl) || (!apidl) || (!rgfInOut))
408         return E_INVALIDARG;
409
410     while (cidl > 0 && *apidl) {
411         pdump (*apidl);
412         SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
413         apidl++;
414         cidl--;
415     }
416
417     TRACE ("-- result=0x%08lx\n", *rgfInOut);
418     return hr;
419 }
420
421 /**************************************************************************
422 *       ISF_MyComputer_fnGetUIObjectOf
423 *
424 * PARAMETERS
425 *  HWND           hwndOwner, //[in ] Parent window for any output
426 *  UINT           cidl,      //[in ] array size
427 *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
428 *  REFIID         riid,      //[in ] Requested Interface
429 *  UINT*          prgfInOut, //[   ] reserved
430 *  LPVOID*        ppvObject) //[out] Resulting Interface
431 *
432 */
433 static HRESULT WINAPI
434 ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface,
435                                 HWND hwndOwner,
436                                 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
437 {
438     ICOM_THIS (IGenericSFImpl, iface);
439
440     LPITEMIDLIST pidl;
441     IUnknown *pObj = NULL;
442     HRESULT hr = E_INVALIDARG;
443
444     TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
445            This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
446
447     if (ppvOut) {
448         *ppvOut = NULL;
449
450         if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
451             pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
452             hr = S_OK;
453         } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
454             pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
455             hr = S_OK;
456         } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
457             pidl = ILCombine (This->pidlRoot, apidl[0]);
458             pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
459             SHFree (pidl);
460             hr = S_OK;
461         } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
462             pidl = ILCombine (This->pidlRoot, apidl[0]);
463             pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
464             SHFree (pidl);
465             hr = S_OK;
466         } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
467             hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
468         } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
469                                 && (cidl == 1)) {
470             pidl = ILCombine (This->pidlRoot, apidl[0]);
471             hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
472             SHFree (pidl);
473         } else {
474             hr = E_NOINTERFACE;
475         }
476
477         if (SUCCEEDED(hr) && !pObj)
478             hr = E_OUTOFMEMORY;
479
480         *ppvOut = pObj;
481     }
482     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
483     return hr;
484 }
485
486 /**************************************************************************
487 *       ISF_MyComputer_fnGetDisplayNameOf
488 */
489 static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
490 {
491     ICOM_THIS (IGenericSFImpl, iface);
492
493     char szPath[MAX_PATH],
494       szDrive[18];
495     int len = 0;
496     BOOL bSimplePidl;
497     HRESULT hr = S_OK;
498
499     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
500     pdump (pidl);
501
502     if (!strRet)
503         return E_INVALIDARG;
504
505     szPath[0] = 0x00;
506     szDrive[0] = 0x00;
507
508     bSimplePidl = _ILIsPidlSimple (pidl);
509
510     if (!pidl->mkid.cb) {
511         /* parsing name like ::{...} */
512         lstrcpyA (szPath, "::");
513         SHELL32_GUIDToStringA(&CLSID_MyComputer, &szPath[2]);
514     } else if (_ILIsSpecialFolder (pidl)) {
515         /* take names of special folders only if its only this folder */
516         if (bSimplePidl) {
517             GUID const *clsid;
518
519             if ((clsid = _ILGetGUIDPointer (pidl))) {
520                 if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) {
521                     int bWantsForParsing;
522
523                     /*
524                      * we can only get a filesystem path from a shellfolder if the value WantsFORPARSING in
525                      * CLSID\\{...}\\shellfolder exists
526                      * exception: the MyComputer folder has this keys not but like any filesystem backed
527                      *            folder it needs these behaviour
528                      */
529                     /* get the "WantsFORPARSING" flag from the registry */
530                     char szRegPath[100];
531
532                     lstrcpyA (szRegPath, "CLSID\\");
533                     SHELL32_GUIDToStringA (clsid, &szRegPath[6]);
534                     lstrcatA (szRegPath, "\\shellfolder");
535                     bWantsForParsing =
536                         (ERROR_SUCCESS ==
537                          SHGetValueA (HKEY_CLASSES_ROOT, szRegPath, "WantsFORPARSING", NULL, NULL, NULL));
538
539                     if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && bWantsForParsing) {
540                         /* we need the filesystem path to the destination folder. Only the folder itself can know it */
541                         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, szPath, MAX_PATH);
542                     } else {
543                         LPSTR p;
544
545                         /* parsing name like ::{...} */
546                         p = lstrcpyA(szPath, "::") + 2;
547                         p += SHELL32_GUIDToStringA(&CLSID_MyComputer, p);
548
549                         lstrcatA(p, "\\::");
550                         p += 3;
551                         SHELL32_GUIDToStringA(clsid, p);
552                     }
553                 } else {
554                     /* user friendly name */
555                     HCR_GetClassNameA (clsid, szPath, MAX_PATH);
556                 }
557             } else
558                 _ILSimpleGetText (pidl, szPath, MAX_PATH);      /* append my own path */
559         } else {
560             FIXME ("special folder\n");
561         }
562     } else {
563         if (!_ILIsDrive (pidl)) {
564             ERR ("Wrong pidl type\n");
565             return E_INVALIDARG;
566         }
567
568         _ILSimpleGetText (pidl, szPath, MAX_PATH);      /* append my own path */
569
570         /* long view "lw_name (C:)" */
571         if (bSimplePidl && !(dwFlags & SHGDN_FORPARSING)) {
572             DWORD dwVolumeSerialNumber,
573               dwMaximumComponetLength,
574               dwFileSystemFlags;
575
576             GetVolumeInformationA (szPath, szDrive, sizeof (szDrive) - 6, &dwVolumeSerialNumber,
577                                    &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
578             strcat (szDrive, " (");
579             strncat (szDrive, szPath, 2);
580             strcat (szDrive, ")");
581             strcpy (szPath, szDrive);
582         }
583     }
584
585     if (!bSimplePidl) {         /* go deeper if needed */
586         PathAddBackslashA (szPath);
587         len = strlen (szPath);
588
589         hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags | SHGDN_INFOLDER, szPath + len, MAX_PATH - len);
590     }
591
592     if (SUCCEEDED (hr)) {
593         strRet->uType = STRRET_CSTR;
594         lstrcpynA (strRet->u.cStr, szPath, MAX_PATH);
595     }
596
597     TRACE ("-- (%p)->(%s)\n", This, szPath);
598     return hr;
599 }
600
601 /**************************************************************************
602 *  ISF_MyComputer_fnSetNameOf
603 *  Changes the name of a file object or subfolder, possibly changing its item
604 *  identifier in the process.
605 *
606 * PARAMETERS
607 *  HWND          hwndOwner,  //[in ] Owner window for output
608 *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
609 *  LPCOLESTR     lpszName,   //[in ] the items new display name
610 *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
611 *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
612 */
613 static HRESULT WINAPI ISF_MyComputer_fnSetNameOf (IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,    /*simple pidl */
614                                                   LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
615 {
616     ICOM_THIS (IGenericSFImpl, iface);
617     FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
618     return E_FAIL;
619 }
620
621 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultSearchGUID (IShellFolder2 * iface, GUID * pguid)
622 {
623     ICOM_THIS (IGenericSFImpl, iface);
624     FIXME ("(%p)\n", This);
625     return E_NOTIMPL;
626 }
627 static HRESULT WINAPI ISF_MyComputer_fnEnumSearches (IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
628 {
629     ICOM_THIS (IGenericSFImpl, iface);
630     FIXME ("(%p)\n", This);
631     return E_NOTIMPL;
632 }
633 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
634 {
635     ICOM_THIS (IGenericSFImpl, iface);
636
637     TRACE ("(%p)\n", This);
638
639     if (pSort) *pSort = 0;
640     if (pDisplay) *pDisplay = 0;
641     return S_OK;
642 }
643 static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
644 {
645     ICOM_THIS (IGenericSFImpl, iface);
646
647     TRACE ("(%p)\n", This);
648
649     if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS) return E_INVALIDARG;
650     *pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
651     return S_OK;
652 }
653 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
654 {
655     ICOM_THIS (IGenericSFImpl, iface);
656     FIXME ("(%p)\n", This);
657     return E_NOTIMPL;
658 }
659
660 /* FIXME: drive size >4GB is rolling over */
661 static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
662 {
663     ICOM_THIS (IGenericSFImpl, iface);
664     HRESULT hr;
665
666     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
667
668     if (!psd || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
669         return E_INVALIDARG;
670
671     if (!pidl) {
672         psd->fmt = MyComputerSFHeader[iColumn].fmt;
673         psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
674         psd->str.uType = STRRET_CSTR;
675         LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
676         return S_OK;
677     } else {
678         char szPath[MAX_PATH];
679         ULARGE_INTEGER ulBytes;
680
681         psd->str.u.cStr[0] = 0x00;
682         psd->str.uType = STRRET_CSTR;
683         switch (iColumn) {
684         case 0:         /* name */
685             hr = IShellFolder_GetDisplayNameOf (iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
686             break;
687         case 1:         /* type */
688             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
689             break;
690         case 2:         /* total size */
691             if (_ILIsDrive (pidl)) {
692                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
693                 GetDiskFreeSpaceExA (szPath, NULL, &ulBytes, NULL);
694                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
695             }
696             break;
697         case 3:         /* free size */
698             if (_ILIsDrive (pidl)) {
699                 _ILSimpleGetText (pidl, szPath, MAX_PATH);
700                 GetDiskFreeSpaceExA (szPath, &ulBytes, NULL, NULL);
701                 StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
702             }
703             break;
704         }
705         hr = S_OK;
706     }
707
708     return hr;
709 }
710 static HRESULT WINAPI ISF_MyComputer_fnMapColumnToSCID (IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
711 {
712     ICOM_THIS (IGenericSFImpl, iface);
713     FIXME ("(%p)\n", This);
714     return E_NOTIMPL;
715 }
716
717 static ICOM_VTABLE (IShellFolder2) vt_ShellFolder2 =
718 {
719         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
720         ISF_MyComputer_fnQueryInterface,
721         ISF_MyComputer_fnAddRef,
722         ISF_MyComputer_fnRelease,
723         ISF_MyComputer_fnParseDisplayName,
724         ISF_MyComputer_fnEnumObjects,
725         ISF_MyComputer_fnBindToObject,
726         ISF_MyComputer_fnBindToStorage,
727         ISF_MyComputer_fnCompareIDs,
728         ISF_MyComputer_fnCreateViewObject,
729         ISF_MyComputer_fnGetAttributesOf,
730         ISF_MyComputer_fnGetUIObjectOf,
731         ISF_MyComputer_fnGetDisplayNameOf,
732         ISF_MyComputer_fnSetNameOf,
733         /* ShellFolder2 */
734         ISF_MyComputer_fnGetDefaultSearchGUID,
735         ISF_MyComputer_fnEnumSearches,
736         ISF_MyComputer_fnGetDefaultColumn,
737         ISF_MyComputer_fnGetDefaultColumnState,
738         ISF_MyComputer_fnGetDetailsEx,
739         ISF_MyComputer_fnGetDetailsOf,
740         ISF_MyComputer_fnMapColumnToSCID
741 };
742
743 /************************************************************************
744  *      IMCFldr_PersistFolder2_QueryInterface
745  */
746 static HRESULT WINAPI IMCFldr_PersistFolder2_QueryInterface (IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObj)
747 {
748     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
749
750     TRACE ("(%p)\n", This);
751
752     return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
753 }
754
755 /************************************************************************
756  *      IMCFldr_PersistFolder2_AddRef
757  */
758 static ULONG WINAPI IMCFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
759 {
760     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
761
762     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
763
764     return IUnknown_AddRef (_IUnknown_ (This));
765 }
766
767 /************************************************************************
768  *      ISFPersistFolder_Release
769  */
770 static ULONG WINAPI IMCFldr_PersistFolder2_Release (IPersistFolder2 * iface)
771 {
772     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
773
774     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
775
776     return IUnknown_Release (_IUnknown_ (This));
777 }
778
779 /************************************************************************
780  *      IMCFldr_PersistFolder2_GetClassID
781  */
782 static HRESULT WINAPI IMCFldr_PersistFolder2_GetClassID (IPersistFolder2 * iface, CLSID * lpClassId)
783 {
784     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
785
786     TRACE ("(%p)\n", This);
787
788     if (!lpClassId)
789         return E_POINTER;
790     *lpClassId = CLSID_MyComputer;
791
792     return S_OK;
793 }
794
795 /************************************************************************
796  *      IMCFldr_PersistFolder2_Initialize
797  *
798  * NOTES: it makes no sense to change the pidl
799  */
800 static HRESULT WINAPI IMCFldr_PersistFolder2_Initialize (IPersistFolder2 * iface, LPCITEMIDLIST pidl)
801 {
802     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
803     TRACE ("(%p)->(%p)\n", This, pidl);
804     return E_NOTIMPL;
805 }
806
807 /**************************************************************************
808  *      IPersistFolder2_fnGetCurFolder
809  */
810 static HRESULT WINAPI IMCFldr_PersistFolder2_GetCurFolder (IPersistFolder2 * iface, LPITEMIDLIST * pidl)
811 {
812     _ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
813
814     TRACE ("(%p)->(%p)\n", This, pidl);
815
816     if (!pidl)
817         return E_POINTER;
818     *pidl = ILClone (This->pidlRoot);
819     return S_OK;
820 }
821
822 static ICOM_VTABLE (IPersistFolder2) vt_PersistFolder2 =
823 {
824 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
825         IMCFldr_PersistFolder2_QueryInterface,
826         IMCFldr_PersistFolder2_AddRef,
827         IMCFldr_PersistFolder2_Release,
828         IMCFldr_PersistFolder2_GetClassID,
829         IMCFldr_PersistFolder2_Initialize,
830         IMCFldr_PersistFolder2_GetCurFolder
831 };