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_rooted_at_desktop [Internal]
112 * Checks if the unixfs namespace extension is rooted at desktop level.
115 * TRUE, if unixfs is rooted at desktop level
118 BOOL UNIXFS_is_rooted_at_desktop(void) {
120 WCHAR *pwszCLSID_UnixDosFolder, wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
121 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
122 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
123 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
124 'N','a','m','e','S','p','a','c','e','\\',0 };
126 if (FAILED(StringFromCLSID(&CLSID_UnixDosFolder, &pwszCLSID_UnixDosFolder)))
129 lstrcatW(wszRootedAtDesktop, pwszCLSID_UnixDosFolder);
130 CoTaskMemFree(pwszCLSID_UnixDosFolder);
132 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
139 /******************************************************************************
140 * UNIXFS_is_pidl_of_type [INTERNAL]
142 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
145 * pIDL [I] The ITEMIDLIST to be checked.
146 * fFilter [I] Shell condition flags, which specify the filter.
149 * TRUE, if pIDL is accepted by fFilter
152 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
153 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
154 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
155 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
159 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
160 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
164 /******************************************************************************
165 * UNIXFS_is_dos_device [Internal]
167 * Determines if a unix directory corresponds to any dos device.
170 * statPath [I] The stat struct of the directory, as returned by stat(2).
173 * TRUE, if statPath corresponds to any dos drive letter
176 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
177 struct stat statDrive;
180 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
182 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
183 if (!(dwDriveMap & 0x1)) continue;
184 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
185 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
186 HeapFree(GetProcessHeap(), 0, pszDrivePath);
187 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
194 /******************************************************************************
195 * UNIXFS_get_unix_path [Internal]
197 * Convert an absolute dos path to an absolute canonicalized unix path.
198 * Evaluate "/.", "/.." and symbolic links.
201 * pszDosPath [I] An absolute dos path
202 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
206 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
208 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
210 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
211 struct stat fileStat;
213 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
215 if (!pszDosPath || pszDosPath[1] != ':')
218 pszUnixPath = wine_get_unix_file_name(pszDosPath);
219 if (!pszUnixPath) return FALSE;
220 strcpy(szPath, pszUnixPath);
221 HeapFree(GetProcessHeap(), 0, pszUnixPath);
223 /* pCanonicalTail always points to the end of the canonical path constructed
224 * thus far. pPathTail points to the still to be processed part of the input
225 * path. pElement points to the path element currently investigated.
227 *pszCanonicalPath = '\0';
228 pCanonicalTail = pszCanonicalPath;
235 pElement = pPathTail;
236 pPathTail = strchr(pPathTail+1, '/');
237 if (!pPathTail) /* Last path element may not be terminated by '/'. */
238 pPathTail = pElement + strlen(pElement);
239 /* Temporarily terminate the current path element. Will be restored later. */
243 /* Skip "/." path elements */
244 if (!strcmp("/.", pElement)) {
249 /* Remove last element in canonical path for "/.." elements, then skip. */
250 if (!strcmp("/..", pElement)) {
251 char *pTemp = strrchr(pszCanonicalPath, '/');
253 pCanonicalTail = pTemp;
254 *pCanonicalTail = '\0';
259 /* lstat returns zero on success. */
260 if (lstat(szPath, &fileStat))
263 if (S_ISLNK(fileStat.st_mode)) {
264 char szSymlink[FILENAME_MAX];
265 int cLinkLen, cTailLen;
267 /* Avoid infinite loop for recursive links. */
271 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
276 cTailLen = strlen(pPathTail);
278 if (szSymlink[0] == '/') {
279 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
280 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
283 /* Avoid double slashes. */
284 if (szSymlink[cLinkLen-1] == '/' && pPathTail[0] == '/') {
285 szSymlink[cLinkLen-1] = '\0';
289 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
290 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
291 *pszCanonicalPath = '\0';
292 pCanonicalTail = pszCanonicalPath;
295 /* Relative link. Expand into szPath and continue. */
296 char szTemp[FILENAME_MAX];
297 int cTailLen = strlen(pPathTail);
299 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
302 memcpy(szTemp, pPathTail, cTailLen + 1);
303 memcpy(pElement + 1, szSymlink, cLinkLen);
304 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
305 pPathTail = pElement;
308 /* Regular directory or file. Copy to canonical path */
309 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
312 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
313 pCanonicalTail += pPathTail - pElement;
316 } while (pPathTail[0] == '/');
318 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
323 /******************************************************************************
324 * UNIXFS_build_shitemid [Internal]
326 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
327 * buffer 'pIDL'. Decorates the SHITEMID with information from a stat system call.
330 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
331 * bParentIsFS [I] Set, if the parent of the last path component is within the wine filesystem.
332 * pIDL [O] SHITEMID will be constructed here.
335 * Success: A pointer to the terminating '\0' character of path.
339 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
340 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
343 static char* UNIXFS_build_shitemid(char *pszUnixPath, BOOL bParentIsFS, void *pIDL) {
347 struct stat fileStat;
348 StatStruct *pStatStruct;
352 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
354 /* Compute the SHITEMID's length and wipe it. */
355 pszComponent = strrchr(pszUnixPath, '/') + 1;
356 cComponentLen = strlen(pszComponent);
357 memset(pIDL, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen));
358 ((LPSHITEMID)pIDL)->cb = SHITEMID_LEN_FROM_NAME_LEN(cComponentLen) ;
360 /* We are only interested in regular files and directories. */
361 if (stat(pszUnixPath, &fileStat)) return NULL;
362 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
364 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pIDL);
365 pStatStruct->st_mode = fileStat.st_mode;
366 pStatStruct->st_uid = fileStat.st_uid;
367 pStatStruct->st_gid = fileStat.st_gid;
368 pStatStruct->sfAttr = S_ISDIR(fileStat.st_mode) ? (SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR) : 0;
369 if (bParentIsFS || UNIXFS_is_dos_device(&fileStat)) pStatStruct->sfAttr |= SFGAO_FILESYSTEM;
371 /* Set shell32's standard SHITEMID data fields. */
372 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
373 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
374 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
375 RtlSecondsSince1970ToTime( fileStat.st_mtime, &time );
376 fileTime.dwLowDateTime = time.u.LowPart;
377 fileTime.dwHighDateTime = time.u.HighPart;
378 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
379 pIDLData->u.file.uFileAttribs = 0;
380 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
381 if (pszComponent[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
382 memcpy(pIDLData->u.file.szNames, pszComponent, cComponentLen);
384 return pszComponent + cComponentLen;
387 /******************************************************************************
388 * UNIXFS_path_to_pidl [Internal]
391 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
392 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
393 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
397 * Failure: FALSE, invalid params or out of memory
400 * pUnixFolder also carries the information if the path is expected to be unix or dos.
402 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
404 int cSubDirs, cPidlLen, cPathLen;
405 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
406 BOOL bParentIsFS = dwRootAttr & SFGAO_FILESYSTEM;
408 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
413 /* Build an absolute path and let pNextPathElement point to the interesting
414 * relative sub-path. We need the absolute path to call 'stat', but the pidl
415 * will only contain the relative part.
417 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
419 /* Absolute dos path. Convert to unix */
420 if (!UNIXFS_get_unix_path(path, szCompletePath))
422 pNextPathElement = szCompletePath;
424 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
426 /* Absolute unix path. Just convert to ANSI. */
427 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
428 pNextPathElement = szCompletePath;
432 /* Relative dos or unix path. Concat with this folder's path */
433 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
434 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
435 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath + cBasePathLen,
436 FILENAME_MAX - cBasePathLen, NULL, NULL);
437 pNextPathElement = szCompletePath + cBasePathLen - 1;
439 /* If in dos mode, replace '\' with '/' */
440 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
441 char *pBackslash = strchr(pNextPathElement, '\\');
444 pBackslash = strchr(pBackslash, '\\');
449 /* Special case for the root folder. */
450 if (!strcmp(szCompletePath, "/")) {
451 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(sizeof(USHORT));
452 if (!pidl) return FALSE;
453 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
457 /* Remove trailing slash, if present */
458 cPathLen = strlen(szCompletePath);
459 if (szCompletePath[cPathLen-1] == '/')
460 szCompletePath[cPathLen-1] = '\0';
462 if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
463 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
467 /* At this point, we have an absolute unix path in szCompletePath
468 * and the relative portion of it in pNextPathElement. Both starting with '/'
469 * and _not_ terminated by a '/'. */
470 TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
472 /* Count the number of sub-directories in the path */
474 pSlash = pNextPathElement;
477 pSlash = strchr(pSlash+1, '/');
480 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
481 * characters, which are not stored in the ITEMIDLIST. */
482 cPidlLen = strlen(pNextPathElement) - cSubDirs + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
483 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
484 if (!pidl) return FALSE;
486 /* Concatenate the SHITEMIDs of the sub-directories. */
487 while (*pNextPathElement) {
488 pSlash = strchr(pNextPathElement+1, '/');
489 if (pSlash) *pSlash = '\0';
490 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, bParentIsFS, pidl);
491 if (pSlash) *pSlash = '/';
493 if (!pNextPathElement) {
497 if (!bParentIsFS && (LPSTATSTRUCT_FROM_LPSHITEMID(pidl)->sfAttr & SFGAO_FILESYSTEM))
499 pidl = ILGetNext(pidl);
501 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
503 if ((int)pidl-(int)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
504 ERR("Computed length of pidl incorrect. Please report.\n");
509 /******************************************************************************
510 * UNIXFS_pidl_to_path [Internal]
512 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
515 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
516 * path [O] The corresponding unix path as a zero terminated ascii string
520 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
522 static BOOL UNIXFS_pidl_to_path(LPCITEMIDLIST pidl, UnixFolder *pUnixFolder) {
523 LPCITEMIDLIST current = pidl, root;
525 char *pNextDir, szBasePath[FILENAME_MAX] = "/";
527 TRACE("(pidl=%p, pUnixFolder=%p)\n", pidl, pUnixFolder);
530 pUnixFolder->m_pszPath = NULL;
532 /* Find the UnixFolderClass root */
533 while (current->mkid.cb) {
534 if (_ILIsDrive(current) || /* The dos drive, which maps to '/' */
535 (_ILIsSpecialFolder(current) &&
536 (IsEqualIID(&CLSID_UnixFolder, _ILGetGUIDPointer(current)) ||
537 IsEqualIID(&CLSID_UnixDosFolder, _ILGetGUIDPointer(current)))))
541 current = ILGetNext(current);
544 if (current && current->mkid.cb) {
545 root = current = ILGetNext(current);
546 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
547 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
548 /* Path rooted at Desktop */
549 WCHAR wszDesktopPath[MAX_PATH];
550 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOP, FALSE)))
552 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
554 dwPathLen = strlen(szBasePath) + 1;
557 ERR("Unknown pidl type!\n");
562 /* Determine the path's length bytes */
563 while (current && current->mkid.cb) {
564 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
565 current = ILGetNext(current);
569 pUnixFolder->m_pszPath = pNextDir = SHAlloc(dwPathLen);
570 if (!pUnixFolder->m_pszPath) {
571 WARN("SHAlloc failed!\n");
575 strcpy(pNextDir, szBasePath);
576 pNextDir += strlen(szBasePath);
577 while (current && current->mkid.cb) {
578 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
579 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
581 current = ILGetNext(current);
585 TRACE("--> %s\n", pUnixFolder->m_pszPath);
589 /******************************************************************************
590 * UNIXFS_build_subfolder_pidls [Internal]
592 * Builds an array of subfolder PIDLs relative to a unix directory
595 * path [I] Name of a unix directory as a zero terminated ascii string
596 * apidl [O] The array of PIDLs
597 * pCount [O] Size of apidl
601 * Failure: FALSE, path is not a valid unix directory or out of memory
604 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
605 * to release each PIDL as well as the array itself with SHFree.
607 static BOOL UNIXFS_build_subfolder_pidls(UnixFolder *pUnixFolder)
609 struct dirent *pDirEntry;
610 struct stat fileStat;
612 DWORD cDirEntries, i;
615 BOOL bParentIsFS = dwRootAttr & SFGAO_FILESYSTEM;
617 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
619 pUnixFolder->m_apidlSubDirs = NULL;
620 pUnixFolder->m_cSubDirs = 0;
622 if (pUnixFolder->m_pidlLocation) {
623 StatStruct *statStruct =
624 LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(pUnixFolder->m_pidlLocation));
625 if (statStruct) bParentIsFS = statStruct->sfAttr & SFGAO_FILESYSTEM;
628 dir = opendir(pUnixFolder->m_pszPath);
630 WARN("Failed to open directory '%s'.\n", pUnixFolder->m_pszPath);
634 /* Allocate space for fully qualified paths */
635 pszFQPath = SHAlloc(strlen(pUnixFolder->m_pszPath) + PATH_MAX);
637 WARN("SHAlloc failed!\n");
641 /* Count number of directory entries. */
642 for (cDirEntries = 0, pDirEntry = readdir(dir); pDirEntry; pDirEntry = readdir(dir)) {
643 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
644 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
645 if (!stat(pszFQPath, &fileStat) && (S_ISDIR(fileStat.st_mode) || S_ISREG(fileStat.st_mode))) cDirEntries++;
648 /* If there are no entries, we are done. */
649 if (cDirEntries == 0) {
655 /* Allocate the array of PIDLs */
656 pUnixFolder->m_apidlSubDirs = SHAlloc(cDirEntries * sizeof(LPITEMIDLIST));
657 if (!pUnixFolder->m_apidlSubDirs) {
658 WARN("SHAlloc failed!\n");
662 /* Allocate and initialize one SHITEMID per sub-directory. */
663 for (rewinddir(dir), pDirEntry = readdir(dir), i = 0; pDirEntry; pDirEntry = readdir(dir)) {
666 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
668 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
670 sLen = strlen(pDirEntry->d_name);
671 pid = (LPSHITEMID)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen)+sizeof(USHORT));
673 WARN("SHAlloc failed!\n");
676 if (!UNIXFS_build_shitemid(pszFQPath, bParentIsFS, pid)) {
680 memset(((PBYTE)pid)+pid->cb, 0, sizeof(USHORT));
682 pUnixFolder->m_apidlSubDirs[i++] = (LPITEMIDLIST)pid;
685 pUnixFolder->m_cSubDirs = i;
692 /******************************************************************************
695 * Class whose heap based instances represent unix filesystem directories.
698 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
701 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
703 if (pUnixFolder->m_apidlSubDirs)
704 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
705 SHFree(pUnixFolder->m_apidlSubDirs[i]);
706 SHFree(pUnixFolder->m_apidlSubDirs);
707 SHFree(pUnixFolder->m_pszPath);
708 ILFree(pUnixFolder->m_pidlLocation);
712 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
715 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
717 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
719 if (!ppv) return E_INVALIDARG;
721 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
722 IsEqualIID(&IID_IShellFolder2, riid))
724 *ppv = &This->lpIShellFolder2Vtbl;
725 } else if (IsEqualIID(&IID_IPersistFolder2, riid) || IsEqualIID(&IID_IPersistFolder, riid) ||
726 IsEqualIID(&IID_IPersist, riid))
728 *ppv = &This->lpIPersistFolder2Vtbl;
731 return E_NOINTERFACE;
734 IUnknown_AddRef((IUnknown*)*ppv);
738 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
739 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
741 TRACE("(iface=%p)\n", iface);
743 return InterlockedIncrement(&This->m_cRef);
746 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
747 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
750 TRACE("(iface=%p)\n", iface);
752 cRef = InterlockedDecrement(&This->m_cRef);
755 UnixFolder_Destroy(This);
760 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
761 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
762 ULONG* pdwAttributes)
764 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
767 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
768 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
769 pchEaten, ppidl, pdwAttributes);
771 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
772 if (result && pdwAttributes && *pdwAttributes)
774 IShellFolder *pParentSF;
775 LPCITEMIDLIST pidlLast;
778 hr = SHBindToParent(This->m_pidlLocation, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
779 if (FAILED(hr)) return E_FAIL;
780 IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
781 IShellFolder_Release(pParentSF);
784 if (!result) TRACE("FAILED!\n");
785 return result ? S_OK : E_FAIL;
788 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter);
790 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
791 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
793 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
794 IUnknown *newIterator;
797 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
798 iface, hwndOwner, grfFlags, ppEnumIDList);
800 if (This->m_cSubDirs == -1)
801 UNIXFS_build_subfolder_pidls(This);
803 newIterator = UnixSubFolderIterator_Construct(This, grfFlags);
804 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
805 IUnknown_Release(newIterator);
810 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
811 LPBC pbcReserved, REFIID riid, void** ppvOut)
813 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
814 IPersistFolder2 *persistFolder;
815 LPITEMIDLIST pidlSubFolder;
818 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
819 iface, pidl, pbcReserved, riid, ppvOut);
821 if (!pidl || !pidl->mkid.cb)
824 if (This->m_dwPathMode == PATHMODE_DOS)
825 hr = UnixDosFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
827 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
829 if (!SUCCEEDED(hr)) return hr;
830 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
832 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
833 IPersistFolder2_Initialize(persistFolder, pidlSubFolder);
834 IPersistFolder2_Release(persistFolder);
835 ILFree(pidlSubFolder);
840 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
841 LPBC pbcReserved, REFIID riid, void** ppvObj)
847 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
848 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
850 BOOL isEmpty1, isEmpty2;
852 LPITEMIDLIST firstpidl;
856 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
858 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
859 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
861 if (isEmpty1 && isEmpty2)
862 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
864 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
866 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
868 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
869 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
870 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
871 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
873 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
874 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
875 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
877 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
878 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
880 if (pidl1->mkid.cb < pidl2->mkid.cb)
881 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
882 else if (pidl1->mkid.cb > pidl2->mkid.cb)
883 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
885 firstpidl = ILCloneFirst(pidl1);
886 pidl1 = ILGetNext(pidl1);
887 pidl2 = ILGetNext(pidl2);
889 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
891 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
892 IShellFolder2_Release(psf);
899 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
900 REFIID riid, void** ppv)
902 HRESULT hr = E_INVALIDARG;
904 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
906 if (!ppv) return E_INVALIDARG;
909 if (IsEqualIID(&IID_IShellView, riid)) {
910 LPSHELLVIEW pShellView;
912 pShellView = IShellView_Constructor((IShellFolder*)iface);
914 hr = IShellView_QueryInterface(pShellView, riid, ppv);
915 IShellView_Release(pShellView);
922 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
923 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
925 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
926 const StatStruct *pStatStruct;
928 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
930 if (!rgfInOut || (cidl && !apidl))
934 if (!strcmp(This->m_pszPath, "/")) {
935 *rgfInOut &= dwRootAttr;
937 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(This->m_pidlLocation));
938 if (!pStatStruct) return E_FAIL;
939 *rgfInOut &= pStatStruct->sfAttr;
943 for (i=0; i<cidl; i++) {
944 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(apidl[i]);
945 if (!pStatStruct) return E_INVALIDARG;
946 *rgfInOut &= pStatStruct->sfAttr;
953 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
954 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
956 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
958 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
959 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
961 if (IsEqualIID(&IID_IContextMenu, riid)) {
962 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
964 } else if (IsEqualIID(&IID_IDataObject, riid)) {
965 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
967 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
969 if (cidl != 1) return E_FAIL;
970 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
971 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
974 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
976 if (cidl != 1) return E_FAIL;
977 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
978 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
981 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
982 FIXME("IDropTarget\n");
984 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
985 FIXME("IShellLinkW\n");
987 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
988 FIXME("IShellLinkA\n");
991 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
992 return E_NOINTERFACE;
996 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
997 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
999 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1002 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
1004 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
1005 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
1007 if (!pidl->mkid.cb) {
1008 lpName->uType = STRRET_CSTR;
1009 strcpy(lpName->u.cStr, This->m_pszPath);
1010 if (This->m_dwPathMode == PATHMODE_DOS) {
1011 char path[MAX_PATH];
1012 GetFullPathNameA(lpName->u.cStr, MAX_PATH, path, NULL);
1013 PathRemoveBackslashA(path);
1014 strcpy(lpName->u.cStr, path);
1017 IShellFolder *pSubFolder;
1018 USHORT emptyIDL = 0;
1020 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
1021 if (!SUCCEEDED(hr)) return hr;
1023 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
1024 IShellFolder_Release(pSubFolder);
1027 char *pszFileName = _ILGetTextPointer(pidl);
1028 lpName->uType = STRRET_CSTR;
1029 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
1032 TRACE("--> %s\n", lpName->u.cStr);
1037 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* This, HWND hwnd,
1038 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
1044 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
1045 IEnumExtraSearch **ppEnum)
1051 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
1052 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
1058 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
1059 UINT iColumn, SHCOLSTATEF *pcsFlags)
1065 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1072 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1073 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1079 #define SHELLVIEWCOLUMNS 6
1081 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1082 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1084 HRESULT hr = E_FAIL;
1085 struct passwd *pPasswd;
1086 struct group *pGroup;
1087 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1088 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1089 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1090 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1091 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1092 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 8},
1093 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
1096 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1098 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1099 return E_INVALIDARG;
1102 psd->fmt = SFHeader[iColumn].fmt;
1103 psd->cxChar = SFHeader[iColumn].cxChar;
1104 psd->str.uType = STRRET_CSTR;
1105 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1108 StatStruct *pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pidl);
1109 psd->str.u.cStr[0] = '\0';
1110 psd->str.uType = STRRET_CSTR;
1113 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1116 psd->str.u.cStr[0] = S_ISDIR(pStatStruct->st_mode) ? 'd' : '-';
1117 psd->str.u.cStr[1] = (pStatStruct->st_mode & S_IRUSR) ? 'r' : '-';
1118 psd->str.u.cStr[2] = (pStatStruct->st_mode & S_IWUSR) ? 'w' : '-';
1119 psd->str.u.cStr[3] = (pStatStruct->st_mode & S_IXUSR) ? 'x' : '-';
1120 psd->str.u.cStr[4] = (pStatStruct->st_mode & S_IRGRP) ? 'r' : '-';
1121 psd->str.u.cStr[5] = (pStatStruct->st_mode & S_IWGRP) ? 'w' : '-';
1122 psd->str.u.cStr[6] = (pStatStruct->st_mode & S_IXGRP) ? 'x' : '-';
1123 psd->str.u.cStr[7] = (pStatStruct->st_mode & S_IROTH) ? 'r' : '-';
1124 psd->str.u.cStr[8] = (pStatStruct->st_mode & S_IWOTH) ? 'w' : '-';
1125 psd->str.u.cStr[9] = (pStatStruct->st_mode & S_IXOTH) ? 'x' : '-';
1126 psd->str.u.cStr[10] = '\0';
1129 pPasswd = getpwuid(pStatStruct->st_uid);
1130 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1133 pGroup = getgrgid(pStatStruct->st_gid);
1134 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1137 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1140 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1148 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1155 /* VTable for UnixFolder's IShellFolder2 interface.
1157 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1158 UnixFolder_IShellFolder2_QueryInterface,
1159 UnixFolder_IShellFolder2_AddRef,
1160 UnixFolder_IShellFolder2_Release,
1161 UnixFolder_IShellFolder2_ParseDisplayName,
1162 UnixFolder_IShellFolder2_EnumObjects,
1163 UnixFolder_IShellFolder2_BindToObject,
1164 UnixFolder_IShellFolder2_BindToStorage,
1165 UnixFolder_IShellFolder2_CompareIDs,
1166 UnixFolder_IShellFolder2_CreateViewObject,
1167 UnixFolder_IShellFolder2_GetAttributesOf,
1168 UnixFolder_IShellFolder2_GetUIObjectOf,
1169 UnixFolder_IShellFolder2_GetDisplayNameOf,
1170 UnixFolder_IShellFolder2_SetNameOf,
1171 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1172 UnixFolder_IShellFolder2_EnumSearches,
1173 UnixFolder_IShellFolder2_GetDefaultColumn,
1174 UnixFolder_IShellFolder2_GetDefaultColumnState,
1175 UnixFolder_IShellFolder2_GetDetailsEx,
1176 UnixFolder_IShellFolder2_GetDetailsOf,
1177 UnixFolder_IShellFolder2_MapColumnToSCID
1180 static HRESULT WINAPI UnixFolder_IPersistFolder2_QueryInterface(IPersistFolder2* This, REFIID riid,
1183 return UnixFolder_IShellFolder2_QueryInterface(
1184 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This), riid, ppvObject);
1187 static ULONG WINAPI UnixFolder_IPersistFolder2_AddRef(IPersistFolder2* This)
1189 return UnixFolder_IShellFolder2_AddRef(
1190 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1193 static ULONG WINAPI UnixFolder_IPersistFolder2_Release(IPersistFolder2* This)
1195 return UnixFolder_IShellFolder2_Release(
1196 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1199 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetClassID(IPersistFolder2* This, CLSID* pClassID)
1205 static HRESULT WINAPI UnixFolder_IPersistFolder2_Initialize(IPersistFolder2* iface, LPCITEMIDLIST pidl)
1207 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1209 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1211 This->m_pidlLocation = ILClone(pidl);
1215 if (!UNIXFS_pidl_to_path(pidl, This))
1218 if (!strcmp(This->m_pszPath, "/")) {
1219 struct stat statRoot;
1220 if (stat(This->m_pszPath, &statRoot)) return E_FAIL;
1221 dwRootAttr = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
1222 if (UNIXFS_is_dos_device(&statRoot)) dwRootAttr |= SFGAO_FILESYSTEM;
1228 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetCurFolder(IPersistFolder2* iface, LPITEMIDLIST* ppidl)
1230 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1232 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1236 *ppidl = ILClone (This->m_pidlLocation);
1240 /* VTable for UnixFolder's IPersistFolder interface.
1242 static const IPersistFolder2Vtbl UnixFolder_IPersistFolder2_Vtbl = {
1243 UnixFolder_IPersistFolder2_QueryInterface,
1244 UnixFolder_IPersistFolder2_AddRef,
1245 UnixFolder_IPersistFolder2_Release,
1246 UnixFolder_IPersistFolder2_GetClassID,
1247 UnixFolder_IPersistFolder2_Initialize,
1248 UnixFolder_IPersistFolder2_GetCurFolder
1251 /******************************************************************************
1252 * Unix[Dos]Folder_Constructor [Internal]
1255 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1256 * riid [I] Interface asked for by the client.
1257 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1260 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1261 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1262 * compatible signature.
1264 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1265 * means that paths are converted from dos to unix and back at the interfaces.
1267 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, DWORD dwPathMode) {
1268 HRESULT hr = E_FAIL;
1269 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1272 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1273 pUnixFolder->lpIPersistFolder2Vtbl = &UnixFolder_IPersistFolder2_Vtbl;
1274 pUnixFolder->m_cRef = 0;
1275 pUnixFolder->m_pszPath = NULL;
1276 pUnixFolder->m_apidlSubDirs = NULL;
1277 pUnixFolder->m_cSubDirs = -1;
1278 pUnixFolder->m_dwPathMode = dwPathMode;
1280 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1281 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1282 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1287 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1288 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1289 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_UNIX);
1292 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1293 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1294 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_DOS);
1297 /******************************************************************************
1298 * UnixSubFolderIterator
1300 * Class whose heap based objects represent iterators over the sub-directories
1301 * of a given UnixFolder object.
1304 /* UnixSubFolderIterator object layout and typedef.
1306 typedef struct _UnixSubFolderIterator {
1307 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1309 UnixFolder *m_pUnixFolder;
1312 } UnixSubFolderIterator;
1314 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1315 TRACE("(iterator=%p)\n", iterator);
1317 UnixFolder_IShellFolder2_Release((IShellFolder2*)iterator->m_pUnixFolder);
1321 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1322 REFIID riid, void** ppv)
1324 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1326 if (!ppv) return E_INVALIDARG;
1328 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1332 return E_NOINTERFACE;
1335 IEnumIDList_AddRef(iface);
1339 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1341 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1343 TRACE("(iface=%p)\n", iface);
1345 return InterlockedIncrement(&This->m_cRef);
1348 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1350 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1353 TRACE("(iface=%p)\n", iface);
1355 cRef = InterlockedDecrement(&This->m_cRef);
1358 UnixSubFolderIterator_Destroy(This);
1363 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1364 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1366 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1369 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface, celt, rgelt, pceltFetched);
1371 for (i=0; (i < celt) && (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs); This->m_cIdx++) {
1372 LPITEMIDLIST pCurrent = This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx];
1373 if (UNIXFS_is_pidl_of_type(pCurrent, This->m_fFilter)) {
1374 rgelt[i] = ILClone(pCurrent);
1382 return i == celt ? S_OK : S_FALSE;
1385 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1387 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1390 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1392 for (i=0; i < celt; i++) {
1393 while (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs &&
1394 !UNIXFS_is_pidl_of_type(This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx], This->m_fFilter))
1401 if (This->m_cIdx > This->m_pUnixFolder->m_cSubDirs) {
1402 This->m_cIdx = This->m_pUnixFolder->m_cSubDirs;
1409 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1411 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1413 TRACE("(iface=%p)\n", iface);
1420 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1421 IEnumIDList** ppenum)
1427 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1429 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1430 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1431 UnixSubFolderIterator_IEnumIDList_AddRef,
1432 UnixSubFolderIterator_IEnumIDList_Release,
1433 UnixSubFolderIterator_IEnumIDList_Next,
1434 UnixSubFolderIterator_IEnumIDList_Skip,
1435 UnixSubFolderIterator_IEnumIDList_Reset,
1436 UnixSubFolderIterator_IEnumIDList_Clone
1439 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1440 UnixSubFolderIterator *iterator;
1442 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1444 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1445 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1446 iterator->m_cRef = 0;
1447 iterator->m_cIdx = 0;
1448 iterator->m_pUnixFolder = pUnixFolder;
1449 iterator->m_fFilter = fFilter;
1451 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1452 UnixFolder_IShellFolder2_AddRef((IShellFolder2*)pUnixFolder);
1454 return (IUnknown*)iterator;