Return correct HRESULT code in UnixFolder's IEnumIDList::Next.
[wine/gsoc_dplay.git] / dlls / shell32 / shfldr_unixfs.c
blobf586605f20d3a895774e0f42e1b84709aaa8b1fc
1 /*
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
21 #include "config.h"
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <limits.h>
25 #include <dirent.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #ifdef HAVE_SYS_STAT_H
30 # include <sys/stat.h>
31 #endif
32 #ifdef HAVE_PWD_H
33 # include <pwd.h>
34 #endif
35 #include <grp.h>
36 #include <limits.h>
38 #define COBJMACROS
39 #define NONAMELESSUNION
40 #define NONAMELESSSTRUCT
42 #include "windef.h"
43 #include "winbase.h"
44 #include "winuser.h"
45 #include "objbase.h"
46 #include "winreg.h"
47 #include "shlwapi.h"
48 #include "winternl.h"
49 #include "wine/debug.h"
51 #include "shell32_main.h"
52 #include "shellfolder.h"
53 #include "shfldr.h"
54 #include "shresdef.h"
55 #include "pidl.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(shell);
59 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
60 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
62 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
63 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
65 /* FileStruct reserves one byte for szNames, thus we don't have to
66 * alloc a byte for the terminating '\0' of 'name'. Two of the
67 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
68 * type field. One is for FileStruct's szNames field, to terminate
69 * the alternate DOS name, which we don't use here. And then there's
70 * the additional StatStruct.
72 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
73 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char)+sizeof(StatStruct))
74 #define NAME_LEN_FROM_LPSHITEMID(s) \
75 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char)-sizeof(StatStruct))
76 #define LPSTATSTRUCT_FROM_LPSHITEMID(s) \
77 (((s) && (((LPSHITEMID)s)->cb > SHITEMID_LEN_FROM_NAME_LEN(0))) ? \
78 ((StatStruct*)(((LPBYTE)s)+((LPSHITEMID)s)->cb-sizeof(StatStruct))) : \
79 (NULL))
81 #define PATHMODE_UNIX 0
82 #define PATHMODE_DOS 1
84 /* ShellFolder attributes of the root folder ('/') */
85 static DWORD dwRootAttr = 0;
87 /* This structure is appended to shell32's FileStruct type in IDLs to store unix
88 * filesystem specific informationen extracted with the stat system call.
90 typedef struct tagStatStruct {
91 mode_t st_mode;
92 uid_t st_uid;
93 gid_t st_gid;
94 SFGAOF sfAttr;
95 } StatStruct;
97 /* UnixFolder object layout and typedef.
99 typedef struct _UnixFolder {
100 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
101 const IPersistFolder2Vtbl *lpIPersistFolder2Vtbl;
102 const ISFHelperVtbl *lpISFHelperVtbl;
103 LONG m_cRef;
104 CHAR *m_pszPath;
105 LPITEMIDLIST m_pidlLocation;
106 LPITEMIDLIST *m_apidlSubDirs;
107 LONG m_cSubDirs;
108 DWORD m_dwPathMode;
109 } UnixFolder;
111 /******************************************************************************
112 * UNIXFS_is_rooted_at_desktop [Internal]
114 * Checks if the unixfs namespace extension is rooted at desktop level.
116 * RETURNS
117 * TRUE, if unixfs is rooted at desktop level
118 * FALSE, if not.
120 BOOL UNIXFS_is_rooted_at_desktop(void) {
121 HKEY hKey;
122 WCHAR *pwszCLSID_UnixDosFolder, wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
123 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
124 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
125 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
126 'N','a','m','e','S','p','a','c','e','\\',0 };
128 if (FAILED(StringFromCLSID(&CLSID_UnixDosFolder, &pwszCLSID_UnixDosFolder)))
129 return FALSE;
131 lstrcatW(wszRootedAtDesktop, pwszCLSID_UnixDosFolder);
132 CoTaskMemFree(pwszCLSID_UnixDosFolder);
134 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
135 return FALSE;
137 RegCloseKey(hKey);
138 return TRUE;
141 /******************************************************************************
142 * UNIXFS_is_pidl_of_type [INTERNAL]
144 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
146 * PARAMS
147 * pIDL [I] The ITEMIDLIST to be checked.
148 * fFilter [I] Shell condition flags, which specify the filter.
150 * RETURNS
151 * TRUE, if pIDL is accepted by fFilter
152 * FALSE, otherwise
154 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
155 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
156 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
157 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
159 return FALSE;
161 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
162 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
163 return FALSE;
166 /******************************************************************************
167 * UNIXFS_is_dos_device [Internal]
169 * Determines if a unix directory corresponds to any dos device.
171 * PARAMS
172 * statPath [I] The stat struct of the directory, as returned by stat(2).
174 * RETURNS
175 * TRUE, if statPath corresponds to any dos drive letter
176 * FALSE, otherwise
178 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
179 struct stat statDrive;
180 char *pszDrivePath;
181 DWORD dwDriveMap;
182 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
184 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
185 if (!(dwDriveMap & 0x1)) continue;
186 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
187 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
188 HeapFree(GetProcessHeap(), 0, pszDrivePath);
189 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
190 return TRUE;
193 return FALSE;
196 /******************************************************************************
197 * UNIXFS_get_unix_path [Internal]
199 * Convert an absolute dos path to an absolute canonicalized unix path.
200 * Evaluate "/.", "/.." and symbolic links.
202 * PARAMS
203 * pszDosPath [I] An absolute dos path
204 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
206 * RETURNS
207 * Success, TRUE
208 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
210 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
212 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
213 struct stat fileStat;
215 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
217 if (!pszDosPath || pszDosPath[1] != ':')
218 return FALSE;
220 pszUnixPath = wine_get_unix_file_name(pszDosPath);
221 if (!pszUnixPath) return FALSE;
222 strcpy(szPath, pszUnixPath);
223 HeapFree(GetProcessHeap(), 0, pszUnixPath);
225 /* pCanonicalTail always points to the end of the canonical path constructed
226 * thus far. pPathTail points to the still to be processed part of the input
227 * path. pElement points to the path element currently investigated.
229 *pszCanonicalPath = '\0';
230 pCanonicalTail = pszCanonicalPath;
231 pPathTail = szPath;
233 do {
234 char cTemp;
235 int cLinks = 0;
237 pElement = pPathTail;
238 pPathTail = strchr(pPathTail+1, '/');
239 if (!pPathTail) /* Last path element may not be terminated by '/'. */
240 pPathTail = pElement + strlen(pElement);
241 /* Temporarily terminate the current path element. Will be restored later. */
242 cTemp = *pPathTail;
243 *pPathTail = '\0';
245 /* Skip "/." path elements */
246 if (!strcmp("/.", pElement)) {
247 *pPathTail = cTemp;
248 continue;
251 /* Remove last element in canonical path for "/.." elements, then skip. */
252 if (!strcmp("/..", pElement)) {
253 char *pTemp = strrchr(pszCanonicalPath, '/');
254 if (pTemp)
255 pCanonicalTail = pTemp;
256 *pCanonicalTail = '\0';
257 *pPathTail = cTemp;
258 continue;
261 /* lstat returns zero on success. */
262 if (lstat(szPath, &fileStat))
263 return FALSE;
265 if (S_ISLNK(fileStat.st_mode)) {
266 char szSymlink[FILENAME_MAX];
267 int cLinkLen, cTailLen;
269 /* Avoid infinite loop for recursive links. */
270 if (++cLinks > 64)
271 return FALSE;
273 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
274 if (cLinkLen < 0)
275 return FALSE;
277 *pPathTail = cTemp;
278 cTailLen = strlen(pPathTail);
280 if (szSymlink[0] == '/') {
281 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
282 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
283 return FALSE;
285 /* Avoid double slashes. */
286 if (szSymlink[cLinkLen-1] == '/' && pPathTail[0] == '/') {
287 szSymlink[cLinkLen-1] = '\0';
288 cLinkLen--;
291 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
292 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
293 *pszCanonicalPath = '\0';
294 pCanonicalTail = pszCanonicalPath;
295 pPathTail = szPath;
296 } else {
297 /* Relative link. Expand into szPath and continue. */
298 char szTemp[FILENAME_MAX];
299 int cTailLen = strlen(pPathTail);
301 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
302 return FALSE;
304 memcpy(szTemp, pPathTail, cTailLen + 1);
305 memcpy(pElement + 1, szSymlink, cLinkLen);
306 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
307 pPathTail = pElement;
309 } else {
310 /* Regular directory or file. Copy to canonical path */
311 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
312 return FALSE;
314 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
315 pCanonicalTail += pPathTail - pElement;
316 *pPathTail = cTemp;
318 } while (pPathTail[0] == '/');
320 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
322 return TRUE;
325 /******************************************************************************
326 * UNIXFS_build_shitemid [Internal]
328 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
329 * buffer 'pIDL'. Decorates the SHITEMID with information from a stat system call.
331 * PARAMS
332 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
333 * bParentIsFS [I] Set, if the parent of the last path component is within the wine filesystem.
334 * pIDL [O] SHITEMID will be constructed here.
336 * RETURNS
337 * Success: A pointer to the terminating '\0' character of path.
338 * Failure: NULL
340 * NOTES
341 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
342 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
343 * a 0 USHORT value.
345 static char* UNIXFS_build_shitemid(char *pszUnixPath, BOOL bParentIsFS, void *pIDL) {
346 LARGE_INTEGER time;
347 FILETIME fileTime;
348 LPPIDLDATA pIDLData;
349 struct stat fileStat;
350 StatStruct *pStatStruct;
351 char *pszComponent;
352 int cComponentLen;
354 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
356 /* Compute the SHITEMID's length and wipe it. */
357 pszComponent = strrchr(pszUnixPath, '/') + 1;
358 cComponentLen = strlen(pszComponent);
359 memset(pIDL, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen));
360 ((LPSHITEMID)pIDL)->cb = SHITEMID_LEN_FROM_NAME_LEN(cComponentLen) ;
362 /* We are only interested in regular files and directories. */
363 if (stat(pszUnixPath, &fileStat)) return NULL;
364 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
366 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pIDL);
367 pStatStruct->st_mode = fileStat.st_mode;
368 pStatStruct->st_uid = fileStat.st_uid;
369 pStatStruct->st_gid = fileStat.st_gid;
370 if (S_ISDIR(fileStat.st_mode))
371 pStatStruct->sfAttr = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
372 else
373 pStatStruct->sfAttr = SFGAO_CANRENAME;
374 if (bParentIsFS || UNIXFS_is_dos_device(&fileStat)) pStatStruct->sfAttr |= SFGAO_FILESYSTEM;
376 /* Set shell32's standard SHITEMID data fields. */
377 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
378 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
379 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
380 RtlSecondsSince1970ToTime( fileStat.st_mtime, &time );
381 fileTime.dwLowDateTime = time.u.LowPart;
382 fileTime.dwHighDateTime = time.u.HighPart;
383 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
384 pIDLData->u.file.uFileAttribs = 0;
385 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
386 if (pszComponent[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
387 memcpy(pIDLData->u.file.szNames, pszComponent, cComponentLen);
389 return pszComponent + cComponentLen;
392 /******************************************************************************
393 * UNIXFS_path_to_pidl [Internal]
395 * PARAMS
396 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
397 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
398 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
400 * RETURNS
401 * Success: TRUE
402 * Failure: FALSE, invalid params or out of memory
404 * NOTES
405 * pUnixFolder also carries the information if the path is expected to be unix or dos.
407 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
408 LPITEMIDLIST pidl;
409 int cSubDirs, cPidlLen, cPathLen;
410 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
411 BOOL bParentIsFS = dwRootAttr & SFGAO_FILESYSTEM;
413 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
415 if (!ppidl || !path)
416 return FALSE;
418 /* Build an absolute path and let pNextPathElement point to the interesting
419 * relative sub-path. We need the absolute path to call 'stat', but the pidl
420 * will only contain the relative part.
422 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
424 /* Absolute dos path. Convert to unix */
425 if (!UNIXFS_get_unix_path(path, szCompletePath))
426 return FALSE;
427 pNextPathElement = szCompletePath;
429 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
431 /* Absolute unix path. Just convert to ANSI. */
432 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
433 pNextPathElement = szCompletePath;
435 else
437 /* Relative dos or unix path. Concat with this folder's path */
438 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
439 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
440 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath + cBasePathLen,
441 FILENAME_MAX - cBasePathLen, NULL, NULL);
442 pNextPathElement = szCompletePath + cBasePathLen - 1;
444 /* If in dos mode, replace '\' with '/' */
445 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
446 char *pBackslash = strchr(pNextPathElement, '\\');
447 while (pBackslash) {
448 *pBackslash = '/';
449 pBackslash = strchr(pBackslash, '\\');
454 /* Special case for the root folder. */
455 if (!strcmp(szCompletePath, "/")) {
456 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(sizeof(USHORT));
457 if (!pidl) return FALSE;
458 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
459 return TRUE;
462 /* Remove trailing slash, if present */
463 cPathLen = strlen(szCompletePath);
464 if (szCompletePath[cPathLen-1] == '/')
465 szCompletePath[cPathLen-1] = '\0';
467 if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
468 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
469 return FALSE;
472 /* At this point, we have an absolute unix path in szCompletePath
473 * and the relative portion of it in pNextPathElement. Both starting with '/'
474 * and _not_ terminated by a '/'. */
475 TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
477 /* Count the number of sub-directories in the path */
478 cSubDirs = 0;
479 pSlash = pNextPathElement;
480 while (pSlash) {
481 cSubDirs++;
482 pSlash = strchr(pSlash+1, '/');
485 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
486 * characters, which are not stored in the ITEMIDLIST. */
487 cPidlLen = strlen(pNextPathElement) - cSubDirs + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
488 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
489 if (!pidl) return FALSE;
491 /* Concatenate the SHITEMIDs of the sub-directories. */
492 while (*pNextPathElement) {
493 pSlash = strchr(pNextPathElement+1, '/');
494 if (pSlash) *pSlash = '\0';
495 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, bParentIsFS, pidl);
496 if (pSlash) *pSlash = '/';
498 if (!pNextPathElement) {
499 SHFree(pidl);
500 return FALSE;
502 if (!bParentIsFS && (LPSTATSTRUCT_FROM_LPSHITEMID(pidl)->sfAttr & SFGAO_FILESYSTEM))
503 bParentIsFS = TRUE;
504 pidl = ILGetNext(pidl);
506 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
508 if ((int)pidl-(int)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
509 ERR("Computed length of pidl incorrect. Please report.\n");
511 return TRUE;
514 /******************************************************************************
515 * UNIXFS_pidl_to_path [Internal]
517 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
519 * PARAMS
520 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
521 * path [O] The corresponding unix path as a zero terminated ascii string
523 * RETURNS
524 * Success: TRUE
525 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
527 static BOOL UNIXFS_pidl_to_path(LPCITEMIDLIST pidl, UnixFolder *pUnixFolder) {
528 LPCITEMIDLIST current = pidl, root;
529 DWORD dwPathLen;
530 char *pNextDir, szBasePath[FILENAME_MAX] = "/";
532 TRACE("(pidl=%p, pUnixFolder=%p)\n", pidl, pUnixFolder);
533 pdump(pidl);
535 pUnixFolder->m_pszPath = NULL;
537 /* Find the UnixFolderClass root */
538 while (current->mkid.cb) {
539 if (_ILIsDrive(current) || /* The dos drive, which maps to '/' */
540 (_ILIsSpecialFolder(current) &&
541 (IsEqualIID(&CLSID_UnixFolder, _ILGetGUIDPointer(current)) ||
542 IsEqualIID(&CLSID_UnixDosFolder, _ILGetGUIDPointer(current)))))
544 break;
546 current = ILGetNext(current);
549 if (current && current->mkid.cb) {
550 root = current = ILGetNext(current);
551 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
552 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
553 /* Path rooted at Desktop */
554 WCHAR wszDesktopPath[MAX_PATH];
555 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOP, FALSE)))
556 return FALSE;
557 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
558 return FALSE;
559 dwPathLen = strlen(szBasePath) + 1;
560 root = current;
561 } else {
562 ERR("Unknown pidl type!\n");
563 pdump(pidl);
564 return FALSE;
567 /* Determine the path's length bytes */
568 while (current && current->mkid.cb) {
569 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
570 current = ILGetNext(current);
573 /* Build the path */
574 pUnixFolder->m_pszPath = pNextDir = SHAlloc(dwPathLen);
575 if (!pUnixFolder->m_pszPath) {
576 WARN("SHAlloc failed!\n");
577 return FALSE;
579 current = root;
580 strcpy(pNextDir, szBasePath);
581 pNextDir += strlen(szBasePath);
582 while (current && current->mkid.cb) {
583 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
584 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
585 *pNextDir++ = '/';
586 current = ILGetNext(current);
588 *pNextDir='\0';
590 TRACE("--> %s\n", pUnixFolder->m_pszPath);
591 return TRUE;
594 /******************************************************************************
595 * UNIXFS_build_subfolder_pidls [Internal]
597 * Builds an array of subfolder PIDLs relative to a unix directory
599 * PARAMS
600 * path [I] Name of a unix directory as a zero terminated ascii string
601 * apidl [O] The array of PIDLs
602 * pCount [O] Size of apidl
604 * RETURNS
605 * Success: TRUE
606 * Failure: FALSE, path is not a valid unix directory or out of memory
608 * NOTES
609 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
610 * to release each PIDL as well as the array itself with SHFree.
612 static BOOL UNIXFS_build_subfolder_pidls(UnixFolder *pUnixFolder)
614 struct dirent *pDirEntry;
615 struct stat fileStat;
616 DIR *dir;
617 DWORD cDirEntries, i;
618 USHORT sLen;
619 char *pszFQPath;
620 BOOL bParentIsFS = dwRootAttr & SFGAO_FILESYSTEM;
622 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
624 /* For updates: If there already is an initialized list, release it */
625 if (pUnixFolder->m_cSubDirs > 0) {
626 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
627 SHFree(pUnixFolder->m_apidlSubDirs[i]);
628 SHFree(pUnixFolder->m_apidlSubDirs);
631 pUnixFolder->m_apidlSubDirs = NULL;
632 pUnixFolder->m_cSubDirs = 0;
634 if (pUnixFolder->m_pidlLocation) {
635 StatStruct *statStruct =
636 LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(pUnixFolder->m_pidlLocation));
637 if (statStruct) bParentIsFS = statStruct->sfAttr & SFGAO_FILESYSTEM;
640 dir = opendir(pUnixFolder->m_pszPath);
641 if (!dir) {
642 WARN("Failed to open directory '%s'.\n", pUnixFolder->m_pszPath);
643 return FALSE;
646 /* Allocate space for fully qualified paths */
647 pszFQPath = SHAlloc(strlen(pUnixFolder->m_pszPath) + PATH_MAX);
648 if (!pszFQPath) {
649 WARN("SHAlloc failed!\n");
650 return FALSE;
653 /* Count number of directory entries. */
654 for (cDirEntries = 0, pDirEntry = readdir(dir); pDirEntry; pDirEntry = readdir(dir)) {
655 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
656 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
657 if (!stat(pszFQPath, &fileStat) && (S_ISDIR(fileStat.st_mode) || S_ISREG(fileStat.st_mode))) cDirEntries++;
660 /* If there are no entries, we are done. */
661 if (cDirEntries == 0) {
662 closedir(dir);
663 SHFree(pszFQPath);
664 return TRUE;
667 /* Allocate the array of PIDLs */
668 pUnixFolder->m_apidlSubDirs = SHAlloc(cDirEntries * sizeof(LPITEMIDLIST));
669 if (!pUnixFolder->m_apidlSubDirs) {
670 WARN("SHAlloc failed!\n");
671 return FALSE;
674 /* Allocate and initialize one SHITEMID per sub-directory. */
675 for (rewinddir(dir), pDirEntry = readdir(dir), i = 0; pDirEntry; pDirEntry = readdir(dir)) {
676 LPSHITEMID pid;
678 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
680 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
682 sLen = strlen(pDirEntry->d_name);
683 pid = (LPSHITEMID)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen)+sizeof(USHORT));
684 if (!pid) {
685 WARN("SHAlloc failed!\n");
686 return FALSE;
688 if (!UNIXFS_build_shitemid(pszFQPath, bParentIsFS, pid)) {
689 SHFree(pid);
690 continue;
692 memset(((PBYTE)pid)+pid->cb, 0, sizeof(USHORT));
694 pUnixFolder->m_apidlSubDirs[i++] = (LPITEMIDLIST)pid;
697 pUnixFolder->m_cSubDirs = i;
698 closedir(dir);
699 SHFree(pszFQPath);
701 return TRUE;
704 /******************************************************************************
705 * UnixFolder
707 * Class whose heap based instances represent unix filesystem directories.
710 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
711 DWORD i;
713 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
715 if (pUnixFolder->m_apidlSubDirs)
716 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
717 SHFree(pUnixFolder->m_apidlSubDirs[i]);
718 SHFree(pUnixFolder->m_apidlSubDirs);
719 SHFree(pUnixFolder->m_pszPath);
720 ILFree(pUnixFolder->m_pidlLocation);
721 SHFree(pUnixFolder);
724 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
725 void **ppv)
727 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
729 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
731 if (!ppv) return E_INVALIDARG;
733 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
734 IsEqualIID(&IID_IShellFolder2, riid))
736 *ppv = &This->lpIShellFolder2Vtbl;
737 } else if (IsEqualIID(&IID_IPersistFolder2, riid) || IsEqualIID(&IID_IPersistFolder, riid) ||
738 IsEqualIID(&IID_IPersist, riid))
740 *ppv = &This->lpIPersistFolder2Vtbl;
741 } else if (IsEqualIID(&IID_ISFHelper, riid)) {
742 *ppv = &This->lpISFHelperVtbl;
743 } else {
744 *ppv = NULL;
745 return E_NOINTERFACE;
748 IUnknown_AddRef((IUnknown*)*ppv);
749 return S_OK;
752 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
753 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
755 TRACE("(iface=%p)\n", iface);
757 return InterlockedIncrement(&This->m_cRef);
760 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
761 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
762 ULONG cRef;
764 TRACE("(iface=%p)\n", iface);
766 cRef = InterlockedDecrement(&This->m_cRef);
768 if (!cRef)
769 UnixFolder_Destroy(This);
771 return cRef;
774 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
775 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
776 ULONG* pdwAttributes)
778 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
779 BOOL result;
781 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
782 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
783 pchEaten, ppidl, pdwAttributes);
785 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
786 if (result && pdwAttributes && *pdwAttributes)
788 IShellFolder *pParentSF;
789 LPCITEMIDLIST pidlLast;
790 HRESULT hr;
792 hr = SHBindToParent(This->m_pidlLocation, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
793 if (FAILED(hr)) return E_FAIL;
794 IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
795 IShellFolder_Release(pParentSF);
798 if (!result) TRACE("FAILED!\n");
799 return result ? S_OK : E_FAIL;
802 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter);
804 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
805 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
807 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
808 IUnknown *newIterator;
809 HRESULT hr;
811 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
812 iface, hwndOwner, grfFlags, ppEnumIDList);
814 if (This->m_cSubDirs == -1)
815 UNIXFS_build_subfolder_pidls(This);
817 newIterator = UnixSubFolderIterator_Construct(This, grfFlags);
818 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
819 IUnknown_Release(newIterator);
821 return hr;
824 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
825 LPBC pbcReserved, REFIID riid, void** ppvOut)
827 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
828 IPersistFolder2 *persistFolder;
829 LPITEMIDLIST pidlSubFolder;
830 HRESULT hr;
832 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
833 iface, pidl, pbcReserved, riid, ppvOut);
835 if (!pidl || !pidl->mkid.cb)
836 return E_INVALIDARG;
838 if (This->m_dwPathMode == PATHMODE_DOS)
839 hr = UnixDosFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
840 else
841 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
843 if (!SUCCEEDED(hr)) return hr;
844 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
846 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
847 IPersistFolder2_Initialize(persistFolder, pidlSubFolder);
848 IPersistFolder2_Release(persistFolder);
849 ILFree(pidlSubFolder);
851 return hr;
854 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
855 LPBC pbcReserved, REFIID riid, void** ppvObj)
857 TRACE("stub\n");
858 return E_NOTIMPL;
861 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
862 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
864 BOOL isEmpty1, isEmpty2;
865 HRESULT hr = E_FAIL;
866 LPITEMIDLIST firstpidl;
867 IShellFolder2 *psf;
868 int compare;
870 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
872 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
873 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
875 if (isEmpty1 && isEmpty2)
876 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
877 else if (isEmpty1)
878 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
879 else if (isEmpty2)
880 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
882 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
883 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
884 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
885 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
887 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
888 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
889 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
891 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
892 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
894 if (pidl1->mkid.cb < pidl2->mkid.cb)
895 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
896 else if (pidl1->mkid.cb > pidl2->mkid.cb)
897 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
899 firstpidl = ILCloneFirst(pidl1);
900 pidl1 = ILGetNext(pidl1);
901 pidl2 = ILGetNext(pidl2);
903 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
904 if (SUCCEEDED(hr)) {
905 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
906 IShellFolder2_Release(psf);
909 ILFree(firstpidl);
910 return hr;
913 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
914 REFIID riid, void** ppv)
916 HRESULT hr = E_INVALIDARG;
918 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
920 if (!ppv) return E_INVALIDARG;
921 *ppv = NULL;
923 if (IsEqualIID(&IID_IShellView, riid)) {
924 LPSHELLVIEW pShellView;
926 pShellView = IShellView_Constructor((IShellFolder*)iface);
927 if (pShellView) {
928 hr = IShellView_QueryInterface(pShellView, riid, ppv);
929 IShellView_Release(pShellView);
933 return hr;
936 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
937 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
939 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
940 const StatStruct *pStatStruct;
942 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
944 if (!rgfInOut || (cidl && !apidl))
945 return E_INVALIDARG;
947 if (cidl == 0) {
948 if (!strcmp(This->m_pszPath, "/")) {
949 *rgfInOut &= dwRootAttr;
950 } else {
951 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(ILFindLastID(This->m_pidlLocation));
952 if (!pStatStruct) return E_FAIL;
953 *rgfInOut &= pStatStruct->sfAttr;
955 } else {
956 UINT i;
957 for (i=0; i<cidl; i++) {
958 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(apidl[i]);
959 if (!pStatStruct) return E_INVALIDARG;
960 *rgfInOut &= pStatStruct->sfAttr;
964 return S_OK;
967 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
968 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
970 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
972 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
973 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
975 if (IsEqualIID(&IID_IContextMenu, riid)) {
976 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
977 return S_OK;
978 } else if (IsEqualIID(&IID_IDataObject, riid)) {
979 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
980 return S_OK;
981 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
982 LPITEMIDLIST pidl;
983 if (cidl != 1) return E_FAIL;
984 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
985 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
986 SHFree(pidl);
987 return S_OK;
988 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
989 LPITEMIDLIST pidl;
990 if (cidl != 1) return E_FAIL;
991 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
992 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
993 SHFree(pidl);
994 return S_OK;
995 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
996 FIXME("IDropTarget\n");
997 return E_FAIL;
998 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
999 FIXME("IShellLinkW\n");
1000 return E_FAIL;
1001 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
1002 FIXME("IShellLinkA\n");
1003 return E_FAIL;
1004 } else {
1005 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
1006 return E_NOINTERFACE;
1010 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
1011 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
1013 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1014 HRESULT hr = S_OK;
1016 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
1018 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
1019 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
1021 if (!pidl->mkid.cb) {
1022 lpName->uType = STRRET_CSTR;
1023 strcpy(lpName->u.cStr, This->m_pszPath);
1024 if (This->m_dwPathMode == PATHMODE_DOS) {
1025 char path[MAX_PATH];
1026 GetFullPathNameA(lpName->u.cStr, MAX_PATH, path, NULL);
1027 PathRemoveBackslashA(path);
1028 strcpy(lpName->u.cStr, path);
1030 } else {
1031 IShellFolder *pSubFolder;
1032 USHORT emptyIDL = 0;
1034 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
1035 if (!SUCCEEDED(hr)) return hr;
1037 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
1038 IShellFolder_Release(pSubFolder);
1040 } else {
1041 char *pszFileName = _ILGetTextPointer(pidl);
1042 lpName->uType = STRRET_CSTR;
1043 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
1046 TRACE("--> %s\n", lpName->u.cStr);
1048 return hr;
1051 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd,
1052 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
1054 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1056 char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
1057 int cBasePathLen = lstrlenA(This->m_pszPath);
1058 struct stat statDest;
1059 LPITEMIDLIST pidlNew;
1061 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
1062 iface, hwnd, pidl, debugstr_w(lpszName), uFlags, ppidlOut);
1064 /* pidl has to contain a single non-empty SHITEMID */
1065 if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
1066 return E_INVALIDARG;
1068 if (ppidlOut)
1069 *ppidlOut = NULL;
1071 /* build source path */
1072 memcpy(szSrc, This->m_pszPath, cBasePathLen);
1073 lstrcpyA(szSrc+cBasePathLen, _ILGetTextPointer(pidl));
1075 /* build destination path */
1076 if (uFlags & SHGDN_FORPARSING) { /* absolute path in lpszName */
1077 WideCharToMultiByte(CP_ACP, 0, lpszName, -1, szDest, FILENAME_MAX, NULL, NULL);
1078 } else {
1079 memcpy(szDest, This->m_pszPath, cBasePathLen);
1080 WideCharToMultiByte(CP_ACP, 0, lpszName, -1, szDest+cBasePathLen,
1081 FILENAME_MAX-cBasePathLen, NULL, NULL);
1084 TRACE("src=%s dest=%s\n", szSrc, szDest);
1086 /* Fail, if destination does already exist */
1087 if (!stat(szDest, &statDest))
1088 return E_FAIL;
1090 /* Rename the file and inform the shell */
1091 if (!rename(szSrc, szDest) && UNIXFS_path_to_pidl(This, lpszName, &pidlNew)) {
1092 LPITEMIDLIST pidlSrc = ILCombine(This->m_pidlLocation, pidl);
1093 LPITEMIDLIST pidlDest = ILCombine(This->m_pidlLocation, pidlNew);
1094 UNIXFS_build_subfolder_pidls(This); /* Update list of children */
1095 if (_ILIsFolder(pidlNew))
1096 SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
1097 else
1098 SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
1099 ILFree(pidlSrc);
1100 ILFree(pidlDest);
1101 if (ppidlOut)
1102 *ppidlOut = pidlNew;
1103 else
1104 ILFree(pidlNew);
1105 return S_OK;
1107 return E_FAIL;
1110 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
1111 IEnumExtraSearch **ppEnum)
1113 TRACE("stub\n");
1114 return E_NOTIMPL;
1117 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
1118 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
1120 TRACE("stub\n");
1121 return E_NOTIMPL;
1124 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
1125 UINT iColumn, SHCOLSTATEF *pcsFlags)
1127 TRACE("stub\n");
1128 return E_NOTIMPL;
1131 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1132 GUID *pguid)
1134 TRACE("stub\n");
1135 return E_NOTIMPL;
1138 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1139 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1141 TRACE("stub\n");
1142 return E_NOTIMPL;
1145 #define SHELLVIEWCOLUMNS 6
1147 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1148 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1150 HRESULT hr = E_FAIL;
1151 struct passwd *pPasswd;
1152 struct group *pGroup;
1153 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1154 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1155 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1156 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1157 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1158 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 8},
1159 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
1162 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1164 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1165 return E_INVALIDARG;
1167 if (!pidl) {
1168 psd->fmt = SFHeader[iColumn].fmt;
1169 psd->cxChar = SFHeader[iColumn].cxChar;
1170 psd->str.uType = STRRET_CSTR;
1171 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1172 return S_OK;
1173 } else {
1174 StatStruct *pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pidl);
1175 psd->str.u.cStr[0] = '\0';
1176 psd->str.uType = STRRET_CSTR;
1177 switch (iColumn) {
1178 case 0:
1179 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1180 break;
1181 case 1:
1182 psd->str.u.cStr[0] = S_ISDIR(pStatStruct->st_mode) ? 'd' : '-';
1183 psd->str.u.cStr[1] = (pStatStruct->st_mode & S_IRUSR) ? 'r' : '-';
1184 psd->str.u.cStr[2] = (pStatStruct->st_mode & S_IWUSR) ? 'w' : '-';
1185 psd->str.u.cStr[3] = (pStatStruct->st_mode & S_IXUSR) ? 'x' : '-';
1186 psd->str.u.cStr[4] = (pStatStruct->st_mode & S_IRGRP) ? 'r' : '-';
1187 psd->str.u.cStr[5] = (pStatStruct->st_mode & S_IWGRP) ? 'w' : '-';
1188 psd->str.u.cStr[6] = (pStatStruct->st_mode & S_IXGRP) ? 'x' : '-';
1189 psd->str.u.cStr[7] = (pStatStruct->st_mode & S_IROTH) ? 'r' : '-';
1190 psd->str.u.cStr[8] = (pStatStruct->st_mode & S_IWOTH) ? 'w' : '-';
1191 psd->str.u.cStr[9] = (pStatStruct->st_mode & S_IXOTH) ? 'x' : '-';
1192 psd->str.u.cStr[10] = '\0';
1193 break;
1194 case 2:
1195 pPasswd = getpwuid(pStatStruct->st_uid);
1196 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1197 break;
1198 case 3:
1199 pGroup = getgrgid(pStatStruct->st_gid);
1200 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1201 break;
1202 case 4:
1203 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1204 break;
1205 case 5:
1206 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1207 break;
1211 return hr;
1214 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1215 SHCOLUMNID *pscid)
1217 TRACE("stub\n");
1218 return E_NOTIMPL;
1221 /* VTable for UnixFolder's IShellFolder2 interface.
1223 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1224 UnixFolder_IShellFolder2_QueryInterface,
1225 UnixFolder_IShellFolder2_AddRef,
1226 UnixFolder_IShellFolder2_Release,
1227 UnixFolder_IShellFolder2_ParseDisplayName,
1228 UnixFolder_IShellFolder2_EnumObjects,
1229 UnixFolder_IShellFolder2_BindToObject,
1230 UnixFolder_IShellFolder2_BindToStorage,
1231 UnixFolder_IShellFolder2_CompareIDs,
1232 UnixFolder_IShellFolder2_CreateViewObject,
1233 UnixFolder_IShellFolder2_GetAttributesOf,
1234 UnixFolder_IShellFolder2_GetUIObjectOf,
1235 UnixFolder_IShellFolder2_GetDisplayNameOf,
1236 UnixFolder_IShellFolder2_SetNameOf,
1237 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1238 UnixFolder_IShellFolder2_EnumSearches,
1239 UnixFolder_IShellFolder2_GetDefaultColumn,
1240 UnixFolder_IShellFolder2_GetDefaultColumnState,
1241 UnixFolder_IShellFolder2_GetDetailsEx,
1242 UnixFolder_IShellFolder2_GetDetailsOf,
1243 UnixFolder_IShellFolder2_MapColumnToSCID
1246 static HRESULT WINAPI UnixFolder_IPersistFolder2_QueryInterface(IPersistFolder2* This, REFIID riid,
1247 void** ppvObject)
1249 return UnixFolder_IShellFolder2_QueryInterface(
1250 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This), riid, ppvObject);
1253 static ULONG WINAPI UnixFolder_IPersistFolder2_AddRef(IPersistFolder2* This)
1255 return UnixFolder_IShellFolder2_AddRef(
1256 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1259 static ULONG WINAPI UnixFolder_IPersistFolder2_Release(IPersistFolder2* This)
1261 return UnixFolder_IShellFolder2_Release(
1262 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1265 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetClassID(IPersistFolder2* This, CLSID* pClassID)
1267 TRACE("stub\n");
1268 return E_NOTIMPL;
1271 static HRESULT WINAPI UnixFolder_IPersistFolder2_Initialize(IPersistFolder2* iface, LPCITEMIDLIST pidl)
1273 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1275 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1277 This->m_pidlLocation = ILClone(pidl);
1279 pdump(pidl);
1281 if (!UNIXFS_pidl_to_path(pidl, This))
1282 return E_FAIL;
1284 if (!strcmp(This->m_pszPath, "/")) {
1285 struct stat statRoot;
1286 if (stat(This->m_pszPath, &statRoot)) return E_FAIL;
1287 dwRootAttr = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
1288 if (UNIXFS_is_dos_device(&statRoot)) dwRootAttr |= SFGAO_FILESYSTEM;
1291 return S_OK;
1294 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetCurFolder(IPersistFolder2* iface, LPITEMIDLIST* ppidl)
1296 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1298 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1300 if (!ppidl)
1301 return E_POINTER;
1302 *ppidl = ILClone (This->m_pidlLocation);
1303 return S_OK;
1306 /* VTable for UnixFolder's IPersistFolder interface.
1308 static const IPersistFolder2Vtbl UnixFolder_IPersistFolder2_Vtbl = {
1309 UnixFolder_IPersistFolder2_QueryInterface,
1310 UnixFolder_IPersistFolder2_AddRef,
1311 UnixFolder_IPersistFolder2_Release,
1312 UnixFolder_IPersistFolder2_GetClassID,
1313 UnixFolder_IPersistFolder2_Initialize,
1314 UnixFolder_IPersistFolder2_GetCurFolder
1317 static HRESULT WINAPI UnixFolder_ISFHelper_QueryInterface(ISFHelper* iface, REFIID riid,
1318 void** ppvObject)
1320 return UnixFolder_IShellFolder2_QueryInterface(
1321 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface), riid, ppvObject);
1324 static ULONG WINAPI UnixFolder_ISFHelper_AddRef(ISFHelper* iface)
1326 return UnixFolder_IShellFolder2_AddRef(
1327 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface));
1330 static ULONG WINAPI UnixFolder_ISFHelper_Release(ISFHelper* iface)
1332 return UnixFolder_IShellFolder2_Release(
1333 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface));
1336 static HRESULT WINAPI UnixFolder_ISFHelper_GetUniqueName(ISFHelper* iface, LPSTR lpName, UINT uLen)
1338 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1339 IEnumIDList *pEnum;
1340 HRESULT hr;
1341 LPITEMIDLIST pidlElem;
1342 DWORD dwFetched;
1343 int i;
1344 static const char szNewFolder[] = "New Folder";
1346 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface, lpName, uLen);
1348 if (uLen < sizeof(szNewFolder)+3)
1349 return E_INVALIDARG;
1351 hr = IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2, This), 0,
1352 SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
1353 if (SUCCEEDED(hr)) {
1354 lstrcpyA(lpName, szNewFolder);
1355 IEnumIDList_Reset(pEnum);
1356 i = 2;
1357 while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
1358 if (!strcasecmp(_ILGetTextPointer(pidlElem), lpName)) {
1359 IEnumIDList_Reset(pEnum);
1360 sprintf(lpName, "%s %d", szNewFolder, i++);
1361 if (i > 99) {
1362 hr = E_FAIL;
1363 break;
1367 IEnumIDList_Release(pEnum);
1369 return hr;
1372 static HRESULT WINAPI UnixFolder_ISFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCSTR pszName,
1373 LPITEMIDLIST* ppidlOut)
1375 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1376 char szNewDir[FILENAME_MAX];
1378 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface, hwnd, pszName, ppidlOut);
1380 if (ppidlOut)
1381 *ppidlOut = NULL;
1383 lstrcpyA(szNewDir, This->m_pszPath);
1384 lstrcatA(szNewDir, pszName);
1386 if (mkdir(szNewDir, 0755)) {
1387 char szMessage[256 + FILENAME_MAX];
1388 char szCaption[256];
1390 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
1391 sprintf(szMessage, szCaption, szNewDir);
1392 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
1393 MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
1395 return E_FAIL;
1396 } else {
1397 LPITEMIDLIST pidlRelative;
1398 WCHAR wszName[MAX_PATH];
1400 /* Update the folder's children */
1401 UNIXFS_build_subfolder_pidls(This);
1403 /* Inform the shell */
1404 MultiByteToWideChar(CP_ACP, 0, pszName, -1, wszName, MAX_PATH);
1405 if (UNIXFS_path_to_pidl(This, wszName, &pidlRelative)) {
1406 LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
1407 if (ppidlOut)
1408 *ppidlOut = pidlRelative;
1409 else
1410 ILFree(pidlRelative);
1411 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1412 ILFree(pidlAbsolute);
1414 return S_OK;
1418 static HRESULT WINAPI UnixFolder_ISFHelper_DeleteItems(ISFHelper* iface, UINT cidl,
1419 LPCITEMIDLIST* apidl)
1421 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1422 char szAbsolute[FILENAME_MAX], *pszRelative;
1423 LPITEMIDLIST pidlAbsolute;
1424 HRESULT hr = S_OK;
1425 UINT i;
1427 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface, cidl, apidl);
1429 lstrcpyA(szAbsolute, This->m_pszPath);
1430 pszRelative = szAbsolute + lstrlenA(szAbsolute);
1432 for (i=0; i<cidl && SUCCEEDED(hr); i++) {
1433 lstrcpyA(pszRelative, _ILGetTextPointer(apidl[i]));
1434 pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
1435 if (_ILIsFolder(apidl[i])) {
1436 if (rmdir(szAbsolute)) {
1437 hr = E_FAIL;
1438 } else {
1439 SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1441 } else if (_ILIsValue(apidl[i])) {
1442 if (unlink(szAbsolute)) {
1443 hr = E_FAIL;
1444 } else {
1445 SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
1448 ILFree(pidlAbsolute);
1450 UNIXFS_build_subfolder_pidls(This);
1452 return hr;
1455 static HRESULT WINAPI UnixFolder_ISFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom,
1456 UINT cidl, LPCITEMIDLIST *apidl)
1458 FIXME("stub\n");
1459 return E_NOTIMPL;
1462 /* VTable for UnixFolder's ISFHelper interface
1464 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl = {
1465 UnixFolder_ISFHelper_QueryInterface,
1466 UnixFolder_ISFHelper_AddRef,
1467 UnixFolder_ISFHelper_Release,
1468 UnixFolder_ISFHelper_GetUniqueName,
1469 UnixFolder_ISFHelper_AddFolder,
1470 UnixFolder_ISFHelper_DeleteItems,
1471 UnixFolder_ISFHelper_CopyItems
1474 /******************************************************************************
1475 * Unix[Dos]Folder_Constructor [Internal]
1477 * PARAMS
1478 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1479 * riid [I] Interface asked for by the client.
1480 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1482 * NOTES
1483 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1484 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1485 * compatible signature.
1487 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1488 * means that paths are converted from dos to unix and back at the interfaces.
1490 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, DWORD dwPathMode) {
1491 HRESULT hr = E_FAIL;
1492 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1494 if(pUnixFolder) {
1495 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1496 pUnixFolder->lpIPersistFolder2Vtbl = &UnixFolder_IPersistFolder2_Vtbl;
1497 pUnixFolder->lpISFHelperVtbl = &UnixFolder_ISFHelper_Vtbl;
1498 pUnixFolder->m_cRef = 0;
1499 pUnixFolder->m_pszPath = NULL;
1500 pUnixFolder->m_apidlSubDirs = NULL;
1501 pUnixFolder->m_cSubDirs = -1;
1502 pUnixFolder->m_dwPathMode = dwPathMode;
1504 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1505 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1506 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1508 return hr;
1511 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1512 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1513 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_UNIX);
1516 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1517 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1518 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_DOS);
1521 /******************************************************************************
1522 * UnixSubFolderIterator
1524 * Class whose heap based objects represent iterators over the sub-directories
1525 * of a given UnixFolder object.
1528 /* UnixSubFolderIterator object layout and typedef.
1530 typedef struct _UnixSubFolderIterator {
1531 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1532 LONG m_cRef;
1533 UnixFolder *m_pUnixFolder;
1534 ULONG m_cIdx;
1535 SHCONTF m_fFilter;
1536 } UnixSubFolderIterator;
1538 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1539 TRACE("(iterator=%p)\n", iterator);
1541 UnixFolder_IShellFolder2_Release((IShellFolder2*)iterator->m_pUnixFolder);
1542 SHFree(iterator);
1545 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1546 REFIID riid, void** ppv)
1548 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1550 if (!ppv) return E_INVALIDARG;
1552 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1553 *ppv = iface;
1554 } else {
1555 *ppv = NULL;
1556 return E_NOINTERFACE;
1559 IEnumIDList_AddRef(iface);
1560 return S_OK;
1563 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1565 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1567 TRACE("(iface=%p)\n", iface);
1569 return InterlockedIncrement(&This->m_cRef);
1572 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1574 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1575 ULONG cRef;
1577 TRACE("(iface=%p)\n", iface);
1579 cRef = InterlockedDecrement(&This->m_cRef);
1581 if (!cRef)
1582 UnixSubFolderIterator_Destroy(This);
1584 return cRef;
1587 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1588 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1590 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1591 ULONG i;
1593 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface, celt, rgelt, pceltFetched);
1595 for (i=0; (i < celt) && (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs); This->m_cIdx++) {
1596 LPITEMIDLIST pCurrent = This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx];
1597 if (UNIXFS_is_pidl_of_type(pCurrent, This->m_fFilter)) {
1598 rgelt[i] = ILClone(pCurrent);
1599 i++;
1603 if (pceltFetched)
1604 *pceltFetched = i;
1606 return (i == 0) ? S_FALSE : S_OK;
1609 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1611 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1612 ULONG i;
1614 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1616 for (i=0; i < celt; i++) {
1617 while (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs &&
1618 !UNIXFS_is_pidl_of_type(This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx], This->m_fFilter))
1620 This->m_cIdx++;
1622 This->m_cIdx++;
1625 if (This->m_cIdx > This->m_pUnixFolder->m_cSubDirs) {
1626 This->m_cIdx = This->m_pUnixFolder->m_cSubDirs;
1627 return S_FALSE;
1628 } else {
1629 return S_OK;
1633 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1635 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1637 TRACE("(iface=%p)\n", iface);
1639 This->m_cIdx = 0;
1641 return S_OK;
1644 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1645 IEnumIDList** ppenum)
1647 TRACE("stub\n");
1648 return E_NOTIMPL;
1651 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1653 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1654 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1655 UnixSubFolderIterator_IEnumIDList_AddRef,
1656 UnixSubFolderIterator_IEnumIDList_Release,
1657 UnixSubFolderIterator_IEnumIDList_Next,
1658 UnixSubFolderIterator_IEnumIDList_Skip,
1659 UnixSubFolderIterator_IEnumIDList_Reset,
1660 UnixSubFolderIterator_IEnumIDList_Clone
1663 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1664 UnixSubFolderIterator *iterator;
1666 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1668 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1669 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1670 iterator->m_cRef = 0;
1671 iterator->m_cIdx = 0;
1672 iterator->m_pUnixFolder = pUnixFolder;
1673 iterator->m_fFilter = fFilter;
1675 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1676 UnixFolder_IShellFolder2_AddRef((IShellFolder2*)pUnixFolder);
1678 return (IUnknown*)iterator;