2 * UNIXFS - Shell namespace extension for the unix filesystem
4 * Copyright (C) 2005 Michael Jung
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
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
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 appart from ordinary strings
45 * here. That's different in the file dialogs, though.
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.
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.
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.
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.
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 should'nt 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.
115 * To sum it all up, you can still savely run wine with you root account (Just
116 * kidding, don't do it.)
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.
126 #include "wine/port.h"
135 #ifdef HAVE_SYS_STAT_H
136 # include <sys/stat.h>
145 #define NONAMELESSUNION
146 #define NONAMELESSSTRUCT
154 #include "winternl.h"
155 #include "wine/debug.h"
157 #include "shell32_main.h"
158 #include "shellfolder.h"
160 #include "shresdef.h"
163 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
165 const GUID CLSID_UnixFolder
= {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
166 const GUID CLSID_UnixDosFolder
= {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
168 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
169 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
171 /* FileStruct reserves one byte for szNames, thus we don't have to
172 * alloc a byte for the terminating '\0' of 'name'. Two of the
173 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
174 * type field. One is for FileStruct's szNames field, to terminate
175 * the alternate DOS name, which we don't use here.
177 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
178 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char))
179 #define NAME_LEN_FROM_LPSHITEMID(s) \
180 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char))
182 #define PATHMODE_UNIX 0
183 #define PATHMODE_DOS 1
185 /* UnixFolder object layout and typedef.
187 typedef struct _UnixFolder
{
188 const IShellFolder2Vtbl
*lpIShellFolder2Vtbl
;
189 const IPersistFolder3Vtbl
*lpIPersistFolder3Vtbl
;
190 const IPersistPropertyBagVtbl
*lpIPersistPropertyBagVtbl
;
191 const ISFHelperVtbl
*lpISFHelperVtbl
;
194 LPITEMIDLIST m_pidlLocation
;
196 DWORD m_dwAttributes
;
197 const CLSID
*m_pCLSID
;
200 /******************************************************************************
201 * UNIXFS_is_rooted_at_desktop [Internal]
203 * Checks if the unixfs namespace extension is rooted at desktop level.
206 * TRUE, if unixfs is rooted at desktop level
209 BOOL
UNIXFS_is_rooted_at_desktop(void) {
211 WCHAR wszRootedAtDesktop
[69 + CHARS_IN_GUID
] = {
212 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
213 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
214 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
215 'N','a','m','e','S','p','a','c','e','\\',0 };
217 if (StringFromGUID2(&CLSID_UnixDosFolder
, wszRootedAtDesktop
+ 69, CHARS_IN_GUID
) &&
218 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszRootedAtDesktop
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
226 /******************************************************************************
227 * UNIXFS_is_pidl_of_type [INTERNAL]
229 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
232 * pIDL [I] The ITEMIDLIST to be checked.
233 * fFilter [I] Shell condition flags, which specify the filter.
236 * TRUE, if pIDL is accepted by fFilter
239 static inline BOOL
UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL
, SHCONTF fFilter
) {
240 LPPIDLDATA pIDLData
= _ILGetDataPointer(pIDL
);
241 if (!(fFilter
& SHCONTF_INCLUDEHIDDEN
) && pIDLData
&&
242 (pIDLData
->u
.file
.uFileAttribs
& FILE_ATTRIBUTE_HIDDEN
))
246 if (_ILIsFolder(pIDL
) && (fFilter
& SHCONTF_FOLDERS
)) return TRUE
;
247 if (_ILIsValue(pIDL
) && (fFilter
& SHCONTF_NONFOLDERS
)) return TRUE
;
251 /******************************************************************************
252 * UNIXFS_is_dos_device [Internal]
254 * Determines if a unix directory corresponds to any dos device.
257 * statPath [I] The stat struct of the directory, as returned by stat(2).
260 * TRUE, if statPath corresponds to any dos drive letter
263 static BOOL
UNIXFS_is_dos_device(const struct stat
*statPath
) {
264 struct stat statDrive
;
267 WCHAR wszDosDevice
[4] = { 'A', ':', '\\', 0 };
269 for (dwDriveMap
= GetLogicalDrives(); dwDriveMap
; dwDriveMap
>>= 1, wszDosDevice
[0]++) {
270 if (!(dwDriveMap
& 0x1)) continue;
271 pszDrivePath
= wine_get_unix_file_name(wszDosDevice
);
272 if (pszDrivePath
&& !stat(pszDrivePath
, &statDrive
)) {
273 HeapFree(GetProcessHeap(), 0, pszDrivePath
);
274 if ((statPath
->st_dev
== statDrive
.st_dev
) && (statPath
->st_ino
== statDrive
.st_ino
))
281 /******************************************************************************
282 * UNIXFS_get_unix_path [Internal]
284 * Convert an absolute dos path to an absolute canonicalized unix path.
285 * Evaluate "/.", "/.." and symbolic links.
288 * pszDosPath [I] An absolute dos path
289 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
293 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
295 static BOOL
UNIXFS_get_unix_path(LPCWSTR pszDosPath
, char *pszCanonicalPath
)
297 char *pPathTail
, *pElement
, *pCanonicalTail
, szPath
[FILENAME_MAX
], *pszUnixPath
;
298 struct stat fileStat
;
300 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath
), pszCanonicalPath
);
302 if (!pszDosPath
|| pszDosPath
[1] != ':')
305 pszUnixPath
= wine_get_unix_file_name(pszDosPath
);
306 if (!pszUnixPath
) return FALSE
;
307 strcpy(szPath
, pszUnixPath
);
308 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
310 /* pCanonicalTail always points to the end of the canonical path constructed
311 * thus far. pPathTail points to the still to be processed part of the input
312 * path. pElement points to the path element currently investigated.
314 *pszCanonicalPath
= '\0';
315 pCanonicalTail
= pszCanonicalPath
;
322 pElement
= pPathTail
;
323 pPathTail
= strchr(pPathTail
+1, '/');
324 if (!pPathTail
) /* Last path element may not be terminated by '/'. */
325 pPathTail
= pElement
+ strlen(pElement
);
326 /* Temporarily terminate the current path element. Will be restored later. */
330 /* Skip "/." path elements */
331 if (!strcmp("/.", pElement
)) {
336 /* Remove last element in canonical path for "/.." elements, then skip. */
337 if (!strcmp("/..", pElement
)) {
338 char *pTemp
= strrchr(pszCanonicalPath
, '/');
340 pCanonicalTail
= pTemp
;
341 *pCanonicalTail
= '\0';
346 /* lstat returns zero on success. */
347 if (lstat(szPath
, &fileStat
))
350 if (S_ISLNK(fileStat
.st_mode
)) {
351 char szSymlink
[FILENAME_MAX
];
352 int cLinkLen
, cTailLen
;
354 /* Avoid infinite loop for recursive links. */
358 cLinkLen
= readlink(szPath
, szSymlink
, FILENAME_MAX
);
363 cTailLen
= strlen(pPathTail
);
365 if (szSymlink
[0] == '/') {
366 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
367 if (cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
370 /* Avoid double slashes. */
371 if (szSymlink
[cLinkLen
-1] == '/' && pPathTail
[0] == '/') {
372 szSymlink
[cLinkLen
-1] = '\0';
376 memcpy(szSymlink
+ cLinkLen
, pPathTail
, cTailLen
+ 1);
377 memcpy(szPath
, szSymlink
, cLinkLen
+ cTailLen
+ 1);
378 *pszCanonicalPath
= '\0';
379 pCanonicalTail
= pszCanonicalPath
;
382 /* Relative link. Expand into szPath and continue. */
383 char szTemp
[FILENAME_MAX
];
384 int cTailLen
= strlen(pPathTail
);
386 if (pElement
- szPath
+ 1 + cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
389 memcpy(szTemp
, pPathTail
, cTailLen
+ 1);
390 memcpy(pElement
+ 1, szSymlink
, cLinkLen
);
391 memcpy(pElement
+ 1 + cLinkLen
, szTemp
, cTailLen
+ 1);
392 pPathTail
= pElement
;
395 /* Regular directory or file. Copy to canonical path */
396 if (pCanonicalTail
- pszCanonicalPath
+ pPathTail
- pElement
+ 1 > FILENAME_MAX
)
399 memcpy(pCanonicalTail
, pElement
, pPathTail
- pElement
+ 1);
400 pCanonicalTail
+= pPathTail
- pElement
;
403 } while (pPathTail
[0] == '/');
405 TRACE("--> %s\n", debugstr_a(pszCanonicalPath
));
410 /******************************************************************************
411 * UNIXFS_build_shitemid [Internal]
413 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
417 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
418 * pIDL [O] SHITEMID will be constructed here.
421 * Success: A pointer to the terminating '\0' character of path.
425 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
426 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
429 static char* UNIXFS_build_shitemid(char *pszUnixPath
, void *pIDL
) {
433 struct stat fileStat
;
437 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath
), pIDL
);
439 /* Compute the SHITEMID's length and wipe it. */
440 pszComponent
= strrchr(pszUnixPath
, '/') + 1;
441 cComponentLen
= strlen(pszComponent
);
442 memset(pIDL
, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
));
443 ((LPSHITEMID
)pIDL
)->cb
= SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
) ;
445 /* We are only interested in regular files and directories. */
446 if (stat(pszUnixPath
, &fileStat
)) return NULL
;
447 if (!S_ISDIR(fileStat
.st_mode
) && !S_ISREG(fileStat
.st_mode
)) return NULL
;
449 /* Set shell32's standard SHITEMID data fields. */
450 pIDLData
= _ILGetDataPointer((LPCITEMIDLIST
)pIDL
);
451 pIDLData
->type
= S_ISDIR(fileStat
.st_mode
) ? PT_FOLDER
: PT_VALUE
;
452 pIDLData
->u
.file
.dwFileSize
= (DWORD
)fileStat
.st_size
;
453 RtlSecondsSince1970ToTime( fileStat
.st_mtime
, &time
);
454 fileTime
.dwLowDateTime
= time
.u
.LowPart
;
455 fileTime
.dwHighDateTime
= time
.u
.HighPart
;
456 FileTimeToDosDateTime(&fileTime
, &pIDLData
->u
.file
.uFileDate
, &pIDLData
->u
.file
.uFileTime
);
457 pIDLData
->u
.file
.uFileAttribs
= 0;
458 if (S_ISDIR(fileStat
.st_mode
)) pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_DIRECTORY
;
459 if (pszComponent
[0] == '.') pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_HIDDEN
;
460 memcpy(pIDLData
->u
.file
.szNames
, pszComponent
, cComponentLen
);
462 return pszComponent
+ cComponentLen
;
465 /******************************************************************************
466 * UNIXFS_path_to_pidl [Internal]
469 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
470 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
471 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
475 * Failure: FALSE, invalid params or out of memory
478 * pUnixFolder also carries the information if the path is expected to be unix or dos.
480 static BOOL
UNIXFS_path_to_pidl(UnixFolder
*pUnixFolder
, const WCHAR
*path
, LPITEMIDLIST
*ppidl
) {
482 int cSubDirs
, cPidlLen
, cPathLen
;
483 char *pSlash
, szCompletePath
[FILENAME_MAX
], *pNextPathElement
;
485 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder
, debugstr_w(path
), ppidl
);
490 /* Build an absolute path and let pNextPathElement point to the interesting
491 * relative sub-path. We need the absolute path to call 'stat', but the pidl
492 * will only contain the relative part.
494 if ((pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) && (path
[1] == ':'))
496 /* Absolute dos path. Convert to unix */
497 if (!UNIXFS_get_unix_path(path
, szCompletePath
))
499 pNextPathElement
= szCompletePath
;
501 else if ((pUnixFolder
->m_dwPathMode
== PATHMODE_UNIX
) && (path
[0] == '/'))
503 /* Absolute unix path. Just convert to ANSI. */
504 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
, FILENAME_MAX
, NULL
, NULL
);
505 pNextPathElement
= szCompletePath
;
509 /* Relative dos or unix path. Concat with this folder's path */
510 int cBasePathLen
= strlen(pUnixFolder
->m_pszPath
);
511 memcpy(szCompletePath
, pUnixFolder
->m_pszPath
, cBasePathLen
);
512 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
+ cBasePathLen
,
513 FILENAME_MAX
- cBasePathLen
, NULL
, NULL
);
514 pNextPathElement
= szCompletePath
+ cBasePathLen
- 1;
516 /* If in dos mode, replace '\' with '/' */
517 if (pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) {
518 char *pBackslash
= strchr(pNextPathElement
, '\\');
521 pBackslash
= strchr(pBackslash
, '\\');
526 /* Special case for the root folder. */
527 if (!strcmp(szCompletePath
, "/")) {
528 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(sizeof(USHORT
));
529 if (!pidl
) return FALSE
;
530 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
534 /* Remove trailing slash, if present */
535 cPathLen
= strlen(szCompletePath
);
536 if (szCompletePath
[cPathLen
-1] == '/')
537 szCompletePath
[cPathLen
-1] = '\0';
539 if ((szCompletePath
[0] != '/') || (pNextPathElement
[0] != '/')) {
540 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath
, pNextPathElement
);
544 /* At this point, we have an absolute unix path in szCompletePath
545 * and the relative portion of it in pNextPathElement. Both starting with '/'
546 * and _not_ terminated by a '/'. */
547 TRACE("complete path: %s, relative path: %s\n", szCompletePath
, pNextPathElement
);
549 /* Count the number of sub-directories in the path */
551 pSlash
= pNextPathElement
;
554 pSlash
= strchr(pSlash
+1, '/');
557 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
558 * characters, which are not stored in the ITEMIDLIST. */
559 cPidlLen
= strlen(pNextPathElement
) - cSubDirs
+ cSubDirs
* SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT
);
560 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(cPidlLen
);
561 if (!pidl
) return FALSE
;
563 /* Concatenate the SHITEMIDs of the sub-directories. */
564 while (*pNextPathElement
) {
565 pSlash
= strchr(pNextPathElement
+1, '/');
566 if (pSlash
) *pSlash
= '\0';
567 pNextPathElement
= UNIXFS_build_shitemid(szCompletePath
, pidl
);
568 if (pSlash
) *pSlash
= '/';
570 if (!pNextPathElement
) {
574 pidl
= ILGetNext(pidl
);
576 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
578 if ((char *)pidl
-(char *)*ppidl
+sizeof(USHORT
) != cPidlLen
) /* We've corrupted the heap :( */
579 ERR("Computed length of pidl incorrect. Please report.\n");
584 /******************************************************************************
587 * Class whose heap based instances represent unix filesystem directories.
590 static void UnixFolder_Destroy(UnixFolder
*pUnixFolder
) {
591 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
593 SHFree(pUnixFolder
->m_pszPath
);
594 ILFree(pUnixFolder
->m_pidlLocation
);
598 static HRESULT WINAPI
UnixFolder_IShellFolder2_QueryInterface(IShellFolder2
*iface
, REFIID riid
,
601 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
603 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
605 if (!ppv
) return E_INVALIDARG
;
607 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellFolder
, riid
) ||
608 IsEqualIID(&IID_IShellFolder2
, riid
))
610 *ppv
= &This
->lpIShellFolder2Vtbl
;
611 } else if (IsEqualIID(&IID_IPersistFolder3
, riid
) || IsEqualIID(&IID_IPersistFolder2
, riid
) ||
612 IsEqualIID(&IID_IPersistFolder
, riid
) || IsEqualIID(&IID_IPersist
, riid
))
614 *ppv
= &This
->lpIPersistFolder3Vtbl
;
615 } else if (IsEqualIID(&IID_IPersistPropertyBag
, riid
)) {
616 *ppv
= &This
->lpIPersistPropertyBagVtbl
;
617 } else if (IsEqualIID(&IID_ISFHelper
, riid
)) {
618 *ppv
= &This
->lpISFHelperVtbl
;
621 return E_NOINTERFACE
;
624 IUnknown_AddRef((IUnknown
*)*ppv
);
628 static ULONG WINAPI
UnixFolder_IShellFolder2_AddRef(IShellFolder2
*iface
) {
629 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
631 TRACE("(iface=%p)\n", iface
);
633 return InterlockedIncrement(&This
->m_cRef
);
636 static ULONG WINAPI
UnixFolder_IShellFolder2_Release(IShellFolder2
*iface
) {
637 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
640 TRACE("(iface=%p)\n", iface
);
642 cRef
= InterlockedDecrement(&This
->m_cRef
);
645 UnixFolder_Destroy(This
);
650 static HRESULT WINAPI
UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2
* iface
, HWND hwndOwner
,
651 LPBC pbcReserved
, LPOLESTR lpszDisplayName
, ULONG
* pchEaten
, LPITEMIDLIST
* ppidl
,
652 ULONG
* pdwAttributes
)
654 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
657 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
658 "pdwAttributes=%p) stub\n", iface
, hwndOwner
, pbcReserved
, debugstr_w(lpszDisplayName
),
659 pchEaten
, ppidl
, pdwAttributes
);
661 result
= UNIXFS_path_to_pidl(This
, lpszDisplayName
, ppidl
);
662 if (result
&& pdwAttributes
&& *pdwAttributes
)
664 IShellFolder
*pParentSF
;
665 LPCITEMIDLIST pidlLast
;
668 hr
= SHBindToParent(*ppidl
, &IID_IShellFolder
, (LPVOID
*)&pParentSF
, &pidlLast
);
669 if (FAILED(hr
)) return E_FAIL
;
670 IShellFolder_GetAttributesOf(pParentSF
, 1, &pidlLast
, pdwAttributes
);
671 IShellFolder_Release(pParentSF
);
674 if (!result
) TRACE("FAILED!\n");
675 return result
? S_OK
: E_FAIL
;
678 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
);
680 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumObjects(IShellFolder2
* iface
, HWND hwndOwner
,
681 SHCONTF grfFlags
, IEnumIDList
** ppEnumIDList
)
683 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
684 IUnknown
*newIterator
;
687 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
688 iface
, hwndOwner
, grfFlags
, ppEnumIDList
);
690 if (!This
->m_pszPath
) {
691 WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
695 newIterator
= UnixSubFolderIterator_Constructor(This
, grfFlags
);
696 hr
= IUnknown_QueryInterface(newIterator
, &IID_IEnumIDList
, (void**)ppEnumIDList
);
697 IUnknown_Release(newIterator
);
702 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, const CLSID
*pCLSID
);
704 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToObject(IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
705 LPBC pbcReserved
, REFIID riid
, void** ppvOut
)
707 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
708 IPersistFolder3
*persistFolder
;
711 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
712 iface
, pidl
, pbcReserved
, riid
, ppvOut
);
714 if (!pidl
|| !pidl
->mkid
.cb
)
717 hr
= CreateUnixFolder(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
, This
->m_pCLSID
);
718 if (!SUCCEEDED(hr
)) return hr
;
719 hr
= IPersistFolder_QueryInterface(persistFolder
, riid
, (void**)ppvOut
);
722 LPITEMIDLIST pidlSubFolder
= ILCombine(This
->m_pidlLocation
, pidl
);
723 hr
= IPersistFolder3_Initialize(persistFolder
, pidlSubFolder
);
724 ILFree(pidlSubFolder
);
727 IPersistFolder3_Release(persistFolder
);
732 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToStorage(IShellFolder2
* This
, LPCITEMIDLIST pidl
,
733 LPBC pbcReserved
, REFIID riid
, void** ppvObj
)
739 static HRESULT WINAPI
UnixFolder_IShellFolder2_CompareIDs(IShellFolder2
* iface
, LPARAM lParam
,
740 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
742 BOOL isEmpty1
, isEmpty2
;
744 LPITEMIDLIST firstpidl
;
748 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface
, lParam
, pidl1
, pidl2
);
750 isEmpty1
= !pidl1
|| !pidl1
->mkid
.cb
;
751 isEmpty2
= !pidl2
|| !pidl2
->mkid
.cb
;
753 if (isEmpty1
&& isEmpty2
)
754 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
756 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
758 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
760 if (_ILIsFolder(pidl1
) && !_ILIsFolder(pidl2
))
761 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
762 if (!_ILIsFolder(pidl1
) && _ILIsFolder(pidl2
))
763 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
765 compare
= CompareStringA(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
,
766 _ILGetTextPointer(pidl1
), NAME_LEN_FROM_LPSHITEMID(pidl1
),
767 _ILGetTextPointer(pidl2
), NAME_LEN_FROM_LPSHITEMID(pidl2
));
769 if ((compare
== CSTR_LESS_THAN
) || (compare
== CSTR_GREATER_THAN
))
770 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)((compare
== CSTR_LESS_THAN
)?-1:1));
772 if (pidl1
->mkid
.cb
< pidl2
->mkid
.cb
)
773 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
774 else if (pidl1
->mkid
.cb
> pidl2
->mkid
.cb
)
775 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
777 firstpidl
= ILCloneFirst(pidl1
);
778 pidl1
= ILGetNext(pidl1
);
779 pidl2
= ILGetNext(pidl2
);
781 hr
= IShellFolder2_BindToObject(iface
, firstpidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
);
783 hr
= IShellFolder_CompareIDs(psf
, lParam
, pidl1
, pidl2
);
784 IShellFolder2_Release(psf
);
791 static HRESULT WINAPI
UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2
* iface
, HWND hwndOwner
,
792 REFIID riid
, void** ppv
)
794 HRESULT hr
= E_INVALIDARG
;
796 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface
, hwndOwner
, riid
, ppv
);
798 if (!ppv
) return E_INVALIDARG
;
801 if (IsEqualIID(&IID_IShellView
, riid
)) {
802 LPSHELLVIEW pShellView
;
804 pShellView
= IShellView_Constructor((IShellFolder
*)iface
);
806 hr
= IShellView_QueryInterface(pShellView
, riid
, ppv
);
807 IShellView_Release(pShellView
);
814 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2
* iface
, UINT cidl
,
815 LPCITEMIDLIST
* apidl
, SFGAOF
* rgfInOut
)
817 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
820 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface
, cidl
, apidl
, rgfInOut
);
822 if (!rgfInOut
|| (cidl
&& !apidl
))
826 *rgfInOut
&= This
->m_dwAttributes
;
828 char szAbsolutePath
[FILENAME_MAX
], *pszRelativePath
;
831 *rgfInOut
= SFGAO_CANCOPY
|SFGAO_CANMOVE
|SFGAO_CANLINK
|SFGAO_CANRENAME
|SFGAO_CANDELETE
|
832 SFGAO_HASPROPSHEET
|SFGAO_DROPTARGET
|SFGAO_FILESYSTEM
;
833 lstrcpyA(szAbsolutePath
, This
->m_pszPath
);
834 pszRelativePath
= szAbsolutePath
+ lstrlenA(szAbsolutePath
);
835 for (i
=0; i
<cidl
; i
++) {
836 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
837 struct stat fileStat
;
838 char *pszName
= _ILGetTextPointer(apidl
[i
]);
839 if (!pszName
) return E_INVALIDARG
;
840 lstrcpyA(pszRelativePath
, pszName
);
841 if (stat(szAbsolutePath
, &fileStat
) || !UNIXFS_is_dos_device(&fileStat
))
842 *rgfInOut
&= ~SFGAO_FILESYSTEM
;
844 if (_ILIsFolder(apidl
[i
]))
845 *rgfInOut
|= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
;
852 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2
* iface
, HWND hwndOwner
,
853 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
, UINT
* prgfInOut
, void** ppvOut
)
855 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
857 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
858 iface
, hwndOwner
, cidl
, apidl
, debugstr_guid(riid
), prgfInOut
, ppvOut
);
860 if (IsEqualIID(&IID_IContextMenu
, riid
)) {
861 *ppvOut
= ISvItemCm_Constructor((IShellFolder
*)iface
, This
->m_pidlLocation
, apidl
, cidl
);
863 } else if (IsEqualIID(&IID_IDataObject
, riid
)) {
864 *ppvOut
= IDataObject_Constructor(hwndOwner
, This
->m_pidlLocation
, apidl
, cidl
);
866 } else if (IsEqualIID(&IID_IExtractIconA
, riid
)) {
868 if (cidl
!= 1) return E_FAIL
;
869 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
870 *ppvOut
= (LPVOID
)IExtractIconA_Constructor(pidl
);
873 } else if (IsEqualIID(&IID_IExtractIconW
, riid
)) {
875 if (cidl
!= 1) return E_FAIL
;
876 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
877 *ppvOut
= (LPVOID
)IExtractIconW_Constructor(pidl
);
880 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
881 FIXME("IDropTarget\n");
883 } else if (IsEqualIID(&IID_IShellLinkW
, riid
)) {
884 FIXME("IShellLinkW\n");
886 } else if (IsEqualIID(&IID_IShellLinkA
, riid
)) {
887 FIXME("IShellLinkA\n");
890 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid
));
891 return E_NOINTERFACE
;
895 /******************************************************************************
896 * Translate file name from unix to ANSI encoding.
898 static void strcpyn_U2A(char *win_fn
, UINT win_fn_len
, const char *unix_fn
)
903 len
= MultiByteToWideChar(CP_UNIXCP
, 0, unix_fn
, -1, NULL
, 0);
904 unicode_fn
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
905 MultiByteToWideChar(CP_UNIXCP
, 0, unix_fn
, -1, unicode_fn
, len
);
907 WideCharToMultiByte(CP_ACP
, 0, unicode_fn
, len
, win_fn
, win_fn_len
, NULL
, NULL
);
908 HeapFree(GetProcessHeap(), 0, unicode_fn
);
911 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2
* iface
,
912 LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
* lpName
)
914 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
917 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface
, pidl
, uFlags
, lpName
);
919 if ((GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) &&
920 (GET_SHGDN_RELATION(uFlags
) != SHGDN_INFOLDER
))
922 if (!pidl
|| !pidl
->mkid
.cb
) {
923 lpName
->uType
= STRRET_CSTR
;
924 if (This
->m_dwPathMode
== PATHMODE_UNIX
) {
925 strcpyn_U2A(lpName
->u
.cStr
, MAX_PATH
, This
->m_pszPath
);
927 WCHAR
*pwszDosPath
= wine_get_dos_file_name(This
->m_pszPath
);
929 return HRESULT_FROM_WIN32(GetLastError());
930 PathRemoveBackslashW(pwszDosPath
);
931 WideCharToMultiByte(CP_UNIXCP
, 0, pwszDosPath
, -1, lpName
->u
.cStr
, MAX_PATH
, NULL
, NULL
);
932 HeapFree(GetProcessHeap(), 0, pwszDosPath
);
935 IShellFolder
*pSubFolder
;
936 SHITEMID emptyIDL
= { 0, { 0 } };
938 hr
= IShellFolder_BindToObject(iface
, pidl
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
939 if (!SUCCEEDED(hr
)) return hr
;
941 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, lpName
);
942 IShellFolder_Release(pSubFolder
);
945 char *pszFileName
= _ILGetTextPointer(pidl
);
946 lpName
->uType
= STRRET_CSTR
;
947 strcpyn_U2A(lpName
->u
.cStr
, MAX_PATH
, pszFileName
? pszFileName
: "");
950 /* If in dos mode, do some post-processing on the path.
951 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
953 if (SUCCEEDED(hr
) && This
->m_dwPathMode
== PATHMODE_DOS
&& !_ILIsFolder(pidl
))
954 SHELL_FS_ProcessDisplayFilename(lpName
->u
.cStr
, uFlags
);
956 TRACE("--> %s\n", lpName
->u
.cStr
);
961 static HRESULT WINAPI
UnixFolder_IShellFolder2_SetNameOf(IShellFolder2
* iface
, HWND hwnd
,
962 LPCITEMIDLIST pidl
, LPCOLESTR lpszName
, SHGDNF uFlags
, LPITEMIDLIST
* ppidlOut
)
964 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
966 char szSrc
[FILENAME_MAX
], szDest
[FILENAME_MAX
];
968 int cBasePathLen
= lstrlenA(This
->m_pszPath
);
969 struct stat statDest
;
970 LPITEMIDLIST pidlSrc
, pidlDest
;
972 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
973 iface
, hwnd
, pidl
, debugstr_w(lpszName
), uFlags
, ppidlOut
);
975 /* pidl has to contain a single non-empty SHITEMID */
976 if (_ILIsDesktop(pidl
) || !_ILIsPidlSimple(pidl
) || !_ILGetTextPointer(pidl
))
982 /* build source path */
983 memcpy(szSrc
, This
->m_pszPath
, cBasePathLen
);
984 lstrcpyA(szSrc
+cBasePathLen
, _ILGetTextPointer(pidl
));
986 /* build destination path */
987 if (uFlags
& SHGDN_FORPARSING
) { /* absolute path in lpszName */
988 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
, FILENAME_MAX
, NULL
, NULL
);
990 WCHAR wszSrcRelative
[MAX_PATH
];
991 memcpy(szDest
, This
->m_pszPath
, cBasePathLen
);
992 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
+cBasePathLen
,
993 FILENAME_MAX
-cBasePathLen
, NULL
, NULL
);
995 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
996 * extension is hidden to the user, we have to append it. */
997 if (_ILSimpleGetTextW(pidl
, wszSrcRelative
, MAX_PATH
) &&
998 SHELL_FS_HideExtension(wszSrcRelative
))
1000 char *pszExt
= PathFindExtensionA(_ILGetTextPointer(pidl
));
1001 lstrcatA(szDest
, pszExt
);
1005 TRACE("src=%s dest=%s\n", szSrc
, szDest
);
1007 /* Fail, if destination does already exist */
1008 if (!stat(szDest
, &statDest
))
1011 /* Rename the file */
1012 if (rename(szSrc
, szDest
))
1015 /* Build a pidl for the path of the renamed file */
1016 pwszDosDest
= wine_get_dos_file_name(szDest
);
1017 if (!pwszDosDest
|| !UNIXFS_path_to_pidl(This
, pwszDosDest
, &pidlDest
)) {
1018 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
1019 rename(szDest
, szSrc
); /* Undo the renaming */
1023 /* Inform the shell */
1024 pidlSrc
= ILCombine(This
->m_pidlLocation
, pidl
);
1025 if (_ILIsFolder(ILFindLastID(pidlDest
)))
1026 SHChangeNotify(SHCNE_RENAMEFOLDER
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
1028 SHChangeNotify(SHCNE_RENAMEITEM
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
1033 _ILCreateFromPathW(pwszDosDest
, ppidlOut
);
1035 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
1039 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumSearches(IShellFolder2
* iface
,
1040 IEnumExtraSearch
**ppEnum
)
1046 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2
* iface
,
1047 DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
1053 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2
* iface
,
1054 UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
1060 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2
* iface
,
1067 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2
* iface
,
1068 LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
1074 #define SHELLVIEWCOLUMNS 7
1076 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2
* iface
,
1077 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
*psd
)
1079 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
1080 HRESULT hr
= E_FAIL
;
1081 struct passwd
*pPasswd
;
1082 struct group
*pGroup
;
1083 static const shvheader SFHeader
[SHELLVIEWCOLUMNS
] = {
1084 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
1085 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
1086 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
1087 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
1088 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 9},
1089 {IDS_SHV_COLUMN10
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
1090 {IDS_SHV_COLUMN11
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7}
1093 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface
, pidl
, iColumn
, psd
);
1095 if (!psd
|| iColumn
>= SHELLVIEWCOLUMNS
)
1096 return E_INVALIDARG
;
1099 psd
->fmt
= SFHeader
[iColumn
].fmt
;
1100 psd
->cxChar
= SFHeader
[iColumn
].cxChar
;
1101 psd
->str
.uType
= STRRET_CSTR
;
1102 LoadStringA(shell32_hInstance
, SFHeader
[iColumn
].colnameid
, psd
->str
.u
.cStr
, MAX_PATH
);
1105 struct stat statItem
;
1106 if (iColumn
== 4 || iColumn
== 5 || iColumn
== 6) {
1107 char szPath
[FILENAME_MAX
], *pszFile
= _ILGetTextPointer(pidl
);
1109 return E_INVALIDARG
;
1110 lstrcpyA(szPath
, This
->m_pszPath
);
1111 lstrcatA(szPath
, pszFile
);
1112 if (stat(szPath
, &statItem
))
1113 return E_INVALIDARG
;
1115 psd
->str
.u
.cStr
[0] = '\0';
1116 psd
->str
.uType
= STRRET_CSTR
;
1119 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
|SHGDN_INFOLDER
, &psd
->str
);
1122 _ILGetFileSize(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1125 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1128 _ILGetFileDate(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1131 psd
->str
.u
.cStr
[0] = S_ISDIR(statItem
.st_mode
) ? 'd' : '-';
1132 psd
->str
.u
.cStr
[1] = (statItem
.st_mode
& S_IRUSR
) ? 'r' : '-';
1133 psd
->str
.u
.cStr
[2] = (statItem
.st_mode
& S_IWUSR
) ? 'w' : '-';
1134 psd
->str
.u
.cStr
[3] = (statItem
.st_mode
& S_IXUSR
) ? 'x' : '-';
1135 psd
->str
.u
.cStr
[4] = (statItem
.st_mode
& S_IRGRP
) ? 'r' : '-';
1136 psd
->str
.u
.cStr
[5] = (statItem
.st_mode
& S_IWGRP
) ? 'w' : '-';
1137 psd
->str
.u
.cStr
[6] = (statItem
.st_mode
& S_IXGRP
) ? 'x' : '-';
1138 psd
->str
.u
.cStr
[7] = (statItem
.st_mode
& S_IROTH
) ? 'r' : '-';
1139 psd
->str
.u
.cStr
[8] = (statItem
.st_mode
& S_IWOTH
) ? 'w' : '-';
1140 psd
->str
.u
.cStr
[9] = (statItem
.st_mode
& S_IXOTH
) ? 'x' : '-';
1141 psd
->str
.u
.cStr
[10] = '\0';
1144 pPasswd
= getpwuid(statItem
.st_uid
);
1145 if (pPasswd
) strcpy(psd
->str
.u
.cStr
, pPasswd
->pw_name
);
1148 pGroup
= getgrgid(statItem
.st_gid
);
1149 if (pGroup
) strcpy(psd
->str
.u
.cStr
, pGroup
->gr_name
);
1157 static HRESULT WINAPI
UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2
* iface
, UINT iColumn
,
1164 /* VTable for UnixFolder's IShellFolder2 interface.
1166 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl
= {
1167 UnixFolder_IShellFolder2_QueryInterface
,
1168 UnixFolder_IShellFolder2_AddRef
,
1169 UnixFolder_IShellFolder2_Release
,
1170 UnixFolder_IShellFolder2_ParseDisplayName
,
1171 UnixFolder_IShellFolder2_EnumObjects
,
1172 UnixFolder_IShellFolder2_BindToObject
,
1173 UnixFolder_IShellFolder2_BindToStorage
,
1174 UnixFolder_IShellFolder2_CompareIDs
,
1175 UnixFolder_IShellFolder2_CreateViewObject
,
1176 UnixFolder_IShellFolder2_GetAttributesOf
,
1177 UnixFolder_IShellFolder2_GetUIObjectOf
,
1178 UnixFolder_IShellFolder2_GetDisplayNameOf
,
1179 UnixFolder_IShellFolder2_SetNameOf
,
1180 UnixFolder_IShellFolder2_GetDefaultSearchGUID
,
1181 UnixFolder_IShellFolder2_EnumSearches
,
1182 UnixFolder_IShellFolder2_GetDefaultColumn
,
1183 UnixFolder_IShellFolder2_GetDefaultColumnState
,
1184 UnixFolder_IShellFolder2_GetDetailsEx
,
1185 UnixFolder_IShellFolder2_GetDetailsOf
,
1186 UnixFolder_IShellFolder2_MapColumnToSCID
1189 static HRESULT WINAPI
UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3
* This
, REFIID riid
,
1192 return UnixFolder_IShellFolder2_QueryInterface(
1193 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
), riid
, ppvObject
);
1196 static ULONG WINAPI
UnixFolder_IPersistFolder3_AddRef(IPersistFolder3
* This
)
1198 return UnixFolder_IShellFolder2_AddRef(
1199 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1202 static ULONG WINAPI
UnixFolder_IPersistFolder3_Release(IPersistFolder3
* This
)
1204 return UnixFolder_IShellFolder2_Release(
1205 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1208 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3
* iface
, CLSID
* pClassID
)
1210 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1212 TRACE("(iface=%p, pClassId=%p)\n", iface
, pClassID
);
1215 return E_INVALIDARG
;
1217 memcpy(pClassID
, This
->m_pCLSID
, sizeof(CLSID
));
1221 static HRESULT WINAPI
UnixFolder_IPersistFolder3_Initialize(IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1223 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1224 struct stat statPrefix
;
1225 LPCITEMIDLIST current
= pidl
, root
;
1227 char *pNextDir
, szBasePath
[FILENAME_MAX
] = "/";
1229 TRACE("(iface=%p, pidl=%p)\n", iface
, pidl
);
1231 /* Find the UnixFolderClass root */
1232 while (current
->mkid
.cb
) {
1233 if (_ILIsSpecialFolder(current
) && IsEqualIID(This
->m_pCLSID
, _ILGetGUIDPointer(current
)))
1235 current
= ILGetNext(current
);
1238 if (current
&& current
->mkid
.cb
) {
1239 if (IsEqualIID(&CLSID_MyDocuments
, _ILGetGUIDPointer(current
))) {
1240 WCHAR wszMyDocumentsPath
[MAX_PATH
];
1241 if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath
, CSIDL_PERSONAL
, FALSE
))
1243 PathAddBackslashW(wszMyDocumentsPath
);
1244 if (!UNIXFS_get_unix_path(wszMyDocumentsPath
, szBasePath
))
1246 dwPathLen
= strlen(szBasePath
) + 1;
1248 dwPathLen
= 2; /* For the '/' prefix and the terminating '\0' */
1250 root
= current
= ILGetNext(current
);
1251 } else if (_ILIsDesktop(pidl
) || _ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1252 /* Path rooted at Desktop */
1253 WCHAR wszDesktopPath
[MAX_PATH
];
1254 if (!SHGetSpecialFolderPathW(0, wszDesktopPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
))
1256 PathAddBackslashW(wszDesktopPath
);
1257 if (!UNIXFS_get_unix_path(wszDesktopPath
, szBasePath
))
1259 dwPathLen
= strlen(szBasePath
) + 1;
1260 root
= current
= pidl
;
1262 ERR("Unknown pidl type!\n");
1264 return E_INVALIDARG
;
1267 /* Determine the path's length bytes */
1268 while (current
&& current
->mkid
.cb
) {
1269 dwPathLen
+= NAME_LEN_FROM_LPSHITEMID(current
) + 1; /* For the '/' */
1270 current
= ILGetNext(current
);
1273 /* Build the path */
1274 This
->m_dwAttributes
= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
;
1275 This
->m_pidlLocation
= ILClone(pidl
);
1276 This
->m_pszPath
= pNextDir
= SHAlloc(dwPathLen
);
1277 if (!This
->m_pszPath
|| !This
->m_pidlLocation
) {
1278 WARN("SHAlloc failed!\n");
1282 strcpy(pNextDir
, szBasePath
);
1283 pNextDir
+= strlen(szBasePath
);
1284 if (This
->m_dwPathMode
== PATHMODE_UNIX
|| IsEqualCLSID(&CLSID_MyDocuments
, This
->m_pCLSID
))
1285 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1286 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1288 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1289 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1291 while (current
&& current
->mkid
.cb
) {
1292 memcpy(pNextDir
, _ILGetTextPointer(current
), NAME_LEN_FROM_LPSHITEMID(current
));
1293 pNextDir
+= NAME_LEN_FROM_LPSHITEMID(current
);
1294 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1296 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1297 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1300 current
= ILGetNext(current
);
1307 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3
* iface
, LPITEMIDLIST
* ppidl
)
1309 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1311 TRACE ("(iface=%p, ppidl=%p)\n", iface
, ppidl
);
1315 *ppidl
= ILClone (This
->m_pidlLocation
);
1319 static HRESULT WINAPI
UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3
*iface
, IBindCtx
*pbc
,
1320 LPCITEMIDLIST pidlRoot
, const PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1322 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1323 WCHAR wszTargetDosPath
[MAX_PATH
];
1324 char szTargetPath
[FILENAME_MAX
] = "";
1326 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface
, pbc
, pidlRoot
, ppfti
);
1328 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1330 return IPersistFolder3_Initialize(iface
, pidlRoot
);
1332 if (ppfti
->csidl
!= -1) {
1333 if (FAILED(SHGetFolderPathW(0, ppfti
->csidl
, NULL
, 0, wszTargetDosPath
)) ||
1334 !UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
))
1338 } else if (*ppfti
->szTargetParsingName
) {
1339 if (!UNIXFS_get_unix_path(ppfti
->szTargetParsingName
, szTargetPath
)) {
1342 } else if (ppfti
->pidlTargetFolder
) {
1343 if (!SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTargetDosPath
) ||
1344 !UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
))
1352 This
->m_pszPath
= SHAlloc(lstrlenA(szTargetPath
)+1);
1353 if (!This
->m_pszPath
)
1355 lstrcpyA(This
->m_pszPath
, szTargetPath
);
1356 This
->m_pidlLocation
= ILClone(pidlRoot
);
1357 This
->m_dwAttributes
= (ppfti
->dwAttributes
!= -1) ? ppfti
->dwAttributes
:
1358 (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|SFGAO_FILESYSTEM
);
1363 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3
*iface
,
1364 PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1366 FIXME("(iface=%p, ppfti=%p) stub\n", iface
, ppfti
);
1370 /* VTable for UnixFolder's IPersistFolder interface.
1372 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl
= {
1373 UnixFolder_IPersistFolder3_QueryInterface
,
1374 UnixFolder_IPersistFolder3_AddRef
,
1375 UnixFolder_IPersistFolder3_Release
,
1376 UnixFolder_IPersistFolder3_GetClassID
,
1377 UnixFolder_IPersistFolder3_Initialize
,
1378 UnixFolder_IPersistFolder3_GetCurFolder
,
1379 UnixFolder_IPersistFolder3_InitializeEx
,
1380 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1383 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag
* This
,
1384 REFIID riid
, void** ppvObject
)
1386 return UnixFolder_IShellFolder2_QueryInterface(
1387 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
), riid
, ppvObject
);
1390 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag
* This
)
1392 return UnixFolder_IShellFolder2_AddRef(
1393 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
));
1396 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag
* This
)
1398 return UnixFolder_IShellFolder2_Release(
1399 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
));
1402 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag
* iface
,
1405 return UnixFolder_IPersistFolder3_GetClassID(
1406 (IPersistFolder3
*)&ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)->lpIPersistFolder3Vtbl
,
1410 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag
* iface
)
1416 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag
*iface
,
1417 IPropertyBag
*pPropertyBag
, IErrorLog
*pErrorLog
)
1419 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
);
1420 static const WCHAR wszTarget
[] = { 'T','a','r','g','e','t', 0 }, wszNull
[] = { 0 };
1421 PERSIST_FOLDER_TARGET_INFO pftiTarget
;
1425 TRACE("(iface=%p, pPropertyBag=%p, pErrorLog=%p)\n", iface
, pPropertyBag
, pErrorLog
);
1430 /* Get 'Target' property from the property bag. */
1431 V_VT(&var
) = VT_BSTR
;
1432 hr
= IPropertyBag_Read(pPropertyBag
, wszTarget
, &var
, NULL
);
1435 lstrcpyW(pftiTarget
.szTargetParsingName
, V_BSTR(&var
));
1436 SysFreeString(V_BSTR(&var
));
1438 pftiTarget
.pidlTargetFolder
= NULL
;
1439 lstrcpyW(pftiTarget
.szNetworkProvider
, wszNull
);
1440 pftiTarget
.dwAttributes
= -1;
1441 pftiTarget
.csidl
= -1;
1443 return UnixFolder_IPersistFolder3_InitializeEx(
1444 STATIC_CAST(IPersistFolder3
, This
), NULL
, NULL
, &pftiTarget
);
1447 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag
*iface
,
1448 IPropertyBag
*pPropertyBag
, BOOL fClearDirty
, BOOL fSaveAllProperties
)
1454 /* VTable for UnixFolder's IPersistPropertyBag interface.
1456 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl
= {
1457 UnixFolder_IPersistPropertyBag_QueryInterface
,
1458 UnixFolder_IPersistPropertyBag_AddRef
,
1459 UnixFolder_IPersistPropertyBag_Release
,
1460 UnixFolder_IPersistPropertyBag_GetClassID
,
1461 UnixFolder_IPersistPropertyBag_InitNew
,
1462 UnixFolder_IPersistPropertyBag_Load
,
1463 UnixFolder_IPersistPropertyBag_Save
1466 static HRESULT WINAPI
UnixFolder_ISFHelper_QueryInterface(ISFHelper
* iface
, REFIID riid
,
1469 return UnixFolder_IShellFolder2_QueryInterface(
1470 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
), riid
, ppvObject
);
1473 static ULONG WINAPI
UnixFolder_ISFHelper_AddRef(ISFHelper
* iface
)
1475 return UnixFolder_IShellFolder2_AddRef(
1476 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1479 static ULONG WINAPI
UnixFolder_ISFHelper_Release(ISFHelper
* iface
)
1481 return UnixFolder_IShellFolder2_Release(
1482 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1485 static HRESULT WINAPI
UnixFolder_ISFHelper_GetUniqueName(ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1487 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1490 LPITEMIDLIST pidlElem
;
1493 static const char szNewFolder
[] = "New Folder";
1495 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface
, lpName
, uLen
);
1497 if (uLen
< sizeof(szNewFolder
)+3)
1498 return E_INVALIDARG
;
1500 hr
= IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2
, This
), 0,
1501 SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
, &pEnum
);
1502 if (SUCCEEDED(hr
)) {
1503 lstrcpyA(lpName
, szNewFolder
);
1504 IEnumIDList_Reset(pEnum
);
1506 while ((IEnumIDList_Next(pEnum
, 1, &pidlElem
, &dwFetched
) == S_OK
) && (dwFetched
== 1)) {
1507 if (!strcasecmp(_ILGetTextPointer(pidlElem
), lpName
)) {
1508 IEnumIDList_Reset(pEnum
);
1509 sprintf(lpName
, "%s %d", szNewFolder
, i
++);
1516 IEnumIDList_Release(pEnum
);
1521 static HRESULT WINAPI
UnixFolder_ISFHelper_AddFolder(ISFHelper
* iface
, HWND hwnd
, LPCSTR pszName
,
1522 LPITEMIDLIST
* ppidlOut
)
1524 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1525 char szNewDir
[FILENAME_MAX
];
1527 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface
, hwnd
, pszName
, ppidlOut
);
1532 lstrcpyA(szNewDir
, This
->m_pszPath
);
1533 lstrcatA(szNewDir
, pszName
);
1535 if (mkdir(szNewDir
, 0755)) {
1536 char szMessage
[256 + FILENAME_MAX
];
1537 char szCaption
[256];
1539 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, szCaption
, sizeof(szCaption
));
1540 sprintf(szMessage
, szCaption
, szNewDir
);
1541 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, szCaption
, sizeof(szCaption
));
1542 MessageBoxA(hwnd
, szMessage
, szCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1546 LPITEMIDLIST pidlRelative
;
1547 WCHAR wszName
[MAX_PATH
];
1549 /* Inform the shell */
1550 MultiByteToWideChar(CP_UNIXCP
, 0, pszName
, -1, wszName
, MAX_PATH
);
1551 if (UNIXFS_path_to_pidl(This
, wszName
, &pidlRelative
)) {
1552 LPITEMIDLIST pidlAbsolute
= ILCombine(This
->m_pidlLocation
, pidlRelative
);
1554 *ppidlOut
= pidlRelative
;
1556 ILFree(pidlRelative
);
1557 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1558 ILFree(pidlAbsolute
);
1564 static HRESULT WINAPI
UnixFolder_ISFHelper_DeleteItems(ISFHelper
* iface
, UINT cidl
,
1565 LPCITEMIDLIST
* apidl
)
1567 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1568 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1569 LPITEMIDLIST pidlAbsolute
;
1573 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface
, cidl
, apidl
);
1575 lstrcpyA(szAbsolute
, This
->m_pszPath
);
1576 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
1578 for (i
=0; i
<cidl
&& SUCCEEDED(hr
); i
++) {
1579 lstrcpyA(pszRelative
, _ILGetTextPointer(apidl
[i
]));
1580 pidlAbsolute
= ILCombine(This
->m_pidlLocation
, apidl
[i
]);
1581 if (_ILIsFolder(apidl
[i
])) {
1582 if (rmdir(szAbsolute
)) {
1585 SHChangeNotify(SHCNE_RMDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1587 } else if (_ILIsValue(apidl
[i
])) {
1588 if (unlink(szAbsolute
)) {
1591 SHChangeNotify(SHCNE_DELETE
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1594 ILFree(pidlAbsolute
);
1600 static HRESULT WINAPI
UnixFolder_ISFHelper_CopyItems(ISFHelper
* iface
, IShellFolder
*psfFrom
,
1601 UINT cidl
, LPCITEMIDLIST
*apidl
)
1603 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1607 char szAbsoluteDst
[FILENAME_MAX
], *pszRelativeDst
;
1609 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface
, psfFrom
, cidl
, apidl
);
1611 if (!psfFrom
|| !cidl
|| !apidl
)
1612 return E_INVALIDARG
;
1614 /* All source items have to be filesystem items. */
1615 dwAttributes
= SFGAO_FILESYSTEM
;
1616 hr
= IShellFolder_GetAttributesOf(psfFrom
, cidl
, apidl
, &dwAttributes
);
1617 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
))
1618 return E_INVALIDARG
;
1620 lstrcpyA(szAbsoluteDst
, This
->m_pszPath
);
1621 pszRelativeDst
= szAbsoluteDst
+ strlen(szAbsoluteDst
);
1623 for (i
=0; i
<cidl
; i
++) {
1624 WCHAR wszSrc
[MAX_PATH
];
1625 char szSrc
[FILENAME_MAX
];
1628 /* Build the unix path of the current source item. */
1629 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom
, apidl
[i
], SHGDN_FORPARSING
, &strret
)))
1631 if (FAILED(StrRetToBufW(&strret
, apidl
[i
], wszSrc
, MAX_PATH
)))
1633 if (!UNIXFS_get_unix_path(wszSrc
, szSrc
))
1636 /* Build the unix path of the current destination item */
1637 lstrcpyA(pszRelativeDst
, _ILGetTextPointer(apidl
[i
]));
1639 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc
, szAbsoluteDst
);
1644 /* VTable for UnixFolder's ISFHelper interface
1646 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl
= {
1647 UnixFolder_ISFHelper_QueryInterface
,
1648 UnixFolder_ISFHelper_AddRef
,
1649 UnixFolder_ISFHelper_Release
,
1650 UnixFolder_ISFHelper_GetUniqueName
,
1651 UnixFolder_ISFHelper_AddFolder
,
1652 UnixFolder_ISFHelper_DeleteItems
,
1653 UnixFolder_ISFHelper_CopyItems
1656 /******************************************************************************
1657 * Unix[Dos]Folder_Constructor [Internal]
1660 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1661 * riid [I] Interface asked for by the client.
1662 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1665 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1666 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1667 * compatible signature.
1669 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1670 * means that paths are converted from dos to unix and back at the interfaces.
1672 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, const CLSID
*pCLSID
)
1674 HRESULT hr
= E_FAIL
;
1675 UnixFolder
*pUnixFolder
= SHAlloc((ULONG
)sizeof(UnixFolder
));
1678 FIXME("Aggregation not yet implemented!\n");
1679 return CLASS_E_NOAGGREGATION
;
1683 pUnixFolder
->lpIShellFolder2Vtbl
= &UnixFolder_IShellFolder2_Vtbl
;
1684 pUnixFolder
->lpIPersistFolder3Vtbl
= &UnixFolder_IPersistFolder3_Vtbl
;
1685 pUnixFolder
->lpIPersistPropertyBagVtbl
= &UnixFolder_IPersistPropertyBag_Vtbl
;
1686 pUnixFolder
->lpISFHelperVtbl
= &UnixFolder_ISFHelper_Vtbl
;
1687 pUnixFolder
->m_cRef
= 0;
1688 pUnixFolder
->m_pszPath
= NULL
;
1689 pUnixFolder
->m_pidlLocation
= NULL
;
1690 pUnixFolder
->m_dwPathMode
= IsEqualCLSID(&CLSID_UnixFolder
, pCLSID
) ? PATHMODE_UNIX
: PATHMODE_DOS
;
1691 pUnixFolder
->m_dwAttributes
= 0;
1692 pUnixFolder
->m_pCLSID
= pCLSID
;
1694 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1695 hr
= UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2
, pUnixFolder
), riid
, ppv
);
1696 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1701 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1702 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1703 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_UnixFolder
);
1706 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1707 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1708 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_UnixDosFolder
);
1711 HRESULT WINAPI
FolderShortcut_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1712 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1713 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_FolderShortcut
);
1716 HRESULT WINAPI
MyDocuments_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1717 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1718 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_MyDocuments
);
1721 /******************************************************************************
1722 * UnixSubFolderIterator
1724 * Class whose heap based objects represent iterators over the sub-directories
1725 * of a given UnixFolder object.
1728 /* UnixSubFolderIterator object layout and typedef.
1730 typedef struct _UnixSubFolderIterator
{
1731 const IEnumIDListVtbl
*lpIEnumIDListVtbl
;
1735 char m_szFolder
[FILENAME_MAX
];
1736 } UnixSubFolderIterator
;
1738 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator
*iterator
) {
1739 TRACE("(iterator=%p)\n", iterator
);
1741 if (iterator
->m_dirFolder
)
1742 closedir(iterator
->m_dirFolder
);
1746 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList
* iface
,
1747 REFIID riid
, void** ppv
)
1749 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
1751 if (!ppv
) return E_INVALIDARG
;
1753 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumIDList
, riid
)) {
1757 return E_NOINTERFACE
;
1760 IEnumIDList_AddRef(iface
);
1764 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList
* iface
)
1766 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1768 TRACE("(iface=%p)\n", iface
);
1770 return InterlockedIncrement(&This
->m_cRef
);
1773 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList
* iface
)
1775 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1778 TRACE("(iface=%p)\n", iface
);
1780 cRef
= InterlockedDecrement(&This
->m_cRef
);
1783 UnixSubFolderIterator_Destroy(This
);
1788 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList
* iface
, ULONG celt
,
1789 LPITEMIDLIST
* rgelt
, ULONG
* pceltFetched
)
1791 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1794 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
1795 if (This
->m_dirFolder
) {
1796 char *pszRelativePath
= This
->m_szFolder
+ lstrlenA(This
->m_szFolder
);
1797 struct dirent
*pDirEntry
;
1800 pDirEntry
= readdir(This
->m_dirFolder
);
1801 if (!pDirEntry
) break; /* No more entries */
1802 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
1804 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
1805 * and see if it passes the filter.
1807 lstrcpyA(pszRelativePath
, pDirEntry
->d_name
);
1808 rgelt
[i
] = (LPITEMIDLIST
)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath
))+sizeof(USHORT
));
1809 if (!UNIXFS_build_shitemid(This
->m_szFolder
, rgelt
[i
]) ||
1810 !UNIXFS_is_pidl_of_type(rgelt
[i
], This
->m_fFilter
))
1815 memset(((PBYTE
)rgelt
[i
])+rgelt
[i
]->mkid
.cb
, 0, sizeof(USHORT
));
1818 *pszRelativePath
= '\0'; /* Restore the original path in This->m_szFolder. */
1824 return (i
== 0) ? S_FALSE
: S_OK
;
1827 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList
* iface
, ULONG celt
)
1829 LPITEMIDLIST
*apidl
;
1833 TRACE("(iface=%p, celt=%ld)\n", iface
, celt
);
1835 /* Call IEnumIDList::Next and delete the resulting pidls. */
1836 apidl
= (LPITEMIDLIST
*)SHAlloc(celt
* sizeof(LPITEMIDLIST
));
1837 hr
= IEnumIDList_Next(iface
, celt
, apidl
, &cFetched
);
1840 SHFree(apidl
[cFetched
]);
1846 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList
* iface
)
1848 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1850 TRACE("(iface=%p)\n", iface
);
1852 if (This
->m_dirFolder
)
1853 rewinddir(This
->m_dirFolder
);
1858 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList
* This
,
1859 IEnumIDList
** ppenum
)
1865 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1867 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl
= {
1868 UnixSubFolderIterator_IEnumIDList_QueryInterface
,
1869 UnixSubFolderIterator_IEnumIDList_AddRef
,
1870 UnixSubFolderIterator_IEnumIDList_Release
,
1871 UnixSubFolderIterator_IEnumIDList_Next
,
1872 UnixSubFolderIterator_IEnumIDList_Skip
,
1873 UnixSubFolderIterator_IEnumIDList_Reset
,
1874 UnixSubFolderIterator_IEnumIDList_Clone
1877 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
) {
1878 UnixSubFolderIterator
*iterator
;
1880 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
1882 iterator
= SHAlloc((ULONG
)sizeof(UnixSubFolderIterator
));
1883 iterator
->lpIEnumIDListVtbl
= &UnixSubFolderIterator_IEnumIDList_Vtbl
;
1884 iterator
->m_cRef
= 0;
1885 iterator
->m_fFilter
= fFilter
;
1886 iterator
->m_dirFolder
= opendir(pUnixFolder
->m_pszPath
);
1887 lstrcpyA(iterator
->m_szFolder
, pUnixFolder
->m_pszPath
);
1889 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList
*)iterator
);
1891 return (IUnknown
*)iterator
;