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 IDropTargetVtbl *lpIDropTargetVtbl;
192 const ISFHelperVtbl *lpISFHelperVtbl;
194 CHAR *m_pszPath; /* Target path of the shell folder */
195 LPITEMIDLIST m_pidlLocation; /* Location in the shell namespace */
197 DWORD m_dwAttributes;
198 const CLSID *m_pCLSID;
199 DWORD m_dwDropEffectsMask;
202 /* Will hold the registered clipboard format identifier for ITEMIDLISTS. */
203 static UINT cfShellIDList = 0;
205 /******************************************************************************
206 * UNIXFS_is_rooted_at_desktop [Internal]
208 * Checks if the unixfs namespace extension is rooted at desktop level.
211 * TRUE, if unixfs is rooted at desktop level
214 BOOL UNIXFS_is_rooted_at_desktop(void) {
216 WCHAR wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
217 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
218 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
219 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
220 'N','a','m','e','S','p','a','c','e','\\',0 };
222 if (StringFromGUID2(&CLSID_UnixDosFolder, wszRootedAtDesktop + 69, CHARS_IN_GUID) &&
223 RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
231 /******************************************************************************
232 * UNIXFS_is_pidl_of_type [INTERNAL]
234 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
237 * pIDL [I] The ITEMIDLIST to be checked.
238 * fFilter [I] Shell condition flags, which specify the filter.
241 * TRUE, if pIDL is accepted by fFilter
244 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
245 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
246 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
247 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
251 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
252 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
256 /******************************************************************************
257 * UNIXFS_is_dos_device [Internal]
259 * Determines if a unix directory corresponds to any dos device.
262 * statPath [I] The stat struct of the directory, as returned by stat(2).
265 * TRUE, if statPath corresponds to any dos drive letter
268 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
269 struct stat statDrive;
272 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
274 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
275 if (!(dwDriveMap & 0x1)) continue;
276 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
277 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
278 HeapFree(GetProcessHeap(), 0, pszDrivePath);
279 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
286 /******************************************************************************
287 * UNIXFS_get_unix_path [Internal]
289 * Convert an absolute dos path to an absolute canonicalized unix path.
290 * Evaluate "/.", "/.." and symbolic links.
293 * pszDosPath [I] An absolute dos path
294 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
298 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
300 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
302 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
303 struct stat fileStat;
305 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
307 if (!pszDosPath || pszDosPath[1] != ':')
310 pszUnixPath = wine_get_unix_file_name(pszDosPath);
311 if (!pszUnixPath) return FALSE;
312 strcpy(szPath, pszUnixPath);
313 HeapFree(GetProcessHeap(), 0, pszUnixPath);
315 /* pCanonicalTail always points to the end of the canonical path constructed
316 * thus far. pPathTail points to the still to be processed part of the input
317 * path. pElement points to the path element currently investigated.
319 *pszCanonicalPath = '\0';
320 pCanonicalTail = pszCanonicalPath;
327 pElement = pPathTail;
328 pPathTail = strchr(pPathTail+1, '/');
329 if (!pPathTail) /* Last path element may not be terminated by '/'. */
330 pPathTail = pElement + strlen(pElement);
331 /* Temporarily terminate the current path element. Will be restored later. */
335 /* Skip "/." path elements */
336 if (!strcmp("/.", pElement)) {
341 /* Remove last element in canonical path for "/.." elements, then skip. */
342 if (!strcmp("/..", pElement)) {
343 char *pTemp = strrchr(pszCanonicalPath, '/');
345 pCanonicalTail = pTemp;
346 *pCanonicalTail = '\0';
351 /* lstat returns zero on success. */
352 if (lstat(szPath, &fileStat))
355 if (S_ISLNK(fileStat.st_mode)) {
356 char szSymlink[FILENAME_MAX];
357 int cLinkLen, cTailLen;
359 /* Avoid infinite loop for recursive links. */
363 cLinkLen = readlink(szPath, szSymlink, FILENAME_MAX);
368 cTailLen = strlen(pPathTail);
370 if (szSymlink[0] == '/') {
371 /* Absolute link. Copy to szPath, concat remaining path and start all over. */
372 if (cLinkLen + cTailLen + 1 > FILENAME_MAX)
375 /* Avoid double slashes. */
376 if (szSymlink[cLinkLen-1] == '/' && pPathTail[0] == '/') {
377 szSymlink[cLinkLen-1] = '\0';
381 memcpy(szSymlink + cLinkLen, pPathTail, cTailLen + 1);
382 memcpy(szPath, szSymlink, cLinkLen + cTailLen + 1);
383 *pszCanonicalPath = '\0';
384 pCanonicalTail = pszCanonicalPath;
387 /* Relative link. Expand into szPath and continue. */
388 char szTemp[FILENAME_MAX];
389 int cTailLen = strlen(pPathTail);
391 if (pElement - szPath + 1 + cLinkLen + cTailLen + 1 > FILENAME_MAX)
394 memcpy(szTemp, pPathTail, cTailLen + 1);
395 memcpy(pElement + 1, szSymlink, cLinkLen);
396 memcpy(pElement + 1 + cLinkLen, szTemp, cTailLen + 1);
397 pPathTail = pElement;
400 /* Regular directory or file. Copy to canonical path */
401 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
404 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
405 pCanonicalTail += pPathTail - pElement;
408 } while (pPathTail[0] == '/');
410 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
415 /******************************************************************************
416 * UNIXFS_build_shitemid [Internal]
418 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
422 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
423 * pIDL [O] SHITEMID will be constructed here.
426 * Success: A pointer to the terminating '\0' character of path.
430 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
431 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
434 static char* UNIXFS_build_shitemid(char *pszUnixPath, void *pIDL) {
438 struct stat fileStat;
442 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
444 /* Compute the SHITEMID's length and wipe it. */
445 pszComponent = strrchr(pszUnixPath, '/') + 1;
446 cComponentLen = strlen(pszComponent);
447 memset(pIDL, 0, SHITEMID_LEN_FROM_NAME_LEN(cComponentLen));
448 ((LPSHITEMID)pIDL)->cb = SHITEMID_LEN_FROM_NAME_LEN(cComponentLen) ;
450 /* We are only interested in regular files and directories. */
451 if (stat(pszUnixPath, &fileStat)) return NULL;
452 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
454 /* Set shell32's standard SHITEMID data fields. */
455 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
456 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
457 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
458 RtlSecondsSince1970ToTime( fileStat.st_mtime, &time );
459 fileTime.dwLowDateTime = time.u.LowPart;
460 fileTime.dwHighDateTime = time.u.HighPart;
461 FileTimeToDosDateTime(&fileTime, &pIDLData->u.file.uFileDate, &pIDLData->u.file.uFileTime);
462 pIDLData->u.file.uFileAttribs = 0;
463 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
464 if (pszComponent[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
465 memcpy(pIDLData->u.file.szNames, pszComponent, cComponentLen);
467 return pszComponent + cComponentLen;
470 /******************************************************************************
471 * UNIXFS_path_to_pidl [Internal]
474 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
475 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
476 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
480 * Failure: FALSE, invalid params or out of memory
483 * pUnixFolder also carries the information if the path is expected to be unix or dos.
485 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
487 int cSubDirs, cPidlLen, cPathLen;
488 char *pSlash, szCompletePath[FILENAME_MAX], *pNextPathElement;
490 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
495 /* Build an absolute path and let pNextPathElement point to the interesting
496 * relative sub-path. We need the absolute path to call 'stat', but the pidl
497 * will only contain the relative part.
499 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
501 /* Absolute dos path. Convert to unix */
502 if (!UNIXFS_get_unix_path(path, szCompletePath))
504 pNextPathElement = szCompletePath;
506 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
508 /* Absolute unix path. Just convert to ANSI. */
509 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
510 pNextPathElement = szCompletePath;
514 /* Relative dos or unix path. Concat with this folder's path */
515 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
516 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
517 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath + cBasePathLen,
518 FILENAME_MAX - cBasePathLen, NULL, NULL);
519 pNextPathElement = szCompletePath + cBasePathLen - 1;
521 /* If in dos mode, replace '\' with '/' */
522 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
523 char *pBackslash = strchr(pNextPathElement, '\\');
526 pBackslash = strchr(pBackslash, '\\');
531 /* Special case for the root folder. */
532 if (!strcmp(szCompletePath, "/")) {
533 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(sizeof(USHORT));
534 if (!pidl) return FALSE;
535 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
539 /* Remove trailing slash, if present */
540 cPathLen = strlen(szCompletePath);
541 if (szCompletePath[cPathLen-1] == '/')
542 szCompletePath[cPathLen-1] = '\0';
544 if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
545 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
549 /* At this point, we have an absolute unix path in szCompletePath
550 * and the relative portion of it in pNextPathElement. Both starting with '/'
551 * and _not_ terminated by a '/'. */
552 TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
554 /* Count the number of sub-directories in the path */
556 pSlash = pNextPathElement;
559 pSlash = strchr(pSlash+1, '/');
562 /* Allocate enough memory to hold the path. The -cSubDirs is for the '/'
563 * characters, which are not stored in the ITEMIDLIST. */
564 cPidlLen = strlen(pNextPathElement) - cSubDirs + cSubDirs * SHITEMID_LEN_FROM_NAME_LEN(0) + sizeof(USHORT);
565 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
566 if (!pidl) return FALSE;
568 /* Concatenate the SHITEMIDs of the sub-directories. */
569 while (*pNextPathElement) {
570 pSlash = strchr(pNextPathElement+1, '/');
571 if (pSlash) *pSlash = '\0';
572 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, pidl);
573 if (pSlash) *pSlash = '/';
575 if (!pNextPathElement) {
579 pidl = ILGetNext(pidl);
581 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
583 if ((char *)pidl-(char *)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
584 ERR("Computed length of pidl incorrect. Please report.\n");
589 /******************************************************************************
590 * UNIXFS_initialize_target_folder [Internal]
592 * Initialize the m_pszPath member of an UnixFolder, given an absolute unix
593 * base path and a relative ITEMIDLIST. Leave the m_pidlLocation member, which
594 * specifies the location in the shell namespace alone.
597 * This [IO] The UnixFolder, whose target path is to be initialized
598 * szBasePath [I] The absolute base path
599 * pidlSubFolder [I] Relative part of the path, given as an ITEMIDLIST
600 * dwAttributes [I] Attributes to add to the Folders m_dwAttributes member
601 * (Used to pass the SFGAO_FILESYSTEM flag down the path)
606 static HRESULT UNIXFS_initialize_target_folder(UnixFolder *This, const char *szBasePath,
607 LPCITEMIDLIST pidlSubFolder, DWORD dwAttributes)
609 LPCITEMIDLIST current = pidlSubFolder;
610 DWORD dwPathLen = strlen(szBasePath)+1;
611 struct stat statPrefix;
614 /* Determine the path's length bytes */
615 while (current && current->mkid.cb) {
616 dwPathLen += NAME_LEN_FROM_LPSHITEMID(current) + 1; /* For the '/' */
617 current = ILGetNext(current);
620 /* Build the path and compute the attributes*/
621 This->m_dwAttributes =
622 dwAttributes|SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
623 This->m_pszPath = pNextDir = SHAlloc(dwPathLen);
624 if (!This->m_pszPath) {
625 WARN("SHAlloc failed!\n");
628 current = pidlSubFolder;
629 strcpy(pNextDir, szBasePath);
630 pNextDir += strlen(szBasePath);
631 if (This->m_dwPathMode == PATHMODE_UNIX || IsEqualCLSID(&CLSID_MyDocuments, This->m_pCLSID))
632 This->m_dwAttributes |= SFGAO_FILESYSTEM;
633 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
635 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
636 This->m_dwAttributes |= SFGAO_FILESYSTEM;
638 while (current && current->mkid.cb) {
639 memcpy(pNextDir, _ILGetTextPointer(current), NAME_LEN_FROM_LPSHITEMID(current));
640 pNextDir += NAME_LEN_FROM_LPSHITEMID(current);
641 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
643 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
644 This->m_dwAttributes |= SFGAO_FILESYSTEM;
647 current = ILGetNext(current);
654 /******************************************************************************
657 * Class whose heap based instances represent unix filesystem directories.
660 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
661 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
663 SHFree(pUnixFolder->m_pszPath);
664 ILFree(pUnixFolder->m_pidlLocation);
668 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
671 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
673 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
675 if (!ppv) return E_INVALIDARG;
677 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
678 IsEqualIID(&IID_IShellFolder2, riid))
680 *ppv = STATIC_CAST(IShellFolder2, This);
681 } else if (IsEqualIID(&IID_IPersistFolder3, riid) || IsEqualIID(&IID_IPersistFolder2, riid) ||
682 IsEqualIID(&IID_IPersistFolder, riid) || IsEqualIID(&IID_IPersist, riid))
684 *ppv = STATIC_CAST(IPersistFolder3, This);
685 } else if (IsEqualIID(&IID_IPersistPropertyBag, riid)) {
686 *ppv = STATIC_CAST(IPersistPropertyBag, This);
687 } else if (IsEqualIID(&IID_ISFHelper, riid)) {
688 *ppv = STATIC_CAST(ISFHelper, This);
689 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
690 *ppv = STATIC_CAST(IDropTarget, This);
692 cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
695 return E_NOINTERFACE;
698 IUnknown_AddRef((IUnknown*)*ppv);
702 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
703 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
705 TRACE("(iface=%p)\n", iface);
707 return InterlockedIncrement(&This->m_cRef);
710 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
711 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
714 TRACE("(iface=%p)\n", iface);
716 cRef = InterlockedDecrement(&This->m_cRef);
719 UnixFolder_Destroy(This);
724 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
725 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
726 ULONG* pdwAttributes)
728 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
731 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
732 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
733 pchEaten, ppidl, pdwAttributes);
735 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
736 if (result && pdwAttributes && *pdwAttributes)
738 IShellFolder *pParentSF;
739 LPCITEMIDLIST pidlLast;
742 hr = SHBindToParent(*ppidl, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
743 if (FAILED(hr)) return E_FAIL;
744 IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
745 IShellFolder_Release(pParentSF);
748 if (!result) TRACE("FAILED!\n");
749 return result ? S_OK : E_FAIL;
752 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter);
754 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
755 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
757 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
758 IUnknown *newIterator;
761 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
762 iface, hwndOwner, grfFlags, ppEnumIDList);
764 if (!This->m_pszPath) {
765 WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
769 newIterator = UnixSubFolderIterator_Constructor(This, grfFlags);
770 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
771 IUnknown_Release(newIterator);
776 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID);
778 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
779 LPBC pbcReserved, REFIID riid, void** ppvOut)
781 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
782 IPersistFolder3 *persistFolder;
784 const CLSID *clsidChild;
786 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
787 iface, pidl, pbcReserved, riid, ppvOut);
789 if (!pidl || !pidl->mkid.cb)
792 if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
793 /* Children of FolderShortcuts are ShellFSFolders on Windows.
794 * Unixfs' counterpart is UnixDosFolder. */
795 clsidChild = &CLSID_UnixDosFolder;
797 clsidChild = This->m_pCLSID;
800 hr = CreateUnixFolder(NULL, &IID_IPersistFolder3, (void**)&persistFolder, clsidChild);
801 if (!SUCCEEDED(hr)) return hr;
802 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
805 UnixFolder *subfolder = ADJUST_THIS(UnixFolder, IPersistFolder3, persistFolder);
806 subfolder->m_pidlLocation = ILCombine(This->m_pidlLocation, pidl);
807 hr = UNIXFS_initialize_target_folder(subfolder, This->m_pszPath, pidl,
808 This->m_dwAttributes & SFGAO_FILESYSTEM);
811 IPersistFolder3_Release(persistFolder);
816 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
817 LPBC pbcReserved, REFIID riid, void** ppvObj)
823 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
824 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
826 BOOL isEmpty1, isEmpty2;
828 LPITEMIDLIST firstpidl;
832 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
834 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
835 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
837 if (isEmpty1 && isEmpty2)
838 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
840 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
842 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
844 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
845 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
846 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
847 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
849 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
850 _ILGetTextPointer(pidl1), NAME_LEN_FROM_LPSHITEMID(pidl1),
851 _ILGetTextPointer(pidl2), NAME_LEN_FROM_LPSHITEMID(pidl2));
853 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
854 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
856 if (pidl1->mkid.cb < pidl2->mkid.cb)
857 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
858 else if (pidl1->mkid.cb > pidl2->mkid.cb)
859 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
861 firstpidl = ILCloneFirst(pidl1);
862 pidl1 = ILGetNext(pidl1);
863 pidl2 = ILGetNext(pidl2);
865 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
867 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
868 IShellFolder2_Release(psf);
875 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
876 REFIID riid, void** ppv)
878 HRESULT hr = E_INVALIDARG;
880 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
882 if (!ppv) return E_INVALIDARG;
885 if (IsEqualIID(&IID_IShellView, riid)) {
886 LPSHELLVIEW pShellView;
888 pShellView = IShellView_Constructor((IShellFolder*)iface);
890 hr = IShellView_QueryInterface(pShellView, riid, ppv);
891 IShellView_Release(pShellView);
893 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
894 hr = IShellFolder2_QueryInterface(iface, &IID_IDropTarget, ppv);
900 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
901 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
903 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
906 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
908 if (!rgfInOut || (cidl && !apidl))
912 *rgfInOut &= This->m_dwAttributes;
914 char szAbsolutePath[FILENAME_MAX], *pszRelativePath;
917 *rgfInOut = SFGAO_CANCOPY|SFGAO_CANMOVE|SFGAO_CANLINK|SFGAO_CANRENAME|SFGAO_CANDELETE|
918 SFGAO_HASPROPSHEET|SFGAO_DROPTARGET|SFGAO_FILESYSTEM;
919 lstrcpyA(szAbsolutePath, This->m_pszPath);
920 pszRelativePath = szAbsolutePath + lstrlenA(szAbsolutePath);
921 for (i=0; i<cidl; i++) {
922 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
923 struct stat fileStat;
924 char *pszName = _ILGetTextPointer(apidl[i]);
925 if (!pszName) return E_INVALIDARG;
926 lstrcpyA(pszRelativePath, pszName);
927 if (stat(szAbsolutePath, &fileStat) || !UNIXFS_is_dos_device(&fileStat))
928 *rgfInOut &= ~SFGAO_FILESYSTEM;
930 if (_ILIsFolder(apidl[i]))
931 *rgfInOut |= SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
938 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
939 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
941 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
944 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
945 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
947 if (!cidl || !apidl || !riid || !ppvOut)
950 for (i=0; i<cidl; i++)
954 if (IsEqualIID(&IID_IContextMenu, riid)) {
955 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
957 } else if (IsEqualIID(&IID_IDataObject, riid)) {
958 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
960 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
962 if (cidl != 1) return E_INVALIDARG;
963 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
964 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
967 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
969 if (cidl != 1) return E_INVALIDARG;
970 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
971 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
974 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
975 if (cidl != 1) return E_INVALIDARG;
976 return IShellFolder2_BindToObject(iface, apidl[0], NULL, &IID_IDropTarget, ppvOut);
977 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
978 FIXME("IShellLinkW\n");
980 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
981 FIXME("IShellLinkA\n");
984 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
985 return E_NOINTERFACE;
989 /******************************************************************************
990 * Translate file name from unix to ANSI encoding.
992 static void strcpyn_U2A(char *win_fn, UINT win_fn_len, const char *unix_fn)
997 len = MultiByteToWideChar(CP_UNIXCP, 0, unix_fn, -1, NULL, 0);
998 unicode_fn = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
999 MultiByteToWideChar(CP_UNIXCP, 0, unix_fn, -1, unicode_fn, len);
1001 WideCharToMultiByte(CP_ACP, 0, unicode_fn, len, win_fn, win_fn_len, NULL, NULL);
1002 HeapFree(GetProcessHeap(), 0, unicode_fn);
1005 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
1006 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
1008 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1011 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
1013 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
1014 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
1016 if (!pidl || !pidl->mkid.cb) {
1017 lpName->uType = STRRET_CSTR;
1018 if (This->m_dwPathMode == PATHMODE_UNIX) {
1019 strcpyn_U2A(lpName->u.cStr, MAX_PATH, This->m_pszPath);
1021 WCHAR *pwszDosPath = wine_get_dos_file_name(This->m_pszPath);
1023 return HRESULT_FROM_WIN32(GetLastError());
1024 PathRemoveBackslashW(pwszDosPath);
1025 WideCharToMultiByte(CP_ACP, 0, pwszDosPath, -1, lpName->u.cStr, MAX_PATH, NULL, NULL);
1026 HeapFree(GetProcessHeap(), 0, pwszDosPath);
1029 IShellFolder *pSubFolder;
1030 SHITEMID emptyIDL = { 0, { 0 } };
1032 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
1033 if (!SUCCEEDED(hr)) return hr;
1035 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
1036 IShellFolder_Release(pSubFolder);
1039 char *pszFileName = _ILGetTextPointer(pidl);
1040 lpName->uType = STRRET_CSTR;
1041 strcpyn_U2A(lpName->u.cStr, MAX_PATH, pszFileName ? pszFileName : "");
1044 /* If in dos mode, do some post-processing on the path.
1045 * (e.g. remove filename extension, if uFlags & SHGDN_FOREDITING)
1047 if (SUCCEEDED(hr) && This->m_dwPathMode == PATHMODE_DOS && !_ILIsFolder(pidl))
1048 SHELL_FS_ProcessDisplayFilename(lpName->u.cStr, uFlags);
1050 TRACE("--> %s\n", lpName->u.cStr);
1055 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd,
1056 LPCITEMIDLIST pidl, LPCOLESTR lpszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
1058 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1060 char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
1062 int cBasePathLen = lstrlenA(This->m_pszPath);
1063 struct stat statDest;
1064 LPITEMIDLIST pidlSrc, pidlDest;
1066 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
1067 iface, hwnd, pidl, debugstr_w(lpszName), uFlags, ppidlOut);
1069 /* pidl has to contain a single non-empty SHITEMID */
1070 if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
1071 return E_INVALIDARG;
1076 /* build source path */
1077 memcpy(szSrc, This->m_pszPath, cBasePathLen);
1078 lstrcpyA(szSrc+cBasePathLen, _ILGetTextPointer(pidl));
1080 /* build destination path */
1081 if (uFlags & SHGDN_FORPARSING) { /* absolute path in lpszName */
1082 WideCharToMultiByte(CP_UNIXCP, 0, lpszName, -1, szDest, FILENAME_MAX, NULL, NULL);
1084 WCHAR wszSrcRelative[MAX_PATH];
1085 memcpy(szDest, This->m_pszPath, cBasePathLen);
1086 WideCharToMultiByte(CP_UNIXCP, 0, lpszName, -1, szDest+cBasePathLen,
1087 FILENAME_MAX-cBasePathLen, NULL, NULL);
1089 /* uFlags is SHGDN_FOREDITING of SHGDN_FORADDRESSBAR. If the filename's
1090 * extension is hidden to the user, we have to append it. */
1091 if (_ILSimpleGetTextW(pidl, wszSrcRelative, MAX_PATH) &&
1092 SHELL_FS_HideExtension(wszSrcRelative))
1094 char *pszExt = PathFindExtensionA(_ILGetTextPointer(pidl));
1095 lstrcatA(szDest, pszExt);
1099 TRACE("src=%s dest=%s\n", szSrc, szDest);
1101 /* Fail, if destination does already exist */
1102 if (!stat(szDest, &statDest))
1105 /* Rename the file */
1106 if (rename(szSrc, szDest))
1109 /* Build a pidl for the path of the renamed file */
1110 pwszDosDest = wine_get_dos_file_name(szDest);
1111 if (!pwszDosDest || !UNIXFS_path_to_pidl(This, pwszDosDest, &pidlDest)) {
1112 HeapFree(GetProcessHeap(), 0, pwszDosDest);
1113 rename(szDest, szSrc); /* Undo the renaming */
1117 /* Inform the shell */
1118 pidlSrc = ILCombine(This->m_pidlLocation, pidl);
1119 if (_ILIsFolder(ILFindLastID(pidlDest)))
1120 SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
1122 SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
1127 _ILCreateFromPathW(pwszDosDest, ppidlOut);
1129 HeapFree(GetProcessHeap(), 0, pwszDosDest);
1133 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
1134 IEnumExtraSearch **ppEnum)
1140 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
1141 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
1147 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
1148 UINT iColumn, SHCOLSTATEF *pcsFlags)
1154 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1161 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1162 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1168 #define SHELLVIEWCOLUMNS 7
1170 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1171 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1173 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1174 HRESULT hr = E_FAIL;
1175 struct passwd *pPasswd;
1176 struct group *pGroup;
1177 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1178 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1179 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1180 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1181 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
1182 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 9},
1183 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1184 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7}
1187 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1189 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1190 return E_INVALIDARG;
1193 psd->fmt = SFHeader[iColumn].fmt;
1194 psd->cxChar = SFHeader[iColumn].cxChar;
1195 psd->str.uType = STRRET_CSTR;
1196 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1199 struct stat statItem;
1200 if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
1201 char szPath[FILENAME_MAX], *pszFile = _ILGetTextPointer(pidl);
1203 return E_INVALIDARG;
1204 lstrcpyA(szPath, This->m_pszPath);
1205 lstrcatA(szPath, pszFile);
1206 if (stat(szPath, &statItem))
1207 return E_INVALIDARG;
1209 psd->str.u.cStr[0] = '\0';
1210 psd->str.uType = STRRET_CSTR;
1213 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1216 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1219 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1222 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1225 psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
1226 psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
1227 psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
1228 psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
1229 psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
1230 psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
1231 psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
1232 psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
1233 psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
1234 psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
1235 psd->str.u.cStr[10] = '\0';
1238 pPasswd = getpwuid(statItem.st_uid);
1239 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1242 pGroup = getgrgid(statItem.st_gid);
1243 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1251 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1258 /* VTable for UnixFolder's IShellFolder2 interface.
1260 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1261 UnixFolder_IShellFolder2_QueryInterface,
1262 UnixFolder_IShellFolder2_AddRef,
1263 UnixFolder_IShellFolder2_Release,
1264 UnixFolder_IShellFolder2_ParseDisplayName,
1265 UnixFolder_IShellFolder2_EnumObjects,
1266 UnixFolder_IShellFolder2_BindToObject,
1267 UnixFolder_IShellFolder2_BindToStorage,
1268 UnixFolder_IShellFolder2_CompareIDs,
1269 UnixFolder_IShellFolder2_CreateViewObject,
1270 UnixFolder_IShellFolder2_GetAttributesOf,
1271 UnixFolder_IShellFolder2_GetUIObjectOf,
1272 UnixFolder_IShellFolder2_GetDisplayNameOf,
1273 UnixFolder_IShellFolder2_SetNameOf,
1274 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1275 UnixFolder_IShellFolder2_EnumSearches,
1276 UnixFolder_IShellFolder2_GetDefaultColumn,
1277 UnixFolder_IShellFolder2_GetDefaultColumnState,
1278 UnixFolder_IShellFolder2_GetDetailsEx,
1279 UnixFolder_IShellFolder2_GetDetailsOf,
1280 UnixFolder_IShellFolder2_MapColumnToSCID
1283 static HRESULT WINAPI UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3* iface, REFIID riid,
1286 return UnixFolder_IShellFolder2_QueryInterface(
1287 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)), riid, ppvObject);
1290 static ULONG WINAPI UnixFolder_IPersistFolder3_AddRef(IPersistFolder3* iface)
1292 return UnixFolder_IShellFolder2_AddRef(
1293 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)));
1296 static ULONG WINAPI UnixFolder_IPersistFolder3_Release(IPersistFolder3* iface)
1298 return UnixFolder_IShellFolder2_Release(
1299 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)));
1302 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3* iface, CLSID* pClassID)
1304 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1306 TRACE("(iface=%p, pClassId=%p)\n", iface, pClassID);
1309 return E_INVALIDARG;
1311 memcpy(pClassID, This->m_pCLSID, sizeof(CLSID));
1315 static HRESULT WINAPI UnixFolder_IPersistFolder3_Initialize(IPersistFolder3* iface, LPCITEMIDLIST pidl)
1317 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1318 LPCITEMIDLIST current = pidl;
1319 char szBasePath[FILENAME_MAX] = "/";
1321 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1323 /* Find the UnixFolderClass root */
1324 while (current->mkid.cb) {
1325 if (_ILIsSpecialFolder(current) && IsEqualIID(This->m_pCLSID, _ILGetGUIDPointer(current)))
1327 current = ILGetNext(current);
1330 if (current && current->mkid.cb) {
1331 if (IsEqualIID(&CLSID_MyDocuments, _ILGetGUIDPointer(current))) {
1332 WCHAR wszMyDocumentsPath[MAX_PATH];
1333 if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath, CSIDL_PERSONAL, FALSE))
1335 PathAddBackslashW(wszMyDocumentsPath);
1336 if (!UNIXFS_get_unix_path(wszMyDocumentsPath, szBasePath))
1339 current = ILGetNext(current);
1340 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
1341 /* Path rooted at Desktop */
1342 WCHAR wszDesktopPath[MAX_PATH];
1343 if (!SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE))
1345 PathAddBackslashW(wszDesktopPath);
1346 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
1349 } else if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
1350 /* FolderShortcuts' Initialize method only sets the ITEMIDLIST, which
1351 * specifies the location in the shell namespace, but leaves the
1352 * target folder (m_pszPath) alone. See unit tests in tests/shlfolder.c */
1353 This->m_pidlLocation = ILClone(pidl);
1356 ERR("Unknown pidl type!\n");
1358 return E_INVALIDARG;
1361 This->m_pidlLocation = ILClone(pidl);
1362 return UNIXFS_initialize_target_folder(This, szBasePath, current, 0);
1365 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3* iface, LPITEMIDLIST* ppidl)
1367 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1369 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1373 *ppidl = ILClone (This->m_pidlLocation);
1377 static HRESULT WINAPI UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3 *iface, IBindCtx *pbc,
1378 LPCITEMIDLIST pidlRoot, const PERSIST_FOLDER_TARGET_INFO *ppfti)
1380 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1381 WCHAR wszTargetDosPath[MAX_PATH];
1382 char szTargetPath[FILENAME_MAX] = "";
1384 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface, pbc, pidlRoot, ppfti);
1386 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1388 return IPersistFolder3_Initialize(iface, pidlRoot);
1390 if (ppfti->csidl != -1) {
1391 if (FAILED(SHGetFolderPathW(0, ppfti->csidl, NULL, 0, wszTargetDosPath)) ||
1392 !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1396 } else if (*ppfti->szTargetParsingName) {
1397 lstrcpyW(wszTargetDosPath, ppfti->szTargetParsingName);
1398 PathAddBackslashW(wszTargetDosPath);
1399 if (!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath)) {
1402 } else if (ppfti->pidlTargetFolder) {
1403 if (!SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTargetDosPath) ||
1404 !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1412 This->m_pszPath = SHAlloc(lstrlenA(szTargetPath)+1);
1413 if (!This->m_pszPath)
1415 lstrcpyA(This->m_pszPath, szTargetPath);
1416 This->m_pidlLocation = ILClone(pidlRoot);
1417 This->m_dwAttributes = (ppfti->dwAttributes != -1) ? ppfti->dwAttributes :
1418 (SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|SFGAO_FILESYSTEM);
1423 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3 *iface,
1424 PERSIST_FOLDER_TARGET_INFO *ppfti)
1426 FIXME("(iface=%p, ppfti=%p) stub\n", iface, ppfti);
1430 /* VTable for UnixFolder's IPersistFolder interface.
1432 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl = {
1433 UnixFolder_IPersistFolder3_QueryInterface,
1434 UnixFolder_IPersistFolder3_AddRef,
1435 UnixFolder_IPersistFolder3_Release,
1436 UnixFolder_IPersistFolder3_GetClassID,
1437 UnixFolder_IPersistFolder3_Initialize,
1438 UnixFolder_IPersistFolder3_GetCurFolder,
1439 UnixFolder_IPersistFolder3_InitializeEx,
1440 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1443 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag* iface,
1444 REFIID riid, void** ppv)
1446 return UnixFolder_IShellFolder2_QueryInterface(
1447 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)), riid, ppv);
1450 static ULONG WINAPI UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag* iface)
1452 return UnixFolder_IShellFolder2_AddRef(
1453 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)));
1456 static ULONG WINAPI UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag* iface)
1458 return UnixFolder_IShellFolder2_Release(
1459 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)));
1462 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag* iface,
1465 return UnixFolder_IPersistFolder3_GetClassID(
1466 STATIC_CAST(IPersistFolder3, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)), pClassID);
1469 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag* iface)
1475 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag *iface,
1476 IPropertyBag *pPropertyBag, IErrorLog *pErrorLog)
1478 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface);
1479 static const WCHAR wszTarget[] = { 'T','a','r','g','e','t', 0 }, wszNull[] = { 0 };
1480 PERSIST_FOLDER_TARGET_INFO pftiTarget;
1484 TRACE("(iface=%p, pPropertyBag=%p, pErrorLog=%p)\n", iface, pPropertyBag, pErrorLog);
1489 /* Get 'Target' property from the property bag. */
1490 V_VT(&var) = VT_BSTR;
1491 hr = IPropertyBag_Read(pPropertyBag, wszTarget, &var, NULL);
1494 lstrcpyW(pftiTarget.szTargetParsingName, V_BSTR(&var));
1495 SysFreeString(V_BSTR(&var));
1497 pftiTarget.pidlTargetFolder = NULL;
1498 lstrcpyW(pftiTarget.szNetworkProvider, wszNull);
1499 pftiTarget.dwAttributes = -1;
1500 pftiTarget.csidl = -1;
1502 return UnixFolder_IPersistFolder3_InitializeEx(
1503 STATIC_CAST(IPersistFolder3, This), NULL, NULL, &pftiTarget);
1506 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag *iface,
1507 IPropertyBag *pPropertyBag, BOOL fClearDirty, BOOL fSaveAllProperties)
1513 /* VTable for UnixFolder's IPersistPropertyBag interface.
1515 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl = {
1516 UnixFolder_IPersistPropertyBag_QueryInterface,
1517 UnixFolder_IPersistPropertyBag_AddRef,
1518 UnixFolder_IPersistPropertyBag_Release,
1519 UnixFolder_IPersistPropertyBag_GetClassID,
1520 UnixFolder_IPersistPropertyBag_InitNew,
1521 UnixFolder_IPersistPropertyBag_Load,
1522 UnixFolder_IPersistPropertyBag_Save
1525 static HRESULT WINAPI UnixFolder_ISFHelper_QueryInterface(ISFHelper* iface, REFIID riid,
1528 return UnixFolder_IShellFolder2_QueryInterface(
1529 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)), riid, ppvObject);
1532 static ULONG WINAPI UnixFolder_ISFHelper_AddRef(ISFHelper* iface)
1534 return UnixFolder_IShellFolder2_AddRef(
1535 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)));
1538 static ULONG WINAPI UnixFolder_ISFHelper_Release(ISFHelper* iface)
1540 return UnixFolder_IShellFolder2_Release(
1541 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)));
1544 static HRESULT WINAPI UnixFolder_ISFHelper_GetUniqueName(ISFHelper* iface, LPSTR lpName, UINT uLen)
1546 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1549 LPITEMIDLIST pidlElem;
1552 static const char szNewFolder[] = "New Folder";
1554 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface, lpName, uLen);
1556 if (uLen < sizeof(szNewFolder)+3)
1557 return E_INVALIDARG;
1559 hr = IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2, This), 0,
1560 SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
1561 if (SUCCEEDED(hr)) {
1562 lstrcpyA(lpName, szNewFolder);
1563 IEnumIDList_Reset(pEnum);
1565 while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
1566 if (!strcasecmp(_ILGetTextPointer(pidlElem), lpName)) {
1567 IEnumIDList_Reset(pEnum);
1568 sprintf(lpName, "%s %d", szNewFolder, i++);
1575 IEnumIDList_Release(pEnum);
1580 static HRESULT WINAPI UnixFolder_ISFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCSTR pszName,
1581 LPITEMIDLIST* ppidlOut)
1583 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1584 char szNewDir[FILENAME_MAX];
1586 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface, hwnd, pszName, ppidlOut);
1591 lstrcpyA(szNewDir, This->m_pszPath);
1592 lstrcatA(szNewDir, pszName);
1594 if (mkdir(szNewDir, 0755)) {
1595 char szMessage[256 + FILENAME_MAX];
1596 char szCaption[256];
1598 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
1599 sprintf(szMessage, szCaption, szNewDir);
1600 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
1601 MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
1605 LPITEMIDLIST pidlRelative;
1606 WCHAR wszName[MAX_PATH];
1608 /* Inform the shell */
1609 MultiByteToWideChar(CP_UNIXCP, 0, pszName, -1, wszName, MAX_PATH);
1610 if (UNIXFS_path_to_pidl(This, wszName, &pidlRelative)) {
1611 LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
1613 *ppidlOut = pidlRelative;
1615 ILFree(pidlRelative);
1616 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1617 ILFree(pidlAbsolute);
1623 static HRESULT WINAPI UnixFolder_ISFHelper_DeleteItems(ISFHelper* iface, UINT cidl,
1624 LPCITEMIDLIST* apidl)
1626 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1627 char szAbsolute[FILENAME_MAX], *pszRelative;
1628 LPITEMIDLIST pidlAbsolute;
1632 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface, cidl, apidl);
1634 lstrcpyA(szAbsolute, This->m_pszPath);
1635 pszRelative = szAbsolute + lstrlenA(szAbsolute);
1637 for (i=0; i<cidl && SUCCEEDED(hr); i++) {
1638 lstrcpyA(pszRelative, _ILGetTextPointer(apidl[i]));
1639 pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
1640 if (_ILIsFolder(apidl[i])) {
1641 if (rmdir(szAbsolute)) {
1644 SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1646 } else if (_ILIsValue(apidl[i])) {
1647 if (unlink(szAbsolute)) {
1650 SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
1653 ILFree(pidlAbsolute);
1659 static HRESULT WINAPI UnixFolder_ISFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom,
1660 UINT cidl, LPCITEMIDLIST *apidl)
1662 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1666 char szAbsoluteDst[FILENAME_MAX], *pszRelativeDst;
1668 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface, psfFrom, cidl, apidl);
1670 if (!psfFrom || !cidl || !apidl)
1671 return E_INVALIDARG;
1673 /* All source items have to be filesystem items. */
1674 dwAttributes = SFGAO_FILESYSTEM;
1675 hr = IShellFolder_GetAttributesOf(psfFrom, cidl, apidl, &dwAttributes);
1676 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM))
1677 return E_INVALIDARG;
1679 lstrcpyA(szAbsoluteDst, This->m_pszPath);
1680 pszRelativeDst = szAbsoluteDst + strlen(szAbsoluteDst);
1682 for (i=0; i<cidl; i++) {
1683 WCHAR wszSrc[MAX_PATH];
1684 char szSrc[FILENAME_MAX];
1687 /* Build the unix path of the current source item. */
1688 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom, apidl[i], SHGDN_FORPARSING, &strret)))
1690 if (FAILED(StrRetToBufW(&strret, apidl[i], wszSrc, MAX_PATH)))
1692 if (!UNIXFS_get_unix_path(wszSrc, szSrc))
1695 /* Build the unix path of the current destination item */
1696 lstrcpyA(pszRelativeDst, _ILGetTextPointer(apidl[i]));
1698 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc, szAbsoluteDst);
1703 /* VTable for UnixFolder's ISFHelper interface
1705 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl = {
1706 UnixFolder_ISFHelper_QueryInterface,
1707 UnixFolder_ISFHelper_AddRef,
1708 UnixFolder_ISFHelper_Release,
1709 UnixFolder_ISFHelper_GetUniqueName,
1710 UnixFolder_ISFHelper_AddFolder,
1711 UnixFolder_ISFHelper_DeleteItems,
1712 UnixFolder_ISFHelper_CopyItems
1715 static HRESULT WINAPI UnixFolder_IDropTarget_QueryInterface(IDropTarget* iface, REFIID riid,
1718 return UnixFolder_IShellFolder2_QueryInterface(
1719 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)), riid, ppvObject);
1722 static ULONG WINAPI UnixFolder_IDropTarget_AddRef(IDropTarget* iface)
1724 return UnixFolder_IShellFolder2_AddRef(
1725 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)));
1728 static ULONG WINAPI UnixFolder_IDropTarget_Release(IDropTarget* iface)
1730 return UnixFolder_IShellFolder2_Release(
1731 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)));
1734 #define HIDA_GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
1735 #define HIDA_GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
1737 static HRESULT WINAPI UnixFolder_IDropTarget_DragEnter(IDropTarget *iface, IDataObject *pDataObject,
1738 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
1740 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1744 TRACE("(iface=%p, pDataObject=%p, dwKeyState=%08lx, pt={.x=%ld, .y=%ld}, pdwEffect=%p)\n",
1745 iface, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
1747 if (!pdwEffect || !pDataObject)
1748 return E_INVALIDARG;
1750 /* Compute a mask of supported drop-effects for this shellfolder object and the given data
1751 * object. Dropping is only supported on folders, which represent filesystem locations. One
1752 * can't drop on file objects. And the 'move' drop effect is only supported, if the source
1753 * folder is not identical to the target folder. */
1754 This->m_dwDropEffectsMask = DROPEFFECT_NONE;
1755 InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
1756 if ((This->m_dwAttributes & SFGAO_FILESYSTEM) && /* Only drop to filesystem folders */
1757 _ILIsFolder(ILFindLastID(This->m_pidlLocation)) && /* Only drop to folders, not to files */
1758 SUCCEEDED(IDataObject_GetData(pDataObject, &format, &medium))) /* Only ShellIDList format */
1760 LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
1761 This->m_dwDropEffectsMask |= DROPEFFECT_COPY|DROPEFFECT_LINK;
1763 if (pidaShellIDList) { /* Files can only be moved between two different folders */
1764 if (!ILIsEqual(HIDA_GetPIDLFolder(pidaShellIDList), This->m_pidlLocation))
1765 This->m_dwDropEffectsMask |= DROPEFFECT_MOVE;
1766 GlobalUnlock(medium.u.hGlobal);
1770 *pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
1775 static HRESULT WINAPI UnixFolder_IDropTarget_DragOver(IDropTarget *iface, DWORD dwKeyState,
1776 POINTL pt, DWORD *pdwEffect)
1778 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1780 TRACE("(iface=%p, dwKeyState=%08lx, pt={.x=%ld, .y=%ld}, pdwEffect=%p)\n", iface, dwKeyState,
1781 pt.x, pt.y, pdwEffect);
1784 return E_INVALIDARG;
1786 *pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
1791 static HRESULT WINAPI UnixFolder_IDropTarget_DragLeave(IDropTarget *iface) {
1792 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1794 TRACE("(iface=%p)\n", iface);
1796 This->m_dwDropEffectsMask = DROPEFFECT_NONE;
1801 static HRESULT WINAPI UnixFolder_IDropTarget_Drop(IDropTarget *iface, IDataObject *pDataObject,
1802 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
1804 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1809 TRACE("(iface=%p, pDataObject=%p, dwKeyState=%ld, pt={.x=%ld, .y=%ld}, pdwEffect=%p) semi-stub\n",
1810 iface, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
1812 InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
1813 hr = IDataObject_GetData(pDataObject, &format, &medium);
1817 if (medium.tymed == TYMED_HGLOBAL) {
1818 IShellFolder *psfSourceFolder, *psfDesktopFolder;
1819 LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
1823 if (!pidaShellIDList)
1824 return HRESULT_FROM_WIN32(GetLastError());
1826 hr = SHGetDesktopFolder(&psfDesktopFolder);
1828 GlobalUnlock(medium.u.hGlobal);
1832 hr = IShellFolder_BindToObject(psfDesktopFolder, HIDA_GetPIDLFolder(pidaShellIDList), NULL,
1833 &IID_IShellFolder, (LPVOID*)&psfSourceFolder);
1834 IShellFolder_Release(psfDesktopFolder);
1836 GlobalUnlock(medium.u.hGlobal);
1840 for (i = 0; i < pidaShellIDList->cidl; i++) {
1841 WCHAR wszSourcePath[MAX_PATH];
1843 hr = IShellFolder_GetDisplayNameOf(psfSourceFolder, HIDA_GetPIDLItem(pidaShellIDList, i),
1844 SHGDN_FORPARSING, &strret);
1848 hr = StrRetToBufW(&strret, NULL, wszSourcePath, MAX_PATH);
1852 switch (*pdwEffect) {
1853 case DROPEFFECT_MOVE:
1854 FIXME("Move %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
1856 case DROPEFFECT_COPY:
1857 FIXME("Copy %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
1859 case DROPEFFECT_LINK:
1860 FIXME("Link %s from %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
1865 IShellFolder_Release(psfSourceFolder);
1866 GlobalUnlock(medium.u.hGlobal);
1873 /* VTable for UnixFolder's IDropTarget interface
1875 static const IDropTargetVtbl UnixFolder_IDropTarget_Vtbl = {
1876 UnixFolder_IDropTarget_QueryInterface,
1877 UnixFolder_IDropTarget_AddRef,
1878 UnixFolder_IDropTarget_Release,
1879 UnixFolder_IDropTarget_DragEnter,
1880 UnixFolder_IDropTarget_DragOver,
1881 UnixFolder_IDropTarget_DragLeave,
1882 UnixFolder_IDropTarget_Drop
1885 /******************************************************************************
1886 * Unix[Dos]Folder_Constructor [Internal]
1889 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
1890 * riid [I] Interface asked for by the client.
1891 * ppv [O] Pointer to an riid interface to the UnixFolder object.
1894 * Those are the only functions exported from shfldr_unixfs.c. They are called from
1895 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
1896 * compatible signature.
1898 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
1899 * means that paths are converted from dos to unix and back at the interfaces.
1901 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID)
1903 HRESULT hr = E_FAIL;
1904 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
1907 FIXME("Aggregation not yet implemented!\n");
1908 return CLASS_E_NOAGGREGATION;
1912 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
1913 pUnixFolder->lpIPersistFolder3Vtbl = &UnixFolder_IPersistFolder3_Vtbl;
1914 pUnixFolder->lpIPersistPropertyBagVtbl = &UnixFolder_IPersistPropertyBag_Vtbl;
1915 pUnixFolder->lpISFHelperVtbl = &UnixFolder_ISFHelper_Vtbl;
1916 pUnixFolder->lpIDropTargetVtbl = &UnixFolder_IDropTarget_Vtbl;
1917 pUnixFolder->m_cRef = 0;
1918 pUnixFolder->m_pszPath = NULL;
1919 pUnixFolder->m_pidlLocation = NULL;
1920 pUnixFolder->m_dwPathMode = IsEqualCLSID(&CLSID_UnixFolder, pCLSID) ? PATHMODE_UNIX : PATHMODE_DOS;
1921 pUnixFolder->m_dwAttributes = 0;
1922 pUnixFolder->m_pCLSID = pCLSID;
1923 pUnixFolder->m_dwDropEffectsMask = DROPEFFECT_NONE;
1925 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
1926 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
1927 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
1932 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1933 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1934 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixFolder);
1937 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1938 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1939 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixDosFolder);
1942 HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1943 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1944 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_FolderShortcut);
1947 HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
1948 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
1949 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_MyDocuments);
1952 /******************************************************************************
1953 * UnixSubFolderIterator
1955 * Class whose heap based objects represent iterators over the sub-directories
1956 * of a given UnixFolder object.
1959 /* UnixSubFolderIterator object layout and typedef.
1961 typedef struct _UnixSubFolderIterator {
1962 const IEnumIDListVtbl *lpIEnumIDListVtbl;
1966 char m_szFolder[FILENAME_MAX];
1967 } UnixSubFolderIterator;
1969 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
1970 TRACE("(iterator=%p)\n", iterator);
1972 if (iterator->m_dirFolder)
1973 closedir(iterator->m_dirFolder);
1977 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
1978 REFIID riid, void** ppv)
1980 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
1982 if (!ppv) return E_INVALIDARG;
1984 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
1988 return E_NOINTERFACE;
1991 IEnumIDList_AddRef(iface);
1995 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
1997 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
1999 TRACE("(iface=%p)\n", iface);
2001 return InterlockedIncrement(&This->m_cRef);
2004 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
2006 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2009 TRACE("(iface=%p)\n", iface);
2011 cRef = InterlockedDecrement(&This->m_cRef);
2014 UnixSubFolderIterator_Destroy(This);
2019 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
2020 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
2022 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2025 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
2026 if (This->m_dirFolder) {
2027 char *pszRelativePath = This->m_szFolder + lstrlenA(This->m_szFolder);
2028 struct dirent *pDirEntry;
2031 pDirEntry = readdir(This->m_dirFolder);
2032 if (!pDirEntry) break; /* No more entries */
2033 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
2035 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
2036 * and see if it passes the filter.
2038 lstrcpyA(pszRelativePath, pDirEntry->d_name);
2039 rgelt[i] = (LPITEMIDLIST)SHAlloc(SHITEMID_LEN_FROM_NAME_LEN(lstrlenA(pszRelativePath))+sizeof(USHORT));
2040 if (!UNIXFS_build_shitemid(This->m_szFolder, rgelt[i]) ||
2041 !UNIXFS_is_pidl_of_type(rgelt[i], This->m_fFilter))
2046 memset(((PBYTE)rgelt[i])+rgelt[i]->mkid.cb, 0, sizeof(USHORT));
2049 *pszRelativePath = '\0'; /* Restore the original path in This->m_szFolder. */
2055 return (i == 0) ? S_FALSE : S_OK;
2058 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
2060 LPITEMIDLIST *apidl;
2064 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
2066 /* Call IEnumIDList::Next and delete the resulting pidls. */
2067 apidl = (LPITEMIDLIST*)SHAlloc(celt * sizeof(LPITEMIDLIST));
2068 hr = IEnumIDList_Next(iface, celt, apidl, &cFetched);
2071 SHFree(apidl[cFetched]);
2077 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
2079 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2081 TRACE("(iface=%p)\n", iface);
2083 if (This->m_dirFolder)
2084 rewinddir(This->m_dirFolder);
2089 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
2090 IEnumIDList** ppenum)
2096 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
2098 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
2099 UnixSubFolderIterator_IEnumIDList_QueryInterface,
2100 UnixSubFolderIterator_IEnumIDList_AddRef,
2101 UnixSubFolderIterator_IEnumIDList_Release,
2102 UnixSubFolderIterator_IEnumIDList_Next,
2103 UnixSubFolderIterator_IEnumIDList_Skip,
2104 UnixSubFolderIterator_IEnumIDList_Reset,
2105 UnixSubFolderIterator_IEnumIDList_Clone
2108 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter) {
2109 UnixSubFolderIterator *iterator;
2111 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
2113 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
2114 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
2115 iterator->m_cRef = 0;
2116 iterator->m_fFilter = fFilter;
2117 iterator->m_dirFolder = opendir(pUnixFolder->m_pszPath);
2118 lstrcpyA(iterator->m_szFolder, pUnixFolder->m_pszPath);
2120 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
2122 return (IUnknown*)iterator;