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 #include "wine/port.h"
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
51 #include "wine/debug.h"
53 #include "shell32_main.h"
54 #include "shellfolder.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
61 const GUID CLSID_UnixFolder
= {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
62 const GUID CLSID_UnixDosFolder
= {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
64 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
65 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
67 /* FileStruct reserves one byte for szNames, thus we don't have to
68 * alloc a byte for the terminating '\0' of 'name'. Two of the
69 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
70 * type field. One is for FileStruct's szNames field, to terminate
71 * the alternate DOS name, which we don't use here.
73 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
74 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char))
75 #define NAME_LEN_FROM_LPSHITEMID(s) \
76 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char))
78 #define PATHMODE_UNIX 0
79 #define PATHMODE_DOS 1
81 /* UnixFolder object layout and typedef.
83 typedef struct _UnixFolder
{
84 const IShellFolder2Vtbl
*lpIShellFolder2Vtbl
;
85 const IPersistFolder3Vtbl
*lpIPersistFolder3Vtbl
;
86 const ISFHelperVtbl
*lpISFHelperVtbl
;
89 LPITEMIDLIST m_pidlLocation
;
92 const CLSID
*m_pCLSID
;
95 /******************************************************************************
96 * UNIXFS_is_rooted_at_desktop [Internal]
98 * Checks if the unixfs namespace extension is rooted at desktop level.
101 * TRUE, if unixfs is rooted at desktop level
104 BOOL
UNIXFS_is_rooted_at_desktop(void) {
106 WCHAR
*pwszCLSID_UnixDosFolder
, wszRootedAtDesktop
[69 + CHARS_IN_GUID
] = {
107 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
108 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
109 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
110 'N','a','m','e','S','p','a','c','e','\\',0 };
112 if (FAILED(StringFromCLSID(&CLSID_UnixDosFolder
, &pwszCLSID_UnixDosFolder
)))
115 lstrcatW(wszRootedAtDesktop
, pwszCLSID_UnixDosFolder
);
116 CoTaskMemFree(pwszCLSID_UnixDosFolder
);
118 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszRootedAtDesktop
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
125 /******************************************************************************
126 * UNIXFS_is_pidl_of_type [INTERNAL]
128 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
131 * pIDL [I] The ITEMIDLIST to be checked.
132 * fFilter [I] Shell condition flags, which specify the filter.
135 * TRUE, if pIDL is accepted by fFilter
138 static inline BOOL
UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL
, SHCONTF fFilter
) {
139 LPPIDLDATA pIDLData
= _ILGetDataPointer(pIDL
);
140 if (!(fFilter
& SHCONTF_INCLUDEHIDDEN
) && pIDLData
&&
141 (pIDLData
->u
.file
.uFileAttribs
& FILE_ATTRIBUTE_HIDDEN
))
145 if (_ILIsFolder(pIDL
) && (fFilter
& SHCONTF_FOLDERS
)) return TRUE
;
146 if (_ILIsValue(pIDL
) && (fFilter
& SHCONTF_NONFOLDERS
)) return TRUE
;
150 /******************************************************************************
151 * UNIXFS_is_dos_device [Internal]
153 * Determines if a unix directory corresponds to any dos device.
156 * statPath [I] The stat struct of the directory, as returned by stat(2).
159 * TRUE, if statPath corresponds to any dos drive letter
162 static BOOL
UNIXFS_is_dos_device(const struct stat
*statPath
) {
163 struct stat statDrive
;
166 WCHAR wszDosDevice
[4] = { 'A', ':', '\\', 0 };
168 for (dwDriveMap
= GetLogicalDrives(); dwDriveMap
; dwDriveMap
>>= 1, wszDosDevice
[0]++) {
169 if (!(dwDriveMap
& 0x1)) continue;
170 pszDrivePath
= wine_get_unix_file_name(wszDosDevice
);
171 if (pszDrivePath
&& !stat(pszDrivePath
, &statDrive
)) {
172 HeapFree(GetProcessHeap(), 0, pszDrivePath
);
173 if ((statPath
->st_dev
== statDrive
.st_dev
) && (statPath
->st_ino
== statDrive
.st_ino
))
180 /******************************************************************************
181 * UNIXFS_get_unix_path [Internal]
183 * Convert an absolute dos path to an absolute canonicalized unix path.
184 * Evaluate "/.", "/.." and symbolic links.
187 * pszDosPath [I] An absolute dos path
188 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
192 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
194 static BOOL
UNIXFS_get_unix_path(LPCWSTR pszDosPath
, char *pszCanonicalPath
)
196 char *pPathTail
, *pElement
, *pCanonicalTail
, szPath
[FILENAME_MAX
], *pszUnixPath
;
197 struct stat fileStat
;
199 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath
), pszCanonicalPath
);
201 if (!pszDosPath
|| pszDosPath
[1] != ':')
204 pszUnixPath
= wine_get_unix_file_name(pszDosPath
);
205 if (!pszUnixPath
) return FALSE
;
206 strcpy(szPath
, pszUnixPath
);
207 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
209 /* pCanonicalTail always points to the end of the canonical path constructed
210 * thus far. pPathTail points to the still to be processed part of the input
211 * path. pElement points to the path element currently investigated.
213 *pszCanonicalPath
= '\0';
214 pCanonicalTail
= pszCanonicalPath
;
221 pElement
= pPathTail
;
222 pPathTail
= strchr(pPathTail
+1, '/');
223 if (!pPathTail
) /* Last path element may not be terminated by '/'. */
224 pPathTail
= pElement
+ strlen(pElement
);
225 /* Temporarily terminate the current path element. Will be restored later. */
229 /* Skip "/." path elements */
230 if (!strcmp("/.", pElement
)) {
235 /* Remove last element in canonical path for "/.." elements, then skip. */
236 if (!strcmp("/..", pElement
)) {
237 char *pTemp
= strrchr(pszCanonicalPath
, '/');
239 pCanonicalTail
= pTemp
;
240 *pCanonicalTail
= '\0';
245 /* lstat returns zero on success. */
246 if (lstat(szPath
, &fileStat
))
249 if (S_ISLNK(fileStat
.st_mode
)) {
250 char szSymlink
[FILENAME_MAX
];
251 int cLinkLen
, cTailLen
;
253 /* Avoid infinite loop for recursive links. */
257 cLinkLen
= readlink(szPath
, szSymlink
, FILENAME_MAX
);
262 cTailLen
= strlen(pPathTail
);
264 if (szSymlink
[0] == '/') {
265 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
266 if (cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
269 /* Avoid double slashes. */
270 if (szSymlink
[cLinkLen
-1] == '/' && pPathTail
[0] == '/') {
271 szSymlink
[cLinkLen
-1] = '\0';
275 memcpy(szSymlink
+ cLinkLen
, pPathTail
, cTailLen
+ 1);
276 memcpy(szPath
, szSymlink
, cLinkLen
+ cTailLen
+ 1);
277 *pszCanonicalPath
= '\0';
278 pCanonicalTail
= pszCanonicalPath
;
281 /* Relative link. Expand into szPath and continue. */
282 char szTemp
[FILENAME_MAX
];
283 int cTailLen
= strlen(pPathTail
);
285 if (pElement
- szPath
+ 1 + cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
288 memcpy(szTemp
, pPathTail
, cTailLen
+ 1);
289 memcpy(pElement
+ 1, szSymlink
, cLinkLen
);
290 memcpy(pElement
+ 1 + cLinkLen
, szTemp
, cTailLen
+ 1);
291 pPathTail
= pElement
;
294 /* Regular directory or file. Copy to canonical path */
295 if (pCanonicalTail
- pszCanonicalPath
+ pPathTail
- pElement
+ 1 > FILENAME_MAX
)
298 memcpy(pCanonicalTail
, pElement
, pPathTail
- pElement
+ 1);
299 pCanonicalTail
+= pPathTail
- pElement
;
302 } while (pPathTail
[0] == '/');
304 TRACE("--> %s\n", debugstr_a(pszCanonicalPath
));
309 /******************************************************************************
310 * UNIXFS_build_shitemid [Internal]
312 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
316 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
317 * pIDL [O] SHITEMID will be constructed here.
320 * Success: A pointer to the terminating '\0' character of path.
324 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
325 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
328 static char* UNIXFS_build_shitemid(char *pszUnixPath
, void *pIDL
) {
332 struct stat fileStat
;
336 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath
), pIDL
);
338 /* Compute the SHITEMID's length and wipe it. */
339 pszComponent
= strrchr(pszUnixPath
, '/') + 1;
340 cComponentLen
= strlen(pszComponent
);
341 memset(pIDL
, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
));
342 ((LPSHITEMID
)pIDL
)->cb
= SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
) ;
344 /* We are only interested in regular files and directories. */
345 if (stat(pszUnixPath
, &fileStat
)) return NULL
;
346 if (!S_ISDIR(fileStat
.st_mode
) && !S_ISREG(fileStat
.st_mode
)) return NULL
;
348 /* Set shell32's standard SHITEMID data fields. */
349 pIDLData
= _ILGetDataPointer((LPCITEMIDLIST
)pIDL
);
350 pIDLData
->type
= S_ISDIR(fileStat
.st_mode
) ? PT_FOLDER
: PT_VALUE
;
351 pIDLData
->u
.file
.dwFileSize
= (DWORD
)fileStat
.st_size
;
352 RtlSecondsSince1970ToTime( fileStat
.st_mtime
, &time
);
353 fileTime
.dwLowDateTime
= time
.u
.LowPart
;
354 fileTime
.dwHighDateTime
= time
.u
.HighPart
;
355 FileTimeToDosDateTime(&fileTime
, &pIDLData
->u
.file
.uFileDate
, &pIDLData
->u
.file
.uFileTime
);
356 pIDLData
->u
.file
.uFileAttribs
= 0;
357 if (S_ISDIR(fileStat
.st_mode
)) pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_DIRECTORY
;
358 if (pszComponent
[0] == '.') pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_HIDDEN
;
359 memcpy(pIDLData
->u
.file
.szNames
, pszComponent
, cComponentLen
);
361 return pszComponent
+ cComponentLen
;
364 /******************************************************************************
365 * UNIXFS_path_to_pidl [Internal]
368 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
369 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
370 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
374 * Failure: FALSE, invalid params or out of memory
377 * pUnixFolder also carries the information if the path is expected to be unix or dos.
379 static BOOL
UNIXFS_path_to_pidl(UnixFolder
*pUnixFolder
, const WCHAR
*path
, LPITEMIDLIST
*ppidl
) {
381 int cSubDirs
, cPidlLen
, cPathLen
;
382 char *pSlash
, szCompletePath
[FILENAME_MAX
], *pNextPathElement
;
384 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder
, debugstr_w(path
), ppidl
);
389 /* Build an absolute path and let pNextPathElement point to the interesting
390 * relative sub-path. We need the absolute path to call 'stat', but the pidl
391 * will only contain the relative part.
393 if ((pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) && (path
[1] == ':'))
395 /* Absolute dos path. Convert to unix */
396 if (!UNIXFS_get_unix_path(path
, szCompletePath
))
398 pNextPathElement
= szCompletePath
;
400 else if ((pUnixFolder
->m_dwPathMode
== PATHMODE_UNIX
) && (path
[0] == '/'))
402 /* Absolute unix path. Just convert to ANSI. */
403 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
, FILENAME_MAX
, NULL
, NULL
);
404 pNextPathElement
= szCompletePath
;
408 /* Relative dos or unix path. Concat with this folder's path */
409 int cBasePathLen
= strlen(pUnixFolder
->m_pszPath
);
410 memcpy(szCompletePath
, pUnixFolder
->m_pszPath
, cBasePathLen
);
411 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
+ cBasePathLen
,
412 FILENAME_MAX
- cBasePathLen
, NULL
, NULL
);
413 pNextPathElement
= szCompletePath
+ cBasePathLen
- 1;
415 /* If in dos mode, replace '\' with '/' */
416 if (pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) {
417 char *pBackslash
= strchr(pNextPathElement
, '\\');
420 pBackslash
= strchr(pBackslash
, '\\');
425 /* Special case for the root folder. */
426 if (!strcmp(szCompletePath
, "/")) {
427 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(sizeof(USHORT
));
428 if (!pidl
) return FALSE
;
429 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
433 /* Remove trailing slash, if present */
434 cPathLen
= strlen(szCompletePath
);
435 if (szCompletePath
[cPathLen
-1] == '/')
436 szCompletePath
[cPathLen
-1] = '\0';
438 if ((szCompletePath
[0] != '/') || (pNextPathElement
[0] != '/')) {
439 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath
, pNextPathElement
);
443 /* At this point, we have an absolute unix path in szCompletePath
444 * and the relative portion of it in pNextPathElement. Both starting with '/'
445 * and _not_ terminated by a '/'. */
446 TRACE("complete path: %s, relative path: %s\n", szCompletePath
, pNextPathElement
);
448 /* Count the number of sub-directories in the path */
450 pSlash
= pNextPathElement
;
453 pSlash
= strchr(pSlash
+1, '/');
456 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
457 * characters, which are not stored in the ITEMIDLIST. */
458 cPidlLen
= strlen(pNextPathElement
) - cSubDirs
+ cSubDirs
* SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT
);
459 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(cPidlLen
);
460 if (!pidl
) return FALSE
;
462 /* Concatenate the SHITEMIDs of the sub-directories. */
463 while (*pNextPathElement
) {
464 pSlash
= strchr(pNextPathElement
+1, '/');
465 if (pSlash
) *pSlash
= '\0';
466 pNextPathElement
= UNIXFS_build_shitemid(szCompletePath
, pidl
);
467 if (pSlash
) *pSlash
= '/';
469 if (!pNextPathElement
) {
473 pidl
= ILGetNext(pidl
);
475 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
477 if ((int)pidl
-(int)*ppidl
+sizeof(USHORT
) != cPidlLen
) /* We've corrupted the heap :( */
478 ERR("Computed length of pidl incorrect. Please report.\n");
483 /******************************************************************************
486 * Class whose heap based instances represent unix filesystem directories.
489 static void UnixFolder_Destroy(UnixFolder
*pUnixFolder
) {
490 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
492 SHFree(pUnixFolder
->m_pszPath
);
493 ILFree(pUnixFolder
->m_pidlLocation
);
497 static HRESULT WINAPI
UnixFolder_IShellFolder2_QueryInterface(IShellFolder2
*iface
, REFIID riid
,
500 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
502 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
504 if (!ppv
) return E_INVALIDARG
;
506 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellFolder
, riid
) ||
507 IsEqualIID(&IID_IShellFolder2
, riid
))
509 *ppv
= &This
->lpIShellFolder2Vtbl
;
510 } else if (IsEqualIID(&IID_IPersistFolder3
, riid
) || IsEqualIID(&IID_IPersistFolder2
, riid
) ||
511 IsEqualIID(&IID_IPersistFolder
, riid
) || IsEqualIID(&IID_IPersist
, riid
))
513 *ppv
= &This
->lpIPersistFolder3Vtbl
;
514 } else if (IsEqualIID(&IID_ISFHelper
, riid
)) {
515 *ppv
= &This
->lpISFHelperVtbl
;
518 return E_NOINTERFACE
;
521 IUnknown_AddRef((IUnknown
*)*ppv
);
525 static ULONG WINAPI
UnixFolder_IShellFolder2_AddRef(IShellFolder2
*iface
) {
526 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
528 TRACE("(iface=%p)\n", iface
);
530 return InterlockedIncrement(&This
->m_cRef
);
533 static ULONG WINAPI
UnixFolder_IShellFolder2_Release(IShellFolder2
*iface
) {
534 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
537 TRACE("(iface=%p)\n", iface
);
539 cRef
= InterlockedDecrement(&This
->m_cRef
);
542 UnixFolder_Destroy(This
);
547 static HRESULT WINAPI
UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2
* iface
, HWND hwndOwner
,
548 LPBC pbcReserved
, LPOLESTR lpszDisplayName
, ULONG
* pchEaten
, LPITEMIDLIST
* ppidl
,
549 ULONG
* pdwAttributes
)
551 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
554 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
555 "pdwAttributes=%p) stub\n", iface
, hwndOwner
, pbcReserved
, debugstr_w(lpszDisplayName
),
556 pchEaten
, ppidl
, pdwAttributes
);
558 result
= UNIXFS_path_to_pidl(This
, lpszDisplayName
, ppidl
);
559 if (result
&& pdwAttributes
&& *pdwAttributes
)
561 IShellFolder
*pParentSF
;
562 LPCITEMIDLIST pidlLast
;
565 hr
= SHBindToParent(*ppidl
, &IID_IShellFolder
, (LPVOID
*)&pParentSF
, &pidlLast
);
566 if (FAILED(hr
)) return E_FAIL
;
567 IShellFolder_GetAttributesOf(pParentSF
, 1, &pidlLast
, pdwAttributes
);
568 IShellFolder_Release(pParentSF
);
571 if (!result
) TRACE("FAILED!\n");
572 return result
? S_OK
: E_FAIL
;
575 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
);
577 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumObjects(IShellFolder2
* iface
, HWND hwndOwner
,
578 SHCONTF grfFlags
, IEnumIDList
** ppEnumIDList
)
580 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
581 IUnknown
*newIterator
;
584 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
585 iface
, hwndOwner
, grfFlags
, ppEnumIDList
);
587 newIterator
= UnixSubFolderIterator_Constructor(This
, grfFlags
);
588 hr
= IUnknown_QueryInterface(newIterator
, &IID_IEnumIDList
, (void**)ppEnumIDList
);
589 IUnknown_Release(newIterator
);
594 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToObject(IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
595 LPBC pbcReserved
, REFIID riid
, void** ppvOut
)
597 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
598 IPersistFolder3
*persistFolder
;
599 LPITEMIDLIST pidlSubFolder
;
602 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
603 iface
, pidl
, pbcReserved
, riid
, ppvOut
);
605 if (!pidl
|| !pidl
->mkid
.cb
)
608 if (This
->m_dwPathMode
== PATHMODE_DOS
)
609 hr
= UnixDosFolder_Constructor(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
);
611 hr
= UnixFolder_Constructor(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
);
613 if (!SUCCEEDED(hr
)) return hr
;
614 hr
= IPersistFolder_QueryInterface(persistFolder
, riid
, (void**)ppvOut
);
616 pidlSubFolder
= ILCombine(This
->m_pidlLocation
, pidl
);
617 IPersistFolder3_Initialize(persistFolder
, pidlSubFolder
);
618 IPersistFolder3_Release(persistFolder
);
619 ILFree(pidlSubFolder
);
624 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToStorage(IShellFolder2
* This
, LPCITEMIDLIST pidl
,
625 LPBC pbcReserved
, REFIID riid
, void** ppvObj
)
631 static HRESULT WINAPI
UnixFolder_IShellFolder2_CompareIDs(IShellFolder2
* iface
, LPARAM lParam
,
632 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
634 BOOL isEmpty1
, isEmpty2
;
636 LPITEMIDLIST firstpidl
;
640 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface
, lParam
, pidl1
, pidl2
);
642 isEmpty1
= !pidl1
|| !pidl1
->mkid
.cb
;
643 isEmpty2
= !pidl2
|| !pidl2
->mkid
.cb
;
645 if (isEmpty1
&& isEmpty2
)
646 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
648 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
650 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
652 if (_ILIsFolder(pidl1
) && !_ILIsFolder(pidl2
))
653 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
654 if (!_ILIsFolder(pidl1
) && _ILIsFolder(pidl2
))
655 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
657 compare
= CompareStringA(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
,
658 _ILGetTextPointer(pidl1
), NAME_LEN_FROM_LPSHITEMID(pidl1
),
659 _ILGetTextPointer(pidl2
), NAME_LEN_FROM_LPSHITEMID(pidl2
));
661 if ((compare
== CSTR_LESS_THAN
) || (compare
== CSTR_GREATER_THAN
))
662 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)((compare
== CSTR_LESS_THAN
)?-1:1));
664 if (pidl1
->mkid
.cb
< pidl2
->mkid
.cb
)
665 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
666 else if (pidl1
->mkid
.cb
> pidl2
->mkid
.cb
)
667 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
669 firstpidl
= ILCloneFirst(pidl1
);
670 pidl1
= ILGetNext(pidl1
);
671 pidl2
= ILGetNext(pidl2
);
673 hr
= IShellFolder2_BindToObject(iface
, firstpidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
);
675 hr
= IShellFolder_CompareIDs(psf
, lParam
, pidl1
, pidl2
);
676 IShellFolder2_Release(psf
);
683 static HRESULT WINAPI
UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2
* iface
, HWND hwndOwner
,
684 REFIID riid
, void** ppv
)
686 HRESULT hr
= E_INVALIDARG
;
688 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface
, hwndOwner
, riid
, ppv
);
690 if (!ppv
) return E_INVALIDARG
;
693 if (IsEqualIID(&IID_IShellView
, riid
)) {
694 LPSHELLVIEW pShellView
;
696 pShellView
= IShellView_Constructor((IShellFolder
*)iface
);
698 hr
= IShellView_QueryInterface(pShellView
, riid
, ppv
);
699 IShellView_Release(pShellView
);
706 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2
* iface
, UINT cidl
,
707 LPCITEMIDLIST
* apidl
, SFGAOF
* rgfInOut
)
709 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
712 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface
, cidl
, apidl
, rgfInOut
);
714 if (!rgfInOut
|| (cidl
&& !apidl
))
718 *rgfInOut
&= This
->m_dwAttributes
;
720 char szAbsolutePath
[FILENAME_MAX
], *pszRelativePath
;
723 *rgfInOut
&= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|
725 lstrcpyA(szAbsolutePath
, This
->m_pszPath
);
726 pszRelativePath
= szAbsolutePath
+ lstrlenA(szAbsolutePath
);
727 for (i
=0; i
<cidl
; i
++) {
728 if ((*rgfInOut
& SFGAO_FILESYSTEM
) && !(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
729 struct stat fileStat
;
730 char *pszName
= _ILGetTextPointer(apidl
[i
]);
731 if (!pszName
) return E_INVALIDARG
;
732 lstrcpyA(pszRelativePath
, pszName
);
733 if (stat(szAbsolutePath
, &fileStat
) || !UNIXFS_is_dos_device(&fileStat
))
734 *rgfInOut
&= ~SFGAO_FILESYSTEM
;
736 if (!_ILIsFolder(apidl
[i
]))
737 *rgfInOut
&= ~(SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
);
744 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2
* iface
, HWND hwndOwner
,
745 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
, UINT
* prgfInOut
, void** ppvOut
)
747 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
749 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
750 iface
, hwndOwner
, cidl
, apidl
, debugstr_guid(riid
), prgfInOut
, ppvOut
);
752 if (IsEqualIID(&IID_IContextMenu
, riid
)) {
753 *ppvOut
= ISvItemCm_Constructor((IShellFolder
*)iface
, This
->m_pidlLocation
, apidl
, cidl
);
755 } else if (IsEqualIID(&IID_IDataObject
, riid
)) {
756 *ppvOut
= IDataObject_Constructor(hwndOwner
, This
->m_pidlLocation
, apidl
, cidl
);
758 } else if (IsEqualIID(&IID_IExtractIconA
, riid
)) {
760 if (cidl
!= 1) return E_FAIL
;
761 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
762 *ppvOut
= (LPVOID
)IExtractIconA_Constructor(pidl
);
765 } else if (IsEqualIID(&IID_IExtractIconW
, riid
)) {
767 if (cidl
!= 1) return E_FAIL
;
768 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
769 *ppvOut
= (LPVOID
)IExtractIconW_Constructor(pidl
);
772 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
773 FIXME("IDropTarget\n");
775 } else if (IsEqualIID(&IID_IShellLinkW
, riid
)) {
776 FIXME("IShellLinkW\n");
778 } else if (IsEqualIID(&IID_IShellLinkA
, riid
)) {
779 FIXME("IShellLinkA\n");
782 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid
));
783 return E_NOINTERFACE
;
787 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2
* iface
,
788 LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
* lpName
)
790 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
793 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface
, pidl
, uFlags
, lpName
);
795 if ((GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) &&
796 (GET_SHGDN_RELATION(uFlags
) != SHGDN_INFOLDER
))
798 if (!pidl
->mkid
.cb
) {
799 lpName
->uType
= STRRET_CSTR
;
800 if (This
->m_dwPathMode
== PATHMODE_UNIX
) {
801 strcpy(lpName
->u
.cStr
, This
->m_pszPath
);
803 WCHAR
*pwszDosPath
= wine_get_dos_file_name(This
->m_pszPath
);
805 return HRESULT_FROM_WIN32(GetLastError());
806 PathRemoveBackslashW(pwszDosPath
);
807 WideCharToMultiByte(CP_UNIXCP
, 0, pwszDosPath
, -1, lpName
->u
.cStr
, MAX_PATH
, NULL
, NULL
);
808 HeapFree(GetProcessHeap(), 0, pwszDosPath
);
811 IShellFolder
*pSubFolder
;
814 hr
= IShellFolder_BindToObject(iface
, pidl
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
815 if (!SUCCEEDED(hr
)) return hr
;
817 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, lpName
);
818 IShellFolder_Release(pSubFolder
);
821 char *pszFileName
= _ILGetTextPointer(pidl
);
822 lpName
->uType
= STRRET_CSTR
;
823 strcpy(lpName
->u
.cStr
, pszFileName
? pszFileName
: "");
826 /* If in dos mode, do some post-processing on the path.
827 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
829 if (SUCCEEDED(hr
) && This
->m_dwPathMode
== PATHMODE_DOS
&& !_ILIsFolder(pidl
))
830 SHELL_FS_ProcessDisplayFilename(lpName
->u
.cStr
, uFlags
);
832 TRACE("--> %s\n", lpName
->u
.cStr
);
837 static HRESULT WINAPI
UnixFolder_IShellFolder2_SetNameOf(IShellFolder2
* iface
, HWND hwnd
,
838 LPCITEMIDLIST pidl
, LPCOLESTR lpszName
, SHGDNF uFlags
, LPITEMIDLIST
* ppidlOut
)
840 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
842 char szSrc
[FILENAME_MAX
], szDest
[FILENAME_MAX
];
844 int cBasePathLen
= lstrlenA(This
->m_pszPath
);
845 struct stat statDest
;
846 LPITEMIDLIST pidlSrc
, pidlDest
;
848 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
849 iface
, hwnd
, pidl
, debugstr_w(lpszName
), uFlags
, ppidlOut
);
851 /* pidl has to contain a single non-empty SHITEMID */
852 if (_ILIsDesktop(pidl
) || !_ILIsPidlSimple(pidl
) || !_ILGetTextPointer(pidl
))
858 /* build source path */
859 memcpy(szSrc
, This
->m_pszPath
, cBasePathLen
);
860 lstrcpyA(szSrc
+cBasePathLen
, _ILGetTextPointer(pidl
));
862 /* build destination path */
863 if (uFlags
& SHGDN_FORPARSING
) { /* absolute path in lpszName */
864 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
, FILENAME_MAX
, NULL
, NULL
);
866 WCHAR wszSrcRelative
[MAX_PATH
];
867 memcpy(szDest
, This
->m_pszPath
, cBasePathLen
);
868 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
+cBasePathLen
,
869 FILENAME_MAX
-cBasePathLen
, NULL
, NULL
);
871 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
872 * extension is hidden to the user, we have to append it. */
873 if (_ILSimpleGetTextW(pidl
, wszSrcRelative
, MAX_PATH
) &&
874 SHELL_FS_HideExtension(wszSrcRelative
))
876 char *pszExt
= PathFindExtensionA(_ILGetTextPointer(pidl
));
877 lstrcatA(szDest
, pszExt
);
881 TRACE("src=%s dest=%s\n", szSrc
, szDest
);
883 /* Fail, if destination does already exist */
884 if (!stat(szDest
, &statDest
))
887 /* Rename the file */
888 if (rename(szSrc
, szDest
))
891 /* Build a pidl for the path of the renamed file */
892 pwszDosDest
= wine_get_dos_file_name(szDest
);
893 if (!pwszDosDest
|| !UNIXFS_path_to_pidl(This
, pwszDosDest
, &pidlDest
)) {
894 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
895 rename(szDest
, szSrc
); /* Undo the renaming */
899 /* Inform the shell */
900 pidlSrc
= ILCombine(This
->m_pidlLocation
, pidl
);
901 if (_ILIsFolder(ILFindLastID(pidlDest
)))
902 SHChangeNotify(SHCNE_RENAMEFOLDER
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
904 SHChangeNotify(SHCNE_RENAMEITEM
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
909 _ILCreateFromPathW(pwszDosDest
, ppidlOut
);
911 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
915 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumSearches(IShellFolder2
* iface
,
916 IEnumExtraSearch
**ppEnum
)
922 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2
* iface
,
923 DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
929 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2
* iface
,
930 UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
936 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2
* iface
,
943 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2
* iface
,
944 LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
950 #define SHELLVIEWCOLUMNS 7
952 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2
* iface
,
953 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
*psd
)
955 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
957 struct passwd
*pPasswd
;
958 struct group
*pGroup
;
959 static const shvheader SFHeader
[SHELLVIEWCOLUMNS
] = {
960 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
961 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
962 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
963 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
964 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 9},
965 {IDS_SHV_COLUMN10
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
966 {IDS_SHV_COLUMN11
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7}
969 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface
, pidl
, iColumn
, psd
);
971 if (!psd
|| iColumn
>= SHELLVIEWCOLUMNS
)
975 psd
->fmt
= SFHeader
[iColumn
].fmt
;
976 psd
->cxChar
= SFHeader
[iColumn
].cxChar
;
977 psd
->str
.uType
= STRRET_CSTR
;
978 LoadStringA(shell32_hInstance
, SFHeader
[iColumn
].colnameid
, psd
->str
.u
.cStr
, MAX_PATH
);
981 struct stat statItem
;
982 if (iColumn
== 4 || iColumn
== 5 || iColumn
== 6) {
983 char szPath
[FILENAME_MAX
], *pszFile
= _ILGetTextPointer(pidl
);
986 lstrcpyA(szPath
, This
->m_pszPath
);
987 lstrcatA(szPath
, pszFile
);
988 if (stat(szPath
, &statItem
))
991 psd
->str
.u
.cStr
[0] = '\0';
992 psd
->str
.uType
= STRRET_CSTR
;
995 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
|SHGDN_INFOLDER
, &psd
->str
);
998 _ILGetFileSize(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1001 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1004 _ILGetFileDate(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1007 psd
->str
.u
.cStr
[0] = S_ISDIR(statItem
.st_mode
) ? 'd' : '-';
1008 psd
->str
.u
.cStr
[1] = (statItem
.st_mode
& S_IRUSR
) ? 'r' : '-';
1009 psd
->str
.u
.cStr
[2] = (statItem
.st_mode
& S_IWUSR
) ? 'w' : '-';
1010 psd
->str
.u
.cStr
[3] = (statItem
.st_mode
& S_IXUSR
) ? 'x' : '-';
1011 psd
->str
.u
.cStr
[4] = (statItem
.st_mode
& S_IRGRP
) ? 'r' : '-';
1012 psd
->str
.u
.cStr
[5] = (statItem
.st_mode
& S_IWGRP
) ? 'w' : '-';
1013 psd
->str
.u
.cStr
[6] = (statItem
.st_mode
& S_IXGRP
) ? 'x' : '-';
1014 psd
->str
.u
.cStr
[7] = (statItem
.st_mode
& S_IROTH
) ? 'r' : '-';
1015 psd
->str
.u
.cStr
[8] = (statItem
.st_mode
& S_IWOTH
) ? 'w' : '-';
1016 psd
->str
.u
.cStr
[9] = (statItem
.st_mode
& S_IXOTH
) ? 'x' : '-';
1017 psd
->str
.u
.cStr
[10] = '\0';
1020 pPasswd
= getpwuid(statItem
.st_uid
);
1021 if (pPasswd
) strcpy(psd
->str
.u
.cStr
, pPasswd
->pw_name
);
1024 pGroup
= getgrgid(statItem
.st_gid
);
1025 if (pGroup
) strcpy(psd
->str
.u
.cStr
, pGroup
->gr_name
);
1033 static HRESULT WINAPI
UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2
* iface
, UINT iColumn
,
1040 /* VTable for UnixFolder's IShellFolder2 interface.
1042 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl
= {
1043 UnixFolder_IShellFolder2_QueryInterface
,
1044 UnixFolder_IShellFolder2_AddRef
,
1045 UnixFolder_IShellFolder2_Release
,
1046 UnixFolder_IShellFolder2_ParseDisplayName
,
1047 UnixFolder_IShellFolder2_EnumObjects
,
1048 UnixFolder_IShellFolder2_BindToObject
,
1049 UnixFolder_IShellFolder2_BindToStorage
,
1050 UnixFolder_IShellFolder2_CompareIDs
,
1051 UnixFolder_IShellFolder2_CreateViewObject
,
1052 UnixFolder_IShellFolder2_GetAttributesOf
,
1053 UnixFolder_IShellFolder2_GetUIObjectOf
,
1054 UnixFolder_IShellFolder2_GetDisplayNameOf
,
1055 UnixFolder_IShellFolder2_SetNameOf
,
1056 UnixFolder_IShellFolder2_GetDefaultSearchGUID
,
1057 UnixFolder_IShellFolder2_EnumSearches
,
1058 UnixFolder_IShellFolder2_GetDefaultColumn
,
1059 UnixFolder_IShellFolder2_GetDefaultColumnState
,
1060 UnixFolder_IShellFolder2_GetDetailsEx
,
1061 UnixFolder_IShellFolder2_GetDetailsOf
,
1062 UnixFolder_IShellFolder2_MapColumnToSCID
1065 static HRESULT WINAPI
UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3
* This
, REFIID riid
,
1068 return UnixFolder_IShellFolder2_QueryInterface(
1069 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
), riid
, ppvObject
);
1072 static ULONG WINAPI
UnixFolder_IPersistFolder3_AddRef(IPersistFolder3
* This
)
1074 return UnixFolder_IShellFolder2_AddRef(
1075 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1078 static ULONG WINAPI
UnixFolder_IPersistFolder3_Release(IPersistFolder3
* This
)
1080 return UnixFolder_IShellFolder2_Release(
1081 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1084 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3
* iface
, CLSID
* pClassID
)
1086 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1088 TRACE("(iface=%p, pClassId=%p)\n", iface
, pClassID
);
1091 return E_INVALIDARG
;
1093 memcpy(pClassID
, This
->m_pCLSID
, sizeof(CLSID
));
1097 static HRESULT WINAPI
UnixFolder_IPersistFolder3_Initialize(IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1099 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1100 struct stat statPrefix
;
1101 LPCITEMIDLIST current
= pidl
, root
;
1103 char *pNextDir
, szBasePath
[FILENAME_MAX
] = "/";
1105 TRACE("(iface=%p, pidl=%p)\n", iface
, pidl
);
1107 /* Find the UnixFolderClass root */
1108 while (current
->mkid
.cb
) {
1109 if (_ILIsSpecialFolder(current
) &&
1110 (IsEqualIID(&CLSID_UnixFolder
, _ILGetGUIDPointer(current
)) ||
1111 IsEqualIID(&CLSID_UnixDosFolder
, _ILGetGUIDPointer(current
))))
1115 current
= ILGetNext(current
);
1118 if (current
&& current
->mkid
.cb
) {
1119 root
= current
= ILGetNext(current
);
1120 dwPathLen
= 2; /* For the '/' prefix and the terminating '\0' */
1121 } else if (_ILIsDesktop(pidl
) || _ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1122 /* Path rooted at Desktop */
1123 WCHAR wszDesktopPath
[MAX_PATH
];
1124 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath
, CSIDL_DESKTOP
, FALSE
)))
1126 PathAddBackslashW(wszDesktopPath
);
1127 if (!UNIXFS_get_unix_path(wszDesktopPath
, szBasePath
))
1129 dwPathLen
= strlen(szBasePath
) + 1;
1130 root
= current
= pidl
;
1132 ERR("Unknown pidl type!\n");
1134 return E_INVALIDARG
;
1137 /* Determine the path's length bytes */
1138 while (current
&& current
->mkid
.cb
) {
1139 dwPathLen
+= NAME_LEN_FROM_LPSHITEMID(current
) + 1; /* For the '/' */
1140 current
= ILGetNext(current
);
1143 /* Build the path */
1144 This
->m_dwAttributes
= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
;
1145 This
->m_pidlLocation
= ILClone(pidl
);
1146 This
->m_pszPath
= pNextDir
= SHAlloc(dwPathLen
);
1147 if (!This
->m_pszPath
|| !This
->m_pidlLocation
) {
1148 WARN("SHAlloc failed!\n");
1152 strcpy(pNextDir
, szBasePath
);
1153 pNextDir
+= strlen(szBasePath
);
1154 if (This
->m_dwPathMode
== PATHMODE_UNIX
)
1155 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1156 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1158 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1159 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1161 while (current
&& current
->mkid
.cb
) {
1162 memcpy(pNextDir
, _ILGetTextPointer(current
), NAME_LEN_FROM_LPSHITEMID(current
));
1163 pNextDir
+= NAME_LEN_FROM_LPSHITEMID(current
);
1164 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1166 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1167 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1170 current
= ILGetNext(current
);
1177 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3
* iface
, LPITEMIDLIST
* ppidl
)
1179 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1181 TRACE ("(iface=%p, ppidl=%p)\n", iface
, ppidl
);
1185 *ppidl
= ILClone (This
->m_pidlLocation
);
1189 static HRESULT WINAPI
UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3
*iface
, IBindCtx
*pbc
,
1190 LPCITEMIDLIST pidlRoot
, const PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1192 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1193 WCHAR wszTargetDosPath
[MAX_PATH
];
1194 char szTargetPath
[FILENAME_MAX
] = "";
1196 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface
, pbc
, pidlRoot
, ppfti
);
1198 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1200 return IPersistFolder3_Initialize(iface
, pidlRoot
);
1202 if (ppfti
->csidl
!= -1) {
1203 if (SUCCEEDED(SHGetFolderPathW(0, ppfti
->csidl
, NULL
, 0, wszTargetDosPath
))) {
1204 UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
);
1206 } else if (*ppfti
->szTargetParsingName
) {
1207 UNIXFS_get_unix_path(ppfti
->szTargetParsingName
, szTargetPath
);
1208 } else if (ppfti
->pidlTargetFolder
) {
1209 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTargetDosPath
)) {
1210 UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
);
1214 This
->m_pszPath
= SHAlloc(lstrlenA(szTargetPath
)+1);
1215 if (!This
->m_pszPath
)
1217 lstrcpyA(This
->m_pszPath
, szTargetPath
);
1218 This
->m_pidlLocation
= ILClone(pidlRoot
);
1219 This
->m_dwAttributes
= (ppfti
->dwAttributes
== -1) ? ppfti
->dwAttributes
:
1220 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|SFGAO_FILESYSTEM
;
1225 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3
*iface
,
1226 PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1228 FIXME("(iface=%p, ppfti=%p) stub\n", iface
, ppfti
);
1232 /* VTable for UnixFolder's IPersistFolder interface.
1234 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl
= {
1235 UnixFolder_IPersistFolder3_QueryInterface
,
1236 UnixFolder_IPersistFolder3_AddRef
,
1237 UnixFolder_IPersistFolder3_Release
,
1238 UnixFolder_IPersistFolder3_GetClassID
,
1239 UnixFolder_IPersistFolder3_Initialize
,
1240 UnixFolder_IPersistFolder3_GetCurFolder
,
1241 UnixFolder_IPersistFolder3_InitializeEx
,
1242 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1245 static HRESULT WINAPI
UnixFolder_ISFHelper_QueryInterface(ISFHelper
* iface
, REFIID riid
,
1248 return UnixFolder_IShellFolder2_QueryInterface(
1249 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
), riid
, ppvObject
);
1252 static ULONG WINAPI
UnixFolder_ISFHelper_AddRef(ISFHelper
* iface
)
1254 return UnixFolder_IShellFolder2_AddRef(
1255 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1258 static ULONG WINAPI
UnixFolder_ISFHelper_Release(ISFHelper
* iface
)
1260 return UnixFolder_IShellFolder2_Release(
1261 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1264 static HRESULT WINAPI
UnixFolder_ISFHelper_GetUniqueName(ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1266 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1269 LPITEMIDLIST pidlElem
;
1272 static const char szNewFolder
[] = "New Folder";
1274 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface
, lpName
, uLen
);
1276 if (uLen
< sizeof(szNewFolder
)+3)
1277 return E_INVALIDARG
;
1279 hr
= IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2
, This
), 0,
1280 SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
, &pEnum
);
1281 if (SUCCEEDED(hr
)) {
1282 lstrcpyA(lpName
, szNewFolder
);
1283 IEnumIDList_Reset(pEnum
);
1285 while ((IEnumIDList_Next(pEnum
, 1, &pidlElem
, &dwFetched
) == S_OK
) && (dwFetched
== 1)) {
1286 if (!strcasecmp(_ILGetTextPointer(pidlElem
), lpName
)) {
1287 IEnumIDList_Reset(pEnum
);
1288 sprintf(lpName
, "%s %d", szNewFolder
, i
++);
1295 IEnumIDList_Release(pEnum
);
1300 static HRESULT WINAPI
UnixFolder_ISFHelper_AddFolder(ISFHelper
* iface
, HWND hwnd
, LPCSTR pszName
,
1301 LPITEMIDLIST
* ppidlOut
)
1303 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1304 char szNewDir
[FILENAME_MAX
];
1306 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface
, hwnd
, pszName
, ppidlOut
);
1311 lstrcpyA(szNewDir
, This
->m_pszPath
);
1312 lstrcatA(szNewDir
, pszName
);
1314 if (mkdir(szNewDir
, 0755)) {
1315 char szMessage
[256 + FILENAME_MAX
];
1316 char szCaption
[256];
1318 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, szCaption
, sizeof(szCaption
));
1319 sprintf(szMessage
, szCaption
, szNewDir
);
1320 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, szCaption
, sizeof(szCaption
));
1321 MessageBoxA(hwnd
, szMessage
, szCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1325 LPITEMIDLIST pidlRelative
;
1326 WCHAR wszName
[MAX_PATH
];
1328 /* Inform the shell */
1329 MultiByteToWideChar(CP_UNIXCP
, 0, pszName
, -1, wszName
, MAX_PATH
);
1330 if (UNIXFS_path_to_pidl(This
, wszName
, &pidlRelative
)) {
1331 LPITEMIDLIST pidlAbsolute
= ILCombine(This
->m_pidlLocation
, pidlRelative
);
1333 *ppidlOut
= pidlRelative
;
1335 ILFree(pidlRelative
);
1336 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1337 ILFree(pidlAbsolute
);
1343 static HRESULT WINAPI
UnixFolder_ISFHelper_DeleteItems(ISFHelper
* iface
, UINT cidl
,
1344 LPCITEMIDLIST
* apidl
)
1346 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1347 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1348 LPITEMIDLIST pidlAbsolute
;
1352 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface
, cidl
, apidl
);
1354 lstrcpyA(szAbsolute
, This
->m_pszPath
);
1355 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
1357 for (i
=0; i
<cidl
&& SUCCEEDED(hr
); i
++) {
1358 lstrcpyA(pszRelative
, _ILGetTextPointer(apidl
[i
]));
1359 pidlAbsolute
= ILCombine(This
->m_pidlLocation
, apidl
[i
]);
1360 if (_ILIsFolder(apidl
[i
])) {
1361 if (rmdir(szAbsolute
)) {
1364 SHChangeNotify(SHCNE_RMDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1366 } else if (_ILIsValue(apidl
[i
])) {
1367 if (unlink(szAbsolute
)) {
1370 SHChangeNotify(SHCNE_DELETE
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1373 ILFree(pidlAbsolute
);
1379 static HRESULT WINAPI
UnixFolder_ISFHelper_CopyItems(ISFHelper
* iface
, IShellFolder
*psfFrom
,
1380 UINT cidl
, LPCITEMIDLIST
*apidl
)
1382 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1386 char szAbsoluteDst
[FILENAME_MAX
], *pszRelativeDst
;
1388 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface
, psfFrom
, cidl
, apidl
);
1390 if (!psfFrom
|| !cidl
|| !apidl
)
1391 return E_INVALIDARG
;
1393 /* All source items have to be filesystem items. */
1394 dwAttributes
= SFGAO_FILESYSTEM
;
1395 hr
= IShellFolder_GetAttributesOf(psfFrom
, cidl
, apidl
, &dwAttributes
);
1396 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
))
1397 return E_INVALIDARG
;
1399 lstrcpyA(szAbsoluteDst
, This
->m_pszPath
);
1400 pszRelativeDst
= szAbsoluteDst
+ strlen(szAbsoluteDst
);
1402 for (i
=0; i
<cidl
; i
++) {
1403 WCHAR wszSrc
[MAX_PATH
];
1404 char szSrc
[FILENAME_MAX
];
1407 /* Build the unix path of the current source item. */
1408 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom
, apidl
[i
], SHGDN_FORPARSING
, &strret
)))
1410 if (FAILED(StrRetToBufW(&strret
, apidl
[i
], wszSrc
, MAX_PATH
)))
1412 if (!UNIXFS_get_unix_path(wszSrc
, szSrc
))
1415 /* Build the unix path of the current destination item */
1416 lstrcpyA(pszRelativeDst
, _ILGetTextPointer(apidl
[i
]));
1418 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc
, szAbsoluteDst
);
1423 /* VTable for UnixFolder's ISFHelper interface
1425 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl
= {
1426 UnixFolder_ISFHelper_QueryInterface
,
1427 UnixFolder_ISFHelper_AddRef
,
1428 UnixFolder_ISFHelper_Release
,
1429 UnixFolder_ISFHelper_GetUniqueName
,
1430 UnixFolder_ISFHelper_AddFolder
,
1431 UnixFolder_ISFHelper_DeleteItems
,
1432 UnixFolder_ISFHelper_CopyItems
1435 /******************************************************************************
1436 * Unix[Dos]Folder_Constructor [Internal]
1439 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1440 * riid [I] Interface asked for by the client.
1441 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1444 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1445 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1446 * compatible signature.
1448 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1449 * means that paths are converted from dos to unix and back at the interfaces.
1451 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, DWORD dwPathMode
,
1452 const CLSID
*pCLSID
)
1454 HRESULT hr
= E_FAIL
;
1455 UnixFolder
*pUnixFolder
= SHAlloc((ULONG
)sizeof(UnixFolder
));
1458 pUnixFolder
->lpIShellFolder2Vtbl
= &UnixFolder_IShellFolder2_Vtbl
;
1459 pUnixFolder
->lpIPersistFolder3Vtbl
= &UnixFolder_IPersistFolder3_Vtbl
;
1460 pUnixFolder
->lpISFHelperVtbl
= &UnixFolder_ISFHelper_Vtbl
;
1461 pUnixFolder
->m_cRef
= 0;
1462 pUnixFolder
->m_pszPath
= NULL
;
1463 pUnixFolder
->m_dwPathMode
= dwPathMode
;
1464 pUnixFolder
->m_pCLSID
= pCLSID
;
1466 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1467 hr
= UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2
, pUnixFolder
), riid
, ppv
);
1468 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1473 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1474 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1475 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_UNIX
, &CLSID_UnixFolder
);
1478 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1479 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1480 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_DOS
, &CLSID_UnixDosFolder
);
1483 /******************************************************************************
1484 * UnixSubFolderIterator
1486 * Class whose heap based objects represent iterators over the sub-directories
1487 * of a given UnixFolder object.
1490 /* UnixSubFolderIterator object layout and typedef.
1492 typedef struct _UnixSubFolderIterator
{
1493 const IEnumIDListVtbl
*lpIEnumIDListVtbl
;
1497 char m_szFolder
[FILENAME_MAX
];
1498 } UnixSubFolderIterator
;
1500 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator
*iterator
) {
1501 TRACE("(iterator=%p)\n", iterator
);
1503 if (iterator
->m_dirFolder
)
1504 closedir(iterator
->m_dirFolder
);
1508 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList
* iface
,
1509 REFIID riid
, void** ppv
)
1511 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
1513 if (!ppv
) return E_INVALIDARG
;
1515 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumIDList
, riid
)) {
1519 return E_NOINTERFACE
;
1522 IEnumIDList_AddRef(iface
);
1526 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList
* iface
)
1528 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1530 TRACE("(iface=%p)\n", iface
);
1532 return InterlockedIncrement(&This
->m_cRef
);
1535 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList
* iface
)
1537 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1540 TRACE("(iface=%p)\n", iface
);
1542 cRef
= InterlockedDecrement(&This
->m_cRef
);
1545 UnixSubFolderIterator_Destroy(This
);
1550 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList
* iface
, ULONG celt
,
1551 LPITEMIDLIST
* rgelt
, ULONG
* pceltFetched
)
1553 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1556 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
1557 if (This
->m_dirFolder
) {
1558 char *pszRelativePath
= This
->m_szFolder
+ lstrlenA(This
->m_szFolder
);
1559 struct dirent
*pDirEntry
;
1562 pDirEntry
= readdir(This
->m_dirFolder
);
1563 if (!pDirEntry
) break; /* No more entries */
1564 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
1566 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
1567 * and see if it passes the filter.
1569 lstrcpyA(pszRelativePath
, pDirEntry
->d_name
);
1570 rgelt
[i
] = (LPITEMIDLIST
)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath
))+sizeof(USHORT
));
1571 if (!UNIXFS_build_shitemid(This
->m_szFolder
, rgelt
[i
]) ||
1572 !UNIXFS_is_pidl_of_type(rgelt
[i
], This
->m_fFilter
))
1577 memset(((PBYTE
)rgelt
[i
])+rgelt
[i
]->mkid
.cb
, 0, sizeof(USHORT
));
1580 *pszRelativePath
= '\0'; /* Restore the original path in This->m_szFolder. */
1586 return (i
== 0) ? S_FALSE
: S_OK
;
1589 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList
* iface
, ULONG celt
)
1591 LPITEMIDLIST
*apidl
;
1595 TRACE("(iface=%p, celt=%ld)\n", iface
, celt
);
1597 /* Call IEnumIDList::Next and delete the resulting pidls. */
1598 apidl
= (LPITEMIDLIST
*)SHAlloc(celt
* sizeof(LPITEMIDLIST
));
1599 hr
= IEnumIDList_Next(iface
, celt
, apidl
, &cFetched
);
1602 SHFree(apidl
[cFetched
]);
1608 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList
* iface
)
1610 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1612 TRACE("(iface=%p)\n", iface
);
1614 if (This
->m_dirFolder
)
1615 rewinddir(This
->m_dirFolder
);
1620 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList
* This
,
1621 IEnumIDList
** ppenum
)
1627 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1629 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl
= {
1630 UnixSubFolderIterator_IEnumIDList_QueryInterface
,
1631 UnixSubFolderIterator_IEnumIDList_AddRef
,
1632 UnixSubFolderIterator_IEnumIDList_Release
,
1633 UnixSubFolderIterator_IEnumIDList_Next
,
1634 UnixSubFolderIterator_IEnumIDList_Skip
,
1635 UnixSubFolderIterator_IEnumIDList_Reset
,
1636 UnixSubFolderIterator_IEnumIDList_Clone
1639 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
) {
1640 UnixSubFolderIterator
*iterator
;
1642 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
1644 iterator
= SHAlloc((ULONG
)sizeof(UnixSubFolderIterator
));
1645 iterator
->lpIEnumIDListVtbl
= &UnixSubFolderIterator_IEnumIDList_Vtbl
;
1646 iterator
->m_cRef
= 0;
1647 iterator
->m_fFilter
= fFilter
;
1648 iterator
->m_dirFolder
= opendir(pUnixFolder
->m_pszPath
);
1649 lstrcpyA(iterator
->m_szFolder
, pUnixFolder
->m_pszPath
);
1651 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList
*)iterator
);
1653 return (IUnknown
*)iterator
;