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 memcpy(szSymlink
+ cLinkLen
, pPathTail
, cTailLen
+ 1);
284 memcpy(szPath
, szSymlink
, cLinkLen
+ cTailLen
+ 1);
285 *pszCanonicalPath
= '\0';
286 pCanonicalTail
= pszCanonicalPath
;
289 /* Relative link. Expand into szPath and continue. */
290 char szTemp
[FILENAME_MAX
];
291 int cTailLen
= strlen(pPathTail
);
293 if (pElement
- szPath
+ 1 + cLinkLen
+ cTailLen
+ 1 > FILENAME_MAX
)
296 memcpy(szTemp
, pPathTail
, cTailLen
+ 1);
297 memcpy(pElement
+ 1, szSymlink
, cLinkLen
);
298 memcpy(pElement
+ 1 + cLinkLen
, szTemp
, cTailLen
+ 1);
299 pPathTail
= pElement
;
302 /* Regular directory or file. Copy to canonical path */
303 if (pCanonicalTail
- pszCanonicalPath
+ pPathTail
- pElement
+ 1 > FILENAME_MAX
)
306 memcpy(pCanonicalTail
, pElement
, pPathTail
- pElement
+ 1);
307 pCanonicalTail
+= pPathTail
- pElement
;
310 } while (pPathTail
[0] == '/' && pPathTail
[1]); /* Also handles paths terminated by '/' */
312 TRACE("--> %s\n", debugstr_a(pszCanonicalPath
));
317 /******************************************************************************
318 * UNIXFS_build_shitemid [Internal]
320 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
321 * buffer 'pIDL'. Decorates the SHITEMID with information from a stat system call.
324 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
325 * bParentIsFS [I] Set, if the parent of the last path component is within the wine filesystem.
326 * pIDL [O] SHITEMID will be constructed here.
329 * Success: A pointer to the terminating '\0' character of path.
333 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
334 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
337 static char* UNIXFS_build_shitemid(char *pszUnixPath
, BOOL bParentIsFS
, void *pIDL
) {
341 struct stat fileStat
;
342 StatStruct
*pStatStruct
;
346 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath
), pIDL
);
348 /* Compute the SHITEMID's length and wipe it. */
349 pszComponent
= strrchr(pszUnixPath
, '/') + 1;
350 cComponentLen
= strlen(pszComponent
);
351 memset(pIDL
, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
));
352 ((LPSHITEMID
)pIDL
)->cb
= SHITEMID_LEN_FROM_NAME_LEN(cComponentLen
) ;
354 /* We are only interested in regular files and directories. */
355 if (stat(pszUnixPath
, &fileStat
)) return NULL
;
356 if (!S_ISDIR(fileStat
.st_mode
) && !S_ISREG(fileStat
.st_mode
)) return NULL
;
358 pStatStruct
= LPSTATSTRUCT_FROM_LPSHITEMID(pIDL
);
359 pStatStruct
->st_mode
= fileStat
.st_mode
;
360 pStatStruct
->st_uid
= fileStat
.st_uid
;
361 pStatStruct
->st_gid
= fileStat
.st_gid
;
362 pStatStruct
->sfAttr
= S_ISDIR(fileStat
.st_mode
) ? (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
) : 0;
363 if (bParentIsFS
|| UNIXFS_is_dos_device(&fileStat
)) pStatStruct
->sfAttr
|= SFGAO_FILESYSTEM
;
365 /* Set shell32's standard SHITEMID data fields. */
366 pIDLData
= _ILGetDataPointer((LPCITEMIDLIST
)pIDL
);
367 pIDLData
->type
= S_ISDIR(fileStat
.st_mode
) ? PT_FOLDER
: PT_VALUE
;
368 pIDLData
->u
.file
.dwFileSize
= (DWORD
)fileStat
.st_size
;
369 RtlSecondsSince1970ToTime( fileStat
.st_mtime
, &time
);
370 fileTime
.dwLowDateTime
= time
.u
.LowPart
;
371 fileTime
.dwHighDateTime
= time
.u
.HighPart
;
372 FileTimeToDosDateTime(&fileTime
, &pIDLData
->u
.file
.uFileDate
, &pIDLData
->u
.file
.uFileTime
);
373 pIDLData
->u
.file
.uFileAttribs
= 0;
374 if (S_ISDIR(fileStat
.st_mode
)) pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_DIRECTORY
;
375 if (pszComponent
[0] == '.') pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_HIDDEN
;
376 memcpy(pIDLData
->u
.file
.szNames
, pszComponent
, cComponentLen
);
378 return pszComponent
+ cComponentLen
;
381 /******************************************************************************
382 * UNIXFS_path_to_pidl [Internal]
385 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
386 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
387 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
391 * Failure: FALSE, invalid params or out of memory
394 * pUnixFolder also carries the information if the path is expected to be unix or dos.
396 static BOOL
UNIXFS_path_to_pidl(UnixFolder
*pUnixFolder
, const WCHAR
*path
, LPITEMIDLIST
*ppidl
) {
398 int cSubDirs
, cPidlLen
, cPathLen
;
399 char *pSlash
, szCompletePath
[FILENAME_MAX
], *pNextPathElement
;
400 BOOL bParentIsFS
= dwRootAttr
& SFGAO_FILESYSTEM
;
402 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder
, debugstr_w(path
), ppidl
);
407 /* Build an absolute path and let pNextPathElement point to the interesting
408 * relative sub-path. We need the absolute path to call 'stat', but the pidl
409 * will only contain the relative part.
411 if ((pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) && (path
[1] == ':'))
413 /* Absolute dos path. Convert to unix */
414 if (!UNIXFS_get_unix_path(path
, szCompletePath
))
416 pNextPathElement
= szCompletePath
;
418 else if ((pUnixFolder
->m_dwPathMode
== PATHMODE_UNIX
) && (path
[0] == '/'))
420 /* Absolute unix path. Just convert to ANSI. */
421 WideCharToMultiByte(CP_ACP
, 0, path
, -1, szCompletePath
, FILENAME_MAX
, NULL
, NULL
);
422 pNextPathElement
= szCompletePath
;
426 /* Relative dos or unix path. Concat with this folder's path */
427 int cBasePathLen
= strlen(pUnixFolder
->m_pszPath
);
428 memcpy(szCompletePath
, pUnixFolder
->m_pszPath
, cBasePathLen
);
429 WideCharToMultiByte(CP_ACP
, 0, path
, -1, szCompletePath
+ cBasePathLen
,
430 FILENAME_MAX
- cBasePathLen
, NULL
, NULL
);
431 pNextPathElement
= szCompletePath
+ cBasePathLen
- 1;
433 /* If in dos mode, replace '\' with '/' */
434 if (pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) {
435 char *pBackslash
= strchr(pNextPathElement
, '\\');
438 pBackslash
= strchr(pBackslash
, '\\');
443 /* Remove trailing slash, if present */
444 cPathLen
= strlen(szCompletePath
);
445 if (szCompletePath
[cPathLen
-1] == '/')
446 szCompletePath
[cPathLen
-1] = '\0';
448 if ((szCompletePath
[0] != '/') || (pNextPathElement
[0] != '/')) {
449 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath
, pNextPathElement
);
453 /* At this point, we have an absolute unix path in szCompletePath
454 * and the relative portion of it in pNextPathElement. Both starting with '/'
455 * and _not_ terminated by a '/'. */
456 TRACE("complete path: %s, relative path: %s\n", szCompletePath
, pNextPathElement
);
458 /* Count the number of sub-directories in the path */
460 pSlash
= pNextPathElement
;
463 pSlash
= strchr(pSlash
+1, '/');
466 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
467 * characters, which are not stored in the ITEMIDLIST. */
468 cPidlLen
= strlen(pNextPathElement
) - cSubDirs
+ cSubDirs
* SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT
);
469 *ppidl
= pidl
= (LPITEMIDLIST
)SHAlloc(cPidlLen
);
470 if (!pidl
) return FALSE
;
472 /* Concatenate the SHITEMIDs of the sub-directories. */
473 while (*pNextPathElement
) {
474 pSlash
= strchr(pNextPathElement
+1, '/');
475 if (pSlash
) *pSlash
= '\0';
476 pNextPathElement
= UNIXFS_build_shitemid(szCompletePath
, bParentIsFS
, pidl
);
477 if (pSlash
) *pSlash
= '/';
479 if (!pNextPathElement
) {
483 if (!bParentIsFS
&& (LPSTATSTRUCT_FROM_LPSHITEMID(pidl
)->sfAttr
& SFGAO_FILESYSTEM
))
485 pidl
= ILGetNext(pidl
);
487 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
489 if ((int)pidl
-(int)*ppidl
+sizeof(USHORT
) != cPidlLen
) /* We've corrupted the heap :( */
490 ERR("Computed length of pidl incorrect. Please report.\n");
495 /******************************************************************************
496 * UNIXFS_pidl_to_path [Internal]
498 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
501 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
502 * path [O] The corresponding unix path as a zero terminated ascii string
506 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
508 static BOOL
UNIXFS_pidl_to_path(LPCITEMIDLIST pidl
, UnixFolder
*pUnixFolder
) {
509 LPCITEMIDLIST current
= pidl
, root
;
511 char *pNextDir
, szBasePath
[FILENAME_MAX
] = "/";
513 TRACE("(pidl=%p, pUnixFolder=%p)\n", pidl
, pUnixFolder
);
516 pUnixFolder
->m_pszPath
= NULL
;
518 /* Find the UnixFolderClass root */
519 while (current
->mkid
.cb
) {
520 if (_ILIsDrive(current
) || /* The dos drive, which maps to '/' */
521 (_ILIsSpecialFolder(current
) &&
522 (IsEqualIID(&CLSID_UnixFolder
, _ILGetGUIDPointer(current
)) ||
523 IsEqualIID(&CLSID_UnixDosFolder
, _ILGetGUIDPointer(current
)))))
527 current
= ILGetNext(current
);
530 if (current
&& current
->mkid
.cb
) {
531 root
= current
= ILGetNext(current
);
532 dwPathLen
= 2; /* For the '/' prefix and the terminating '\0' */
533 } else if (_ILIsDesktop(pidl
) || _ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
534 /* Path rooted at Desktop */
535 WCHAR wszDesktopPath
[MAX_PATH
];
536 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath
, CSIDL_DESKTOP
, FALSE
)))
538 if (!UNIXFS_get_unix_path(wszDesktopPath
, szBasePath
))
540 dwPathLen
= strlen(szBasePath
) + 1;
543 ERR("Unknown pidl type!\n");
548 /* Determine the path's length bytes */
549 while (current
&& current
->mkid
.cb
) {
550 dwPathLen
+= NAME_LEN_FROM_LPSHITEMID(current
) + 1; /* For the '/' */
551 current
= ILGetNext(current
);
555 pUnixFolder
->m_pszPath
= pNextDir
= SHAlloc(dwPathLen
);
556 if (!pUnixFolder
->m_pszPath
) {
557 WARN("SHAlloc failed!\n");
561 strcpy(pNextDir
, szBasePath
);
562 pNextDir
+= strlen(szBasePath
);
563 while (current
&& current
->mkid
.cb
) {
564 memcpy(pNextDir
, _ILGetTextPointer(current
), NAME_LEN_FROM_LPSHITEMID(current
));
565 pNextDir
+= NAME_LEN_FROM_LPSHITEMID(current
);
567 current
= ILGetNext(current
);
571 TRACE("--> %s\n", pUnixFolder
->m_pszPath
);
575 /******************************************************************************
576 * UNIXFS_build_subfolder_pidls [Internal]
578 * Builds an array of subfolder PIDLs relative to a unix directory
581 * path [I] Name of a unix directory as a zero terminated ascii string
582 * apidl [O] The array of PIDLs
583 * pCount [O] Size of apidl
587 * Failure: FALSE, path is not a valid unix directory or out of memory
590 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
591 * to release each PIDL as well as the array itself with SHFree.
593 static BOOL
UNIXFS_build_subfolder_pidls(UnixFolder
*pUnixFolder
)
595 struct dirent
*pDirEntry
;
596 struct stat fileStat
;
598 DWORD cDirEntries
, i
;
601 BOOL bParentIsFS
= dwRootAttr
& SFGAO_FILESYSTEM
;
603 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
605 pUnixFolder
->m_apidlSubDirs
= NULL
;
606 pUnixFolder
->m_cSubDirs
= 0;
608 if (pUnixFolder
->m_pidlLocation
) {
609 StatStruct
*statStruct
=
610 LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(pUnixFolder
->m_pidlLocation
));
611 if (statStruct
) bParentIsFS
= statStruct
->sfAttr
& SFGAO_FILESYSTEM
;
614 dir
= opendir(pUnixFolder
->m_pszPath
);
616 WARN("Failed to open directory '%s'.\n", pUnixFolder
->m_pszPath
);
620 /* Allocate space for fully qualified paths */
621 pszFQPath
= SHAlloc(strlen(pUnixFolder
->m_pszPath
) + PATH_MAX
);
623 WARN("SHAlloc failed!\n");
627 /* Count number of directory entries. */
628 for (cDirEntries
= 0, pDirEntry
= readdir(dir
); pDirEntry
; pDirEntry
= readdir(dir
)) {
629 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
630 sprintf(pszFQPath
, "%s%s", pUnixFolder
->m_pszPath
, pDirEntry
->d_name
);
631 if (!stat(pszFQPath
, &fileStat
) && (S_ISDIR(fileStat
.st_mode
) || S_ISREG(fileStat
.st_mode
))) cDirEntries
++;
634 /* If there are no entries, we are done. */
635 if (cDirEntries
== 0) {
641 /* Allocate the array of PIDLs */
642 pUnixFolder
->m_apidlSubDirs
= SHAlloc(cDirEntries
* sizeof(LPITEMIDLIST
));
643 if (!pUnixFolder
->m_apidlSubDirs
) {
644 WARN("SHAlloc failed!\n");
648 /* Allocate and initialize one SHITEMID per sub-directory. */
649 for (rewinddir(dir
), pDirEntry
= readdir(dir
), i
= 0; pDirEntry
; pDirEntry
= readdir(dir
)) {
652 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
654 sprintf(pszFQPath
, "%s%s", pUnixFolder
->m_pszPath
, pDirEntry
->d_name
);
656 sLen
= strlen(pDirEntry
->d_name
);
657 pid
= (LPSHITEMID
)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen
)+sizeof(USHORT
));
659 WARN("SHAlloc failed!\n");
662 if (!UNIXFS_build_shitemid(pszFQPath
, bParentIsFS
, pid
)) {
666 memset(((PBYTE
)pid
)+pid
->cb
, 0, sizeof(USHORT
));
668 pUnixFolder
->m_apidlSubDirs
[i
++] = (LPITEMIDLIST
)pid
;
671 pUnixFolder
->m_cSubDirs
= i
;
678 /******************************************************************************
681 * Class whose heap based instances represent unix filesystem directories.
684 static void UnixFolder_Destroy(UnixFolder
*pUnixFolder
) {
687 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
689 if (pUnixFolder
->m_apidlSubDirs
)
690 for (i
=0; i
< pUnixFolder
->m_cSubDirs
; i
++)
691 SHFree(pUnixFolder
->m_apidlSubDirs
[i
]);
692 SHFree(pUnixFolder
->m_apidlSubDirs
);
693 SHFree(pUnixFolder
->m_pszPath
);
694 ILFree(pUnixFolder
->m_pidlLocation
);
698 static HRESULT WINAPI
UnixFolder_IShellFolder2_QueryInterface(IShellFolder2
*iface
, REFIID riid
,
701 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
703 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
705 if (!ppv
) return E_INVALIDARG
;
707 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellFolder
, riid
) ||
708 IsEqualIID(&IID_IShellFolder2
, riid
))
710 *ppv
= &This
->lpIShellFolder2Vtbl
;
711 } else if (IsEqualIID(&IID_IPersistFolder2
, riid
) || IsEqualIID(&IID_IPersistFolder
, riid
) ||
712 IsEqualIID(&IID_IPersist
, riid
))
714 *ppv
= &This
->lpIPersistFolder2Vtbl
;
717 return E_NOINTERFACE
;
720 IUnknown_AddRef((IUnknown
*)*ppv
);
724 static ULONG WINAPI
UnixFolder_IShellFolder2_AddRef(IShellFolder2
*iface
) {
725 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
727 TRACE("(iface=%p)\n", iface
);
729 return InterlockedIncrement(&This
->m_cRef
);
732 static ULONG WINAPI
UnixFolder_IShellFolder2_Release(IShellFolder2
*iface
) {
733 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
736 TRACE("(iface=%p)\n", iface
);
738 cRef
= InterlockedDecrement(&This
->m_cRef
);
741 UnixFolder_Destroy(This
);
746 static HRESULT WINAPI
UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2
* iface
, HWND hwndOwner
,
747 LPBC pbcReserved
, LPOLESTR lpszDisplayName
, ULONG
* pchEaten
, LPITEMIDLIST
* ppidl
,
748 ULONG
* pdwAttributes
)
750 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
753 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
754 "pdwAttributes=%p) stub\n", iface
, hwndOwner
, pbcReserved
, debugstr_w(lpszDisplayName
),
755 pchEaten
, ppidl
, pdwAttributes
);
757 result
= UNIXFS_path_to_pidl(This
, lpszDisplayName
, ppidl
);
758 if (result
&& pdwAttributes
&& *pdwAttributes
)
760 /* need to traverse to the last element for the attribute */
761 LPCITEMIDLIST pidl
, last_pidl
;
762 pidl
= last_pidl
= *ppidl
;
763 while(pidl
&& pidl
->mkid
.cb
)
766 pidl
= ILGetNext(pidl
);
768 SHELL32_GetItemAttributes((IShellFolder
*)iface
, last_pidl
, pdwAttributes
);
771 if (!result
) TRACE("FAILED!\n");
772 return result
? S_OK
: E_FAIL
;
775 static IUnknown
*UnixSubFolderIterator_Construct(UnixFolder
*pUnixFolder
, SHCONTF fFilter
);
777 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumObjects(IShellFolder2
* iface
, HWND hwndOwner
,
778 SHCONTF grfFlags
, IEnumIDList
** ppEnumIDList
)
780 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
781 IUnknown
*newIterator
;
784 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
785 iface
, hwndOwner
, grfFlags
, ppEnumIDList
);
787 if (This
->m_cSubDirs
== -1)
788 UNIXFS_build_subfolder_pidls(This
);
790 newIterator
= UnixSubFolderIterator_Construct(This
, grfFlags
);
791 hr
= IUnknown_QueryInterface(newIterator
, &IID_IEnumIDList
, (void**)ppEnumIDList
);
792 IUnknown_Release(newIterator
);
797 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToObject(IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
798 LPBC pbcReserved
, REFIID riid
, void** ppvOut
)
800 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
801 IPersistFolder2
*persistFolder
;
802 LPITEMIDLIST pidlSubFolder
;
805 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
806 iface
, pidl
, pbcReserved
, riid
, ppvOut
);
808 if (!pidl
|| !pidl
->mkid
.cb
)
811 if (This
->m_dwPathMode
== PATHMODE_DOS
)
812 hr
= UnixDosFolder_Constructor(NULL
, &IID_IPersistFolder2
, (void**)&persistFolder
);
814 hr
= UnixFolder_Constructor(NULL
, &IID_IPersistFolder2
, (void**)&persistFolder
);
816 if (!SUCCEEDED(hr
)) return hr
;
817 hr
= IPersistFolder_QueryInterface(persistFolder
, riid
, (void**)ppvOut
);
819 pidlSubFolder
= ILCombine(This
->m_pidlLocation
, pidl
);
820 IPersistFolder2_Initialize(persistFolder
, pidlSubFolder
);
821 IPersistFolder2_Release(persistFolder
);
822 ILFree(pidlSubFolder
);
827 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToStorage(IShellFolder2
* This
, LPCITEMIDLIST pidl
,
828 LPBC pbcReserved
, REFIID riid
, void** ppvObj
)
834 static HRESULT WINAPI
UnixFolder_IShellFolder2_CompareIDs(IShellFolder2
* iface
, LPARAM lParam
,
835 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
837 BOOL isEmpty1
, isEmpty2
;
839 LPITEMIDLIST firstpidl
;
843 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface
, lParam
, pidl1
, pidl2
);
845 isEmpty1
= !pidl1
|| !pidl1
->mkid
.cb
;
846 isEmpty2
= !pidl2
|| !pidl2
->mkid
.cb
;
848 if (isEmpty1
&& isEmpty2
)
849 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
851 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
853 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
855 if (_ILIsFolder(pidl1
) && !_ILIsFolder(pidl2
))
856 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
857 if (!_ILIsFolder(pidl1
) && _ILIsFolder(pidl2
))
858 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
860 compare
= CompareStringA(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
,
861 _ILGetTextPointer(pidl1
), NAME_LEN_FROM_LPSHITEMID(pidl1
),
862 _ILGetTextPointer(pidl2
), NAME_LEN_FROM_LPSHITEMID(pidl2
));
864 if ((compare
== CSTR_LESS_THAN
) || (compare
== CSTR_GREATER_THAN
))
865 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)((compare
== CSTR_LESS_THAN
)?-1:1));
867 if (pidl1
->mkid
.cb
< pidl2
->mkid
.cb
)
868 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
869 else if (pidl1
->mkid
.cb
> pidl2
->mkid
.cb
)
870 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
872 firstpidl
= ILCloneFirst(pidl1
);
873 pidl1
= ILGetNext(pidl1
);
874 pidl2
= ILGetNext(pidl2
);
876 hr
= IShellFolder2_BindToObject(iface
, firstpidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psf
);
878 hr
= IShellFolder_CompareIDs(psf
, lParam
, pidl1
, pidl2
);
879 IShellFolder2_Release(psf
);
886 static HRESULT WINAPI
UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2
* iface
, HWND hwndOwner
,
887 REFIID riid
, void** ppv
)
889 HRESULT hr
= E_INVALIDARG
;
891 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface
, hwndOwner
, riid
, ppv
);
893 if (!ppv
) return E_INVALIDARG
;
896 if (IsEqualIID(&IID_IShellView
, riid
)) {
897 LPSHELLVIEW pShellView
;
899 pShellView
= IShellView_Constructor((IShellFolder
*)iface
);
901 hr
= IShellView_QueryInterface(pShellView
, riid
, ppv
);
902 IShellView_Release(pShellView
);
909 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2
* iface
, UINT cidl
,
910 LPCITEMIDLIST
* apidl
, SFGAOF
* rgfInOut
)
912 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
913 const StatStruct
*pStatStruct
;
915 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface
, cidl
, apidl
, rgfInOut
);
917 if (!rgfInOut
|| (cidl
&& !apidl
))
921 if (!strcmp(This
->m_pszPath
, "/")) {
922 *rgfInOut
&= dwRootAttr
;
924 pStatStruct
= LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(This
->m_pidlLocation
));
925 if (!pStatStruct
) return E_FAIL
;
926 *rgfInOut
&= pStatStruct
->sfAttr
;
930 for (i
=0; i
<cidl
; i
++) {
931 pStatStruct
= LPSTATSTRUCT_FROM_LPSHITEMID(apidl
[i
]);
932 if (!pStatStruct
) return E_INVALIDARG
;
933 *rgfInOut
&= pStatStruct
->sfAttr
;
940 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2
* iface
, HWND hwndOwner
,
941 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
, UINT
* prgfInOut
, void** ppvOut
)
943 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
945 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
946 iface
, hwndOwner
, cidl
, apidl
, debugstr_guid(riid
), prgfInOut
, ppvOut
);
948 if (IsEqualIID(&IID_IContextMenu
, riid
)) {
949 *ppvOut
= ISvItemCm_Constructor((IShellFolder
*)iface
, This
->m_pidlLocation
, apidl
, cidl
);
951 } else if (IsEqualIID(&IID_IDataObject
, riid
)) {
952 *ppvOut
= IDataObject_Constructor(hwndOwner
, This
->m_pidlLocation
, apidl
, cidl
);
954 } else if (IsEqualIID(&IID_IExtractIconA
, riid
)) {
956 if (cidl
!= 1) return E_FAIL
;
957 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
958 *ppvOut
= (LPVOID
)IExtractIconA_Constructor(pidl
);
961 } else if (IsEqualIID(&IID_IExtractIconW
, riid
)) {
963 if (cidl
!= 1) return E_FAIL
;
964 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
965 *ppvOut
= (LPVOID
)IExtractIconW_Constructor(pidl
);
968 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
969 FIXME("IDropTarget\n");
971 } else if (IsEqualIID(&IID_IShellLinkW
, riid
)) {
972 FIXME("IShellLinkW\n");
974 } else if (IsEqualIID(&IID_IShellLinkA
, riid
)) {
975 FIXME("IShellLinkA\n");
978 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid
));
979 return E_NOINTERFACE
;
983 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2
* iface
,
984 LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
* lpName
)
986 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
989 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface
, pidl
, uFlags
, lpName
);
991 if ((GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) &&
992 (GET_SHGDN_RELATION(uFlags
) != SHGDN_INFOLDER
))
994 if (!pidl
->mkid
.cb
) {
995 lpName
->uType
= STRRET_CSTR
;
996 strcpy(lpName
->u
.cStr
, This
->m_pszPath
);
997 if (This
->m_dwPathMode
== PATHMODE_DOS
) {
999 GetFullPathNameA(lpName
->u
.cStr
, MAX_PATH
, path
, NULL
);
1000 PathRemoveBackslashA(path
);
1001 strcpy(lpName
->u
.cStr
, path
);
1004 IShellFolder
*pSubFolder
;
1005 USHORT emptyIDL
= 0;
1007 hr
= IShellFolder_BindToObject(iface
, pidl
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
1008 if (!SUCCEEDED(hr
)) return hr
;
1010 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, lpName
);
1011 IShellFolder_Release(pSubFolder
);
1014 char *pszFileName
= _ILGetTextPointer(pidl
);
1015 lpName
->uType
= STRRET_CSTR
;
1016 strcpy(lpName
->u
.cStr
, pszFileName
? pszFileName
: "");
1019 TRACE("--> %s\n", lpName
->u
.cStr
);
1024 static HRESULT WINAPI
UnixFolder_IShellFolder2_SetNameOf(IShellFolder2
* This
, HWND hwnd
,
1025 LPCITEMIDLIST pidl
, LPCOLESTR lpszName
, SHGDNF uFlags
, LPITEMIDLIST
* ppidlOut
)
1031 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumSearches(IShellFolder2
* iface
,
1032 IEnumExtraSearch
**ppEnum
)
1038 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2
* iface
,
1039 DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
1045 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2
* iface
,
1046 UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
1052 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2
* iface
,
1059 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2
* iface
,
1060 LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
1066 #define SHELLVIEWCOLUMNS 6
1068 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2
* iface
,
1069 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
*psd
)
1071 HRESULT hr
= E_FAIL
;
1072 struct passwd
*pPasswd
;
1073 struct group
*pGroup
;
1074 static const shvheader SFHeader
[SHELLVIEWCOLUMNS
] = {
1075 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
1076 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
1077 {IDS_SHV_COLUMN10
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
1078 {IDS_SHV_COLUMN11
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
1079 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 8},
1080 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10}
1083 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface
, pidl
, iColumn
, psd
);
1085 if (!psd
|| iColumn
>= SHELLVIEWCOLUMNS
)
1086 return E_INVALIDARG
;
1089 psd
->fmt
= SFHeader
[iColumn
].fmt
;
1090 psd
->cxChar
= SFHeader
[iColumn
].cxChar
;
1091 psd
->str
.uType
= STRRET_CSTR
;
1092 LoadStringA(shell32_hInstance
, SFHeader
[iColumn
].colnameid
, psd
->str
.u
.cStr
, MAX_PATH
);
1095 StatStruct
*pStatStruct
= LPSTATSTRUCT_FROM_LPSHITEMID(pidl
);
1096 psd
->str
.u
.cStr
[0] = '\0';
1097 psd
->str
.uType
= STRRET_CSTR
;
1100 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
|SHGDN_INFOLDER
, &psd
->str
);
1103 psd
->str
.u
.cStr
[0] = S_ISDIR(pStatStruct
->st_mode
) ? 'd' : '-';
1104 psd
->str
.u
.cStr
[1] = (pStatStruct
->st_mode
& S_IRUSR
) ? 'r' : '-';
1105 psd
->str
.u
.cStr
[2] = (pStatStruct
->st_mode
& S_IWUSR
) ? 'w' : '-';
1106 psd
->str
.u
.cStr
[3] = (pStatStruct
->st_mode
& S_IXUSR
) ? 'x' : '-';
1107 psd
->str
.u
.cStr
[4] = (pStatStruct
->st_mode
& S_IRGRP
) ? 'r' : '-';
1108 psd
->str
.u
.cStr
[5] = (pStatStruct
->st_mode
& S_IWGRP
) ? 'w' : '-';
1109 psd
->str
.u
.cStr
[6] = (pStatStruct
->st_mode
& S_IXGRP
) ? 'x' : '-';
1110 psd
->str
.u
.cStr
[7] = (pStatStruct
->st_mode
& S_IROTH
) ? 'r' : '-';
1111 psd
->str
.u
.cStr
[8] = (pStatStruct
->st_mode
& S_IWOTH
) ? 'w' : '-';
1112 psd
->str
.u
.cStr
[9] = (pStatStruct
->st_mode
& S_IXOTH
) ? 'x' : '-';
1113 psd
->str
.u
.cStr
[10] = '\0';
1116 pPasswd
= getpwuid(pStatStruct
->st_uid
);
1117 if (pPasswd
) strcpy(psd
->str
.u
.cStr
, pPasswd
->pw_name
);
1120 pGroup
= getgrgid(pStatStruct
->st_gid
);
1121 if (pGroup
) strcpy(psd
->str
.u
.cStr
, pGroup
->gr_name
);
1124 _ILGetFileSize(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1127 _ILGetFileDate(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1135 static HRESULT WINAPI
UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2
* iface
, UINT iColumn
,
1142 /* VTable for UnixFolder's IShellFolder2 interface.
1144 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl
= {
1145 UnixFolder_IShellFolder2_QueryInterface
,
1146 UnixFolder_IShellFolder2_AddRef
,
1147 UnixFolder_IShellFolder2_Release
,
1148 UnixFolder_IShellFolder2_ParseDisplayName
,
1149 UnixFolder_IShellFolder2_EnumObjects
,
1150 UnixFolder_IShellFolder2_BindToObject
,
1151 UnixFolder_IShellFolder2_BindToStorage
,
1152 UnixFolder_IShellFolder2_CompareIDs
,
1153 UnixFolder_IShellFolder2_CreateViewObject
,
1154 UnixFolder_IShellFolder2_GetAttributesOf
,
1155 UnixFolder_IShellFolder2_GetUIObjectOf
,
1156 UnixFolder_IShellFolder2_GetDisplayNameOf
,
1157 UnixFolder_IShellFolder2_SetNameOf
,
1158 UnixFolder_IShellFolder2_GetDefaultSearchGUID
,
1159 UnixFolder_IShellFolder2_EnumSearches
,
1160 UnixFolder_IShellFolder2_GetDefaultColumn
,
1161 UnixFolder_IShellFolder2_GetDefaultColumnState
,
1162 UnixFolder_IShellFolder2_GetDetailsEx
,
1163 UnixFolder_IShellFolder2_GetDetailsOf
,
1164 UnixFolder_IShellFolder2_MapColumnToSCID
1167 static HRESULT WINAPI
UnixFolder_IPersistFolder2_QueryInterface(IPersistFolder2
* This
, REFIID riid
,
1170 return UnixFolder_IShellFolder2_QueryInterface(
1171 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder2
, This
), riid
, ppvObject
);
1174 static ULONG WINAPI
UnixFolder_IPersistFolder2_AddRef(IPersistFolder2
* This
)
1176 return UnixFolder_IShellFolder2_AddRef(
1177 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder2
, This
));
1180 static ULONG WINAPI
UnixFolder_IPersistFolder2_Release(IPersistFolder2
* This
)
1182 return UnixFolder_IShellFolder2_Release(
1183 (IShellFolder2
*)ADJUST_THIS(UnixFolder
, IPersistFolder2
, This
));
1186 static HRESULT WINAPI
UnixFolder_IPersistFolder2_GetClassID(IPersistFolder2
* This
, CLSID
* pClassID
)
1192 static HRESULT WINAPI
UnixFolder_IPersistFolder2_Initialize(IPersistFolder2
* iface
, LPCITEMIDLIST pidl
)
1194 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder2
, iface
);
1196 TRACE("(iface=%p, pidl=%p)\n", iface
, pidl
);
1198 This
->m_pidlLocation
= ILClone(pidl
);
1202 if (!UNIXFS_pidl_to_path(pidl
, This
))
1205 if (!strcmp(This
->m_pszPath
, "/")) {
1206 struct stat statRoot
;
1207 if (stat(This
->m_pszPath
, &statRoot
)) return E_FAIL
;
1208 dwRootAttr
= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
;
1209 if (UNIXFS_is_dos_device(&statRoot
)) dwRootAttr
|= SFGAO_FILESYSTEM
;
1215 static HRESULT WINAPI
UnixFolder_IPersistFolder2_GetCurFolder(IPersistFolder2
* iface
, LPITEMIDLIST
* ppidl
)
1217 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder2
, iface
);
1219 TRACE ("(iface=%p, ppidl=%p)\n", iface
, ppidl
);
1223 *ppidl
= ILClone (This
->m_pidlLocation
);
1227 /* VTable for UnixFolder's IPersistFolder interface.
1229 static const IPersistFolder2Vtbl UnixFolder_IPersistFolder2_Vtbl
= {
1230 UnixFolder_IPersistFolder2_QueryInterface
,
1231 UnixFolder_IPersistFolder2_AddRef
,
1232 UnixFolder_IPersistFolder2_Release
,
1233 UnixFolder_IPersistFolder2_GetClassID
,
1234 UnixFolder_IPersistFolder2_Initialize
,
1235 UnixFolder_IPersistFolder2_GetCurFolder
1238 /******************************************************************************
1239 * Unix[Dos]Folder_Constructor [Internal]
1242 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1243 * riid [I] Interface asked for by the client.
1244 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1247 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1248 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1249 * compatible signature.
1251 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1252 * means that paths are converted from dos to unix and back at the interfaces.
1254 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, DWORD dwPathMode
) {
1255 HRESULT hr
= E_FAIL
;
1256 UnixFolder
*pUnixFolder
= SHAlloc((ULONG
)sizeof(UnixFolder
));
1259 pUnixFolder
->lpIShellFolder2Vtbl
= &UnixFolder_IShellFolder2_Vtbl
;
1260 pUnixFolder
->lpIPersistFolder2Vtbl
= &UnixFolder_IPersistFolder2_Vtbl
;
1261 pUnixFolder
->m_cRef
= 0;
1262 pUnixFolder
->m_pszPath
= NULL
;
1263 pUnixFolder
->m_apidlSubDirs
= NULL
;
1264 pUnixFolder
->m_cSubDirs
= -1;
1265 pUnixFolder
->m_dwPathMode
= dwPathMode
;
1267 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1268 hr
= UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2
, pUnixFolder
), riid
, ppv
);
1269 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2
, pUnixFolder
));
1274 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1275 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1276 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_UNIX
);
1279 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
1280 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
1281 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, PATHMODE_DOS
);
1284 /******************************************************************************
1285 * UnixSubFolderIterator
1287 * Class whose heap based objects represent iterators over the sub-directories
1288 * of a given UnixFolder object.
1291 /* UnixSubFolderIterator object layout and typedef.
1293 typedef struct _UnixSubFolderIterator
{
1294 const IEnumIDListVtbl
*lpIEnumIDListVtbl
;
1296 UnixFolder
*m_pUnixFolder
;
1299 } UnixSubFolderIterator
;
1301 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator
*iterator
) {
1302 TRACE("(iterator=%p)\n", iterator
);
1304 UnixFolder_IShellFolder2_Release((IShellFolder2
*)iterator
->m_pUnixFolder
);
1308 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList
* iface
,
1309 REFIID riid
, void** ppv
)
1311 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
1313 if (!ppv
) return E_INVALIDARG
;
1315 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumIDList
, riid
)) {
1319 return E_NOINTERFACE
;
1322 IEnumIDList_AddRef(iface
);
1326 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList
* iface
)
1328 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1330 TRACE("(iface=%p)\n", iface
);
1332 return InterlockedIncrement(&This
->m_cRef
);
1335 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList
* iface
)
1337 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1340 TRACE("(iface=%p)\n", iface
);
1342 cRef
= InterlockedDecrement(&This
->m_cRef
);
1345 UnixSubFolderIterator_Destroy(This
);
1350 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList
* iface
, ULONG celt
,
1351 LPITEMIDLIST
* rgelt
, ULONG
* pceltFetched
)
1353 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1356 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface
, celt
, rgelt
, pceltFetched
);
1358 for (i
=0; (i
< celt
) && (This
->m_cIdx
< This
->m_pUnixFolder
->m_cSubDirs
); This
->m_cIdx
++) {
1359 LPITEMIDLIST pCurrent
= This
->m_pUnixFolder
->m_apidlSubDirs
[This
->m_cIdx
];
1360 if (UNIXFS_is_pidl_of_type(pCurrent
, This
->m_fFilter
)) {
1361 rgelt
[i
] = ILClone(pCurrent
);
1369 return i
== celt
? S_OK
: S_FALSE
;
1372 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList
* iface
, ULONG celt
)
1374 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1377 TRACE("(iface=%p, celt=%ld)\n", iface
, celt
);
1379 for (i
=0; i
< celt
; i
++) {
1380 while (This
->m_cIdx
< This
->m_pUnixFolder
->m_cSubDirs
&&
1381 !UNIXFS_is_pidl_of_type(This
->m_pUnixFolder
->m_apidlSubDirs
[This
->m_cIdx
], This
->m_fFilter
))
1388 if (This
->m_cIdx
> This
->m_pUnixFolder
->m_cSubDirs
) {
1389 This
->m_cIdx
= This
->m_pUnixFolder
->m_cSubDirs
;
1396 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList
* iface
)
1398 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
1400 TRACE("(iface=%p)\n", iface
);
1407 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList
* This
,
1408 IEnumIDList
** ppenum
)
1414 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1416 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl
= {
1417 UnixSubFolderIterator_IEnumIDList_QueryInterface
,
1418 UnixSubFolderIterator_IEnumIDList_AddRef
,
1419 UnixSubFolderIterator_IEnumIDList_Release
,
1420 UnixSubFolderIterator_IEnumIDList_Next
,
1421 UnixSubFolderIterator_IEnumIDList_Skip
,
1422 UnixSubFolderIterator_IEnumIDList_Reset
,
1423 UnixSubFolderIterator_IEnumIDList_Clone
1426 static IUnknown
*UnixSubFolderIterator_Construct(UnixFolder
*pUnixFolder
, SHCONTF fFilter
) {
1427 UnixSubFolderIterator
*iterator
;
1429 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
1431 iterator
= SHAlloc((ULONG
)sizeof(UnixSubFolderIterator
));
1432 iterator
->lpIEnumIDListVtbl
= &UnixSubFolderIterator_IEnumIDList_Vtbl
;
1433 iterator
->m_cRef
= 0;
1434 iterator
->m_cIdx
= 0;
1435 iterator
->m_pUnixFolder
= pUnixFolder
;
1436 iterator
->m_fFilter
= fFilter
;
1438 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList
*)iterator
);
1439 UnixFolder_IShellFolder2_AddRef((IShellFolder2
*)pUnixFolder
);
1441 return (IUnknown
*)iterator
;