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
*pwszCLSID_UnixDosFolder
, 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 (FAILED(StringFromCLSID(&CLSID_UnixDosFolder
, &pwszCLSID_UnixDosFolder
)))
116 lstrcatW(wszRootedAtDesktop
, pwszCLSID_UnixDosFolder
);
117 CoTaskMemFree(pwszCLSID_UnixDosFolder
);
119 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszRootedAtDesktop
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
126 /******************************************************************************
127 * UNIXFS_is_pidl_of_type [INTERNAL]
129 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
132 * pIDL [I] The ITEMIDLIST to be checked.
133 * fFilter [I] Shell condition flags, which specify the filter.
136 * TRUE, if pIDL is accepted by fFilter
139 static inline BOOL
UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL
, SHCONTF fFilter
) {
140 LPPIDLDATA pIDLData
= _ILGetDataPointer(pIDL
);
141 if (!(fFilter
& SHCONTF_INCLUDEHIDDEN
) && pIDLData
&&
142 (pIDLData
->u
.file
.uFileAttribs
& FILE_ATTRIBUTE_HIDDEN
))
146 if (_ILIsFolder(pIDL
) && (fFilter
& SHCONTF_FOLDERS
)) return TRUE
;
147 if (_ILIsValue(pIDL
) && (fFilter
& SHCONTF_NONFOLDERS
)) return TRUE
;
151 /******************************************************************************
152 * UNIXFS_is_dos_device [Internal]
154 * Determines if a unix directory corresponds to any dos device.
157 * statPath [I] The stat struct of the directory, as returned by stat(2).
160 * TRUE, if statPath corresponds to any dos drive letter
163 static BOOL
UNIXFS_is_dos_device(const struct stat
*statPath
) {
164 struct stat statDrive
;
167 WCHAR wszDosDevice
[4] = { 'A', ':', '\\', 0 };
169 for (dwDriveMap
= GetLogicalDrives(); dwDriveMap
; dwDriveMap
>>= 1, wszDosDevice
[0]++) {
170 if (!(dwDriveMap
& 0x1)) continue;
171 pszDrivePath
= wine_get_unix_file_name(wszDosDevice
);
172 if (pszDrivePath
&& !stat(pszDrivePath
, &statDrive
)) {
173 HeapFree(GetProcessHeap(), 0, pszDrivePath
);
174 if ((statPath
->st_dev
== statDrive
.st_dev
) && (statPath
->st_ino
== statDrive
.st_ino
))
181 /******************************************************************************
182 * UNIXFS_get_unix_path [Internal]
184 * Convert an absolute dos path to an absolute canonicalized unix path.
185 * Evaluate "/.", "/.." and symbolic links.
188 * pszDosPath [I] An absolute dos path
189 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
193 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
195 static BOOL
UNIXFS_get_unix_path(LPCWSTR pszDosPath
, char *pszCanonicalPath
)
197 char *pPathTail
, *pElement
, *pCanonicalTail
, szPath
[FILENAME_MAX
], *pszUnixPath
;
198 struct stat fileStat
;
200 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath
), pszCanonicalPath
);
202 if (!pszDosPath
|| pszDosPath
[1] != ':')
205 pszUnixPath
= wine_get_unix_file_name(pszDosPath
);
206 if (!pszUnixPath
) return FALSE
;
207 strcpy(szPath
, pszUnixPath
);
208 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
210 /* pCanonicalTail always points to the end of the canonical path constructed
211 * thus far. pPathTail points to the still to be processed part of the input
212 * path. pElement points to the path element currently investigated.
214 *pszCanonicalPath
= '\0';
215 pCanonicalTail
= pszCanonicalPath
;
222 pElement
= pPathTail
;
223 pPathTail
= strchr(pPathTail
+1, '/');
224 if (!pPathTail
) /* Last path element may not be terminated by '/'. */
225 pPathTail
= pElement
+ strlen(pElement
);
226 /* Temporarily terminate the current path element. Will be restored later. */
230 /* Skip "/." path elements */
231 if (!strcmp("/.", pElement
)) {
236 /* Remove last element in canonical path for "/.." elements, then skip. */
237 if (!strcmp("/..", pElement
)) {
238 char *pTemp
= strrchr(pszCanonicalPath
, '/');
240 pCanonicalTail
= pTemp
;
241 *pCanonicalTail
= '\0';
246 /* lstat returns zero on success. */
247 if (lstat(szPath
, &fileStat
))
250 if (S_ISLNK(fileStat
.st_mode
)) {
251 char szSymlink
[FILENAME_MAX
];
252 int cLinkLen
, cTailLen
;
254 /* Avoid infinite loop for recursive links. */
258 cLinkLen
= readlink(szPath
, szSymlink
, FILENAME_MAX
);
263 cTailLen
= strlen(pPathTail
);
265 if (szSymlink
[0] == '/') {
266 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
267 if (cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
270 /* Avoid double slashes. */
271 if (szSymlink
[cLinkLen
-1] == '/' && pPathTail
[0] == '/') {
272 szSymlink
[cLinkLen
-1] = '\0';
276 memcpy(szSymlink
+ cLinkLen
, pPathTail
, cTailLen
+ 1);
277 memcpy(szPath
, szSymlink
, cLinkLen
+ cTailLen
+ 1);
278 *pszCanonicalPath
= '\0';
279 pCanonicalTail
= pszCanonicalPath
;
282 /* Relative link. Expand into szPath and continue. */
283 char szTemp
[FILENAME_MAX
];
284 int cTailLen
= strlen(pPathTail
);
286 if (pElement
- szPath
+ 1 + cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
289 memcpy(szTemp
, pPathTail
, cTailLen
+ 1);
290 memcpy(pElement
+ 1, szSymlink
, cLinkLen
);
291 memcpy(pElement
+ 1 + cLinkLen
, szTemp
, cTailLen
+ 1);
292 pPathTail
= pElement
;
295 /* Regular directory or file. Copy to canonical path */
296 if (pCanonicalTail
- pszCanonicalPath
+ pPathTail
- pElement
+ 1 > FILENAME_MAX
)
299 memcpy(pCanonicalTail
, pElement
, pPathTail
- pElement
+ 1);
300 pCanonicalTail
+= pPathTail
- pElement
;
303 } while (pPathTail
[0] == '/');
305 TRACE("--> %s\n", debugstr_a(pszCanonicalPath
));
310 /******************************************************************************
311 * UNIXFS_build_shitemid [Internal]
313 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
317 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
318 * pIDL [O] SHITEMID will be constructed here.
321 * Success: A pointer to the terminating '\0' character of path.
325 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
326 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
329 static char* UNIXFS_build_shitemid(char *pszUnixPath
, void *pIDL
) {
333 struct stat fileStat
;
337 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath
), pIDL
);
339 /* Compute the SHITEMID's length and wipe it. */
340 pszComponent
= strrchr(pszUnixPath
, '/') + 1;
341 cComponentLen
= strlen(pszComponent
);
342 memset(pIDL
, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
));
343 ((LPSHITEMID
)pIDL
)->cb
= SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
) ;
345 /* We are only interested in regular files and directories. */
346 if (stat(pszUnixPath
, &fileStat
)) return NULL
;
347 if (!S_ISDIR(fileStat
.st_mode
) && !S_ISREG(fileStat
.st_mode
)) return NULL
;
349 /* Set shell32's standard SHITEMID data fields. */
350 pIDLData
= _ILGetDataPointer((LPCITEMIDLIST
)pIDL
);
351 pIDLData
->type
= S_ISDIR(fileStat
.st_mode
) ? PT_FOLDER
: PT_VALUE
;
352 pIDLData
->u
.file
.dwFileSize
= (DWORD
)fileStat
.st_size
;
353 RtlSecondsSince1970ToTime( fileStat
.st_mtime
, &time
);
354 fileTime
.dwLowDateTime
= time
.u
.LowPart
;
355 fileTime
.dwHighDateTime
= time
.u
.HighPart
;
356 FileTimeToDosDateTime(&fileTime
, &pIDLData
->u
.file
.uFileDate
, &pIDLData
->u
.file
.uFileTime
);
357 pIDLData
->u
.file
.uFileAttribs
= 0;
358 if (S_ISDIR(fileStat
.st_mode
)) pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_DIRECTORY
;
359 if (pszComponent
[0] == '.') pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_HIDDEN
;
360 memcpy(pIDLData
->u
.file
.szNames
, pszComponent
, cComponentLen
);
362 return pszComponent
+ cComponentLen
;
365 /******************************************************************************
366 * UNIXFS_path_to_pidl [Internal]
369 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
370 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
371 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
375 * Failure: FALSE, invalid params or out of memory
378 * pUnixFolder also carries the information if the path is expected to be unix or dos.
380 static BOOL
UNIXFS_path_to_pidl(UnixFolder
*pUnixFolder
, const WCHAR
*path
, LPITEMIDLIST
*ppidl
) {
382 int cSubDirs
, cPidlLen
, cPathLen
;
383 char *pSlash
, szCompletePath
[FILENAME_MAX
], *pNextPathElement
;
385 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder
, debugstr_w(path
), ppidl
);
390 /* Build an absolute path and let pNextPathElement point to the interesting
391 * relative sub-path. We need the absolute path to call 'stat', but the pidl
392 * will only contain the relative part.
394 if ((pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) && (path
[1] == ':'))
396 /* Absolute dos path. Convert to unix */
397 if (!UNIXFS_get_unix_path(path
, szCompletePath
))
399 pNextPathElement
= szCompletePath
;
401 else if ((pUnixFolder
->m_dwPathMode
== PATHMODE_UNIX
) && (path
[0] == '/'))
403 /* Absolute unix path. Just convert to ANSI. */
404 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
, FILENAME_MAX
, NULL
, NULL
);
405 pNextPathElement
= szCompletePath
;
409 /* Relative dos or unix path. Concat with this folder's path */
410 int cBasePathLen
= strlen(pUnixFolder
->m_pszPath
);
411 memcpy(szCompletePath
, pUnixFolder
->m_pszPath
, cBasePathLen
);
412 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
+ cBasePathLen
,
413 FILENAME_MAX
- cBasePathLen
, NULL
, NULL
);
414 pNextPathElement
= szCompletePath
+ cBasePathLen
- 1;
416 /* If in dos mode, replace '\' with '/' */
417 if (pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) {
418 char *pBackslash
= strchr(pNextPathElement
, '\\');
421 pBackslash
= strchr(pBackslash
, '\\');
426 /* Special case for the root folder. */
427 if (!strcmp(szCompletePath
, "/")) {
428 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(sizeof(USHORT
));
429 if (!pidl
) return FALSE
;
430 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
434 /* Remove trailing slash, if present */
435 cPathLen
= strlen(szCompletePath
);
436 if (szCompletePath
[cPathLen
-1] == '/')
437 szCompletePath
[cPathLen
-1] = '\0';
439 if ((szCompletePath
[0] != '/') || (pNextPathElement
[0] != '/')) {
440 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath
, pNextPathElement
);
444 /* At this point, we have an absolute unix path in szCompletePath
445 * and the relative portion of it in pNextPathElement. Both starting with '/'
446 * and _not_ terminated by a '/'. */
447 TRACE("complete path: %s, relative path: %s\n", szCompletePath
, pNextPathElement
);
449 /* Count the number of sub-directories in the path */
451 pSlash
= pNextPathElement
;
454 pSlash
= strchr(pSlash
+1, '/');
457 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
458 * characters, which are not stored in the ITEMIDLIST. */
459 cPidlLen
= strlen(pNextPathElement
) - cSubDirs
+ cSubDirs
* SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT
);
460 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(cPidlLen
);
461 if (!pidl
) return FALSE
;
463 /* Concatenate the SHITEMIDs of the sub-directories. */
464 while (*pNextPathElement
) {
465 pSlash
= strchr(pNextPathElement
+1, '/');
466 if (pSlash
) *pSlash
= '\0';
467 pNextPathElement
= UNIXFS_build_shitemid(szCompletePath
, pidl
);
468 if (pSlash
) *pSlash
= '/';
470 if (!pNextPathElement
) {
474 pidl
= ILGetNext(pidl
);
476 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
478 if ((int)pidl
-(int)*ppidl
+sizeof(USHORT
) != cPidlLen
) /* We've corrupted the heap :( */
479 ERR("Computed length of pidl incorrect. Please report.\n");
484 /******************************************************************************
487 * Class whose heap based instances represent unix filesystem directories.
490 static void UnixFolder_Destroy(UnixFolder
*pUnixFolder
) {
491 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
493 SHFree(pUnixFolder
->m_pszPath
);
494 ILFree(pUnixFolder
->m_pidlLocation
);
498 static HRESULT WINAPI
UnixFolder_IShellFolder2_QueryInterface(IShellFolder2
*iface
, REFIID riid
,
501 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
503 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
505 if (!ppv
) return E_INVALIDARG
;
507 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellFolder
, riid
) ||
508 IsEqualIID(&IID_IShellFolder2
, riid
))
510 *ppv
= &This
->lpIShellFolder2Vtbl
;
511 } else if (IsEqualIID(&IID_IPersistFolder3
, riid
) || IsEqualIID(&IID_IPersistFolder2
, riid
) ||
512 IsEqualIID(&IID_IPersistFolder
, riid
) || IsEqualIID(&IID_IPersist
, riid
))
514 *ppv
= &This
->lpIPersistFolder3Vtbl
;
515 } else if (IsEqualIID(&IID_IPersistPropertyBag
, riid
)) {
516 *ppv
= &This
->lpIPersistPropertyBagVtbl
;
517 } else if (IsEqualIID(&IID_ISFHelper
, riid
)) {
518 *ppv
= &This
->lpISFHelperVtbl
;
521 return E_NOINTERFACE
;
524 IUnknown_AddRef((IUnknown
*)*ppv
);
528 static ULONG WINAPI
UnixFolder_IShellFolder2_AddRef(IShellFolder2
*iface
) {
529 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
531 TRACE("(iface=%p)\n", iface
);
533 return InterlockedIncrement(&This
->m_cRef
);
536 static ULONG WINAPI
UnixFolder_IShellFolder2_Release(IShellFolder2
*iface
) {
537 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
540 TRACE("(iface=%p)\n", iface
);
542 cRef
= InterlockedDecrement(&This
->m_cRef
);
545 UnixFolder_Destroy(This
);
550 static HRESULT WINAPI
UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2
* iface
, HWND hwndOwner
,
551 LPBC pbcReserved
, LPOLESTR lpszDisplayName
, ULONG
* pchEaten
, LPITEMIDLIST
* ppidl
,
552 ULONG
* pdwAttributes
)
554 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
557 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
558 "pdwAttributes=%p) stub\n", iface
, hwndOwner
, pbcReserved
, debugstr_w(lpszDisplayName
),
559 pchEaten
, ppidl
, pdwAttributes
);
561 result
= UNIXFS_path_to_pidl(This
, lpszDisplayName
, ppidl
);
562 if (result
&& pdwAttributes
&& *pdwAttributes
)
564 IShellFolder
*pParentSF
;
565 LPCITEMIDLIST pidlLast
;
568 hr
= SHBindToParent(*ppidl
, &IID_IShellFolder
, (LPVOID
*)&pParentSF
, &pidlLast
);
569 if (FAILED(hr
)) return E_FAIL
;
570 IShellFolder_GetAttributesOf(pParentSF
, 1, &pidlLast
, pdwAttributes
);
571 IShellFolder_Release(pParentSF
);
574 if (!result
) TRACE("FAILED!\n");
575 return result
? S_OK
: E_FAIL
;
578 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
);
580 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumObjects(IShellFolder2
* iface
, HWND hwndOwner
,
581 SHCONTF grfFlags
, IEnumIDList
** ppEnumIDList
)
583 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
584 IUnknown
*newIterator
;
587 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
588 iface
, hwndOwner
, grfFlags
, ppEnumIDList
);
590 newIterator
= UnixSubFolderIterator_Constructor(This
, grfFlags
);
591 hr
= IUnknown_QueryInterface(newIterator
, &IID_IEnumIDList
, (void**)ppEnumIDList
);
592 IUnknown_Release(newIterator
);
597 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToObject(IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
598 LPBC pbcReserved
, REFIID riid
, void** ppvOut
)
600 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
601 IPersistFolder3
*persistFolder
;
602 LPITEMIDLIST pidlSubFolder
;
605 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
606 iface
, pidl
, pbcReserved
, riid
, ppvOut
);
608 if (!pidl
|| !pidl
->mkid
.cb
)
611 if (This
->m_dwPathMode
== PATHMODE_DOS
)
612 hr
= UnixDosFolder_Constructor(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
);
614 hr
= UnixFolder_Constructor(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
);
616 if (!SUCCEEDED(hr
)) return hr
;
617 hr
= IPersistFolder_QueryInterface(persistFolder
, riid
, (void**)ppvOut
);
619 pidlSubFolder
= ILCombine(This
->m_pidlLocation
, pidl
);
620 IPersistFolder3_Initialize(persistFolder
, pidlSubFolder
);
621 IPersistFolder3_Release(persistFolder
);
622 ILFree(pidlSubFolder
);
627 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToStorage(IShellFolder2
* This
, LPCITEMIDLIST pidl
,
628 LPBC pbcReserved
, REFIID riid
, void** ppvObj
)
634 static HRESULT WINAPI
UnixFolder_IShellFolder2_CompareIDs(IShellFolder2
* iface
, LPARAM lParam
,
635 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
637 BOOL isEmpty1
, isEmpty2
;
639 LPITEMIDLIST firstpidl
;
643 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface
, lParam
, pidl1
, pidl2
);
645 isEmpty1
= !pidl1
|| !pidl1
->mkid
.cb
;
646 isEmpty2
= !pidl2
|| !pidl2
->mkid
.cb
;
648 if (isEmpty1
&& isEmpty2
)
649 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
651 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
653 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
655 if (_ILIsFolder(pidl1
) && !_ILIsFolder(pidl2
))
656 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
657 if (!_ILIsFolder(pidl1
) && _ILIsFolder(pidl2
))
658 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
660 compare
= CompareStringA(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
,
661 _ILGetTextPointer(pidl1
), NAME_LEN_FROM_LPSHITEMID(pidl1
),
662 _ILGetTextPointer(pidl2
), NAME_LEN_FROM_LPSHITEMID(pidl2
));
664 if ((compare
== CSTR_LESS_THAN
) || (compare
== CSTR_GREATER_THAN
))
665 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)((compare
== CSTR_LESS_THAN
)?-1:1));
667 if (pidl1
->mkid
.cb
< pidl2
->mkid
.cb
)
668 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
669 else if (pidl1
->mkid
.cb
> pidl2
->mkid
.cb
)
670 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
672 firstpidl
= ILCloneFirst(pidl1
);
673 pidl1
= ILGetNext(pidl1
);
674 pidl2
= ILGetNext(pidl2
);
676 hr
= IShellFolder2_BindToObject(iface
, firstpidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
);
678 hr
= IShellFolder_CompareIDs(psf
, lParam
, pidl1
, pidl2
);
679 IShellFolder2_Release(psf
);
686 static HRESULT WINAPI
UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2
* iface
, HWND hwndOwner
,
687 REFIID riid
, void** ppv
)
689 HRESULT hr
= E_INVALIDARG
;
691 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface
, hwndOwner
, riid
, ppv
);
693 if (!ppv
) return E_INVALIDARG
;
696 if (IsEqualIID(&IID_IShellView
, riid
)) {
697 LPSHELLVIEW pShellView
;
699 pShellView
= IShellView_Constructor((IShellFolder
*)iface
);
701 hr
= IShellView_QueryInterface(pShellView
, riid
, ppv
);
702 IShellView_Release(pShellView
);
709 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2
* iface
, UINT cidl
,
710 LPCITEMIDLIST
* apidl
, SFGAOF
* rgfInOut
)
712 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
715 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface
, cidl
, apidl
, rgfInOut
);
717 if (!rgfInOut
|| (cidl
&& !apidl
))
721 *rgfInOut
&= This
->m_dwAttributes
;
723 char szAbsolutePath
[FILENAME_MAX
], *pszRelativePath
;
726 *rgfInOut
&= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|
728 lstrcpyA(szAbsolutePath
, This
->m_pszPath
);
729 pszRelativePath
= szAbsolutePath
+ lstrlenA(szAbsolutePath
);
730 for (i
=0; i
<cidl
; i
++) {
731 if ((*rgfInOut
& SFGAO_FILESYSTEM
) && !(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
732 struct stat fileStat
;
733 char *pszName
= _ILGetTextPointer(apidl
[i
]);
734 if (!pszName
) return E_INVALIDARG
;
735 lstrcpyA(pszRelativePath
, pszName
);
736 if (stat(szAbsolutePath
, &fileStat
) || !UNIXFS_is_dos_device(&fileStat
))
737 *rgfInOut
&= ~SFGAO_FILESYSTEM
;
739 if (!_ILIsFolder(apidl
[i
]))
740 *rgfInOut
&= ~(SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
);
747 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2
* iface
, HWND hwndOwner
,
748 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
, UINT
* prgfInOut
, void** ppvOut
)
750 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
752 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
753 iface
, hwndOwner
, cidl
, apidl
, debugstr_guid(riid
), prgfInOut
, ppvOut
);
755 if (IsEqualIID(&IID_IContextMenu
, riid
)) {
756 *ppvOut
= ISvItemCm_Constructor((IShellFolder
*)iface
, This
->m_pidlLocation
, apidl
, cidl
);
758 } else if (IsEqualIID(&IID_IDataObject
, riid
)) {
759 *ppvOut
= IDataObject_Constructor(hwndOwner
, This
->m_pidlLocation
, apidl
, cidl
);
761 } else if (IsEqualIID(&IID_IExtractIconA
, riid
)) {
763 if (cidl
!= 1) return E_FAIL
;
764 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
765 *ppvOut
= (LPVOID
)IExtractIconA_Constructor(pidl
);
768 } else if (IsEqualIID(&IID_IExtractIconW
, riid
)) {
770 if (cidl
!= 1) return E_FAIL
;
771 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
772 *ppvOut
= (LPVOID
)IExtractIconW_Constructor(pidl
);
775 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
776 FIXME("IDropTarget\n");
778 } else if (IsEqualIID(&IID_IShellLinkW
, riid
)) {
779 FIXME("IShellLinkW\n");
781 } else if (IsEqualIID(&IID_IShellLinkA
, riid
)) {
782 FIXME("IShellLinkA\n");
785 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid
));
786 return E_NOINTERFACE
;
790 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2
* iface
,
791 LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
* lpName
)
793 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
796 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface
, pidl
, uFlags
, lpName
);
798 if ((GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) &&
799 (GET_SHGDN_RELATION(uFlags
) != SHGDN_INFOLDER
))
801 if (!pidl
|| !pidl
->mkid
.cb
) {
802 lpName
->uType
= STRRET_CSTR
;
803 if (This
->m_dwPathMode
== PATHMODE_UNIX
) {
804 strcpy(lpName
->u
.cStr
, This
->m_pszPath
);
806 WCHAR
*pwszDosPath
= wine_get_dos_file_name(This
->m_pszPath
);
808 return HRESULT_FROM_WIN32(GetLastError());
809 PathRemoveBackslashW(pwszDosPath
);
810 WideCharToMultiByte(CP_UNIXCP
, 0, pwszDosPath
, -1, lpName
->u
.cStr
, MAX_PATH
, NULL
, NULL
);
811 HeapFree(GetProcessHeap(), 0, pwszDosPath
);
814 IShellFolder
*pSubFolder
;
817 hr
= IShellFolder_BindToObject(iface
, pidl
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
818 if (!SUCCEEDED(hr
)) return hr
;
820 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, lpName
);
821 IShellFolder_Release(pSubFolder
);
824 char *pszFileName
= _ILGetTextPointer(pidl
);
825 lpName
->uType
= STRRET_CSTR
;
826 strcpy(lpName
->u
.cStr
, pszFileName
? pszFileName
: "");
829 /* If in dos mode, do some post-processing on the path.
830 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
832 if (SUCCEEDED(hr
) && This
->m_dwPathMode
== PATHMODE_DOS
&& !_ILIsFolder(pidl
))
833 SHELL_FS_ProcessDisplayFilename(lpName
->u
.cStr
, uFlags
);
835 TRACE("--> %s\n", lpName
->u
.cStr
);
840 static HRESULT WINAPI
UnixFolder_IShellFolder2_SetNameOf(IShellFolder2
* iface
, HWND hwnd
,
841 LPCITEMIDLIST pidl
, LPCOLESTR lpszName
, SHGDNF uFlags
, LPITEMIDLIST
* ppidlOut
)
843 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
845 char szSrc
[FILENAME_MAX
], szDest
[FILENAME_MAX
];
847 int cBasePathLen
= lstrlenA(This
->m_pszPath
);
848 struct stat statDest
;
849 LPITEMIDLIST pidlSrc
, pidlDest
;
851 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
852 iface
, hwnd
, pidl
, debugstr_w(lpszName
), uFlags
, ppidlOut
);
854 /* pidl has to contain a single non-empty SHITEMID */
855 if (_ILIsDesktop(pidl
) || !_ILIsPidlSimple(pidl
) || !_ILGetTextPointer(pidl
))
861 /* build source path */
862 memcpy(szSrc
, This
->m_pszPath
, cBasePathLen
);
863 lstrcpyA(szSrc
+cBasePathLen
, _ILGetTextPointer(pidl
));
865 /* build destination path */
866 if (uFlags
& SHGDN_FORPARSING
) { /* absolute path in lpszName */
867 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
, FILENAME_MAX
, NULL
, NULL
);
869 WCHAR wszSrcRelative
[MAX_PATH
];
870 memcpy(szDest
, This
->m_pszPath
, cBasePathLen
);
871 WideCharToMultiByte(CP_UNIXCP
, 0, lpszName
, -1, szDest
+cBasePathLen
,
872 FILENAME_MAX
-cBasePathLen
, NULL
, NULL
);
874 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
875 * extension is hidden to the user, we have to append it. */
876 if (_ILSimpleGetTextW(pidl
, wszSrcRelative
, MAX_PATH
) &&
877 SHELL_FS_HideExtension(wszSrcRelative
))
879 char *pszExt
= PathFindExtensionA(_ILGetTextPointer(pidl
));
880 lstrcatA(szDest
, pszExt
);
884 TRACE("src=%s dest=%s\n", szSrc
, szDest
);
886 /* Fail, if destination does already exist */
887 if (!stat(szDest
, &statDest
))
890 /* Rename the file */
891 if (rename(szSrc
, szDest
))
894 /* Build a pidl for the path of the renamed file */
895 pwszDosDest
= wine_get_dos_file_name(szDest
);
896 if (!pwszDosDest
|| !UNIXFS_path_to_pidl(This
, pwszDosDest
, &pidlDest
)) {
897 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
898 rename(szDest
, szSrc
); /* Undo the renaming */
902 /* Inform the shell */
903 pidlSrc
= ILCombine(This
->m_pidlLocation
, pidl
);
904 if (_ILIsFolder(ILFindLastID(pidlDest
)))
905 SHChangeNotify(SHCNE_RENAMEFOLDER
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
907 SHChangeNotify(SHCNE_RENAMEITEM
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
912 _ILCreateFromPathW(pwszDosDest
, ppidlOut
);
914 HeapFree(GetProcessHeap(), 0, pwszDosDest
);
918 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumSearches(IShellFolder2
* iface
,
919 IEnumExtraSearch
**ppEnum
)
925 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2
* iface
,
926 DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
932 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2
* iface
,
933 UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
939 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2
* iface
,
946 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2
* iface
,
947 LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
953 #define SHELLVIEWCOLUMNS 7
955 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2
* iface
,
956 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
*psd
)
958 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
960 struct passwd
*pPasswd
;
961 struct group
*pGroup
;
962 static const shvheader SFHeader
[SHELLVIEWCOLUMNS
] = {
963 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
964 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
965 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
966 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
967 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 9},
968 {IDS_SHV_COLUMN10
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
969 {IDS_SHV_COLUMN11
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7}
972 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface
, pidl
, iColumn
, psd
);
974 if (!psd
|| iColumn
>= SHELLVIEWCOLUMNS
)
978 psd
->fmt
= SFHeader
[iColumn
].fmt
;
979 psd
->cxChar
= SFHeader
[iColumn
].cxChar
;
980 psd
->str
.uType
= STRRET_CSTR
;
981 LoadStringA(shell32_hInstance
, SFHeader
[iColumn
].colnameid
, psd
->str
.u
.cStr
, MAX_PATH
);
984 struct stat statItem
;
985 if (iColumn
== 4 || iColumn
== 5 || iColumn
== 6) {
986 char szPath
[FILENAME_MAX
], *pszFile
= _ILGetTextPointer(pidl
);
989 lstrcpyA(szPath
, This
->m_pszPath
);
990 lstrcatA(szPath
, pszFile
);
991 if (stat(szPath
, &statItem
))
994 psd
->str
.u
.cStr
[0] = '\0';
995 psd
->str
.uType
= STRRET_CSTR
;
998 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
|SHGDN_INFOLDER
, &psd
->str
);
1001 _ILGetFileSize(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1004 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1007 _ILGetFileDate(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1010 psd
->str
.u
.cStr
[0] = S_ISDIR(statItem
.st_mode
) ? 'd' : '-';
1011 psd
->str
.u
.cStr
[1] = (statItem
.st_mode
& S_IRUSR
) ? 'r' : '-';
1012 psd
->str
.u
.cStr
[2] = (statItem
.st_mode
& S_IWUSR
) ? 'w' : '-';
1013 psd
->str
.u
.cStr
[3] = (statItem
.st_mode
& S_IXUSR
) ? 'x' : '-';
1014 psd
->str
.u
.cStr
[4] = (statItem
.st_mode
& S_IRGRP
) ? 'r' : '-';
1015 psd
->str
.u
.cStr
[5] = (statItem
.st_mode
& S_IWGRP
) ? 'w' : '-';
1016 psd
->str
.u
.cStr
[6] = (statItem
.st_mode
& S_IXGRP
) ? 'x' : '-';
1017 psd
->str
.u
.cStr
[7] = (statItem
.st_mode
& S_IROTH
) ? 'r' : '-';
1018 psd
->str
.u
.cStr
[8] = (statItem
.st_mode
& S_IWOTH
) ? 'w' : '-';
1019 psd
->str
.u
.cStr
[9] = (statItem
.st_mode
& S_IXOTH
) ? 'x' : '-';
1020 psd
->str
.u
.cStr
[10] = '\0';
1023 pPasswd
= getpwuid(statItem
.st_uid
);
1024 if (pPasswd
) strcpy(psd
->str
.u
.cStr
, pPasswd
->pw_name
);
1027 pGroup
= getgrgid(statItem
.st_gid
);
1028 if (pGroup
) strcpy(psd
->str
.u
.cStr
, pGroup
->gr_name
);
1036 static HRESULT WINAPI
UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2
* iface
, UINT iColumn
,
1043 /* VTable for UnixFolder's IShellFolder2 interface.
1045 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl
= {
1046 UnixFolder_IShellFolder2_QueryInterface
,
1047 UnixFolder_IShellFolder2_AddRef
,
1048 UnixFolder_IShellFolder2_Release
,
1049 UnixFolder_IShellFolder2_ParseDisplayName
,
1050 UnixFolder_IShellFolder2_EnumObjects
,
1051 UnixFolder_IShellFolder2_BindToObject
,
1052 UnixFolder_IShellFolder2_BindToStorage
,
1053 UnixFolder_IShellFolder2_CompareIDs
,
1054 UnixFolder_IShellFolder2_CreateViewObject
,
1055 UnixFolder_IShellFolder2_GetAttributesOf
,
1056 UnixFolder_IShellFolder2_GetUIObjectOf
,
1057 UnixFolder_IShellFolder2_GetDisplayNameOf
,
1058 UnixFolder_IShellFolder2_SetNameOf
,
1059 UnixFolder_IShellFolder2_GetDefaultSearchGUID
,
1060 UnixFolder_IShellFolder2_EnumSearches
,
1061 UnixFolder_IShellFolder2_GetDefaultColumn
,
1062 UnixFolder_IShellFolder2_GetDefaultColumnState
,
1063 UnixFolder_IShellFolder2_GetDetailsEx
,
1064 UnixFolder_IShellFolder2_GetDetailsOf
,
1065 UnixFolder_IShellFolder2_MapColumnToSCID
1068 static HRESULT WINAPI
UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3
* This
, REFIID riid
,
1071 return UnixFolder_IShellFolder2_QueryInterface(
1072 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
), riid
, ppvObject
);
1075 static ULONG WINAPI
UnixFolder_IPersistFolder3_AddRef(IPersistFolder3
* This
)
1077 return UnixFolder_IShellFolder2_AddRef(
1078 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1081 static ULONG WINAPI
UnixFolder_IPersistFolder3_Release(IPersistFolder3
* This
)
1083 return UnixFolder_IShellFolder2_Release(
1084 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder3
, This
));
1087 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3
* iface
, CLSID
* pClassID
)
1089 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1091 TRACE("(iface=%p, pClassId=%p)\n", iface
, pClassID
);
1094 return E_INVALIDARG
;
1096 memcpy(pClassID
, This
->m_pCLSID
, sizeof(CLSID
));
1100 static HRESULT WINAPI
UnixFolder_IPersistFolder3_Initialize(IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1102 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1103 struct stat statPrefix
;
1104 LPCITEMIDLIST current
= pidl
, root
;
1106 char *pNextDir
, szBasePath
[FILENAME_MAX
] = "/";
1108 TRACE("(iface=%p, pidl=%p)\n", iface
, pidl
);
1110 /* Find the UnixFolderClass root */
1111 while (current
->mkid
.cb
) {
1112 if (_ILIsSpecialFolder(current
) &&
1113 (IsEqualIID(&CLSID_UnixFolder
, _ILGetGUIDPointer(current
)) ||
1114 IsEqualIID(&CLSID_UnixDosFolder
, _ILGetGUIDPointer(current
))))
1118 current
= ILGetNext(current
);
1121 if (current
&& current
->mkid
.cb
) {
1122 root
= current
= ILGetNext(current
);
1123 dwPathLen
= 2; /* For the '/' prefix and the terminating '\0' */
1124 } else if (_ILIsDesktop(pidl
) || _ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1125 /* Path rooted at Desktop */
1126 WCHAR wszDesktopPath
[MAX_PATH
];
1127 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath
, CSIDL_DESKTOP
, FALSE
)))
1129 PathAddBackslashW(wszDesktopPath
);
1130 if (!UNIXFS_get_unix_path(wszDesktopPath
, szBasePath
))
1132 dwPathLen
= strlen(szBasePath
) + 1;
1133 root
= current
= pidl
;
1135 ERR("Unknown pidl type!\n");
1137 return E_INVALIDARG
;
1140 /* Determine the path's length bytes */
1141 while (current
&& current
->mkid
.cb
) {
1142 dwPathLen
+= NAME_LEN_FROM_LPSHITEMID(current
) + 1; /* For the '/' */
1143 current
= ILGetNext(current
);
1146 /* Build the path */
1147 This
->m_dwAttributes
= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
;
1148 This
->m_pidlLocation
= ILClone(pidl
);
1149 This
->m_pszPath
= pNextDir
= SHAlloc(dwPathLen
);
1150 if (!This
->m_pszPath
|| !This
->m_pidlLocation
) {
1151 WARN("SHAlloc failed!\n");
1155 strcpy(pNextDir
, szBasePath
);
1156 pNextDir
+= strlen(szBasePath
);
1157 if (This
->m_dwPathMode
== PATHMODE_UNIX
)
1158 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1159 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1161 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1162 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1164 while (current
&& current
->mkid
.cb
) {
1165 memcpy(pNextDir
, _ILGetTextPointer(current
), NAME_LEN_FROM_LPSHITEMID(current
));
1166 pNextDir
+= NAME_LEN_FROM_LPSHITEMID(current
);
1167 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1169 if (!stat(This
->m_pszPath
, &statPrefix
) && UNIXFS_is_dos_device(&statPrefix
))
1170 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
1173 current
= ILGetNext(current
);
1180 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3
* iface
, LPITEMIDLIST
* ppidl
)
1182 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1184 TRACE ("(iface=%p, ppidl=%p)\n", iface
, ppidl
);
1188 *ppidl
= ILClone (This
->m_pidlLocation
);
1192 static HRESULT WINAPI
UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3
*iface
, IBindCtx
*pbc
,
1193 LPCITEMIDLIST pidlRoot
, const PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1195 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1196 WCHAR wszTargetDosPath
[MAX_PATH
];
1197 char szTargetPath
[FILENAME_MAX
] = "";
1199 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface
, pbc
, pidlRoot
, ppfti
);
1201 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1203 return IPersistFolder3_Initialize(iface
, pidlRoot
);
1205 if (ppfti
->csidl
!= -1) {
1206 if (SUCCEEDED(SHGetFolderPathW(0, ppfti
->csidl
, NULL
, 0, wszTargetDosPath
))) {
1207 UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
);
1209 } else if (*ppfti
->szTargetParsingName
) {
1210 UNIXFS_get_unix_path(ppfti
->szTargetParsingName
, szTargetPath
);
1211 } else if (ppfti
->pidlTargetFolder
) {
1212 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTargetDosPath
)) {
1213 UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
);
1217 This
->m_pszPath
= SHAlloc(lstrlenA(szTargetPath
)+1);
1218 if (!This
->m_pszPath
)
1220 lstrcpyA(This
->m_pszPath
, szTargetPath
);
1221 This
->m_pidlLocation
= ILClone(pidlRoot
);
1222 This
->m_dwAttributes
= (ppfti
->dwAttributes
== -1) ? ppfti
->dwAttributes
:
1223 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|SFGAO_FILESYSTEM
;
1228 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3
*iface
,
1229 PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1231 FIXME("(iface=%p, ppfti=%p) stub\n", iface
, ppfti
);
1235 /* VTable for UnixFolder's IPersistFolder interface.
1237 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl
= {
1238 UnixFolder_IPersistFolder3_QueryInterface
,
1239 UnixFolder_IPersistFolder3_AddRef
,
1240 UnixFolder_IPersistFolder3_Release
,
1241 UnixFolder_IPersistFolder3_GetClassID
,
1242 UnixFolder_IPersistFolder3_Initialize
,
1243 UnixFolder_IPersistFolder3_GetCurFolder
,
1244 UnixFolder_IPersistFolder3_InitializeEx
,
1245 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1248 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag
* This
,
1249 REFIID riid
, void** ppvObject
)
1251 return UnixFolder_IShellFolder2_QueryInterface(
1252 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
), riid
, ppvObject
);
1255 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag
* This
)
1257 return UnixFolder_IShellFolder2_AddRef(
1258 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
));
1261 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag
* This
)
1263 return UnixFolder_IShellFolder2_Release(
1264 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, This
));
1267 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag
* iface
,
1270 return UnixFolder_IPersistFolder3_GetClassID(
1271 (IPersistFolder3
*)&ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)->lpIPersistFolder3Vtbl
,
1275 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag
* iface
)
1281 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag
*iface
,
1282 IPropertyBag
*pPropertyBag
, IErrorLog
*pErrorLog
)
1288 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag
*iface
,
1289 IPropertyBag
*pPropertyBag
, BOOL fClearDirty
, BOOL fSaveAllProperties
)
1295 /* VTable for UnixFolder's IPersistPropertyBag interface.
1297 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl
= {
1298 UnixFolder_IPersistPropertyBag_QueryInterface
,
1299 UnixFolder_IPersistPropertyBag_AddRef
,
1300 UnixFolder_IPersistPropertyBag_Release
,
1301 UnixFolder_IPersistPropertyBag_GetClassID
,
1302 UnixFolder_IPersistPropertyBag_InitNew
,
1303 UnixFolder_IPersistPropertyBag_Load
,
1304 UnixFolder_IPersistPropertyBag_Save
1307 static HRESULT WINAPI
UnixFolder_ISFHelper_QueryInterface(ISFHelper
* iface
, REFIID riid
,
1310 return UnixFolder_IShellFolder2_QueryInterface(
1311 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
), riid
, ppvObject
);
1314 static ULONG WINAPI
UnixFolder_ISFHelper_AddRef(ISFHelper
* iface
)
1316 return UnixFolder_IShellFolder2_AddRef(
1317 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1320 static ULONG WINAPI
UnixFolder_ISFHelper_Release(ISFHelper
* iface
)
1322 return UnixFolder_IShellFolder2_Release(
1323 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, ISFHelper
, iface
));
1326 static HRESULT WINAPI
UnixFolder_ISFHelper_GetUniqueName(ISFHelper
* iface
, LPSTR lpName
, UINT uLen
)
1328 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1331 LPITEMIDLIST pidlElem
;
1334 static const char szNewFolder
[] = "New Folder";
1336 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface
, lpName
, uLen
);
1338 if (uLen
< sizeof(szNewFolder
)+3)
1339 return E_INVALIDARG
;
1341 hr
= IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2
, This
), 0,
1342 SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
, &pEnum
);
1343 if (SUCCEEDED(hr
)) {
1344 lstrcpyA(lpName
, szNewFolder
);
1345 IEnumIDList_Reset(pEnum
);
1347 while ((IEnumIDList_Next(pEnum
, 1, &pidlElem
, &dwFetched
) == S_OK
) && (dwFetched
== 1)) {
1348 if (!strcasecmp(_ILGetTextPointer(pidlElem
), lpName
)) {
1349 IEnumIDList_Reset(pEnum
);
1350 sprintf(lpName
, "%s %d", szNewFolder
, i
++);
1357 IEnumIDList_Release(pEnum
);
1362 static HRESULT WINAPI
UnixFolder_ISFHelper_AddFolder(ISFHelper
* iface
, HWND hwnd
, LPCSTR pszName
,
1363 LPITEMIDLIST
* ppidlOut
)
1365 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1366 char szNewDir
[FILENAME_MAX
];
1368 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface
, hwnd
, pszName
, ppidlOut
);
1373 lstrcpyA(szNewDir
, This
->m_pszPath
);
1374 lstrcatA(szNewDir
, pszName
);
1376 if (mkdir(szNewDir
, 0755)) {
1377 char szMessage
[256 + FILENAME_MAX
];
1378 char szCaption
[256];
1380 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, szCaption
, sizeof(szCaption
));
1381 sprintf(szMessage
, szCaption
, szNewDir
);
1382 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, szCaption
, sizeof(szCaption
));
1383 MessageBoxA(hwnd
, szMessage
, szCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1387 LPITEMIDLIST pidlRelative
;
1388 WCHAR wszName
[MAX_PATH
];
1390 /* Inform the shell */
1391 MultiByteToWideChar(CP_UNIXCP
, 0, pszName
, -1, wszName
, MAX_PATH
);
1392 if (UNIXFS_path_to_pidl(This
, wszName
, &pidlRelative
)) {
1393 LPITEMIDLIST pidlAbsolute
= ILCombine(This
->m_pidlLocation
, pidlRelative
);
1395 *ppidlOut
= pidlRelative
;
1397 ILFree(pidlRelative
);
1398 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1399 ILFree(pidlAbsolute
);
1405 static HRESULT WINAPI
UnixFolder_ISFHelper_DeleteItems(ISFHelper
* iface
, UINT cidl
,
1406 LPCITEMIDLIST
* apidl
)
1408 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1409 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1410 LPITEMIDLIST pidlAbsolute
;
1414 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface
, cidl
, apidl
);
1416 lstrcpyA(szAbsolute
, This
->m_pszPath
);
1417 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
1419 for (i
=0; i
<cidl
&& SUCCEEDED(hr
); i
++) {
1420 lstrcpyA(pszRelative
, _ILGetTextPointer(apidl
[i
]));
1421 pidlAbsolute
= ILCombine(This
->m_pidlLocation
, apidl
[i
]);
1422 if (_ILIsFolder(apidl
[i
])) {
1423 if (rmdir(szAbsolute
)) {
1426 SHChangeNotify(SHCNE_RMDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1428 } else if (_ILIsValue(apidl
[i
])) {
1429 if (unlink(szAbsolute
)) {
1432 SHChangeNotify(SHCNE_DELETE
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1435 ILFree(pidlAbsolute
);
1441 static HRESULT WINAPI
UnixFolder_ISFHelper_CopyItems(ISFHelper
* iface
, IShellFolder
*psfFrom
,
1442 UINT cidl
, LPCITEMIDLIST
*apidl
)
1444 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1448 char szAbsoluteDst
[FILENAME_MAX
], *pszRelativeDst
;
1450 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface
, psfFrom
, cidl
, apidl
);
1452 if (!psfFrom
|| !cidl
|| !apidl
)
1453 return E_INVALIDARG
;
1455 /* All source items have to be filesystem items. */
1456 dwAttributes
= SFGAO_FILESYSTEM
;
1457 hr
= IShellFolder_GetAttributesOf(psfFrom
, cidl
, apidl
, &dwAttributes
);
1458 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
))
1459 return E_INVALIDARG
;
1461 lstrcpyA(szAbsoluteDst
, This
->m_pszPath
);
1462 pszRelativeDst
= szAbsoluteDst
+ strlen(szAbsoluteDst
);
1464 for (i
=0; i
<cidl
; i
++) {
1465 WCHAR wszSrc
[MAX_PATH
];
1466 char szSrc
[FILENAME_MAX
];
1469 /* Build the unix path of the current source item. */
1470 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom
, apidl
[i
], SHGDN_FORPARSING
, &strret
)))
1472 if (FAILED(StrRetToBufW(&strret
, apidl
[i
], wszSrc
, MAX_PATH
)))
1474 if (!UNIXFS_get_unix_path(wszSrc
, szSrc
))
1477 /* Build the unix path of the current destination item */
1478 lstrcpyA(pszRelativeDst
, _ILGetTextPointer(apidl
[i
]));
1480 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc
, szAbsoluteDst
);
1485 /* VTable for UnixFolder's ISFHelper interface
1487 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl
= {
1488 UnixFolder_ISFHelper_QueryInterface
,
1489 UnixFolder_ISFHelper_AddRef
,
1490 UnixFolder_ISFHelper_Release
,
1491 UnixFolder_ISFHelper_GetUniqueName
,
1492 UnixFolder_ISFHelper_AddFolder
,
1493 UnixFolder_ISFHelper_DeleteItems
,
1494 UnixFolder_ISFHelper_CopyItems
1497 /******************************************************************************
1498 * Unix[Dos]Folder_Constructor [Internal]
1501 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1502 * riid [I] Interface asked for by the client.
1503 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1506 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1507 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1508 * compatible signature.
1510 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1511 * means that paths are converted from dos to unix and back at the interfaces.
1513 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, DWORD dwPathMode
,
1514 const CLSID
*pCLSID
)
1516 HRESULT hr
= E_FAIL
;
1517 UnixFolder
*pUnixFolder
= SHAlloc((ULONG
)sizeof(UnixFolder
));
1520 pUnixFolder
->lpIShellFolder2Vtbl
= &UnixFolder_IShellFolder2_Vtbl
;
1521 pUnixFolder
->lpIPersistFolder3Vtbl
= &UnixFolder_IPersistFolder3_Vtbl
;
1522 pUnixFolder
->lpIPersistPropertyBagVtbl
= &UnixFolder_IPersistPropertyBag_Vtbl
;
1523 pUnixFolder
->lpISFHelperVtbl
= &UnixFolder_ISFHelper_Vtbl
;
1524 pUnixFolder
->m_cRef
= 0;
1525 pUnixFolder
->m_pszPath
= NULL
;
1526 pUnixFolder
->m_pidlLocation
= NULL
;
1527 pUnixFolder
->m_dwPathMode
= dwPathMode
;
1528 pUnixFolder
->m_dwAttributes
= 0;
1529 pUnixFolder
->m_pCLSID
= pCLSID
;
1531 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1532 hr
= UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2
, pUnixFolder
), riid
, ppv
);
1533 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1538 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1539 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1540 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_UNIX
, &CLSID_UnixFolder
);
1543 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1544 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1545 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_DOS
, &CLSID_UnixDosFolder
);
1548 HRESULT WINAPI
FolderShortcut_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1549 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1550 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_DOS
, &CLSID_FolderShortcut
);
1553 /******************************************************************************
1554 * UnixSubFolderIterator
1556 * Class whose heap based objects represent iterators over the sub-directories
1557 * of a given UnixFolder object.
1560 /* UnixSubFolderIterator object layout and typedef.
1562 typedef struct _UnixSubFolderIterator
{
1563 const IEnumIDListVtbl
*lpIEnumIDListVtbl
;
1567 char m_szFolder
[FILENAME_MAX
];
1568 } UnixSubFolderIterator
;
1570 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator
*iterator
) {
1571 TRACE("(iterator=%p)\n", iterator
);
1573 if (iterator
->m_dirFolder
)
1574 closedir(iterator
->m_dirFolder
);
1578 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList
* iface
,
1579 REFIID riid
, void** ppv
)
1581 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
1583 if (!ppv
) return E_INVALIDARG
;
1585 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumIDList
, riid
)) {
1589 return E_NOINTERFACE
;
1592 IEnumIDList_AddRef(iface
);
1596 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList
* iface
)
1598 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1600 TRACE("(iface=%p)\n", iface
);
1602 return InterlockedIncrement(&This
->m_cRef
);
1605 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList
* iface
)
1607 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1610 TRACE("(iface=%p)\n", iface
);
1612 cRef
= InterlockedDecrement(&This
->m_cRef
);
1615 UnixSubFolderIterator_Destroy(This
);
1620 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList
* iface
, ULONG celt
,
1621 LPITEMIDLIST
* rgelt
, ULONG
* pceltFetched
)
1623 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1626 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
1627 if (This
->m_dirFolder
) {
1628 char *pszRelativePath
= This
->m_szFolder
+ lstrlenA(This
->m_szFolder
);
1629 struct dirent
*pDirEntry
;
1632 pDirEntry
= readdir(This
->m_dirFolder
);
1633 if (!pDirEntry
) break; /* No more entries */
1634 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
1636 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
1637 * and see if it passes the filter.
1639 lstrcpyA(pszRelativePath
, pDirEntry
->d_name
);
1640 rgelt
[i
] = (LPITEMIDLIST
)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath
))+sizeof(USHORT
));
1641 if (!UNIXFS_build_shitemid(This
->m_szFolder
, rgelt
[i
]) ||
1642 !UNIXFS_is_pidl_of_type(rgelt
[i
], This
->m_fFilter
))
1647 memset(((PBYTE
)rgelt
[i
])+rgelt
[i
]->mkid
.cb
, 0, sizeof(USHORT
));
1650 *pszRelativePath
= '\0'; /* Restore the original path in This->m_szFolder. */
1656 return (i
== 0) ? S_FALSE
: S_OK
;
1659 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList
* iface
, ULONG celt
)
1661 LPITEMIDLIST
*apidl
;
1665 TRACE("(iface=%p, celt=%ld)\n", iface
, celt
);
1667 /* Call IEnumIDList::Next and delete the resulting pidls. */
1668 apidl
= (LPITEMIDLIST
*)SHAlloc(celt
* sizeof(LPITEMIDLIST
));
1669 hr
= IEnumIDList_Next(iface
, celt
, apidl
, &cFetched
);
1672 SHFree(apidl
[cFetched
]);
1678 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList
* iface
)
1680 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1682 TRACE("(iface=%p)\n", iface
);
1684 if (This
->m_dirFolder
)
1685 rewinddir(This
->m_dirFolder
);
1690 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList
* This
,
1691 IEnumIDList
** ppenum
)
1697 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1699 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl
= {
1700 UnixSubFolderIterator_IEnumIDList_QueryInterface
,
1701 UnixSubFolderIterator_IEnumIDList_AddRef
,
1702 UnixSubFolderIterator_IEnumIDList_Release
,
1703 UnixSubFolderIterator_IEnumIDList_Next
,
1704 UnixSubFolderIterator_IEnumIDList_Skip
,
1705 UnixSubFolderIterator_IEnumIDList_Reset
,
1706 UnixSubFolderIterator_IEnumIDList_Clone
1709 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
) {
1710 UnixSubFolderIterator
*iterator
;
1712 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
1714 iterator
= SHAlloc((ULONG
)sizeof(UnixSubFolderIterator
));
1715 iterator
->lpIEnumIDListVtbl
= &UnixSubFolderIterator_IEnumIDList_Vtbl
;
1716 iterator
->m_cRef
= 0;
1717 iterator
->m_fFilter
= fFilter
;
1718 iterator
->m_dirFolder
= opendir(pUnixFolder
->m_pszPath
);
1719 lstrcpyA(iterator
->m_szFolder
, pUnixFolder
->m_pszPath
);
1721 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList
*)iterator
);
1723 return (IUnknown
*)iterator
;