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
22 * As you know, windows and unix do have a different philosophy with regard to
23 * the question of how a filesystem should be laid out. While we unix geeks
24 * learned to love the 'one-tree-rooted-at-/' approach, windows has in fact
25 * a whole forest of filesystem trees, each of which is typically identified by
28 * We would like wine to integrate as smoothly as possible (that is without
29 * sacrificing win32 compatibility) into the unix environment. For the
30 * filesystem question, this means we really would like those windows
31 * applications to work with unix path- and file-names. Unfortunately, this
32 * seems to be impossible in general. Therefore we have those symbolic links
33 * in wine's 'dosdevices' directory, which are used to simulate drives
34 * to keep windows applications happy. And as a consequence, we have those
35 * drive letters show up now and then in GUI applications running under wine,
36 * which gets the unix hardcore fans all angry, shouting at us @#!&$%* wine
37 * hackers that we are seducing the big companies not to port their applications
40 * DOS paths do appear at various places in GUI applications. Sometimes, they
41 * show up in the title bar of an application's window. They tend to accumulate
42 * in the most-recently-used section of the file-menu. And I've even seen some
43 * in a configuration dialog's edit control. In those examples, wine can't do a
44 * lot about this, since path-names can't be told appart from ordinary strings
45 * here. That's different in the file dialogs, though.
47 * With the introduction of the 'shell' in win32, Microsoft established an
48 * abstraction layer on top of the filesystem, called the shell namespace (I was
49 * told that Gnome's virtual filesystem is conceptually similar). In the shell
50 * namespace, one doesn't use ascii- or unicode-strings to uniquely identify
51 * objects. Instead Microsoft introduced item-identifier-lists (The c type is
52 * called ITEMIDLIST) as an abstraction of path-names. As you probably would
53 * have guessed, an item-identifier-list is a list of item-identifiers (whose
54 * c type's funny name is SHITEMID), which are opaque binary objects. This means
55 * that no application (apart from Microsoft Office) should make any assumptions
56 * on the internal structure of these SHITEMIDs.
58 * Since the user prefers to be presented the good-old DOS file-names instead of
59 * binary ITEMIDLISTs, a translation method between string-based file-names and
60 * ITEMIDLISTs was established. At the core of this are the COM-Interface
61 * IShellFolder and especially it's methods ParseDisplayName and
62 * GetDisplayNameOf. Basically, you give a DOS-path (let's say C:\windows) to
63 * ParseDisplayName and get a SHITEMID similar to <Desktop|My Computer|C:|windows|>.
64 * Since it's opaque, you can't see the 'C', the 'windows' and the other stuff.
65 * You can only figure out that the ITEMIDLIST is composed of four SHITEMIDS.
66 * The file dialog applies IShellFolder's BindToObject method to bind to each of
67 * those four objects (Desktop, My Computer, C: and windows. All of them have to
68 * implement the IShellFolder interface.) and asks them how they would like to be
69 * displayed (basically their icon and the string displayed). If the file dialog
70 * asks <Desktop|My Computer|C:|windows> which sub-objects it contains (via
71 * EnumObjects) it gets a list of opaque SHITEMIDs, which can be concatenated to
72 * <Desktop|...|windows> to build a new ITEMIDLIST and browse, for instance,
73 * into <system32>. This means the file dialog browses the shell namespace by
74 * identifying objects via ITEMIDLISTs. Once the user has selected a location to
75 * save his valuable file, the file dialog calls IShellFolder's GetDisplayNameOf
76 * method to translate the ITEMIDLIST back to a DOS filename.
78 * It seems that one intention of the shell namespace concept was to make it
79 * possible to have objects in the namespace, which don't have any counterpart
80 * in the filesystem. The 'My Computer' shell folder object is one instance
81 * which comes to mind (Go try to save a file into 'My Computer' on windows.)
82 * So, to make matters a little more complex, before the file dialog asks a
83 * shell namespace object for it's DOS path, it asks if it actually has one.
84 * This is done via the IShellFolder::GetAttributesOf method, which sets the
85 * SFGAO_FILESYSTEM if - and only if - it has.
87 * The two things, described in the previous two paragraphs, are what unixfs is
88 * based on. So basically, if UnixDosFolder's ParseDisplayName method is called
89 * with a 'c:\windows' path-name, it doesn't return an
90 * <Desktop|My Computer|C:|windows|> ITEMIDLIST. Instead, it uses
91 * shell32's wine_get_unix_path_name and the _posix_ (which means not the win32)
92 * fileio api's to figure out that c: is mapped to - let's say -
93 * /home/mjung/.wine/drive_c and then constructs a
94 * <Desktop|/|home|mjung|.wine|drive_c> ITEMIDLIST. Which is what the file
95 * dialog uses to display the folder and file objects, which is why you see a
96 * unix path. When the user has found a nice place for his file and hits the
97 * save button, the ITEMIDLIST of the selected folder object is passed to
98 * GetDisplayNameOf, which returns a _DOS_ path name
99 * (like H:\home_of_my_new_file out of <|Desktop|/|home|mjung|home_of_my_new_file|>).
100 * Unixfs basically mounts your dos devices together in order to construct
101 * a copy of your unix filesystem structure.
103 * But what if none of the symbolic links in 'dosdevices' points to '/', you
104 * might ask ("And I don't want wine have access to my complete hard drive, you
105 * *%&1#!"). No problem, as I stated above, unixfs uses the _posix_ apis to
106 * construct the ITEMIDLISTs. Folders, which aren't accessible via a drive letter,
107 * don't have the SFGAO_FILESYSTEM flag set. So the file dialogs should'nt allow
108 * the user to select such a folder for file storage (And if it does anyhow, it
109 * will not be able to return a valid path, since there is none). Think of those
110 * folders as a hierarchy of 'My Computer'-like folders, which happen to be a
111 * shadow of your unix filesystem tree. And since all of this stuff doesn't
112 * change anything at all in wine's fileio api's, windows applications will have
113 * no more access rights as they had before.
115 * To sum it all up, you can still savely run wine with you root account (Just
116 * kidding, don't do it.)
118 * If you are now standing in front of your computer, shouting hotly
119 * "I am not convinced, Mr. Rumsfeld^H^H^H^H^H^H^H^H^H^H^H^H", fire up regedit
120 * and delete HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\
121 * Explorer\Desktop\Namespace\{9D20AAE8-0625-44B0-9CA7-71889C2254D9} and you
122 * will be back in the pre-unixfs days.
126 #include "wine/port.h"
135 #ifdef HAVE_SYS_STAT_H
136 # include <sys/stat.h>
145 #define NONAMELESSUNION
146 #define NONAMELESSSTRUCT
154 #include "winternl.h"
155 #include "wine/debug.h"
157 #include "shell32_main.h"
158 #include "shellfolder.h"
160 #include "shresdef.h"
163 WINE_DEFAULT_DEBUG_CHANNEL(shell);
165 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
166 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
168 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
169 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
171 /* FileStruct reserves one byte for szNames, thus we don't have to
172 * alloc a byte for the terminating '\0' of 'name'. Two of the
173 * additional bytes are for SHITEMID's cb field. One is for IDLDATA's
174 * type field. One is for FileStruct's szNames field, to terminate
175 * the alternate DOS name, which we don't use here.
177 #define SHITEMID_LEN_FROM_NAME_LEN(n) \
178 (sizeof(USHORT)+sizeof(PIDLTYPE)+sizeof(FileStruct)+(n)+sizeof(char))
179 #define NAME_LEN_FROM_LPSHITEMID(s) \
180 (((LPSHITEMID)s)->cb-sizeof(USHORT)-sizeof(PIDLTYPE)-sizeof(FileStruct)-sizeof(char))
182 #define PATHMODE_UNIX 0
183 #define PATHMODE_DOS 1
185 /* UnixFolder object layout and typedef.
187 typedef struct _UnixFolder {
188 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
189 const IPersistFolder3Vtbl *lpIPersistFolder3Vtbl;
190 const IPersistPropertyBagVtbl *lpIPersistPropertyBagVtbl;
191 const ISFHelperVtbl *lpISFHelperVtbl;
193 CHAR *m_pszPath; /* Target path of the shell folder */
194 LPITEMIDLIST m_pidlLocation; /* Location in the shell namespace */
196 DWORD m_dwAttributes;
197 const CLSID *m_pCLSID;
200 /******************************************************************************
201 * UNIXFS_is_rooted_at_desktop [Internal]
203 * Checks if the unixfs namespace extension is rooted at desktop level.
206 * TRUE, if unixfs is rooted at desktop level
209 BOOL UNIXFS_is_rooted_at_desktop(void) {
211 WCHAR wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
212 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
213 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
214 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
215 'N','a','m','e','S','p','a','c','e','\\',0 };
217 if (StringFromGUID2(&CLSID_UnixDosFolder, wszRootedAtDesktop + 69, CHARS_IN_GUID) &&
218 RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
226 /******************************************************************************
227 * UNIXFS_is_pidl_of_type [INTERNAL]
229 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
232 * pIDL [I] The ITEMIDLIST to be checked.
233 * fFilter [I] Shell condition flags, which specify the filter.
236 * TRUE, if pIDL is accepted by fFilter
239 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
240 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
241 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
242 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
246 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
247 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
251 /******************************************************************************
252 * UNIXFS_is_dos_device [Internal]
254 * Determines if a unix directory corresponds to any dos device.
257 * statPath [I] The stat struct of the directory, as returned by stat(2).
260 * TRUE, if statPath corresponds to any dos drive letter
263 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
264 struct stat statDrive;
267 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
269 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
270 if (!(dwDriveMap & 0x1)) continue;
271 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
272 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
273 HeapFree(GetProcessHeap(), 0, pszDrivePath);
274 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
281 /******************************************************************************
282 * UNIXFS_get_unix_path [Internal]
284 * Convert an absolute dos path to an absolute canonicalized unix path.
285 * Evaluate "/.", "/.." and symbolic links.
288 * pszDosPath [I] An absolute dos path
289 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
293 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
295 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
297 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
298 struct stat fileStat;
300 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
302 if (!pszDosPath || pszDosPath[1] != ':')
305 pszUnixPath = wine_get_unix_file_name(pszDosPath);
306 if (!pszUnixPath) return FALSE;
307 strcpy(szPath, pszUnixPath);
308 HeapFree(GetProcessHeap(), 0, pszUnixPath);
310 /* pCanonicalTail always points to the end of the canonical path constructed
311 * thus far. pPathTail points to the still to be processed part of the input
312 * path. pElement points to the path element currently investigated.
314 *pszCanonicalPath = '\0';
315 pCanonicalTail = pszCanonicalPath;
322 pElement = pPathTail;
323 pPathTail = strchr(pPathTail+1, '/');
324 if (!pPathTail) /* Last path element may not be terminated by '/'. */
325 pPathTail = pElement + strlen(pElement);
326 /* Temporarily terminate the current path element. Will be restored later. */
330 /* Skip "/." path elements */
331 if (!strcmp("/.", pElement)) {
336 /* Remove last element in canonical path for "/.." elements, then skip. */
337 if (!strcmp("/..", pElement)) {
338 char *pTemp = strrchr(pszCanonicalPath, '/');
340 pCanonicalTail = pTemp;
341 *pCanonicalTail = '\0';
346 /* lstat returns zero on success. */
347 if (lstat(szPath, &fileStat))
350 if (S_ISLNK(fileStat.st_mode)) {
351 char szSymlink[FILENAME_MAX];
352 int cLinkLen, cTailLen;
354 /* Avoid infinite loop for recursive links. */
358 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
363 cTailLen = strlen(pPathTail);
365 if (szSymlink[0] == '/') {
366 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
367 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
370 /* Avoid double slashes. */
371 if (szSymlink[cLinkLen-1] == '/' && pPathTail[0] == '/') {
372 szSymlink[cLinkLen-1] = '\0';
376 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
377 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
378 *pszCanonicalPath = '\0';
379 pCanonicalTail = pszCanonicalPath;
382 /* Relative link. Expand into szPath and continue. */
383 char szTemp[FILENAME_MAX];
384 int cTailLen = strlen(pPathTail);
386 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
389 memcpy(szTemp, pPathTail, cTailLen + 1);
390 memcpy(pElement + 1, szSymlink, cLinkLen);
391 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
392 pPathTail = pElement;
395 /* Regular directory or file. Copy to canonical path */
396 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
399 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
400 pCanonicalTail += pPathTail - pElement;
403 } while (pPathTail[0] == '/');
405 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
410 /******************************************************************************
411 * UNIXFS_build_shitemid [Internal]
413 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
417 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
418 * pIDL [O] SHITEMID will be constructed here.
421 * Success: A pointer to the terminating '\0' character of path.
425 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
426 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
429 static char* UNIXFS_build_shitemid(char *pszUnixPath, void *pIDL) {
433 struct stat fileStat;
437 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
439 /* Compute the SHITEMID's length and wipe it. */
440 pszComponent = strrchr(pszUnixPath, '/') + 1;
441 cComponentLen = strlen(pszComponent);
442 memset(pIDL, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen));
443 ((LPSHITEMID)pIDL)->cb = SHITEMID_LEN_FROM_NAME_LEN(cComponentLen) ;
445 /* We are only interested in regular files and directories. */
446 if (stat(pszUnixPath, &fileStat)) return NULL;
447 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
449 /* Set shell32's standard SHITEMID data fields. */
450 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
451 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
452 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
453 RtlSecondsSince1970ToTime( fileStat.st_mtime, &time );
454 fileTime.dwLowDateTime = time.u.LowPart;
455 fileTime.dwHighDateTime = time.u.HighPart;
456 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
457 pIDLData->u.file.uFileAttribs = 0;
458 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
459 if (pszComponent[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
460 memcpy(pIDLData->u.file.szNames, pszComponent, cComponentLen);
462 return pszComponent + cComponentLen;
465 /******************************************************************************
466 * UNIXFS_path_to_pidl [Internal]
469 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
470 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
471 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
475 * Failure: FALSE, invalid params or out of memory
478 * pUnixFolder also carries the information if the path is expected to be unix or dos.
480 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
482 int cSubDirs, cPidlLen, cPathLen;
483 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
485 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
490 /* Build an absolute path and let pNextPathElement point to the interesting
491 * relative sub-path. We need the absolute path to call 'stat', but the pidl
492 * will only contain the relative part.
494 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
496 /* Absolute dos path. Convert to unix */
497 if (!UNIXFS_get_unix_path(path, szCompletePath))
499 pNextPathElement = szCompletePath;
501 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
503 /* Absolute unix path. Just convert to ANSI. */
504 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
505 pNextPathElement = szCompletePath;
509 /* Relative dos or unix path. Concat with this folder's path */
510 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
511 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
512 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath + cBasePathLen,
513 FILENAME_MAX - cBasePathLen, NULL, NULL);
514 pNextPathElement = szCompletePath + cBasePathLen - 1;
516 /* If in dos mode, replace '\' with '/' */
517 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
518 char *pBackslash = strchr(pNextPathElement, '\\');
521 pBackslash = strchr(pBackslash, '\\');
526 /* Special case for the root folder. */
527 if (!strcmp(szCompletePath, "/")) {
528 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(sizeof(USHORT));
529 if (!pidl) return FALSE;
530 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
534 /* Remove trailing slash, if present */
535 cPathLen = strlen(szCompletePath);
536 if (szCompletePath[cPathLen-1] == '/')
537 szCompletePath[cPathLen-1] = '\0';
539 if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
540 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
544 /* At this point, we have an absolute unix path in szCompletePath
545 * and the relative portion of it in pNextPathElement. Both starting with '/'
546 * and _not_ terminated by a '/'. */
547 TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
549 /* Count the number of sub-directories in the path */
551 pSlash = pNextPathElement;
554 pSlash = strchr(pSlash+1, '/');
557 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
558 * characters, which are not stored in the ITEMIDLIST. */
559 cPidlLen = strlen(pNextPathElement) - cSubDirs + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
560 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
561 if (!pidl) return FALSE;
563 /* Concatenate the SHITEMIDs of the sub-directories. */
564 while (*pNextPathElement) {
565 pSlash = strchr(pNextPathElement+1, '/');
566 if (pSlash) *pSlash = '\0';
567 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, pidl);
568 if (pSlash) *pSlash = '/';
570 if (!pNextPathElement) {
574 pidl = ILGetNext(pidl);
576 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
578 if ((char *)pidl-(char *)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
579 ERR("Computed length of pidl incorrect. Please report.\n");
584 /******************************************************************************
585 * UNIXFS_initialize_target_folder [Internal]
587 * Initialize the m_pszPath member of an UnixFolder, given an absolute unix
588 * base path and a relative ITEMIDLIST. Leave the m_pidlLocation member, which
589 * specifies the location in the shell namespace alone.
592 * This [IO] The UnixFolder, whose target path is to be initialized
593 * szBasePath [I] The absolute base path
594 * pidlSubFolder [I] Relative part of the path, given as an ITEMIDLIST
595 * dwAttributes [I] Attributes to add to the Folders m_dwAttributes member
596 * (Used to pass the SFGAO_FILESYSTEM flag down the path)
601 static HRESULT UNIXFS_initialize_target_folder(UnixFolder *This, const char *szBasePath,
602 LPCITEMIDLIST pidlSubFolder, DWORD dwAttributes)
604 LPCITEMIDLIST current = pidlSubFolder;
605 DWORD dwPathLen = strlen(szBasePath)+1;
606 struct stat statPrefix;
609 /* Determine the path's length bytes */
610 while (current && current->mkid.cb) {
611 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
612 current = ILGetNext(current);
615 /* Build the path and compute the attributes*/
616 This->m_dwAttributes =
617 dwAttributes|SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
618 This->m_pszPath = pNextDir = SHAlloc(dwPathLen);
619 if (!This->m_pszPath) {
620 WARN("SHAlloc failed!\n");
623 current = pidlSubFolder;
624 strcpy(pNextDir, szBasePath);
625 pNextDir += strlen(szBasePath);
626 if (This->m_dwPathMode == PATHMODE_UNIX || IsEqualCLSID(&CLSID_MyDocuments, This->m_pCLSID))
627 This->m_dwAttributes |= SFGAO_FILESYSTEM;
628 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
630 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
631 This->m_dwAttributes |= SFGAO_FILESYSTEM;
633 while (current && current->mkid.cb) {
634 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
635 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
636 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
638 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
639 This->m_dwAttributes |= SFGAO_FILESYSTEM;
642 current = ILGetNext(current);
649 /******************************************************************************
652 * Class whose heap based instances represent unix filesystem directories.
655 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
656 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
658 SHFree(pUnixFolder->m_pszPath);
659 ILFree(pUnixFolder->m_pidlLocation);
663 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
666 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
668 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
670 if (!ppv) return E_INVALIDARG;
672 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
673 IsEqualIID(&IID_IShellFolder2, riid))
675 *ppv = &This->lpIShellFolder2Vtbl;
676 } else if (IsEqualIID(&IID_IPersistFolder3, riid) || IsEqualIID(&IID_IPersistFolder2, riid) ||
677 IsEqualIID(&IID_IPersistFolder, riid) || IsEqualIID(&IID_IPersist, riid))
679 *ppv = &This->lpIPersistFolder3Vtbl;
680 } else if (IsEqualIID(&IID_IPersistPropertyBag, riid)) {
681 *ppv = &This->lpIPersistPropertyBagVtbl;
682 } else if (IsEqualIID(&IID_ISFHelper, riid)) {
683 *ppv = &This->lpISFHelperVtbl;
686 return E_NOINTERFACE;
689 IUnknown_AddRef((IUnknown*)*ppv);
693 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
694 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
696 TRACE("(iface=%p)\n", iface);
698 return InterlockedIncrement(&This->m_cRef);
701 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
702 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
705 TRACE("(iface=%p)\n", iface);
707 cRef = InterlockedDecrement(&This->m_cRef);
710 UnixFolder_Destroy(This);
715 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
716 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
717 ULONG* pdwAttributes)
719 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
722 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
723 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
724 pchEaten, ppidl, pdwAttributes);
726 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
727 if (result && pdwAttributes && *pdwAttributes)
729 IShellFolder *pParentSF;
730 LPCITEMIDLIST pidlLast;
733 hr = SHBindToParent(*ppidl, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
734 if (FAILED(hr)) return E_FAIL;
735 IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
736 IShellFolder_Release(pParentSF);
739 if (!result) TRACE("FAILED!\n");
740 return result ? S_OK : E_FAIL;
743 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter);
745 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
746 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
748 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
749 IUnknown *newIterator;
752 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
753 iface, hwndOwner, grfFlags, ppEnumIDList);
755 if (!This->m_pszPath) {
756 WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
760 newIterator = UnixSubFolderIterator_Constructor(This, grfFlags);
761 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
762 IUnknown_Release(newIterator);
767 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID);
769 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
770 LPBC pbcReserved, REFIID riid, void** ppvOut)
772 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
773 IPersistFolder3 *persistFolder;
775 const CLSID *clsidChild;
777 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
778 iface, pidl, pbcReserved, riid, ppvOut);
780 if (!pidl || !pidl->mkid.cb)
783 if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
784 /* Children of FolderShortcuts are ShellFSFolders on Windows.
785 * Unixfs' counterpart is UnixDosFolder. */
786 clsidChild = &CLSID_UnixDosFolder;
788 clsidChild = This->m_pCLSID;
791 hr = CreateUnixFolder(NULL, &IID_IPersistFolder3, (void**)&persistFolder, clsidChild);
792 if (!SUCCEEDED(hr)) return hr;
793 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
796 UnixFolder *subfolder = ADJUST_THIS(UnixFolder, IPersistFolder3, persistFolder);
797 subfolder->m_pidlLocation = ILCombine(This->m_pidlLocation, pidl);
798 hr = UNIXFS_initialize_target_folder(subfolder, This->m_pszPath, pidl,
799 This->m_dwAttributes & SFGAO_FILESYSTEM);
802 IPersistFolder3_Release(persistFolder);
807 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
808 LPBC pbcReserved, REFIID riid, void** ppvObj)
814 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
815 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
817 BOOL isEmpty1, isEmpty2;
819 LPITEMIDLIST firstpidl;
823 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
825 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
826 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
828 if (isEmpty1 && isEmpty2)
829 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
831 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
833 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
835 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
836 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
837 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
838 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
840 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
841 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
842 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
844 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
845 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
847 if (pidl1->mkid.cb < pidl2->mkid.cb)
848 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
849 else if (pidl1->mkid.cb > pidl2->mkid.cb)
850 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
852 firstpidl = ILCloneFirst(pidl1);
853 pidl1 = ILGetNext(pidl1);
854 pidl2 = ILGetNext(pidl2);
856 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
858 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
859 IShellFolder2_Release(psf);
866 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
867 REFIID riid, void** ppv)
869 HRESULT hr = E_INVALIDARG;
871 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
873 if (!ppv) return E_INVALIDARG;
876 if (IsEqualIID(&IID_IShellView, riid)) {
877 LPSHELLVIEW pShellView;
879 pShellView = IShellView_Constructor((IShellFolder*)iface);
881 hr = IShellView_QueryInterface(pShellView, riid, ppv);
882 IShellView_Release(pShellView);
889 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
890 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
892 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
895 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
897 if (!rgfInOut || (cidl && !apidl))
901 *rgfInOut &= This->m_dwAttributes;
903 char szAbsolutePath[FILENAME_MAX], *pszRelativePath;
906 *rgfInOut = SFGAO_CANCOPY|SFGAO_CANMOVE|SFGAO_CANLINK|SFGAO_CANRENAME|SFGAO_CANDELETE|
907 SFGAO_HASPROPSHEET|SFGAO_DROPTARGET|SFGAO_FILESYSTEM;
908 lstrcpyA(szAbsolutePath, This->m_pszPath);
909 pszRelativePath = szAbsolutePath + lstrlenA(szAbsolutePath);
910 for (i=0; i<cidl; i++) {
911 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
912 struct stat fileStat;
913 char *pszName = _ILGetTextPointer(apidl[i]);
914 if (!pszName) return E_INVALIDARG;
915 lstrcpyA(pszRelativePath, pszName);
916 if (stat(szAbsolutePath, &fileStat) || !UNIXFS_is_dos_device(&fileStat))
917 *rgfInOut &= ~SFGAO_FILESYSTEM;
919 if (_ILIsFolder(apidl[i]))
920 *rgfInOut |= SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
927 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
928 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
930 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
932 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
933 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
935 if (IsEqualIID(&IID_IContextMenu, riid)) {
936 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
938 } else if (IsEqualIID(&IID_IDataObject, riid)) {
939 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
941 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
943 if (cidl != 1) return E_FAIL;
944 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
945 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
948 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
950 if (cidl != 1) return E_FAIL;
951 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
952 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
955 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
956 FIXME("IDropTarget\n");
958 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
959 FIXME("IShellLinkW\n");
961 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
962 FIXME("IShellLinkA\n");
965 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
966 return E_NOINTERFACE;
970 /******************************************************************************
971 * Translate file name from unix to ANSI encoding.
973 static void strcpyn_U2A(char *win_fn, UINT win_fn_len, const char *unix_fn)
978 len = MultiByteToWideChar(CP_UNIXCP, 0, unix_fn, -1, NULL, 0);
979 unicode_fn = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
980 MultiByteToWideChar(CP_UNIXCP, 0, unix_fn, -1, unicode_fn, len);
982 WideCharToMultiByte(CP_ACP, 0, unicode_fn, len, win_fn, win_fn_len, NULL, NULL);
983 HeapFree(GetProcessHeap(), 0, unicode_fn);
986 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
987 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
989 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
992 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
994 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
995 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
997 if (!pidl || !pidl->mkid.cb) {
998 lpName->uType = STRRET_CSTR;
999 if (This->m_dwPathMode == PATHMODE_UNIX) {
1000 strcpyn_U2A(lpName->u.cStr, MAX_PATH, This->m_pszPath);
1002 WCHAR *pwszDosPath = wine_get_dos_file_name(This->m_pszPath);
1004 return HRESULT_FROM_WIN32(GetLastError());
1005 PathRemoveBackslashW(pwszDosPath);
1006 WideCharToMultiByte(CP_UNIXCP, 0, pwszDosPath, -1, lpName->u.cStr, MAX_PATH, NULL, NULL);
1007 HeapFree(GetProcessHeap(), 0, pwszDosPath);
1010 IShellFolder *pSubFolder;
1011 SHITEMID emptyIDL = { 0, { 0 } };
1013 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
1014 if (!SUCCEEDED(hr)) return hr;
1016 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
1017 IShellFolder_Release(pSubFolder);
1020 char *pszFileName = _ILGetTextPointer(pidl);
1021 lpName->uType = STRRET_CSTR;
1022 strcpyn_U2A(lpName->u.cStr, MAX_PATH, pszFileName ? pszFileName : "");
1025 /* If in dos mode, do some post-processing on the path.
1026 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
1028 if (SUCCEEDED(hr) && This->m_dwPathMode == PATHMODE_DOS && !_ILIsFolder(pidl))
1029 SHELL_FS_ProcessDisplayFilename(lpName->u.cStr, uFlags);
1031 TRACE("--> %s\n", lpName->u.cStr);
1036 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd,
1037 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
1039 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1041 char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
1043 int cBasePathLen = lstrlenA(This->m_pszPath);
1044 struct stat statDest;
1045 LPITEMIDLIST pidlSrc, pidlDest;
1047 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
1048 iface, hwnd, pidl, debugstr_w(lpszName), uFlags, ppidlOut);
1050 /* pidl has to contain a single non-empty SHITEMID */
1051 if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
1052 return E_INVALIDARG;
1057 /* build source path */
1058 memcpy(szSrc, This->m_pszPath, cBasePathLen);
1059 lstrcpyA(szSrc+cBasePathLen, _ILGetTextPointer(pidl));
1061 /* build destination path */
1062 if (uFlags & SHGDN_FORPARSING) { /* absolute path in lpszName */
1063 WideCharToMultiByte(CP_UNIXCP, 0, lpszName, -1, szDest, FILENAME_MAX, NULL, NULL);
1065 WCHAR wszSrcRelative[MAX_PATH];
1066 memcpy(szDest, This->m_pszPath, cBasePathLen);
1067 WideCharToMultiByte(CP_UNIXCP, 0, lpszName, -1, szDest+cBasePathLen,
1068 FILENAME_MAX-cBasePathLen, NULL, NULL);
1070 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
1071 * extension is hidden to the user, we have to append it. */
1072 if (_ILSimpleGetTextW(pidl, wszSrcRelative, MAX_PATH) &&
1073 SHELL_FS_HideExtension(wszSrcRelative))
1075 char *pszExt = PathFindExtensionA(_ILGetTextPointer(pidl));
1076 lstrcatA(szDest, pszExt);
1080 TRACE("src=%s dest=%s\n", szSrc, szDest);
1082 /* Fail, if destination does already exist */
1083 if (!stat(szDest, &statDest))
1086 /* Rename the file */
1087 if (rename(szSrc, szDest))
1090 /* Build a pidl for the path of the renamed file */
1091 pwszDosDest = wine_get_dos_file_name(szDest);
1092 if (!pwszDosDest || !UNIXFS_path_to_pidl(This, pwszDosDest, &pidlDest)) {
1093 HeapFree(GetProcessHeap(), 0, pwszDosDest);
1094 rename(szDest, szSrc); /* Undo the renaming */
1098 /* Inform the shell */
1099 pidlSrc = ILCombine(This->m_pidlLocation, pidl);
1100 if (_ILIsFolder(ILFindLastID(pidlDest)))
1101 SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
1103 SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
1108 _ILCreateFromPathW(pwszDosDest, ppidlOut);
1110 HeapFree(GetProcessHeap(), 0, pwszDosDest);
1114 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
1115 IEnumExtraSearch **ppEnum)
1121 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
1122 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
1128 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
1129 UINT iColumn, SHCOLSTATEF *pcsFlags)
1135 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1142 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1143 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1149 #define SHELLVIEWCOLUMNS 7
1151 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1152 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1154 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1155 HRESULT hr = E_FAIL;
1156 struct passwd *pPasswd;
1157 struct group *pGroup;
1158 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1159 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1160 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1161 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1162 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
1163 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 9},
1164 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1165 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7}
1168 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1170 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1171 return E_INVALIDARG;
1174 psd->fmt = SFHeader[iColumn].fmt;
1175 psd->cxChar = SFHeader[iColumn].cxChar;
1176 psd->str.uType = STRRET_CSTR;
1177 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1180 struct stat statItem;
1181 if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
1182 char szPath[FILENAME_MAX], *pszFile = _ILGetTextPointer(pidl);
1184 return E_INVALIDARG;
1185 lstrcpyA(szPath, This->m_pszPath);
1186 lstrcatA(szPath, pszFile);
1187 if (stat(szPath, &statItem))
1188 return E_INVALIDARG;
1190 psd->str.u.cStr[0] = '\0';
1191 psd->str.uType = STRRET_CSTR;
1194 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1197 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1200 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1203 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1206 psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
1207 psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
1208 psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
1209 psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
1210 psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
1211 psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
1212 psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
1213 psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
1214 psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
1215 psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
1216 psd->str.u.cStr[10] = '\0';
1219 pPasswd = getpwuid(statItem.st_uid);
1220 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1223 pGroup = getgrgid(statItem.st_gid);
1224 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1232 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1239 /* VTable for UnixFolder's IShellFolder2 interface.
1241 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1242 UnixFolder_IShellFolder2_QueryInterface,
1243 UnixFolder_IShellFolder2_AddRef,
1244 UnixFolder_IShellFolder2_Release,
1245 UnixFolder_IShellFolder2_ParseDisplayName,
1246 UnixFolder_IShellFolder2_EnumObjects,
1247 UnixFolder_IShellFolder2_BindToObject,
1248 UnixFolder_IShellFolder2_BindToStorage,
1249 UnixFolder_IShellFolder2_CompareIDs,
1250 UnixFolder_IShellFolder2_CreateViewObject,
1251 UnixFolder_IShellFolder2_GetAttributesOf,
1252 UnixFolder_IShellFolder2_GetUIObjectOf,
1253 UnixFolder_IShellFolder2_GetDisplayNameOf,
1254 UnixFolder_IShellFolder2_SetNameOf,
1255 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1256 UnixFolder_IShellFolder2_EnumSearches,
1257 UnixFolder_IShellFolder2_GetDefaultColumn,
1258 UnixFolder_IShellFolder2_GetDefaultColumnState,
1259 UnixFolder_IShellFolder2_GetDetailsEx,
1260 UnixFolder_IShellFolder2_GetDetailsOf,
1261 UnixFolder_IShellFolder2_MapColumnToSCID
1264 static HRESULT WINAPI UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3* This, REFIID riid,
1267 return UnixFolder_IShellFolder2_QueryInterface(
1268 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder3, This), riid, ppvObject);
1271 static ULONG WINAPI UnixFolder_IPersistFolder3_AddRef(IPersistFolder3* This)
1273 return UnixFolder_IShellFolder2_AddRef(
1274 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder3, This));
1277 static ULONG WINAPI UnixFolder_IPersistFolder3_Release(IPersistFolder3* This)
1279 return UnixFolder_IShellFolder2_Release(
1280 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistFolder3, This));
1283 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3* iface, CLSID* pClassID)
1285 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1287 TRACE("(iface=%p, pClassId=%p)\n", iface, pClassID);
1290 return E_INVALIDARG;
1292 memcpy(pClassID, This->m_pCLSID, sizeof(CLSID));
1296 static HRESULT WINAPI UnixFolder_IPersistFolder3_Initialize(IPersistFolder3* iface, LPCITEMIDLIST pidl)
1298 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1299 LPCITEMIDLIST current = pidl;
1300 char szBasePath[FILENAME_MAX] = "/";
1302 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1304 /* Find the UnixFolderClass root */
1305 while (current->mkid.cb) {
1306 if (_ILIsSpecialFolder(current) && IsEqualIID(This->m_pCLSID, _ILGetGUIDPointer(current)))
1308 current = ILGetNext(current);
1311 if (current && current->mkid.cb) {
1312 if (IsEqualIID(&CLSID_MyDocuments, _ILGetGUIDPointer(current))) {
1313 WCHAR wszMyDocumentsPath[MAX_PATH];
1314 if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath, CSIDL_PERSONAL, FALSE))
1316 PathAddBackslashW(wszMyDocumentsPath);
1317 if (!UNIXFS_get_unix_path(wszMyDocumentsPath, szBasePath))
1320 current = ILGetNext(current);
1321 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
1322 /* Path rooted at Desktop */
1323 WCHAR wszDesktopPath[MAX_PATH];
1324 if (!SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE))
1326 PathAddBackslashW(wszDesktopPath);
1327 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
1330 } else if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
1331 /* FolderShortcuts' Initialize method only sets the ITEMIDLIST, which
1332 * specifies the location in the shell namespace, but leaves the
1333 * target folder (m_pszPath) alone. See unit tests in tests/shlfolder.c */
1334 This->m_pidlLocation = ILClone(pidl);
1337 ERR("Unknown pidl type!\n");
1339 return E_INVALIDARG;
1342 This->m_pidlLocation = ILClone(pidl);
1343 return UNIXFS_initialize_target_folder(This, szBasePath, current, 0);
1346 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3* iface, LPITEMIDLIST* ppidl)
1348 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1350 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1354 *ppidl = ILClone (This->m_pidlLocation);
1358 static HRESULT WINAPI UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3 *iface, IBindCtx *pbc,
1359 LPCITEMIDLIST pidlRoot, const PERSIST_FOLDER_TARGET_INFO *ppfti)
1361 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1362 WCHAR wszTargetDosPath[MAX_PATH];
1363 char szTargetPath[FILENAME_MAX] = "";
1365 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface, pbc, pidlRoot, ppfti);
1367 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1369 return IPersistFolder3_Initialize(iface, pidlRoot);
1371 if (ppfti->csidl != -1) {
1372 if (FAILED(SHGetFolderPathW(0, ppfti->csidl, NULL, 0, wszTargetDosPath)) ||
1373 !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1377 } else if (*ppfti->szTargetParsingName) {
1378 lstrcpyW(wszTargetDosPath, ppfti->szTargetParsingName);
1379 PathAddBackslashW(wszTargetDosPath);
1380 if (!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath)) {
1383 } else if (ppfti->pidlTargetFolder) {
1384 if (!SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTargetDosPath) ||
1385 !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1393 This->m_pszPath = SHAlloc(lstrlenA(szTargetPath)+1);
1394 if (!This->m_pszPath)
1396 lstrcpyA(This->m_pszPath, szTargetPath);
1397 This->m_pidlLocation = ILClone(pidlRoot);
1398 This->m_dwAttributes = (ppfti->dwAttributes != -1) ? ppfti->dwAttributes :
1399 (SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|SFGAO_FILESYSTEM);
1404 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3 *iface,
1405 PERSIST_FOLDER_TARGET_INFO *ppfti)
1407 FIXME("(iface=%p, ppfti=%p) stub\n", iface, ppfti);
1411 /* VTable for UnixFolder's IPersistFolder interface.
1413 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl = {
1414 UnixFolder_IPersistFolder3_QueryInterface,
1415 UnixFolder_IPersistFolder3_AddRef,
1416 UnixFolder_IPersistFolder3_Release,
1417 UnixFolder_IPersistFolder3_GetClassID,
1418 UnixFolder_IPersistFolder3_Initialize,
1419 UnixFolder_IPersistFolder3_GetCurFolder,
1420 UnixFolder_IPersistFolder3_InitializeEx,
1421 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1424 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag* This,
1425 REFIID riid, void** ppvObject)
1427 return UnixFolder_IShellFolder2_QueryInterface(
1428 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistPropertyBag, This), riid, ppvObject);
1431 static ULONG WINAPI UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag* This)
1433 return UnixFolder_IShellFolder2_AddRef(
1434 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistPropertyBag, This));
1437 static ULONG WINAPI UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag* This)
1439 return UnixFolder_IShellFolder2_Release(
1440 (IShellFolder2*)ADJUST_THIS(UnixFolder, IPersistPropertyBag, This));
1443 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag* iface,
1446 return UnixFolder_IPersistFolder3_GetClassID(
1447 (IPersistFolder3*)&ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)->lpIPersistFolder3Vtbl,
1451 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag* iface)
1457 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag *iface,
1458 IPropertyBag *pPropertyBag, IErrorLog *pErrorLog)
1460 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface);
1461 static const WCHAR wszTarget[] = { 'T','a','r','g','e','t', 0 }, wszNull[] = { 0 };
1462 PERSIST_FOLDER_TARGET_INFO pftiTarget;
1466 TRACE("(iface=%p, pPropertyBag=%p, pErrorLog=%p)\n", iface, pPropertyBag, pErrorLog);
1471 /* Get 'Target' property from the property bag. */
1472 V_VT(&var) = VT_BSTR;
1473 hr = IPropertyBag_Read(pPropertyBag, wszTarget, &var, NULL);
1476 lstrcpyW(pftiTarget.szTargetParsingName, V_BSTR(&var));
1477 SysFreeString(V_BSTR(&var));
1479 pftiTarget.pidlTargetFolder = NULL;
1480 lstrcpyW(pftiTarget.szNetworkProvider, wszNull);
1481 pftiTarget.dwAttributes = -1;
1482 pftiTarget.csidl = -1;
1484 return UnixFolder_IPersistFolder3_InitializeEx(
1485 STATIC_CAST(IPersistFolder3, This), NULL, NULL, &pftiTarget);
1488 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag *iface,
1489 IPropertyBag *pPropertyBag, BOOL fClearDirty, BOOL fSaveAllProperties)
1495 /* VTable for UnixFolder's IPersistPropertyBag interface.
1497 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl = {
1498 UnixFolder_IPersistPropertyBag_QueryInterface,
1499 UnixFolder_IPersistPropertyBag_AddRef,
1500 UnixFolder_IPersistPropertyBag_Release,
1501 UnixFolder_IPersistPropertyBag_GetClassID,
1502 UnixFolder_IPersistPropertyBag_InitNew,
1503 UnixFolder_IPersistPropertyBag_Load,
1504 UnixFolder_IPersistPropertyBag_Save
1507 static HRESULT WINAPI UnixFolder_ISFHelper_QueryInterface(ISFHelper* iface, REFIID riid,
1510 return UnixFolder_IShellFolder2_QueryInterface(
1511 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface), riid, ppvObject);
1514 static ULONG WINAPI UnixFolder_ISFHelper_AddRef(ISFHelper* iface)
1516 return UnixFolder_IShellFolder2_AddRef(
1517 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface));
1520 static ULONG WINAPI UnixFolder_ISFHelper_Release(ISFHelper* iface)
1522 return UnixFolder_IShellFolder2_Release(
1523 (IShellFolder2*)ADJUST_THIS(UnixFolder, ISFHelper, iface));
1526 static HRESULT WINAPI UnixFolder_ISFHelper_GetUniqueName(ISFHelper* iface, LPSTR lpName, UINT uLen)
1528 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1531 LPITEMIDLIST pidlElem;
1534 static const char szNewFolder[] = "New Folder";
1536 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface, lpName, uLen);
1538 if (uLen < sizeof(szNewFolder)+3)
1539 return E_INVALIDARG;
1541 hr = IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2, This), 0,
1542 SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
1543 if (SUCCEEDED(hr)) {
1544 lstrcpyA(lpName, szNewFolder);
1545 IEnumIDList_Reset(pEnum);
1547 while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
1548 if (!strcasecmp(_ILGetTextPointer(pidlElem), lpName)) {
1549 IEnumIDList_Reset(pEnum);
1550 sprintf(lpName, "%s %d", szNewFolder, i++);
1557 IEnumIDList_Release(pEnum);
1562 static HRESULT WINAPI UnixFolder_ISFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCSTR pszName,
1563 LPITEMIDLIST* ppidlOut)
1565 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1566 char szNewDir[FILENAME_MAX];
1568 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface, hwnd, pszName, ppidlOut);
1573 lstrcpyA(szNewDir, This->m_pszPath);
1574 lstrcatA(szNewDir, pszName);
1576 if (mkdir(szNewDir, 0755)) {
1577 char szMessage[256 + FILENAME_MAX];
1578 char szCaption[256];
1580 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
1581 sprintf(szMessage, szCaption, szNewDir);
1582 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
1583 MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
1587 LPITEMIDLIST pidlRelative;
1588 WCHAR wszName[MAX_PATH];
1590 /* Inform the shell */
1591 MultiByteToWideChar(CP_UNIXCP, 0, pszName, -1, wszName, MAX_PATH);
1592 if (UNIXFS_path_to_pidl(This, wszName, &pidlRelative)) {
1593 LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
1595 *ppidlOut = pidlRelative;
1597 ILFree(pidlRelative);
1598 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1599 ILFree(pidlAbsolute);
1605 static HRESULT WINAPI UnixFolder_ISFHelper_DeleteItems(ISFHelper* iface, UINT cidl,
1606 LPCITEMIDLIST* apidl)
1608 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1609 char szAbsolute[FILENAME_MAX], *pszRelative;
1610 LPITEMIDLIST pidlAbsolute;
1614 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface, cidl, apidl);
1616 lstrcpyA(szAbsolute, This->m_pszPath);
1617 pszRelative = szAbsolute + lstrlenA(szAbsolute);
1619 for (i=0; i<cidl && SUCCEEDED(hr); i++) {
1620 lstrcpyA(pszRelative, _ILGetTextPointer(apidl[i]));
1621 pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
1622 if (_ILIsFolder(apidl[i])) {
1623 if (rmdir(szAbsolute)) {
1626 SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1628 } else if (_ILIsValue(apidl[i])) {
1629 if (unlink(szAbsolute)) {
1632 SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
1635 ILFree(pidlAbsolute);
1641 static HRESULT WINAPI UnixFolder_ISFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom,
1642 UINT cidl, LPCITEMIDLIST *apidl)
1644 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1648 char szAbsoluteDst[FILENAME_MAX], *pszRelativeDst;
1650 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface, psfFrom, cidl, apidl);
1652 if (!psfFrom || !cidl || !apidl)
1653 return E_INVALIDARG;
1655 /* All source items have to be filesystem items. */
1656 dwAttributes = SFGAO_FILESYSTEM;
1657 hr = IShellFolder_GetAttributesOf(psfFrom, cidl, apidl, &dwAttributes);
1658 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM))
1659 return E_INVALIDARG;
1661 lstrcpyA(szAbsoluteDst, This->m_pszPath);
1662 pszRelativeDst = szAbsoluteDst + strlen(szAbsoluteDst);
1664 for (i=0; i<cidl; i++) {
1665 WCHAR wszSrc[MAX_PATH];
1666 char szSrc[FILENAME_MAX];
1669 /* Build the unix path of the current source item. */
1670 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom, apidl[i], SHGDN_FORPARSING, &strret)))
1672 if (FAILED(StrRetToBufW(&strret, apidl[i], wszSrc, MAX_PATH)))
1674 if (!UNIXFS_get_unix_path(wszSrc, szSrc))
1677 /* Build the unix path of the current destination item */
1678 lstrcpyA(pszRelativeDst, _ILGetTextPointer(apidl[i]));
1680 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc, szAbsoluteDst);
1685 /* VTable for UnixFolder's ISFHelper interface
1687 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl = {
1688 UnixFolder_ISFHelper_QueryInterface,
1689 UnixFolder_ISFHelper_AddRef,
1690 UnixFolder_ISFHelper_Release,
1691 UnixFolder_ISFHelper_GetUniqueName,
1692 UnixFolder_ISFHelper_AddFolder,
1693 UnixFolder_ISFHelper_DeleteItems,
1694 UnixFolder_ISFHelper_CopyItems
1697 /******************************************************************************
1698 * Unix[Dos]Folder_Constructor [Internal]
1701 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1702 * riid [I] Interface asked for by the client.
1703 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1706 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1707 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1708 * compatible signature.
1710 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1711 * means that paths are converted from dos to unix and back at the interfaces.
1713 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID)
1715 HRESULT hr = E_FAIL;
1716 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1719 FIXME("Aggregation not yet implemented!\n");
1720 return CLASS_E_NOAGGREGATION;
1724 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1725 pUnixFolder->lpIPersistFolder3Vtbl = &UnixFolder_IPersistFolder3_Vtbl;
1726 pUnixFolder->lpIPersistPropertyBagVtbl = &UnixFolder_IPersistPropertyBag_Vtbl;
1727 pUnixFolder->lpISFHelperVtbl = &UnixFolder_ISFHelper_Vtbl;
1728 pUnixFolder->m_cRef = 0;
1729 pUnixFolder->m_pszPath = NULL;
1730 pUnixFolder->m_pidlLocation = NULL;
1731 pUnixFolder->m_dwPathMode = IsEqualCLSID(&CLSID_UnixFolder, pCLSID) ? PATHMODE_UNIX : PATHMODE_DOS;
1732 pUnixFolder->m_dwAttributes = 0;
1733 pUnixFolder->m_pCLSID = pCLSID;
1735 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1736 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1737 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1742 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1743 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1744 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixFolder);
1747 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1748 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1749 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixDosFolder);
1752 HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1753 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1754 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_FolderShortcut);
1757 HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1758 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1759 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_MyDocuments);
1762 /******************************************************************************
1763 * UnixSubFolderIterator
1765 * Class whose heap based objects represent iterators over the sub-directories
1766 * of a given UnixFolder object.
1769 /* UnixSubFolderIterator object layout and typedef.
1771 typedef struct _UnixSubFolderIterator {
1772 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1776 char m_szFolder[FILENAME_MAX];
1777 } UnixSubFolderIterator;
1779 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1780 TRACE("(iterator=%p)\n", iterator);
1782 if (iterator->m_dirFolder)
1783 closedir(iterator->m_dirFolder);
1787 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1788 REFIID riid, void** ppv)
1790 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1792 if (!ppv) return E_INVALIDARG;
1794 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1798 return E_NOINTERFACE;
1801 IEnumIDList_AddRef(iface);
1805 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1807 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1809 TRACE("(iface=%p)\n", iface);
1811 return InterlockedIncrement(&This->m_cRef);
1814 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
1816 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1819 TRACE("(iface=%p)\n", iface);
1821 cRef = InterlockedDecrement(&This->m_cRef);
1824 UnixSubFolderIterator_Destroy(This);
1829 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
1830 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
1832 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1835 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
1836 if (This->m_dirFolder) {
1837 char *pszRelativePath = This->m_szFolder + lstrlenA(This->m_szFolder);
1838 struct dirent *pDirEntry;
1841 pDirEntry = readdir(This->m_dirFolder);
1842 if (!pDirEntry) break; /* No more entries */
1843 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
1845 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
1846 * and see if it passes the filter.
1848 lstrcpyA(pszRelativePath, pDirEntry->d_name);
1849 rgelt[i] = (LPITEMIDLIST)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath))+sizeof(USHORT));
1850 if (!UNIXFS_build_shitemid(This->m_szFolder, rgelt[i]) ||
1851 !UNIXFS_is_pidl_of_type(rgelt[i], This->m_fFilter))
1856 memset(((PBYTE)rgelt[i])+rgelt[i]->mkid.cb, 0, sizeof(USHORT));
1859 *pszRelativePath = '\0'; /* Restore the original path in This->m_szFolder. */
1865 return (i == 0) ? S_FALSE : S_OK;
1868 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
1870 LPITEMIDLIST *apidl;
1874 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
1876 /* Call IEnumIDList::Next and delete the resulting pidls. */
1877 apidl = (LPITEMIDLIST*)SHAlloc(celt * sizeof(LPITEMIDLIST));
1878 hr = IEnumIDList_Next(iface, celt, apidl, &cFetched);
1881 SHFree(apidl[cFetched]);
1887 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
1889 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1891 TRACE("(iface=%p)\n", iface);
1893 if (This->m_dirFolder)
1894 rewinddir(This->m_dirFolder);
1899 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
1900 IEnumIDList** ppenum)
1906 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
1908 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
1909 UnixSubFolderIterator_IEnumIDList_QueryInterface,
1910 UnixSubFolderIterator_IEnumIDList_AddRef,
1911 UnixSubFolderIterator_IEnumIDList_Release,
1912 UnixSubFolderIterator_IEnumIDList_Next,
1913 UnixSubFolderIterator_IEnumIDList_Skip,
1914 UnixSubFolderIterator_IEnumIDList_Reset,
1915 UnixSubFolderIterator_IEnumIDList_Clone
1918 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter) {
1919 UnixSubFolderIterator *iterator;
1921 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
1923 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
1924 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
1925 iterator->m_cRef = 0;
1926 iterator->m_fFilter = fFilter;
1927 iterator->m_dirFolder = opendir(pUnixFolder->m_pszPath);
1928 lstrcpyA(iterator->m_szFolder, pUnixFolder->m_pszPath);
1930 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
1932 return (IUnknown*)iterator;