Implemented IPersist::GetClassID.
[wine/testsucceed.git] / dlls / shell32 / shfldr_unixfs.c
blob8f029e8fa3f9ea25a629385f1b1c7586b44fe9b9
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 "wine/port.h"
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <limits.h>
27 #include <dirent.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
33 #endif
34 #ifdef HAVE_PWD_H
35 # include <pwd.h>
36 #endif
37 #include <grp.h>
38 #include <limits.h>
40 #define COBJMACROS
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winuser.h"
47 #include "objbase.h"
48 #include "winreg.h"
49 #include "shlwapi.h"
50 #include "winternl.h"
51 #include "wine/debug.h"
53 #include "shell32_main.h"
54 #include "shellfolder.h"
55 #include "shfldr.h"
56 #include "shresdef.h"
57 #include "pidl.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell);
61 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
62 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
64 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
65 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
67 /* FileStruct reserves one byte for szNames, thus we don't have to
68 * alloc a byte for the terminating '\0' of 'name'. Two of the
69 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
70 * type field. One is for FileStruct's szNames field, to terminate
71 * the alternate DOS name, which we don't use here.
73 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
74 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char))
75 #define NAME_LEN_FROM_LPSHITEMID(s) \
76 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char))
78 #define PATHMODE_UNIX 0
79 #define PATHMODE_DOS 1
81 /* UnixFolder object layout and typedef.
83 typedef struct _UnixFolder {
84 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
85 const IPersistFolder3Vtbl *lpIPersistFolder3Vtbl;
86 const ISFHelperVtbl *lpISFHelperVtbl;
87 LONG m_cRef;
88 CHAR *m_pszPath;
89 LPITEMIDLIST m_pidlLocation;
90 DWORD m_dwPathMode;
91 DWORD m_dwAttributes;
92 const CLSID *m_pCLSID;
93 } UnixFolder;
95 /******************************************************************************
96 * UNIXFS_is_rooted_at_desktop [Internal]
98 * Checks if the unixfs namespace extension is rooted at desktop level.
100 * RETURNS
101 * TRUE, if unixfs is rooted at desktop level
102 * FALSE, if not.
104 BOOL UNIXFS_is_rooted_at_desktop(void) {
105 HKEY hKey;
106 WCHAR *pwszCLSID_UnixDosFolder, wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
107 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
108 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
109 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
110 'N','a','m','e','S','p','a','c','e','\\',0 };
112 if (FAILED(StringFromCLSID(&CLSID_UnixDosFolder, &pwszCLSID_UnixDosFolder)))
113 return FALSE;
115 lstrcatW(wszRootedAtDesktop, pwszCLSID_UnixDosFolder);
116 CoTaskMemFree(pwszCLSID_UnixDosFolder);
118 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
119 return FALSE;
121 RegCloseKey(hKey);
122 return TRUE;
125 /******************************************************************************
126 * UNIXFS_is_pidl_of_type [INTERNAL]
128 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
130 * PARAMS
131 * pIDL [I] The ITEMIDLIST to be checked.
132 * fFilter [I] Shell condition flags, which specify the filter.
134 * RETURNS
135 * TRUE, if pIDL is accepted by fFilter
136 * FALSE, otherwise
138 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
139 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
140 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
141 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
143 return FALSE;
145 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
146 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
147 return FALSE;
150 /******************************************************************************
151 * UNIXFS_is_dos_device [Internal]
153 * Determines if a unix directory corresponds to any dos device.
155 * PARAMS
156 * statPath [I] The stat struct of the directory, as returned by stat(2).
158 * RETURNS
159 * TRUE, if statPath corresponds to any dos drive letter
160 * FALSE, otherwise
162 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
163 struct stat statDrive;
164 char *pszDrivePath;
165 DWORD dwDriveMap;
166 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
168 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
169 if (!(dwDriveMap & 0x1)) continue;
170 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
171 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
172 HeapFree(GetProcessHeap(), 0, pszDrivePath);
173 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
174 return TRUE;
177 return FALSE;
180 /******************************************************************************
181 * UNIXFS_get_unix_path [Internal]
183 * Convert an absolute dos path to an absolute canonicalized unix path.
184 * Evaluate "/.", "/.." and symbolic links.
186 * PARAMS
187 * pszDosPath [I] An absolute dos path
188 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
190 * RETURNS
191 * Success, TRUE
192 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
194 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
196 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
197 struct stat fileStat;
199 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
201 if (!pszDosPath || pszDosPath[1] != ':')
202 return FALSE;
204 pszUnixPath = wine_get_unix_file_name(pszDosPath);
205 if (!pszUnixPath) return FALSE;
206 strcpy(szPath, pszUnixPath);
207 HeapFree(GetProcessHeap(), 0, pszUnixPath);
209 /* pCanonicalTail always points to the end of the canonical path constructed
210 * thus far. pPathTail points to the still to be processed part of the input
211 * path. pElement points to the path element currently investigated.
213 *pszCanonicalPath = '\0';
214 pCanonicalTail = pszCanonicalPath;
215 pPathTail = szPath;
217 do {
218 char cTemp;
219 int cLinks = 0;
221 pElement = pPathTail;
222 pPathTail = strchr(pPathTail+1, '/');
223 if (!pPathTail) /* Last path element may not be terminated by '/'. */
224 pPathTail = pElement + strlen(pElement);
225 /* Temporarily terminate the current path element. Will be restored later. */
226 cTemp = *pPathTail;
227 *pPathTail = '\0';
229 /* Skip "/." path elements */
230 if (!strcmp("/.", pElement)) {
231 *pPathTail = cTemp;
232 continue;
235 /* Remove last element in canonical path for "/.." elements, then skip. */
236 if (!strcmp("/..", pElement)) {
237 char *pTemp = strrchr(pszCanonicalPath, '/');
238 if (pTemp)
239 pCanonicalTail = pTemp;
240 *pCanonicalTail = '\0';
241 *pPathTail = cTemp;
242 continue;
245 /* lstat returns zero on success. */
246 if (lstat(szPath, &fileStat))
247 return FALSE;
249 if (S_ISLNK(fileStat.st_mode)) {
250 char szSymlink[FILENAME_MAX];
251 int cLinkLen, cTailLen;
253 /* Avoid infinite loop for recursive links. */
254 if (++cLinks > 64)
255 return FALSE;
257 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
258 if (cLinkLen < 0)
259 return FALSE;
261 *pPathTail = cTemp;
262 cTailLen = strlen(pPathTail);
264 if (szSymlink[0] == '/') {
265 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
266 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
267 return FALSE;
269 /* Avoid double slashes. */
270 if (szSymlink[cLinkLen-1] == '/' && pPathTail[0] == '/') {
271 szSymlink[cLinkLen-1] = '\0';
272 cLinkLen--;
275 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
276 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
277 *pszCanonicalPath = '\0';
278 pCanonicalTail = pszCanonicalPath;
279 pPathTail = szPath;
280 } else {
281 /* Relative link. Expand into szPath and continue. */
282 char szTemp[FILENAME_MAX];
283 int cTailLen = strlen(pPathTail);
285 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
286 return FALSE;
288 memcpy(szTemp, pPathTail, cTailLen + 1);
289 memcpy(pElement + 1, szSymlink, cLinkLen);
290 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
291 pPathTail = pElement;
293 } else {
294 /* Regular directory or file. Copy to canonical path */
295 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
296 return FALSE;
298 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
299 pCanonicalTail += pPathTail - pElement;
300 *pPathTail = cTemp;
302 } while (pPathTail[0] == '/');
304 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
306 return TRUE;
309 /******************************************************************************
310 * UNIXFS_build_shitemid [Internal]
312 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
313 * buffer 'pIDL'.
315 * PARAMS
316 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
317 * pIDL [O] SHITEMID will be constructed here.
319 * RETURNS
320 * Success: A pointer to the terminating '\0' character of path.
321 * Failure: NULL
323 * NOTES
324 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
325 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
326 * a 0 USHORT value.
328 static char* UNIXFS_build_shitemid(char *pszUnixPath, void *pIDL) {
329 LARGE_INTEGER time;
330 FILETIME fileTime;
331 LPPIDLDATA pIDLData;
332 struct stat fileStat;
333 char *pszComponent;
334 int cComponentLen;
336 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
338 /* Compute the SHITEMID's length and wipe it. */
339 pszComponent = strrchr(pszUnixPath, '/') + 1;
340 cComponentLen = strlen(pszComponent);
341 memset(pIDL, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen));
342 ((LPSHITEMID)pIDL)->cb = SHITEMID_LEN_FROM_NAME_LEN(cComponentLen) ;
344 /* We are only interested in regular files and directories. */
345 if (stat(pszUnixPath, &fileStat)) return NULL;
346 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
348 /* Set shell32's standard SHITEMID data fields. */
349 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
350 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
351 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
352 RtlSecondsSince1970ToTime( fileStat.st_mtime, &time );
353 fileTime.dwLowDateTime = time.u.LowPart;
354 fileTime.dwHighDateTime = time.u.HighPart;
355 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
356 pIDLData->u.file.uFileAttribs = 0;
357 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
358 if (pszComponent[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
359 memcpy(pIDLData->u.file.szNames, pszComponent, cComponentLen);
361 return pszComponent + cComponentLen;
364 /******************************************************************************
365 * UNIXFS_path_to_pidl [Internal]
367 * PARAMS
368 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
369 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
370 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
372 * RETURNS
373 * Success: TRUE
374 * Failure: FALSE, invalid params or out of memory
376 * NOTES
377 * pUnixFolder also carries the information if the path is expected to be unix or dos.
379 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
380 LPITEMIDLIST pidl;
381 int cSubDirs, cPidlLen, cPathLen;
382 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
384 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
386 if (!ppidl || !path)
387 return FALSE;
389 /* Build an absolute path and let pNextPathElement point to the interesting
390 * relative sub-path. We need the absolute path to call 'stat', but the pidl
391 * will only contain the relative part.
393 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
395 /* Absolute dos path. Convert to unix */
396 if (!UNIXFS_get_unix_path(path, szCompletePath))
397 return FALSE;
398 pNextPathElement = szCompletePath;
400 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
402 /* Absolute unix path. Just convert to ANSI. */
403 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
404 pNextPathElement = szCompletePath;
406 else
408 /* Relative dos or unix path. Concat with this folder's path */
409 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
410 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
411 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath + cBasePathLen,
412 FILENAME_MAX - cBasePathLen, NULL, NULL);
413 pNextPathElement = szCompletePath + cBasePathLen - 1;
415 /* If in dos mode, replace '\' with '/' */
416 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
417 char *pBackslash = strchr(pNextPathElement, '\\');
418 while (pBackslash) {
419 *pBackslash = '/';
420 pBackslash = strchr(pBackslash, '\\');
425 /* Special case for the root folder. */
426 if (!strcmp(szCompletePath, "/")) {
427 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(sizeof(USHORT));
428 if (!pidl) return FALSE;
429 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
430 return TRUE;
433 /* Remove trailing slash, if present */
434 cPathLen = strlen(szCompletePath);
435 if (szCompletePath[cPathLen-1] == '/')
436 szCompletePath[cPathLen-1] = '\0';
438 if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
439 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
440 return FALSE;
443 /* At this point, we have an absolute unix path in szCompletePath
444 * and the relative portion of it in pNextPathElement. Both starting with '/'
445 * and _not_ terminated by a '/'. */
446 TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
448 /* Count the number of sub-directories in the path */
449 cSubDirs = 0;
450 pSlash = pNextPathElement;
451 while (pSlash) {
452 cSubDirs++;
453 pSlash = strchr(pSlash+1, '/');
456 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
457 * characters, which are not stored in the ITEMIDLIST. */
458 cPidlLen = strlen(pNextPathElement) - cSubDirs + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
459 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
460 if (!pidl) return FALSE;
462 /* Concatenate the SHITEMIDs of the sub-directories. */
463 while (*pNextPathElement) {
464 pSlash = strchr(pNextPathElement+1, '/');
465 if (pSlash) *pSlash = '\0';
466 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, pidl);
467 if (pSlash) *pSlash = '/';
469 if (!pNextPathElement) {
470 SHFree(pidl);
471 return FALSE;
473 pidl = ILGetNext(pidl);
475 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
477 if ((int)pidl-(int)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
478 ERR("Computed length of pidl incorrect. Please report.\n");
480 return TRUE;
483 /******************************************************************************
484 * UnixFolder
486 * Class whose heap based instances represent unix filesystem directories.
489 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
490 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
492 SHFree(pUnixFolder->m_pszPath);
493 ILFree(pUnixFolder->m_pidlLocation);
494 SHFree(pUnixFolder);
497 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
498 void **ppv)
500 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
502 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
504 if (!ppv) return E_INVALIDARG;
506 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
507 IsEqualIID(&IID_IShellFolder2, riid))
509 *ppv = &This->lpIShellFolder2Vtbl;
510 } else if (IsEqualIID(&IID_IPersistFolder3, riid) || IsEqualIID(&IID_IPersistFolder2, riid) ||
511 IsEqualIID(&IID_IPersistFolder, riid) || IsEqualIID(&IID_IPersist, riid))
513 *ppv = &This->lpIPersistFolder3Vtbl;
514 } else if (IsEqualIID(&IID_ISFHelper, riid)) {
515 *ppv = &This->lpISFHelperVtbl;
516 } else {
517 *ppv = NULL;
518 return E_NOINTERFACE;
521 IUnknown_AddRef((IUnknown*)*ppv);
522 return S_OK;
525 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
526 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
528 TRACE("(iface=%p)\n", iface);
530 return InterlockedIncrement(&This->m_cRef);
533 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
534 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
535 ULONG cRef;
537 TRACE("(iface=%p)\n", iface);
539 cRef = InterlockedDecrement(&This->m_cRef);
541 if (!cRef)
542 UnixFolder_Destroy(This);
544 return cRef;
547 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
548 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
549 ULONG* pdwAttributes)
551 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
552 BOOL result;
554 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
555 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
556 pchEaten, ppidl, pdwAttributes);
558 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
559 if (result && pdwAttributes && *pdwAttributes)
561 IShellFolder *pParentSF;
562 LPCITEMIDLIST pidlLast;
563 HRESULT hr;
565 hr = SHBindToParent(*ppidl, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
566 if (FAILED(hr)) return E_FAIL;
567 IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
568 IShellFolder_Release(pParentSF);
571 if (!result) TRACE("FAILED!\n");
572 return result ? S_OK : E_FAIL;
575 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter);
577 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
578 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
580 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
581 IUnknown *newIterator;
582 HRESULT hr;
584 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
585 iface, hwndOwner, grfFlags, ppEnumIDList);
587 newIterator = UnixSubFolderIterator_Constructor(This, grfFlags);
588 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
589 IUnknown_Release(newIterator);
591 return hr;
594 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
595 LPBC pbcReserved, REFIID riid, void** ppvOut)
597 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
598 IPersistFolder3 *persistFolder;
599 LPITEMIDLIST pidlSubFolder;
600 HRESULT hr;
602 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
603 iface, pidl, pbcReserved, riid, ppvOut);
605 if (!pidl || !pidl->mkid.cb)
606 return E_INVALIDARG;
608 if (This->m_dwPathMode == PATHMODE_DOS)
609 hr = UnixDosFolder_Constructor(NULL, &IID_IPersistFolder3, (void**)&persistFolder);
610 else
611 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder3, (void**)&persistFolder);
613 if (!SUCCEEDED(hr)) return hr;
614 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
616 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
617 IPersistFolder3_Initialize(persistFolder, pidlSubFolder);
618 IPersistFolder3_Release(persistFolder);
619 ILFree(pidlSubFolder);
621 return hr;
624 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
625 LPBC pbcReserved, REFIID riid, void** ppvObj)
627 TRACE("stub\n");
628 return E_NOTIMPL;
631 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
632 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
634 BOOL isEmpty1, isEmpty2;
635 HRESULT hr = E_FAIL;
636 LPITEMIDLIST firstpidl;
637 IShellFolder2 *psf;
638 int compare;
640 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
642 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
643 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
645 if (isEmpty1 && isEmpty2)
646 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
647 else if (isEmpty1)
648 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
649 else if (isEmpty2)
650 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
652 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
653 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
654 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
655 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
657 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
658 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
659 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
661 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
662 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
664 if (pidl1->mkid.cb < pidl2->mkid.cb)
665 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
666 else if (pidl1->mkid.cb > pidl2->mkid.cb)
667 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
669 firstpidl = ILCloneFirst(pidl1);
670 pidl1 = ILGetNext(pidl1);
671 pidl2 = ILGetNext(pidl2);
673 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
674 if (SUCCEEDED(hr)) {
675 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
676 IShellFolder2_Release(psf);
679 ILFree(firstpidl);
680 return hr;
683 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
684 REFIID riid, void** ppv)
686 HRESULT hr = E_INVALIDARG;
688 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
690 if (!ppv) return E_INVALIDARG;
691 *ppv = NULL;
693 if (IsEqualIID(&IID_IShellView, riid)) {
694 LPSHELLVIEW pShellView;
696 pShellView = IShellView_Constructor((IShellFolder*)iface);
697 if (pShellView) {
698 hr = IShellView_QueryInterface(pShellView, riid, ppv);
699 IShellView_Release(pShellView);
703 return hr;
706 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
707 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
709 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
710 HRESULT hr = S_OK;
712 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
714 if (!rgfInOut || (cidl && !apidl))
715 return E_INVALIDARG;
717 if (cidl == 0) {
718 *rgfInOut &= This->m_dwAttributes;
719 } else {
720 char szAbsolutePath[FILENAME_MAX], *pszRelativePath;
721 UINT i;
723 *rgfInOut &= SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|
724 SFGAO_FILESYSTEM;
725 lstrcpyA(szAbsolutePath, This->m_pszPath);
726 pszRelativePath = szAbsolutePath + lstrlenA(szAbsolutePath);
727 for (i=0; i<cidl; i++) {
728 if ((*rgfInOut & SFGAO_FILESYSTEM) && !(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
729 struct stat fileStat;
730 char *pszName = _ILGetTextPointer(apidl[i]);
731 if (!pszName) return E_INVALIDARG;
732 lstrcpyA(pszRelativePath, pszName);
733 if (stat(szAbsolutePath, &fileStat) || !UNIXFS_is_dos_device(&fileStat))
734 *rgfInOut &= ~SFGAO_FILESYSTEM;
736 if (!_ILIsFolder(apidl[i]))
737 *rgfInOut &= ~(SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR);
741 return hr;
744 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
745 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
747 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
749 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
750 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
752 if (IsEqualIID(&IID_IContextMenu, riid)) {
753 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
754 return S_OK;
755 } else if (IsEqualIID(&IID_IDataObject, riid)) {
756 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
757 return S_OK;
758 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
759 LPITEMIDLIST pidl;
760 if (cidl != 1) return E_FAIL;
761 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
762 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
763 SHFree(pidl);
764 return S_OK;
765 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
766 LPITEMIDLIST pidl;
767 if (cidl != 1) return E_FAIL;
768 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
769 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
770 SHFree(pidl);
771 return S_OK;
772 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
773 FIXME("IDropTarget\n");
774 return E_FAIL;
775 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
776 FIXME("IShellLinkW\n");
777 return E_FAIL;
778 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
779 FIXME("IShellLinkA\n");
780 return E_FAIL;
781 } else {
782 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
783 return E_NOINTERFACE;
787 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
788 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
790 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
791 HRESULT hr = S_OK;
793 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
795 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
796 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
798 if (!pidl->mkid.cb) {
799 lpName->uType = STRRET_CSTR;
800 if (This->m_dwPathMode == PATHMODE_UNIX) {
801 strcpy(lpName->u.cStr, This->m_pszPath);
802 } else {
803 WCHAR *pwszDosPath = wine_get_dos_file_name(This->m_pszPath);
804 if (!pwszDosPath)
805 return HRESULT_FROM_WIN32(GetLastError());
806 PathRemoveBackslashW(pwszDosPath);
807 WideCharToMultiByte(CP_UNIXCP, 0, pwszDosPath, -1, lpName->u.cStr, MAX_PATH, NULL, NULL);
808 HeapFree(GetProcessHeap(), 0, pwszDosPath);
810 } else {
811 IShellFolder *pSubFolder;
812 USHORT emptyIDL = 0;
814 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
815 if (!SUCCEEDED(hr)) return hr;
817 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
818 IShellFolder_Release(pSubFolder);
820 } else {
821 char *pszFileName = _ILGetTextPointer(pidl);
822 lpName->uType = STRRET_CSTR;
823 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
826 /* If in dos mode, do some post-processing on the path.
827 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
829 if (SUCCEEDED(hr) && This->m_dwPathMode == PATHMODE_DOS && !_ILIsFolder(pidl))
830 SHELL_FS_ProcessDisplayFilename(lpName->u.cStr, uFlags);
832 TRACE("--> %s\n", lpName->u.cStr);
834 return hr;
837 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd,
838 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
840 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
842 char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
843 WCHAR *pwszDosDest;
844 int cBasePathLen = lstrlenA(This->m_pszPath);
845 struct stat statDest;
846 LPITEMIDLIST pidlSrc, pidlDest;
848 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
849 iface, hwnd, pidl, debugstr_w(lpszName), uFlags, ppidlOut);
851 /* pidl has to contain a single non-empty SHITEMID */
852 if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
853 return E_INVALIDARG;
855 if (ppidlOut)
856 *ppidlOut = NULL;
858 /* build source path */
859 memcpy(szSrc, This->m_pszPath, cBasePathLen);
860 lstrcpyA(szSrc+cBasePathLen, _ILGetTextPointer(pidl));
862 /* build destination path */
863 if (uFlags & SHGDN_FORPARSING) { /* absolute path in lpszName */
864 WideCharToMultiByte(CP_UNIXCP, 0, lpszName, -1, szDest, FILENAME_MAX, NULL, NULL);
865 } else {
866 WCHAR wszSrcRelative[MAX_PATH];
867 memcpy(szDest, This->m_pszPath, cBasePathLen);
868 WideCharToMultiByte(CP_UNIXCP, 0, lpszName, -1, szDest+cBasePathLen,
869 FILENAME_MAX-cBasePathLen, NULL, NULL);
871 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
872 * extension is hidden to the user, we have to append it. */
873 if (_ILSimpleGetTextW(pidl, wszSrcRelative, MAX_PATH) &&
874 SHELL_FS_HideExtension(wszSrcRelative))
876 char *pszExt = PathFindExtensionA(_ILGetTextPointer(pidl));
877 lstrcatA(szDest, pszExt);
881 TRACE("src=%s dest=%s\n", szSrc, szDest);
883 /* Fail, if destination does already exist */
884 if (!stat(szDest, &statDest))
885 return E_FAIL;
887 /* Rename the file */
888 if (rename(szSrc, szDest))
889 return E_FAIL;
891 /* Build a pidl for the path of the renamed file */
892 pwszDosDest = wine_get_dos_file_name(szDest);
893 if (!pwszDosDest || !UNIXFS_path_to_pidl(This, pwszDosDest, &pidlDest)) {
894 HeapFree(GetProcessHeap(), 0, pwszDosDest);
895 rename(szDest, szSrc); /* Undo the renaming */
896 return E_FAIL;
899 /* Inform the shell */
900 pidlSrc = ILCombine(This->m_pidlLocation, pidl);
901 if (_ILIsFolder(ILFindLastID(pidlDest)))
902 SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
903 else
904 SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
905 ILFree(pidlSrc);
906 ILFree(pidlDest);
908 if (ppidlOut)
909 _ILCreateFromPathW(pwszDosDest, ppidlOut);
911 HeapFree(GetProcessHeap(), 0, pwszDosDest);
912 return S_OK;
915 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
916 IEnumExtraSearch **ppEnum)
918 TRACE("stub\n");
919 return E_NOTIMPL;
922 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
923 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
925 TRACE("stub\n");
926 return E_NOTIMPL;
929 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
930 UINT iColumn, SHCOLSTATEF *pcsFlags)
932 TRACE("stub\n");
933 return E_NOTIMPL;
936 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
937 GUID *pguid)
939 TRACE("stub\n");
940 return E_NOTIMPL;
943 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
944 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
946 TRACE("stub\n");
947 return E_NOTIMPL;
950 #define SHELLVIEWCOLUMNS 7
952 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
953 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
955 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
956 HRESULT hr = E_FAIL;
957 struct passwd *pPasswd;
958 struct group *pGroup;
959 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
960 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
961 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
962 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
963 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
964 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 9},
965 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
966 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7}
969 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
971 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
972 return E_INVALIDARG;
974 if (!pidl) {
975 psd->fmt = SFHeader[iColumn].fmt;
976 psd->cxChar = SFHeader[iColumn].cxChar;
977 psd->str.uType = STRRET_CSTR;
978 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
979 return S_OK;
980 } else {
981 struct stat statItem;
982 if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
983 char szPath[FILENAME_MAX], *pszFile = _ILGetTextPointer(pidl);
984 if (!pszFile)
985 return E_INVALIDARG;
986 lstrcpyA(szPath, This->m_pszPath);
987 lstrcatA(szPath, pszFile);
988 if (stat(szPath, &statItem))
989 return E_INVALIDARG;
991 psd->str.u.cStr[0] = '\0';
992 psd->str.uType = STRRET_CSTR;
993 switch (iColumn) {
994 case 0:
995 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
996 break;
997 case 1:
998 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
999 break;
1000 case 2:
1001 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1002 break;
1003 case 3:
1004 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1005 break;
1006 case 4:
1007 psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
1008 psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
1009 psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
1010 psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
1011 psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
1012 psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
1013 psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
1014 psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
1015 psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
1016 psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
1017 psd->str.u.cStr[10] = '\0';
1018 break;
1019 case 5:
1020 pPasswd = getpwuid(statItem.st_uid);
1021 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1022 break;
1023 case 6:
1024 pGroup = getgrgid(statItem.st_gid);
1025 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1026 break;
1030 return hr;
1033 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1034 SHCOLUMNID *pscid)
1036 TRACE("stub\n");
1037 return E_NOTIMPL;
1040 /* VTable for UnixFolder's IShellFolder2 interface.
1042 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1043 UnixFolder_IShellFolder2_QueryInterface,
1044 UnixFolder_IShellFolder2_AddRef,
1045 UnixFolder_IShellFolder2_Release,
1046 UnixFolder_IShellFolder2_ParseDisplayName,
1047 UnixFolder_IShellFolder2_EnumObjects,
1048 UnixFolder_IShellFolder2_BindToObject,
1049 UnixFolder_IShellFolder2_BindToStorage,
1050 UnixFolder_IShellFolder2_CompareIDs,
1051 UnixFolder_IShellFolder2_CreateViewObject,
1052 UnixFolder_IShellFolder2_GetAttributesOf,
1053 UnixFolder_IShellFolder2_GetUIObjectOf,
1054 UnixFolder_IShellFolder2_GetDisplayNameOf,
1055 UnixFolder_IShellFolder2_SetNameOf,
1056 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1057 UnixFolder_IShellFolder2_EnumSearches,
1058 UnixFolder_IShellFolder2_GetDefaultColumn,
1059 UnixFolder_IShellFolder2_GetDefaultColumnState,
1060 UnixFolder_IShellFolder2_GetDetailsEx,
1061 UnixFolder_IShellFolder2_GetDetailsOf,
1062 UnixFolder_IShellFolder2_MapColumnToSCID
1065 static HRESULT WINAPI UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3* This, REFIID riid,
1066 void** ppvObject)
1068 return UnixFolder_IShellFolder2_QueryInterface(
1069 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder3, This), riid, ppvObject);
1072 static ULONG WINAPI UnixFolder_IPersistFolder3_AddRef(IPersistFolder3* This)
1074 return UnixFolder_IShellFolder2_AddRef(
1075 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder3, This));
1078 static ULONG WINAPI UnixFolder_IPersistFolder3_Release(IPersistFolder3* This)
1080 return UnixFolder_IShellFolder2_Release(
1081 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder3, This));
1084 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3* iface, CLSID* pClassID)
1086 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1088 TRACE("(iface=%p, pClassId=%p)\n", iface, pClassID);
1090 if (!pClassID)
1091 return E_INVALIDARG;
1093 memcpy(pClassID, This->m_pCLSID, sizeof(CLSID));
1094 return S_OK;
1097 static HRESULT WINAPI UnixFolder_IPersistFolder3_Initialize(IPersistFolder3* iface, LPCITEMIDLIST pidl)
1099 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1100 struct stat statPrefix;
1101 LPCITEMIDLIST current = pidl, root;
1102 DWORD dwPathLen;
1103 char *pNextDir, szBasePath[FILENAME_MAX] = "/";
1105 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1107 /* Find the UnixFolderClass root */
1108 while (current->mkid.cb) {
1109 if (_ILIsSpecialFolder(current) &&
1110 (IsEqualIID(&CLSID_UnixFolder, _ILGetGUIDPointer(current)) ||
1111 IsEqualIID(&CLSID_UnixDosFolder, _ILGetGUIDPointer(current))))
1113 break;
1115 current = ILGetNext(current);
1118 if (current && current->mkid.cb) {
1119 root = current = ILGetNext(current);
1120 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
1121 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
1122 /* Path rooted at Desktop */
1123 WCHAR wszDesktopPath[MAX_PATH];
1124 if (FAILED(SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOP, FALSE)))
1125 return E_FAIL;
1126 PathAddBackslashW(wszDesktopPath);
1127 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
1128 return E_FAIL;
1129 dwPathLen = strlen(szBasePath) + 1;
1130 root = current = pidl;
1131 } else {
1132 ERR("Unknown pidl type!\n");
1133 pdump(pidl);
1134 return E_INVALIDARG;
1137 /* Determine the path's length bytes */
1138 while (current && current->mkid.cb) {
1139 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
1140 current = ILGetNext(current);
1143 /* Build the path */
1144 This->m_dwAttributes = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
1145 This->m_pidlLocation = ILClone(pidl);
1146 This->m_pszPath = pNextDir = SHAlloc(dwPathLen);
1147 if (!This->m_pszPath || !This->m_pidlLocation) {
1148 WARN("SHAlloc failed!\n");
1149 return E_FAIL;
1151 current = root;
1152 strcpy(pNextDir, szBasePath);
1153 pNextDir += strlen(szBasePath);
1154 if (This->m_dwPathMode == PATHMODE_UNIX)
1155 This->m_dwAttributes |= SFGAO_FILESYSTEM;
1156 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
1157 *pNextDir = '\0';
1158 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
1159 This->m_dwAttributes |= SFGAO_FILESYSTEM;
1161 while (current && current->mkid.cb) {
1162 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
1163 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
1164 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
1165 *pNextDir = '\0';
1166 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
1167 This->m_dwAttributes |= SFGAO_FILESYSTEM;
1169 *pNextDir++ = '/';
1170 current = ILGetNext(current);
1172 *pNextDir='\0';
1174 return S_OK;
1177 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3* iface, LPITEMIDLIST* ppidl)
1179 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1181 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1183 if (!ppidl)
1184 return E_POINTER;
1185 *ppidl = ILClone (This->m_pidlLocation);
1186 return S_OK;
1189 static HRESULT WINAPI UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3 *iface, IBindCtx *pbc,
1190 LPCITEMIDLIST pidlRoot, const PERSIST_FOLDER_TARGET_INFO *ppfti)
1192 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1193 WCHAR wszTargetDosPath[MAX_PATH];
1194 char szTargetPath[FILENAME_MAX] = "";
1196 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface, pbc, pidlRoot, ppfti);
1198 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1199 if (!ppfti)
1200 return IPersistFolder3_Initialize(iface, pidlRoot);
1202 if (ppfti->csidl != -1) {
1203 if (SUCCEEDED(SHGetFolderPathW(0, ppfti->csidl, NULL, 0, wszTargetDosPath))) {
1204 UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath);
1206 } else if (*ppfti->szTargetParsingName) {
1207 UNIXFS_get_unix_path(ppfti->szTargetParsingName, szTargetPath);
1208 } else if (ppfti->pidlTargetFolder) {
1209 if (SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTargetDosPath)) {
1210 UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath);
1214 This->m_pszPath = SHAlloc(lstrlenA(szTargetPath)+1);
1215 if (!This->m_pszPath)
1216 return E_FAIL;
1217 lstrcpyA(This->m_pszPath, szTargetPath);
1218 This->m_pidlLocation = ILClone(pidlRoot);
1219 This->m_dwAttributes = (ppfti->dwAttributes == -1) ? ppfti->dwAttributes :
1220 SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1222 return S_OK;
1225 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3 *iface,
1226 PERSIST_FOLDER_TARGET_INFO *ppfti)
1228 FIXME("(iface=%p, ppfti=%p) stub\n", iface, ppfti);
1229 return E_NOTIMPL;
1232 /* VTable for UnixFolder's IPersistFolder interface.
1234 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl = {
1235 UnixFolder_IPersistFolder3_QueryInterface,
1236 UnixFolder_IPersistFolder3_AddRef,
1237 UnixFolder_IPersistFolder3_Release,
1238 UnixFolder_IPersistFolder3_GetClassID,
1239 UnixFolder_IPersistFolder3_Initialize,
1240 UnixFolder_IPersistFolder3_GetCurFolder,
1241 UnixFolder_IPersistFolder3_InitializeEx,
1242 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1245 static HRESULT WINAPI UnixFolder_ISFHelper_QueryInterface(ISFHelper* iface, REFIID riid,
1246 void** ppvObject)
1248 return UnixFolder_IShellFolder2_QueryInterface(
1249 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface), riid, ppvObject);
1252 static ULONG WINAPI UnixFolder_ISFHelper_AddRef(ISFHelper* iface)
1254 return UnixFolder_IShellFolder2_AddRef(
1255 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface));
1258 static ULONG WINAPI UnixFolder_ISFHelper_Release(ISFHelper* iface)
1260 return UnixFolder_IShellFolder2_Release(
1261 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface));
1264 static HRESULT WINAPI UnixFolder_ISFHelper_GetUniqueName(ISFHelper* iface, LPSTR lpName, UINT uLen)
1266 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1267 IEnumIDList *pEnum;
1268 HRESULT hr;
1269 LPITEMIDLIST pidlElem;
1270 DWORD dwFetched;
1271 int i;
1272 static const char szNewFolder[] = "New Folder";
1274 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface, lpName, uLen);
1276 if (uLen < sizeof(szNewFolder)+3)
1277 return E_INVALIDARG;
1279 hr = IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2, This), 0,
1280 SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
1281 if (SUCCEEDED(hr)) {
1282 lstrcpyA(lpName, szNewFolder);
1283 IEnumIDList_Reset(pEnum);
1284 i = 2;
1285 while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
1286 if (!strcasecmp(_ILGetTextPointer(pidlElem), lpName)) {
1287 IEnumIDList_Reset(pEnum);
1288 sprintf(lpName, "%s %d", szNewFolder, i++);
1289 if (i > 99) {
1290 hr = E_FAIL;
1291 break;
1295 IEnumIDList_Release(pEnum);
1297 return hr;
1300 static HRESULT WINAPI UnixFolder_ISFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCSTR pszName,
1301 LPITEMIDLIST* ppidlOut)
1303 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1304 char szNewDir[FILENAME_MAX];
1306 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface, hwnd, pszName, ppidlOut);
1308 if (ppidlOut)
1309 *ppidlOut = NULL;
1311 lstrcpyA(szNewDir, This->m_pszPath);
1312 lstrcatA(szNewDir, pszName);
1314 if (mkdir(szNewDir, 0755)) {
1315 char szMessage[256 + FILENAME_MAX];
1316 char szCaption[256];
1318 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
1319 sprintf(szMessage, szCaption, szNewDir);
1320 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
1321 MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
1323 return E_FAIL;
1324 } else {
1325 LPITEMIDLIST pidlRelative;
1326 WCHAR wszName[MAX_PATH];
1328 /* Inform the shell */
1329 MultiByteToWideChar(CP_UNIXCP, 0, pszName, -1, wszName, MAX_PATH);
1330 if (UNIXFS_path_to_pidl(This, wszName, &pidlRelative)) {
1331 LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
1332 if (ppidlOut)
1333 *ppidlOut = pidlRelative;
1334 else
1335 ILFree(pidlRelative);
1336 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1337 ILFree(pidlAbsolute);
1339 return S_OK;
1343 static HRESULT WINAPI UnixFolder_ISFHelper_DeleteItems(ISFHelper* iface, UINT cidl,
1344 LPCITEMIDLIST* apidl)
1346 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1347 char szAbsolute[FILENAME_MAX], *pszRelative;
1348 LPITEMIDLIST pidlAbsolute;
1349 HRESULT hr = S_OK;
1350 UINT i;
1352 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface, cidl, apidl);
1354 lstrcpyA(szAbsolute, This->m_pszPath);
1355 pszRelative = szAbsolute + lstrlenA(szAbsolute);
1357 for (i=0; i<cidl && SUCCEEDED(hr); i++) {
1358 lstrcpyA(pszRelative, _ILGetTextPointer(apidl[i]));
1359 pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
1360 if (_ILIsFolder(apidl[i])) {
1361 if (rmdir(szAbsolute)) {
1362 hr = E_FAIL;
1363 } else {
1364 SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1366 } else if (_ILIsValue(apidl[i])) {
1367 if (unlink(szAbsolute)) {
1368 hr = E_FAIL;
1369 } else {
1370 SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
1373 ILFree(pidlAbsolute);
1376 return hr;
1379 static HRESULT WINAPI UnixFolder_ISFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom,
1380 UINT cidl, LPCITEMIDLIST *apidl)
1382 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1383 DWORD dwAttributes;
1384 UINT i;
1385 HRESULT hr;
1386 char szAbsoluteDst[FILENAME_MAX], *pszRelativeDst;
1388 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface, psfFrom, cidl, apidl);
1390 if (!psfFrom || !cidl || !apidl)
1391 return E_INVALIDARG;
1393 /* All source items have to be filesystem items. */
1394 dwAttributes = SFGAO_FILESYSTEM;
1395 hr = IShellFolder_GetAttributesOf(psfFrom, cidl, apidl, &dwAttributes);
1396 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM))
1397 return E_INVALIDARG;
1399 lstrcpyA(szAbsoluteDst, This->m_pszPath);
1400 pszRelativeDst = szAbsoluteDst + strlen(szAbsoluteDst);
1402 for (i=0; i<cidl; i++) {
1403 WCHAR wszSrc[MAX_PATH];
1404 char szSrc[FILENAME_MAX];
1405 STRRET strret;
1407 /* Build the unix path of the current source item. */
1408 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom, apidl[i], SHGDN_FORPARSING, &strret)))
1409 return E_FAIL;
1410 if (FAILED(StrRetToBufW(&strret, apidl[i], wszSrc, MAX_PATH)))
1411 return E_FAIL;
1412 if (!UNIXFS_get_unix_path(wszSrc, szSrc))
1413 return E_FAIL;
1415 /* Build the unix path of the current destination item */
1416 lstrcpyA(pszRelativeDst, _ILGetTextPointer(apidl[i]));
1418 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc, szAbsoluteDst);
1420 return S_OK;
1423 /* VTable for UnixFolder's ISFHelper interface
1425 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl = {
1426 UnixFolder_ISFHelper_QueryInterface,
1427 UnixFolder_ISFHelper_AddRef,
1428 UnixFolder_ISFHelper_Release,
1429 UnixFolder_ISFHelper_GetUniqueName,
1430 UnixFolder_ISFHelper_AddFolder,
1431 UnixFolder_ISFHelper_DeleteItems,
1432 UnixFolder_ISFHelper_CopyItems
1435 /******************************************************************************
1436 * Unix[Dos]Folder_Constructor [Internal]
1438 * PARAMS
1439 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1440 * riid [I] Interface asked for by the client.
1441 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1443 * NOTES
1444 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1445 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1446 * compatible signature.
1448 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1449 * means that paths are converted from dos to unix and back at the interfaces.
1451 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, DWORD dwPathMode,
1452 const CLSID *pCLSID)
1454 HRESULT hr = E_FAIL;
1455 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1457 if(pUnixFolder) {
1458 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1459 pUnixFolder->lpIPersistFolder3Vtbl = &UnixFolder_IPersistFolder3_Vtbl;
1460 pUnixFolder->lpISFHelperVtbl = &UnixFolder_ISFHelper_Vtbl;
1461 pUnixFolder->m_cRef = 0;
1462 pUnixFolder->m_pszPath = NULL;
1463 pUnixFolder->m_dwPathMode = dwPathMode;
1464 pUnixFolder->m_pCLSID = pCLSID;
1466 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1467 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1468 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1470 return hr;
1473 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1474 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1475 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_UNIX, &CLSID_UnixFolder);
1478 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1479 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1480 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_DOS, &CLSID_UnixDosFolder);
1483 /******************************************************************************
1484 * UnixSubFolderIterator
1486 * Class whose heap based objects represent iterators over the sub-directories
1487 * of a given UnixFolder object.
1490 /* UnixSubFolderIterator object layout and typedef.
1492 typedef struct _UnixSubFolderIterator {
1493 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1494 LONG m_cRef;
1495 SHCONTF m_fFilter;
1496 DIR *m_dirFolder;
1497 char m_szFolder[FILENAME_MAX];
1498 } UnixSubFolderIterator;
1500 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1501 TRACE("(iterator=%p)\n", iterator);
1503 if (iterator->m_dirFolder)
1504 closedir(iterator->m_dirFolder);
1505 SHFree(iterator);
1508 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1509 REFIID riid, void** ppv)
1511 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1513 if (!ppv) return E_INVALIDARG;
1515 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1516 *ppv = iface;
1517 } else {
1518 *ppv = NULL;
1519 return E_NOINTERFACE;
1522 IEnumIDList_AddRef(iface);
1523 return S_OK;
1526 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1528 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1530 TRACE("(iface=%p)\n", iface);
1532 return InterlockedIncrement(&This->m_cRef);
1535 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1537 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1538 ULONG cRef;
1540 TRACE("(iface=%p)\n", iface);
1542 cRef = InterlockedDecrement(&This->m_cRef);
1544 if (!cRef)
1545 UnixSubFolderIterator_Destroy(This);
1547 return cRef;
1550 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1551 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1553 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1554 ULONG i = 0;
1556 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
1557 if (This->m_dirFolder) {
1558 char *pszRelativePath = This->m_szFolder + lstrlenA(This->m_szFolder);
1559 struct dirent *pDirEntry;
1561 while (i < celt) {
1562 pDirEntry = readdir(This->m_dirFolder);
1563 if (!pDirEntry) break; /* No more entries */
1564 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
1566 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
1567 * and see if it passes the filter.
1569 lstrcpyA(pszRelativePath, pDirEntry->d_name);
1570 rgelt[i] = (LPITEMIDLIST)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath))+sizeof(USHORT));
1571 if (!UNIXFS_build_shitemid(This->m_szFolder, rgelt[i]) ||
1572 !UNIXFS_is_pidl_of_type(rgelt[i], This->m_fFilter))
1574 SHFree(rgelt[i]);
1575 continue;
1577 memset(((PBYTE)rgelt[i])+rgelt[i]->mkid.cb, 0, sizeof(USHORT));
1578 i++;
1580 *pszRelativePath = '\0'; /* Restore the original path in This->m_szFolder. */
1583 if (pceltFetched)
1584 *pceltFetched = i;
1586 return (i == 0) ? S_FALSE : S_OK;
1589 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1591 LPITEMIDLIST *apidl;
1592 ULONG cFetched;
1593 HRESULT hr;
1595 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1597 /* Call IEnumIDList::Next and delete the resulting pidls. */
1598 apidl = (LPITEMIDLIST*)SHAlloc(celt * sizeof(LPITEMIDLIST));
1599 hr = IEnumIDList_Next(iface, celt, apidl, &cFetched);
1600 if (SUCCEEDED(hr))
1601 while (cFetched--)
1602 SHFree(apidl[cFetched]);
1603 SHFree(apidl);
1605 return hr;
1608 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1610 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1612 TRACE("(iface=%p)\n", iface);
1614 if (This->m_dirFolder)
1615 rewinddir(This->m_dirFolder);
1617 return S_OK;
1620 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1621 IEnumIDList** ppenum)
1623 TRACE("stub\n");
1624 return E_NOTIMPL;
1627 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1629 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1630 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1631 UnixSubFolderIterator_IEnumIDList_AddRef,
1632 UnixSubFolderIterator_IEnumIDList_Release,
1633 UnixSubFolderIterator_IEnumIDList_Next,
1634 UnixSubFolderIterator_IEnumIDList_Skip,
1635 UnixSubFolderIterator_IEnumIDList_Reset,
1636 UnixSubFolderIterator_IEnumIDList_Clone
1639 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1640 UnixSubFolderIterator *iterator;
1642 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1644 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1645 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1646 iterator->m_cRef = 0;
1647 iterator->m_fFilter = fFilter;
1648 iterator->m_dirFolder = opendir(pUnixFolder->m_pszPath);
1649 lstrcpyA(iterator->m_szFolder, pUnixFolder->m_pszPath);
1651 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1653 return (IUnknown*)iterator;