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
27 #ifdef HAVE_SYS_STAT_H
28 # include <sys/stat.h>
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
46 #include "wine/debug.h"
48 #include "shell32_main.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
56 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
58 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
59 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
61 /* FileStruct reserves one byte for szNames, thus we don't have to
62 * alloc a byte for the terminating '\0' of 'name'. Two of the
63 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
64 * type field. One is for FileStruct's szNames field, to terminate
65 * the alternate DOS name, which we don't use here. And then there's
66 * the additional StatStruct.
68 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
69 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char)+sizeof(StatStruct))
70 #define NAME_LEN_FROM_LPSHITEMID(s) \
71 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char)-sizeof(StatStruct))
72 #define LPSTATSTRUCT_FROM_LPSHITEMID(s) ((StatStruct*)(((LPBYTE)s)+((LPSHITEMID)s)->cb-sizeof(StatStruct)))
74 #define PATHMODE_UNIX 0
75 #define PATHMODE_DOS 1
77 /* This structure is appended to shell32's FileStruct type in IDLs to store unix
78 * filesystem specific informationen extracted with the stat system call.
80 typedef struct tagStatStruct {
86 /* UnixFolder object layout and typedef.
88 typedef struct _UnixFolder {
89 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
90 const IPersistFolder2Vtbl *lpIPersistFolder2Vtbl;
93 LPITEMIDLIST m_pidlLocation;
94 LPITEMIDLIST *m_apidlSubDirs;
99 /******************************************************************************
100 * UNIXFS_is_pidl_of_type [INTERNAL]
102 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
105 * pIDL [I] The ITEMIDLIST to be checked.
106 * fFilter [I] Shell condition flags, which specify the filter.
109 * TRUE, if pIDL is accepted by fFilter
112 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
113 LPSTR pszText = _ILGetTextPointer(pIDL);
114 if (!pszText) return FALSE;
115 if (pszText[0] == '.' && !(fFilter & SHCONTF_INCLUDEHIDDEN)) return FALSE;
116 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
117 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
121 /******************************************************************************
122 * UNIXFS_build_shitemid [Internal]
124 * Constructs a new SHITEMID for a single path item (up to the next '/' or
125 * '\0') into a buffer. Decorates the SHITEMID with information from a stat
129 * name [I] The name of the next path item. Terminated by either '\0' or '/'.
130 * pStat [I] A stat struct variable obtained by a stat system call on the file.
131 * buffer [O] SHITEMID will be constructed here.
134 * A pointer to the next '/' or '\0' character in name.
137 * Minimum size of buffer is SHITEMID_LEN_FROM_NAME_LEN(strlen(name)).
138 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
141 static char* UNIXFS_build_shitemid(char *name, struct stat *pStat, void *buffer) {
145 StatStruct *pStatStruct;
149 TRACE("(name=%s, pStat=%p, buffer=%p)\n", debugstr_a(name), pStat, buffer);
151 pSlash = strchr(name, '/');
152 cNameLen = pSlash ? pSlash - name : strlen(name);
154 memset(buffer, 0, SHITEMID_LEN_FROM_NAME_LEN(cNameLen));
155 ((LPSHITEMID)buffer)->cb = SHITEMID_LEN_FROM_NAME_LEN(cNameLen) ;
157 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)buffer);
158 pIDLData->type = S_ISDIR(pStat->st_mode) ? PT_FOLDER : PT_VALUE;
159 pIDLData->u.file.dwFileSize = (DWORD)pStat->st_size;
160 RtlSecondsSince1970ToTime( pStat->st_mtime, &time );
161 fileTime.dwLowDateTime = time.u.LowPart;
162 fileTime.dwHighDateTime = time.u.HighPart;
163 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
164 pIDLData->u.file.uFileAttribs =
165 (S_ISDIR(pStat->st_mode) ? FILE_ATTRIBUTE_DIRECTORY : 0) |
166 (name[0] == '.' ? FILE_ATTRIBUTE_HIDDEN : 0);
167 memcpy(pIDLData->u.file.szNames, name, cNameLen);
169 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(buffer);
170 pStatStruct->st_mode = pStat->st_mode;
171 pStatStruct->st_uid = pStat->st_uid;
172 pStatStruct->st_gid = pStat->st_gid;
174 return pSlash ? pSlash+1 : (name + cNameLen);
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 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
267 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
268 *pszCanonicalPath = '\0';
269 pCanonicalTail = pszCanonicalPath;
272 /* Relative link. Expand into szPath and continue. */
273 char szTemp[FILENAME_MAX];
274 int cTailLen = strlen(pPathTail);
276 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
279 memcpy(szTemp, pPathTail, cTailLen + 1);
280 memcpy(pElement + 1, szSymlink, cLinkLen);
281 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
282 pPathTail = pElement;
285 /* Regular directory or file. Copy to canonical path */
286 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
289 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
290 pCanonicalTail += pPathTail - pElement;
293 } while (pPathTail[0] == '/' && pPathTail[1]); /* Also handles paths terminated by '/' */
295 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
300 /******************************************************************************
301 * UNIXFS_path_to_pidl [Internal]
304 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
305 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
306 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
310 * Failure: FALSE, invalid params or out of memory
313 * pUnixFolder also carries the information if the path is expected to be unix or dos.
315 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
317 struct stat fileStat;
318 int cSubDirs, cPidlLen, res, cPathLen;
319 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
321 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
326 cPathLen = lstrlenW(path);
328 /* Build an absolute path and let pNextPathElement point to the interesting
329 * relative sub-path. We need the absolute path to call 'stat', but the pidl
330 * will only contain the relative part.
332 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
334 /* Absolute dos path. Convert to unix */
335 if (!UNIXFS_get_unix_path(path, szCompletePath))
337 pNextPathElement = szCompletePath + 1;
339 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
341 /* Absolute unix path. Just convert to ANSI. */
342 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
343 pNextPathElement = szCompletePath + 1;
347 /* Relative dos or unix path. Concat with this folder's path */
348 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
349 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
350 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath + cBasePathLen,
351 FILENAME_MAX - cBasePathLen, NULL, NULL);
352 pNextPathElement = szCompletePath + cBasePathLen;
354 /* If in dos mode, replace '\' with '/' */
355 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
356 char *pBackslash = strchr(pNextPathElement, '\\');
359 pBackslash = strchr(pBackslash, '\\');
364 /* At this point, we have an absolute unix path in szCompletePath. */
365 TRACE("complete path: %s\n", szCompletePath);
367 /* Count the number of sub-directories in the path */
368 cSubDirs = 1; /* Path may not be terminated with '/', thus start with 1 */
369 pSlash = strchr(pNextPathElement, '/');
370 while (pSlash && pSlash[1]) {
372 pSlash = strchr(pSlash+1, '/');
375 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
376 * characters, which are not stored in the ITEMIDLIST. */
377 cPidlLen = strlen(pNextPathElement) - cSubDirs + 1 + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
378 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
379 if (!pidl) return FALSE;
381 /* Concatenate the SHITEMIDs of the sub-directories. */
382 while (*pNextPathElement) {
383 pSlash = strchr(pNextPathElement, '/');
386 res = stat(szCompletePath, &fileStat);
393 if (stat(szCompletePath, &fileStat)) {
399 pNextPathElement = UNIXFS_build_shitemid(pNextPathElement, &fileStat, pidl);
400 pidl = ILGetNext(pidl);
402 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
404 if ((int)pidl-(int)*ppidl+sizeof(USHORT) > cPidlLen) /* We've corrupted the heap :( */
405 ERR("Computed length of pidl to small. Please report.\n");
410 /******************************************************************************
411 * UNIXFS_pidl_to_path [Internal]
413 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
416 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
417 * path [O] The corresponding unix path as a zero terminated ascii string
421 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
423 static BOOL UNIXFS_pidl_to_path(LPCITEMIDLIST pidl, UnixFolder *pUnixFolder) {
424 LPCITEMIDLIST current = pidl, root;
426 char *pNextDir, szBasePath[FILENAME_MAX] = "/";
428 TRACE("(pidl=%p, pUnixFolder=%p)\n", pidl, pUnixFolder);
431 pUnixFolder->m_pszPath = NULL;
433 /* Find the UnixFolderClass root */
434 while (current->mkid.cb) {
435 if (_ILIsDrive(current) || /* The dos drive, which maps to '/' */
436 (_ILIsSpecialFolder(current) &&
437 (IsEqualIID(&CLSID_UnixFolder, _ILGetGUIDPointer(current)) ||
438 IsEqualIID(&CLSID_UnixDosFolder, _ILGetGUIDPointer(current)))))
442 current = ILGetNext(current);
445 if (current && current->mkid.cb) {
446 root = current = ILGetNext(current);
447 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
448 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
449 /* Path rooted at Desktop */
450 WCHAR wszDesktopPath[MAX_PATH];
451 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOP, FALSE)))
453 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
455 dwPathLen = strlen(szBasePath) + 1;
458 ERR("Unknown pidl type!\n");
463 /* Determine the path's length bytes */
464 while (current && current->mkid.cb) {
465 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
466 current = ILGetNext(current);
470 pUnixFolder->m_pszPath = pNextDir = SHAlloc(dwPathLen);
471 if (!pUnixFolder->m_pszPath) {
472 WARN("SHAlloc failed!\n");
476 strcpy(pNextDir, szBasePath);
477 pNextDir += strlen(szBasePath);
478 while (current && current->mkid.cb) {
479 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
480 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
482 current = ILGetNext(current);
486 TRACE("--> %s\n", pUnixFolder->m_pszPath);
490 /******************************************************************************
491 * UNIXFS_build_subfolder_pidls [Internal]
493 * Builds an array of subfolder PIDLs relative to a unix directory
496 * path [I] Name of a unix directory as a zero terminated ascii string
497 * apidl [O] The array of PIDLs
498 * pCount [O] Size of apidl
502 * Failure: FALSE, path is not a valid unix directory or out of memory
505 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
506 * to release each PIDL as well as the array itself with SHFree.
508 static BOOL UNIXFS_build_subfolder_pidls(UnixFolder *pUnixFolder)
510 struct dirent *pDirEntry;
511 struct stat fileStat;
513 DWORD cDirEntries, i;
517 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
519 pUnixFolder->m_apidlSubDirs = NULL;
520 pUnixFolder->m_cSubDirs = 0;
522 dir = opendir(pUnixFolder->m_pszPath);
524 WARN("Failed to open directory '%s'.\n", pUnixFolder->m_pszPath);
528 /* Allocate space for fully qualified paths */
529 pszFQPath = SHAlloc(strlen(pUnixFolder->m_pszPath) + PATH_MAX);
531 WARN("SHAlloc failed!\n");
535 /* Count number of directory entries. */
536 for (cDirEntries = 0, pDirEntry = readdir(dir); pDirEntry; pDirEntry = readdir(dir)) {
537 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
538 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
539 if (!stat(pszFQPath, &fileStat) && (S_ISDIR(fileStat.st_mode) || S_ISREG(fileStat.st_mode))) cDirEntries++;
542 /* If there are no entries, we are done. */
543 if (cDirEntries == 0) {
549 /* Allocate the array of PIDLs */
550 pUnixFolder->m_apidlSubDirs = SHAlloc(cDirEntries * sizeof(LPITEMIDLIST));
551 if (!pUnixFolder->m_apidlSubDirs) {
552 WARN("SHAlloc failed!\n");
556 /* Allocate and initialize one SHITEMID per sub-directory. */
557 for (rewinddir(dir), pDirEntry = readdir(dir), i = 0; pDirEntry; pDirEntry = readdir(dir)) {
560 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
562 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
563 if (stat(pszFQPath, &fileStat)) continue;
564 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) continue;
566 sLen = strlen(pDirEntry->d_name);
567 pid = (LPSHITEMID)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen)+sizeof(USHORT));
569 WARN("SHAlloc failed!\n");
572 UNIXFS_build_shitemid(pDirEntry->d_name, &fileStat, pid);
573 memset(((PBYTE)pid)+pid->cb, 0, sizeof(USHORT));
575 pUnixFolder->m_apidlSubDirs[i++] = (LPITEMIDLIST)pid;
578 pUnixFolder->m_cSubDirs = i;
585 /******************************************************************************
588 * Class whose heap based instances represent unix filesystem directories.
591 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
594 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
596 if (pUnixFolder->m_apidlSubDirs)
597 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
598 SHFree(pUnixFolder->m_apidlSubDirs[i]);
599 SHFree(pUnixFolder->m_apidlSubDirs);
600 SHFree(pUnixFolder->m_pszPath);
601 ILFree(pUnixFolder->m_pidlLocation);
605 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
608 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
610 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
612 if (!ppv) return E_INVALIDARG;
614 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
615 IsEqualIID(&IID_IShellFolder2, riid))
617 *ppv = &This->lpIShellFolder2Vtbl;
618 } else if (IsEqualIID(&IID_IPersistFolder2, riid) || IsEqualIID(&IID_IPersistFolder, riid) ||
619 IsEqualIID(&IID_IPersist, riid))
621 *ppv = &This->lpIPersistFolder2Vtbl;
624 return E_NOINTERFACE;
627 IUnknown_AddRef((IUnknown*)*ppv);
631 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
632 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
634 TRACE("(iface=%p)\n", iface);
636 return InterlockedIncrement(&This->m_cRef);
639 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
640 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
643 TRACE("(iface=%p)\n", iface);
645 cRef = InterlockedDecrement(&This->m_cRef);
648 UnixFolder_Destroy(This);
653 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
654 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
655 ULONG* pdwAttributes)
657 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
660 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
661 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
662 pchEaten, ppidl, pdwAttributes);
664 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
665 if (result && pdwAttributes && *pdwAttributes)
667 /* need to traverse to the last element for the attribute */
668 LPCITEMIDLIST pidl, last_pidl;
669 pidl = last_pidl = *ppidl;
670 while(pidl && pidl->mkid.cb)
673 pidl = ILGetNext(pidl);
675 SHELL32_GetItemAttributes((IShellFolder*)iface, last_pidl, pdwAttributes);
678 if (!result) TRACE("FAILED!\n");
679 return result ? S_OK : E_FAIL;
682 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter);
684 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
685 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
687 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
688 IUnknown *newIterator;
691 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
692 iface, hwndOwner, grfFlags, ppEnumIDList);
694 newIterator = UnixSubFolderIterator_Construct(This, grfFlags);
695 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
696 IUnknown_Release(newIterator);
701 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
702 LPBC pbcReserved, REFIID riid, void** ppvOut)
704 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
705 IPersistFolder2 *persistFolder;
706 LPITEMIDLIST pidlSubFolder;
709 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
710 iface, pidl, pbcReserved, riid, ppvOut);
712 if (!pidl || !pidl->mkid.cb)
715 if (This->m_dwPathMode == PATHMODE_DOS)
716 hr = UnixDosFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
718 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
720 if (!SUCCEEDED(hr)) return hr;
721 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
723 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
724 IPersistFolder2_Initialize(persistFolder, pidlSubFolder);
725 IPersistFolder2_Release(persistFolder);
726 ILFree(pidlSubFolder);
731 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
732 LPBC pbcReserved, REFIID riid, void** ppvObj)
738 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
739 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
741 BOOL isEmpty1, isEmpty2;
743 LPITEMIDLIST firstpidl;
747 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
749 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
750 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
752 if (isEmpty1 && isEmpty2)
753 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
755 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
757 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
759 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
760 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
761 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
762 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
764 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
765 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
766 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
768 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
769 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
771 if (pidl1->mkid.cb < pidl2->mkid.cb)
772 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
773 else if (pidl1->mkid.cb > pidl2->mkid.cb)
774 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
776 firstpidl = ILCloneFirst(pidl1);
777 pidl1 = ILGetNext(pidl1);
778 pidl2 = ILGetNext(pidl2);
780 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
782 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
783 IShellFolder2_Release(psf);
790 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
791 REFIID riid, void** ppv)
793 HRESULT hr = E_INVALIDARG;
795 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
797 if (!ppv) return E_INVALIDARG;
800 if (IsEqualIID(&IID_IShellView, riid)) {
801 LPSHELLVIEW pShellView;
803 pShellView = IShellView_Constructor((IShellFolder*)iface);
805 hr = IShellView_QueryInterface(pShellView, riid, ppv);
806 IShellView_Release(pShellView);
813 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
814 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
817 SFGAOF flags= ~(SFGAOF)0;
819 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p) semi-stub\n", iface, cidl, apidl, rgfInOut);
821 for (i=0; i<cidl; i++) {
822 LPPIDLDATA pData = _ILGetDataPointer(apidl[i]);
823 if (!pData) continue;
824 if (pData->type == PT_FOLDER) flags &= (SFGAO_FILESYSTEM|SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER);
825 if (pData->type == PT_VALUE) flags &= SFGAO_FILESYSTEM;
828 *rgfInOut = *rgfInOut & flags;
833 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
834 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
836 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
838 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
839 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
841 if (IsEqualIID(&IID_IContextMenu, riid)) {
842 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
844 } else if (IsEqualIID(&IID_IDataObject, riid)) {
845 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
847 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
849 if (cidl != 1) return E_FAIL;
850 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
851 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
854 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
856 if (cidl != 1) return E_FAIL;
857 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
858 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
861 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
862 FIXME("IDropTarget\n");
864 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
865 FIXME("IShellLinkW\n");
867 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
868 FIXME("IShellLinkA\n");
871 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
872 return E_NOINTERFACE;
876 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
877 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
879 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
882 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
884 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
885 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
887 if (!pidl->mkid.cb) {
888 lpName->uType = STRRET_CSTR;
889 strcpy(lpName->u.cStr, This->m_pszPath);
890 if (This->m_dwPathMode == PATHMODE_DOS) {
892 GetFullPathNameA(lpName->u.cStr, MAX_PATH, path, NULL);
893 strcpy(lpName->u.cStr, path);
896 IShellFolder *pSubFolder;
899 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
900 if (!SUCCEEDED(hr)) return hr;
902 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
903 IShellFolder_Release(pSubFolder);
906 char *pszFileName = _ILGetTextPointer(pidl);
907 lpName->uType = STRRET_CSTR;
908 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
911 TRACE("--> %s\n", lpName->u.cStr);
916 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* This, HWND hwnd,
917 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
923 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
924 IEnumExtraSearch **ppEnum)
930 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
931 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
937 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
938 UINT iColumn, SHCOLSTATEF *pcsFlags)
944 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
951 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
952 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
958 #define SHELLVIEWCOLUMNS 6
960 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
961 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
964 struct passwd *pPasswd;
965 struct group *pGroup;
966 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
967 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
968 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
969 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
970 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
971 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 8},
972 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
975 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
977 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
981 psd->fmt = SFHeader[iColumn].fmt;
982 psd->cxChar = SFHeader[iColumn].cxChar;
983 psd->str.uType = STRRET_CSTR;
984 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
987 StatStruct *pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pidl);
988 psd->str.u.cStr[0] = '\0';
989 psd->str.uType = STRRET_CSTR;
992 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
995 psd->str.u.cStr[0] = S_ISDIR(pStatStruct->st_mode) ? 'd' : '-';
996 psd->str.u.cStr[1] = (pStatStruct->st_mode & S_IRUSR) ? 'r' : '-';
997 psd->str.u.cStr[2] = (pStatStruct->st_mode & S_IWUSR) ? 'w' : '-';
998 psd->str.u.cStr[3] = (pStatStruct->st_mode & S_IXUSR) ? 'x' : '-';
999 psd->str.u.cStr[4] = (pStatStruct->st_mode & S_IRGRP) ? 'r' : '-';
1000 psd->str.u.cStr[5] = (pStatStruct->st_mode & S_IWGRP) ? 'w' : '-';
1001 psd->str.u.cStr[6] = (pStatStruct->st_mode & S_IXGRP) ? 'x' : '-';
1002 psd->str.u.cStr[7] = (pStatStruct->st_mode & S_IROTH) ? 'r' : '-';
1003 psd->str.u.cStr[8] = (pStatStruct->st_mode & S_IWOTH) ? 'w' : '-';
1004 psd->str.u.cStr[9] = (pStatStruct->st_mode & S_IXOTH) ? 'x' : '-';
1005 psd->str.u.cStr[10] = '\0';
1008 pPasswd = getpwuid(pStatStruct->st_uid);
1009 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1012 pGroup = getgrgid(pStatStruct->st_gid);
1013 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1016 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1019 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1027 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1034 /* VTable for UnixFolder's IShellFolder2 interface.
1036 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1037 UnixFolder_IShellFolder2_QueryInterface,
1038 UnixFolder_IShellFolder2_AddRef,
1039 UnixFolder_IShellFolder2_Release,
1040 UnixFolder_IShellFolder2_ParseDisplayName,
1041 UnixFolder_IShellFolder2_EnumObjects,
1042 UnixFolder_IShellFolder2_BindToObject,
1043 UnixFolder_IShellFolder2_BindToStorage,
1044 UnixFolder_IShellFolder2_CompareIDs,
1045 UnixFolder_IShellFolder2_CreateViewObject,
1046 UnixFolder_IShellFolder2_GetAttributesOf,
1047 UnixFolder_IShellFolder2_GetUIObjectOf,
1048 UnixFolder_IShellFolder2_GetDisplayNameOf,
1049 UnixFolder_IShellFolder2_SetNameOf,
1050 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1051 UnixFolder_IShellFolder2_EnumSearches,
1052 UnixFolder_IShellFolder2_GetDefaultColumn,
1053 UnixFolder_IShellFolder2_GetDefaultColumnState,
1054 UnixFolder_IShellFolder2_GetDetailsEx,
1055 UnixFolder_IShellFolder2_GetDetailsOf,
1056 UnixFolder_IShellFolder2_MapColumnToSCID
1059 static HRESULT WINAPI UnixFolder_IPersistFolder2_QueryInterface(IPersistFolder2* This, REFIID riid,
1062 return UnixFolder_IShellFolder2_QueryInterface(
1063 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This), riid, ppvObject);
1066 static ULONG WINAPI UnixFolder_IPersistFolder2_AddRef(IPersistFolder2* This)
1068 return UnixFolder_IShellFolder2_AddRef(
1069 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1072 static ULONG WINAPI UnixFolder_IPersistFolder2_Release(IPersistFolder2* This)
1074 return UnixFolder_IShellFolder2_Release(
1075 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1078 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetClassID(IPersistFolder2* This, CLSID* pClassID)
1084 static HRESULT WINAPI UnixFolder_IPersistFolder2_Initialize(IPersistFolder2* iface, LPCITEMIDLIST pidl)
1086 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1088 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1090 This->m_pidlLocation = ILClone(pidl);
1094 if (!UNIXFS_pidl_to_path(pidl, This))
1096 UNIXFS_build_subfolder_pidls(This);
1101 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetCurFolder(IPersistFolder2* iface, LPITEMIDLIST* ppidl)
1103 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1105 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1109 *ppidl = ILClone (This->m_pidlLocation);
1113 /* VTable for UnixFolder's IPersistFolder interface.
1115 static const IPersistFolder2Vtbl UnixFolder_IPersistFolder2_Vtbl = {
1116 UnixFolder_IPersistFolder2_QueryInterface,
1117 UnixFolder_IPersistFolder2_AddRef,
1118 UnixFolder_IPersistFolder2_Release,
1119 UnixFolder_IPersistFolder2_GetClassID,
1120 UnixFolder_IPersistFolder2_Initialize,
1121 UnixFolder_IPersistFolder2_GetCurFolder
1124 /******************************************************************************
1125 * Unix[Dos]Folder_Constructor [Internal]
1128 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1129 * riid [I] Interface asked for by the client.
1130 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1133 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1134 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1135 * compatible signature.
1137 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1138 * means that paths are converted from dos to unix and back at the interfaces.
1140 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, DWORD dwPathMode) {
1141 HRESULT hr = E_FAIL;
1142 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1145 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1146 pUnixFolder->lpIPersistFolder2Vtbl = &UnixFolder_IPersistFolder2_Vtbl;
1147 pUnixFolder->m_cRef = 0;
1148 pUnixFolder->m_pszPath = NULL;
1149 pUnixFolder->m_apidlSubDirs = NULL;
1150 pUnixFolder->m_cSubDirs = 0;
1151 pUnixFolder->m_dwPathMode = dwPathMode;
1153 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1154 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1155 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1160 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1161 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1162 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_UNIX);
1165 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1166 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1167 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_DOS);
1170 /******************************************************************************
1171 * UnixSubFolderIterator
1173 * Class whose heap based objects represent iterators over the sub-directories
1174 * of a given UnixFolder object.
1177 /* UnixSubFolderIterator object layout and typedef.
1179 typedef struct _UnixSubFolderIterator {
1180 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1182 UnixFolder *m_pUnixFolder;
1185 } UnixSubFolderIterator;
1187 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1188 TRACE("(iterator=%p)\n", iterator);
1190 UnixFolder_IShellFolder2_Release((IShellFolder2*)iterator->m_pUnixFolder);
1194 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1195 REFIID riid, void** ppv)
1197 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1199 if (!ppv) return E_INVALIDARG;
1201 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1205 return E_NOINTERFACE;
1208 IEnumIDList_AddRef(iface);
1212 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1214 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1216 TRACE("(iface=%p)\n", iface);
1218 return InterlockedIncrement(&This->m_cRef);
1221 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1223 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1226 TRACE("(iface=%p)\n", iface);
1228 cRef = InterlockedDecrement(&This->m_cRef);
1231 UnixSubFolderIterator_Destroy(This);
1236 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1237 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1239 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1242 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface, celt, rgelt, pceltFetched);
1244 for (i=0; (i < celt) && (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs); This->m_cIdx++) {
1245 LPITEMIDLIST pCurrent = This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx];
1246 if (UNIXFS_is_pidl_of_type(pCurrent, This->m_fFilter)) {
1247 rgelt[i] = ILClone(pCurrent);
1255 return i == celt ? S_OK : S_FALSE;
1258 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1260 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1263 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1265 for (i=0; i < celt; i++) {
1266 while (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs &&
1267 !UNIXFS_is_pidl_of_type(This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx], This->m_fFilter))
1274 if (This->m_cIdx > This->m_pUnixFolder->m_cSubDirs) {
1275 This->m_cIdx = This->m_pUnixFolder->m_cSubDirs;
1282 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1284 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1286 TRACE("(iface=%p)\n", iface);
1293 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1294 IEnumIDList** ppenum)
1300 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1302 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1303 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1304 UnixSubFolderIterator_IEnumIDList_AddRef,
1305 UnixSubFolderIterator_IEnumIDList_Release,
1306 UnixSubFolderIterator_IEnumIDList_Next,
1307 UnixSubFolderIterator_IEnumIDList_Skip,
1308 UnixSubFolderIterator_IEnumIDList_Reset,
1309 UnixSubFolderIterator_IEnumIDList_Clone
1312 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1313 UnixSubFolderIterator *iterator;
1315 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1317 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1318 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1319 iterator->m_cRef = 0;
1320 iterator->m_cIdx = 0;
1321 iterator->m_pUnixFolder = pUnixFolder;
1322 iterator->m_fFilter = fFilter;
1324 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1325 UnixFolder_IShellFolder2_AddRef((IShellFolder2*)pUnixFolder);
1327 return (IUnknown*)iterator;