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
26 #ifdef HAVE_SYS_STAT_H
27 # include <sys/stat.h>
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
44 #include "wine/debug.h"
46 #include "shell32_main.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(shell);
53 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
55 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
56 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
58 /* FileStruct reserves one byte for szNames, thus we don't have to
59 * alloc a byte for the terminating '\0' of 'name'. Two of the
60 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
61 * type field. One is for FileStruct's szNames field, to terminate
62 * the alternate DOS name, which we don't use here. And then there's
63 * the additional StatStruct.
65 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
66 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char)+sizeof(StatStruct))
67 #define NAME_LEN_FROM_LPSHITEMID(s) \
68 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char)-sizeof(StatStruct))
69 #define LPSTATSTRUCT_FROM_LPSHITEMID(s) ((StatStruct*)(((LPBYTE)s)+((LPSHITEMID)s)->cb-sizeof(StatStruct)))
71 /* This structure is appended to shell32's FileStruct type in IDLs to store unix
72 * filesystem specific informationen extracted with the stat system call.
74 typedef struct tagStatStruct {
80 /******************************************************************************
81 * UNIXFS_is_pidl_of_type [INTERNAL]
83 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
86 * pIDL [I] The ITEMIDLIST to be checked.
87 * fFilter [I] Shell condition flags, which specify the filter.
90 * TRUE, if pIDL is accepted by fFilter
93 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
94 LPSTR pszText = _ILGetTextPointer(pIDL);
95 if (!pszText) return FALSE;
96 if (pszText[0] == '.' && !(fFilter & SHCONTF_INCLUDEHIDDEN)) return FALSE;
97 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
98 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
102 /******************************************************************************
103 * UNIXFS_build_shitemid [Internal]
105 * Constructs a new SHITEMID for a single path item (up to the next '/' or
106 * '\0') into a buffer. Decorates the SHITEMID with information from a stat
110 * name [I] The name of the next path item. Terminated by either '\0' or '/'.
111 * pStat [I] A stat struct variable obtained by a stat system call on the file.
112 * buffer [O] SHITEMID will be constructed here.
115 * A pointer to the next '/' or '\0' character in name.
118 * Minimum size of buffer is SHITEMID_LEN_FROM_NAME_LEN(strlen(name)).
119 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
122 static char* UNIXFS_build_shitemid(char *name, struct stat *pStat, void *buffer) {
126 StatStruct *pStatStruct;
130 TRACE("(name=%s, buffer=%p)\n", debugstr_a(name), buffer);
132 pSlash = strchr(name, '/');
133 cNameLen = pSlash ? pSlash - name : strlen(name);
135 memset(buffer, 0, SHITEMID_LEN_FROM_NAME_LEN(cNameLen));
136 ((LPSHITEMID)buffer)->cb = SHITEMID_LEN_FROM_NAME_LEN(cNameLen) ;
138 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)buffer);
139 pIDLData->type = S_ISDIR(pStat->st_mode) ? PT_FOLDER : PT_VALUE;
140 pIDLData->u.file.dwFileSize = (DWORD)pStat->st_size;
141 RtlSecondsSince1970ToTime( pStat->st_mtime, &time );
142 fileTime.dwLowDateTime = time.u.LowPart;
143 fileTime.dwHighDateTime = time.u.HighPart;
144 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
145 pIDLData->u.file.uFileAttribs = 0;
146 memcpy(pIDLData->u.file.szNames, name, cNameLen);
148 pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(buffer);
149 pStatStruct->st_mode = pStat->st_mode;
150 pStatStruct->st_uid = pStat->st_uid;
151 pStatStruct->st_gid = pStat->st_gid;
153 return pSlash ? pSlash+1 : (name + cNameLen);
156 /******************************************************************************
157 * UNIXFS_path_to_pidl [Internal]
160 * path [I] An absolute unix path
161 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
165 * Failure: FALSE, invalid params, path not absolute or out of memory
168 * 'path' has to be an absolute unix filesystem path starting and
169 * ending with a slash ('/'). Currently, only directories (no files)
172 static BOOL UNIXFS_path_to_pidl(char *path, LPITEMIDLIST *ppidl) {
174 struct stat fileStat;
175 int cSubDirs, cPidlLen, res;
178 TRACE("path=%s, ppidl=%p", debugstr_a(path), ppidl);
180 /* Fail, if no absolute path given */
181 if (!ppidl || !path || path[0] != '/') return FALSE;
183 /* Skip the '/' prefix */
186 /* Count the number of sub-directories in the path */
188 pSlash = strchr(path, '/');
191 pSlash = strchr(pSlash+1, '/');
194 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
195 * characters, which are not stored in the ITEMIDLIST. */
196 cPidlLen = strlen(path) - cSubDirs + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
197 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
198 if (!pidl) return FALSE;
200 /* Concatenate the SHITEMIDs of the sub-directories. */
202 pSlash = strchr(path, '/');
205 res = stat(path, &fileStat);
207 if (res) return FALSE;
209 if (stat(path, &fileStat)) return FALSE;
212 path = UNIXFS_build_shitemid(path, &fileStat, pidl);
213 pidl = ILGetNext(pidl);
215 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
220 /******************************************************************************
221 * UNIXFS_pidl_to_path [Internal]
223 * Construct the unix path that corresponds to a fully qualified ITEMIDLIST
226 * pidl [I] ITEMIDLIST that specifies the absolute location of the folder
227 * path [O] The corresponding unix path as a zero terminated ascii string
231 * Failure: FALSE, pidl doesn't specify a unix path or out of memory
233 static BOOL UNIXFS_pidl_to_path(LPCITEMIDLIST pidl, PSZ *path) {
234 LPCITEMIDLIST current = pidl, root;
238 TRACE("(pidl=%p, path=%p)\n", pidl, path);
242 /* Find the UnixFolderClass root */
243 while (current->mkid.cb) {
244 LPPIDLDATA pData = _ILGetDataPointer(current);
245 if (!pData) return FALSE;
246 if (pData->type == PT_GUID && IsEqualIID(&CLSID_UnixFolder, &pData->u.guid.guid)) break;
247 current = ILGetNext(current);
249 root = current = ILGetNext(current);
251 /* Determine the path's length bytes */
252 dwPathLen = 2; /* For the '/' prefix and the terminating '\0' */
253 while (current->mkid.cb) {
254 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
255 current = ILGetNext(current);
259 *path = pNextDir = SHAlloc(dwPathLen);
261 WARN("SHAlloc failed!\n");
266 while (current->mkid.cb) {
267 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
268 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
270 current = ILGetNext(current);
274 TRACE("resulting path: %s\n", *path);
278 /******************************************************************************
279 * UNIXFS_build_subfolder_pidls [Internal]
281 * Builds an array of subfolder PIDLs relative to a unix directory
284 * path [I] Name of a unix directory as a zero terminated ascii string
285 * apidl [O] The array of PIDLs
286 * pCount [O] Size of apidl
290 * Failure: FALSE, path is not a valid unix directory or out of memory
293 * The array of PIDLs and each PIDL are allocated with SHAlloc. You'll have
294 * to release each PIDL as well as the array itself with SHFree.
296 static BOOL UNIXFS_build_subfolder_pidls(const char *path, LPITEMIDLIST **apidl, DWORD *pCount)
298 struct dirent *pDirEntry;
299 struct stat fileStat;
301 DWORD cDirEntries, i;
305 TRACE("(path=%s, apidl=%p, pCount=%p)\n", debugstr_a(path), apidl, pCount);
312 WARN("Failed to open directory '%s'.\n", path);
316 /* Allocate space for fully qualified paths */
317 pszFQPath = SHAlloc(strlen(path) + NAME_MAX);
319 WARN("SHAlloc failed!\n");
323 /* Count number of directory entries. */
324 for (cDirEntries = 0, pDirEntry = readdir(dir); pDirEntry; pDirEntry = readdir(dir)) {
325 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
326 sprintf(pszFQPath, "%s%s", path, pDirEntry->d_name);
327 if (!stat(pszFQPath, &fileStat) && (S_ISDIR(fileStat.st_mode) || S_ISREG(fileStat.st_mode))) cDirEntries++;
330 /* If there are no entries, we are done. */
331 if (cDirEntries == 0) {
337 /* Allocate the array of PIDLs */
338 *apidl = SHAlloc(cDirEntries * sizeof(LPITEMIDLIST));
340 WARN("SHAlloc failed!\n");
344 /* Allocate and initialize one SHITEMID per sub-directory. */
345 for (rewinddir(dir), pDirEntry = readdir(dir), i = 0; pDirEntry; pDirEntry = readdir(dir)) {
348 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
350 sprintf(pszFQPath, "%s%s", path, pDirEntry->d_name);
351 if (stat(pszFQPath, &fileStat)) continue;
352 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) continue;
354 sLen = strlen(pDirEntry->d_name);
355 pid = (LPSHITEMID)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(sLen)+sizeof(USHORT));
357 WARN("SHAlloc failed!\n");
360 UNIXFS_build_shitemid(pDirEntry->d_name, &fileStat, pid);
361 memset(((PBYTE)pid)+pid->cb, 0, sizeof(USHORT));
363 (*apidl)[i++] = (LPITEMIDLIST)pid;
373 /******************************************************************************
376 * Singleton class, which is used by the shell to extract icons to represent
377 * folders in tree- and listviews. Currently, all this singleton does is to
378 * provide the shell with the absolute path to "shell32.dll" and with the
379 * indices of the closed and opened folder icons in the resources of this dll.
382 /* UnixFolderIcon object layout and typedef.
384 typedef struct _UnixFolderIcon {
385 const IExtractIconWVtbl *lpIExtractIconWVtbl;
389 static HRESULT WINAPI UnixFolderIcon_IExtractIconW_QueryInterface(IExtractIconW *iface, REFIID riid,
392 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
394 if (!ppv) return E_INVALIDARG;
396 if (IsEqualIID(&IID_IUnknown, riid) ||
397 IsEqualIID(&IID_IExtractIconW, riid))
402 return E_NOINTERFACE;
405 IExtractIconW_AddRef(iface);
409 static ULONG WINAPI UnixFolderIcon_IExtractIconW_AddRef(IExtractIconW *iface) {
410 TRACE("(iface=%p)\n", iface);
414 static ULONG WINAPI UnixFolderIcon_IExtractIconW_Release(IExtractIconW *iface) {
415 TRACE("(iface=%p)\n", iface);
419 static HRESULT WINAPI UnixFolderIcon_IExtractIconW_GetIconLocation(IExtractIconW *iface,
420 UINT uFlags, LPWSTR szIconFile, UINT cchMax, INT* piIndex, UINT* pwFlags)
422 UnixFolderIcon *This = ADJUST_THIS(UnixFolderIcon, IExtractIconW, iface);
424 TRACE("(iface=%p, uFlags=%u, szIconFile=%s, cchMax=%u, piIndex=%p, pwFlags=%p)\n",
425 iface, uFlags, debugstr_w(szIconFile), cchMax, piIndex, pwFlags);
427 lstrcpynW(szIconFile, swShell32Name, cchMax);
429 *piIndex = (uFlags & GIL_OPENICON) ? -IDI_SHELL_FOLDER_OPEN : -IDI_SHELL_FOLDER;
431 *piIndex = -IDI_SHELL_DOCUMENT;
438 static HRESULT WINAPI UnixFolderIcon_IExtractIconW_Extract(
439 IExtractIconW *iface, LPCWSTR pszFile, UINT nIconIndex, HICON* phiconLarge, HICON* phiconSmall,
442 TRACE("(iface=%p, pszFile=%s, nIconIndex=%u, phiconLarge=%p, phiconSmall=%p, nIconSize=%u)"
443 "stub\n", iface, debugstr_w(pszFile), nIconIndex, phiconLarge, phiconSmall, nIconSize);
448 /* VTable for the IExtractIconW interface of the UnixFolderIcon class.
450 static const IExtractIconWVtbl UnixFolderIcon_IExtractIconW_Vtbl = {
451 UnixFolderIcon_IExtractIconW_QueryInterface,
452 UnixFolderIcon_IExtractIconW_AddRef,
453 UnixFolderIcon_IExtractIconW_Release,
454 UnixFolderIcon_IExtractIconW_GetIconLocation,
455 UnixFolderIcon_IExtractIconW_Extract
458 /* The singleton instance
460 UnixFolderIcon UnixFolderIconSingleton = { &UnixFolderIcon_IExtractIconW_Vtbl, TRUE };
461 UnixFolderIcon UnixDocumentIconSingleton = { &UnixFolderIcon_IExtractIconW_Vtbl, FALSE };
463 /******************************************************************************
466 * Class whose heap based instances represent unix filesystem directories.
469 /* UnixFolder object layout and typedef.
471 typedef struct _UnixFolder {
472 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
473 const IPersistFolderVtbl *lpIPersistFolderVtbl;
476 LPITEMIDLIST m_pidlLocation;
477 LPITEMIDLIST *m_apidlSubDirs;
481 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
484 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
486 if (pUnixFolder->m_apidlSubDirs)
487 for (i=0; i < pUnixFolder->m_cSubDirs; i++)
488 SHFree(pUnixFolder->m_apidlSubDirs[i]);
489 SHFree(pUnixFolder->m_apidlSubDirs);
490 SHFree(pUnixFolder->m_pszPath);
491 ILFree(pUnixFolder->m_pidlLocation);
495 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
498 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
500 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
502 if (!ppv) return E_INVALIDARG;
504 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
505 IsEqualIID(&IID_IShellFolder2, riid))
507 *ppv = &This->lpIShellFolder2Vtbl;
508 } else if (IsEqualIID(&IID_IPersistFolder, riid) || IsEqualIID(&IID_IPersist, riid)) {
509 *ppv = &This->lpIPersistFolderVtbl;
512 return E_NOINTERFACE;
515 IUnknown_AddRef((IUnknown*)*ppv);
519 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
520 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
522 TRACE("(iface=%p)\n", iface);
524 return InterlockedIncrement(&This->m_cRef);
527 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
528 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
531 TRACE("(iface=%p)\n", iface);
533 cRef = InterlockedDecrement(&This->m_cRef);
536 UnixFolder_Destroy(This);
541 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
542 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
543 ULONG* pdwAttributes)
549 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
550 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
551 pchEaten, ppidl, pdwAttributes);
553 cPathLen = lstrlenW(lpszDisplayName);
554 pszAnsiPath = (char*)SHAlloc(cPathLen+1);
555 WideCharToMultiByte(CP_ACP, 0, lpszDisplayName, -1, pszAnsiPath, cPathLen+1, NULL, NULL);
557 result = UNIXFS_path_to_pidl(pszAnsiPath, ppidl);
561 return result ? S_OK : E_FAIL;
564 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter);
566 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
567 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
569 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
570 IUnknown *newIterator;
573 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
574 iface, hwndOwner, grfFlags, ppEnumIDList);
576 newIterator = UnixSubFolderIterator_Construct(This, grfFlags);
577 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
578 IUnknown_Release(newIterator);
583 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
584 LPBC pbcReserved, REFIID riid, void** ppvOut)
586 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
587 IPersistFolder *persistFolder;
588 LPITEMIDLIST pidlSubFolder;
591 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
592 iface, pidl, pbcReserved, riid, ppvOut);
594 hr = UnixFolder_Constructor(NULL, &IID_IPersistFolder, (void**)&persistFolder);
595 if (!SUCCEEDED(hr)) return hr;
596 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
598 pidlSubFolder = ILCombine(This->m_pidlLocation, pidl);
599 IPersistFolder_Initialize(persistFolder, pidlSubFolder);
600 IPersistFolder_Release(persistFolder);
601 ILFree(pidlSubFolder);
606 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
607 LPBC pbcReserved, REFIID riid, void** ppvObj)
613 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
614 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
616 BOOL isEmpty1, isEmpty2;
618 LPITEMIDLIST firstpidl;
622 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
624 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
625 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
627 if (isEmpty1 && isEmpty2)
628 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
630 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
632 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
634 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
635 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
636 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
637 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
639 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
640 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
641 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
643 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
644 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)(compare == CSTR_LESS_THAN)?-1:1);
646 if (pidl1->mkid.cb < pidl2->mkid.cb)
647 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
648 else if (pidl1->mkid.cb > pidl2->mkid.cb)
649 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
651 firstpidl = ILCloneFirst(pidl1);
652 pidl1 = ILGetNext(pidl1);
653 pidl2 = ILGetNext(pidl2);
655 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
657 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
658 IShellFolder2_Release(psf);
665 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
666 REFIID riid, void** ppv)
668 HRESULT hr = E_INVALIDARG;
670 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
672 if (!ppv) return E_INVALIDARG;
675 if (IsEqualIID(&IID_IShellView, riid)) {
676 LPSHELLVIEW pShellView;
678 pShellView = IShellView_Constructor((IShellFolder*)iface);
680 hr = IShellView_QueryInterface(pShellView, riid, ppv);
681 IShellView_Release(pShellView);
688 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
689 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
692 SFGAOF flags= ~(SFGAOF)0;
694 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p) semi-stub\n", iface, cidl, apidl, rgfInOut);
696 for (i=0; i<cidl; i++) {
697 LPPIDLDATA pData = _ILGetDataPointer(apidl[i]);
698 if (!pData) continue;
699 if (pData->type == PT_FOLDER) flags &= (SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_HASSUBFOLDER);
700 if (pData->type == PT_VALUE) flags &= SFGAO_FILESYSTEM;
703 *rgfInOut = *rgfInOut & flags;
708 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
709 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
711 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
713 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
714 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
716 if (IsEqualIID(&IID_IContextMenu, riid)) {
717 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
719 } else if (IsEqualIID(&IID_IDataObject, riid)) {
720 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
722 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
723 FIXME("IExtractIconA\n");
725 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
726 if (cidl != 1) return E_FAIL;
727 if (_ILIsFolder(apidl[0]))
728 *ppvOut = &UnixFolderIconSingleton;
730 *ppvOut = &UnixDocumentIconSingleton;
732 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
733 FIXME("IDropTarget\n");
735 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
736 FIXME("IShellLinkW\n");
738 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
739 FIXME("IShellLinkA\n");
742 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
743 return E_NOINTERFACE;
747 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
748 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
750 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
753 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
755 if ((GET_SHGDN_FOR(uFlags) == SHGDN_FORPARSING) &&
756 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
758 if (!pidl->mkid.cb) {
759 lpName->uType = STRRET_CSTR;
760 strcpy(lpName->u.cStr, This->m_pszPath);
762 IShellFolder *pSubFolder;
765 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
766 if (!SUCCEEDED(hr)) return hr;
768 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
769 IShellFolder_Release(pSubFolder);
772 char *pszFileName = _ILGetTextPointer(pidl);
773 lpName->uType = STRRET_CSTR;
774 strcpy(lpName->u.cStr, pszFileName ? pszFileName : "");
780 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* This, HWND hwnd,
781 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
787 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
788 IEnumExtraSearch **ppEnum)
794 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
795 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
801 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
802 UINT iColumn, SHCOLSTATEF *pcsFlags)
808 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
815 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
816 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
822 #define SHELLVIEWCOLUMNS 6
824 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
825 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
828 struct passwd *pPasswd;
829 struct group *pGroup;
830 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
831 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
832 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
833 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
834 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
835 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 8},
836 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
839 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
841 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
845 psd->fmt = SFHeader[iColumn].fmt;
846 psd->cxChar = SFHeader[iColumn].cxChar;
847 psd->str.uType = STRRET_CSTR;
848 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
851 StatStruct *pStatStruct = LPSTATSTRUCT_FROM_LPSHITEMID(pidl);
852 psd->str.u.cStr[0] = '\0';
853 psd->str.uType = STRRET_CSTR;
856 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
859 psd->str.u.cStr[0] = S_ISDIR(pStatStruct->st_mode) ? 'd' : '-';
860 psd->str.u.cStr[1] = (pStatStruct->st_mode & S_IRUSR) ? 'r' : '-';
861 psd->str.u.cStr[2] = (pStatStruct->st_mode & S_IWUSR) ? 'w' : '-';
862 psd->str.u.cStr[3] = (pStatStruct->st_mode & S_IXUSR) ? 'x' : '-';
863 psd->str.u.cStr[4] = (pStatStruct->st_mode & S_IRGRP) ? 'r' : '-';
864 psd->str.u.cStr[5] = (pStatStruct->st_mode & S_IWGRP) ? 'w' : '-';
865 psd->str.u.cStr[6] = (pStatStruct->st_mode & S_IXGRP) ? 'x' : '-';
866 psd->str.u.cStr[7] = (pStatStruct->st_mode & S_IROTH) ? 'r' : '-';
867 psd->str.u.cStr[8] = (pStatStruct->st_mode & S_IWOTH) ? 'w' : '-';
868 psd->str.u.cStr[9] = (pStatStruct->st_mode & S_IXOTH) ? 'x' : '-';
869 psd->str.u.cStr[10] = '\0';
872 pPasswd = getpwuid(pStatStruct->st_uid);
873 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
876 pGroup = getgrgid(pStatStruct->st_gid);
877 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
880 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
883 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
891 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
898 /* VTable for UnixFolder's IShellFolder2 interface.
900 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
901 UnixFolder_IShellFolder2_QueryInterface,
902 UnixFolder_IShellFolder2_AddRef,
903 UnixFolder_IShellFolder2_Release,
904 UnixFolder_IShellFolder2_ParseDisplayName,
905 UnixFolder_IShellFolder2_EnumObjects,
906 UnixFolder_IShellFolder2_BindToObject,
907 UnixFolder_IShellFolder2_BindToStorage,
908 UnixFolder_IShellFolder2_CompareIDs,
909 UnixFolder_IShellFolder2_CreateViewObject,
910 UnixFolder_IShellFolder2_GetAttributesOf,
911 UnixFolder_IShellFolder2_GetUIObjectOf,
912 UnixFolder_IShellFolder2_GetDisplayNameOf,
913 UnixFolder_IShellFolder2_SetNameOf,
914 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
915 UnixFolder_IShellFolder2_EnumSearches,
916 UnixFolder_IShellFolder2_GetDefaultColumn,
917 UnixFolder_IShellFolder2_GetDefaultColumnState,
918 UnixFolder_IShellFolder2_GetDetailsEx,
919 UnixFolder_IShellFolder2_GetDetailsOf,
920 UnixFolder_IShellFolder2_MapColumnToSCID
923 static HRESULT WINAPI UnixFolder_IPersistFolder_QueryInterface(IPersistFolder* This, REFIID riid,
926 return UnixFolder_IShellFolder2_QueryInterface(
927 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder, This), riid, ppvObject);
930 static ULONG WINAPI UnixFolder_IPersistFolder_AddRef(IPersistFolder* This)
932 return UnixFolder_IShellFolder2_AddRef(
933 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder, This));
936 static ULONG WINAPI UnixFolder_IPersistFolder_Release(IPersistFolder* This)
938 return UnixFolder_IShellFolder2_Release(
939 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder, This));
942 static HRESULT WINAPI UnixFolder_IPersistFolder_GetClassID(IPersistFolder* This, CLSID* pClassID)
948 static HRESULT WINAPI UnixFolder_IPersistFolder_Initialize(IPersistFolder* iface, LPCITEMIDLIST pidl)
950 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder, iface);
952 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
954 This->m_pidlLocation = ILClone(pidl);
955 UNIXFS_pidl_to_path(pidl, &This->m_pszPath);
956 UNIXFS_build_subfolder_pidls(This->m_pszPath, &This->m_apidlSubDirs, &This->m_cSubDirs);
961 /* VTable for UnixFolder's IPersistFolder interface.
963 static const IPersistFolderVtbl UnixFolder_IPersistFolder_Vtbl = {
964 UnixFolder_IPersistFolder_QueryInterface,
965 UnixFolder_IPersistFolder_AddRef,
966 UnixFolder_IPersistFolder_Release,
967 UnixFolder_IPersistFolder_GetClassID,
968 UnixFolder_IPersistFolder_Initialize
971 /******************************************************************************
972 * UnixFolder_Constructor [Internal]
975 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
976 * riid [I] Interface asked for by the client.
977 * ppv [O] Pointer to an riid interface to the UnixFolder object.
980 * This is the only function exported from shfldr_unixfs.c. It's called from
981 * shellole.c's default class factory and thus has to exhibit a LPFNCREATEINSTANCE
982 * compatible signature.
984 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
986 UnixFolder *pUnixFolder;
988 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
990 pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
991 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
992 pUnixFolder->lpIPersistFolderVtbl = &UnixFolder_IPersistFolder_Vtbl;
993 pUnixFolder->m_cRef = 0;
994 pUnixFolder->m_pszPath = NULL;
995 pUnixFolder->m_apidlSubDirs = NULL;
996 pUnixFolder->m_cSubDirs = 0;
998 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
999 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1000 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1004 /******************************************************************************
1005 * UnixSubFolderIterator
1007 * Class whose heap based objects represent iterators over the sub-directories
1008 * of a given UnixFolder object.
1011 /* UnixSubFolderIterator object layout and typedef.
1013 typedef struct _UnixSubFolderIterator {
1014 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1016 UnixFolder *m_pUnixFolder;
1019 } UnixSubFolderIterator;
1021 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1022 TRACE("(iterator=%p)\n", iterator);
1024 UnixFolder_IShellFolder2_Release((IShellFolder2*)iterator->m_pUnixFolder);
1028 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1029 REFIID riid, void** ppv)
1031 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1033 if (!ppv) return E_INVALIDARG;
1035 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1039 return E_NOINTERFACE;
1042 IEnumIDList_AddRef(iface);
1046 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1048 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1050 TRACE("(iface=%p)\n", iface);
1052 return InterlockedIncrement(&This->m_cRef);
1055 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1057 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1060 TRACE("(iface=%p)\n", iface);
1062 cRef = InterlockedDecrement(&This->m_cRef);
1065 UnixSubFolderIterator_Destroy(This);
1070 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1071 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1073 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1076 TRACE("(iface=%p, celt=%ld, rgelt=%p, pceltFetched=%p)\n", iface, celt, rgelt, pceltFetched);
1078 for (i=0; (i < celt) && (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs); This->m_cIdx++) {
1079 LPITEMIDLIST pCurrent = This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx];
1080 if (UNIXFS_is_pidl_of_type(pCurrent, This->m_fFilter)) {
1081 rgelt[i] = ILClone(pCurrent);
1089 return i == celt ? S_OK : S_FALSE;
1092 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1094 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1097 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1099 for (i=0; i < celt; i++) {
1100 while (This->m_cIdx < This->m_pUnixFolder->m_cSubDirs &&
1101 !UNIXFS_is_pidl_of_type(This->m_pUnixFolder->m_apidlSubDirs[This->m_cIdx], This->m_fFilter))
1108 if (This->m_cIdx > This->m_pUnixFolder->m_cSubDirs) {
1109 This->m_cIdx = This->m_pUnixFolder->m_cSubDirs;
1116 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1118 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1120 TRACE("(iface=%p)\n", iface);
1127 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1128 IEnumIDList** ppenum)
1134 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1136 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1137 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1138 UnixSubFolderIterator_IEnumIDList_AddRef,
1139 UnixSubFolderIterator_IEnumIDList_Release,
1140 UnixSubFolderIterator_IEnumIDList_Next,
1141 UnixSubFolderIterator_IEnumIDList_Skip,
1142 UnixSubFolderIterator_IEnumIDList_Reset,
1143 UnixSubFolderIterator_IEnumIDList_Clone
1146 static IUnknown *UnixSubFolderIterator_Construct(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1147 UnixSubFolderIterator *iterator;
1149 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1151 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1152 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1153 iterator->m_cRef = 0;
1154 iterator->m_cIdx = 0;
1155 iterator->m_pUnixFolder = pUnixFolder;
1156 iterator->m_fFilter = fFilter;
1158 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1159 UnixFolder_IShellFolder2_AddRef((IShellFolder2*)pUnixFolder);
1161 return (IUnknown*)iterator;