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
29 #ifdef HAVE_SYS_STAT_H
30 # include <sys/stat.h>
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
49 #include "wine/debug.h"
51 #include "shell32_main.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(shell);
58 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
59 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
61 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
62 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
64 /* FileStruct reserves one byte for szNames, thus we don't have to
65 * alloc a byte for the terminating '\0' of 'name'. Two of the
66 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
67 * type field. One is for FileStruct's szNames field, to terminate
68 * the alternate DOS name, which we don't use here. And then there's
69 * the additional StatStruct.
71 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
72 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char)+sizeof(StatStruct))
73 #define NAME_LEN_FROM_LPSHITEMID(s) \
74 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char)-sizeof(StatStruct))
75 #define LPSTATSTRUCT_FROM_LPSHITEMID(s) \
76 (((s) && (((LPSHITEMID)s)->cb > SHITEMID_LEN_FROM_NAME_LEN(0))) ? \
77 ((StatStruct*)(((LPBYTE)s)+((LPSHITEMID)s)->cb-sizeof(StatStruct))) : \
80 #define PATHMODE_UNIX 0
81 #define PATHMODE_DOS 1
83 /* ShellFolder attributes of the root folder ('/') */
84 static DWORD dwRootAttr = 0;
86 /* This structure is appended to shell32's FileStruct type in IDLs to store unix
87 * filesystem specific informationen extracted with the stat system call.
89 typedef struct tagStatStruct {
96 /* UnixFolder object layout and typedef.
98 typedef struct _UnixFolder {
99 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
100 const IPersistFolder2Vtbl *lpIPersistFolder2Vtbl;
103 LPITEMIDLIST m_pidlLocation;
104 LPITEMIDLIST *m_apidlSubDirs;
109 /******************************************************************************
110 * UNIXFS_is_pidl_of_type [INTERNAL]
112 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
115 * pIDL [I] The ITEMIDLIST to be checked.
116 * fFilter [I] Shell condition flags, which specify the filter.
119 * TRUE, if pIDL is accepted by fFilter
122 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
123 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
124 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
125 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
129 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
130 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
134 /******************************************************************************
135 * UNIXFS_is_dos_device [Internal]
137 * Determines if a unix directory corresponds to any dos device.
140 * statPath [I] The stat struct of the directory, as returned by stat(2).
143 * TRUE, if statPath corresponds to any dos drive letter
146 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
147 struct stat statDrive;
150 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
152 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
153 if (!(dwDriveMap & 0x1)) continue;
154 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
155 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
156 HeapFree(GetProcessHeap(), 0, pszDrivePath);
157 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
164 /******************************************************************************
165 * UNIXFS_get_unix_path [Internal]
167 * Convert an absolute dos path to an absolute canonicalized unix path.
168 * Evaluate "/.", "/.." and symbolic links.
171 * pszDosPath [I] An absolute dos path
172 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
176 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
178 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
180 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
181 struct stat fileStat;
183 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
185 if (!pszDosPath || pszDosPath[1] != ':')
188 pszUnixPath = wine_get_unix_file_name(pszDosPath);
189 if (!pszUnixPath) return FALSE;
190 strcpy(szPath, pszUnixPath);
191 HeapFree(GetProcessHeap(), 0, pszUnixPath);
193 /* pCanonicalTail always points to the end of the canonical path constructed
194 * thus far. pPathTail points to the still to be processed part of the input
195 * path. pElement points to the path element currently investigated.
197 *pszCanonicalPath = '\0';
198 pCanonicalTail = pszCanonicalPath;
205 pElement = pPathTail;
206 pPathTail = strchr(pPathTail+1, '/');
207 if (!pPathTail) /* Last path element may not be terminated by '/'. */
208 pPathTail = pElement + strlen(pElement);
209 /* Temporarily terminate the current path element. Will be restored later. */
213 /* Skip "/." path elements */
214 if (!strcmp("/.", pElement)) {
219 /* Remove last element in canonical path for "/.." elements, then skip. */
220 if (!strcmp("/..", pElement)) {
221 char *pTemp = strrchr(pszCanonicalPath, '/');
223 pCanonicalTail = pTemp;
224 *pCanonicalTail = '\0';
229 /* lstat returns zero on success. */
230 if (lstat(szPath, &fileStat))
233 if (S_ISLNK(fileStat.st_mode)) {
234 char szSymlink[FILENAME_MAX];
235 int cLinkLen, cTailLen;
237 /* Avoid infinite loop for recursive links. */
241 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
246 cTailLen = strlen(pPathTail);
248 if (szSymlink[0] == '/') {
249 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
250 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
253 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
254 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
255 *pszCanonicalPath = '\0';
256 pCanonicalTail = pszCanonicalPath;
259 /* Relative link. Expand into szPath and continue. */
260 char szTemp[FILENAME_MAX];
261 int cTailLen = strlen(pPathTail);
263 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
266 memcpy(szTemp, pPathTail, cTailLen + 1);
267 memcpy(pElement + 1, szSymlink, cLinkLen);
268 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
269 pPathTail = pElement;
272 /* Regular directory or file. Copy to canonical path */
273 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
276 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
277 pCanonicalTail += pPathTail - pElement;
280 } while (pPathTail[0] == '/' && pPathTail[1]); /* Also handles paths terminated by '/' */
282 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
287 /******************************************************************************
288 * UNIXFS_build_shitemid [Internal]
290 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
291 * buffer 'pIDL'. Decorates the SHITEMID with information from a stat system call.
294 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
295 * bParentIsFS [I] Set, if the parent of the last path component is within the wine filesystem.
296 * pIDL [O] SHITEMID will be constructed here.
299 * Success: A pointer to the terminating '\0' character of path.
303 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
304 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
307 static char* UNIXFS_build_shitemid(char *pszUnixPath, BOOL bParentIsFS, void *pIDL) {
311 struct stat fileStat;
312 StatStruct *pStatStruct;
316 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
318 /* Compute the SHITEMID's length and wipe it. */
319 pszComponent = strrchr(pszUnixPath, '/') + 1;
320 cComponentLen = strlen(pszComponent);
321 memset(pIDL, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen));
322 ((LPSHITEMID)pIDL)->cb = SHITEMID_LEN_FROM_NAME_LEN(cComponentLen) ;
324 /* We are only interested in regular files and directories. */
325 if (stat(pszUnixPath, &fileStat)) return NULL;
326 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
328 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pIDL);
329 pStatStruct->st_mode = fileStat.st_mode;
330 pStatStruct->st_uid = fileStat.st_uid;
331 pStatStruct->st_gid = fileStat.st_gid;
332 pStatStruct->sfAttr = S_ISDIR(fileStat.st_mode) ? (SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR) : 0;
333 if (bParentIsFS || UNIXFS_is_dos_device(&fileStat)) pStatStruct->sfAttr |= SFGAO_FILESYSTEM;
335 /* Set shell32's standard SHITEMID data fields. */
336 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
337 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
338 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
339 RtlSecondsSince1970ToTime( fileStat.st_mtime, &time );
340 fileTime.dwLowDateTime = time.u.LowPart;
341 fileTime.dwHighDateTime = time.u.HighPart;
342 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
343 pIDLData->u.file.uFileAttribs = 0;
344 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
345 if (pszComponent[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
346 memcpy(pIDLData->u.file.szNames, pszComponent, cComponentLen);
348 return pszComponent + cComponentLen;
351 /******************************************************************************
352 * UNIXFS_path_to_pidl [Internal]
355 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
356 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
357 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
361 * Failure: FALSE, invalid params or out of memory
364 * pUnixFolder also carries the information if the path is expected to be unix or dos.
366 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
368 int cSubDirs, cPidlLen, cPathLen;
369 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
370 BOOL bParentIsFS = dwRootAttr & SFGAO_FILESYSTEM;
372 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
377 cPathLen = lstrlenW(path);
379 /* Build an absolute path and let pNextPathElement point to the interesting
380 * relative sub-path. We need the absolute path to call 'stat', but the pidl
381 * will only contain the relative part.
383 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
385 /* Absolute dos path. Convert to unix */
386 if (!UNIXFS_get_unix_path(path, szCompletePath))
388 pNextPathElement = szCompletePath + 1;
390 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
392 /* Absolute unix path. Just convert to ANSI. */
393 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
394 pNextPathElement = szCompletePath + 1;
398 /* Relative dos or unix path. Concat with this folder's path */
399 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
400 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
401 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath + cBasePathLen,
402 FILENAME_MAX - cBasePathLen, NULL, NULL);
403 pNextPathElement = szCompletePath + cBasePathLen;
405 /* If in dos mode, replace '\' with '/' */
406 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
407 char *pBackslash = strchr(pNextPathElement, '\\');
410 pBackslash = strchr(pBackslash, '\\');
415 /* At this point, we have an absolute unix path in szCompletePath. */
416 TRACE("complete path: %s\n", szCompletePath);
418 /* Count the number of sub-directories in the path */
419 cSubDirs = 1; /* Path may not be terminated with '/', thus start with 1 */
420 pSlash = strchr(pNextPathElement, '/');
421 while (pSlash && pSlash[1]) {
423 pSlash = strchr(pSlash+1, '/');
426 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
427 * characters, which are not stored in the ITEMIDLIST. */
428 cPidlLen = strlen(pNextPathElement) - cSubDirs + 1 + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
429 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
430 if (!pidl) return FALSE;
432 /* Concatenate the SHITEMIDs of the sub-directories. */
433 while (*pNextPathElement) {
434 pSlash = strchr(pNextPathElement, '/');
435 if (pSlash) *pSlash = '\0';
436 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, bParentIsFS, pidl);
437 if (pSlash) *pSlash = '/';
439 if (!pNextPathElement) {
443 if (!bParentIsFS && (LPSTATSTRUCT_FROM_LPSHITEMID(pidl)->sfAttr & SFGAO_FILESYSTEM))
445 pidl = ILGetNext(pidl);
447 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
449 if ((int)pidl-(int)*ppidl+sizeof(USHORT) > cPidlLen) /* We've corrupted the heap :( */
450 ERR("Computed length of pidl to small. Please report.\n");
455 /******************************************************************************
456 * UNIXFS_pidl_to_path [Internal]
458 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
461 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
462 * path [O] The corresponding unix path as a zero terminated ascii string
466 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
468 static BOOL UNIXFS_pidl_to_path(LPCITEMIDLIST pidl, UnixFolder *pUnixFolder) {
469 LPCITEMIDLIST current = pidl, root;
471 char *pNextDir, szBasePath[FILENAME_MAX] = "/";
473 TRACE("(pidl=%p, pUnixFolder=%p)\n", pidl, pUnixFolder);
476 pUnixFolder->m_pszPath = NULL;
478 /* Find the UnixFolderClass root */
479 while (current->mkid.cb) {
480 if (_ILIsDrive(current) || /* The dos drive, which maps to '/' */
481 (_ILIsSpecialFolder(current) &&
482 (IsEqualIID(&CLSID_UnixFolder, _ILGetGUIDPointer(current)) ||
483 IsEqualIID(&CLSID_UnixDosFolder, _ILGetGUIDPointer(current)))))
487 current = ILGetNext(current);
490 if (current && current->mkid.cb) {
491 root = current = ILGetNext(current);
492 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
493 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
494 /* Path rooted at Desktop */
495 WCHAR wszDesktopPath[MAX_PATH];
496 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOP, FALSE)))
498 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
500 dwPathLen = strlen(szBasePath) + 1;
503 ERR("Unknown pidl type!\n");
508 /* Determine the path's length bytes */
509 while (current && current->mkid.cb) {
510 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
511 current = ILGetNext(current);
515 pUnixFolder->m_pszPath = pNextDir = SHAlloc(dwPathLen);
516 if (!pUnixFolder->m_pszPath) {
517 WARN("SHAlloc failed!\n");
521 strcpy(pNextDir, szBasePath);
522 pNextDir += strlen(szBasePath);
523 while (current && current->mkid.cb) {
524 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
525 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
527 current = ILGetNext(current);
531 TRACE("--> %s\n", pUnixFolder->m_pszPath);
535 /******************************************************************************
536 * UNIXFS_build_subfolder_pidls [Internal]
538 * Builds an array of subfolder PIDLs relative to a unix directory
541 * path [I] Name of a unix directory as a zero terminated ascii string
542 * apidl [O] The array of PIDLs
543 * pCount [O] Size of apidl
547 * Failure: FALSE, path is not a valid unix directory or out of memory
550 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
551 * to release each PIDL as well as the array itself with SHFree.
553 static BOOL UNIXFS_build_subfolder_pidls(UnixFolder *pUnixFolder)
555 struct dirent *pDirEntry;
556 struct stat fileStat;
558 DWORD cDirEntries, i;
561 BOOL bParentIsFS = dwRootAttr & SFGAO_FILESYSTEM;
563 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
565 pUnixFolder->m_apidlSubDirs = NULL;
566 pUnixFolder->m_cSubDirs = 0;
568 if (pUnixFolder->m_pidlLocation) {
569 StatStruct *statStruct =
570 LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(pUnixFolder->m_pidlLocation));
571 if (statStruct) bParentIsFS = statStruct->sfAttr & SFGAO_FILESYSTEM;
574 dir = opendir(pUnixFolder->m_pszPath);
576 WARN("Failed to open directory '%s'.\n", pUnixFolder->m_pszPath);
580 /* Allocate space for fully qualified paths */
581 pszFQPath = SHAlloc(strlen(pUnixFolder->m_pszPath) + PATH_MAX);
583 WARN("SHAlloc failed!\n");
587 /* Count number of directory entries. */
588 for (cDirEntries = 0, pDirEntry = readdir(dir); pDirEntry; pDirEntry = readdir(dir)) {
589 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
590 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
591 if (!stat(pszFQPath, &fileStat) && (S_ISDIR(fileStat.st_mode) || S_ISREG(fileStat.st_mode))) cDirEntries++;
594 /* If there are no entries, we are done. */
595 if (cDirEntries == 0) {
601 /* Allocate the array of PIDLs */
602 pUnixFolder->m_apidlSubDirs = SHAlloc(cDirEntries * sizeof(LPITEMIDLIST));
603 if (!pUnixFolder->m_apidlSubDirs) {
604 WARN("SHAlloc failed!\n");
608 /* Allocate and initialize one SHITEMID per sub-directory. */
609 for (rewinddir(dir), pDirEntry = readdir(dir), i = 0; pDirEntry; pDirEntry = readdir(dir)) {
612 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
614 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
616 sLen = strlen(pDirEntry->d_name);
617 pid = (LPSHITEMID)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen)+sizeof(USHORT));
619 WARN("SHAlloc failed!\n");
622 if (!UNIXFS_build_shitemid(pszFQPath, bParentIsFS, pid)) {
626 memset(((PBYTE)pid)+pid->cb, 0, sizeof(USHORT));
628 pUnixFolder->m_apidlSubDirs[i++] = (LPITEMIDLIST)pid;
631 pUnixFolder->m_cSubDirs = i;
638 /******************************************************************************
641 * Class whose heap based instances represent unix filesystem directories.
644 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
647 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
649 if (pUnixFolder->m_apidlSubDirs)
650 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
651 SHFree(pUnixFolder->m_apidlSubDirs[i]);
652 SHFree(pUnixFolder->m_apidlSubDirs);
653 SHFree(pUnixFolder->m_pszPath);
654 ILFree(pUnixFolder->m_pidlLocation);
658 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
661 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
663 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
665 if (!ppv) return E_INVALIDARG;
667 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
668 IsEqualIID(&IID_IShellFolder2, riid))
670 *ppv = &This->lpIShellFolder2Vtbl;
671 } else if (IsEqualIID(&IID_IPersistFolder2, riid) || IsEqualIID(&IID_IPersistFolder, riid) ||
672 IsEqualIID(&IID_IPersist, riid))
674 *ppv = &This->lpIPersistFolder2Vtbl;
677 return E_NOINTERFACE;
680 IUnknown_AddRef((IUnknown*)*ppv);
684 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
685 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
687 TRACE("(iface=%p)\n", iface);
689 return InterlockedIncrement(&This->m_cRef);
692 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
693 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
696 TRACE("(iface=%p)\n", iface);
698 cRef = InterlockedDecrement(&This->m_cRef);
701 UnixFolder_Destroy(This);
706 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
707 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
708 ULONG* pdwAttributes)
710 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
713 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
714 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
715 pchEaten, ppidl, pdwAttributes);
717 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
718 if (result && pdwAttributes && *pdwAttributes)
720 /* need to traverse to the last element for the attribute */
721 LPCITEMIDLIST pidl, last_pidl;
722 pidl = last_pidl = *ppidl;
723 while(pidl && pidl->mkid.cb)
726 pidl = ILGetNext(pidl);
728 SHELL32_GetItemAttributes((IShellFolder*)iface, last_pidl, pdwAttributes);
731 if (!result) TRACE("FAILED!\n");
732 return result ? S_OK : E_FAIL;
735 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter);
737 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
738 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
740 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
741 IUnknown *newIterator;
744 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
745 iface, hwndOwner, grfFlags, ppEnumIDList);
747 if (This->m_cSubDirs == -1)
748 UNIXFS_build_subfolder_pidls(This);
750 newIterator = UnixSubFolderIterator_Construct(This, grfFlags);
751 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
752 IUnknown_Release(newIterator);
757 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
758 LPBC pbcReserved, REFIID riid, void** ppvOut)
760 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
761 IPersistFolder2 *persistFolder;
762 LPITEMIDLIST pidlSubFolder;
765 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
766 iface, pidl, pbcReserved, riid, ppvOut);
768 if (!pidl || !pidl->mkid.cb)
771 if (This->m_dwPathMode == PATHMODE_DOS)
772 hr = UnixDosFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
774 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
776 if (!SUCCEEDED(hr)) return hr;
777 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
779 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
780 IPersistFolder2_Initialize(persistFolder, pidlSubFolder);
781 IPersistFolder2_Release(persistFolder);
782 ILFree(pidlSubFolder);
787 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
788 LPBC pbcReserved, REFIID riid, void** ppvObj)
794 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
795 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
797 BOOL isEmpty1, isEmpty2;
799 LPITEMIDLIST firstpidl;
803 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
805 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
806 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
808 if (isEmpty1 && isEmpty2)
809 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
811 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
813 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
815 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
816 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
817 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
818 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
820 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
821 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
822 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
824 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
825 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
827 if (pidl1->mkid.cb < pidl2->mkid.cb)
828 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
829 else if (pidl1->mkid.cb > pidl2->mkid.cb)
830 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
832 firstpidl = ILCloneFirst(pidl1);
833 pidl1 = ILGetNext(pidl1);
834 pidl2 = ILGetNext(pidl2);
836 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
838 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
839 IShellFolder2_Release(psf);
846 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
847 REFIID riid, void** ppv)
849 HRESULT hr = E_INVALIDARG;
851 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
853 if (!ppv) return E_INVALIDARG;
856 if (IsEqualIID(&IID_IShellView, riid)) {
857 LPSHELLVIEW pShellView;
859 pShellView = IShellView_Constructor((IShellFolder*)iface);
861 hr = IShellView_QueryInterface(pShellView, riid, ppv);
862 IShellView_Release(pShellView);
869 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
870 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
873 SFGAOF flags= ~(SFGAOF)0;
875 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p) semi-stub\n", iface, cidl, apidl, rgfInOut);
877 for (i=0; i<cidl; i++)
878 flags &= LPSTATSTRUCT_FROM_LPSHITEMID(apidl[i])->sfAttr;
880 *rgfInOut = *rgfInOut & flags;
885 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
886 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
888 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
890 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
891 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
893 if (IsEqualIID(&IID_IContextMenu, riid)) {
894 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
896 } else if (IsEqualIID(&IID_IDataObject, riid)) {
897 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
899 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
901 if (cidl != 1) return E_FAIL;
902 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
903 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
906 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
908 if (cidl != 1) return E_FAIL;
909 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
910 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
913 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
914 FIXME("IDropTarget\n");
916 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
917 FIXME("IShellLinkW\n");
919 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
920 FIXME("IShellLinkA\n");
923 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
924 return E_NOINTERFACE;
928 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
929 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
931 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
934 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
936 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
937 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
939 if (!pidl->mkid.cb) {
940 lpName->uType = STRRET_CSTR;
941 strcpy(lpName->u.cStr, This->m_pszPath);
942 if (This->m_dwPathMode == PATHMODE_DOS) {
944 GetFullPathNameA(lpName->u.cStr, MAX_PATH, path, NULL);
945 PathRemoveBackslashA(path);
946 strcpy(lpName->u.cStr, path);
949 IShellFolder *pSubFolder;
952 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
953 if (!SUCCEEDED(hr)) return hr;
955 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
956 IShellFolder_Release(pSubFolder);
959 char *pszFileName = _ILGetTextPointer(pidl);
960 lpName->uType = STRRET_CSTR;
961 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
964 TRACE("--> %s\n", lpName->u.cStr);
969 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* This, HWND hwnd,
970 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
976 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
977 IEnumExtraSearch **ppEnum)
983 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
984 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
990 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
991 UINT iColumn, SHCOLSTATEF *pcsFlags)
997 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1004 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1005 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1011 #define SHELLVIEWCOLUMNS 6
1013 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1014 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1016 HRESULT hr = E_FAIL;
1017 struct passwd *pPasswd;
1018 struct group *pGroup;
1019 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1020 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1021 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1022 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1023 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1024 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 8},
1025 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
1028 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1030 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1031 return E_INVALIDARG;
1034 psd->fmt = SFHeader[iColumn].fmt;
1035 psd->cxChar = SFHeader[iColumn].cxChar;
1036 psd->str.uType = STRRET_CSTR;
1037 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1040 StatStruct *pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pidl);
1041 psd->str.u.cStr[0] = '\0';
1042 psd->str.uType = STRRET_CSTR;
1045 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1048 psd->str.u.cStr[0] = S_ISDIR(pStatStruct->st_mode) ? 'd' : '-';
1049 psd->str.u.cStr[1] = (pStatStruct->st_mode & S_IRUSR) ? 'r' : '-';
1050 psd->str.u.cStr[2] = (pStatStruct->st_mode & S_IWUSR) ? 'w' : '-';
1051 psd->str.u.cStr[3] = (pStatStruct->st_mode & S_IXUSR) ? 'x' : '-';
1052 psd->str.u.cStr[4] = (pStatStruct->st_mode & S_IRGRP) ? 'r' : '-';
1053 psd->str.u.cStr[5] = (pStatStruct->st_mode & S_IWGRP) ? 'w' : '-';
1054 psd->str.u.cStr[6] = (pStatStruct->st_mode & S_IXGRP) ? 'x' : '-';
1055 psd->str.u.cStr[7] = (pStatStruct->st_mode & S_IROTH) ? 'r' : '-';
1056 psd->str.u.cStr[8] = (pStatStruct->st_mode & S_IWOTH) ? 'w' : '-';
1057 psd->str.u.cStr[9] = (pStatStruct->st_mode & S_IXOTH) ? 'x' : '-';
1058 psd->str.u.cStr[10] = '\0';
1061 pPasswd = getpwuid(pStatStruct->st_uid);
1062 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1065 pGroup = getgrgid(pStatStruct->st_gid);
1066 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1069 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1072 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1080 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1087 /* VTable for UnixFolder's IShellFolder2 interface.
1089 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1090 UnixFolder_IShellFolder2_QueryInterface,
1091 UnixFolder_IShellFolder2_AddRef,
1092 UnixFolder_IShellFolder2_Release,
1093 UnixFolder_IShellFolder2_ParseDisplayName,
1094 UnixFolder_IShellFolder2_EnumObjects,
1095 UnixFolder_IShellFolder2_BindToObject,
1096 UnixFolder_IShellFolder2_BindToStorage,
1097 UnixFolder_IShellFolder2_CompareIDs,
1098 UnixFolder_IShellFolder2_CreateViewObject,
1099 UnixFolder_IShellFolder2_GetAttributesOf,
1100 UnixFolder_IShellFolder2_GetUIObjectOf,
1101 UnixFolder_IShellFolder2_GetDisplayNameOf,
1102 UnixFolder_IShellFolder2_SetNameOf,
1103 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1104 UnixFolder_IShellFolder2_EnumSearches,
1105 UnixFolder_IShellFolder2_GetDefaultColumn,
1106 UnixFolder_IShellFolder2_GetDefaultColumnState,
1107 UnixFolder_IShellFolder2_GetDetailsEx,
1108 UnixFolder_IShellFolder2_GetDetailsOf,
1109 UnixFolder_IShellFolder2_MapColumnToSCID
1112 static HRESULT WINAPI UnixFolder_IPersistFolder2_QueryInterface(IPersistFolder2* This, REFIID riid,
1115 return UnixFolder_IShellFolder2_QueryInterface(
1116 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This), riid, ppvObject);
1119 static ULONG WINAPI UnixFolder_IPersistFolder2_AddRef(IPersistFolder2* This)
1121 return UnixFolder_IShellFolder2_AddRef(
1122 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1125 static ULONG WINAPI UnixFolder_IPersistFolder2_Release(IPersistFolder2* This)
1127 return UnixFolder_IShellFolder2_Release(
1128 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1131 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetClassID(IPersistFolder2* This, CLSID* pClassID)
1137 static HRESULT WINAPI UnixFolder_IPersistFolder2_Initialize(IPersistFolder2* iface, LPCITEMIDLIST pidl)
1139 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1141 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1143 This->m_pidlLocation = ILClone(pidl);
1147 if (!UNIXFS_pidl_to_path(pidl, This))
1150 /* Attributes of a shell namespace extension's root folder (in this case the '/' folder)
1151 * are not queried for with ShellFolder's GetAttributesOf, but looked up in the registry
1152 * (see MSDN: Creating a Shell Namespace Extension > Implementing the Basic Folder Object
1153 * Interface > Registering an Extension). When they change, we have to write them there.
1155 if (!strcmp(This->m_pszPath, "/")) {
1156 DWORD dwTempAttr = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
1157 struct stat statRoot;
1159 if (stat(This->m_pszPath, &statRoot)) return E_FAIL;
1160 if (UNIXFS_is_dos_device(&statRoot)) dwTempAttr |= SFGAO_FILESYSTEM;
1162 if (dwRootAttr != dwTempAttr) {
1164 static const WCHAR wszFolderAttrValue[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
1165 static const WCHAR wszFolderAttrKey[] = { 'C','L','S','I','D','\\',
1166 '{','9','D','2','0','A','A','E','8','-','0','6','2','5','-','4','4','B','0','-',
1167 '9','C','A','7','-','7','1','8','8','9','C','2','2','5','4','D','9','}','\\',
1168 'S','h','e','l','l','F','o','l','d','e','r',0 };
1170 dwRootAttr = dwTempAttr;
1171 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFolderAttrKey, 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {
1172 RegSetValueExW(hKey, wszFolderAttrValue, 0, REG_DWORD, (BYTE*)&dwTempAttr, sizeof(DWORD));
1181 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetCurFolder(IPersistFolder2* iface, LPITEMIDLIST* ppidl)
1183 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1185 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1189 *ppidl = ILClone (This->m_pidlLocation);
1193 /* VTable for UnixFolder's IPersistFolder interface.
1195 static const IPersistFolder2Vtbl UnixFolder_IPersistFolder2_Vtbl = {
1196 UnixFolder_IPersistFolder2_QueryInterface,
1197 UnixFolder_IPersistFolder2_AddRef,
1198 UnixFolder_IPersistFolder2_Release,
1199 UnixFolder_IPersistFolder2_GetClassID,
1200 UnixFolder_IPersistFolder2_Initialize,
1201 UnixFolder_IPersistFolder2_GetCurFolder
1204 /******************************************************************************
1205 * Unix[Dos]Folder_Constructor [Internal]
1208 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1209 * riid [I] Interface asked for by the client.
1210 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1213 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1214 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1215 * compatible signature.
1217 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1218 * means that paths are converted from dos to unix and back at the interfaces.
1220 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, DWORD dwPathMode) {
1221 HRESULT hr = E_FAIL;
1222 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1225 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1226 pUnixFolder->lpIPersistFolder2Vtbl = &UnixFolder_IPersistFolder2_Vtbl;
1227 pUnixFolder->m_cRef = 0;
1228 pUnixFolder->m_pszPath = NULL;
1229 pUnixFolder->m_apidlSubDirs = NULL;
1230 pUnixFolder->m_cSubDirs = -1;
1231 pUnixFolder->m_dwPathMode = dwPathMode;
1233 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1234 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1235 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1240 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1241 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1242 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_UNIX);
1245 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1246 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1247 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_DOS);
1250 /******************************************************************************
1251 * UnixSubFolderIterator
1253 * Class whose heap based objects represent iterators over the sub-directories
1254 * of a given UnixFolder object.
1257 /* UnixSubFolderIterator object layout and typedef.
1259 typedef struct _UnixSubFolderIterator {
1260 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1262 UnixFolder *m_pUnixFolder;
1265 } UnixSubFolderIterator;
1267 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1268 TRACE("(iterator=%p)\n", iterator);
1270 UnixFolder_IShellFolder2_Release((IShellFolder2*)iterator->m_pUnixFolder);
1274 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1275 REFIID riid, void** ppv)
1277 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1279 if (!ppv) return E_INVALIDARG;
1281 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1285 return E_NOINTERFACE;
1288 IEnumIDList_AddRef(iface);
1292 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1294 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1296 TRACE("(iface=%p)\n", iface);
1298 return InterlockedIncrement(&This->m_cRef);
1301 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1303 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1306 TRACE("(iface=%p)\n", iface);
1308 cRef = InterlockedDecrement(&This->m_cRef);
1311 UnixSubFolderIterator_Destroy(This);
1316 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1317 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1319 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1322 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface, celt, rgelt, pceltFetched);
1324 for (i=0; (i < celt) && (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs); This->m_cIdx++) {
1325 LPITEMIDLIST pCurrent = This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx];
1326 if (UNIXFS_is_pidl_of_type(pCurrent, This->m_fFilter)) {
1327 rgelt[i] = ILClone(pCurrent);
1335 return i == celt ? S_OK : S_FALSE;
1338 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1340 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1343 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1345 for (i=0; i < celt; i++) {
1346 while (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs &&
1347 !UNIXFS_is_pidl_of_type(This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx], This->m_fFilter))
1354 if (This->m_cIdx > This->m_pUnixFolder->m_cSubDirs) {
1355 This->m_cIdx = This->m_pUnixFolder->m_cSubDirs;
1362 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1364 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1366 TRACE("(iface=%p)\n", iface);
1373 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1374 IEnumIDList** ppenum)
1380 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1382 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1383 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1384 UnixSubFolderIterator_IEnumIDList_AddRef,
1385 UnixSubFolderIterator_IEnumIDList_Release,
1386 UnixSubFolderIterator_IEnumIDList_Next,
1387 UnixSubFolderIterator_IEnumIDList_Skip,
1388 UnixSubFolderIterator_IEnumIDList_Reset,
1389 UnixSubFolderIterator_IEnumIDList_Clone
1392 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1393 UnixSubFolderIterator *iterator;
1395 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1397 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1398 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1399 iterator->m_cRef = 0;
1400 iterator->m_cIdx = 0;
1401 iterator->m_pUnixFolder = pUnixFolder;
1402 iterator->m_fFilter = fFilter;
1404 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1405 UnixFolder_IShellFolder2_AddRef((IShellFolder2*)pUnixFolder);
1407 return (IUnknown*)iterator;