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 IPersistPropertyBagVtbl
*lpIPersistPropertyBagVtbl
;
87 const ISFHelperVtbl
*lpISFHelperVtbl
;
90 LPITEMIDLIST m_pidlLocation
;
93 const CLSID
*m_pCLSID
;
96 /******************************************************************************
97 * UNIXFS_is_rooted_at_desktop [Internal]
99 * Checks if the unixfs namespace extension is rooted at desktop level.
102 * TRUE, if unixfs is rooted at desktop level
105 BOOL
UNIXFS_is_rooted_at_desktop(void) {
107 WCHAR wszRootedAtDesktop
[69 + CHARS_IN_GUID
] = {
108 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
109 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
110 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
111 'N','a','m','e','S','p','a','c','e','\\',0 };
113 if (StringFromGUID2(&CLSID_UnixDosFolder
, wszRootedAtDesktop
+ 69, CHARS_IN_GUID
) &&
114 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszRootedAtDesktop
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
122 /******************************************************************************
123 * UNIXFS_is_pidl_of_type [INTERNAL]
125 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
128 * pIDL [I] The ITEMIDLIST to be checked.
129 * fFilter [I] Shell condition flags, which specify the filter.
132 * TRUE, if pIDL is accepted by fFilter
135 static inline BOOL
UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL
, SHCONTF fFilter
) {
136 LPPIDLDATA pIDLData
= _ILGetDataPointer(pIDL
);
137 if (!(fFilter
& SHCONTF_INCLUDEHIDDEN
) && pIDLData
&&
138 (pIDLData
->u
.file
.uFileAttribs
& FILE_ATTRIBUTE_HIDDEN
))
142 if (_ILIsFolder(pIDL
) && (fFilter
& SHCONTF_FOLDERS
)) return TRUE
;
143 if (_ILIsValue(pIDL
) && (fFilter
& SHCONTF_NONFOLDERS
)) return TRUE
;
147 /******************************************************************************
148 * UNIXFS_is_dos_device [Internal]
150 * Determines if a unix directory corresponds to any dos device.
153 * statPath [I] The stat struct of the directory, as returned by stat(2).
156 * TRUE, if statPath corresponds to any dos drive letter
159 static BOOL
UNIXFS_is_dos_device(const struct stat
*statPath
) {
160 struct stat statDrive
;
163 WCHAR wszDosDevice
[4] = { 'A', ':', '\\', 0 };
165 for (dwDriveMap
= GetLogicalDrives(); dwDriveMap
; dwDriveMap
>>= 1, wszDosDevice
[0]++) {
166 if (!(dwDriveMap
& 0x1)) continue;
167 pszDrivePath
= wine_get_unix_file_name(wszDosDevice
);
168 if (pszDrivePath
&& !stat(pszDrivePath
, &statDrive
)) {
169 HeapFree(GetProcessHeap(), 0, pszDrivePath
);
170 if ((statPath
->st_dev
== statDrive
.st_dev
) && (statPath
->st_ino
== statDrive
.st_ino
))
177 /******************************************************************************
178 * UNIXFS_get_unix_path [Internal]
180 * Convert an absolute dos path to an absolute canonicalized unix path.
181 * Evaluate "/.", "/.." and symbolic links.
184 * pszDosPath [I] An absolute dos path
185 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
189 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
191 static BOOL
UNIXFS_get_unix_path(LPCWSTR pszDosPath
, char *pszCanonicalPath
)
193 char *pPathTail
, *pElement
, *pCanonicalTail
, szPath
[FILENAME_MAX
], *pszUnixPath
;
194 struct stat fileStat
;
196 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath
), pszCanonicalPath
);
198 if (!pszDosPath
|| pszDosPath
[1] != ':')
201 pszUnixPath
= wine_get_unix_file_name(pszDosPath
);
202 if (!pszUnixPath
) return FALSE
;
203 strcpy(szPath
, pszUnixPath
);
204 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
206 /* pCanonicalTail always points to the end of the canonical path constructed
207 * thus far. pPathTail points to the still to be processed part of the input
208 * path. pElement points to the path element currently investigated.
210 *pszCanonicalPath
= '\0';
211 pCanonicalTail
= pszCanonicalPath
;
218 pElement
= pPathTail
;
219 pPathTail
= strchr(pPathTail
+1, '/');
220 if (!pPathTail
) /* Last path element may not be terminated by '/'. */
221 pPathTail
= pElement
+ strlen(pElement
);
222 /* Temporarily terminate the current path element. Will be restored later. */
226 /* Skip "/." path elements */
227 if (!strcmp("/.", pElement
)) {
232 /* Remove last element in canonical path for "/.." elements, then skip. */
233 if (!strcmp("/..", pElement
)) {
234 char *pTemp
= strrchr(pszCanonicalPath
, '/');
236 pCanonicalTail
= pTemp
;
237 *pCanonicalTail
= '\0';
242 /* lstat returns zero on success. */
243 if (lstat(szPath
, &fileStat
))
246 if (S_ISLNK(fileStat
.st_mode
)) {
247 char szSymlink
[FILENAME_MAX
];
248 int cLinkLen
, cTailLen
;
250 /* Avoid infinite loop for recursive links. */
254 cLinkLen
= readlink(szPath
, szSymlink
, FILENAME_MAX
);
259 cTailLen
= strlen(pPathTail
);
261 if (szSymlink
[0] == '/') {
262 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
263 if (cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
266 /* Avoid double slashes. */
267 if (szSymlink
[cLinkLen
-1] == '/' && pPathTail
[0] == '/') {
268 szSymlink
[cLinkLen
-1] = '\0';
272 memcpy(szSymlink
+ cLinkLen
, pPathTail
, cTailLen
+ 1);
273 memcpy(szPath
, szSymlink
, cLinkLen
+ cTailLen
+ 1);
274 *pszCanonicalPath
= '\0';
275 pCanonicalTail
= pszCanonicalPath
;
278 /* Relative link. Expand into szPath and continue. */
279 char szTemp
[FILENAME_MAX
];
280 int cTailLen
= strlen(pPathTail
);
282 if (pElement
- szPath
+ 1 + cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
285 memcpy(szTemp
, pPathTail
, cTailLen
+ 1);
286 memcpy(pElement
+ 1, szSymlink
, cLinkLen
);
287 memcpy(pElement
+ 1 + cLinkLen
, szTemp
, cTailLen
+ 1);
288 pPathTail
= pElement
;
291 /* Regular directory or file. Copy to canonical path */
292 if (pCanonicalTail
- pszCanonicalPath
+ pPathTail
- pElement
+ 1 > FILENAME_MAX
)
295 memcpy(pCanonicalTail
, pElement
, pPathTail
- pElement
+ 1);
296 pCanonicalTail
+= pPathTail
- pElement
;
299 } while (pPathTail
[0] == '/');
301 TRACE("--> %s\n", debugstr_a(pszCanonicalPath
));
306 /******************************************************************************
307 * UNIXFS_build_shitemid [Internal]
309 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
313 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
314 * pIDL [O] SHITEMID will be constructed here.
317 * Success: A pointer to the terminating '\0' character of path.
321 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
322 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
325 static char* UNIXFS_build_shitemid(char *pszUnixPath
, void *pIDL
) {
329 struct stat fileStat
;
333 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath
), pIDL
);
335 /* Compute the SHITEMID's length and wipe it. */
336 pszComponent
= strrchr(pszUnixPath
, '/') + 1;
337 cComponentLen
= strlen(pszComponent
);
338 memset(pIDL
, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
));
339 ((LPSHITEMID
)pIDL
)->cb
= SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
) ;
341 /* We are only interested in regular files and directories. */
342 if (stat(pszUnixPath
, &fileStat
)) return NULL
;
343 if (!S_ISDIR(fileStat
.st_mode
) && !S_ISREG(fileStat
.st_mode
)) return NULL
;
345 /* Set shell32's standard SHITEMID data fields. */
346 pIDLData
= _ILGetDataPointer((LPCITEMIDLIST
)pIDL
);
347 pIDLData
->type
= S_ISDIR(fileStat
.st_mode
) ? PT_FOLDER
: PT_VALUE
;
348 pIDLData
->u
.file
.dwFileSize
= (DWORD
)fileStat
.st_size
;
349 RtlSecondsSince1970ToTime( fileStat
.st_mtime
, &time
);
350 fileTime
.dwLowDateTime
= time
.u
.LowPart
;
351 fileTime
.dwHighDateTime
= time
.u
.HighPart
;
352 FileTimeToDosDateTime(&fileTime
, &pIDLData
->u
.file
.uFileDate
, &pIDLData
->u
.file
.uFileTime
);
353 pIDLData
->u
.file
.uFileAttribs
= 0;
354 if (S_ISDIR(fileStat
.st_mode
)) pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_DIRECTORY
;
355 if (pszComponent
[0] == '.') pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_HIDDEN
;
356 memcpy(pIDLData
->u
.file
.szNames
, pszComponent
, cComponentLen
);
358 return pszComponent
+ cComponentLen
;
361 /******************************************************************************
362 * UNIXFS_path_to_pidl [Internal]
365 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
366 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
367 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
371 * Failure: FALSE, invalid params or out of memory
374 * pUnixFolder also carries the information if the path is expected to be unix or dos.
376 static BOOL
UNIXFS_path_to_pidl(UnixFolder
*pUnixFolder
, const WCHAR
*path
, LPITEMIDLIST
*ppidl
) {
378 int cSubDirs
, cPidlLen
, cPathLen
;
379 char *pSlash
, szCompletePath
[FILENAME_MAX
], *pNextPathElement
;
381 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder
, debugstr_w(path
), ppidl
);
386 /* Build an absolute path and let pNextPathElement point to the interesting
387 * relative sub-path. We need the absolute path to call 'stat', but the pidl
388 * will only contain the relative part.
390 if ((pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) && (path
[1] == ':'))
392 /* Absolute dos path. Convert to unix */
393 if (!UNIXFS_get_unix_path(path
, szCompletePath
))
395 pNextPathElement
= szCompletePath
;
397 else if ((pUnixFolder
->m_dwPathMode
== PATHMODE_UNIX
) && (path
[0] == '/'))
399 /* Absolute unix path. Just convert to ANSI. */
400 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
, FILENAME_MAX
, NULL
, NULL
);
401 pNextPathElement
= szCompletePath
;
405 /* Relative dos or unix path. Concat with this folder's path */
406 int cBasePathLen
= strlen(pUnixFolder
->m_pszPath
);
407 memcpy(szCompletePath
, pUnixFolder
->m_pszPath
, cBasePathLen
);
408 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
+ cBasePathLen
,
409 FILENAME_MAX
- cBasePathLen
, NULL
, NULL
);
410 pNextPathElement
= szCompletePath
+ cBasePathLen
- 1;
412 /* If in dos mode, replace '\' with '/' */
413 if (pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) {
414 char *pBackslash
= strchr(pNextPathElement
, '\\');
417 pBackslash
= strchr(pBackslash
, '\\');
422 /* Special case for the root folder. */
423 if (!strcmp(szCompletePath
, "/")) {
424 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(sizeof(USHORT
));
425 if (!pidl
) return FALSE
;
426 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
430 /* Remove trailing slash, if present */
431 cPathLen
= strlen(szCompletePath
);
432 if (szCompletePath
[cPathLen
-1] == '/')
433 szCompletePath
[cPathLen
-1] = '\0';
435 if ((szCompletePath
[0] != '/') || (pNextPathElement
[0] != '/')) {
436 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath
, pNextPathElement
);
440 /* At this point, we have an absolute unix path in szCompletePath
441 * and the relative portion of it in pNextPathElement. Both starting with '/'
442 * and _not_ terminated by a '/'. */
443 TRACE("complete path: %s, relative path: %s\n", szCompletePath
, pNextPathElement
);
445 /* Count the number of sub-directories in the path */
447 pSlash
= pNextPathElement
;
450 pSlash
= strchr(pSlash
+1, '/');
453 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
454 * characters, which are not stored in the ITEMIDLIST. */
455 cPidlLen
= strlen(pNextPathElement
) - cSubDirs
+ cSubDirs
* SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT
);
456 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(cPidlLen
);
457 if (!pidl
) return FALSE
;
459 /* Concatenate the SHITEMIDs of the sub-directories. */
460 while (*pNextPathElement
) {
461 pSlash
= strchr(pNextPathElement
+1, '/');
462 if (pSlash
) *pSlash
= '\0';
463 pNextPathElement
= UNIXFS_build_shitemid(szCompletePath
, pidl
);
464 if (pSlash
) *pSlash
= '/';
466 if (!pNextPathElement
) {
470 pidl
= ILGetNext(pidl
);
472 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
474 if ((char *)pidl
-(char *)*ppidl
+sizeof(USHORT
) != cPidlLen
) /* We've corrupted the heap :( */
475 ERR("Computed length of pidl incorrect. Please report.\n");
480 /******************************************************************************
483 * Class whose heap based instances represent unix filesystem directories.
486 static void UnixFolder_Destroy(UnixFolder
*pUnixFolder
) {
487 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
489 SHFree(pUnixFolder
->m_pszPath
);
490 ILFree(pUnixFolder
->m_pidlLocation
);
494 static HRESULT WINAPI
UnixFolder_IShellFolder2_QueryInterface(IShellFolder2
*iface
, REFIID riid
,
497 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
499 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
501 if (!ppv
) return E_INVALIDARG
;
503 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellFolder
, riid
) ||
504 IsEqualIID(&IID_IShellFolder2
, riid
))
506 *ppv
= &This
->lpIShellFolder2Vtbl
;
507 } else if (IsEqualIID(&IID_IPersistFolder3
, riid
) || IsEqualIID(&IID_IPersistFolder2
, riid
) ||
508 IsEqualIID(&IID_IPersistFolder
, riid
) || IsEqualIID(&IID_IPersist
, riid
))
510 *ppv
= &This
->lpIPersistFolder3Vtbl
;
511 } else if (IsEqualIID(&IID_IPersistPropertyBag
, riid
)) {
512 *ppv
= &This
->lpIPersistPropertyBagVtbl
;
513 } else if (IsEqualIID(&IID_ISFHelper
, riid
)) {
514 *ppv
= &This
->lpISFHelperVtbl
;
517 return E_NOINTERFACE
;
520 IUnknown_AddRef((IUnknown
*)*ppv
);
524 static ULONG WINAPI
UnixFolder_IShellFolder2_AddRef(IShellFolder2
*iface
) {
525 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
527 TRACE("(iface=%p)\n", iface
);
529 return InterlockedIncrement(&This
->m_cRef
);
532 static ULONG WINAPI
UnixFolder_IShellFolder2_Release(IShellFolder2
*iface
) {
533 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
536 TRACE("(iface=%p)\n", iface
);
538 cRef
= InterlockedDecrement(&This
->m_cRef
);
541 UnixFolder_Destroy(This
);
546 static HRESULT WINAPI
UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2
* iface
, HWND hwndOwner
,
547 LPBC pbcReserved
, LPOLESTR lpszDisplayName
, ULONG
* pchEaten
, LPITEMIDLIST
* ppidl
,
548 ULONG
* pdwAttributes
)
550 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
553 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
554 "pdwAttributes=%p) stub\n", iface
, hwndOwner
, pbcReserved
, debugstr_w(lpszDisplayName
),
555 pchEaten
, ppidl
, pdwAttributes
);
557 result
= UNIXFS_path_to_pidl(This
, lpszDisplayName
, ppidl
);
558 if (result
&& pdwAttributes
&& *pdwAttributes
)
560 IShellFolder
*pParentSF
;
561 LPCITEMIDLIST pidlLast
;
564 hr
= SHBindToParent(*ppidl
, &IID_IShellFolder
, (LPVOID
*)&pParentSF
, &pidlLast
);
565 if (FAILED(hr
)) return E_FAIL
;
566 IShellFolder_GetAttributesOf(pParentSF
, 1, &pidlLast
, pdwAttributes
);
567 IShellFolder_Release(pParentSF
);
570 if (!result
) TRACE("FAILED!\n");
571 return result
? S_OK
: E_FAIL
;
574 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
);
576 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumObjects(IShellFolder2
* iface
, HWND hwndOwner
,
577 SHCONTF grfFlags
, IEnumIDList
** ppEnumIDList
)
579 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
580 IUnknown
*newIterator
;
583 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
584 iface
, hwndOwner
, grfFlags
, ppEnumIDList
);
586 newIterator
= UnixSubFolderIterator_Constructor(This
, grfFlags
);
587 hr
= IUnknown_QueryInterface(newIterator
, &IID_IEnumIDList
, (void**)ppEnumIDList
);
588 IUnknown_Release(newIterator
);
593 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, const CLSID
*pCLSID
);
595 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToObject(IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
596 LPBC pbcReserved
, REFIID riid
, void** ppvOut
)
598 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
599 IPersistFolder3
*persistFolder
;
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 hr
= CreateUnixFolder(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
, This
->m_pCLSID
);
609 if (!SUCCEEDED(hr
)) return hr
;
610 hr
= IPersistFolder_QueryInterface(persistFolder
, riid
, (void**)ppvOut
);
613 LPITEMIDLIST pidlSubFolder
= ILCombine(This
->m_pidlLocation
, pidl
);
614 hr
= IPersistFolder3_Initialize(persistFolder
, pidlSubFolder
);
615 ILFree(pidlSubFolder
);
618 IPersistFolder3_Release(persistFolder
);
623 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToStorage(IShellFolder2
* This
, LPCITEMIDLIST pidl
,
624 LPBC pbcReserved
, REFIID riid
, void** ppvObj
)
630 static HRESULT WINAPI
UnixFolder_IShellFolder2_CompareIDs(IShellFolder2
* iface
, LPARAM lParam
,
631 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
633 BOOL isEmpty1
, isEmpty2
;
635 LPITEMIDLIST firstpidl
;
639 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface
, lParam
, pidl1
, pidl2
);
641 isEmpty1
= !pidl1
|| !pidl1
->mkid
.cb
;
642 isEmpty2
= !pidl2
|| !pidl2
->mkid
.cb
;
644 if (isEmpty1
&& isEmpty2
)
645 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
647 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
649 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
651 if (_ILIsFolder(pidl1
) && !_ILIsFolder(pidl2
))
652 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
653 if (!_ILIsFolder(pidl1
) && _ILIsFolder(pidl2
))
654 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
656 compare
= CompareStringA(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
,
657 _ILGetTextPointer(pidl1
), NAME_LEN_FROM_LPSHITEMID(pidl1
),
658 _ILGetTextPointer(pidl2
), NAME_LEN_FROM_LPSHITEMID(pidl2
));
660 if ((compare
== CSTR_LESS_THAN
) || (compare
== CSTR_GREATER_THAN
))
661 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)((compare
== CSTR_LESS_THAN
)?-1:1));
663 if (pidl1
->mkid
.cb
< pidl2
->mkid
.cb
)
664 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
665 else if (pidl1
->mkid
.cb
> pidl2
->mkid
.cb
)
666 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
668 firstpidl
= ILCloneFirst(pidl1
);
669 pidl1
= ILGetNext(pidl1
);
670 pidl2
= ILGetNext(pidl2
);
672 hr
= IShellFolder2_BindToObject(iface
, firstpidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
);
674 hr
= IShellFolder_CompareIDs(psf
, lParam
, pidl1
, pidl2
);
675 IShellFolder2_Release(psf
);
682 static HRESULT WINAPI
UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2
* iface
, HWND hwndOwner
,
683 REFIID riid
, void** ppv
)
685 HRESULT hr
= E_INVALIDARG
;
687 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface
, hwndOwner
, riid
, ppv
);
689 if (!ppv
) return E_INVALIDARG
;
692 if (IsEqualIID(&IID_IShellView
, riid
)) {
693 LPSHELLVIEW pShellView
;
695 pShellView
= IShellView_Constructor((IShellFolder
*)iface
);
697 hr
= IShellView_QueryInterface(pShellView
, riid
, ppv
);
698 IShellView_Release(pShellView
);
705 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2
* iface
, UINT cidl
,
706 LPCITEMIDLIST
* apidl
, SFGAOF
* rgfInOut
)
708 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
711 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface
, cidl
, apidl
, rgfInOut
);
713 if (!rgfInOut
|| (cidl
&& !apidl
))
717 *rgfInOut
&= This
->m_dwAttributes
;
719 char szAbsolutePath
[FILENAME_MAX
], *pszRelativePath
;
722 *rgfInOut
&= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|
724 lstrcpyA(szAbsolutePath
, This
->m_pszPath
);
725 pszRelativePath
= szAbsolutePath
+ lstrlenA(szAbsolutePath
);
726 for (i
=0; i
<cidl
; i
++) {
727 if ((*rgfInOut
& SFGAO_FILESYSTEM
) && !(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
728 struct stat fileStat
;
729 char *pszName
= _ILGetTextPointer(apidl
[i
]);
730 if (!pszName
) return E_INVALIDARG
;
731 lstrcpyA(pszRelativePath
, pszName
);
732 if (stat(szAbsolutePath
, &fileStat
) || !UNIXFS_is_dos_device(&fileStat
))
733 *rgfInOut
&= ~SFGAO_FILESYSTEM
;
735 if (!_ILIsFolder(apidl
[i
]))
736 *rgfInOut
&= ~(SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
);
743 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2
* iface
, HWND hwndOwner
,
744 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
, UINT
* prgfInOut
, void** ppvOut
)
746 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
748 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
749 iface
, hwndOwner
, cidl
, apidl
, debugstr_guid(riid
), prgfInOut
, ppvOut
);
751 if (IsEqualIID(&IID_IContextMenu
, riid
)) {
752 *ppvOut
= ISvItemCm_Constructor((IShellFolder
*)iface
, This
->m_pidlLocation
, apidl
, cidl
);
754 } else if (IsEqualIID(&IID_IDataObject
, riid
)) {
755 *ppvOut
= IDataObject_Constructor(hwndOwner
, This
->m_pidlLocation
, apidl
, cidl
);
757 } else if (IsEqualIID(&IID_IExtractIconA
, riid
)) {
759 if (cidl
!= 1) return E_FAIL
;
760 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
761 *ppvOut
= (LPVOID
)IExtractIconA_Constructor(pidl
);
764 } else if (IsEqualIID(&IID_IExtractIconW
, riid
)) {
766 if (cidl
!= 1) return E_FAIL
;
767 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
768 *ppvOut
= (LPVOID
)IExtractIconW_Constructor(pidl
);
771 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
772 FIXME("IDropTarget\n");
774 } else if (IsEqualIID(&IID_IShellLinkW
, riid
)) {
775 FIXME("IShellLinkW\n");
777 } else if (IsEqualIID(&IID_IShellLinkA
, riid
)) {
778 FIXME("IShellLinkA\n");
781 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid
));
782 return E_NOINTERFACE
;
786 /******************************************************************************
787 * Translate file name from unix to ANSI encoding.
789 static void strcpyn_U2A(char *win_fn
, UINT win_fn_len
, const char *unix_fn
)
794 len
= MultiByteToWideChar(CP_UNIXCP
, 0, unix_fn
, -1, NULL
, 0);
795 unicode_fn
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
796 MultiByteToWideChar(CP_UNIXCP
, 0, unix_fn
, -1, unicode_fn
, len
);
798 WideCharToMultiByte(CP_ACP
, 0, unicode_fn
, len
, win_fn
, win_fn_len
, NULL
, NULL
);
799 HeapFree(GetProcessHeap(), 0, unicode_fn
);
802 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2
* iface
,
803 LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
* lpName
)
805 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
808 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface
, pidl
, uFlags
, lpName
);
810 if ((GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) &&
811 (GET_SHGDN_RELATION(uFlags
) != SHGDN_INFOLDER
))
813 if (!pidl
|| !pidl
->mkid
.cb
) {
814 lpName
->uType
= STRRET_CSTR
;
815 if (This
->m_dwPathMode
== PATHMODE_UNIX
) {
816 strcpyn_U2A(lpName
->u
.cStr
, MAX_PATH
, This
->m_pszPath
);
818 WCHAR
*pwszDosPath
= wine_get_dos_file_name(This
->m_pszPath
);
820 return HRESULT_FROM_WIN32(GetLastError());
821 PathRemoveBackslashW(pwszDosPath
);
822 WideCharToMultiByte(CP_UNIXCP
, 0, pwszDosPath
, -1, lpName
->u
.cStr
, MAX_PATH
, NULL
, NULL
);
823 HeapFree(GetProcessHeap(), 0, pwszDosPath
);
826 IShellFolder
*pSubFolder
;
827 SHITEMID emptyIDL
= { 0, { 0 } };
829 hr
= IShellFolder_BindToObject(iface
, pidl
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
830 if (!SUCCEEDED(hr
)) return hr
;
832 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, lpName
);
833 IShellFolder_Release(pSubFolder
);
836 char *pszFileName
= _ILGetTextPointer(pidl
);
837 lpName
->uType
= STRRET_CSTR
;
838 strcpyn_U2A(lpName
->u
.cStr
, MAX_PATH
, pszFileName
? pszFileName
: "");
841 /* If in dos mode, do some post-processing on the path.
842 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
844 if (SUCCEEDED(hr
) && This
->m_dwPathMode
== PATHMODE_DOS
&& !_ILIsFolder(pidl
))
845 SHELL_FS_ProcessDisplayFilename(lpName
->u
.cStr
, uFlags
);
847 TRACE("--> %s\n", lpName
->u
.cStr
);
852 static HRESULT WINAPI
UnixFolder_IShellFolder2_SetNameOf(IShellFolder2
* iface
, HWND hwnd
,
853 LPCITEMIDLIST pidl
, LPCOLESTR lpszName
, SHGDNF uFlags
, LPITEMIDLIST
* ppidlOut
)
855 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
857 char szSrc
[FILENAME_MAX
], szDest
[FILENAME_MAX
];
859 int cBasePathLen
= lstrlenA(This
->m_pszPath
);
860 struct stat statDest
;
861 LPITEMIDLIST pidlSrc
, pidlDest
;
863 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
864 iface
, hwnd
, pidl
, debugstr_w(lpszName
), uFlags
, ppidlOut
);
866 /* pidl has to contain a single non-empty SHITEMID */
867 if (_ILIsDesktop(pidl
) || !_ILIsPidlSimple(pidl
) || !_ILGetTextPointer(pidl
))
873 /* build source path */
874 memcpy(szSrc
, This
->m_pszPath
, cBasePathLen
);
875 lstrcpyA(szSrc
+cBasePathLen
, _ILGetTextPointer(pidl
));
877 /* build destination path */
878 if (uFlags
& SHGDN_FORPARSING
) { /* absolute path in lpszName */
879 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
, FILENAME_MAX
, NULL
, NULL
);
881 WCHAR wszSrcRelative
[MAX_PATH
];
882 memcpy(szDest
, This
->m_pszPath
, cBasePathLen
);
883 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
+cBasePathLen
,
884 FILENAME_MAX
-cBasePathLen
, NULL
, NULL
);
886 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
887 * extension is hidden to the user, we have to append it. */
888 if (_ILSimpleGetTextW(pidl
, wszSrcRelative
, MAX_PATH
) &&
889 SHELL_FS_HideExtension(wszSrcRelative
))
891 char *pszExt
= PathFindExtensionA(_ILGetTextPointer(pidl
));
892 lstrcatA(szDest
, pszExt
);
896 TRACE("src=%s dest=%s\n", szSrc
, szDest
);
898 /* Fail, if destination does already exist */
899 if (!stat(szDest
, &statDest
))
902 /* Rename the file */
903 if (rename(szSrc
, szDest
))
906 /* Build a pidl for the path of the renamed file */
907 pwszDosDest
= wine_get_dos_file_name(szDest
);
908 if (!pwszDosDest
|| !UNIXFS_path_to_pidl(This
, pwszDosDest
, &pidlDest
)) {
909 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
910 rename(szDest
, szSrc
); /* Undo the renaming */
914 /* Inform the shell */
915 pidlSrc
= ILCombine(This
->m_pidlLocation
, pidl
);
916 if (_ILIsFolder(ILFindLastID(pidlDest
)))
917 SHChangeNotify(SHCNE_RENAMEFOLDER
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
919 SHChangeNotify(SHCNE_RENAMEITEM
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
924 _ILCreateFromPathW(pwszDosDest
, ppidlOut
);
926 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
930 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumSearches(IShellFolder2
* iface
,
931 IEnumExtraSearch
**ppEnum
)
937 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2
* iface
,
938 DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
944 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2
* iface
,
945 UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
951 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2
* iface
,
958 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2
* iface
,
959 LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
965 #define SHELLVIEWCOLUMNS 7
967 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2
* iface
,
968 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
*psd
)
970 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
972 struct passwd
*pPasswd
;
973 struct group
*pGroup
;
974 static const shvheader SFHeader
[SHELLVIEWCOLUMNS
] = {
975 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
976 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
977 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
978 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
979 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 9},
980 {IDS_SHV_COLUMN10
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
981 {IDS_SHV_COLUMN11
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7}
984 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface
, pidl
, iColumn
, psd
);
986 if (!psd
|| iColumn
>= SHELLVIEWCOLUMNS
)
990 psd
->fmt
= SFHeader
[iColumn
].fmt
;
991 psd
->cxChar
= SFHeader
[iColumn
].cxChar
;
992 psd
->str
.uType
= STRRET_CSTR
;
993 LoadStringA(shell32_hInstance
, SFHeader
[iColumn
].colnameid
, psd
->str
.u
.cStr
, MAX_PATH
);
996 struct stat statItem
;
997 if (iColumn
== 4 || iColumn
== 5 || iColumn
== 6) {
998 char szPath
[FILENAME_MAX
], *pszFile
= _ILGetTextPointer(pidl
);
1000 return E_INVALIDARG
;
1001 lstrcpyA(szPath
, This
->m_pszPath
);
1002 lstrcatA(szPath
, pszFile
);
1003 if (stat(szPath
, &statItem
))
1004 return E_INVALIDARG
;
1006 psd
->str
.u
.cStr
[0] = '\0';
1007 psd
->str
.uType
= STRRET_CSTR
;
1010 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
|SHGDN_INFOLDER
, &psd
->str
);
1013 _ILGetFileSize(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1016 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1019 _ILGetFileDate(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1022 psd
->str
.u
.cStr
[0] = S_ISDIR(statItem
.st_mode
) ? 'd' : '-';
1023 psd
->str
.u
.cStr
[1] = (statItem
.st_mode
& S_IRUSR
) ? 'r' : '-';
1024 psd
->str
.u
.cStr
[2] = (statItem
.st_mode
& S_IWUSR
) ? 'w' : '-';
1025 psd
->str
.u
.cStr
[3] = (statItem
.st_mode
& S_IXUSR
) ? 'x' : '-';
1026 psd
->str
.u
.cStr
[4] = (statItem
.st_mode
& S_IRGRP
) ? 'r' : '-';
1027 psd
->str
.u
.cStr
[5] = (statItem
.st_mode
& S_IWGRP
) ? 'w' : '-';
1028 psd
->str
.u
.cStr
[6] = (statItem
.st_mode
& S_IXGRP
) ? 'x' : '-';
1029 psd
->str
.u
.cStr
[7] = (statItem
.st_mode
& S_IROTH
) ? 'r' : '-';
1030 psd
->str
.u
.cStr
[8] = (statItem
.st_mode
& S_IWOTH
) ? 'w' : '-';
1031 psd
->str
.u
.cStr
[9] = (statItem
.st_mode
& S_IXOTH
) ? 'x' : '-';
1032 psd
->str
.u
.cStr
[10] = '\0';
1035 pPasswd
= getpwuid(statItem
.st_uid
);
1036 if (pPasswd
) strcpy(psd
->str
.u
.cStr
, pPasswd
->pw_name
);
1039 pGroup
= getgrgid(statItem
.st_gid
);
1040 if (pGroup
) strcpy(psd
->str
.u
.cStr
, pGroup
->gr_name
);
1048 static HRESULT WINAPI
UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2
* iface
, UINT iColumn
,
1055 /* VTable for UnixFolder's IShellFolder2 interface.
1057 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl
= {
1058 UnixFolder_IShellFolder2_QueryInterface
,
1059 UnixFolder_IShellFolder2_AddRef
,
1060 UnixFolder_IShellFolder2_Release
,
1061 UnixFolder_IShellFolder2_ParseDisplayName
,
1062 UnixFolder_IShellFolder2_EnumObjects
,
1063 UnixFolder_IShellFolder2_BindToObject
,
1064 UnixFolder_IShellFolder2_BindToStorage
,
1065 UnixFolder_IShellFolder2_CompareIDs
,
1066 UnixFolder_IShellFolder2_CreateViewObject
,
1067 UnixFolder_IShellFolder2_GetAttributesOf
,
1068 UnixFolder_IShellFolder2_GetUIObjectOf
,
1069 UnixFolder_IShellFolder2_GetDisplayNameOf
,
1070 UnixFolder_IShellFolder2_SetNameOf
,
1071 UnixFolder_IShellFolder2_GetDefaultSearchGUID
,
1072 UnixFolder_IShellFolder2_EnumSearches
,
1073 UnixFolder_IShellFolder2_GetDefaultColumn
,
1074 UnixFolder_IShellFolder2_GetDefaultColumnState
,
1075 UnixFolder_IShellFolder2_GetDetailsEx
,
1076 UnixFolder_IShellFolder2_GetDetailsOf
,
1077 UnixFolder_IShellFolder2_MapColumnToSCID
1080 static HRESULT WINAPI
UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3
* This
, REFIID riid
,
1083 return UnixFolder_IShellFolder2_QueryInterface(
1084 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
), riid
, ppvObject
);
1087 static ULONG WINAPI
UnixFolder_IPersistFolder3_AddRef(IPersistFolder3
* This
)
1089 return UnixFolder_IShellFolder2_AddRef(
1090 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1093 static ULONG WINAPI
UnixFolder_IPersistFolder3_Release(IPersistFolder3
* This
)
1095 return UnixFolder_IShellFolder2_Release(
1096 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1099 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3
* iface
, CLSID
* pClassID
)
1101 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1103 TRACE("(iface=%p, pClassId=%p)\n", iface
, pClassID
);
1106 return E_INVALIDARG
;
1108 memcpy(pClassID
, This
->m_pCLSID
, sizeof(CLSID
));
1112 static HRESULT WINAPI
UnixFolder_IPersistFolder3_Initialize(IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1114 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1115 struct stat statPrefix
;
1116 LPCITEMIDLIST current
= pidl
, root
;
1118 char *pNextDir
, szBasePath
[FILENAME_MAX
] = "/";
1120 TRACE("(iface=%p, pidl=%p)\n", iface
, pidl
);
1122 /* Find the UnixFolderClass root */
1123 while (current
->mkid
.cb
) {
1124 if (_ILIsSpecialFolder(current
) && IsEqualIID(This
->m_pCLSID
, _ILGetGUIDPointer(current
)))
1126 current
= ILGetNext(current
);
1129 if (current
&& current
->mkid
.cb
) {
1130 if (IsEqualIID(&CLSID_MyDocuments
, _ILGetGUIDPointer(current
))) {
1131 WCHAR wszMyDocumentsPath
[MAX_PATH
];
1132 if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath
, CSIDL_PERSONAL
, FALSE
))
1134 PathAddBackslashW(wszMyDocumentsPath
);
1135 if (!UNIXFS_get_unix_path(wszMyDocumentsPath
, szBasePath
))
1137 dwPathLen
= strlen(szBasePath
) + 1;
1139 dwPathLen
= 2; /* For the '/' prefix and the terminating '\0' */
1141 root
= current
= ILGetNext(current
);
1142 } else if (_ILIsDesktop(pidl
) || _ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1143 /* Path rooted at Desktop */
1144 WCHAR wszDesktopPath
[MAX_PATH
];
1145 if (!SHGetSpecialFolderPathW(0, wszDesktopPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
))
1147 PathAddBackslashW(wszDesktopPath
);
1148 if (!UNIXFS_get_unix_path(wszDesktopPath
, szBasePath
))
1150 dwPathLen
= strlen(szBasePath
) + 1;
1151 root
= current
= pidl
;
1153 ERR("Unknown pidl type!\n");
1155 return E_INVALIDARG
;
1158 /* Determine the path's length bytes */
1159 while (current
&& current
->mkid
.cb
) {
1160 dwPathLen
+= NAME_LEN_FROM_LPSHITEMID(current
) + 1; /* For the '/' */
1161 current
= ILGetNext(current
);
1164 /* Build the path */
1165 This
->m_dwAttributes
= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
;
1166 This
->m_pidlLocation
= ILClone(pidl
);
1167 This
->m_pszPath
= pNextDir
= SHAlloc(dwPathLen
);
1168 if (!This
->m_pszPath
|| !This
->m_pidlLocation
) {
1169 WARN("SHAlloc failed!\n");
1173 strcpy(pNextDir
, szBasePath
);
1174 pNextDir
+= strlen(szBasePath
);
1175 if (This
->m_dwPathMode
== PATHMODE_UNIX
|| IsEqualCLSID(&CLSID_MyDocuments
, This
->m_pCLSID
))
1176 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1177 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1179 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1180 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1182 while (current
&& current
->mkid
.cb
) {
1183 memcpy(pNextDir
, _ILGetTextPointer(current
), NAME_LEN_FROM_LPSHITEMID(current
));
1184 pNextDir
+= NAME_LEN_FROM_LPSHITEMID(current
);
1185 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1187 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1188 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1191 current
= ILGetNext(current
);
1198 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3
* iface
, LPITEMIDLIST
* ppidl
)
1200 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1202 TRACE ("(iface=%p, ppidl=%p)\n", iface
, ppidl
);
1206 *ppidl
= ILClone (This
->m_pidlLocation
);
1210 static HRESULT WINAPI
UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3
*iface
, IBindCtx
*pbc
,
1211 LPCITEMIDLIST pidlRoot
, const PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1213 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1214 WCHAR wszTargetDosPath
[MAX_PATH
];
1215 char szTargetPath
[FILENAME_MAX
] = "";
1217 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface
, pbc
, pidlRoot
, ppfti
);
1219 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1221 return IPersistFolder3_Initialize(iface
, pidlRoot
);
1223 if (ppfti
->csidl
!= -1) {
1224 if (FAILED(SHGetFolderPathW(0, ppfti
->csidl
, NULL
, 0, wszTargetDosPath
)) ||
1225 !UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
))
1229 } else if (*ppfti
->szTargetParsingName
) {
1230 if (!UNIXFS_get_unix_path(ppfti
->szTargetParsingName
, szTargetPath
)) {
1233 } else if (ppfti
->pidlTargetFolder
) {
1234 if (!SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTargetDosPath
) ||
1235 !UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
))
1243 This
->m_pszPath
= SHAlloc(lstrlenA(szTargetPath
)+1);
1244 if (!This
->m_pszPath
)
1246 lstrcpyA(This
->m_pszPath
, szTargetPath
);
1247 This
->m_pidlLocation
= ILClone(pidlRoot
);
1248 This
->m_dwAttributes
= (ppfti
->dwAttributes
!= -1) ? ppfti
->dwAttributes
:
1249 (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|SFGAO_FILESYSTEM
);
1254 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3
*iface
,
1255 PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1257 FIXME("(iface=%p, ppfti=%p) stub\n", iface
, ppfti
);
1261 /* VTable for UnixFolder's IPersistFolder interface.
1263 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl
= {
1264 UnixFolder_IPersistFolder3_QueryInterface
,
1265 UnixFolder_IPersistFolder3_AddRef
,
1266 UnixFolder_IPersistFolder3_Release
,
1267 UnixFolder_IPersistFolder3_GetClassID
,
1268 UnixFolder_IPersistFolder3_Initialize
,
1269 UnixFolder_IPersistFolder3_GetCurFolder
,
1270 UnixFolder_IPersistFolder3_InitializeEx
,
1271 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1274 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag
* This
,
1275 REFIID riid
, void** ppvObject
)
1277 return UnixFolder_IShellFolder2_QueryInterface(
1278 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
), riid
, ppvObject
);
1281 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag
* This
)
1283 return UnixFolder_IShellFolder2_AddRef(
1284 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
));
1287 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag
* This
)
1289 return UnixFolder_IShellFolder2_Release(
1290 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
));
1293 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag
* iface
,
1296 return UnixFolder_IPersistFolder3_GetClassID(
1297 (IPersistFolder3
*)&ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)->lpIPersistFolder3Vtbl
,
1301 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag
* iface
)
1307 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag
*iface
,
1308 IPropertyBag
*pPropertyBag
, IErrorLog
*pErrorLog
)
1314 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag
*iface
,
1315 IPropertyBag
*pPropertyBag
, BOOL fClearDirty
, BOOL fSaveAllProperties
)
1321 /* VTable for UnixFolder's IPersistPropertyBag interface.
1323 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl
= {
1324 UnixFolder_IPersistPropertyBag_QueryInterface
,
1325 UnixFolder_IPersistPropertyBag_AddRef
,
1326 UnixFolder_IPersistPropertyBag_Release
,
1327 UnixFolder_IPersistPropertyBag_GetClassID
,
1328 UnixFolder_IPersistPropertyBag_InitNew
,
1329 UnixFolder_IPersistPropertyBag_Load
,
1330 UnixFolder_IPersistPropertyBag_Save
1333 static HRESULT WINAPI
UnixFolder_ISFHelper_QueryInterface(ISFHelper
* iface
, REFIID riid
,
1336 return UnixFolder_IShellFolder2_QueryInterface(
1337 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
), riid
, ppvObject
);
1340 static ULONG WINAPI
UnixFolder_ISFHelper_AddRef(ISFHelper
* iface
)
1342 return UnixFolder_IShellFolder2_AddRef(
1343 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1346 static ULONG WINAPI
UnixFolder_ISFHelper_Release(ISFHelper
* iface
)
1348 return UnixFolder_IShellFolder2_Release(
1349 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1352 static HRESULT WINAPI
UnixFolder_ISFHelper_GetUniqueName(ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1354 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1357 LPITEMIDLIST pidlElem
;
1360 static const char szNewFolder
[] = "New Folder";
1362 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface
, lpName
, uLen
);
1364 if (uLen
< sizeof(szNewFolder
)+3)
1365 return E_INVALIDARG
;
1367 hr
= IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2
, This
), 0,
1368 SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
, &pEnum
);
1369 if (SUCCEEDED(hr
)) {
1370 lstrcpyA(lpName
, szNewFolder
);
1371 IEnumIDList_Reset(pEnum
);
1373 while ((IEnumIDList_Next(pEnum
, 1, &pidlElem
, &dwFetched
) == S_OK
) && (dwFetched
== 1)) {
1374 if (!strcasecmp(_ILGetTextPointer(pidlElem
), lpName
)) {
1375 IEnumIDList_Reset(pEnum
);
1376 sprintf(lpName
, "%s %d", szNewFolder
, i
++);
1383 IEnumIDList_Release(pEnum
);
1388 static HRESULT WINAPI
UnixFolder_ISFHelper_AddFolder(ISFHelper
* iface
, HWND hwnd
, LPCSTR pszName
,
1389 LPITEMIDLIST
* ppidlOut
)
1391 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1392 char szNewDir
[FILENAME_MAX
];
1394 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface
, hwnd
, pszName
, ppidlOut
);
1399 lstrcpyA(szNewDir
, This
->m_pszPath
);
1400 lstrcatA(szNewDir
, pszName
);
1402 if (mkdir(szNewDir
, 0755)) {
1403 char szMessage
[256 + FILENAME_MAX
];
1404 char szCaption
[256];
1406 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, szCaption
, sizeof(szCaption
));
1407 sprintf(szMessage
, szCaption
, szNewDir
);
1408 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, szCaption
, sizeof(szCaption
));
1409 MessageBoxA(hwnd
, szMessage
, szCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1413 LPITEMIDLIST pidlRelative
;
1414 WCHAR wszName
[MAX_PATH
];
1416 /* Inform the shell */
1417 MultiByteToWideChar(CP_UNIXCP
, 0, pszName
, -1, wszName
, MAX_PATH
);
1418 if (UNIXFS_path_to_pidl(This
, wszName
, &pidlRelative
)) {
1419 LPITEMIDLIST pidlAbsolute
= ILCombine(This
->m_pidlLocation
, pidlRelative
);
1421 *ppidlOut
= pidlRelative
;
1423 ILFree(pidlRelative
);
1424 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1425 ILFree(pidlAbsolute
);
1431 static HRESULT WINAPI
UnixFolder_ISFHelper_DeleteItems(ISFHelper
* iface
, UINT cidl
,
1432 LPCITEMIDLIST
* apidl
)
1434 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1435 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1436 LPITEMIDLIST pidlAbsolute
;
1440 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface
, cidl
, apidl
);
1442 lstrcpyA(szAbsolute
, This
->m_pszPath
);
1443 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
1445 for (i
=0; i
<cidl
&& SUCCEEDED(hr
); i
++) {
1446 lstrcpyA(pszRelative
, _ILGetTextPointer(apidl
[i
]));
1447 pidlAbsolute
= ILCombine(This
->m_pidlLocation
, apidl
[i
]);
1448 if (_ILIsFolder(apidl
[i
])) {
1449 if (rmdir(szAbsolute
)) {
1452 SHChangeNotify(SHCNE_RMDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1454 } else if (_ILIsValue(apidl
[i
])) {
1455 if (unlink(szAbsolute
)) {
1458 SHChangeNotify(SHCNE_DELETE
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1461 ILFree(pidlAbsolute
);
1467 static HRESULT WINAPI
UnixFolder_ISFHelper_CopyItems(ISFHelper
* iface
, IShellFolder
*psfFrom
,
1468 UINT cidl
, LPCITEMIDLIST
*apidl
)
1470 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1474 char szAbsoluteDst
[FILENAME_MAX
], *pszRelativeDst
;
1476 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface
, psfFrom
, cidl
, apidl
);
1478 if (!psfFrom
|| !cidl
|| !apidl
)
1479 return E_INVALIDARG
;
1481 /* All source items have to be filesystem items. */
1482 dwAttributes
= SFGAO_FILESYSTEM
;
1483 hr
= IShellFolder_GetAttributesOf(psfFrom
, cidl
, apidl
, &dwAttributes
);
1484 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
))
1485 return E_INVALIDARG
;
1487 lstrcpyA(szAbsoluteDst
, This
->m_pszPath
);
1488 pszRelativeDst
= szAbsoluteDst
+ strlen(szAbsoluteDst
);
1490 for (i
=0; i
<cidl
; i
++) {
1491 WCHAR wszSrc
[MAX_PATH
];
1492 char szSrc
[FILENAME_MAX
];
1495 /* Build the unix path of the current source item. */
1496 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom
, apidl
[i
], SHGDN_FORPARSING
, &strret
)))
1498 if (FAILED(StrRetToBufW(&strret
, apidl
[i
], wszSrc
, MAX_PATH
)))
1500 if (!UNIXFS_get_unix_path(wszSrc
, szSrc
))
1503 /* Build the unix path of the current destination item */
1504 lstrcpyA(pszRelativeDst
, _ILGetTextPointer(apidl
[i
]));
1506 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc
, szAbsoluteDst
);
1511 /* VTable for UnixFolder's ISFHelper interface
1513 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl
= {
1514 UnixFolder_ISFHelper_QueryInterface
,
1515 UnixFolder_ISFHelper_AddRef
,
1516 UnixFolder_ISFHelper_Release
,
1517 UnixFolder_ISFHelper_GetUniqueName
,
1518 UnixFolder_ISFHelper_AddFolder
,
1519 UnixFolder_ISFHelper_DeleteItems
,
1520 UnixFolder_ISFHelper_CopyItems
1523 /******************************************************************************
1524 * Unix[Dos]Folder_Constructor [Internal]
1527 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1528 * riid [I] Interface asked for by the client.
1529 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1532 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1533 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1534 * compatible signature.
1536 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1537 * means that paths are converted from dos to unix and back at the interfaces.
1539 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, const CLSID
*pCLSID
)
1541 HRESULT hr
= E_FAIL
;
1542 UnixFolder
*pUnixFolder
= SHAlloc((ULONG
)sizeof(UnixFolder
));
1545 FIXME("Aggregation not yet implemented!\n");
1546 return CLASS_E_NOAGGREGATION
;
1550 pUnixFolder
->lpIShellFolder2Vtbl
= &UnixFolder_IShellFolder2_Vtbl
;
1551 pUnixFolder
->lpIPersistFolder3Vtbl
= &UnixFolder_IPersistFolder3_Vtbl
;
1552 pUnixFolder
->lpIPersistPropertyBagVtbl
= &UnixFolder_IPersistPropertyBag_Vtbl
;
1553 pUnixFolder
->lpISFHelperVtbl
= &UnixFolder_ISFHelper_Vtbl
;
1554 pUnixFolder
->m_cRef
= 0;
1555 pUnixFolder
->m_pszPath
= NULL
;
1556 pUnixFolder
->m_pidlLocation
= NULL
;
1557 pUnixFolder
->m_dwPathMode
= IsEqualCLSID(&CLSID_UnixFolder
, pCLSID
) ? PATHMODE_UNIX
: PATHMODE_DOS
;
1558 pUnixFolder
->m_dwAttributes
= 0;
1559 pUnixFolder
->m_pCLSID
= pCLSID
;
1561 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1562 hr
= UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2
, pUnixFolder
), riid
, ppv
);
1563 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1568 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1569 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1570 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_UnixFolder
);
1573 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1574 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1575 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_UnixDosFolder
);
1578 HRESULT WINAPI
FolderShortcut_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1579 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1580 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_FolderShortcut
);
1583 HRESULT WINAPI
MyDocuments_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1584 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1585 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_MyDocuments
);
1588 /******************************************************************************
1589 * UnixSubFolderIterator
1591 * Class whose heap based objects represent iterators over the sub-directories
1592 * of a given UnixFolder object.
1595 /* UnixSubFolderIterator object layout and typedef.
1597 typedef struct _UnixSubFolderIterator
{
1598 const IEnumIDListVtbl
*lpIEnumIDListVtbl
;
1602 char m_szFolder
[FILENAME_MAX
];
1603 } UnixSubFolderIterator
;
1605 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator
*iterator
) {
1606 TRACE("(iterator=%p)\n", iterator
);
1608 if (iterator
->m_dirFolder
)
1609 closedir(iterator
->m_dirFolder
);
1613 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList
* iface
,
1614 REFIID riid
, void** ppv
)
1616 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
1618 if (!ppv
) return E_INVALIDARG
;
1620 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumIDList
, riid
)) {
1624 return E_NOINTERFACE
;
1627 IEnumIDList_AddRef(iface
);
1631 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList
* iface
)
1633 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1635 TRACE("(iface=%p)\n", iface
);
1637 return InterlockedIncrement(&This
->m_cRef
);
1640 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList
* iface
)
1642 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1645 TRACE("(iface=%p)\n", iface
);
1647 cRef
= InterlockedDecrement(&This
->m_cRef
);
1650 UnixSubFolderIterator_Destroy(This
);
1655 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList
* iface
, ULONG celt
,
1656 LPITEMIDLIST
* rgelt
, ULONG
* pceltFetched
)
1658 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1661 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
1662 if (This
->m_dirFolder
) {
1663 char *pszRelativePath
= This
->m_szFolder
+ lstrlenA(This
->m_szFolder
);
1664 struct dirent
*pDirEntry
;
1667 pDirEntry
= readdir(This
->m_dirFolder
);
1668 if (!pDirEntry
) break; /* No more entries */
1669 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
1671 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
1672 * and see if it passes the filter.
1674 lstrcpyA(pszRelativePath
, pDirEntry
->d_name
);
1675 rgelt
[i
] = (LPITEMIDLIST
)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath
))+sizeof(USHORT
));
1676 if (!UNIXFS_build_shitemid(This
->m_szFolder
, rgelt
[i
]) ||
1677 !UNIXFS_is_pidl_of_type(rgelt
[i
], This
->m_fFilter
))
1682 memset(((PBYTE
)rgelt
[i
])+rgelt
[i
]->mkid
.cb
, 0, sizeof(USHORT
));
1685 *pszRelativePath
= '\0'; /* Restore the original path in This->m_szFolder. */
1691 return (i
== 0) ? S_FALSE
: S_OK
;
1694 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList
* iface
, ULONG celt
)
1696 LPITEMIDLIST
*apidl
;
1700 TRACE("(iface=%p, celt=%ld)\n", iface
, celt
);
1702 /* Call IEnumIDList::Next and delete the resulting pidls. */
1703 apidl
= (LPITEMIDLIST
*)SHAlloc(celt
* sizeof(LPITEMIDLIST
));
1704 hr
= IEnumIDList_Next(iface
, celt
, apidl
, &cFetched
);
1707 SHFree(apidl
[cFetched
]);
1713 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList
* iface
)
1715 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1717 TRACE("(iface=%p)\n", iface
);
1719 if (This
->m_dirFolder
)
1720 rewinddir(This
->m_dirFolder
);
1725 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList
* This
,
1726 IEnumIDList
** ppenum
)
1732 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1734 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl
= {
1735 UnixSubFolderIterator_IEnumIDList_QueryInterface
,
1736 UnixSubFolderIterator_IEnumIDList_AddRef
,
1737 UnixSubFolderIterator_IEnumIDList_Release
,
1738 UnixSubFolderIterator_IEnumIDList_Next
,
1739 UnixSubFolderIterator_IEnumIDList_Skip
,
1740 UnixSubFolderIterator_IEnumIDList_Reset
,
1741 UnixSubFolderIterator_IEnumIDList_Clone
1744 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
) {
1745 UnixSubFolderIterator
*iterator
;
1747 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
1749 iterator
= SHAlloc((ULONG
)sizeof(UnixSubFolderIterator
));
1750 iterator
->lpIEnumIDListVtbl
= &UnixSubFolderIterator_IEnumIDList_Vtbl
;
1751 iterator
->m_cRef
= 0;
1752 iterator
->m_fFilter
= fFilter
;
1753 iterator
->m_dirFolder
= opendir(pUnixFolder
->m_pszPath
);
1754 lstrcpyA(iterator
->m_szFolder
, pUnixFolder
->m_pszPath
);
1756 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList
*)iterator
);
1758 return (IUnknown
*)iterator
;