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"
136 #ifdef HAVE_SYS_STAT_H
137 # include <sys/stat.h>
146 #define NONAMELESSUNION
147 #define NONAMELESSSTRUCT
155 #include "winternl.h"
156 #include "wine/debug.h"
158 #include "shell32_main.h"
159 #include "shellfolder.h"
161 #include "shresdef.h"
164 WINE_DEFAULT_DEBUG_CHANNEL(shell);
166 const GUID CLSID_UnixFolder = {0xcc702eb2, 0x7dc5, 0x11d9, {0xc6, 0x87, 0x00, 0x04, 0x23, 0x8a, 0x01, 0xcd}};
167 const GUID CLSID_UnixDosFolder = {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
169 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
170 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
172 #define LEN_SHITEMID_FIXED_PART ((USHORT) \
173 ( sizeof(USHORT) /* SHITEMID's cb field. */ \
174 + sizeof(PIDLTYPE) /* PIDLDATA's type field. */ \
175 + sizeof(FileStruct) /* Well, the FileStruct. */ \
176 - sizeof(char) /* One char too much in FileStruct. */ \
177 + sizeof(FileStructW) /* You name it. */ \
178 - sizeof(WCHAR) /* One WCHAR too much in FileStructW. */ \
179 + sizeof(WORD) )) /* Offset of FileStructW field in PIDL. */
181 #define PATHMODE_UNIX 0
182 #define PATHMODE_DOS 1
184 /* UnixFolder object layout and typedef.
186 typedef struct _UnixFolder {
187 const IShellFolder2Vtbl *lpIShellFolder2Vtbl;
188 const IPersistFolder3Vtbl *lpIPersistFolder3Vtbl;
189 const IPersistPropertyBagVtbl *lpIPersistPropertyBagVtbl;
190 const IDropTargetVtbl *lpIDropTargetVtbl;
191 const ISFHelperVtbl *lpISFHelperVtbl;
193 CHAR *m_pszPath; /* Target path of the shell folder (CP_UNIXCP) */
194 LPITEMIDLIST m_pidlLocation; /* Location in the shell namespace */
196 DWORD m_dwAttributes;
197 const CLSID *m_pCLSID;
198 DWORD m_dwDropEffectsMask;
201 /* Will hold the registered clipboard format identifier for ITEMIDLISTS. */
202 static UINT cfShellIDList = 0;
204 /******************************************************************************
205 * UNIXFS_is_rooted_at_desktop [Internal]
207 * Checks if the unixfs namespace extension is rooted at desktop level.
210 * TRUE, if unixfs is rooted at desktop level
213 BOOL UNIXFS_is_rooted_at_desktop(void) {
215 WCHAR wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
216 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
217 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
218 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
219 'N','a','m','e','S','p','a','c','e','\\',0 };
221 if (StringFromGUID2(&CLSID_UnixDosFolder, wszRootedAtDesktop + 69, CHARS_IN_GUID) &&
222 RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
230 /******************************************************************************
231 * UNIXFS_filename_from_shitemid [Internal]
233 * Get CP_UNIXCP encoded filename corresponding to the first item of a pidl
236 * pidl [I] A simple SHITEMID
237 * pszPathElement [O] Filename in CP_UNIXCP encoding will be stored here
240 * Success: Number of bytes necessary to store the CP_UNIXCP encoded filename
241 * _without_ the terminating NUL.
245 * Size of the buffer at pszPathElement has to be FILENAME_MAX. pszPathElement
246 * may be NULL, if you are only interested in the return value.
248 static int UNIXFS_filename_from_shitemid(LPCITEMIDLIST pidl, char* pszPathElement) {
249 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
253 cLen = WideCharToMultiByte(CP_UNIXCP, 0, pFileStructW->wszName, -1, pszPathElement,
254 pszPathElement ? FILENAME_MAX : 0, 0, 0);
256 /* There might be pidls slipping in from shfldr_fs.c, which don't contain the
257 * FileStructW field. In this case, we have to convert from CP_ACP to CP_UNIXCP. */
258 char *pszText = _ILGetTextPointer(pidl);
259 WCHAR *pwszPathElement = NULL;
262 cWideChars = MultiByteToWideChar(CP_ACP, 0, pszText, -1, NULL, 0);
263 if (!cWideChars) goto cleanup;
265 pwszPathElement = SHAlloc(cWideChars * sizeof(WCHAR));
266 if (!pwszPathElement) goto cleanup;
268 cWideChars = MultiByteToWideChar(CP_ACP, 0, pszText, -1, pwszPathElement, cWideChars);
269 if (!cWideChars) goto cleanup;
271 cLen = WideCharToMultiByte(CP_UNIXCP, 0, pwszPathElement, -1, pszPathElement,
272 pszPathElement ? FILENAME_MAX : 0, 0, 0);
275 SHFree(pwszPathElement);
278 if (cLen) cLen--; /* Don't count terminating NUL! */
282 /******************************************************************************
283 * UNIXFS_shitemid_len_from_filename [Internal]
285 * Computes the necessary length of a pidl to hold a path element
288 * szPathElement [I] The path element string in CP_UNIXCP encoding.
289 * ppszPathElement [O] Path element string in CP_ACP encoding.
290 * ppwszPathElement [O] Path element string as WCHAR string.
293 * Success: Length in bytes of a SHITEMID representing szPathElement
297 * Provide NULL values if not interested in pp(w)szPathElement. Otherwise
298 * caller is responsible to free ppszPathElement and ppwszPathElement with
301 static USHORT UNIXFS_shitemid_len_from_filename(
302 const char *szPathElement, char **ppszPathElement, WCHAR **ppwszPathElement)
304 USHORT cbPidlLen = 0;
305 WCHAR *pwszPathElement = NULL;
306 char *pszPathElement = NULL;
307 int cWideChars, cChars;
309 /* There and Back Again: A Hobbit's Holiday. CP_UNIXCP might be some ANSI
310 * codepage or it might be a real multi-byte encoding like utf-8. There is no
311 * other way to figure out the length of the corresponding WCHAR and CP_ACP
312 * strings without actually doing the full CP_UNIXCP -> WCHAR -> CP_ACP cycle. */
314 cWideChars = MultiByteToWideChar(CP_UNIXCP, 0, szPathElement, -1, NULL, 0);
315 if (!cWideChars) goto cleanup;
317 pwszPathElement = SHAlloc(cWideChars * sizeof(WCHAR));
318 if (!pwszPathElement) goto cleanup;
320 cWideChars = MultiByteToWideChar(CP_UNIXCP, 0, szPathElement, -1, pwszPathElement, cWideChars);
321 if (!cWideChars) goto cleanup;
323 cChars = WideCharToMultiByte(CP_ACP, 0, pwszPathElement, -1, NULL, 0, 0, 0);
324 if (!cChars) goto cleanup;
326 pszPathElement = SHAlloc(cChars);
327 if (!pszPathElement) goto cleanup;
329 cChars = WideCharToMultiByte(CP_ACP, 0, pwszPathElement, -1, pszPathElement, cChars, 0, 0);
330 if (!cChars) goto cleanup;
332 /* (cChars & 0x1) is for the potential alignment byte */
333 cbPidlLen = LEN_SHITEMID_FIXED_PART + cChars + (cChars & 0x1) + cWideChars * sizeof(WCHAR);
336 if (cbPidlLen && ppszPathElement)
337 *ppszPathElement = pszPathElement;
339 SHFree(pszPathElement);
341 if (cbPidlLen && ppwszPathElement)
342 *ppwszPathElement = pwszPathElement;
344 SHFree(pwszPathElement);
349 /******************************************************************************
350 * UNIXFS_is_pidl_of_type [Internal]
352 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
355 * pIDL [I] The ITEMIDLIST to be checked.
356 * fFilter [I] Shell condition flags, which specify the filter.
359 * TRUE, if pIDL is accepted by fFilter
362 static inline BOOL UNIXFS_is_pidl_of_type(LPITEMIDLIST pIDL, SHCONTF fFilter) {
363 LPPIDLDATA pIDLData = _ILGetDataPointer(pIDL);
364 if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
365 (pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
369 if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
370 if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
374 /******************************************************************************
375 * UNIXFS_is_dos_device [Internal]
377 * Determines if a unix directory corresponds to any dos device.
380 * statPath [I] The stat struct of the directory, as returned by stat(2).
383 * TRUE, if statPath corresponds to any dos drive letter
386 static BOOL UNIXFS_is_dos_device(const struct stat *statPath) {
387 struct stat statDrive;
390 WCHAR wszDosDevice[4] = { 'A', ':', '\\', 0 };
392 for (dwDriveMap = GetLogicalDrives(); dwDriveMap; dwDriveMap >>= 1, wszDosDevice[0]++) {
393 if (!(dwDriveMap & 0x1)) continue;
394 pszDrivePath = wine_get_unix_file_name(wszDosDevice);
395 if (pszDrivePath && !stat(pszDrivePath, &statDrive)) {
396 HeapFree(GetProcessHeap(), 0, pszDrivePath);
397 if ((statPath->st_dev == statDrive.st_dev) && (statPath->st_ino == statDrive.st_ino))
404 /******************************************************************************
405 * UNIXFS_get_unix_path [Internal]
407 * Convert an absolute dos path to an absolute unix path.
408 * Evaluate "/.", "/.." and the symbolic links in $WINEPREFIX/dosdevices.
411 * pszDosPath [I] An absolute dos path
412 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
416 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
418 static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
420 char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath;
421 WCHAR wszDrive[] = { '?', ':', '\\', 0 };
422 int cDriveSymlinkLen;
424 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
426 if (!pszDosPath || pszDosPath[1] != ':')
429 /* Get the canonicalized unix path corresponding to the drive letter. */
430 wszDrive[0] = pszDosPath[0];
431 pszUnixPath = wine_get_unix_file_name(wszDrive);
432 if (!pszUnixPath) return FALSE;
433 cDriveSymlinkLen = strlen(pszUnixPath);
434 pElement = realpath(pszUnixPath, szPath);
435 HeapFree(GetProcessHeap(), 0, pszUnixPath);
436 if (!pElement) return FALSE;
437 if (szPath[strlen(szPath)-1] != '/') strcat(szPath, "/");
439 /* Append the part relative to the drive symbolic link target. */
440 pszUnixPath = wine_get_unix_file_name(pszDosPath);
441 if (!pszUnixPath) return FALSE;
442 strcat(szPath, pszUnixPath + cDriveSymlinkLen);
443 HeapFree(GetProcessHeap(), 0, pszUnixPath);
445 /* pCanonicalTail always points to the end of the canonical path constructed
446 * thus far. pPathTail points to the still to be processed part of the input
447 * path. pElement points to the path element currently investigated.
449 *pszCanonicalPath = '\0';
450 pCanonicalTail = pszCanonicalPath;
456 pElement = pPathTail;
457 pPathTail = strchr(pPathTail+1, '/');
458 if (!pPathTail) /* Last path element may not be terminated by '/'. */
459 pPathTail = pElement + strlen(pElement);
460 /* Temporarily terminate the current path element. Will be restored later. */
464 /* Skip "/." path elements */
465 if (!strcmp("/.", pElement)) {
467 } else if (!strcmp("/..", pElement)) {
468 /* Remove last element in canonical path for "/.." elements, then skip. */
469 char *pTemp = strrchr(pszCanonicalPath, '/');
471 pCanonicalTail = pTemp;
472 *pCanonicalTail = '\0';
475 /* Directory or file. Copy to canonical path */
476 if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
479 memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
480 pCanonicalTail += pPathTail - pElement;
483 } while (pPathTail[0] == '/');
485 TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
490 /******************************************************************************
491 * UNIXFS_seconds_since_1970_to_dos_date_time [Internal]
493 * Convert unix time to FAT time
496 * ss1970 [I] Unix time (seconds since 1970)
497 * pDate [O] Corresponding FAT date
498 * pTime [O] Corresponding FAT time
500 static inline void UNIXFS_seconds_since_1970_to_dos_date_time(
501 time_t ss1970, LPWORD pDate, LPWORD pTime)
506 RtlSecondsSince1970ToTime( ss1970, &time );
507 fileTime.dwLowDateTime = time.u.LowPart;
508 fileTime.dwHighDateTime = time.u.HighPart;
509 FileTimeToDosDateTime(&fileTime, pDate, pTime);
512 /******************************************************************************
513 * UNIXFS_build_shitemid [Internal]
515 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
519 * pszUnixPath [I] An absolute path. The SHITEMID will be build for the last component.
520 * pIDL [O] SHITEMID will be constructed here.
523 * Success: A pointer to the terminating '\0' character of path.
527 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
528 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
531 static char* UNIXFS_build_shitemid(char *pszUnixPath, void *pIDL) {
533 struct stat fileStat;
534 char *pszComponentU, *pszComponentA;
535 WCHAR *pwszComponentW;
536 int cComponentULen, cComponentALen;
538 FileStructW *pFileStructW;
539 WORD uOffsetW, *pOffsetW;
541 TRACE("(pszUnixPath=%s, pIDL=%p)\n", debugstr_a(pszUnixPath), pIDL);
543 /* We are only interested in regular files and directories. */
544 if (stat(pszUnixPath, &fileStat)) return NULL;
545 if (!S_ISDIR(fileStat.st_mode) && !S_ISREG(fileStat.st_mode)) return NULL;
547 /* Compute the SHITEMID's length and wipe it. */
548 pszComponentU = strrchr(pszUnixPath, '/') + 1;
549 cComponentULen = strlen(pszComponentU);
550 cbLen = UNIXFS_shitemid_len_from_filename(pszComponentU, &pszComponentA, &pwszComponentW);
551 if (!cbLen) return NULL;
552 memset(pIDL, 0, cbLen);
553 ((LPSHITEMID)pIDL)->cb = cbLen;
555 /* Set shell32's standard SHITEMID data fields. */
556 pIDLData = _ILGetDataPointer((LPCITEMIDLIST)pIDL);
557 pIDLData->type = S_ISDIR(fileStat.st_mode) ? PT_FOLDER : PT_VALUE;
558 pIDLData->u.file.dwFileSize = (DWORD)fileStat.st_size;
559 UNIXFS_seconds_since_1970_to_dos_date_time(fileStat.st_mtime, &pIDLData->u.file.uFileDate,
560 &pIDLData->u.file.uFileTime);
561 pIDLData->u.file.uFileAttribs = 0;
562 if (S_ISDIR(fileStat.st_mode)) pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
563 if (pszComponentU[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
564 cComponentALen = lstrlenA(pszComponentA) + 1;
565 memcpy(pIDLData->u.file.szNames, pszComponentA, cComponentALen);
567 pFileStructW = (FileStructW*)(pIDLData->u.file.szNames + cComponentALen + (cComponentALen & 0x1));
568 uOffsetW = (WORD)(((LPBYTE)pFileStructW) - ((LPBYTE)pIDL));
569 pFileStructW->cbLen = cbLen - uOffsetW;
570 UNIXFS_seconds_since_1970_to_dos_date_time(fileStat.st_mtime, &pFileStructW->uCreationDate,
571 &pFileStructW->uCreationTime);
572 UNIXFS_seconds_since_1970_to_dos_date_time(fileStat.st_atime, &pFileStructW->uLastAccessDate,
573 &pFileStructW->uLastAccessTime);
574 lstrcpyW(pFileStructW->wszName, pwszComponentW);
576 pOffsetW = (WORD*)(((LPBYTE)pIDL) + cbLen - sizeof(WORD));
577 *pOffsetW = uOffsetW;
579 SHFree(pszComponentA);
580 SHFree(pwszComponentW);
582 return pszComponentU + cComponentULen;
585 /******************************************************************************
586 * UNIXFS_path_to_pidl [Internal]
589 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
590 * path [I] An absolute unix or dos path or a path relativ to pUnixFolder
591 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
595 * Failure: FALSE, invalid params or out of memory
598 * pUnixFolder also carries the information if the path is expected to be unix or dos.
600 static BOOL UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, const WCHAR *path, LPITEMIDLIST *ppidl) {
602 int cPidlLen, cPathLen;
603 char *pSlash, *pNextSlash, szCompletePath[FILENAME_MAX], *pNextPathElement, *pszAPath;
606 TRACE("pUnixFolder=%p, path=%s, ppidl=%p\n", pUnixFolder, debugstr_w(path), ppidl);
611 /* Build an absolute path and let pNextPathElement point to the interesting
612 * relative sub-path. We need the absolute path to call 'stat', but the pidl
613 * will only contain the relative part.
615 if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
617 /* Absolute dos path. Convert to unix */
618 if (!UNIXFS_get_unix_path(path, szCompletePath))
620 pNextPathElement = szCompletePath;
622 else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
624 /* Absolute unix path. Just convert to ANSI. */
625 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
626 pNextPathElement = szCompletePath;
630 /* Relative dos or unix path. Concat with this folder's path */
631 int cBasePathLen = strlen(pUnixFolder->m_pszPath);
632 memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
633 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath + cBasePathLen,
634 FILENAME_MAX - cBasePathLen, NULL, NULL);
635 pNextPathElement = szCompletePath + cBasePathLen - 1;
637 /* If in dos mode, replace '\' with '/' */
638 if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
639 char *pBackslash = strchr(pNextPathElement, '\\');
642 pBackslash = strchr(pBackslash, '\\');
647 /* Special case for the root folder. */
648 if (!strcmp(szCompletePath, "/")) {
649 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(sizeof(USHORT));
650 if (!pidl) return FALSE;
651 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
655 /* Remove trailing slash, if present */
656 cPathLen = strlen(szCompletePath);
657 if (szCompletePath[cPathLen-1] == '/')
658 szCompletePath[cPathLen-1] = '\0';
660 if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
661 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
665 /* At this point, we have an absolute unix path in szCompletePath
666 * and the relative portion of it in pNextPathElement. Both starting with '/'
667 * and _not_ terminated by a '/'. */
668 TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
670 /* Convert to CP_ACP and WCHAR */
671 if (!UNIXFS_shitemid_len_from_filename(pNextPathElement, &pszAPath, &pwszPath))
674 /* Compute the length of the complete ITEMIDLIST */
678 pNextSlash = strchr(pSlash+1, '/');
679 cPidlLen += LEN_SHITEMID_FIXED_PART + /* Fixed part length plus potential alignment byte. */
680 (pNextSlash ? (pNextSlash - pSlash) & 0x1 : lstrlenA(pSlash) & 0x1);
684 /* The USHORT is for the ITEMIDLIST terminator. The NUL terminators for the sub-path-strings
685 * are accounted for by the '/' separators, which are not stored in the SHITEMIDs. Above we
686 * have ensured that the number of '/'s exactly matches the number of sub-path-strings. */
687 cPidlLen += lstrlenA(pszAPath) + lstrlenW(pwszPath) * sizeof(WCHAR) + sizeof(USHORT);
692 *ppidl = pidl = (LPITEMIDLIST)SHAlloc(cPidlLen);
693 if (!pidl) return FALSE;
695 /* Concatenate the SHITEMIDs of the sub-directories. */
696 while (*pNextPathElement) {
697 pSlash = strchr(pNextPathElement+1, '/');
698 if (pSlash) *pSlash = '\0';
699 pNextPathElement = UNIXFS_build_shitemid(szCompletePath, pidl);
700 if (pSlash) *pSlash = '/';
702 if (!pNextPathElement) {
706 pidl = ILGetNext(pidl);
708 pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
710 if ((char *)pidl-(char *)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
711 ERR("Computed length of pidl incorrect. Please report.\n");
716 /******************************************************************************
717 * UNIXFS_initialize_target_folder [Internal]
719 * Initialize the m_pszPath member of an UnixFolder, given an absolute unix
720 * base path and a relative ITEMIDLIST. Leave the m_pidlLocation member, which
721 * specifies the location in the shell namespace alone.
724 * This [IO] The UnixFolder, whose target path is to be initialized
725 * szBasePath [I] The absolute base path
726 * pidlSubFolder [I] Relative part of the path, given as an ITEMIDLIST
727 * dwAttributes [I] Attributes to add to the Folders m_dwAttributes member
728 * (Used to pass the SFGAO_FILESYSTEM flag down the path)
733 static HRESULT UNIXFS_initialize_target_folder(UnixFolder *This, const char *szBasePath,
734 LPCITEMIDLIST pidlSubFolder, DWORD dwAttributes)
736 LPCITEMIDLIST current = pidlSubFolder;
737 DWORD dwPathLen = strlen(szBasePath)+1;
738 struct stat statPrefix;
741 /* Determine the path's length bytes */
742 while (current && current->mkid.cb) {
743 dwPathLen += UNIXFS_filename_from_shitemid(current, NULL) + 1; /* For the '/' */
744 current = ILGetNext(current);
747 /* Build the path and compute the attributes*/
748 This->m_dwAttributes =
749 dwAttributes|SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
750 This->m_pszPath = pNextDir = SHAlloc(dwPathLen);
751 if (!This->m_pszPath) {
752 WARN("SHAlloc failed!\n");
755 current = pidlSubFolder;
756 strcpy(pNextDir, szBasePath);
757 pNextDir += strlen(szBasePath);
758 if (This->m_dwPathMode == PATHMODE_UNIX || IsEqualCLSID(&CLSID_MyDocuments, This->m_pCLSID))
759 This->m_dwAttributes |= SFGAO_FILESYSTEM;
760 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
762 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
763 This->m_dwAttributes |= SFGAO_FILESYSTEM;
765 while (current && current->mkid.cb) {
766 pNextDir += UNIXFS_filename_from_shitemid(current, pNextDir);
767 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
769 if (!stat(This->m_pszPath, &statPrefix) && UNIXFS_is_dos_device(&statPrefix))
770 This->m_dwAttributes |= SFGAO_FILESYSTEM;
773 current = ILGetNext(current);
780 /******************************************************************************
783 * Class whose heap based instances represent unix filesystem directories.
786 static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
787 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
789 SHFree(pUnixFolder->m_pszPath);
790 ILFree(pUnixFolder->m_pidlLocation);
794 static HRESULT WINAPI UnixFolder_IShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
797 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
799 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
801 if (!ppv) return E_INVALIDARG;
803 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellFolder, riid) ||
804 IsEqualIID(&IID_IShellFolder2, riid))
806 *ppv = STATIC_CAST(IShellFolder2, This);
807 } else if (IsEqualIID(&IID_IPersistFolder3, riid) || IsEqualIID(&IID_IPersistFolder2, riid) ||
808 IsEqualIID(&IID_IPersistFolder, riid) || IsEqualIID(&IID_IPersist, riid))
810 *ppv = STATIC_CAST(IPersistFolder3, This);
811 } else if (IsEqualIID(&IID_IPersistPropertyBag, riid)) {
812 *ppv = STATIC_CAST(IPersistPropertyBag, This);
813 } else if (IsEqualIID(&IID_ISFHelper, riid)) {
814 *ppv = STATIC_CAST(ISFHelper, This);
815 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
816 *ppv = STATIC_CAST(IDropTarget, This);
818 cfShellIDList = RegisterClipboardFormatA(CFSTR_SHELLIDLIST);
821 return E_NOINTERFACE;
824 IUnknown_AddRef((IUnknown*)*ppv);
828 static ULONG WINAPI UnixFolder_IShellFolder2_AddRef(IShellFolder2 *iface) {
829 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
831 TRACE("(iface=%p)\n", iface);
833 return InterlockedIncrement(&This->m_cRef);
836 static ULONG WINAPI UnixFolder_IShellFolder2_Release(IShellFolder2 *iface) {
837 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
840 TRACE("(iface=%p)\n", iface);
842 cRef = InterlockedDecrement(&This->m_cRef);
845 UnixFolder_Destroy(This);
850 static HRESULT WINAPI UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
851 LPBC pbcReserved, LPOLESTR lpszDisplayName, ULONG* pchEaten, LPITEMIDLIST* ppidl,
852 ULONG* pdwAttributes)
854 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
857 TRACE("(iface=%p, hwndOwner=%p, pbcReserved=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
858 "pdwAttributes=%p) stub\n", iface, hwndOwner, pbcReserved, debugstr_w(lpszDisplayName),
859 pchEaten, ppidl, pdwAttributes);
861 result = UNIXFS_path_to_pidl(This, lpszDisplayName, ppidl);
862 if (result && pdwAttributes && *pdwAttributes)
864 IShellFolder *pParentSF;
865 LPCITEMIDLIST pidlLast;
866 LPITEMIDLIST pidlComplete = ILCombine(This->m_pidlLocation, *ppidl);
869 hr = SHBindToParent(pidlComplete, &IID_IShellFolder, (LPVOID*)&pParentSF, &pidlLast);
871 FIXME("SHBindToParent failed! hr = %08lx\n", hr);
872 ILFree(pidlComplete);
875 IShellFolder_GetAttributesOf(pParentSF, 1, &pidlLast, pdwAttributes);
876 IShellFolder_Release(pParentSF);
877 ILFree(pidlComplete);
880 if (!result) TRACE("FAILED!\n");
881 return result ? S_OK : E_FAIL;
884 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter);
886 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
887 SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
889 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
890 IUnknown *newIterator;
893 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08lx, ppEnumIDList=%p)\n",
894 iface, hwndOwner, grfFlags, ppEnumIDList);
896 if (!This->m_pszPath) {
897 WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
901 newIterator = UnixSubFolderIterator_Constructor(This, grfFlags);
902 hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
903 IUnknown_Release(newIterator);
908 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID);
910 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
911 LPBC pbcReserved, REFIID riid, void** ppvOut)
913 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
914 IPersistFolder3 *persistFolder;
916 const CLSID *clsidChild;
918 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
919 iface, pidl, pbcReserved, riid, ppvOut);
921 if (!pidl || !pidl->mkid.cb)
924 if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
925 /* Children of FolderShortcuts are ShellFSFolders on Windows.
926 * Unixfs' counterpart is UnixDosFolder. */
927 clsidChild = &CLSID_UnixDosFolder;
929 clsidChild = This->m_pCLSID;
932 hr = CreateUnixFolder(NULL, &IID_IPersistFolder3, (void**)&persistFolder, clsidChild);
933 if (!SUCCEEDED(hr)) return hr;
934 hr = IPersistFolder_QueryInterface(persistFolder, riid, (void**)ppvOut);
937 UnixFolder *subfolder = ADJUST_THIS(UnixFolder, IPersistFolder3, persistFolder);
938 subfolder->m_pidlLocation = ILCombine(This->m_pidlLocation, pidl);
939 hr = UNIXFS_initialize_target_folder(subfolder, This->m_pszPath, pidl,
940 This->m_dwAttributes & SFGAO_FILESYSTEM);
943 IPersistFolder3_Release(persistFolder);
948 static HRESULT WINAPI UnixFolder_IShellFolder2_BindToStorage(IShellFolder2* This, LPCITEMIDLIST pidl,
949 LPBC pbcReserved, REFIID riid, void** ppvObj)
955 static HRESULT WINAPI UnixFolder_IShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
956 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
958 BOOL isEmpty1, isEmpty2;
960 LPITEMIDLIST firstpidl;
964 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface, lParam, pidl1, pidl2);
966 isEmpty1 = !pidl1 || !pidl1->mkid.cb;
967 isEmpty2 = !pidl2 || !pidl2->mkid.cb;
969 if (isEmpty1 && isEmpty2)
970 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
972 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
974 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
976 if (_ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
977 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
978 if (!_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
979 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
981 compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
982 _ILGetTextPointer(pidl1), -1,
983 _ILGetTextPointer(pidl2), -1);
985 if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
986 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
988 if (pidl1->mkid.cb < pidl2->mkid.cb)
989 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
990 else if (pidl1->mkid.cb > pidl2->mkid.cb)
991 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
993 firstpidl = ILCloneFirst(pidl1);
994 pidl1 = ILGetNext(pidl1);
995 pidl2 = ILGetNext(pidl2);
997 hr = IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID*)&psf);
999 hr = IShellFolder_CompareIDs(psf, lParam, pidl1, pidl2);
1000 IShellFolder2_Release(psf);
1007 static HRESULT WINAPI UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
1008 REFIID riid, void** ppv)
1010 HRESULT hr = E_INVALIDARG;
1012 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface, hwndOwner, riid, ppv);
1014 if (!ppv) return E_INVALIDARG;
1017 if (IsEqualIID(&IID_IShellView, riid)) {
1018 LPSHELLVIEW pShellView;
1020 pShellView = IShellView_Constructor((IShellFolder*)iface);
1022 hr = IShellView_QueryInterface(pShellView, riid, ppv);
1023 IShellView_Release(pShellView);
1025 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
1026 hr = IShellFolder2_QueryInterface(iface, &IID_IDropTarget, ppv);
1032 static HRESULT WINAPI UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
1033 LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
1035 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1038 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface, cidl, apidl, rgfInOut);
1040 if (!rgfInOut || (cidl && !apidl))
1041 return E_INVALIDARG;
1044 *rgfInOut &= This->m_dwAttributes;
1046 char szAbsolutePath[FILENAME_MAX], *pszRelativePath;
1049 *rgfInOut = SFGAO_CANCOPY|SFGAO_CANMOVE|SFGAO_CANLINK|SFGAO_CANRENAME|SFGAO_CANDELETE|
1050 SFGAO_HASPROPSHEET|SFGAO_DROPTARGET|SFGAO_FILESYSTEM;
1051 lstrcpyA(szAbsolutePath, This->m_pszPath);
1052 pszRelativePath = szAbsolutePath + lstrlenA(szAbsolutePath);
1053 for (i=0; i<cidl; i++) {
1054 if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
1055 struct stat fileStat;
1056 if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelativePath))
1057 return E_INVALIDARG;
1058 if (stat(szAbsolutePath, &fileStat) || !UNIXFS_is_dos_device(&fileStat))
1059 *rgfInOut &= ~SFGAO_FILESYSTEM;
1061 if (_ILIsFolder(apidl[i]))
1062 *rgfInOut |= SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
1069 static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
1070 UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
1072 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1075 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
1076 iface, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
1078 if (!cidl || !apidl || !riid || !ppvOut)
1079 return E_INVALIDARG;
1081 for (i=0; i<cidl; i++)
1083 return E_INVALIDARG;
1085 if (IsEqualIID(&IID_IContextMenu, riid)) {
1086 *ppvOut = ISvItemCm_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl);
1088 } else if (IsEqualIID(&IID_IDataObject, riid)) {
1089 *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
1091 } else if (IsEqualIID(&IID_IExtractIconA, riid)) {
1093 if (cidl != 1) return E_INVALIDARG;
1094 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
1095 *ppvOut = (LPVOID)IExtractIconA_Constructor(pidl);
1098 } else if (IsEqualIID(&IID_IExtractIconW, riid)) {
1100 if (cidl != 1) return E_INVALIDARG;
1101 pidl = ILCombine(This->m_pidlLocation, apidl[0]);
1102 *ppvOut = (LPVOID)IExtractIconW_Constructor(pidl);
1105 } else if (IsEqualIID(&IID_IDropTarget, riid)) {
1106 if (cidl != 1) return E_INVALIDARG;
1107 return IShellFolder2_BindToObject(iface, apidl[0], NULL, &IID_IDropTarget, ppvOut);
1108 } else if (IsEqualIID(&IID_IShellLinkW, riid)) {
1109 FIXME("IShellLinkW\n");
1111 } else if (IsEqualIID(&IID_IShellLinkA, riid)) {
1112 FIXME("IShellLinkA\n");
1115 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
1116 return E_NOINTERFACE;
1120 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
1121 LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
1123 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1126 TRACE("(iface=%p, pidl=%p, uFlags=%lx, lpName=%p)\n", iface, pidl, uFlags, lpName);
1128 if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
1129 (GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
1131 if (!pidl || !pidl->mkid.cb) {
1132 lpName->uType = STRRET_WSTR;
1133 if (This->m_dwPathMode == PATHMODE_UNIX) {
1134 UINT len = MultiByteToWideChar(CP_UNIXCP, 0, This->m_pszPath, -1, NULL, 0);
1135 lpName->u.pOleStr = SHAlloc(len * sizeof(WCHAR));
1136 if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
1137 MultiByteToWideChar(CP_UNIXCP, 0, This->m_pszPath, -1, lpName->u.pOleStr, len);
1139 LPWSTR pwszDosFileName = wine_get_dos_file_name(This->m_pszPath);
1140 if (!pwszDosFileName) return HRESULT_FROM_WIN32(GetLastError());
1141 lpName->u.pOleStr = SHAlloc((lstrlenW(pwszDosFileName) + 1) * sizeof(WCHAR));
1142 if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
1143 lstrcpyW(lpName->u.pOleStr, pwszDosFileName);
1144 PathRemoveBackslashW(lpName->u.pOleStr);
1145 HeapFree(GetProcessHeap(), 0, pwszDosFileName);
1148 IShellFolder *pSubFolder;
1149 SHITEMID emptyIDL = { 0, { 0 } };
1151 hr = IShellFolder_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
1152 if (!SUCCEEDED(hr)) return hr;
1154 hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
1155 IShellFolder_Release(pSubFolder);
1158 WCHAR wszFileName[MAX_PATH];
1159 if (!_ILSimpleGetTextW(pidl, wszFileName, MAX_PATH)) return E_INVALIDARG;
1160 lpName->uType = STRRET_WSTR;
1161 lpName->u.pOleStr = SHAlloc((lstrlenW(wszFileName)+1)*sizeof(WCHAR));
1162 if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
1163 lstrcpyW(lpName->u.pOleStr, wszFileName);
1164 if (!(GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) && This->m_dwPathMode == PATHMODE_DOS &&
1165 !_ILIsFolder(pidl) && wszFileName[0] != '.' && SHELL_FS_HideExtension(wszFileName))
1167 PathRemoveExtensionW(lpName->u.pOleStr);
1171 TRACE("--> %s\n", debugstr_w(lpName->u.pOleStr));
1176 static HRESULT WINAPI UnixFolder_IShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd,
1177 LPCITEMIDLIST pidl, LPCOLESTR lpcwszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
1179 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1181 static const WCHAR awcInvalidChars[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
1182 char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
1183 WCHAR wszSrcRelative[MAX_PATH];
1184 int cBasePathLen = lstrlenA(This->m_pszPath), i;
1185 struct stat statDest;
1186 LPITEMIDLIST pidlSrc, pidlDest, pidlRelativeDest;
1190 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpcwszName=%s, uFlags=0x%08lx, ppidlOut=%p)\n",
1191 iface, hwnd, pidl, debugstr_w(lpcwszName), uFlags, ppidlOut);
1193 /* prepare to fail */
1197 /* pidl has to contain a single non-empty SHITEMID */
1198 if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
1199 return E_INVALIDARG;
1201 /* check for invalid characters in lpcwszName. */
1202 for (i=0; i < sizeof(awcInvalidChars)/sizeof(*awcInvalidChars); i++)
1203 if (StrChrW(lpcwszName, awcInvalidChars[i]))
1204 return HRESULT_FROM_WIN32(ERROR_CANCELLED);
1206 /* build source path */
1207 memcpy(szSrc, This->m_pszPath, cBasePathLen);
1208 UNIXFS_filename_from_shitemid(pidl, szSrc + cBasePathLen);
1210 /* build destination path */
1211 memcpy(szDest, This->m_pszPath, cBasePathLen);
1212 WideCharToMultiByte(CP_UNIXCP, 0, lpcwszName, -1, szDest+cBasePathLen,
1213 FILENAME_MAX-cBasePathLen, NULL, NULL);
1215 /* If the filename's extension is hidden to the user, we have to append it. */
1216 if (!(uFlags & SHGDN_FORPARSING) &&
1217 _ILSimpleGetTextW(pidl, wszSrcRelative, MAX_PATH) &&
1218 SHELL_FS_HideExtension(wszSrcRelative))
1220 WCHAR *pwszExt = PathFindExtensionW(wszSrcRelative);
1221 int cLenDest = strlen(szDest);
1222 WideCharToMultiByte(CP_UNIXCP, 0, pwszExt, -1, szDest + cLenDest,
1223 FILENAME_MAX - cLenDest, NULL, NULL);
1226 TRACE("src=%s dest=%s\n", szSrc, szDest);
1228 /* Fail, if destination does already exist */
1229 if (!stat(szDest, &statDest))
1232 /* Rename the file */
1233 if (rename(szSrc, szDest))
1236 /* Build a pidl for the path of the renamed file */
1237 lpwszName = SHAlloc((lstrlenW(lpcwszName)+1)*sizeof(WCHAR)); /* due to const correctness. */
1238 lstrcpyW(lpwszName, lpcwszName);
1239 hr = IShellFolder2_ParseDisplayName(iface, NULL, NULL, lpwszName, NULL, &pidlRelativeDest, NULL);
1242 rename(szDest, szSrc); /* Undo the renaming */
1245 pidlDest = ILCombine(This->m_pidlLocation, pidlRelativeDest);
1246 ILFree(pidlRelativeDest);
1247 pidlSrc = ILCombine(This->m_pidlLocation, pidl);
1249 /* Inform the shell */
1250 if (_ILIsFolder(ILFindLastID(pidlDest)))
1251 SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
1253 SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
1256 *ppidlOut = ILClone(ILFindLastID(pidlDest));
1264 static HRESULT WINAPI UnixFolder_IShellFolder2_EnumSearches(IShellFolder2* iface,
1265 IEnumExtraSearch **ppEnum)
1271 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2* iface,
1272 DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
1278 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
1279 UINT iColumn, SHCOLSTATEF *pcsFlags)
1285 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
1292 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2* iface,
1293 LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
1299 #define SHELLVIEWCOLUMNS 7
1301 static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface,
1302 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
1304 UnixFolder *This = ADJUST_THIS(UnixFolder, IShellFolder2, iface);
1305 HRESULT hr = E_FAIL;
1306 struct passwd *pPasswd;
1307 struct group *pGroup;
1308 static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
1309 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
1310 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1311 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
1312 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
1313 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 9},
1314 {IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
1315 {IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7}
1318 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface, pidl, iColumn, psd);
1320 if (!psd || iColumn >= SHELLVIEWCOLUMNS)
1321 return E_INVALIDARG;
1324 psd->fmt = SFHeader[iColumn].fmt;
1325 psd->cxChar = SFHeader[iColumn].cxChar;
1326 psd->str.uType = STRRET_CSTR;
1327 LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
1330 struct stat statItem;
1331 if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
1332 char szPath[FILENAME_MAX];
1333 strcpy(szPath, This->m_pszPath);
1334 if (!UNIXFS_filename_from_shitemid(pidl, szPath + strlen(szPath)))
1335 return E_INVALIDARG;
1336 if (stat(szPath, &statItem))
1337 return E_INVALIDARG;
1339 psd->str.u.cStr[0] = '\0';
1340 psd->str.uType = STRRET_CSTR;
1343 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
1346 _ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
1349 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1352 _ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
1355 psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
1356 psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
1357 psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
1358 psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
1359 psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
1360 psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
1361 psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
1362 psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
1363 psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
1364 psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
1365 psd->str.u.cStr[10] = '\0';
1368 pPasswd = getpwuid(statItem.st_uid);
1369 if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
1372 pGroup = getgrgid(statItem.st_gid);
1373 if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
1381 static HRESULT WINAPI UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT iColumn,
1388 /* VTable for UnixFolder's IShellFolder2 interface.
1390 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl = {
1391 UnixFolder_IShellFolder2_QueryInterface,
1392 UnixFolder_IShellFolder2_AddRef,
1393 UnixFolder_IShellFolder2_Release,
1394 UnixFolder_IShellFolder2_ParseDisplayName,
1395 UnixFolder_IShellFolder2_EnumObjects,
1396 UnixFolder_IShellFolder2_BindToObject,
1397 UnixFolder_IShellFolder2_BindToStorage,
1398 UnixFolder_IShellFolder2_CompareIDs,
1399 UnixFolder_IShellFolder2_CreateViewObject,
1400 UnixFolder_IShellFolder2_GetAttributesOf,
1401 UnixFolder_IShellFolder2_GetUIObjectOf,
1402 UnixFolder_IShellFolder2_GetDisplayNameOf,
1403 UnixFolder_IShellFolder2_SetNameOf,
1404 UnixFolder_IShellFolder2_GetDefaultSearchGUID,
1405 UnixFolder_IShellFolder2_EnumSearches,
1406 UnixFolder_IShellFolder2_GetDefaultColumn,
1407 UnixFolder_IShellFolder2_GetDefaultColumnState,
1408 UnixFolder_IShellFolder2_GetDetailsEx,
1409 UnixFolder_IShellFolder2_GetDetailsOf,
1410 UnixFolder_IShellFolder2_MapColumnToSCID
1413 static HRESULT WINAPI UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3* iface, REFIID riid,
1416 return UnixFolder_IShellFolder2_QueryInterface(
1417 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)), riid, ppvObject);
1420 static ULONG WINAPI UnixFolder_IPersistFolder3_AddRef(IPersistFolder3* iface)
1422 return UnixFolder_IShellFolder2_AddRef(
1423 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)));
1426 static ULONG WINAPI UnixFolder_IPersistFolder3_Release(IPersistFolder3* iface)
1428 return UnixFolder_IShellFolder2_Release(
1429 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistFolder3, iface)));
1432 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3* iface, CLSID* pClassID)
1434 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1436 TRACE("(iface=%p, pClassId=%p)\n", iface, pClassID);
1439 return E_INVALIDARG;
1441 memcpy(pClassID, This->m_pCLSID, sizeof(CLSID));
1445 static HRESULT WINAPI UnixFolder_IPersistFolder3_Initialize(IPersistFolder3* iface, LPCITEMIDLIST pidl)
1447 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1448 LPCITEMIDLIST current = pidl;
1449 char szBasePath[FILENAME_MAX] = "/";
1451 TRACE("(iface=%p, pidl=%p)\n", iface, pidl);
1453 /* Find the UnixFolderClass root */
1454 while (current->mkid.cb) {
1455 if ((_ILIsDrive(current) && IsEqualCLSID(This->m_pCLSID, &CLSID_ShellFSFolder)) ||
1456 (_ILIsSpecialFolder(current) && IsEqualCLSID(This->m_pCLSID, _ILGetGUIDPointer(current))))
1460 current = ILGetNext(current);
1463 if (current && current->mkid.cb) {
1464 if (_ILIsDrive(current)) {
1465 WCHAR wszDrive[4] = { '?', ':', '\\', 0 };
1466 wszDrive[0] = (WCHAR)*_ILGetTextPointer(current);
1467 if (!UNIXFS_get_unix_path(wszDrive, szBasePath))
1469 } else if (IsEqualIID(&CLSID_MyDocuments, _ILGetGUIDPointer(current))) {
1470 WCHAR wszMyDocumentsPath[MAX_PATH];
1471 if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath, CSIDL_PERSONAL, FALSE))
1473 PathAddBackslashW(wszMyDocumentsPath);
1474 if (!UNIXFS_get_unix_path(wszMyDocumentsPath, szBasePath))
1477 current = ILGetNext(current);
1478 } else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
1479 /* Path rooted at Desktop */
1480 WCHAR wszDesktopPath[MAX_PATH];
1481 if (!SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE))
1483 PathAddBackslashW(wszDesktopPath);
1484 if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
1487 } else if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
1488 /* FolderShortcuts' Initialize method only sets the ITEMIDLIST, which
1489 * specifies the location in the shell namespace, but leaves the
1490 * target folder (m_pszPath) alone. See unit tests in tests/shlfolder.c */
1491 This->m_pidlLocation = ILClone(pidl);
1494 ERR("Unknown pidl type!\n");
1496 return E_INVALIDARG;
1499 This->m_pidlLocation = ILClone(pidl);
1500 return UNIXFS_initialize_target_folder(This, szBasePath, current, 0);
1503 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3* iface, LPITEMIDLIST* ppidl)
1505 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1507 TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
1511 *ppidl = ILClone (This->m_pidlLocation);
1515 static HRESULT WINAPI UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3 *iface, IBindCtx *pbc,
1516 LPCITEMIDLIST pidlRoot, const PERSIST_FOLDER_TARGET_INFO *ppfti)
1518 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistFolder3, iface);
1519 WCHAR wszTargetDosPath[MAX_PATH];
1520 char szTargetPath[FILENAME_MAX] = "";
1522 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface, pbc, pidlRoot, ppfti);
1524 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1526 return IPersistFolder3_Initialize(iface, pidlRoot);
1528 if (ppfti->csidl != -1) {
1529 if (FAILED(SHGetFolderPathW(0, ppfti->csidl, NULL, 0, wszTargetDosPath)) ||
1530 !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1534 } else if (*ppfti->szTargetParsingName) {
1535 lstrcpyW(wszTargetDosPath, ppfti->szTargetParsingName);
1536 PathAddBackslashW(wszTargetDosPath);
1537 if (!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath)) {
1540 } else if (ppfti->pidlTargetFolder) {
1541 if (!SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTargetDosPath) ||
1542 !UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
1550 This->m_pszPath = SHAlloc(lstrlenA(szTargetPath)+1);
1551 if (!This->m_pszPath)
1553 lstrcpyA(This->m_pszPath, szTargetPath);
1554 This->m_pidlLocation = ILClone(pidlRoot);
1555 This->m_dwAttributes = (ppfti->dwAttributes != -1) ? ppfti->dwAttributes :
1556 (SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|SFGAO_FILESYSTEM);
1561 static HRESULT WINAPI UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3 *iface,
1562 PERSIST_FOLDER_TARGET_INFO *ppfti)
1564 FIXME("(iface=%p, ppfti=%p) stub\n", iface, ppfti);
1568 /* VTable for UnixFolder's IPersistFolder interface.
1570 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl = {
1571 UnixFolder_IPersistFolder3_QueryInterface,
1572 UnixFolder_IPersistFolder3_AddRef,
1573 UnixFolder_IPersistFolder3_Release,
1574 UnixFolder_IPersistFolder3_GetClassID,
1575 UnixFolder_IPersistFolder3_Initialize,
1576 UnixFolder_IPersistFolder3_GetCurFolder,
1577 UnixFolder_IPersistFolder3_InitializeEx,
1578 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1581 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag* iface,
1582 REFIID riid, void** ppv)
1584 return UnixFolder_IShellFolder2_QueryInterface(
1585 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)), riid, ppv);
1588 static ULONG WINAPI UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag* iface)
1590 return UnixFolder_IShellFolder2_AddRef(
1591 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)));
1594 static ULONG WINAPI UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag* iface)
1596 return UnixFolder_IShellFolder2_Release(
1597 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)));
1600 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag* iface,
1603 return UnixFolder_IPersistFolder3_GetClassID(
1604 STATIC_CAST(IPersistFolder3, ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface)), pClassID);
1607 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag* iface)
1613 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag *iface,
1614 IPropertyBag *pPropertyBag, IErrorLog *pErrorLog)
1616 UnixFolder *This = ADJUST_THIS(UnixFolder, IPersistPropertyBag, iface);
1617 static const WCHAR wszTarget[] = { 'T','a','r','g','e','t', 0 }, wszNull[] = { 0 };
1618 PERSIST_FOLDER_TARGET_INFO pftiTarget;
1622 TRACE("(iface=%p, pPropertyBag=%p, pErrorLog=%p)\n", iface, pPropertyBag, pErrorLog);
1627 /* Get 'Target' property from the property bag. */
1628 V_VT(&var) = VT_BSTR;
1629 hr = IPropertyBag_Read(pPropertyBag, wszTarget, &var, NULL);
1632 lstrcpyW(pftiTarget.szTargetParsingName, V_BSTR(&var));
1633 SysFreeString(V_BSTR(&var));
1635 pftiTarget.pidlTargetFolder = NULL;
1636 lstrcpyW(pftiTarget.szNetworkProvider, wszNull);
1637 pftiTarget.dwAttributes = -1;
1638 pftiTarget.csidl = -1;
1640 return UnixFolder_IPersistFolder3_InitializeEx(
1641 STATIC_CAST(IPersistFolder3, This), NULL, NULL, &pftiTarget);
1644 static HRESULT WINAPI UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag *iface,
1645 IPropertyBag *pPropertyBag, BOOL fClearDirty, BOOL fSaveAllProperties)
1651 /* VTable for UnixFolder's IPersistPropertyBag interface.
1653 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl = {
1654 UnixFolder_IPersistPropertyBag_QueryInterface,
1655 UnixFolder_IPersistPropertyBag_AddRef,
1656 UnixFolder_IPersistPropertyBag_Release,
1657 UnixFolder_IPersistPropertyBag_GetClassID,
1658 UnixFolder_IPersistPropertyBag_InitNew,
1659 UnixFolder_IPersistPropertyBag_Load,
1660 UnixFolder_IPersistPropertyBag_Save
1663 static HRESULT WINAPI UnixFolder_ISFHelper_QueryInterface(ISFHelper* iface, REFIID riid,
1666 return UnixFolder_IShellFolder2_QueryInterface(
1667 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)), riid, ppvObject);
1670 static ULONG WINAPI UnixFolder_ISFHelper_AddRef(ISFHelper* iface)
1672 return UnixFolder_IShellFolder2_AddRef(
1673 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)));
1676 static ULONG WINAPI UnixFolder_ISFHelper_Release(ISFHelper* iface)
1678 return UnixFolder_IShellFolder2_Release(
1679 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, ISFHelper, iface)));
1682 static HRESULT WINAPI UnixFolder_ISFHelper_GetUniqueName(ISFHelper* iface, LPSTR lpName, UINT uLen)
1684 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1687 LPITEMIDLIST pidlElem;
1690 static const char szNewFolder[] = "New Folder";
1692 TRACE("(iface=%p, lpName=%p, uLen=%u)\n", iface, lpName, uLen);
1694 if (uLen < sizeof(szNewFolder)+3)
1695 return E_INVALIDARG;
1697 hr = IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2, This), 0,
1698 SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
1699 if (SUCCEEDED(hr)) {
1700 lstrcpyA(lpName, szNewFolder);
1701 IEnumIDList_Reset(pEnum);
1703 while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
1704 if (!strcasecmp(_ILGetTextPointer(pidlElem), lpName)) {
1705 IEnumIDList_Reset(pEnum);
1706 sprintf(lpName, "%s %d", szNewFolder, i++);
1713 IEnumIDList_Release(pEnum);
1718 static HRESULT WINAPI UnixFolder_ISFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCSTR pszName,
1719 LPITEMIDLIST* ppidlOut)
1721 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1722 char szNewDir[FILENAME_MAX];
1724 TRACE("(iface=%p, hwnd=%p, pszName=%s, ppidlOut=%p)\n", iface, hwnd, pszName, ppidlOut);
1729 lstrcpyA(szNewDir, This->m_pszPath);
1730 lstrcatA(szNewDir, pszName);
1732 if (mkdir(szNewDir, 0755)) {
1733 char szMessage[256 + FILENAME_MAX];
1734 char szCaption[256];
1736 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
1737 sprintf(szMessage, szCaption, szNewDir);
1738 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
1739 MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
1743 LPITEMIDLIST pidlRelative;
1744 WCHAR wszName[MAX_PATH];
1746 /* Inform the shell */
1747 MultiByteToWideChar(CP_UNIXCP, 0, pszName, -1, wszName, MAX_PATH);
1748 if (UNIXFS_path_to_pidl(This, wszName, &pidlRelative)) {
1749 LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
1751 *ppidlOut = pidlRelative;
1753 ILFree(pidlRelative);
1754 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1755 ILFree(pidlAbsolute);
1761 static HRESULT WINAPI UnixFolder_ISFHelper_DeleteItems(ISFHelper* iface, UINT cidl,
1762 LPCITEMIDLIST* apidl)
1764 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1765 char szAbsolute[FILENAME_MAX], *pszRelative;
1766 LPITEMIDLIST pidlAbsolute;
1770 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface, cidl, apidl);
1772 lstrcpyA(szAbsolute, This->m_pszPath);
1773 pszRelative = szAbsolute + lstrlenA(szAbsolute);
1775 for (i=0; i<cidl && SUCCEEDED(hr); i++) {
1776 if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
1777 return E_INVALIDARG;
1778 pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
1779 if (_ILIsFolder(apidl[i])) {
1780 if (rmdir(szAbsolute)) {
1783 SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
1785 } else if (_ILIsValue(apidl[i])) {
1786 if (unlink(szAbsolute)) {
1789 SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
1792 ILFree(pidlAbsolute);
1798 static HRESULT WINAPI UnixFolder_ISFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom,
1799 UINT cidl, LPCITEMIDLIST *apidl)
1801 UnixFolder *This = ADJUST_THIS(UnixFolder, ISFHelper, iface);
1805 char szAbsoluteDst[FILENAME_MAX], *pszRelativeDst;
1807 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p): semi-stub\n", iface, psfFrom, cidl, apidl);
1809 if (!psfFrom || !cidl || !apidl)
1810 return E_INVALIDARG;
1812 /* All source items have to be filesystem items. */
1813 dwAttributes = SFGAO_FILESYSTEM;
1814 hr = IShellFolder_GetAttributesOf(psfFrom, cidl, apidl, &dwAttributes);
1815 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM))
1816 return E_INVALIDARG;
1818 lstrcpyA(szAbsoluteDst, This->m_pszPath);
1819 pszRelativeDst = szAbsoluteDst + strlen(szAbsoluteDst);
1821 for (i=0; i<cidl; i++) {
1822 WCHAR wszSrc[MAX_PATH];
1823 char szSrc[FILENAME_MAX];
1826 /* Build the unix path of the current source item. */
1827 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom, apidl[i], SHGDN_FORPARSING, &strret)))
1829 if (FAILED(StrRetToBufW(&strret, apidl[i], wszSrc, MAX_PATH)))
1831 if (!UNIXFS_get_unix_path(wszSrc, szSrc))
1834 /* Build the unix path of the current destination item */
1835 UNIXFS_filename_from_shitemid(apidl[i], pszRelativeDst);
1837 FIXME("Would copy %s to %s. Not yet implemented.\n", szSrc, szAbsoluteDst);
1842 /* VTable for UnixFolder's ISFHelper interface
1844 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl = {
1845 UnixFolder_ISFHelper_QueryInterface,
1846 UnixFolder_ISFHelper_AddRef,
1847 UnixFolder_ISFHelper_Release,
1848 UnixFolder_ISFHelper_GetUniqueName,
1849 UnixFolder_ISFHelper_AddFolder,
1850 UnixFolder_ISFHelper_DeleteItems,
1851 UnixFolder_ISFHelper_CopyItems
1854 static HRESULT WINAPI UnixFolder_IDropTarget_QueryInterface(IDropTarget* iface, REFIID riid,
1857 return UnixFolder_IShellFolder2_QueryInterface(
1858 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)), riid, ppvObject);
1861 static ULONG WINAPI UnixFolder_IDropTarget_AddRef(IDropTarget* iface)
1863 return UnixFolder_IShellFolder2_AddRef(
1864 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)));
1867 static ULONG WINAPI UnixFolder_IDropTarget_Release(IDropTarget* iface)
1869 return UnixFolder_IShellFolder2_Release(
1870 STATIC_CAST(IShellFolder2, ADJUST_THIS(UnixFolder, IDropTarget, iface)));
1873 #define HIDA_GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
1874 #define HIDA_GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
1876 static HRESULT WINAPI UnixFolder_IDropTarget_DragEnter(IDropTarget *iface, IDataObject *pDataObject,
1877 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
1879 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1883 TRACE("(iface=%p, pDataObject=%p, dwKeyState=%08lx, pt={.x=%ld, .y=%ld}, pdwEffect=%p)\n",
1884 iface, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
1886 if (!pdwEffect || !pDataObject)
1887 return E_INVALIDARG;
1889 /* Compute a mask of supported drop-effects for this shellfolder object and the given data
1890 * object. Dropping is only supported on folders, which represent filesystem locations. One
1891 * can't drop on file objects. And the 'move' drop effect is only supported, if the source
1892 * folder is not identical to the target folder. */
1893 This->m_dwDropEffectsMask = DROPEFFECT_NONE;
1894 InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
1895 if ((This->m_dwAttributes & SFGAO_FILESYSTEM) && /* Only drop to filesystem folders */
1896 _ILIsFolder(ILFindLastID(This->m_pidlLocation)) && /* Only drop to folders, not to files */
1897 SUCCEEDED(IDataObject_GetData(pDataObject, &format, &medium))) /* Only ShellIDList format */
1899 LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
1900 This->m_dwDropEffectsMask |= DROPEFFECT_COPY|DROPEFFECT_LINK;
1902 if (pidaShellIDList) { /* Files can only be moved between two different folders */
1903 if (!ILIsEqual(HIDA_GetPIDLFolder(pidaShellIDList), This->m_pidlLocation))
1904 This->m_dwDropEffectsMask |= DROPEFFECT_MOVE;
1905 GlobalUnlock(medium.u.hGlobal);
1909 *pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
1914 static HRESULT WINAPI UnixFolder_IDropTarget_DragOver(IDropTarget *iface, DWORD dwKeyState,
1915 POINTL pt, DWORD *pdwEffect)
1917 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1919 TRACE("(iface=%p, dwKeyState=%08lx, pt={.x=%ld, .y=%ld}, pdwEffect=%p)\n", iface, dwKeyState,
1920 pt.x, pt.y, pdwEffect);
1923 return E_INVALIDARG;
1925 *pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
1930 static HRESULT WINAPI UnixFolder_IDropTarget_DragLeave(IDropTarget *iface) {
1931 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1933 TRACE("(iface=%p)\n", iface);
1935 This->m_dwDropEffectsMask = DROPEFFECT_NONE;
1940 static HRESULT WINAPI UnixFolder_IDropTarget_Drop(IDropTarget *iface, IDataObject *pDataObject,
1941 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
1943 UnixFolder *This = ADJUST_THIS(UnixFolder, IDropTarget, iface);
1948 TRACE("(iface=%p, pDataObject=%p, dwKeyState=%ld, pt={.x=%ld, .y=%ld}, pdwEffect=%p) semi-stub\n",
1949 iface, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
1951 InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
1952 hr = IDataObject_GetData(pDataObject, &format, &medium);
1956 if (medium.tymed == TYMED_HGLOBAL) {
1957 IShellFolder *psfSourceFolder, *psfDesktopFolder;
1958 LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
1962 if (!pidaShellIDList)
1963 return HRESULT_FROM_WIN32(GetLastError());
1965 hr = SHGetDesktopFolder(&psfDesktopFolder);
1967 GlobalUnlock(medium.u.hGlobal);
1971 hr = IShellFolder_BindToObject(psfDesktopFolder, HIDA_GetPIDLFolder(pidaShellIDList), NULL,
1972 &IID_IShellFolder, (LPVOID*)&psfSourceFolder);
1973 IShellFolder_Release(psfDesktopFolder);
1975 GlobalUnlock(medium.u.hGlobal);
1979 for (i = 0; i < pidaShellIDList->cidl; i++) {
1980 WCHAR wszSourcePath[MAX_PATH];
1982 hr = IShellFolder_GetDisplayNameOf(psfSourceFolder, HIDA_GetPIDLItem(pidaShellIDList, i),
1983 SHGDN_FORPARSING, &strret);
1987 hr = StrRetToBufW(&strret, NULL, wszSourcePath, MAX_PATH);
1991 switch (*pdwEffect) {
1992 case DROPEFFECT_MOVE:
1993 FIXME("Move %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
1995 case DROPEFFECT_COPY:
1996 FIXME("Copy %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
1998 case DROPEFFECT_LINK:
1999 FIXME("Link %s from %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
2004 IShellFolder_Release(psfSourceFolder);
2005 GlobalUnlock(medium.u.hGlobal);
2012 /* VTable for UnixFolder's IDropTarget interface
2014 static const IDropTargetVtbl UnixFolder_IDropTarget_Vtbl = {
2015 UnixFolder_IDropTarget_QueryInterface,
2016 UnixFolder_IDropTarget_AddRef,
2017 UnixFolder_IDropTarget_Release,
2018 UnixFolder_IDropTarget_DragEnter,
2019 UnixFolder_IDropTarget_DragOver,
2020 UnixFolder_IDropTarget_DragLeave,
2021 UnixFolder_IDropTarget_Drop
2024 /******************************************************************************
2025 * Unix[Dos]Folder_Constructor [Internal]
2028 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
2029 * riid [I] Interface asked for by the client.
2030 * ppv [O] Pointer to an riid interface to the UnixFolder object.
2033 * Those are the only functions exported from shfldr_unixfs.c. They are called from
2034 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
2035 * compatible signature.
2037 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
2038 * means that paths are converted from dos to unix and back at the interfaces.
2040 static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID)
2042 HRESULT hr = E_FAIL;
2043 UnixFolder *pUnixFolder = SHAlloc((ULONG)sizeof(UnixFolder));
2046 FIXME("Aggregation not yet implemented!\n");
2047 return CLASS_E_NOAGGREGATION;
2051 pUnixFolder->lpIShellFolder2Vtbl = &UnixFolder_IShellFolder2_Vtbl;
2052 pUnixFolder->lpIPersistFolder3Vtbl = &UnixFolder_IPersistFolder3_Vtbl;
2053 pUnixFolder->lpIPersistPropertyBagVtbl = &UnixFolder_IPersistPropertyBag_Vtbl;
2054 pUnixFolder->lpISFHelperVtbl = &UnixFolder_ISFHelper_Vtbl;
2055 pUnixFolder->lpIDropTargetVtbl = &UnixFolder_IDropTarget_Vtbl;
2056 pUnixFolder->m_cRef = 0;
2057 pUnixFolder->m_pszPath = NULL;
2058 pUnixFolder->m_pidlLocation = NULL;
2059 pUnixFolder->m_dwPathMode = IsEqualCLSID(&CLSID_UnixFolder, pCLSID) ? PATHMODE_UNIX : PATHMODE_DOS;
2060 pUnixFolder->m_dwAttributes = 0;
2061 pUnixFolder->m_pCLSID = pCLSID;
2062 pUnixFolder->m_dwDropEffectsMask = DROPEFFECT_NONE;
2064 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2, pUnixFolder));
2065 hr = UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2, pUnixFolder), riid, ppv);
2066 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2, pUnixFolder));
2071 HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2072 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2073 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixFolder);
2076 HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2077 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2078 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixDosFolder);
2081 HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2082 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2083 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_FolderShortcut);
2086 HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2087 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2088 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_MyDocuments);
2091 HRESULT WINAPI ShellFSFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
2092 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
2093 return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_ShellFSFolder);
2096 /******************************************************************************
2097 * UnixSubFolderIterator
2099 * Class whose heap based objects represent iterators over the sub-directories
2100 * of a given UnixFolder object.
2103 /* UnixSubFolderIterator object layout and typedef.
2105 typedef struct _UnixSubFolderIterator {
2106 const IEnumIDListVtbl *lpIEnumIDListVtbl;
2110 char m_szFolder[FILENAME_MAX];
2111 } UnixSubFolderIterator;
2113 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
2114 TRACE("(iterator=%p)\n", iterator);
2116 if (iterator->m_dirFolder)
2117 closedir(iterator->m_dirFolder);
2121 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
2122 REFIID riid, void** ppv)
2124 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
2126 if (!ppv) return E_INVALIDARG;
2128 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
2132 return E_NOINTERFACE;
2135 IEnumIDList_AddRef(iface);
2139 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
2141 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2143 TRACE("(iface=%p)\n", iface);
2145 return InterlockedIncrement(&This->m_cRef);
2148 static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
2150 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2153 TRACE("(iface=%p)\n", iface);
2155 cRef = InterlockedDecrement(&This->m_cRef);
2158 UnixSubFolderIterator_Destroy(This);
2163 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
2164 LPITEMIDLIST* rgelt, ULONG* pceltFetched)
2166 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2169 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
2170 if (This->m_dirFolder) {
2171 char *pszRelativePath = This->m_szFolder + lstrlenA(This->m_szFolder);
2172 struct dirent *pDirEntry;
2175 pDirEntry = readdir(This->m_dirFolder);
2176 if (!pDirEntry) break; /* No more entries */
2177 if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
2179 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
2180 * and see if it passes the filter.
2182 lstrcpyA(pszRelativePath, pDirEntry->d_name);
2183 rgelt[i] = (LPITEMIDLIST)SHAlloc(
2184 UNIXFS_shitemid_len_from_filename(pszRelativePath, NULL, NULL)+sizeof(USHORT));
2185 if (!UNIXFS_build_shitemid(This->m_szFolder, rgelt[i]) ||
2186 !UNIXFS_is_pidl_of_type(rgelt[i], This->m_fFilter))
2191 memset(((PBYTE)rgelt[i])+rgelt[i]->mkid.cb, 0, sizeof(USHORT));
2194 *pszRelativePath = '\0'; /* Restore the original path in This->m_szFolder. */
2200 return (i == 0) ? S_FALSE : S_OK;
2203 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
2205 LPITEMIDLIST *apidl;
2209 TRACE("(iface=%p, celt=%ld)\n", iface, celt);
2211 /* Call IEnumIDList::Next and delete the resulting pidls. */
2212 apidl = (LPITEMIDLIST*)SHAlloc(celt * sizeof(LPITEMIDLIST));
2213 hr = IEnumIDList_Next(iface, celt, apidl, &cFetched);
2216 SHFree(apidl[cFetched]);
2222 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
2224 UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
2226 TRACE("(iface=%p)\n", iface);
2228 if (This->m_dirFolder)
2229 rewinddir(This->m_dirFolder);
2234 static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
2235 IEnumIDList** ppenum)
2241 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
2243 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
2244 UnixSubFolderIterator_IEnumIDList_QueryInterface,
2245 UnixSubFolderIterator_IEnumIDList_AddRef,
2246 UnixSubFolderIterator_IEnumIDList_Release,
2247 UnixSubFolderIterator_IEnumIDList_Next,
2248 UnixSubFolderIterator_IEnumIDList_Skip,
2249 UnixSubFolderIterator_IEnumIDList_Reset,
2250 UnixSubFolderIterator_IEnumIDList_Clone
2253 static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter) {
2254 UnixSubFolderIterator *iterator;
2256 TRACE("(pUnixFolder=%p)\n", pUnixFolder);
2258 iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
2259 iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
2260 iterator->m_cRef = 0;
2261 iterator->m_fFilter = fFilter;
2262 iterator->m_dirFolder = opendir(pUnixFolder->m_pszPath);
2263 lstrcpyA(iterator->m_szFolder, pUnixFolder->m_pszPath);
2265 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
2267 return (IUnknown*)iterator;