shell32: Implement IExplorerBrowser::SetOptions and IExplorerBrowser::GetOptions.
[wine] / dlls / shell32 / shfldr_unixfs.c
1 /*
2  * UNIXFS - Shell namespace extension for the unix filesystem
3  *
4  * Copyright (C) 2005 Michael Jung
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /*
22  * As you know, windows and unix do have a different philosophy with regard to
23  * the question of how a filesystem should be laid out. While we unix geeks
24  * learned to love the 'one-tree-rooted-at-/' approach, windows has in fact
25  * a whole forest of filesystem trees, each of which is typically identified by
26  * a drive letter.
27  *
28  * We would like wine to integrate as smoothly as possible (that is without
29  * sacrificing win32 compatibility) into the unix environment. For the
30  * filesystem question, this means we really would like those windows
31  * applications to work with unix path- and file-names. Unfortunately, this
32  * seems to be impossible in general. Therefore we have those symbolic links
33  * in wine's 'dosdevices' directory, which are used to simulate drives
34  * to keep windows applications happy. And as a consequence, we have those
35  * drive letters show up now and then in GUI applications running under wine,
36  * which gets the unix hardcore fans all angry, shouting at us @#!&$%* wine
37  * hackers that we are seducing the big companies not to port their applications
38  * to unix.
39  *
40  * DOS paths do appear at various places in GUI applications. Sometimes, they
41  * show up in the title bar of an application's window. They tend to accumulate
42  * in the most-recently-used section of the file-menu. And I've even seen some
43  * in a configuration dialog's edit control. In those examples, wine can't do a
44  * lot about this, since path-names can't be told apart from ordinary strings
45  * here. That's different in the file dialogs, though.
46  *
47  * With the introduction of the 'shell' in win32, Microsoft established an 
48  * abstraction layer on top of the filesystem, called the shell namespace (I was
49  * told that Gnome's virtual filesystem is conceptually similar). In the shell
50  * namespace, one doesn't use ascii- or unicode-strings to uniquely identify
51  * objects. Instead Microsoft introduced item-identifier-lists (The c type is 
52  * called ITEMIDLIST) as an abstraction of path-names. As you probably would
53  * have guessed, an item-identifier-list is a list of item-identifiers (whose
54  * c type's funny name is SHITEMID), which are opaque binary objects. This means
55  * that no application (apart from Microsoft Office) should make any assumptions
56  * on the internal structure of these SHITEMIDs. 
57  *
58  * Since the user prefers to be presented the good-old DOS file-names instead of 
59  * binary ITEMIDLISTs, a translation method between string-based file-names and
60  * ITEMIDLISTs was established. At the core of this are the COM-Interface
61  * IShellFolder and especially it's methods ParseDisplayName and 
62  * GetDisplayNameOf. Basically, you give a DOS-path (let's say C:\windows) to
63  * ParseDisplayName and get a SHITEMID similar to <Desktop|My Computer|C:|windows|>.
64  * Since it's opaque, you can't see the 'C', the 'windows' and the other stuff.
65  * You can only figure out that the ITEMIDLIST is composed of four SHITEMIDS.
66  * The file dialog applies IShellFolder's BindToObject method to bind to each of
67  * those four objects (Desktop, My Computer, C: and windows. All of them have to 
68  * implement the IShellFolder interface.) and asks them how they would like to be 
69  * displayed (basically their icon and the string displayed). If the file dialog 
70  * asks <Desktop|My Computer|C:|windows> which sub-objects it contains (via 
71  * EnumObjects) it gets a list of opaque SHITEMIDs, which can be concatenated to 
72  * <Desktop|...|windows> to build a new ITEMIDLIST and browse, for instance, 
73  * into <system32>. This means the file dialog browses the shell namespace by 
74  * identifying objects via ITEMIDLISTs. Once the user has selected a location to 
75  * save his valuable file, the file dialog calls IShellFolder's GetDisplayNameOf
76  * method to translate the ITEMIDLIST back to a DOS filename.
77  * 
78  * It seems that one intention of the shell namespace concept was to make it 
79  * possible to have objects in the namespace, which don't have any counterpart 
80  * in the filesystem. The 'My Computer' shell folder object is one instance
81  * which comes to mind (Go try to save a file into 'My Computer' on windows.)
82  * So, to make matters a little more complex, before the file dialog asks a
83  * shell namespace object for it's DOS path, it asks if it actually has one.
84  * This is done via the IShellFolder::GetAttributesOf method, which sets the
85  * SFGAO_FILESYSTEM if - and only if - it has.
86  *
87  * The two things, described in the previous two paragraphs, are what unixfs is
88  * based on. So basically, if UnixDosFolder's ParseDisplayName method is called 
89  * with a 'c:\windows' path-name, it doesn't return an 
90  * <Desktop|My Computer|C:|windows|> ITEMIDLIST. Instead, it uses 
91  * shell32's wine_get_unix_path_name and the _posix_ (which means not the win32) 
92  * fileio api's to figure out that c: is mapped to - let's say - 
93  * /home/mjung/.wine/drive_c and then constructs a 
94  * <Desktop|/|home|mjung|.wine|drive_c> ITEMIDLIST. Which is what the file 
95  * dialog uses to display the folder and file objects, which is why you see a 
96  * unix path. When the user has found a nice place for his file and hits the
97  * save button, the ITEMIDLIST of the selected folder object is passed to 
98  * GetDisplayNameOf, which returns a _DOS_ path name 
99  * (like H:\home_of_my_new_file out of <|Desktop|/|home|mjung|home_of_my_new_file|>).
100  * Unixfs basically mounts your dos devices together in order to construct
101  * a copy of your unix filesystem structure.
102  *
103  * But what if none of the symbolic links in 'dosdevices' points to '/', you 
104  * might ask ("And I don't want wine have access to my complete hard drive, you 
105  * *%&1#!"). No problem, as I stated above, unixfs uses the _posix_ apis to 
106  * construct the ITEMIDLISTs. Folders, which aren't accessible via a drive letter,
107  * don't have the SFGAO_FILESYSTEM flag set. So the file dialogs shouldn't allow
108  * the user to select such a folder for file storage (And if it does anyhow, it 
109  * will not be able to return a valid path, since there is none). Think of those 
110  * folders as a hierarchy of 'My Computer'-like folders, which happen to be a 
111  * shadow of your unix filesystem tree. And since all of this stuff doesn't 
112  * change anything at all in wine's fileio api's, windows applications will have 
113  * no more access rights as they had before. 
114  *
115  * To sum it all up, you can still safely run wine with you root account (Just
116  * kidding, don't do it.)
117  *
118  * If you are now standing in front of your computer, shouting hotly 
119  * "I am not convinced, Mr. Rumsfeld^H^H^H^H^H^H^H^H^H^H^H^H", fire up regedit
120  * and delete HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\
121  * Explorer\Desktop\Namespace\{9D20AAE8-0625-44B0-9CA7-71889C2254D9} and you 
122  * will be back in the pre-unixfs days.
123  */
124
125 #include "config.h"
126 #include "wine/port.h"
127
128 #include <stdio.h>
129 #include <stdarg.h>
130 #include <limits.h>
131 #include <errno.h>
132 #ifdef HAVE_DIRENT_H
133 # include <dirent.h>
134 #endif
135 #include <stdlib.h>
136 #ifdef HAVE_UNISTD_H
137 # include <unistd.h>
138 #endif
139 #ifdef HAVE_SYS_STAT_H
140 # include <sys/stat.h>
141 #endif
142 #ifdef HAVE_PWD_H
143 # include <pwd.h>
144 #endif
145 #ifdef HAVE_GRP_H
146 # include <grp.h>
147 #endif
148
149 #define COBJMACROS
150 #define NONAMELESSUNION
151 #define NONAMELESSSTRUCT
152
153 #include "windef.h"
154 #include "winbase.h"
155 #include "winuser.h"
156 #include "objbase.h"
157 #include "winreg.h"
158 #include "shlwapi.h"
159 #include "winternl.h"
160 #include "wine/debug.h"
161
162 #include "shell32_main.h"
163 #include "shellfolder.h"
164 #include "shfldr.h"
165 #include "shresdef.h"
166 #include "pidl.h"
167 #include "debughlp.h"
168
169 WINE_DEFAULT_DEBUG_CHANNEL(shell);
170
171 #if !defined(__MINGW32__) && !defined(_MSC_VER)
172
173 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
174 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
175
176 #define LEN_SHITEMID_FIXED_PART ((USHORT) \
177     ( sizeof(USHORT)      /* SHITEMID's cb field. */ \
178     + sizeof(PIDLTYPE)    /* PIDLDATA's type field. */ \
179     + sizeof(FileStruct)  /* Well, the FileStruct. */ \
180     - sizeof(char)        /* One char too much in FileStruct. */ \
181     + sizeof(FileStructW) /* You name it. */ \
182     - sizeof(WCHAR)       /* One WCHAR too much in FileStructW. */ \
183     + sizeof(WORD) ))     /* Offset of FileStructW field in PIDL. */
184
185 #define PATHMODE_UNIX 0
186 #define PATHMODE_DOS  1
187
188 static const WCHAR wFileSystemBindData[] = {
189     'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
190
191 /* UnixFolder object layout and typedef.
192  */
193 typedef struct _UnixFolder {
194     const IShellFolder2Vtbl       *lpIShellFolder2Vtbl;
195     const IPersistFolder3Vtbl     *lpIPersistFolder3Vtbl;
196     const IPersistPropertyBagVtbl *lpIPersistPropertyBagVtbl;
197     const IDropTargetVtbl         *lpIDropTargetVtbl;
198     const ISFHelperVtbl           *lpISFHelperVtbl;
199     LONG         m_cRef;
200     CHAR         *m_pszPath;     /* Target path of the shell folder (CP_UNIXCP) */
201     LPITEMIDLIST m_pidlLocation; /* Location in the shell namespace */
202     DWORD        m_dwPathMode;
203     DWORD        m_dwAttributes;
204     const CLSID  *m_pCLSID;
205     DWORD        m_dwDropEffectsMask;
206 } UnixFolder;
207
208 /* Will hold the registered clipboard format identifier for ITEMIDLISTS. */
209 static UINT cfShellIDList = 0;
210
211 /******************************************************************************
212  * UNIXFS_filename_from_shitemid [Internal]
213  *
214  *  Get CP_UNIXCP encoded filename corresponding to the first item of a pidl
215  * 
216  * PARAMS
217  *  pidl           [I] A simple SHITEMID
218  *  pszPathElement [O] Filename in CP_UNIXCP encoding will be stored here
219  *
220  * RETURNS
221  *  Success: Number of bytes necessary to store the CP_UNIXCP encoded filename 
222  *   _without_ the terminating NUL.
223  *  Failure: 0
224  *  
225  * NOTES
226  *  Size of the buffer at pszPathElement has to be FILENAME_MAX. pszPathElement
227  *  may be NULL, if you are only interested in the return value. 
228  */
229 static int UNIXFS_filename_from_shitemid(LPCITEMIDLIST pidl, char* pszPathElement) {
230     FileStructW *pFileStructW = _ILGetFileStructW(pidl);
231     int cLen = 0;
232
233     if (pFileStructW) {
234         cLen = WideCharToMultiByte(CP_UNIXCP, 0, pFileStructW->wszName, -1, pszPathElement,
235             pszPathElement ? FILENAME_MAX : 0, 0, 0);
236     } else {
237         /* There might be pidls slipping in from shfldr_fs.c, which don't contain the
238          * FileStructW field. In this case, we have to convert from CP_ACP to CP_UNIXCP. */
239         char *pszText = _ILGetTextPointer(pidl);
240         WCHAR *pwszPathElement = NULL;
241         int cWideChars;
242     
243         cWideChars = MultiByteToWideChar(CP_ACP, 0, pszText, -1, NULL, 0);
244         if (!cWideChars) goto cleanup;
245
246         pwszPathElement = SHAlloc(cWideChars * sizeof(WCHAR));
247         if (!pwszPathElement) goto cleanup;
248     
249         cWideChars = MultiByteToWideChar(CP_ACP, 0, pszText, -1, pwszPathElement, cWideChars);
250         if (!cWideChars) goto cleanup; 
251
252         cLen = WideCharToMultiByte(CP_UNIXCP, 0, pwszPathElement, -1, pszPathElement, 
253             pszPathElement ? FILENAME_MAX : 0, 0, 0);
254
255     cleanup:
256         SHFree(pwszPathElement);
257     }
258         
259     if (cLen) cLen--; /* Don't count terminating NUL! */
260     return cLen;
261 }
262
263 /******************************************************************************
264  * UNIXFS_shitemid_len_from_filename [Internal]
265  *
266  * Computes the necessary length of a pidl to hold a path element
267  *
268  * PARAMS
269  *  szPathElement    [I] The path element string in CP_UNIXCP encoding.
270  *  ppszPathElement  [O] Path element string in CP_ACP encoding.
271  *  ppwszPathElement [O] Path element string as WCHAR string.
272  *
273  * RETURNS
274  *  Success: Length in bytes of a SHITEMID representing szPathElement
275  *  Failure: 0
276  * 
277  * NOTES
278  *  Provide NULL values if not interested in pp(w)szPathElement. Otherwise
279  *  caller is responsible to free ppszPathElement and ppwszPathElement with
280  *  SHFree.
281  */
282 static USHORT UNIXFS_shitemid_len_from_filename(
283     const char *szPathElement, char **ppszPathElement, WCHAR **ppwszPathElement) 
284 {
285     USHORT cbPidlLen = 0;
286     WCHAR *pwszPathElement = NULL;
287     char *pszPathElement = NULL;
288     int cWideChars, cChars;
289
290     /* There and Back Again: A Hobbit's Holiday. CP_UNIXCP might be some ANSI
291      * codepage or it might be a real multi-byte encoding like utf-8. There is no
292      * other way to figure out the length of the corresponding WCHAR and CP_ACP 
293      * strings without actually doing the full CP_UNIXCP -> WCHAR -> CP_ACP cycle. */
294     
295     cWideChars = MultiByteToWideChar(CP_UNIXCP, 0, szPathElement, -1, NULL, 0);
296     if (!cWideChars) goto cleanup;
297
298     pwszPathElement = SHAlloc(cWideChars * sizeof(WCHAR));
299     if (!pwszPathElement) goto cleanup;
300
301     cWideChars = MultiByteToWideChar(CP_UNIXCP, 0, szPathElement, -1, pwszPathElement, cWideChars);
302     if (!cWideChars) goto cleanup; 
303
304     cChars = WideCharToMultiByte(CP_ACP, 0, pwszPathElement, -1, NULL, 0, 0, 0);
305     if (!cChars) goto cleanup;
306
307     pszPathElement = SHAlloc(cChars);
308     if (!pszPathElement) goto cleanup;
309
310     cChars = WideCharToMultiByte(CP_ACP, 0, pwszPathElement, -1, pszPathElement, cChars, 0, 0);
311     if (!cChars) goto cleanup;
312
313     /* (cChars & 0x1) is for the potential alignment byte */
314     cbPidlLen = LEN_SHITEMID_FIXED_PART + cChars + (cChars & 0x1) + cWideChars * sizeof(WCHAR);
315     
316 cleanup:
317     if (cbPidlLen && ppszPathElement) 
318         *ppszPathElement = pszPathElement;
319     else 
320         SHFree(pszPathElement);
321
322     if (cbPidlLen && ppwszPathElement)
323         *ppwszPathElement = pwszPathElement;
324     else
325         SHFree(pwszPathElement);
326
327     return cbPidlLen;
328 }
329
330 /******************************************************************************
331  * UNIXFS_is_pidl_of_type [Internal]
332  *
333  * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
334  *
335  * PARAMS
336  *  pIDL    [I] The ITEMIDLIST to be checked.
337  *  fFilter [I] Shell condition flags, which specify the filter.
338  *
339  * RETURNS
340  *  TRUE, if pIDL is accepted by fFilter
341  *  FALSE, otherwise
342  */
343 static inline BOOL UNIXFS_is_pidl_of_type(LPCITEMIDLIST pIDL, SHCONTF fFilter) {
344     const PIDLDATA *pIDLData = _ILGetDataPointer(pIDL);
345     if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData && 
346         (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN)) 
347     {
348         return FALSE;
349     }
350     if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
351     if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
352     return FALSE;
353 }
354
355 /******************************************************************************
356  * UNIXFS_get_unix_path [Internal]
357  *
358  * Convert an absolute dos path to an absolute unix path.
359  * Evaluate "/.", "/.." and the symbolic links in $WINEPREFIX/dosdevices.
360  *
361  * PARAMS
362  *  pszDosPath       [I] An absolute dos path
363  *  pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
364  *
365  * RETURNS
366  *  Success, TRUE
367  *  Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
368  */
369 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
370 {
371     char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
372     WCHAR wszDrive[] = { '?', ':', '\\', 0 };
373     int cDriveSymlinkLen;
374     
375     TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
376
377     if (!pszDosPath || pszDosPath[1] != ':')
378         return FALSE;
379
380     /* Get the canonicalized unix path corresponding to the drive letter. */
381     wszDrive[0] = pszDosPath[0];
382     pszUnixPath = wine_get_unix_file_name(wszDrive);
383     if (!pszUnixPath) return FALSE;
384     cDriveSymlinkLen = strlen(pszUnixPath);
385     pElement = realpath(pszUnixPath, szPath);
386     HeapFree(GetProcessHeap(), 0, pszUnixPath);
387     if (!pElement) return FALSE;
388     if (szPath[strlen(szPath)-1] != '/') strcat(szPath, "/");
389
390     /* Append the part relative to the drive symbolic link target. */
391     pszUnixPath = wine_get_unix_file_name(pszDosPath);
392     if (!pszUnixPath) return FALSE;
393     strcat(szPath, pszUnixPath + cDriveSymlinkLen);
394     HeapFree(GetProcessHeap(), 0, pszUnixPath);
395     
396     /* pCanonicalTail always points to the end of the canonical path constructed
397      * thus far. pPathTail points to the still to be processed part of the input
398      * path. pElement points to the path element currently investigated.
399      */
400     *pszCanonicalPath = '\0';
401     pCanonicalTail = pszCanonicalPath;
402     pPathTail = szPath;
403
404     do {
405         char cTemp;
406             
407         pElement = pPathTail;
408         pPathTail = strchr(pPathTail+1, '/');
409         if (!pPathTail) /* Last path element may not be terminated by '/'. */ 
410             pPathTail = pElement + strlen(pElement);
411         /* Temporarily terminate the current path element. Will be restored later. */
412         cTemp = *pPathTail;
413         *pPathTail = '\0';
414
415         /* Skip "/." path elements */
416         if (!strcmp("/.", pElement)) {
417             *pPathTail = cTemp;
418         } else if (!strcmp("/..", pElement)) {
419             /* Remove last element in canonical path for "/.." elements, then skip. */
420             char *pTemp = strrchr(pszCanonicalPath, '/');
421             if (pTemp)
422                 pCanonicalTail = pTemp;
423             *pCanonicalTail = '\0';
424             *pPathTail = cTemp;
425         } else {
426             /* Directory or file. Copy to canonical path */
427             if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
428                 return FALSE;
429                 
430             memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
431             pCanonicalTail += pPathTail - pElement;
432             *pPathTail = cTemp;
433         }
434     } while (pPathTail[0] == '/');
435    
436     TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
437     
438     return TRUE;
439 }
440
441 /******************************************************************************
442  * UNIXFS_seconds_since_1970_to_dos_date_time [Internal]
443  *
444  * Convert unix time to FAT time
445  *
446  * PARAMS 
447  *  ss1970 [I] Unix time (seconds since 1970)
448  *  pDate  [O] Corresponding FAT date
449  *  pTime  [O] Corresponding FAT time
450  */
451 static inline void UNIXFS_seconds_since_1970_to_dos_date_time(
452     time_t ss1970, LPWORD pDate, LPWORD pTime)
453 {
454     LARGE_INTEGER time;
455     FILETIME fileTime;
456
457     RtlSecondsSince1970ToTime( ss1970, &time );
458     fileTime.dwLowDateTime = time.u.LowPart;
459     fileTime.dwHighDateTime = time.u.HighPart;
460     FileTimeToDosDateTime(&fileTime, pDate, pTime);
461 }
462
463 /******************************************************************************
464  * UNIXFS_build_shitemid [Internal]
465  *
466  * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into 
467  * buffer 'pIDL'.
468  *
469  * PARAMS
470  *  pszUnixPath [I] An absolute path. The SHITEMID will be built for the last component.
471  *  pbc         [I] Bind context for this action, used to determine if the file must exist
472  *  pIDL        [O] SHITEMID will be constructed here.
473  *
474  * RETURNS
475  *  Success: A pointer to the terminating '\0' character of path.
476  *  Failure: NULL
477  *
478  * NOTES
479  *  Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
480  *  If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
481  *  a 0 USHORT value.
482  */
483 static char* UNIXFS_build_shitemid(char *pszUnixPath, LPBC pbc, void *pIDL) {
484     LPPIDLDATA pIDLData;
485     struct stat fileStat;
486     char *pszComponentU, *pszComponentA;
487     WCHAR *pwszComponentW;
488     int cComponentULen, cComponentALen;
489     USHORT cbLen;
490     FileStructW *pFileStructW;
491     WORD uOffsetW, *pOffsetW;
492     BOOL must_exist = TRUE;
493
494     TRACE("(pszUnixPath=%s, pbc=%p, pIDL=%p)\n", debugstr_a(pszUnixPath), pbc, pIDL);
495
496     if (pbc){
497         IUnknown *unk;
498         IFileSystemBindData *fsb;
499         HRESULT hr;
500
501         hr = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &unk);
502         if (SUCCEEDED(hr)) {
503             hr = IUnknown_QueryInterface(unk, &IID_IFileSystemBindData, (LPVOID*)&fsb);
504             if (SUCCEEDED(hr)) {
505                 /* Windows tries to get WIN32_FIND_DATAW structure from
506                  * fsb here for no known reason */
507                 must_exist = FALSE;
508                 IFileSystemBindData_Release(fsb);
509             }
510             IUnknown_Release(unk);
511         }
512     }
513
514     /* We are only interested in regular files and directories. */
515     if (stat(pszUnixPath, &fileStat)){
516         if (must_exist || errno != ENOENT)
517             return NULL;
518     }else
519         if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode))
520             return NULL;
521     
522     /* Compute the SHITEMID's length and wipe it. */
523     pszComponentU = strrchr(pszUnixPath, '/') + 1;
524     cComponentULen = strlen(pszComponentU);
525     cbLen = UNIXFS_shitemid_len_from_filename(pszComponentU, &pszComponentA, &pwszComponentW);
526     if (!cbLen) return NULL;
527     memset(pIDL, 0, cbLen);
528     ((LPSHITEMID)pIDL)->cb = cbLen;
529     
530     /* Set shell32's standard SHITEMID data fields. */
531     pIDLData = _ILGetDataPointer(pIDL);
532     pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
533     pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
534     UNIXFS_seconds_since_1970_to_dos_date_time(fileStat.st_mtime, &pIDLData->u.file.uFileDate, 
535         &pIDLData->u.file.uFileTime);
536     pIDLData->u.file.uFileAttribs = 0;
537     if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
538     if (pszComponentU[0] == '.') pIDLData->u.file.uFileAttribs |=  FILE_ATTRIBUTE_HIDDEN;
539     cComponentALen = lstrlenA(pszComponentA) + 1;
540     memcpy(pIDLData->u.file.szNames, pszComponentA, cComponentALen);
541     
542     pFileStructW = (FileStructW*)(pIDLData->u.file.szNames + cComponentALen + (cComponentALen & 0x1));
543     uOffsetW = (WORD)(((LPBYTE)pFileStructW) - ((LPBYTE)pIDL));
544     pFileStructW->cbLen = cbLen - uOffsetW;
545     UNIXFS_seconds_since_1970_to_dos_date_time(fileStat.st_mtime, &pFileStructW->uCreationDate, 
546         &pFileStructW->uCreationTime);
547     UNIXFS_seconds_since_1970_to_dos_date_time(fileStat.st_atime, &pFileStructW->uLastAccessDate,
548         &pFileStructW->uLastAccessTime);
549     lstrcpyW(pFileStructW->wszName, pwszComponentW);
550
551     pOffsetW = (WORD*)(((LPBYTE)pIDL) + cbLen - sizeof(WORD));
552     *pOffsetW = uOffsetW;
553     
554     SHFree(pszComponentA);
555     SHFree(pwszComponentW);
556     
557     return pszComponentU + cComponentULen;
558 }
559
560 /******************************************************************************
561  * UNIXFS_path_to_pidl [Internal]
562  *
563  * PARAMS
564  *  pUnixFolder [I] If path is relative, pUnixFolder represents the base path
565  *  path        [I] An absolute unix or dos path or a path relative to pUnixFolder
566  *  ppidl       [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
567  *  
568  * RETURNS
569  *  Success: S_OK
570  *  Failure: Error code, invalid params or out of memory
571  *
572  * NOTES
573  *  pUnixFolder also carries the information if the path is expected to be unix or dos.
574  */
575 static HRESULT UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, LPBC pbc, const WCHAR *path,
576         LPITEMIDLIST *ppidl) {
577     LPITEMIDLIST pidl;
578     int cPidlLen, cPathLen;
579     char *pSlash, *pNextSlash, szCompletePath[FILENAME_MAX], *pNextPathElement, *pszAPath;
580     WCHAR *pwszPath;
581
582     TRACE("pUnixFolder=%p, pbc=%p, path=%s, ppidl=%p\n", pUnixFolder, pbc, debugstr_w(path), ppidl);
583    
584     if (!ppidl || !path)
585         return E_INVALIDARG;
586
587     /* Build an absolute path and let pNextPathElement point to the interesting 
588      * relative sub-path. We need the absolute path to call 'stat', but the pidl
589      * will only contain the relative part.
590      */
591     if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':')) 
592     {
593         /* Absolute dos path. Convert to unix */
594         if (!UNIXFS_get_unix_path(path, szCompletePath))
595             return E_FAIL;
596         pNextPathElement = szCompletePath;
597     } 
598     else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/')) 
599     {
600         /* Absolute unix path. Just convert to ANSI. */
601         WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL); 
602         pNextPathElement = szCompletePath;
603     } 
604     else 
605     {
606         /* Relative dos or unix path. Concat with this folder's path */
607         int cBasePathLen = strlen(pUnixFolder->m_pszPath);
608         memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
609         WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath + cBasePathLen, 
610                             FILENAME_MAX - cBasePathLen, NULL, NULL);
611         pNextPathElement = szCompletePath + cBasePathLen - 1;
612         
613         /* If in dos mode, replace '\' with '/' */
614         if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
615             char *pBackslash = strchr(pNextPathElement, '\\');
616             while (pBackslash) {
617                 *pBackslash = '/';
618                 pBackslash = strchr(pBackslash, '\\');
619             }
620         }
621     }
622
623     /* Special case for the root folder. */
624     if (!strcmp(szCompletePath, "/")) {
625         *ppidl = pidl = SHAlloc(sizeof(USHORT));
626         if (!pidl) return E_FAIL;
627         pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
628         return S_OK;
629     }
630     
631     /* Remove trailing slash, if present */
632     cPathLen = strlen(szCompletePath);
633     if (szCompletePath[cPathLen-1] == '/') 
634         szCompletePath[cPathLen-1] = '\0';
635
636     if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
637         ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
638         return E_FAIL;
639     }
640     
641     /* At this point, we have an absolute unix path in szCompletePath 
642      * and the relative portion of it in pNextPathElement. Both starting with '/'
643      * and _not_ terminated by a '/'. */
644     TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
645     
646     /* Convert to CP_ACP and WCHAR */
647     if (!UNIXFS_shitemid_len_from_filename(pNextPathElement, &pszAPath, &pwszPath))
648         return E_FAIL;
649
650     /* Compute the length of the complete ITEMIDLIST */
651     cPidlLen = 0;
652     pSlash = pszAPath;
653     while (pSlash) {
654         pNextSlash = strchr(pSlash+1, '/');
655         cPidlLen += LEN_SHITEMID_FIXED_PART + /* Fixed part length plus potential alignment byte. */
656             (pNextSlash ? (pNextSlash - pSlash) & 0x1 : lstrlenA(pSlash) & 0x1); 
657         pSlash = pNextSlash;
658     }
659
660     /* The USHORT is for the ITEMIDLIST terminator. The NUL terminators for the sub-path-strings
661      * are accounted for by the '/' separators, which are not stored in the SHITEMIDs. Above we
662      * have ensured that the number of '/'s exactly matches the number of sub-path-strings. */
663     cPidlLen += lstrlenA(pszAPath) + lstrlenW(pwszPath) * sizeof(WCHAR) + sizeof(USHORT);
664
665     SHFree(pszAPath);
666     SHFree(pwszPath);
667
668     *ppidl = pidl = SHAlloc(cPidlLen);
669     if (!pidl) return E_FAIL;
670
671     /* Concatenate the SHITEMIDs of the sub-directories. */
672     while (*pNextPathElement) {
673         pSlash = strchr(pNextPathElement+1, '/');
674         if (pSlash) *pSlash = '\0';
675         pNextPathElement = UNIXFS_build_shitemid(szCompletePath, pbc, pidl);
676         if (pSlash) *pSlash = '/';
677             
678         if (!pNextPathElement) {
679             SHFree(*ppidl);
680             *ppidl = NULL;
681             return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
682         }
683         pidl = ILGetNext(pidl);
684     }
685     pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
686
687     if ((char *)pidl-(char *)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */ 
688         ERR("Computed length of pidl incorrect. Please report.\n");
689     
690     return S_OK;
691 }
692
693 /******************************************************************************
694  * UNIXFS_initialize_target_folder [Internal]
695  *
696  *  Initialize the m_pszPath member of an UnixFolder, given an absolute unix
697  *  base path and a relative ITEMIDLIST. Leave the m_pidlLocation member, which
698  *  specifies the location in the shell namespace alone. 
699  * 
700  * PARAMS
701  *  This          [IO] The UnixFolder, whose target path is to be initialized
702  *  szBasePath    [I]  The absolute base path
703  *  pidlSubFolder [I]  Relative part of the path, given as an ITEMIDLIST
704  *  dwAttributes  [I]  Attributes to add to the Folders m_dwAttributes member 
705  *                     (Used to pass the SFGAO_FILESYSTEM flag down the path)
706  * RETURNS
707  *  Success: S_OK,
708  *  Failure: E_FAIL
709  */
710 static HRESULT UNIXFS_initialize_target_folder(UnixFolder *This, const char *szBasePath,
711     LPCITEMIDLIST pidlSubFolder, DWORD dwAttributes)
712 {
713     LPCITEMIDLIST current = pidlSubFolder;
714     DWORD dwPathLen = strlen(szBasePath)+1;
715     char *pNextDir;
716     WCHAR *dos_name;
717
718     /* Determine the path's length bytes */
719     while (!_ILIsEmpty(current)) {
720         dwPathLen += UNIXFS_filename_from_shitemid(current, NULL) + 1; /* For the '/' */
721         current = ILGetNext(current);
722     };
723
724     /* Build the path and compute the attributes*/
725     This->m_dwAttributes = 
726             dwAttributes|SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
727     This->m_pszPath = pNextDir = SHAlloc(dwPathLen);
728     if (!This->m_pszPath) {
729         WARN("SHAlloc failed!\n");
730         return E_FAIL;
731     }
732     current = pidlSubFolder;
733     strcpy(pNextDir, szBasePath);
734     pNextDir += strlen(szBasePath);
735     if (This->m_dwPathMode == PATHMODE_UNIX || IsEqualCLSID(&CLSID_MyDocuments, This->m_pCLSID))
736         This->m_dwAttributes |= SFGAO_FILESYSTEM;
737     while (!_ILIsEmpty(current)) {
738         pNextDir += UNIXFS_filename_from_shitemid(current, pNextDir);
739         *pNextDir++ = '/';
740         current = ILGetNext(current);
741     }
742     *pNextDir='\0';
743
744     if (!(This->m_dwAttributes & SFGAO_FILESYSTEM) &&
745         ((dos_name = wine_get_dos_file_name(This->m_pszPath))))
746     {
747         This->m_dwAttributes |= SFGAO_FILESYSTEM;
748         HeapFree( GetProcessHeap(), 0, dos_name );
749     }
750
751     return S_OK;
752 }
753
754 /******************************************************************************
755  * UNIXFS_copy [Internal]
756  *
757  *  Copy pwszDosSrc to pwszDosDst.
758  *
759  * PARAMS
760  *  pwszDosSrc [I]  absolute path of the source
761  *  pwszDosDst [I]  absolute path of the destination
762  *
763  * RETURNS
764  *  Success: S_OK,
765  *  Failure: E_FAIL
766  */
767 static HRESULT UNIXFS_copy(LPCWSTR pwszDosSrc, LPCWSTR pwszDosDst)
768 {
769     SHFILEOPSTRUCTW op;
770     LPWSTR pwszSrc, pwszDst;
771     HRESULT res = E_OUTOFMEMORY;
772     UINT iSrcLen, iDstLen;
773
774     if (!pwszDosSrc || !pwszDosDst)
775         return E_FAIL;
776
777     iSrcLen = lstrlenW(pwszDosSrc);
778     iDstLen = lstrlenW(pwszDosDst);
779     pwszSrc = HeapAlloc(GetProcessHeap(), 0, (iSrcLen + 2) * sizeof(WCHAR));
780     pwszDst = HeapAlloc(GetProcessHeap(), 0, (iDstLen + 2) * sizeof(WCHAR));
781
782     if (pwszSrc && pwszDst) {
783         lstrcpyW(pwszSrc, pwszDosSrc);
784         lstrcpyW(pwszDst, pwszDosDst);
785         /* double null termination */
786         pwszSrc[iSrcLen + 1] = 0;
787         pwszDst[iDstLen + 1] = 0;
788
789         ZeroMemory(&op, sizeof(op));
790         op.hwnd = GetActiveWindow();
791         op.wFunc = FO_COPY;
792         op.pFrom = pwszSrc;
793         op.pTo = pwszDst;
794         op.fFlags = FOF_ALLOWUNDO;
795         if (!SHFileOperationW(&op))
796         {
797             WARN("SHFileOperationW failed\n");
798             res = E_FAIL;
799         }
800         else
801             res = S_OK;
802     }
803
804     HeapFree(GetProcessHeap(), 0, pwszSrc);
805     HeapFree(GetProcessHeap(), 0, pwszDst);
806     return res;
807 }
808
809 /******************************************************************************
810  * UnixFolder
811  *
812  * Class whose heap based instances represent unix filesystem directories.
813  */
814
815 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
816     TRACE("(pUnixFolder=%p)\n", pUnixFolder);
817     
818     SHFree(pUnixFolder->m_pszPath);
819     ILFree(pUnixFolder->m_pidlLocation);
820     SHFree(pUnixFolder);
821 }
822
823 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid, 
824     void **ppv) 
825 {
826     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
827         
828     TRACE("(iface=%p, riid=%s, ppv=%p)\n", iface, shdebugstr_guid(riid), ppv);
829     
830     if (!ppv) return E_INVALIDARG;
831     
832     if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) || 
833         IsEqualIID(&IID_IShellFolder2, riid)) 
834     {
835         *ppv = STATIC_CAST(IShellFolder2, This);
836     } else if (IsEqualIID(&IID_IPersistFolder3, riid) || IsEqualIID(&IID_IPersistFolder2, riid) || 
837                IsEqualIID(&IID_IPersistFolder, riid) || IsEqualIID(&IID_IPersist, riid)) 
838     {
839         *ppv = STATIC_CAST(IPersistFolder3, This);
840     } else if (IsEqualIID(&IID_IPersistPropertyBag, riid)) {
841         *ppv = STATIC_CAST(IPersistPropertyBag, This);
842     } else if (IsEqualIID(&IID_ISFHelper, riid)) {
843         *ppv = STATIC_CAST(ISFHelper, This);
844     } else if (IsEqualIID(&IID_IDropTarget, riid)) {
845         *ppv = STATIC_CAST(IDropTarget, This);
846         if (!cfShellIDList) 
847             cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
848     } else {
849         *ppv = NULL;
850         TRACE("Unimplemented interface %s\n", shdebugstr_guid(riid));
851         return E_NOINTERFACE;
852     }
853
854     IUnknown_AddRef((IUnknown*)*ppv);
855     return S_OK;
856 }
857
858 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
859     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
860
861     TRACE("(iface=%p)\n", iface);
862
863     return InterlockedIncrement(&This->m_cRef);
864 }
865
866 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
867     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
868     ULONG cRef;
869     
870     TRACE("(iface=%p)\n", iface);
871
872     cRef = InterlockedDecrement(&This->m_cRef);
873     
874     if (!cRef) 
875         UnixFolder_Destroy(This);
876
877     return cRef;
878 }
879
880 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner, 
881     LPBC pbc, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
882     ULONG* pdwAttributes)
883 {
884     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
885     HRESULT result;
886
887     TRACE("(iface=%p, hwndOwner=%p, pbc=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
888           "pdwAttributes=%p) stub\n", iface, hwndOwner, pbc, debugstr_w(lpszDisplayName),
889           pchEaten, ppidl, pdwAttributes);
890
891     result = UNIXFS_path_to_pidl(This, pbc, lpszDisplayName, ppidl);
892     if (SUCCEEDED(result) && pdwAttributes && *pdwAttributes)
893     {
894         IShellFolder *pParentSF;
895         LPCITEMIDLIST pidlLast;
896         LPITEMIDLIST pidlComplete = ILCombine(This->m_pidlLocation, *ppidl);
897         HRESULT hr;
898         
899         hr = SHBindToParent(pidlComplete, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
900         if (FAILED(hr)) {
901             FIXME("SHBindToParent failed! hr = %08x\n", hr);
902             ILFree(pidlComplete);
903             return E_FAIL;
904         }
905         IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
906         IShellFolder_Release(pParentSF);
907         ILFree(pidlComplete);
908     }
909
910     if (FAILED(result)) TRACE("FAILED!\n");
911     return result;
912 }
913
914 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter);
915
916 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner, 
917     SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
918 {
919     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
920     IUnknown *newIterator;
921     HRESULT hr;
922     
923     TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08x, ppEnumIDList=%p)\n", 
924             iface, hwndOwner, grfFlags, ppEnumIDList);
925
926     if (!This->m_pszPath) {
927         WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
928         return E_UNEXPECTED;
929     }
930
931     newIterator = UnixSubFolderIterator_Constructor(This, grfFlags);
932     hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
933     IUnknown_Release(newIterator);
934     
935     return hr;
936 }
937
938 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID);
939
940 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
941     LPBC pbcReserved, REFIID riid, void** ppvOut)
942 {
943     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
944     IPersistFolder3 *persistFolder;
945     HRESULT hr;
946     const CLSID *clsidChild;
947         
948     TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n", 
949             iface, pidl, pbcReserved, riid, ppvOut);
950
951     if (_ILIsEmpty(pidl))
952         return E_INVALIDARG;
953    
954     if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
955         /* Children of FolderShortcuts are ShellFSFolders on Windows. 
956          * Unixfs' counterpart is UnixDosFolder. */
957         clsidChild = &CLSID_UnixDosFolder;    
958     } else {
959         clsidChild = This->m_pCLSID;
960     }
961
962     hr = CreateUnixFolder(NULL, &IID_IPersistFolder3, (void**)&persistFolder, clsidChild);
963     if (FAILED(hr)) return hr;
964     hr = IPersistFolder_QueryInterface(persistFolder, riid, ppvOut);
965
966     if (SUCCEEDED(hr)) {
967         UnixFolder *subfolder = ADJUST_THIS(UnixFolder, IPersistFolder3, persistFolder);
968         subfolder->m_pidlLocation = ILCombine(This->m_pidlLocation, pidl);
969         hr = UNIXFS_initialize_target_folder(subfolder, This->m_pszPath, pidl,
970                                              This->m_dwAttributes & SFGAO_FILESYSTEM);
971     } 
972
973     IPersistFolder3_Release(persistFolder);
974     
975     return hr;
976 }
977
978 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl, 
979     LPBC pbcReserved, REFIID riid, void** ppvObj)
980 {
981     FIXME("stub\n");
982     return E_NOTIMPL;
983 }
984
985 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam, 
986     LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
987 {
988     BOOL isEmpty1, isEmpty2;
989     HRESULT hr = E_FAIL;
990     LPITEMIDLIST firstpidl;
991     IShellFolder2 *psf;
992     int compare;
993
994     TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
995     
996     isEmpty1 = _ILIsEmpty(pidl1);
997     isEmpty2 = _ILIsEmpty(pidl2);
998
999     if (isEmpty1 && isEmpty2) 
1000         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
1001     else if (isEmpty1)
1002         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
1003     else if (isEmpty2)
1004         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
1005
1006     if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2)) 
1007         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
1008     if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
1009         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
1010
1011     compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE, 
1012                              _ILGetTextPointer(pidl1), -1,
1013                              _ILGetTextPointer(pidl2), -1);
1014     
1015     if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN)) 
1016         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
1017
1018     if (pidl1->mkid.cb < pidl2->mkid.cb)
1019         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
1020     else if (pidl1->mkid.cb > pidl2->mkid.cb)
1021         return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
1022
1023     firstpidl = ILCloneFirst(pidl1);
1024     pidl1 = ILGetNext(pidl1);
1025     pidl2 = ILGetNext(pidl2);
1026     
1027     hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
1028     if (SUCCEEDED(hr)) {
1029         hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
1030         IShellFolder2_Release(psf);
1031     }
1032
1033     ILFree(firstpidl);
1034     return hr;
1035 }
1036
1037 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
1038     REFIID riid, void** ppv)
1039 {
1040     HRESULT hr = E_INVALIDARG;
1041         
1042     TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
1043     
1044     if (!ppv) return E_INVALIDARG;
1045     *ppv = NULL;
1046     
1047     if (IsEqualIID(&IID_IShellView, riid)) {
1048         LPSHELLVIEW pShellView;
1049         
1050         pShellView = IShellView_Constructor((IShellFolder*)iface);
1051         if (pShellView) {
1052             hr = IShellView_QueryInterface(pShellView, riid, ppv);
1053             IShellView_Release(pShellView);
1054         }
1055     } else if (IsEqualIID(&IID_IDropTarget, riid)) {
1056         hr = IShellFolder2_QueryInterface(iface, &IID_IDropTarget, ppv);
1057     }
1058     
1059     return hr;
1060 }
1061
1062 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl, 
1063     LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
1064 {
1065     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1066     HRESULT hr = S_OK;
1067         
1068     TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
1069  
1070     if (!rgfInOut || (cidl && !apidl)) 
1071         return E_INVALIDARG;
1072     
1073     if (cidl == 0) {
1074         *rgfInOut &= This->m_dwAttributes;
1075     } else {
1076         char szAbsolutePath[FILENAME_MAX], *pszRelativePath;
1077         UINT i;
1078
1079         *rgfInOut = SFGAO_CANCOPY|SFGAO_CANMOVE|SFGAO_CANLINK|SFGAO_CANRENAME|SFGAO_CANDELETE|
1080                     SFGAO_HASPROPSHEET|SFGAO_DROPTARGET|SFGAO_FILESYSTEM;
1081         lstrcpyA(szAbsolutePath, This->m_pszPath);
1082         pszRelativePath = szAbsolutePath + lstrlenA(szAbsolutePath);
1083         for (i=0; i<cidl; i++) {
1084             if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
1085                 WCHAR *dos_name;
1086                 if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelativePath)) 
1087                     return E_INVALIDARG;
1088                 if (!(dos_name = wine_get_dos_file_name( szAbsolutePath )))
1089                     *rgfInOut &= ~SFGAO_FILESYSTEM;
1090                 else
1091                     HeapFree( GetProcessHeap(), 0, dos_name );
1092             }
1093             if (_ILIsFolder(apidl[i])) 
1094                 *rgfInOut |= SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
1095         }
1096     }
1097     
1098     return hr;
1099 }
1100
1101 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner, 
1102     UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
1103 {
1104     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1105     UINT i;
1106     
1107     TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
1108         iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
1109
1110     if (!cidl || !apidl || !riid || !ppvOut) 
1111         return E_INVALIDARG;
1112
1113     for (i=0; i<cidl; i++) 
1114         if (!apidl[i]) 
1115             return E_INVALIDARG;
1116     
1117     if (IsEqualIID(&IID_IContextMenu, riid)) {
1118         *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
1119         return S_OK;
1120     } else if (IsEqualIID(&IID_IDataObject, riid)) {
1121         *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
1122         return S_OK;
1123     } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
1124         LPITEMIDLIST pidl;
1125         if (cidl != 1) return E_INVALIDARG;
1126         pidl = ILCombine(This->m_pidlLocation, apidl[0]);
1127         *ppvOut = IExtractIconA_Constructor(pidl);
1128         SHFree(pidl);
1129         return S_OK;
1130     } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
1131         LPITEMIDLIST pidl;
1132         if (cidl != 1) return E_INVALIDARG;
1133         pidl = ILCombine(This->m_pidlLocation, apidl[0]);
1134         *ppvOut = IExtractIconW_Constructor(pidl);
1135         SHFree(pidl);
1136         return S_OK;
1137     } else if (IsEqualIID(&IID_IDropTarget, riid)) {
1138         if (cidl != 1) return E_INVALIDARG;
1139         return IShellFolder2_BindToObject(iface, apidl[0], NULL, &IID_IDropTarget, ppvOut);
1140     } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
1141         FIXME("IShellLinkW\n");
1142         return E_FAIL;
1143     } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
1144         FIXME("IShellLinkA\n");
1145         return E_FAIL;
1146     } else {
1147         FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
1148         return E_NOINTERFACE;
1149     }
1150 }
1151
1152 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface, 
1153     LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
1154 {
1155     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1156     HRESULT hr = S_OK;    
1157
1158     TRACE("(iface=%p, pidl=%p, uFlags=%x, lpName=%p)\n", iface, pidl, uFlags, lpName);
1159     
1160     if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
1161         (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
1162     {
1163         if (_ILIsEmpty(pidl)) {
1164             lpName->uType = STRRET_WSTR;
1165             if (This->m_dwPathMode == PATHMODE_UNIX) {
1166                 UINT len = MultiByteToWideChar(CP_UNIXCP, 0, This->m_pszPath, -1, NULL, 0);
1167                 lpName->u.pOleStr = SHAlloc(len * sizeof(WCHAR));
1168                 if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
1169                 MultiByteToWideChar(CP_UNIXCP, 0, This->m_pszPath, -1, lpName->u.pOleStr, len);
1170             } else {
1171                 LPWSTR pwszDosFileName = wine_get_dos_file_name(This->m_pszPath);
1172                 if (!pwszDosFileName) return HRESULT_FROM_WIN32(GetLastError());
1173                 lpName->u.pOleStr = SHAlloc((lstrlenW(pwszDosFileName) + 1) * sizeof(WCHAR));
1174                 if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
1175                 lstrcpyW(lpName->u.pOleStr, pwszDosFileName);
1176                 PathRemoveBackslashW(lpName->u.pOleStr);
1177                 HeapFree(GetProcessHeap(), 0, pwszDosFileName);
1178             }
1179         } else {
1180             IShellFolder *pSubFolder;
1181             SHITEMID emptyIDL = { 0, { 0 } };
1182
1183             hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
1184             if (FAILED(hr)) return hr;
1185
1186             hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
1187             IShellFolder_Release(pSubFolder);
1188         }
1189     } else {
1190         WCHAR wszFileName[MAX_PATH];
1191         if (!_ILSimpleGetTextW(pidl, wszFileName, MAX_PATH)) return E_INVALIDARG;
1192         lpName->uType = STRRET_WSTR;
1193         lpName->u.pOleStr = SHAlloc((lstrlenW(wszFileName)+1)*sizeof(WCHAR));
1194         if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
1195         lstrcpyW(lpName->u.pOleStr, wszFileName);
1196         if (!(GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) && This->m_dwPathMode == PATHMODE_DOS && 
1197             !_ILIsFolder(pidl) && wszFileName[0] != '.' && SHELL_FS_HideExtension(wszFileName))
1198         {
1199             PathRemoveExtensionW(lpName->u.pOleStr);
1200         }
1201     }
1202
1203     TRACE("--> %s\n", debugstr_w(lpName->u.pOleStr));
1204     
1205     return hr;
1206 }
1207
1208 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd, 
1209     LPCITEMIDLIST pidl, LPCOLESTR lpcwszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
1210 {
1211     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1212
1213     static const WCHAR awcInvalidChars[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
1214     char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
1215     WCHAR wszSrcRelative[MAX_PATH], *pwszExt = NULL;
1216     unsigned int i;
1217     int cBasePathLen = lstrlenA(This->m_pszPath), cNameLen;
1218     struct stat statDest;
1219     LPITEMIDLIST pidlSrc, pidlDest, pidlRelativeDest;
1220     LPOLESTR lpwszName;
1221     HRESULT hr;
1222    
1223     TRACE("(iface=%p, hwnd=%p, pidl=%p, lpcwszName=%s, uFlags=0x%08x, ppidlOut=%p)\n",
1224           iface, hwnd, pidl, debugstr_w(lpcwszName), uFlags, ppidlOut); 
1225
1226     /* prepare to fail */
1227     if (ppidlOut)
1228         *ppidlOut = NULL;
1229     
1230     /* pidl has to contain a single non-empty SHITEMID */
1231     if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
1232         return E_INVALIDARG;
1233  
1234     /* check for invalid characters in lpcwszName. */
1235     for (i=0; i < sizeof(awcInvalidChars)/sizeof(*awcInvalidChars); i++)
1236         if (StrChrW(lpcwszName, awcInvalidChars[i]))
1237             return HRESULT_FROM_WIN32(ERROR_CANCELLED);
1238
1239     /* build source path */
1240     memcpy(szSrc, This->m_pszPath, cBasePathLen);
1241     UNIXFS_filename_from_shitemid(pidl, szSrc + cBasePathLen);
1242
1243     /* build destination path */
1244     memcpy(szDest, This->m_pszPath, cBasePathLen);
1245     WideCharToMultiByte(CP_UNIXCP, 0, lpcwszName, -1, szDest+cBasePathLen, 
1246                         FILENAME_MAX-cBasePathLen, NULL, NULL);
1247
1248     /* If the filename's extension is hidden to the user, we have to append it. */
1249     if (!(uFlags & SHGDN_FORPARSING) && 
1250         _ILSimpleGetTextW(pidl, wszSrcRelative, MAX_PATH) && 
1251         SHELL_FS_HideExtension(wszSrcRelative))
1252     {
1253         int cLenDest = strlen(szDest);
1254         pwszExt = PathFindExtensionW(wszSrcRelative);
1255         WideCharToMultiByte(CP_UNIXCP, 0, pwszExt, -1, szDest + cLenDest, 
1256             FILENAME_MAX - cLenDest, NULL, NULL);
1257     }
1258
1259     TRACE("src=%s dest=%s\n", szSrc, szDest);
1260
1261     /* Fail, if destination does already exist */
1262     if (!stat(szDest, &statDest)) 
1263         return E_FAIL;
1264
1265     /* Rename the file */
1266     if (rename(szSrc, szDest)) 
1267         return E_FAIL;
1268     
1269     /* Build a pidl for the path of the renamed file */
1270     cNameLen = lstrlenW(lpcwszName) + 1;
1271     if(pwszExt)
1272         cNameLen += lstrlenW(pwszExt);
1273     lpwszName = SHAlloc(cNameLen*sizeof(WCHAR)); /* due to const correctness. */
1274     lstrcpyW(lpwszName, lpcwszName);
1275     if(pwszExt)
1276         lstrcatW(lpwszName, pwszExt);
1277
1278     hr = IShellFolder2_ParseDisplayName(iface, NULL, NULL, lpwszName, NULL, &pidlRelativeDest, NULL);
1279     SHFree(lpwszName);
1280     if (FAILED(hr)) {
1281         rename(szDest, szSrc); /* Undo the renaming */
1282         return E_FAIL;
1283     }
1284     pidlDest = ILCombine(This->m_pidlLocation, pidlRelativeDest);
1285     ILFree(pidlRelativeDest);
1286     pidlSrc = ILCombine(This->m_pidlLocation, pidl);
1287     
1288     /* Inform the shell */
1289     if (_ILIsFolder(ILFindLastID(pidlDest))) 
1290         SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
1291     else 
1292         SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
1293     
1294     if (ppidlOut) 
1295         *ppidlOut = ILClone(ILFindLastID(pidlDest));
1296         
1297     ILFree(pidlSrc);
1298     ILFree(pidlDest);
1299     
1300     return S_OK;
1301 }
1302
1303 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface, 
1304     IEnumExtraSearch **ppEnum) 
1305 {
1306     FIXME("stub\n");
1307     return E_NOTIMPL;
1308 }
1309
1310 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface, 
1311     DWORD dwReserved, ULONG *pSort, ULONG *pDisplay) 
1312 {
1313     TRACE("(iface=%p,dwReserved=%x,pSort=%p,pDisplay=%p)\n", iface, dwReserved, pSort, pDisplay);
1314
1315     if (pSort)
1316         *pSort = 0;
1317     if (pDisplay)
1318         *pDisplay = 0;
1319
1320     return S_OK;
1321 }
1322
1323 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface, 
1324     UINT iColumn, SHCOLSTATEF *pcsFlags)
1325 {
1326     FIXME("stub\n");
1327     return E_NOTIMPL;
1328 }
1329
1330 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface, 
1331     GUID *pguid)
1332 {
1333     FIXME("stub\n");
1334     return E_NOTIMPL;
1335 }
1336
1337 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface, 
1338     LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1339 {
1340     FIXME("stub\n");
1341     return E_NOTIMPL;
1342 }
1343
1344 #define SHELLVIEWCOLUMNS 7 
1345
1346 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface, 
1347     LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1348 {
1349     UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1350     HRESULT hr = E_FAIL;
1351     struct passwd *pPasswd;
1352     struct group *pGroup;
1353     struct stat statItem;
1354
1355     static const shvheader unixfs_header[SHELLVIEWCOLUMNS] = {
1356         {IDS_SHV_COLUMN1,  SHCOLSTATE_TYPE_STR  | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1357         {IDS_SHV_COLUMN2,  SHCOLSTATE_TYPE_STR  | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1358         {IDS_SHV_COLUMN3,  SHCOLSTATE_TYPE_STR  | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1359         {IDS_SHV_COLUMN4,  SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
1360         {IDS_SHV_COLUMN5,  SHCOLSTATE_TYPE_STR  | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 9},
1361         {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR  | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1362         {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR  | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7}
1363     };
1364
1365     TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1366     
1367     if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1368         return E_INVALIDARG;
1369
1370     if (!pidl)
1371         return SHELL32_GetColumnDetails(unixfs_header, iColumn, psd);
1372
1373     if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
1374         char szPath[FILENAME_MAX];
1375         strcpy(szPath, This->m_pszPath);
1376         if (!UNIXFS_filename_from_shitemid(pidl, szPath + strlen(szPath)))
1377             return E_INVALIDARG;
1378         if (stat(szPath, &statItem))
1379             return E_INVALIDARG;
1380     }
1381
1382     psd->str.u.cStr[0] = '\0';
1383     psd->str.uType = STRRET_CSTR;
1384
1385     switch (iColumn) {
1386         case 0:
1387             hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1388             break;
1389         case 1:
1390             _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1391             break;
1392         case 2:
1393             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1394             break;
1395         case 3:
1396             _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1397             break;
1398         case 4:
1399             psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
1400             psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
1401             psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
1402             psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
1403             psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
1404             psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
1405             psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
1406             psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
1407             psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
1408             psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
1409             psd->str.u.cStr[10] = '\0';
1410             break;
1411         case 5:
1412             pPasswd = getpwuid(statItem.st_uid);
1413             if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1414             break;
1415         case 6:
1416             pGroup = getgrgid(statItem.st_gid);
1417             if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1418             break;
1419     }
1420     
1421     return hr;
1422 }
1423
1424 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1425     SHCOLUMNID *pscid) 
1426 {
1427     FIXME("stub\n");
1428     return E_NOTIMPL;
1429 }
1430
1431 /* VTable for UnixFolder's IShellFolder2 interface.
1432  */
1433 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1434     UnixFolder_IShellFolder2_QueryInterface,
1435     UnixFolder_IShellFolder2_AddRef,
1436     UnixFolder_IShellFolder2_Release,
1437     UnixFolder_IShellFolder2_ParseDisplayName,
1438     UnixFolder_IShellFolder2_EnumObjects,
1439     UnixFolder_IShellFolder2_BindToObject,
1440     UnixFolder_IShellFolder2_BindToStorage,
1441     UnixFolder_IShellFolder2_CompareIDs,
1442     UnixFolder_IShellFolder2_CreateViewObject,
1443     UnixFolder_IShellFolder2_GetAttributesOf,
1444     UnixFolder_IShellFolder2_GetUIObjectOf,
1445     UnixFolder_IShellFolder2_GetDisplayNameOf,
1446     UnixFolder_IShellFolder2_SetNameOf,
1447     UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1448     UnixFolder_IShellFolder2_EnumSearches,
1449     UnixFolder_IShellFolder2_GetDefaultColumn,
1450     UnixFolder_IShellFolder2_GetDefaultColumnState,
1451     UnixFolder_IShellFolder2_GetDetailsEx,
1452     UnixFolder_IShellFolder2_GetDetailsOf,
1453     UnixFolder_IShellFolder2_MapColumnToSCID
1454 };
1455
1456 static HRESULT WINAPI UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3* iface, REFIID riid, 
1457     void** ppvObject)
1458 {
1459     return UnixFolder_IShellFolder2_QueryInterface(
1460         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)), riid, ppvObject);
1461 }
1462
1463 static ULONG WINAPI UnixFolder_IPersistFolder3_AddRef(IPersistFolder3* iface)
1464 {
1465     return UnixFolder_IShellFolder2_AddRef(
1466         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)));
1467 }
1468
1469 static ULONG WINAPI UnixFolder_IPersistFolder3_Release(IPersistFolder3* iface)
1470 {
1471     return UnixFolder_IShellFolder2_Release(
1472         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)));
1473 }
1474
1475 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3* iface, CLSID* pClassID)
1476 {    
1477     UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1478     
1479     TRACE("(iface=%p, pClassId=%p)\n", iface, pClassID);
1480     
1481     if (!pClassID)
1482         return E_INVALIDARG;
1483
1484     *pClassID = *This->m_pCLSID;
1485     return S_OK;
1486 }
1487
1488 static HRESULT WINAPI UnixFolder_IPersistFolder3_Initialize(IPersistFolder3* iface, LPCITEMIDLIST pidl)
1489 {
1490     UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1491     LPCITEMIDLIST current = pidl;
1492     char szBasePath[FILENAME_MAX] = "/";
1493     
1494     TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1495
1496     /* Find the UnixFolderClass root */
1497     while (current->mkid.cb) {
1498         if ((_ILIsDrive(current) && IsEqualCLSID(This->m_pCLSID, &CLSID_ShellFSFolder)) ||
1499             (_ILIsSpecialFolder(current) && IsEqualCLSID(This->m_pCLSID, _ILGetGUIDPointer(current))))
1500         {
1501             break;
1502         }
1503         current = ILGetNext(current);
1504     }
1505
1506     if (current->mkid.cb) {
1507         if (_ILIsDrive(current)) {
1508             WCHAR wszDrive[4] = { '?', ':', '\\', 0 };
1509             wszDrive[0] = (WCHAR)*_ILGetTextPointer(current);
1510             if (!UNIXFS_get_unix_path(wszDrive, szBasePath))
1511                 return E_FAIL;
1512         } else if (IsEqualIID(&CLSID_MyDocuments, _ILGetGUIDPointer(current))) {
1513             WCHAR wszMyDocumentsPath[MAX_PATH];
1514             if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath, CSIDL_PERSONAL, FALSE))
1515                 return E_FAIL;
1516             PathAddBackslashW(wszMyDocumentsPath);
1517             if (!UNIXFS_get_unix_path(wszMyDocumentsPath, szBasePath))
1518                 return E_FAIL;
1519         } 
1520         current = ILGetNext(current);
1521     } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
1522         /* Path rooted at Desktop */
1523         WCHAR wszDesktopPath[MAX_PATH];
1524         if (!SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE)) 
1525             return E_FAIL;
1526         PathAddBackslashW(wszDesktopPath);
1527         if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
1528             return E_FAIL;
1529         current = pidl;
1530     } else if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
1531         /* FolderShortcuts' Initialize method only sets the ITEMIDLIST, which
1532          * specifies the location in the shell namespace, but leaves the
1533          * target folder (m_pszPath) alone. See unit tests in tests/shlfolder.c */
1534         This->m_pidlLocation = ILClone(pidl);
1535         return S_OK;
1536     } else {
1537         ERR("Unknown pidl type!\n");
1538         pdump(pidl);
1539         return E_INVALIDARG;
1540     }
1541   
1542     This->m_pidlLocation = ILClone(pidl);
1543     return UNIXFS_initialize_target_folder(This, szBasePath, current, 0); 
1544 }
1545
1546 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3* iface, LPITEMIDLIST* ppidl)
1547 {
1548     UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1549     
1550     TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1551
1552     if (!ppidl)
1553         return E_POINTER;
1554     *ppidl = ILClone (This->m_pidlLocation);
1555     return S_OK;
1556 }
1557
1558 static HRESULT WINAPI UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3 *iface, IBindCtx *pbc, 
1559     LPCITEMIDLIST pidlRoot, const PERSIST_FOLDER_TARGET_INFO *ppfti)
1560 {
1561     UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1562     WCHAR wszTargetDosPath[MAX_PATH];
1563     char szTargetPath[FILENAME_MAX] = "";
1564     
1565     TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface, pbc, pidlRoot, ppfti);
1566
1567     /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1568     if (!ppfti) 
1569         return IPersistFolder3_Initialize(iface, pidlRoot);
1570
1571     if (ppfti->csidl != -1) {
1572         if (FAILED(SHGetFolderPathW(0, ppfti->csidl, NULL, 0, wszTargetDosPath)) ||
1573             !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1574         {
1575             return E_FAIL;
1576         }
1577     } else if (*ppfti->szTargetParsingName) {
1578         lstrcpyW(wszTargetDosPath, ppfti->szTargetParsingName);
1579         PathAddBackslashW(wszTargetDosPath);
1580         if (!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath)) {
1581             return E_FAIL;
1582         }
1583     } else if (ppfti->pidlTargetFolder) {
1584         if (!SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTargetDosPath) ||
1585             !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1586         {
1587             return E_FAIL;
1588         }
1589     } else {
1590         return E_FAIL;
1591     }
1592
1593     This->m_pszPath = SHAlloc(lstrlenA(szTargetPath)+1);
1594     if (!This->m_pszPath) 
1595         return E_FAIL;
1596     lstrcpyA(This->m_pszPath, szTargetPath);
1597     This->m_pidlLocation = ILClone(pidlRoot);
1598     This->m_dwAttributes = (ppfti->dwAttributes != -1) ? ppfti->dwAttributes :
1599         (SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|SFGAO_FILESYSTEM);
1600
1601     return S_OK;
1602 }
1603
1604 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3 *iface, 
1605     PERSIST_FOLDER_TARGET_INFO *ppfti)
1606 {
1607     FIXME("(iface=%p, ppfti=%p) stub\n", iface, ppfti);
1608     return E_NOTIMPL;
1609 }
1610
1611 /* VTable for UnixFolder's IPersistFolder interface.
1612  */
1613 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl = {
1614     UnixFolder_IPersistFolder3_QueryInterface,
1615     UnixFolder_IPersistFolder3_AddRef,
1616     UnixFolder_IPersistFolder3_Release,
1617     UnixFolder_IPersistFolder3_GetClassID,
1618     UnixFolder_IPersistFolder3_Initialize,
1619     UnixFolder_IPersistFolder3_GetCurFolder,
1620     UnixFolder_IPersistFolder3_InitializeEx,
1621     UnixFolder_IPersistFolder3_GetFolderTargetInfo
1622 };
1623
1624 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag* iface,
1625     REFIID riid, void** ppv)
1626 {
1627     return UnixFolder_IShellFolder2_QueryInterface(
1628         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)), riid, ppv);
1629 }
1630
1631 static ULONG WINAPI UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag* iface)
1632 {
1633     return UnixFolder_IShellFolder2_AddRef(
1634         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)));
1635 }
1636
1637 static ULONG WINAPI UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag* iface)
1638 {
1639     return UnixFolder_IShellFolder2_Release(
1640         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)));
1641 }
1642
1643 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag* iface, 
1644     CLSID* pClassID)
1645 {
1646     return UnixFolder_IPersistFolder3_GetClassID(
1647         STATIC_CAST(IPersistFolder3, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)), pClassID);
1648 }
1649
1650 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag* iface)
1651 {
1652     FIXME("() stub\n");
1653     return E_NOTIMPL;
1654 }
1655
1656 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag *iface, 
1657     IPropertyBag *pPropertyBag, IErrorLog *pErrorLog)
1658 {
1659      UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface);
1660      static const WCHAR wszTarget[] = { 'T','a','r','g','e','t', 0 }, wszNull[] = { 0 };
1661      PERSIST_FOLDER_TARGET_INFO pftiTarget;
1662      VARIANT var;
1663      HRESULT hr;
1664      
1665      TRACE("(iface=%p, pPropertyBag=%p, pErrorLog=%p)\n", iface, pPropertyBag, pErrorLog);
1666  
1667      if (!pPropertyBag)
1668          return E_POINTER;
1669  
1670      /* Get 'Target' property from the property bag. */
1671      V_VT(&var) = VT_BSTR;
1672      hr = IPropertyBag_Read(pPropertyBag, wszTarget, &var, NULL);
1673      if (FAILED(hr)) 
1674          return E_FAIL;
1675      lstrcpyW(pftiTarget.szTargetParsingName, V_BSTR(&var));
1676      SysFreeString(V_BSTR(&var));
1677  
1678      pftiTarget.pidlTargetFolder = NULL;
1679      lstrcpyW(pftiTarget.szNetworkProvider, wszNull);
1680      pftiTarget.dwAttributes = -1;
1681      pftiTarget.csidl = -1;
1682  
1683      return UnixFolder_IPersistFolder3_InitializeEx(
1684                  STATIC_CAST(IPersistFolder3, This), NULL, NULL, &pftiTarget);
1685 }
1686
1687 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag *iface,
1688     IPropertyBag *pPropertyBag, BOOL fClearDirty, BOOL fSaveAllProperties)
1689 {
1690     FIXME("() stub\n");
1691     return E_NOTIMPL;
1692 }
1693
1694 /* VTable for UnixFolder's IPersistPropertyBag interface.
1695  */
1696 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl = {
1697     UnixFolder_IPersistPropertyBag_QueryInterface,
1698     UnixFolder_IPersistPropertyBag_AddRef,
1699     UnixFolder_IPersistPropertyBag_Release,
1700     UnixFolder_IPersistPropertyBag_GetClassID,
1701     UnixFolder_IPersistPropertyBag_InitNew,
1702     UnixFolder_IPersistPropertyBag_Load,
1703     UnixFolder_IPersistPropertyBag_Save
1704 };
1705
1706 static HRESULT WINAPI UnixFolder_ISFHelper_QueryInterface(ISFHelper* iface, REFIID riid, 
1707     void** ppvObject)
1708 {
1709     return UnixFolder_IShellFolder2_QueryInterface(
1710         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)), riid, ppvObject);
1711 }
1712
1713 static ULONG WINAPI UnixFolder_ISFHelper_AddRef(ISFHelper* iface)
1714 {
1715     return UnixFolder_IShellFolder2_AddRef(
1716         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)));
1717 }
1718
1719 static ULONG WINAPI UnixFolder_ISFHelper_Release(ISFHelper* iface)
1720 {
1721     return UnixFolder_IShellFolder2_Release(
1722         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)));
1723 }
1724
1725 static HRESULT WINAPI UnixFolder_ISFHelper_GetUniqueName(ISFHelper* iface, LPWSTR pwszName, UINT uLen)
1726 {
1727     UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1728     IEnumIDList *pEnum;
1729     HRESULT hr;
1730     LPITEMIDLIST pidlElem;
1731     DWORD dwFetched;
1732     int i;
1733     WCHAR wszNewFolder[25];
1734     static const WCHAR wszFormat[] = { '%','s',' ','%','d',0 };
1735
1736     TRACE("(iface=%p, pwszName=%p, uLen=%u)\n", iface, pwszName, uLen);
1737
1738     LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, sizeof(wszNewFolder)/sizeof(WCHAR));
1739
1740     if (uLen < sizeof(wszNewFolder)/sizeof(WCHAR)+3)
1741         return E_INVALIDARG;
1742
1743     hr = IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2, This), 0,
1744                                    SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
1745     if (SUCCEEDED(hr)) {
1746         lstrcpynW(pwszName, wszNewFolder, uLen);
1747         IEnumIDList_Reset(pEnum);
1748         i = 2;
1749         while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
1750             WCHAR wszTemp[MAX_PATH];
1751             _ILSimpleGetTextW(pidlElem, wszTemp, MAX_PATH);
1752             if (!lstrcmpiW(wszTemp, pwszName)) {
1753                 IEnumIDList_Reset(pEnum);
1754                 snprintfW(pwszName, uLen, wszFormat, wszNewFolder, i++);
1755                 if (i > 99) {
1756                     hr = E_FAIL;
1757                     break;
1758                 }
1759             }
1760         }
1761         IEnumIDList_Release(pEnum);
1762     }
1763     return hr;
1764 }
1765
1766 static HRESULT WINAPI UnixFolder_ISFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCWSTR pwszName, 
1767     LPITEMIDLIST* ppidlOut)
1768 {
1769     UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1770     char szNewDir[FILENAME_MAX];
1771     int cBaseLen;
1772
1773     TRACE("(iface=%p, hwnd=%p, pwszName=%s, ppidlOut=%p)\n", 
1774             iface, hwnd, debugstr_w(pwszName), ppidlOut);
1775
1776     if (ppidlOut)
1777         *ppidlOut = NULL;
1778
1779     if (!This->m_pszPath || !(This->m_dwAttributes & SFGAO_FILESYSTEM))
1780         return E_FAIL;
1781     
1782     lstrcpynA(szNewDir, This->m_pszPath, FILENAME_MAX);
1783     cBaseLen = lstrlenA(szNewDir);
1784     WideCharToMultiByte(CP_UNIXCP, 0, pwszName, -1, szNewDir+cBaseLen, FILENAME_MAX-cBaseLen, 0, 0);
1785    
1786     if (mkdir(szNewDir, 0777)) {
1787         char szMessage[256 + FILENAME_MAX];
1788         char szCaption[256];
1789
1790         LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
1791         sprintf(szMessage, szCaption, szNewDir);
1792         LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
1793         MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
1794
1795         return E_FAIL;
1796     } else {
1797         LPITEMIDLIST pidlRelative;
1798
1799         /* Inform the shell */
1800         if (SUCCEEDED(UNIXFS_path_to_pidl(This, NULL, pwszName, &pidlRelative))) {
1801             LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
1802             if (ppidlOut)
1803                 *ppidlOut = pidlRelative;
1804             else
1805                 ILFree(pidlRelative);
1806             SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1807             ILFree(pidlAbsolute);
1808         } else return E_FAIL;
1809         return S_OK;
1810     }
1811 }
1812
1813 /*
1814  * Delete specified files by converting the path to DOS paths and calling
1815  * SHFileOperationW. If an error occurs it returns an error code. If the paths can't
1816  * be converted, S_FALSE is returned. In such situation DeleteItems will try to delete
1817  * the files using syscalls
1818  */
1819 static HRESULT UNIXFS_delete_with_shfileop(UnixFolder *This, UINT cidl, const LPCITEMIDLIST *apidl)
1820 {
1821     char szAbsolute[FILENAME_MAX], *pszRelative;
1822     LPWSTR wszPathsList, wszListPos;
1823     SHFILEOPSTRUCTW op;
1824     HRESULT ret;
1825     UINT i;
1826     
1827     lstrcpyA(szAbsolute, This->m_pszPath);
1828     pszRelative = szAbsolute + lstrlenA(szAbsolute);
1829     
1830     wszListPos = wszPathsList = HeapAlloc(GetProcessHeap(), 0, cidl*MAX_PATH*sizeof(WCHAR)+1);
1831     if (wszPathsList == NULL)
1832         return E_OUTOFMEMORY;
1833     for (i=0; i<cidl; i++) {
1834         LPWSTR wszDosPath;
1835         
1836         if (!_ILIsFolder(apidl[i]) && !_ILIsValue(apidl[i]))
1837             continue;
1838         if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
1839         {
1840             HeapFree(GetProcessHeap(), 0, wszPathsList);
1841             return E_INVALIDARG;
1842         }
1843         wszDosPath = wine_get_dos_file_name(szAbsolute);
1844         if (wszDosPath == NULL || lstrlenW(wszDosPath) >= MAX_PATH)
1845         {
1846             HeapFree(GetProcessHeap(), 0, wszPathsList);
1847             HeapFree(GetProcessHeap(), 0, wszDosPath);
1848             return S_FALSE;
1849         }
1850         lstrcpyW(wszListPos, wszDosPath);
1851         wszListPos += lstrlenW(wszListPos)+1;
1852         HeapFree(GetProcessHeap(), 0, wszDosPath);
1853     }
1854     *wszListPos = 0;
1855     
1856     ZeroMemory(&op, sizeof(op));
1857     op.hwnd = GetActiveWindow();
1858     op.wFunc = FO_DELETE;
1859     op.pFrom = wszPathsList;
1860     op.fFlags = FOF_ALLOWUNDO;
1861     if (!SHFileOperationW(&op))
1862     {
1863         WARN("SHFileOperationW failed\n");
1864         ret = E_FAIL;
1865     }
1866     else
1867         ret = S_OK;
1868
1869     HeapFree(GetProcessHeap(), 0, wszPathsList);
1870     return ret;
1871 }
1872
1873 static HRESULT UNIXFS_delete_with_syscalls(UnixFolder *This, UINT cidl, const LPCITEMIDLIST *apidl)
1874 {
1875     char szAbsolute[FILENAME_MAX], *pszRelative;
1876     static const WCHAR empty[] = {0};
1877     UINT i;
1878     
1879     if (!SHELL_ConfirmYesNoW(GetActiveWindow(), ASK_DELETE_SELECTED, empty))
1880         return S_OK;
1881     
1882     lstrcpyA(szAbsolute, This->m_pszPath);
1883     pszRelative = szAbsolute + lstrlenA(szAbsolute);
1884     
1885     for (i=0; i<cidl; i++) {
1886         if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
1887             return E_INVALIDARG;
1888         if (_ILIsFolder(apidl[i])) {
1889             if (rmdir(szAbsolute))
1890                 return E_FAIL;
1891         } else if (_ILIsValue(apidl[i])) {
1892             if (unlink(szAbsolute))
1893                 return E_FAIL;
1894         }
1895     }
1896     return S_OK;
1897 }
1898
1899 static HRESULT WINAPI UnixFolder_ISFHelper_DeleteItems(ISFHelper* iface, UINT cidl, 
1900     LPCITEMIDLIST* apidl)
1901 {
1902     UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1903     char szAbsolute[FILENAME_MAX], *pszRelative;
1904     LPITEMIDLIST pidlAbsolute;
1905     HRESULT hr = S_OK;
1906     UINT i;
1907     struct stat st;
1908     
1909     TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface, cidl, apidl);
1910
1911     hr = UNIXFS_delete_with_shfileop(This, cidl, apidl);
1912     if (hr == S_FALSE)
1913         hr = UNIXFS_delete_with_syscalls(This, cidl, apidl);
1914
1915     lstrcpyA(szAbsolute, This->m_pszPath);
1916     pszRelative = szAbsolute + lstrlenA(szAbsolute);
1917     
1918     /* we need to manually send the notifies if the files doesn't exist */
1919     for (i=0; i<cidl; i++) {
1920         if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
1921             continue;
1922         pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
1923         if (stat(szAbsolute, &st))
1924         {
1925             if (_ILIsFolder(apidl[i])) {
1926                 SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1927             } else if (_ILIsValue(apidl[i])) {
1928                 SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
1929             }
1930         }
1931         ILFree(pidlAbsolute);
1932     }
1933         
1934     return hr;
1935 }
1936
1937 static HRESULT WINAPI UnixFolder_ISFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom, 
1938     UINT cidl, LPCITEMIDLIST *apidl)
1939 {
1940     UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1941     DWORD dwAttributes;
1942     UINT i;
1943     HRESULT hr;
1944     char szAbsoluteDst[FILENAME_MAX], *pszRelativeDst;
1945     
1946     TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p)\n", iface, psfFrom, cidl, apidl);
1947
1948     if (!psfFrom || !cidl || !apidl)
1949         return E_INVALIDARG;
1950
1951     /* All source items have to be filesystem items. */
1952     dwAttributes = SFGAO_FILESYSTEM;
1953     hr = IShellFolder_GetAttributesOf(psfFrom, cidl, apidl, &dwAttributes);
1954     if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) 
1955         return E_INVALIDARG;
1956
1957     lstrcpyA(szAbsoluteDst, This->m_pszPath);
1958     pszRelativeDst = szAbsoluteDst + strlen(szAbsoluteDst);
1959     
1960     for (i=0; i<cidl; i++) {
1961         WCHAR wszSrc[MAX_PATH];
1962         char szSrc[FILENAME_MAX];
1963         STRRET strret;
1964         HRESULT res;
1965         WCHAR *pwszDosSrc, *pwszDosDst;
1966
1967         /* Build the unix path of the current source item. */
1968         if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom, apidl[i], SHGDN_FORPARSING, &strret)))
1969             return E_FAIL;
1970         if (FAILED(StrRetToBufW(&strret, apidl[i], wszSrc, MAX_PATH)))
1971             return E_FAIL;
1972         if (!UNIXFS_get_unix_path(wszSrc, szSrc)) 
1973             return E_FAIL;
1974
1975         /* Build the unix path of the current destination item */
1976         UNIXFS_filename_from_shitemid(apidl[i], pszRelativeDst);
1977
1978         pwszDosSrc = wine_get_dos_file_name(szSrc);
1979         pwszDosDst = wine_get_dos_file_name(szAbsoluteDst);
1980
1981         if (pwszDosSrc && pwszDosDst)
1982             res = UNIXFS_copy(pwszDosSrc, pwszDosDst);
1983         else
1984             res = E_OUTOFMEMORY;
1985
1986         HeapFree(GetProcessHeap(), 0, pwszDosSrc);
1987         HeapFree(GetProcessHeap(), 0, pwszDosDst);
1988
1989         if (res != S_OK)
1990             return res;
1991     }
1992     return S_OK;
1993 }
1994
1995 /* VTable for UnixFolder's ISFHelper interface
1996  */
1997 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl = {
1998     UnixFolder_ISFHelper_QueryInterface,
1999     UnixFolder_ISFHelper_AddRef,
2000     UnixFolder_ISFHelper_Release,
2001     UnixFolder_ISFHelper_GetUniqueName,
2002     UnixFolder_ISFHelper_AddFolder,
2003     UnixFolder_ISFHelper_DeleteItems,
2004     UnixFolder_ISFHelper_CopyItems
2005 };
2006
2007 static HRESULT WINAPI UnixFolder_IDropTarget_QueryInterface(IDropTarget* iface, REFIID riid, 
2008     void** ppvObject)
2009 {
2010     return UnixFolder_IShellFolder2_QueryInterface(
2011         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)), riid, ppvObject);
2012 }
2013
2014 static ULONG WINAPI UnixFolder_IDropTarget_AddRef(IDropTarget* iface)
2015 {
2016     return UnixFolder_IShellFolder2_AddRef(
2017         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)));
2018 }
2019
2020 static ULONG WINAPI UnixFolder_IDropTarget_Release(IDropTarget* iface)
2021 {
2022     return UnixFolder_IShellFolder2_Release(
2023         STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)));
2024 }
2025
2026 #define HIDA_GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
2027 #define HIDA_GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
2028
2029 static HRESULT WINAPI UnixFolder_IDropTarget_DragEnter(IDropTarget *iface, IDataObject *pDataObject,
2030     DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
2031 {
2032     UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
2033     FORMATETC format;
2034     STGMEDIUM medium; 
2035         
2036     TRACE("(iface=%p, pDataObject=%p, dwKeyState=%08x, pt={.x=%d, .y=%d}, pdwEffect=%p)\n",
2037         iface, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
2038
2039     if (!pdwEffect || !pDataObject)
2040         return E_INVALIDARG;
2041   
2042     /* Compute a mask of supported drop-effects for this shellfolder object and the given data 
2043      * object. Dropping is only supported on folders, which represent filesystem locations. One
2044      * can't drop on file objects. And the 'move' drop effect is only supported, if the source
2045      * folder is not identical to the target folder. */
2046     This->m_dwDropEffectsMask = DROPEFFECT_NONE;
2047     InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
2048     if ((This->m_dwAttributes & SFGAO_FILESYSTEM) && /* Only drop to filesystem folders */
2049         _ILIsFolder(ILFindLastID(This->m_pidlLocation)) && /* Only drop to folders, not to files */
2050         SUCCEEDED(IDataObject_GetData(pDataObject, &format, &medium))) /* Only ShellIDList format */
2051     {
2052         LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
2053         This->m_dwDropEffectsMask |= DROPEFFECT_COPY|DROPEFFECT_LINK;
2054
2055         if (pidaShellIDList) { /* Files can only be moved between two different folders */
2056             if (!ILIsEqual(HIDA_GetPIDLFolder(pidaShellIDList), This->m_pidlLocation))
2057                 This->m_dwDropEffectsMask |= DROPEFFECT_MOVE;
2058             GlobalUnlock(medium.u.hGlobal);
2059         }
2060     }
2061
2062     *pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
2063     
2064     return S_OK;
2065 }
2066
2067 static HRESULT WINAPI UnixFolder_IDropTarget_DragOver(IDropTarget *iface, DWORD dwKeyState, 
2068     POINTL pt, DWORD *pdwEffect)
2069 {
2070     UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
2071     
2072     TRACE("(iface=%p, dwKeyState=%08x, pt={.x=%d, .y=%d}, pdwEffect=%p)\n", iface, dwKeyState, 
2073         pt.x, pt.y, pdwEffect);
2074
2075     if (!pdwEffect)
2076         return E_INVALIDARG;
2077
2078     *pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
2079     
2080     return S_OK;
2081 }
2082
2083 static HRESULT WINAPI UnixFolder_IDropTarget_DragLeave(IDropTarget *iface) {
2084     UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
2085     
2086     TRACE("(iface=%p)\n", iface);
2087  
2088     This->m_dwDropEffectsMask = DROPEFFECT_NONE;
2089     
2090     return S_OK;
2091 }
2092
2093 static HRESULT WINAPI UnixFolder_IDropTarget_Drop(IDropTarget *iface, IDataObject *pDataObject,
2094     DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
2095 {
2096     UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
2097     FORMATETC format;
2098     STGMEDIUM medium; 
2099     HRESULT hr;
2100
2101     TRACE("(iface=%p, pDataObject=%p, dwKeyState=%d, pt={.x=%d, .y=%d}, pdwEffect=%p) semi-stub\n",
2102         iface, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
2103
2104     InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
2105     hr = IDataObject_GetData(pDataObject, &format, &medium);
2106     if (FAILED(hr))
2107         return hr;
2108
2109     if (medium.tymed == TYMED_HGLOBAL) {
2110         IShellFolder *psfSourceFolder, *psfDesktopFolder;
2111         LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
2112         STRRET strret;
2113         UINT i;
2114     
2115         if (!pidaShellIDList) 
2116             return HRESULT_FROM_WIN32(GetLastError());
2117         
2118         hr = SHGetDesktopFolder(&psfDesktopFolder);
2119         if (FAILED(hr)) {
2120             GlobalUnlock(medium.u.hGlobal);
2121             return hr;
2122         }
2123
2124         hr = IShellFolder_BindToObject(psfDesktopFolder, HIDA_GetPIDLFolder(pidaShellIDList), NULL, 
2125                                        &IID_IShellFolder, (LPVOID*)&psfSourceFolder);
2126         IShellFolder_Release(psfDesktopFolder);
2127         if (FAILED(hr)) {
2128             GlobalUnlock(medium.u.hGlobal);
2129             return hr;
2130         }
2131
2132         for (i = 0; i < pidaShellIDList->cidl; i++) {
2133             WCHAR wszSourcePath[MAX_PATH];
2134
2135             hr = IShellFolder_GetDisplayNameOf(psfSourceFolder, HIDA_GetPIDLItem(pidaShellIDList, i),
2136                                                SHGDN_FORPARSING, &strret);
2137             if (FAILED(hr)) 
2138                 break;
2139
2140             hr = StrRetToBufW(&strret, NULL, wszSourcePath, MAX_PATH);
2141             if (FAILED(hr)) 
2142                 break;
2143
2144             switch (*pdwEffect) {
2145                 case DROPEFFECT_MOVE:
2146                     FIXME("Move %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
2147                     break;
2148                 case DROPEFFECT_COPY:
2149                     FIXME("Copy %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
2150                     break;
2151                 case DROPEFFECT_LINK:
2152                     FIXME("Link %s from %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
2153                     break;
2154             }
2155         }
2156     
2157         IShellFolder_Release(psfSourceFolder);
2158         GlobalUnlock(medium.u.hGlobal);
2159         return hr;
2160     }
2161  
2162     return E_NOTIMPL;
2163 }
2164
2165 /* VTable for UnixFolder's IDropTarget interface
2166  */
2167 static const IDropTargetVtbl UnixFolder_IDropTarget_Vtbl = {
2168     UnixFolder_IDropTarget_QueryInterface,
2169     UnixFolder_IDropTarget_AddRef,
2170     UnixFolder_IDropTarget_Release,
2171     UnixFolder_IDropTarget_DragEnter,
2172     UnixFolder_IDropTarget_DragOver,
2173     UnixFolder_IDropTarget_DragLeave,
2174     UnixFolder_IDropTarget_Drop
2175 };
2176
2177 /******************************************************************************
2178  * Unix[Dos]Folder_Constructor [Internal]
2179  *
2180  * PARAMS
2181  *  pUnkOuter [I] Outer class for aggregation. Currently ignored.
2182  *  riid      [I] Interface asked for by the client.
2183  *  ppv       [O] Pointer to an riid interface to the UnixFolder object.
2184  *
2185  * NOTES
2186  *  Those are the only functions exported from shfldr_unixfs.c. They are called from
2187  *  shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
2188  *  compatible signature.
2189  *
2190  *  The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
2191  *  means that paths are converted from dos to unix and back at the interfaces.
2192  */
2193 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID) 
2194 {
2195     HRESULT hr = E_FAIL;
2196     UnixFolder *pUnixFolder;
2197    
2198     if (pUnkOuter) {
2199         FIXME("Aggregation not yet implemented!\n");
2200         return CLASS_E_NOAGGREGATION;
2201     }
2202     
2203     pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
2204
2205     if(pUnixFolder) {
2206         pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
2207         pUnixFolder->lpIPersistFolder3Vtbl = &UnixFolder_IPersistFolder3_Vtbl;
2208         pUnixFolder->lpIPersistPropertyBagVtbl = &UnixFolder_IPersistPropertyBag_Vtbl;
2209         pUnixFolder->lpISFHelperVtbl = &UnixFolder_ISFHelper_Vtbl;
2210         pUnixFolder->lpIDropTargetVtbl = &UnixFolder_IDropTarget_Vtbl;
2211         pUnixFolder->m_cRef = 0;
2212         pUnixFolder->m_pszPath = NULL;
2213         pUnixFolder->m_pidlLocation = NULL;
2214         pUnixFolder->m_dwPathMode = IsEqualCLSID(&CLSID_UnixFolder, pCLSID) ? PATHMODE_UNIX : PATHMODE_DOS;
2215         pUnixFolder->m_dwAttributes = 0;
2216         pUnixFolder->m_pCLSID = pCLSID;
2217         pUnixFolder->m_dwDropEffectsMask = DROPEFFECT_NONE;
2218
2219         UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
2220         hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
2221         UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
2222     }
2223     return hr;
2224 }
2225
2226 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2227     TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2228     return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixFolder);
2229 }
2230
2231 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2232     TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2233     return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixDosFolder);
2234 }
2235
2236 HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2237     TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2238     return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_FolderShortcut);
2239 }
2240
2241 HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2242     TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2243     return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_MyDocuments);
2244 }
2245
2246 /******************************************************************************
2247  * UnixSubFolderIterator
2248  *
2249  * Class whose heap based objects represent iterators over the sub-directories
2250  * of a given UnixFolder object. 
2251  */
2252
2253 /* UnixSubFolderIterator object layout and typedef.
2254  */
2255 typedef struct _UnixSubFolderIterator {
2256     const IEnumIDListVtbl *lpIEnumIDListVtbl;
2257     LONG m_cRef;
2258     SHCONTF m_fFilter;
2259     DIR *m_dirFolder;
2260     char m_szFolder[FILENAME_MAX];
2261 } UnixSubFolderIterator;
2262
2263 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
2264     TRACE("(iterator=%p)\n", iterator);
2265
2266     if (iterator->m_dirFolder)
2267         closedir(iterator->m_dirFolder);
2268     SHFree(iterator);
2269 }
2270
2271 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface, 
2272     REFIID riid, void** ppv)
2273 {
2274     TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
2275     
2276     if (!ppv) return E_INVALIDARG;
2277     
2278     if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
2279         *ppv = iface;
2280     } else {
2281         *ppv = NULL;
2282         return E_NOINTERFACE;
2283     }
2284
2285     IEnumIDList_AddRef(iface);
2286     return S_OK;
2287 }
2288                             
2289 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
2290 {
2291     UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2292
2293     TRACE("(iface=%p)\n", iface);
2294    
2295     return InterlockedIncrement(&This->m_cRef);
2296 }
2297
2298 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
2299 {
2300     UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2301     ULONG cRef;
2302     
2303     TRACE("(iface=%p)\n", iface);
2304
2305     cRef = InterlockedDecrement(&This->m_cRef);
2306     
2307     if (!cRef) 
2308         UnixSubFolderIterator_Destroy(This);
2309
2310     return cRef;
2311 }
2312
2313 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt, 
2314     LPITEMIDLIST* rgelt, ULONG* pceltFetched)
2315 {
2316     UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2317     ULONG i = 0;
2318
2319     /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
2320     if (This->m_dirFolder) {
2321         char *pszRelativePath = This->m_szFolder + lstrlenA(This->m_szFolder);
2322         struct dirent *pDirEntry;
2323
2324         while (i < celt) {
2325             pDirEntry = readdir(This->m_dirFolder);
2326             if (!pDirEntry) break; /* No more entries */
2327             if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
2328
2329             /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
2330              * and see if it passes the filter. 
2331              */
2332             lstrcpyA(pszRelativePath, pDirEntry->d_name);
2333             rgelt[i] = SHAlloc(
2334                 UNIXFS_shitemid_len_from_filename(pszRelativePath, NULL, NULL)+sizeof(USHORT));
2335             if (!UNIXFS_build_shitemid(This->m_szFolder, NULL, rgelt[i]) ||
2336                 !UNIXFS_is_pidl_of_type(rgelt[i], This->m_fFilter)) 
2337             {
2338                 SHFree(rgelt[i]);
2339                 continue;
2340             }
2341             memset(((PBYTE)rgelt[i])+rgelt[i]->mkid.cb, 0, sizeof(USHORT));
2342             i++;
2343         }
2344         *pszRelativePath = '\0'; /* Restore the original path in This->m_szFolder. */
2345     }
2346     
2347     if (pceltFetched)
2348         *pceltFetched = i;
2349
2350     return (i == 0) ? S_FALSE : S_OK;
2351 }
2352     
2353 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
2354 {
2355     LPITEMIDLIST *apidl;
2356     ULONG cFetched;
2357     HRESULT hr;
2358     
2359     TRACE("(iface=%p, celt=%d)\n", iface, celt);
2360
2361     /* Call IEnumIDList::Next and delete the resulting pidls. */
2362     apidl = SHAlloc(celt * sizeof(LPITEMIDLIST));
2363     hr = IEnumIDList_Next(iface, celt, apidl, &cFetched);
2364     if (SUCCEEDED(hr))
2365         while (cFetched--) 
2366             SHFree(apidl[cFetched]);
2367     SHFree(apidl);
2368
2369     return hr;
2370 }
2371
2372 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
2373 {
2374     UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2375         
2376     TRACE("(iface=%p)\n", iface);
2377
2378     if (This->m_dirFolder)
2379         rewinddir(This->m_dirFolder);
2380     
2381     return S_OK;
2382 }
2383
2384 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This, 
2385     IEnumIDList** ppenum)
2386 {
2387     FIXME("stub\n");
2388     return E_NOTIMPL;
2389 }
2390
2391 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
2392  */
2393 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
2394     UnixSubFolderIterator_IEnumIDList_QueryInterface,
2395     UnixSubFolderIterator_IEnumIDList_AddRef,
2396     UnixSubFolderIterator_IEnumIDList_Release,
2397     UnixSubFolderIterator_IEnumIDList_Next,
2398     UnixSubFolderIterator_IEnumIDList_Skip,
2399     UnixSubFolderIterator_IEnumIDList_Reset,
2400     UnixSubFolderIterator_IEnumIDList_Clone
2401 };
2402
2403 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter) {
2404     UnixSubFolderIterator *iterator;
2405
2406     TRACE("(pUnixFolder=%p)\n", pUnixFolder);
2407     
2408     iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
2409     iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
2410     iterator->m_cRef = 0;
2411     iterator->m_fFilter = fFilter;
2412     iterator->m_dirFolder = opendir(pUnixFolder->m_pszPath);
2413     lstrcpyA(iterator->m_szFolder, pUnixFolder->m_pszPath);
2414
2415     UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
2416     
2417     return (IUnknown*)iterator;
2418 }
2419
2420 #else /* __MINGW32__ || _MSC_VER */
2421
2422 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
2423 {
2424     return E_NOTIMPL;
2425 }
2426
2427 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
2428 {
2429     return E_NOTIMPL;
2430 }
2431
2432 HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
2433 {
2434     return E_NOTIMPL;
2435 }
2436
2437 HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
2438 {
2439     return E_NOTIMPL;
2440 }
2441
2442 #endif /* __MINGW32__ || _MSC_VER */
2443
2444 /******************************************************************************
2445  * UNIXFS_is_rooted_at_desktop [Internal]
2446  *
2447  * Checks if the unixfs namespace extension is rooted at desktop level.
2448  *
2449  * RETURNS
2450  *  TRUE, if unixfs is rooted at desktop level
2451  *  FALSE, if not.
2452  */
2453 BOOL UNIXFS_is_rooted_at_desktop(void) {
2454     HKEY hKey;
2455     WCHAR wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
2456         'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2457         'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2458         'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
2459         'N','a','m','e','S','p','a','c','e','\\',0 };
2460
2461     if (StringFromGUID2(&CLSID_UnixDosFolder, wszRootedAtDesktop + 69, CHARS_IN_GUID) &&
2462         RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
2463     {
2464         RegCloseKey(hKey);
2465         return TRUE;
2466     }
2467     return FALSE;
2468 }