_findclose() exists on MinGW, so prefix it.
[wine/gsoc_dplay.git] / dlls / shell32 / shfldr_unixfs.c
blobebfe7f4a33bfffe0f68ba929ee47ad689d7d5270
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 #include <unistd.h>
27 #ifdef HAVE_SYS_STAT_H
28 # include <sys/stat.h>
29 #endif
30 #ifdef HAVE_PWD_H
31 # include <pwd.h>
32 #endif
33 #include <grp.h>
34 #include <limits.h>
36 #define COBJMACROS
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
40 #include "windef.h"
41 #include "winbase.h"
42 #include "winuser.h"
43 #include "objbase.h"
44 #include "winreg.h"
45 #include "winternl.h"
46 #include "wine/debug.h"
48 #include "shell32_main.h"
49 #include "shfldr.h"
50 #include "shresdef.h"
51 #include "pidl.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
56 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
58 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
59 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
61 /* FileStruct reserves one byte for szNames, thus we don't have to
62 * alloc a byte for the terminating '\0' of 'name'. Two of the
63 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
64 * type field. One is for FileStruct's szNames field, to terminate
65 * the alternate DOS name, which we don't use here. And then there's
66 * the additional StatStruct.
68 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
69 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char)+sizeof(StatStruct))
70 #define NAME_LEN_FROM_LPSHITEMID(s) \
71 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char)-sizeof(StatStruct))
72 #define LPSTATSTRUCT_FROM_LPSHITEMID(s) ((StatStruct*)(((LPBYTE)s)+((LPSHITEMID)s)->cb-sizeof(StatStruct)))
74 #define PATHMODE_UNIX 0
75 #define PATHMODE_DOS 1
77 /* This structure is appended to shell32's FileStruct type in IDLs to store unix
78 * filesystem specific informationen extracted with the stat system call.
80 typedef struct tagStatStruct {
81 mode_t st_mode;
82 uid_t st_uid;
83 gid_t st_gid;
84 } StatStruct;
86 /* UnixFolder object layout and typedef.
88 typedef struct _UnixFolder {
89 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
90 const IPersistFolder2Vtbl *lpIPersistFolder2Vtbl;
91 ULONG m_cRef;
92 CHAR *m_pszPath;
93 LPITEMIDLIST m_pidlLocation;
94 LPITEMIDLIST *m_apidlSubDirs;
95 DWORD m_cSubDirs;
96 DWORD m_dwPathMode;
97 } UnixFolder;
99 /******************************************************************************
100 * UNIXFS_is_pidl_of_type [INTERNAL]
102 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
104 * PARAMS
105 * pIDL [I] The ITEMIDLIST to be checked.
106 * fFilter [I] Shell condition flags, which specify the filter.
108 * RETURNS
109 * TRUE, if pIDL is accepted by fFilter
110 * FALSE, otherwise
112 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
113 LPSTR pszText = _ILGetTextPointer(pIDL);
114 if (!pszText) return FALSE;
115 if (pszText[0] == '.' && !(fFilter & SHCONTF_INCLUDEHIDDEN)) return FALSE;
116 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
117 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
118 return FALSE;
121 /******************************************************************************
122 * UNIXFS_build_shitemid [Internal]
124 * Constructs a new SHITEMID for a single path item (up to the next '/' or
125 * '\0') into a buffer. Decorates the SHITEMID with information from a stat
126 * system call.
128 * PARAMS
129 * name [I] The name of the next path item. Terminated by either '\0' or '/'.
130 * pStat [I] A stat struct variable obtained by a stat system call on the file.
131 * buffer [O] SHITEMID will be constructed here.
133 * RETURNS
134 * A pointer to the next '/' or '\0' character in name.
136 * NOTES
137 * Minimum size of buffer is SHITEMID_LEN_FROM_NAME_LEN(strlen(name)).
138 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
139 * a 0 USHORT value.
141 static char* UNIXFS_build_shitemid(char *name, struct stat *pStat, void *buffer) {
142 LARGE_INTEGER time;
143 FILETIME fileTime;
144 LPPIDLDATA pIDLData;
145 StatStruct *pStatStruct;
146 int cNameLen;
147 char *pSlash;
149 TRACE("(name=%s, pStat=%p, buffer=%p)\n", debugstr_a(name), pStat, buffer);
151 pSlash = strchr(name, '/');
152 cNameLen = pSlash ? pSlash - name : strlen(name);
154 memset(buffer, 0, SHITEMID_LEN_FROM_NAME_LEN(cNameLen));
155 ((LPSHITEMID)buffer)->cb = SHITEMID_LEN_FROM_NAME_LEN(cNameLen) ;
157 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)buffer);
158 pIDLData->type = S_ISDIR(pStat->st_mode) ? PT_FOLDER : PT_VALUE;
159 pIDLData->u.file.dwFileSize = (DWORD)pStat->st_size;
160 RtlSecondsSince1970ToTime( pStat->st_mtime, &time );
161 fileTime.dwLowDateTime = time.u.LowPart;
162 fileTime.dwHighDateTime = time.u.HighPart;
163 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
164 pIDLData->u.file.uFileAttribs =
165 (S_ISDIR(pStat->st_mode) ? FILE_ATTRIBUTE_DIRECTORY : 0) |
166 (name[0] == '.' ? FILE_ATTRIBUTE_HIDDEN : 0);
167 memcpy(pIDLData->u.file.szNames, name, cNameLen);
169 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(buffer);
170 pStatStruct->st_mode = pStat->st_mode;
171 pStatStruct->st_uid = pStat->st_uid;
172 pStatStruct->st_gid = pStat->st_gid;
174 return pSlash ? pSlash+1 : (name + cNameLen);
177 /******************************************************************************
178 * UNIXFS_canonicalize_path [Internal]
180 * Evaluate "/.", "/.." and symbolic links for an absolute unix path.
182 * PARAMS
183 * pszUnixPath [I] An absolute unix path
184 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
186 * RETURNS
187 * Success, TRUE
188 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
190 static BOOL UNIXFS_canonicalize_path(const char *pszUnixPath, char *pszCanonicalPath)
192 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX];
193 struct stat fileStat;
195 TRACE("(pszUnixPath=%s, pszCanonicalPath=%p)\n", debugstr_a(pszUnixPath), pszCanonicalPath);
197 if (!pszUnixPath || *pszUnixPath != '/')
198 return FALSE;
200 strcpy(szPath, pszUnixPath);
202 /* pCanonicalTail always points to the end of the canonical path constructed
203 * thus far. pPathTail points to the still to be processed part of the input
204 * path. pElement points to the path element currently investigated.
206 *pszCanonicalPath = '\0';
207 pCanonicalTail = pszCanonicalPath;
208 pPathTail = szPath;
210 do {
211 char cTemp;
212 int cLinks = 0;
214 pElement = pPathTail;
215 pPathTail = strchr(pPathTail+1, '/');
216 if (!pPathTail) /* Last path element may not be terminated by '/'. */
217 pPathTail = pElement + strlen(pElement);
218 /* Temporarily terminate the current path element. Will be restored later. */
219 cTemp = *pPathTail;
220 *pPathTail = '\0';
222 /* Skip "/." path elements */
223 if (!strcmp("/.", pElement)) {
224 *pPathTail = cTemp;
225 continue;
228 /* Remove last element in canonical path for "/.." elements, then skip. */
229 if (!strcmp("/..", pElement)) {
230 char *pTemp = strrchr(pszCanonicalPath, '/');
231 if (pTemp)
232 pCanonicalTail = pTemp;
233 *pCanonicalTail = '\0';
234 *pPathTail = cTemp;
235 continue;
238 /* lstat returns zero on success. */
239 if (lstat(szPath, &fileStat))
240 return FALSE;
242 if (S_ISLNK(fileStat.st_mode)) {
243 char szSymlink[FILENAME_MAX];
244 int cLinkLen, cTailLen;
246 /* Avoid infinite loop for recursive links. */
247 if (++cLinks > 64)
248 return FALSE;
250 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
251 if (cLinkLen < 0)
252 return FALSE;
254 *pPathTail = cTemp;
255 cTailLen = strlen(pPathTail);
257 if (szSymlink[0] == '/') {
258 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
259 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
260 return FALSE;
262 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
263 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
264 *pszCanonicalPath = '\0';
265 pCanonicalTail = pszCanonicalPath;
266 pPathTail = szPath;
267 } else {
268 /* Relative link. Expand into szPath and continue. */
269 char szTemp[FILENAME_MAX];
270 int cTailLen = strlen(pPathTail);
272 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
273 return FALSE;
275 memcpy(szTemp, pPathTail, cTailLen + 1);
276 memcpy(pElement + 1, szSymlink, cLinkLen);
277 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
278 pPathTail = pElement;
280 } else {
281 /* Regular directory or file. Copy to canonical path */
282 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
283 return FALSE;
285 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
286 pCanonicalTail += pPathTail - pElement;
287 *pPathTail = cTemp;
289 } while (pPathTail[0] == '/' && pPathTail[1]); /* Also handles paths terminated by '/' */
291 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
293 return TRUE;
296 /******************************************************************************
297 * UNIXFS_path_to_pidl [Internal]
299 * PARAMS
300 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
301 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
302 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
304 * RETURNS
305 * Success: TRUE
306 * Failure: FALSE, invalid params or out of memory
308 * NOTES
309 * pUnixFolder also carries the information if the path is expected to be unix or dos.
311 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
312 LPITEMIDLIST pidl;
313 struct stat fileStat;
314 int cSubDirs, cPidlLen, res, cPathLen;
315 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
317 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
319 if (!ppidl || !path)
320 return FALSE;
322 cPathLen = lstrlenW(path);
324 /* Build an absolute path and let pNextPathElement point to the interesting
325 * relative sub-path. We need the absolute path to call 'stat', but the pidl
326 * will only contain the relative part.
328 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
330 /* Absolute dos path. Convert to unix */
331 char *pszUnixPath = wine_get_unix_file_name(path);
332 if (!UNIXFS_canonicalize_path(pszUnixPath, szCompletePath)) {
333 HeapFree(GetProcessHeap(), 0, pszUnixPath);
334 return FALSE;
336 HeapFree(GetProcessHeap(), 0, pszUnixPath);
337 pNextPathElement = szCompletePath + 1;
339 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
341 /* Absolute unix path. Just convert to ANSI. */
342 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
343 pNextPathElement = szCompletePath + 1;
345 else
347 /* Relative dos or unix path. Concat with this folder's path */
348 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
349 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
350 WideCharToMultiByte(CP_ACP, 0, path, -1, szCompletePath + cBasePathLen,
351 FILENAME_MAX - cBasePathLen, NULL, NULL);
352 pNextPathElement = szCompletePath + cBasePathLen;
354 /* If in dos mode, replace '\' with '/' */
355 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
356 char *pBackslash = strchr(pNextPathElement, '\\');
357 while (pBackslash) {
358 *pBackslash = '/';
359 pBackslash = strchr(pBackslash, '\\');
364 /* At this point, we have an absolute unix path in szCompletePath. */
365 TRACE("complete path: %s\n", szCompletePath);
367 /* Count the number of sub-directories in the path */
368 cSubDirs = 1; /* Path may not be terminated with '/', thus start with 1 */
369 pSlash = strchr(pNextPathElement, '/');
370 while (pSlash && pSlash[1]) {
371 cSubDirs++;
372 pSlash = strchr(pSlash+1, '/');
375 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
376 * characters, which are not stored in the ITEMIDLIST. */
377 cPidlLen = strlen(pNextPathElement) - cSubDirs + 1 + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
378 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
379 if (!pidl) return FALSE;
381 /* Concatenate the SHITEMIDs of the sub-directories. */
382 while (*pNextPathElement) {
383 pSlash = strchr(pNextPathElement, '/');
384 if (pSlash) {
385 *pSlash = '\0';
386 res = stat(szCompletePath, &fileStat);
387 *pSlash = '/';
388 if (res) {
389 SHFree(pidl);
390 return FALSE;
392 } else {
393 if (stat(szCompletePath, &fileStat)) {
394 SHFree(pidl);
395 return FALSE;
399 pNextPathElement = UNIXFS_build_shitemid(pNextPathElement, &fileStat, pidl);
400 pidl = ILGetNext(pidl);
402 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
404 if ((int)pidl-(int)*ppidl+sizeof(USHORT) > cPidlLen) /* We've corrupted the heap :( */
405 ERR("Computed length of pidl to small. Please report.\n");
407 return TRUE;
410 /******************************************************************************
411 * UNIXFS_pidl_to_path [Internal]
413 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
415 * PARAMS
416 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
417 * path [O] The corresponding unix path as a zero terminated ascii string
419 * RETURNS
420 * Success: TRUE
421 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
423 static BOOL UNIXFS_pidl_to_path(LPCITEMIDLIST pidl, UnixFolder *pUnixFolder) {
424 LPCITEMIDLIST current = pidl, root;
425 DWORD dwPathLen;
426 char *pNextDir;
428 TRACE("(pidl=%p, pUnixFolder=%p)\n", pidl, pUnixFolder);
430 pUnixFolder->m_pszPath = NULL;
432 /* Find the UnixFolderClass root */
433 while (current->mkid.cb) {
434 LPPIDLDATA pData = _ILGetDataPointer(current);
435 if (!pData) return FALSE;
436 if (pData->type == PT_GUID &&
437 (IsEqualIID(&CLSID_UnixFolder, &pData->u.guid.guid) ||
438 IsEqualIID(&CLSID_UnixDosFolder, &pData->u.guid.guid)))
440 break;
442 current = ILGetNext(current);
444 root = current = ILGetNext(current);
446 /* Determine the path's length bytes */
447 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
448 while (current->mkid.cb) {
449 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
450 current = ILGetNext(current);
453 /* Build the path */
454 pUnixFolder->m_pszPath = pNextDir = SHAlloc(dwPathLen);
455 if (!pUnixFolder->m_pszPath) {
456 WARN("SHAlloc failed!\n");
457 return FALSE;
459 current = root;
460 *pNextDir++ = '/';
461 while (current->mkid.cb) {
462 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
463 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
464 *pNextDir++ = '/';
465 current = ILGetNext(current);
467 *pNextDir='\0';
469 TRACE("--> %s\n", pUnixFolder->m_pszPath);
470 return TRUE;
473 /******************************************************************************
474 * UNIXFS_build_subfolder_pidls [Internal]
476 * Builds an array of subfolder PIDLs relative to a unix directory
478 * PARAMS
479 * path [I] Name of a unix directory as a zero terminated ascii string
480 * apidl [O] The array of PIDLs
481 * pCount [O] Size of apidl
483 * RETURNS
484 * Success: TRUE
485 * Failure: FALSE, path is not a valid unix directory or out of memory
487 * NOTES
488 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
489 * to release each PIDL as well as the array itself with SHFree.
491 static BOOL UNIXFS_build_subfolder_pidls(UnixFolder *pUnixFolder)
493 struct dirent *pDirEntry;
494 struct stat fileStat;
495 DIR *dir;
496 DWORD cDirEntries, i;
497 USHORT sLen;
498 char *pszFQPath;
500 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
502 pUnixFolder->m_apidlSubDirs = NULL;
503 pUnixFolder->m_cSubDirs = 0;
505 dir = opendir(pUnixFolder->m_pszPath);
506 if (!dir) {
507 WARN("Failed to open directory '%s'.\n", pUnixFolder->m_pszPath);
508 return FALSE;
511 /* Allocate space for fully qualified paths */
512 pszFQPath = SHAlloc(strlen(pUnixFolder->m_pszPath) + PATH_MAX);
513 if (!pszFQPath) {
514 WARN("SHAlloc failed!\n");
515 return FALSE;
518 /* Count number of directory entries. */
519 for (cDirEntries = 0, pDirEntry = readdir(dir); pDirEntry; pDirEntry = readdir(dir)) {
520 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
521 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
522 if (!stat(pszFQPath, &fileStat) && (S_ISDIR(fileStat.st_mode) || S_ISREG(fileStat.st_mode))) cDirEntries++;
525 /* If there are no entries, we are done. */
526 if (cDirEntries == 0) {
527 closedir(dir);
528 SHFree(pszFQPath);
529 return TRUE;
532 /* Allocate the array of PIDLs */
533 pUnixFolder->m_apidlSubDirs = SHAlloc(cDirEntries * sizeof(LPITEMIDLIST));
534 if (!pUnixFolder->m_apidlSubDirs) {
535 WARN("SHAlloc failed!\n");
536 return FALSE;
539 /* Allocate and initialize one SHITEMID per sub-directory. */
540 for (rewinddir(dir), pDirEntry = readdir(dir), i = 0; pDirEntry; pDirEntry = readdir(dir)) {
541 LPSHITEMID pid;
543 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
545 sprintf(pszFQPath, "%s%s", pUnixFolder->m_pszPath, pDirEntry->d_name);
546 if (stat(pszFQPath, &fileStat)) continue;
547 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) continue;
549 sLen = strlen(pDirEntry->d_name);
550 pid = (LPSHITEMID)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen)+sizeof(USHORT));
551 if (!pid) {
552 WARN("SHAlloc failed!\n");
553 return FALSE;
555 UNIXFS_build_shitemid(pDirEntry->d_name, &fileStat, pid);
556 memset(((PBYTE)pid)+pid->cb, 0, sizeof(USHORT));
558 pUnixFolder->m_apidlSubDirs[i++] = (LPITEMIDLIST)pid;
561 pUnixFolder->m_cSubDirs = i;
562 closedir(dir);
563 SHFree(pszFQPath);
565 return TRUE;
568 /******************************************************************************
569 * UnixFolderIcon
571 * Singleton class, which is used by the shell to extract icons to represent
572 * folders in tree- and listviews. Currently, all this singleton does is to
573 * provide the shell with the absolute path to "shell32.dll" and with the
574 * indices of the closed and opened folder icons in the resources of this dll.
577 /* UnixFolderIcon object layout and typedef.
579 typedef struct _UnixFolderIcon {
580 const IExtractIconWVtbl *lpIExtractIconWVtbl;
581 BOOL bFolder;
582 } UnixFolderIcon;
584 static HRESULT WINAPI UnixFolderIcon_IExtractIconW_QueryInterface(IExtractIconW *iface, REFIID riid,
585 void **ppv)
587 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
589 if (!ppv) return E_INVALIDARG;
591 if (IsEqualIID(&IID_IUnknown, riid) ||
592 IsEqualIID(&IID_IExtractIconW, riid))
594 *ppv = iface;
595 } else {
596 *ppv = NULL;
597 return E_NOINTERFACE;
600 IExtractIconW_AddRef(iface);
601 return S_OK;
604 static ULONG WINAPI UnixFolderIcon_IExtractIconW_AddRef(IExtractIconW *iface) {
605 TRACE("(iface=%p)\n", iface);
606 return 2;
609 static ULONG WINAPI UnixFolderIcon_IExtractIconW_Release(IExtractIconW *iface) {
610 TRACE("(iface=%p)\n", iface);
611 return 1;
614 static HRESULT WINAPI UnixFolderIcon_IExtractIconW_GetIconLocation(IExtractIconW *iface,
615 UINT uFlags, LPWSTR szIconFile, UINT cchMax, INT* piIndex, UINT* pwFlags)
617 UnixFolderIcon *This = ADJUST_THIS(UnixFolderIcon, IExtractIconW, iface);
619 TRACE("(iface=%p, uFlags=%u, szIconFile=%s, cchMax=%u, piIndex=%p, pwFlags=%p)\n",
620 iface, uFlags, debugstr_w(szIconFile), cchMax, piIndex, pwFlags);
622 lstrcpynW(szIconFile, swShell32Name, cchMax);
623 if (This->bFolder) {
624 *piIndex = (uFlags & GIL_OPENICON) ? -IDI_SHELL_FOLDER_OPEN : -IDI_SHELL_FOLDER;
625 } else {
626 *piIndex = -IDI_SHELL_DOCUMENT;
628 *pwFlags = 0;
630 return S_OK;
633 static HRESULT WINAPI UnixFolderIcon_IExtractIconW_Extract(
634 IExtractIconW *iface, LPCWSTR pszFile, UINT nIconIndex, HICON* phiconLarge, HICON* phiconSmall,
635 UINT nIconSize)
637 TRACE("(iface=%p, pszFile=%s, nIconIndex=%u, phiconLarge=%p, phiconSmall=%p, nIconSize=%u)"
638 "stub\n", iface, debugstr_w(pszFile), nIconIndex, phiconLarge, phiconSmall, nIconSize);
640 return E_NOTIMPL;
643 /* VTable for the IExtractIconW interface of the UnixFolderIcon class.
645 static const IExtractIconWVtbl UnixFolderIcon_IExtractIconW_Vtbl = {
646 UnixFolderIcon_IExtractIconW_QueryInterface,
647 UnixFolderIcon_IExtractIconW_AddRef,
648 UnixFolderIcon_IExtractIconW_Release,
649 UnixFolderIcon_IExtractIconW_GetIconLocation,
650 UnixFolderIcon_IExtractIconW_Extract
653 /* The singleton instance
655 UnixFolderIcon UnixFolderIconSingleton = { &UnixFolderIcon_IExtractIconW_Vtbl, TRUE };
656 UnixFolderIcon UnixDocumentIconSingleton = { &UnixFolderIcon_IExtractIconW_Vtbl, FALSE };
658 /******************************************************************************
659 * UnixFolder
661 * Class whose heap based instances represent unix filesystem directories.
664 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
665 DWORD i;
667 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
669 if (pUnixFolder->m_apidlSubDirs)
670 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
671 SHFree(pUnixFolder->m_apidlSubDirs[i]);
672 SHFree(pUnixFolder->m_apidlSubDirs);
673 SHFree(pUnixFolder->m_pszPath);
674 ILFree(pUnixFolder->m_pidlLocation);
675 SHFree(pUnixFolder);
678 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
679 void **ppv)
681 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
683 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
685 if (!ppv) return E_INVALIDARG;
687 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
688 IsEqualIID(&IID_IShellFolder2, riid))
690 *ppv = &This->lpIShellFolder2Vtbl;
691 } else if (IsEqualIID(&IID_IPersistFolder2, riid) || IsEqualIID(&IID_IPersistFolder, riid) ||
692 IsEqualIID(&IID_IPersist, riid))
694 *ppv = &This->lpIPersistFolder2Vtbl;
695 } else {
696 *ppv = NULL;
697 return E_NOINTERFACE;
700 IUnknown_AddRef((IUnknown*)*ppv);
701 return S_OK;
704 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
705 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
707 TRACE("(iface=%p)\n", iface);
709 return InterlockedIncrement(&This->m_cRef);
712 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
713 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
714 ULONG cRef;
716 TRACE("(iface=%p)\n", iface);
718 cRef = InterlockedDecrement(&This->m_cRef);
720 if (!cRef)
721 UnixFolder_Destroy(This);
723 return cRef;
726 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
727 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
728 ULONG* pdwAttributes)
730 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
731 BOOL result;
733 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
734 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
735 pchEaten, ppidl, pdwAttributes);
737 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
738 if (result && pdwAttributes && *pdwAttributes)
740 /* need to traverse to the last element for the attribute */
741 LPCITEMIDLIST pidl, last_pidl;
742 pidl = last_pidl = *ppidl;
743 while(pidl && pidl->mkid.cb)
745 last_pidl = pidl;
746 pidl = ILGetNext(pidl);
748 SHELL32_GetItemAttributes((IShellFolder*)iface, last_pidl, pdwAttributes);
751 if (!result) TRACE("FAILED!\n");
752 return result ? S_OK : E_FAIL;
755 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter);
757 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
758 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
760 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
761 IUnknown *newIterator;
762 HRESULT hr;
764 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
765 iface, hwndOwner, grfFlags, ppEnumIDList);
767 newIterator = UnixSubFolderIterator_Construct(This, grfFlags);
768 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
769 IUnknown_Release(newIterator);
771 return hr;
774 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
775 LPBC pbcReserved, REFIID riid, void** ppvOut)
777 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
778 IPersistFolder2 *persistFolder;
779 LPITEMIDLIST pidlSubFolder;
780 HRESULT hr;
782 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
783 iface, pidl, pbcReserved, riid, ppvOut);
785 if (This->m_dwPathMode == PATHMODE_DOS)
786 hr = UnixDosFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
787 else
788 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder2, (void**)&persistFolder);
790 if (!SUCCEEDED(hr)) return hr;
791 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
793 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
794 IPersistFolder2_Initialize(persistFolder, pidlSubFolder);
795 IPersistFolder2_Release(persistFolder);
796 ILFree(pidlSubFolder);
798 return hr;
801 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
802 LPBC pbcReserved, REFIID riid, void** ppvObj)
804 TRACE("stub\n");
805 return E_NOTIMPL;
808 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
809 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
811 BOOL isEmpty1, isEmpty2;
812 HRESULT hr = E_FAIL;
813 LPITEMIDLIST firstpidl;
814 IShellFolder2 *psf;
815 int compare;
817 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
819 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
820 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
822 if (isEmpty1 && isEmpty2)
823 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
824 else if (isEmpty1)
825 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
826 else if (isEmpty2)
827 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
829 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
830 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
831 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
832 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
834 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
835 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
836 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
838 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
839 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
841 if (pidl1->mkid.cb < pidl2->mkid.cb)
842 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
843 else if (pidl1->mkid.cb > pidl2->mkid.cb)
844 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
846 firstpidl = ILCloneFirst(pidl1);
847 pidl1 = ILGetNext(pidl1);
848 pidl2 = ILGetNext(pidl2);
850 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
851 if (SUCCEEDED(hr)) {
852 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
853 IShellFolder2_Release(psf);
856 ILFree(firstpidl);
857 return hr;
860 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
861 REFIID riid, void** ppv)
863 HRESULT hr = E_INVALIDARG;
865 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
867 if (!ppv) return E_INVALIDARG;
868 *ppv = NULL;
870 if (IsEqualIID(&IID_IShellView, riid)) {
871 LPSHELLVIEW pShellView;
873 pShellView = IShellView_Constructor((IShellFolder*)iface);
874 if (pShellView) {
875 hr = IShellView_QueryInterface(pShellView, riid, ppv);
876 IShellView_Release(pShellView);
880 return hr;
883 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
884 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
886 UINT i;
887 SFGAOF flags= ~(SFGAOF)0;
889 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p) semi-stub\n", iface, cidl, apidl, rgfInOut);
891 for (i=0; i<cidl; i++) {
892 LPPIDLDATA pData = _ILGetDataPointer(apidl[i]);
893 if (!pData) continue;
894 if (pData->type == PT_FOLDER) flags &= (SFGAO_FILESYSTEM|SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER);
895 if (pData->type == PT_VALUE) flags &= SFGAO_FILESYSTEM;
898 *rgfInOut = *rgfInOut & flags;
900 return S_OK;
903 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
904 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
906 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
908 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
909 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
911 if (IsEqualIID(&IID_IContextMenu, riid)) {
912 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
913 return S_OK;
914 } else if (IsEqualIID(&IID_IDataObject, riid)) {
915 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
916 return S_OK;
917 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
918 FIXME("IExtractIconA\n");
919 return E_FAIL;
920 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
921 if (cidl != 1) return E_FAIL;
922 if (_ILIsFolder(apidl[0]))
923 *ppvOut = &UnixFolderIconSingleton;
924 else
925 *ppvOut = &UnixDocumentIconSingleton;
926 return S_OK;
927 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
928 FIXME("IDropTarget\n");
929 return E_FAIL;
930 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
931 FIXME("IShellLinkW\n");
932 return E_FAIL;
933 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
934 FIXME("IShellLinkA\n");
935 return E_FAIL;
936 } else {
937 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
938 return E_NOINTERFACE;
942 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
943 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
945 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
946 HRESULT hr = S_OK;
948 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
950 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
951 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
953 if (!pidl->mkid.cb) {
954 lpName->uType = STRRET_CSTR;
955 strcpy(lpName->u.cStr, This->m_pszPath);
956 if (This->m_dwPathMode == PATHMODE_DOS) {
957 char path[MAX_PATH];
958 GetFullPathNameA(lpName->u.cStr, MAX_PATH, path, NULL);
959 strcpy(lpName->u.cStr, path);
961 } else {
962 IShellFolder *pSubFolder;
963 USHORT emptyIDL = 0;
965 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
966 if (!SUCCEEDED(hr)) return hr;
968 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
969 IShellFolder_Release(pSubFolder);
971 } else {
972 char *pszFileName = _ILGetTextPointer(pidl);
973 lpName->uType = STRRET_CSTR;
974 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
977 TRACE("--> %s\n", lpName->u.cStr);
979 return hr;
982 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* This, HWND hwnd,
983 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
985 TRACE("stub\n");
986 return E_NOTIMPL;
989 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
990 IEnumExtraSearch **ppEnum)
992 TRACE("stub\n");
993 return E_NOTIMPL;
996 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
997 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
999 TRACE("stub\n");
1000 return E_NOTIMPL;
1003 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
1004 UINT iColumn, SHCOLSTATEF *pcsFlags)
1006 TRACE("stub\n");
1007 return E_NOTIMPL;
1010 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1011 GUID *pguid)
1013 TRACE("stub\n");
1014 return E_NOTIMPL;
1017 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1018 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1020 TRACE("stub\n");
1021 return E_NOTIMPL;
1024 #define SHELLVIEWCOLUMNS 6
1026 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1027 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1029 HRESULT hr = E_FAIL;
1030 struct passwd *pPasswd;
1031 struct group *pGroup;
1032 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1033 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1034 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1035 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1036 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1037 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 8},
1038 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
1041 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1043 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1044 return E_INVALIDARG;
1046 if (!pidl) {
1047 psd->fmt = SFHeader[iColumn].fmt;
1048 psd->cxChar = SFHeader[iColumn].cxChar;
1049 psd->str.uType = STRRET_CSTR;
1050 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1051 return S_OK;
1052 } else {
1053 StatStruct *pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pidl);
1054 psd->str.u.cStr[0] = '\0';
1055 psd->str.uType = STRRET_CSTR;
1056 switch (iColumn) {
1057 case 0:
1058 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1059 break;
1060 case 1:
1061 psd->str.u.cStr[0] = S_ISDIR(pStatStruct->st_mode) ? 'd' : '-';
1062 psd->str.u.cStr[1] = (pStatStruct->st_mode & S_IRUSR) ? 'r' : '-';
1063 psd->str.u.cStr[2] = (pStatStruct->st_mode & S_IWUSR) ? 'w' : '-';
1064 psd->str.u.cStr[3] = (pStatStruct->st_mode & S_IXUSR) ? 'x' : '-';
1065 psd->str.u.cStr[4] = (pStatStruct->st_mode & S_IRGRP) ? 'r' : '-';
1066 psd->str.u.cStr[5] = (pStatStruct->st_mode & S_IWGRP) ? 'w' : '-';
1067 psd->str.u.cStr[6] = (pStatStruct->st_mode & S_IXGRP) ? 'x' : '-';
1068 psd->str.u.cStr[7] = (pStatStruct->st_mode & S_IROTH) ? 'r' : '-';
1069 psd->str.u.cStr[8] = (pStatStruct->st_mode & S_IWOTH) ? 'w' : '-';
1070 psd->str.u.cStr[9] = (pStatStruct->st_mode & S_IXOTH) ? 'x' : '-';
1071 psd->str.u.cStr[10] = '\0';
1072 break;
1073 case 2:
1074 pPasswd = getpwuid(pStatStruct->st_uid);
1075 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1076 break;
1077 case 3:
1078 pGroup = getgrgid(pStatStruct->st_gid);
1079 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1080 break;
1081 case 4:
1082 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1083 break;
1084 case 5:
1085 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1086 break;
1090 return hr;
1093 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1094 SHCOLUMNID *pscid)
1096 TRACE("stub\n");
1097 return E_NOTIMPL;
1100 /* VTable for UnixFolder's IShellFolder2 interface.
1102 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1103 UnixFolder_IShellFolder2_QueryInterface,
1104 UnixFolder_IShellFolder2_AddRef,
1105 UnixFolder_IShellFolder2_Release,
1106 UnixFolder_IShellFolder2_ParseDisplayName,
1107 UnixFolder_IShellFolder2_EnumObjects,
1108 UnixFolder_IShellFolder2_BindToObject,
1109 UnixFolder_IShellFolder2_BindToStorage,
1110 UnixFolder_IShellFolder2_CompareIDs,
1111 UnixFolder_IShellFolder2_CreateViewObject,
1112 UnixFolder_IShellFolder2_GetAttributesOf,
1113 UnixFolder_IShellFolder2_GetUIObjectOf,
1114 UnixFolder_IShellFolder2_GetDisplayNameOf,
1115 UnixFolder_IShellFolder2_SetNameOf,
1116 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1117 UnixFolder_IShellFolder2_EnumSearches,
1118 UnixFolder_IShellFolder2_GetDefaultColumn,
1119 UnixFolder_IShellFolder2_GetDefaultColumnState,
1120 UnixFolder_IShellFolder2_GetDetailsEx,
1121 UnixFolder_IShellFolder2_GetDetailsOf,
1122 UnixFolder_IShellFolder2_MapColumnToSCID
1125 static HRESULT WINAPI UnixFolder_IPersistFolder2_QueryInterface(IPersistFolder2* This, REFIID riid,
1126 void** ppvObject)
1128 return UnixFolder_IShellFolder2_QueryInterface(
1129 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This), riid, ppvObject);
1132 static ULONG WINAPI UnixFolder_IPersistFolder2_AddRef(IPersistFolder2* This)
1134 return UnixFolder_IShellFolder2_AddRef(
1135 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1138 static ULONG WINAPI UnixFolder_IPersistFolder2_Release(IPersistFolder2* This)
1140 return UnixFolder_IShellFolder2_Release(
1141 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder2, This));
1144 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetClassID(IPersistFolder2* This, CLSID* pClassID)
1146 TRACE("stub\n");
1147 return E_NOTIMPL;
1150 static HRESULT WINAPI UnixFolder_IPersistFolder2_Initialize(IPersistFolder2* iface, LPCITEMIDLIST pidl)
1152 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1154 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1156 This->m_pidlLocation = ILClone(pidl);
1158 pdump(pidl);
1160 UNIXFS_pidl_to_path(pidl, This);
1161 UNIXFS_build_subfolder_pidls(This);
1163 return S_OK;
1166 static HRESULT WINAPI UnixFolder_IPersistFolder2_GetCurFolder(IPersistFolder2* iface, LPITEMIDLIST* ppidl)
1168 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder2, iface);
1170 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1172 if (!ppidl)
1173 return E_POINTER;
1174 *ppidl = ILClone (This->m_pidlLocation);
1175 return S_OK;
1178 /* VTable for UnixFolder's IPersistFolder interface.
1180 static const IPersistFolder2Vtbl UnixFolder_IPersistFolder2_Vtbl = {
1181 UnixFolder_IPersistFolder2_QueryInterface,
1182 UnixFolder_IPersistFolder2_AddRef,
1183 UnixFolder_IPersistFolder2_Release,
1184 UnixFolder_IPersistFolder2_GetClassID,
1185 UnixFolder_IPersistFolder2_Initialize,
1186 UnixFolder_IPersistFolder2_GetCurFolder
1189 /******************************************************************************
1190 * Unix[Dos]Folder_Constructor [Internal]
1192 * PARAMS
1193 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1194 * riid [I] Interface asked for by the client.
1195 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1197 * NOTES
1198 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1199 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1200 * compatible signature.
1202 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1203 * means that paths are converted from dos to unix and back at the interfaces.
1205 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, DWORD dwPathMode) {
1206 HRESULT hr = E_FAIL;
1207 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1209 if(pUnixFolder) {
1210 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1211 pUnixFolder->lpIPersistFolder2Vtbl = &UnixFolder_IPersistFolder2_Vtbl;
1212 pUnixFolder->m_cRef = 0;
1213 pUnixFolder->m_pszPath = NULL;
1214 pUnixFolder->m_apidlSubDirs = NULL;
1215 pUnixFolder->m_cSubDirs = 0;
1216 pUnixFolder->m_dwPathMode = dwPathMode;
1218 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1219 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1220 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1222 return hr;
1225 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1226 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1227 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_UNIX);
1230 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1231 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1232 return CreateUnixFolder(pUnkOuter, riid, ppv, PATHMODE_DOS);
1235 /******************************************************************************
1236 * UnixSubFolderIterator
1238 * Class whose heap based objects represent iterators over the sub-directories
1239 * of a given UnixFolder object.
1242 /* UnixSubFolderIterator object layout and typedef.
1244 typedef struct _UnixSubFolderIterator {
1245 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1246 ULONG m_cRef;
1247 UnixFolder *m_pUnixFolder;
1248 ULONG m_cIdx;
1249 SHCONTF m_fFilter;
1250 } UnixSubFolderIterator;
1252 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1253 TRACE("(iterator=%p)\n", iterator);
1255 UnixFolder_IShellFolder2_Release((IShellFolder2*)iterator->m_pUnixFolder);
1256 SHFree(iterator);
1259 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1260 REFIID riid, void** ppv)
1262 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1264 if (!ppv) return E_INVALIDARG;
1266 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1267 *ppv = iface;
1268 } else {
1269 *ppv = NULL;
1270 return E_NOINTERFACE;
1273 IEnumIDList_AddRef(iface);
1274 return S_OK;
1277 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1279 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1281 TRACE("(iface=%p)\n", iface);
1283 return InterlockedIncrement(&This->m_cRef);
1286 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1288 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1289 ULONG cRef;
1291 TRACE("(iface=%p)\n", iface);
1293 cRef = InterlockedDecrement(&This->m_cRef);
1295 if (!cRef)
1296 UnixSubFolderIterator_Destroy(This);
1298 return cRef;
1301 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1302 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1304 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1305 ULONG i;
1307 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface, celt, rgelt, pceltFetched);
1309 for (i=0; (i < celt) && (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs); This->m_cIdx++) {
1310 LPITEMIDLIST pCurrent = This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx];
1311 if (UNIXFS_is_pidl_of_type(pCurrent, This->m_fFilter)) {
1312 rgelt[i] = ILClone(pCurrent);
1313 i++;
1317 if (pceltFetched)
1318 *pceltFetched = i;
1320 return i == celt ? S_OK : S_FALSE;
1323 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1325 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1326 ULONG i;
1328 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1330 for (i=0; i < celt; i++) {
1331 while (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs &&
1332 !UNIXFS_is_pidl_of_type(This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx], This->m_fFilter))
1334 This->m_cIdx++;
1336 This->m_cIdx++;
1339 if (This->m_cIdx > This->m_pUnixFolder->m_cSubDirs) {
1340 This->m_cIdx = This->m_pUnixFolder->m_cSubDirs;
1341 return S_FALSE;
1342 } else {
1343 return S_OK;
1347 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1349 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1351 TRACE("(iface=%p)\n", iface);
1353 This->m_cIdx = 0;
1355 return S_OK;
1358 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1359 IEnumIDList** ppenum)
1361 TRACE("stub\n");
1362 return E_NOTIMPL;
1365 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1367 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1368 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1369 UnixSubFolderIterator_IEnumIDList_AddRef,
1370 UnixSubFolderIterator_IEnumIDList_Release,
1371 UnixSubFolderIterator_IEnumIDList_Next,
1372 UnixSubFolderIterator_IEnumIDList_Skip,
1373 UnixSubFolderIterator_IEnumIDList_Reset,
1374 UnixSubFolderIterator_IEnumIDList_Clone
1377 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1378 UnixSubFolderIterator *iterator;
1380 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1382 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1383 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1384 iterator->m_cRef = 0;
1385 iterator->m_cIdx = 0;
1386 iterator->m_pUnixFolder = pUnixFolder;
1387 iterator->m_fFilter = fFilter;
1389 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1390 UnixFolder_IShellFolder2_AddRef((IShellFolder2*)pUnixFolder);
1392 return (IUnknown*)iterator;