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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 apart 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 shouldn't 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 safely 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"
139 #ifdef HAVE_SYS_STAT_H
140 # include <sys/stat.h>
150 #define NONAMELESSUNION
151 #define NONAMELESSSTRUCT
159 #include "winternl.h"
160 #include "wine/debug.h"
162 #include "shell32_main.h"
163 #include "shellfolder.h"
165 #include "shresdef.h"
167 #include "debughlp.h"
169 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
171 #if !defined(__MINGW32__) && !defined(_MSC_VER)
173 #define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
174 #define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
176 #define LEN_SHITEMID_FIXED_PART ((USHORT) \
177 ( sizeof(USHORT) /* SHITEMID's cb field. */ \
178 + sizeof(PIDLTYPE) /* PIDLDATA's type field. */ \
179 + sizeof(FileStruct) /* Well, the FileStruct. */ \
180 - sizeof(char) /* One char too much in FileStruct. */ \
181 + sizeof(FileStructW) /* You name it. */ \
182 - sizeof(WCHAR) /* One WCHAR too much in FileStructW. */ \
183 + sizeof(WORD) )) /* Offset of FileStructW field in PIDL. */
185 #define PATHMODE_UNIX 0
186 #define PATHMODE_DOS 1
188 static const WCHAR wFileSystemBindData
[] = {
189 'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
191 /* UnixFolder object layout and typedef.
193 typedef struct _UnixFolder
{
194 const IShellFolder2Vtbl
*lpIShellFolder2Vtbl
;
195 const IPersistFolder3Vtbl
*lpIPersistFolder3Vtbl
;
196 const IPersistPropertyBagVtbl
*lpIPersistPropertyBagVtbl
;
197 const IDropTargetVtbl
*lpIDropTargetVtbl
;
198 const ISFHelperVtbl
*lpISFHelperVtbl
;
200 CHAR
*m_pszPath
; /* Target path of the shell folder (CP_UNIXCP) */
201 LPITEMIDLIST m_pidlLocation
; /* Location in the shell namespace */
203 DWORD m_dwAttributes
;
204 const CLSID
*m_pCLSID
;
205 DWORD m_dwDropEffectsMask
;
208 /* Will hold the registered clipboard format identifier for ITEMIDLISTS. */
209 static UINT cfShellIDList
= 0;
211 /******************************************************************************
212 * UNIXFS_filename_from_shitemid [Internal]
214 * Get CP_UNIXCP encoded filename corresponding to the first item of a pidl
217 * pidl [I] A simple SHITEMID
218 * pszPathElement [O] Filename in CP_UNIXCP encoding will be stored here
221 * Success: Number of bytes necessary to store the CP_UNIXCP encoded filename
222 * _without_ the terminating NUL.
226 * Size of the buffer at pszPathElement has to be FILENAME_MAX. pszPathElement
227 * may be NULL, if you are only interested in the return value.
229 static int UNIXFS_filename_from_shitemid(LPCITEMIDLIST pidl
, char* pszPathElement
) {
230 FileStructW
*pFileStructW
= _ILGetFileStructW(pidl
);
234 cLen
= WideCharToMultiByte(CP_UNIXCP
, 0, pFileStructW
->wszName
, -1, pszPathElement
,
235 pszPathElement
? FILENAME_MAX
: 0, 0, 0);
237 /* There might be pidls slipping in from shfldr_fs.c, which don't contain the
238 * FileStructW field. In this case, we have to convert from CP_ACP to CP_UNIXCP. */
239 char *pszText
= _ILGetTextPointer(pidl
);
240 WCHAR
*pwszPathElement
= NULL
;
243 cWideChars
= MultiByteToWideChar(CP_ACP
, 0, pszText
, -1, NULL
, 0);
244 if (!cWideChars
) goto cleanup
;
246 pwszPathElement
= SHAlloc(cWideChars
* sizeof(WCHAR
));
247 if (!pwszPathElement
) goto cleanup
;
249 cWideChars
= MultiByteToWideChar(CP_ACP
, 0, pszText
, -1, pwszPathElement
, cWideChars
);
250 if (!cWideChars
) goto cleanup
;
252 cLen
= WideCharToMultiByte(CP_UNIXCP
, 0, pwszPathElement
, -1, pszPathElement
,
253 pszPathElement
? FILENAME_MAX
: 0, 0, 0);
256 SHFree(pwszPathElement
);
259 if (cLen
) cLen
--; /* Don't count terminating NUL! */
263 /******************************************************************************
264 * UNIXFS_shitemid_len_from_filename [Internal]
266 * Computes the necessary length of a pidl to hold a path element
269 * szPathElement [I] The path element string in CP_UNIXCP encoding.
270 * ppszPathElement [O] Path element string in CP_ACP encoding.
271 * ppwszPathElement [O] Path element string as WCHAR string.
274 * Success: Length in bytes of a SHITEMID representing szPathElement
278 * Provide NULL values if not interested in pp(w)szPathElement. Otherwise
279 * caller is responsible to free ppszPathElement and ppwszPathElement with
282 static USHORT
UNIXFS_shitemid_len_from_filename(
283 const char *szPathElement
, char **ppszPathElement
, WCHAR
**ppwszPathElement
)
285 USHORT cbPidlLen
= 0;
286 WCHAR
*pwszPathElement
= NULL
;
287 char *pszPathElement
= NULL
;
288 int cWideChars
, cChars
;
290 /* There and Back Again: A Hobbit's Holiday. CP_UNIXCP might be some ANSI
291 * codepage or it might be a real multi-byte encoding like utf-8. There is no
292 * other way to figure out the length of the corresponding WCHAR and CP_ACP
293 * strings without actually doing the full CP_UNIXCP -> WCHAR -> CP_ACP cycle. */
295 cWideChars
= MultiByteToWideChar(CP_UNIXCP
, 0, szPathElement
, -1, NULL
, 0);
296 if (!cWideChars
) goto cleanup
;
298 pwszPathElement
= SHAlloc(cWideChars
* sizeof(WCHAR
));
299 if (!pwszPathElement
) goto cleanup
;
301 cWideChars
= MultiByteToWideChar(CP_UNIXCP
, 0, szPathElement
, -1, pwszPathElement
, cWideChars
);
302 if (!cWideChars
) goto cleanup
;
304 cChars
= WideCharToMultiByte(CP_ACP
, 0, pwszPathElement
, -1, NULL
, 0, 0, 0);
305 if (!cChars
) goto cleanup
;
307 pszPathElement
= SHAlloc(cChars
);
308 if (!pszPathElement
) goto cleanup
;
310 cChars
= WideCharToMultiByte(CP_ACP
, 0, pwszPathElement
, -1, pszPathElement
, cChars
, 0, 0);
311 if (!cChars
) goto cleanup
;
313 /* (cChars & 0x1) is for the potential alignment byte */
314 cbPidlLen
= LEN_SHITEMID_FIXED_PART
+ cChars
+ (cChars
& 0x1) + cWideChars
* sizeof(WCHAR
);
317 if (cbPidlLen
&& ppszPathElement
)
318 *ppszPathElement
= pszPathElement
;
320 SHFree(pszPathElement
);
322 if (cbPidlLen
&& ppwszPathElement
)
323 *ppwszPathElement
= pwszPathElement
;
325 SHFree(pwszPathElement
);
330 /******************************************************************************
331 * UNIXFS_is_pidl_of_type [Internal]
333 * Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
336 * pIDL [I] The ITEMIDLIST to be checked.
337 * fFilter [I] Shell condition flags, which specify the filter.
340 * TRUE, if pIDL is accepted by fFilter
343 static inline BOOL
UNIXFS_is_pidl_of_type(LPCITEMIDLIST pIDL
, SHCONTF fFilter
) {
344 const PIDLDATA
*pIDLData
= _ILGetDataPointer(pIDL
);
345 if (!(fFilter
& SHCONTF_INCLUDEHIDDEN
) && pIDLData
&&
346 (pIDLData
->u
.file
.uFileAttribs
& FILE_ATTRIBUTE_HIDDEN
))
350 if (_ILIsFolder(pIDL
) && (fFilter
& SHCONTF_FOLDERS
)) return TRUE
;
351 if (_ILIsValue(pIDL
) && (fFilter
& SHCONTF_NONFOLDERS
)) return TRUE
;
355 /******************************************************************************
356 * UNIXFS_get_unix_path [Internal]
358 * Convert an absolute dos path to an absolute unix path.
359 * Evaluate "/.", "/.." and the symbolic links in $WINEPREFIX/dosdevices.
362 * pszDosPath [I] An absolute dos path
363 * pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
367 * Failure, FALSE - Path not existent, too long, insufficient rights, to many symlinks
369 static BOOL
UNIXFS_get_unix_path(LPCWSTR pszDosPath
, char *pszCanonicalPath
)
371 char *pPathTail
, *pElement
, *pCanonicalTail
, szPath
[FILENAME_MAX
], *pszUnixPath
, has_failed
= 0, mb_path
[FILENAME_MAX
];
372 WCHAR wszDrive
[] = { '?', ':', '\\', 0 }, dospath
[PATH_MAX
], *dospath_end
;
373 int cDriveSymlinkLen
;
375 TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath
), pszCanonicalPath
);
377 if (!pszDosPath
|| pszDosPath
[1] != ':')
380 /* Get the canonicalized unix path corresponding to the drive letter. */
381 wszDrive
[0] = pszDosPath
[0];
382 pszUnixPath
= wine_get_unix_file_name(wszDrive
);
383 if (!pszUnixPath
) return FALSE
;
384 cDriveSymlinkLen
= strlen(pszUnixPath
);
385 pElement
= realpath(pszUnixPath
, szPath
);
386 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
387 if (!pElement
) return FALSE
;
388 if (szPath
[strlen(szPath
)-1] != '/') strcat(szPath
, "/");
390 /* Append the part relative to the drive symbolic link target. */
391 lstrcpyW(dospath
, pszDosPath
);
392 dospath_end
= dospath
+ lstrlenW(dospath
);
393 while(!(pszUnixPath
= wine_get_unix_file_name(dospath
))){
398 while(*dospath_end
!= '\\' && *dospath_end
!= '/')
402 strcat(szPath
, pszUnixPath
+ cDriveSymlinkLen
);
403 HeapFree(GetProcessHeap(), 0, pszUnixPath
);
405 if(has_failed
&& WideCharToMultiByte(CP_UNIXCP
, 0, dospath_end
+ 1, -1,
406 mb_path
, FILENAME_MAX
, NULL
, NULL
) > 0){
408 strcat(szPath
, mb_path
);
411 /* pCanonicalTail always points to the end of the canonical path constructed
412 * thus far. pPathTail points to the still to be processed part of the input
413 * path. pElement points to the path element currently investigated.
415 *pszCanonicalPath
= '\0';
416 pCanonicalTail
= pszCanonicalPath
;
422 pElement
= pPathTail
;
423 pPathTail
= strchr(pPathTail
+1, '/');
424 if (!pPathTail
) /* Last path element may not be terminated by '/'. */
425 pPathTail
= pElement
+ strlen(pElement
);
426 /* Temporarily terminate the current path element. Will be restored later. */
430 /* Skip "/." path elements */
431 if (!strcmp("/.", pElement
)) {
433 } else if (!strcmp("/..", pElement
)) {
434 /* Remove last element in canonical path for "/.." elements, then skip. */
435 char *pTemp
= strrchr(pszCanonicalPath
, '/');
437 pCanonicalTail
= pTemp
;
438 *pCanonicalTail
= '\0';
441 /* Directory or file. Copy to canonical path */
442 if (pCanonicalTail
- pszCanonicalPath
+ pPathTail
- pElement
+ 1 > FILENAME_MAX
)
445 memcpy(pCanonicalTail
, pElement
, pPathTail
- pElement
+ 1);
446 pCanonicalTail
+= pPathTail
- pElement
;
449 } while (pPathTail
[0] == '/');
451 TRACE("--> %s\n", debugstr_a(pszCanonicalPath
));
456 /******************************************************************************
457 * UNIXFS_seconds_since_1970_to_dos_date_time [Internal]
459 * Convert unix time to FAT time
462 * ss1970 [I] Unix time (seconds since 1970)
463 * pDate [O] Corresponding FAT date
464 * pTime [O] Corresponding FAT time
466 static inline void UNIXFS_seconds_since_1970_to_dos_date_time(
467 time_t ss1970
, LPWORD pDate
, LPWORD pTime
)
472 RtlSecondsSince1970ToTime( ss1970
, &time
);
473 fileTime
.dwLowDateTime
= time
.u
.LowPart
;
474 fileTime
.dwHighDateTime
= time
.u
.HighPart
;
475 FileTimeToDosDateTime(&fileTime
, pDate
, pTime
);
478 /******************************************************************************
479 * UNIXFS_build_shitemid [Internal]
481 * Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
485 * pszUnixPath [I] An absolute path. The SHITEMID will be built for the last component.
486 * pbc [I] Bind context for this action, used to determine if the file must exist
487 * pIDL [O] SHITEMID will be constructed here.
490 * Success: A pointer to the terminating '\0' character of path.
494 * Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
495 * If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
498 static char* UNIXFS_build_shitemid(char *pszUnixPath
, LPBC pbc
, void *pIDL
) {
500 struct stat fileStat
;
501 char *pszComponentU
, *pszComponentA
;
502 WCHAR
*pwszComponentW
;
503 int cComponentULen
, cComponentALen
;
505 FileStructW
*pFileStructW
;
506 WORD uOffsetW
, *pOffsetW
;
507 BOOL must_exist
= TRUE
;
509 TRACE("(pszUnixPath=%s, pbc=%p, pIDL=%p)\n", debugstr_a(pszUnixPath
), pbc
, pIDL
);
513 IFileSystemBindData
*fsb
;
516 hr
= IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)wFileSystemBindData
, &unk
);
518 hr
= IUnknown_QueryInterface(unk
, &IID_IFileSystemBindData
, (LPVOID
*)&fsb
);
520 /* Windows tries to get WIN32_FIND_DATAW structure from
521 * fsb here for no known reason */
523 IFileSystemBindData_Release(fsb
);
525 IUnknown_Release(unk
);
529 /* We are only interested in regular files and directories. */
530 if (stat(pszUnixPath
, &fileStat
)){
531 if (must_exist
|| errno
!= ENOENT
)
534 if (!S_ISDIR(fileStat
.st_mode
) && !S_ISREG(fileStat
.st_mode
))
537 /* Compute the SHITEMID's length and wipe it. */
538 pszComponentU
= strrchr(pszUnixPath
, '/') + 1;
539 cComponentULen
= strlen(pszComponentU
);
540 cbLen
= UNIXFS_shitemid_len_from_filename(pszComponentU
, &pszComponentA
, &pwszComponentW
);
541 if (!cbLen
) return NULL
;
542 memset(pIDL
, 0, cbLen
);
543 ((LPSHITEMID
)pIDL
)->cb
= cbLen
;
545 /* Set shell32's standard SHITEMID data fields. */
546 pIDLData
= _ILGetDataPointer(pIDL
);
547 pIDLData
->type
= S_ISDIR(fileStat
.st_mode
) ? PT_FOLDER
: PT_VALUE
;
548 pIDLData
->u
.file
.dwFileSize
= (DWORD
)fileStat
.st_size
;
549 UNIXFS_seconds_since_1970_to_dos_date_time(fileStat
.st_mtime
, &pIDLData
->u
.file
.uFileDate
,
550 &pIDLData
->u
.file
.uFileTime
);
551 pIDLData
->u
.file
.uFileAttribs
= 0;
552 if (S_ISDIR(fileStat
.st_mode
)) pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_DIRECTORY
;
553 if (pszComponentU
[0] == '.') pIDLData
->u
.file
.uFileAttribs
|= FILE_ATTRIBUTE_HIDDEN
;
554 cComponentALen
= lstrlenA(pszComponentA
) + 1;
555 memcpy(pIDLData
->u
.file
.szNames
, pszComponentA
, cComponentALen
);
557 pFileStructW
= (FileStructW
*)(pIDLData
->u
.file
.szNames
+ cComponentALen
+ (cComponentALen
& 0x1));
558 uOffsetW
= (WORD
)(((LPBYTE
)pFileStructW
) - ((LPBYTE
)pIDL
));
559 pFileStructW
->cbLen
= cbLen
- uOffsetW
;
560 UNIXFS_seconds_since_1970_to_dos_date_time(fileStat
.st_mtime
, &pFileStructW
->uCreationDate
,
561 &pFileStructW
->uCreationTime
);
562 UNIXFS_seconds_since_1970_to_dos_date_time(fileStat
.st_atime
, &pFileStructW
->uLastAccessDate
,
563 &pFileStructW
->uLastAccessTime
);
564 lstrcpyW(pFileStructW
->wszName
, pwszComponentW
);
566 pOffsetW
= (WORD
*)(((LPBYTE
)pIDL
) + cbLen
- sizeof(WORD
));
567 *pOffsetW
= uOffsetW
;
569 SHFree(pszComponentA
);
570 SHFree(pwszComponentW
);
572 return pszComponentU
+ cComponentULen
;
575 /******************************************************************************
576 * UNIXFS_path_to_pidl [Internal]
579 * pUnixFolder [I] If path is relative, pUnixFolder represents the base path
580 * path [I] An absolute unix or dos path or a path relative to pUnixFolder
581 * ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
585 * Failure: Error code, invalid params or out of memory
588 * pUnixFolder also carries the information if the path is expected to be unix or dos.
590 static HRESULT
UNIXFS_path_to_pidl(UnixFolder
*pUnixFolder
, LPBC pbc
, const WCHAR
*path
,
591 LPITEMIDLIST
*ppidl
) {
593 int cPidlLen
, cPathLen
;
594 char *pSlash
, *pNextSlash
, szCompletePath
[FILENAME_MAX
], *pNextPathElement
, *pszAPath
;
597 TRACE("pUnixFolder=%p, pbc=%p, path=%s, ppidl=%p\n", pUnixFolder
, pbc
, debugstr_w(path
), ppidl
);
602 /* Build an absolute path and let pNextPathElement point to the interesting
603 * relative sub-path. We need the absolute path to call 'stat', but the pidl
604 * will only contain the relative part.
606 if ((pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) && (path
[1] == ':'))
608 /* Absolute dos path. Convert to unix */
609 if (!UNIXFS_get_unix_path(path
, szCompletePath
))
611 pNextPathElement
= szCompletePath
;
613 else if ((pUnixFolder
->m_dwPathMode
== PATHMODE_UNIX
) && (path
[0] == '/'))
615 /* Absolute unix path. Just convert to ANSI. */
616 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
, FILENAME_MAX
, NULL
, NULL
);
617 pNextPathElement
= szCompletePath
;
621 /* Relative dos or unix path. Concat with this folder's path */
622 int cBasePathLen
= strlen(pUnixFolder
->m_pszPath
);
623 memcpy(szCompletePath
, pUnixFolder
->m_pszPath
, cBasePathLen
);
624 WideCharToMultiByte(CP_UNIXCP
, 0, path
, -1, szCompletePath
+ cBasePathLen
,
625 FILENAME_MAX
- cBasePathLen
, NULL
, NULL
);
626 pNextPathElement
= szCompletePath
+ cBasePathLen
- 1;
628 /* If in dos mode, replace '\' with '/' */
629 if (pUnixFolder
->m_dwPathMode
== PATHMODE_DOS
) {
630 char *pBackslash
= strchr(pNextPathElement
, '\\');
633 pBackslash
= strchr(pBackslash
, '\\');
638 /* Special case for the root folder. */
639 if (!strcmp(szCompletePath
, "/")) {
640 *ppidl
= pidl
= SHAlloc(sizeof(USHORT
));
641 if (!pidl
) return E_FAIL
;
642 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
646 /* Remove trailing slash, if present */
647 cPathLen
= strlen(szCompletePath
);
648 if (szCompletePath
[cPathLen
-1] == '/')
649 szCompletePath
[cPathLen
-1] = '\0';
651 if ((szCompletePath
[0] != '/') || (pNextPathElement
[0] != '/')) {
652 ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath
, pNextPathElement
);
656 /* At this point, we have an absolute unix path in szCompletePath
657 * and the relative portion of it in pNextPathElement. Both starting with '/'
658 * and _not_ terminated by a '/'. */
659 TRACE("complete path: %s, relative path: %s\n", szCompletePath
, pNextPathElement
);
661 /* Convert to CP_ACP and WCHAR */
662 if (!UNIXFS_shitemid_len_from_filename(pNextPathElement
, &pszAPath
, &pwszPath
))
665 /* Compute the length of the complete ITEMIDLIST */
669 pNextSlash
= strchr(pSlash
+1, '/');
670 cPidlLen
+= LEN_SHITEMID_FIXED_PART
+ /* Fixed part length plus potential alignment byte. */
671 (pNextSlash
? (pNextSlash
- pSlash
) & 0x1 : lstrlenA(pSlash
) & 0x1);
675 /* The USHORT is for the ITEMIDLIST terminator. The NUL terminators for the sub-path-strings
676 * are accounted for by the '/' separators, which are not stored in the SHITEMIDs. Above we
677 * have ensured that the number of '/'s exactly matches the number of sub-path-strings. */
678 cPidlLen
+= lstrlenA(pszAPath
) + lstrlenW(pwszPath
) * sizeof(WCHAR
) + sizeof(USHORT
);
683 *ppidl
= pidl
= SHAlloc(cPidlLen
);
684 if (!pidl
) return E_FAIL
;
686 /* Concatenate the SHITEMIDs of the sub-directories. */
687 while (*pNextPathElement
) {
688 pSlash
= strchr(pNextPathElement
+1, '/');
689 if (pSlash
) *pSlash
= '\0';
690 pNextPathElement
= UNIXFS_build_shitemid(szCompletePath
, pbc
, pidl
);
691 if (pSlash
) *pSlash
= '/';
693 if (!pNextPathElement
) {
696 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
698 pidl
= ILGetNext(pidl
);
700 pidl
->mkid
.cb
= 0; /* Terminate the ITEMIDLIST */
702 if ((char *)pidl
-(char *)*ppidl
+sizeof(USHORT
) != cPidlLen
) /* We've corrupted the heap :( */
703 ERR("Computed length of pidl incorrect. Please report.\n");
708 /******************************************************************************
709 * UNIXFS_initialize_target_folder [Internal]
711 * Initialize the m_pszPath member of an UnixFolder, given an absolute unix
712 * base path and a relative ITEMIDLIST. Leave the m_pidlLocation member, which
713 * specifies the location in the shell namespace alone.
716 * This [IO] The UnixFolder, whose target path is to be initialized
717 * szBasePath [I] The absolute base path
718 * pidlSubFolder [I] Relative part of the path, given as an ITEMIDLIST
719 * dwAttributes [I] Attributes to add to the Folders m_dwAttributes member
720 * (Used to pass the SFGAO_FILESYSTEM flag down the path)
725 static HRESULT
UNIXFS_initialize_target_folder(UnixFolder
*This
, const char *szBasePath
,
726 LPCITEMIDLIST pidlSubFolder
, DWORD dwAttributes
)
728 LPCITEMIDLIST current
= pidlSubFolder
;
729 DWORD dwPathLen
= strlen(szBasePath
)+1;
733 /* Determine the path's length bytes */
734 while (!_ILIsEmpty(current
)) {
735 dwPathLen
+= UNIXFS_filename_from_shitemid(current
, NULL
) + 1; /* For the '/' */
736 current
= ILGetNext(current
);
739 /* Build the path and compute the attributes*/
740 This
->m_dwAttributes
=
741 dwAttributes
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
;
742 This
->m_pszPath
= pNextDir
= SHAlloc(dwPathLen
);
743 if (!This
->m_pszPath
) {
744 WARN("SHAlloc failed!\n");
747 current
= pidlSubFolder
;
748 strcpy(pNextDir
, szBasePath
);
749 pNextDir
+= strlen(szBasePath
);
750 if (This
->m_dwPathMode
== PATHMODE_UNIX
|| IsEqualCLSID(&CLSID_MyDocuments
, This
->m_pCLSID
))
751 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
752 while (!_ILIsEmpty(current
)) {
753 pNextDir
+= UNIXFS_filename_from_shitemid(current
, pNextDir
);
755 current
= ILGetNext(current
);
759 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
) &&
760 ((dos_name
= wine_get_dos_file_name(This
->m_pszPath
))))
762 This
->m_dwAttributes
|= SFGAO_FILESYSTEM
;
763 HeapFree( GetProcessHeap(), 0, dos_name
);
769 /******************************************************************************
770 * UNIXFS_copy [Internal]
772 * Copy pwszDosSrc to pwszDosDst.
775 * pwszDosSrc [I] absolute path of the source
776 * pwszDosDst [I] absolute path of the destination
782 static HRESULT
UNIXFS_copy(LPCWSTR pwszDosSrc
, LPCWSTR pwszDosDst
)
785 LPWSTR pwszSrc
, pwszDst
;
786 HRESULT res
= E_OUTOFMEMORY
;
787 UINT iSrcLen
, iDstLen
;
789 if (!pwszDosSrc
|| !pwszDosDst
)
792 iSrcLen
= lstrlenW(pwszDosSrc
);
793 iDstLen
= lstrlenW(pwszDosDst
);
794 pwszSrc
= HeapAlloc(GetProcessHeap(), 0, (iSrcLen
+ 2) * sizeof(WCHAR
));
795 pwszDst
= HeapAlloc(GetProcessHeap(), 0, (iDstLen
+ 2) * sizeof(WCHAR
));
797 if (pwszSrc
&& pwszDst
) {
798 lstrcpyW(pwszSrc
, pwszDosSrc
);
799 lstrcpyW(pwszDst
, pwszDosDst
);
800 /* double null termination */
801 pwszSrc
[iSrcLen
+ 1] = 0;
802 pwszDst
[iDstLen
+ 1] = 0;
804 ZeroMemory(&op
, sizeof(op
));
805 op
.hwnd
= GetActiveWindow();
809 op
.fFlags
= FOF_ALLOWUNDO
;
810 if (!SHFileOperationW(&op
))
812 WARN("SHFileOperationW failed\n");
819 HeapFree(GetProcessHeap(), 0, pwszSrc
);
820 HeapFree(GetProcessHeap(), 0, pwszDst
);
824 /******************************************************************************
827 * Class whose heap based instances represent unix filesystem directories.
830 static void UnixFolder_Destroy(UnixFolder
*pUnixFolder
) {
831 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
833 SHFree(pUnixFolder
->m_pszPath
);
834 ILFree(pUnixFolder
->m_pidlLocation
);
838 static HRESULT WINAPI
UnixFolder_IShellFolder2_QueryInterface(IShellFolder2
*iface
, REFIID riid
,
841 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
843 TRACE("(iface=%p, riid=%s, ppv=%p)\n", iface
, shdebugstr_guid(riid
), ppv
);
845 if (!ppv
) return E_INVALIDARG
;
847 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellFolder
, riid
) ||
848 IsEqualIID(&IID_IShellFolder2
, riid
))
850 *ppv
= STATIC_CAST(IShellFolder2
, This
);
851 } else if (IsEqualIID(&IID_IPersistFolder3
, riid
) || IsEqualIID(&IID_IPersistFolder2
, riid
) ||
852 IsEqualIID(&IID_IPersistFolder
, riid
) || IsEqualIID(&IID_IPersist
, riid
))
854 *ppv
= STATIC_CAST(IPersistFolder3
, This
);
855 } else if (IsEqualIID(&IID_IPersistPropertyBag
, riid
)) {
856 *ppv
= STATIC_CAST(IPersistPropertyBag
, This
);
857 } else if (IsEqualIID(&IID_ISFHelper
, riid
)) {
858 *ppv
= STATIC_CAST(ISFHelper
, This
);
859 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
860 *ppv
= STATIC_CAST(IDropTarget
, This
);
862 cfShellIDList
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
865 TRACE("Unimplemented interface %s\n", shdebugstr_guid(riid
));
866 return E_NOINTERFACE
;
869 IUnknown_AddRef((IUnknown
*)*ppv
);
873 static ULONG WINAPI
UnixFolder_IShellFolder2_AddRef(IShellFolder2
*iface
) {
874 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
876 TRACE("(iface=%p)\n", iface
);
878 return InterlockedIncrement(&This
->m_cRef
);
881 static ULONG WINAPI
UnixFolder_IShellFolder2_Release(IShellFolder2
*iface
) {
882 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
885 TRACE("(iface=%p)\n", iface
);
887 cRef
= InterlockedDecrement(&This
->m_cRef
);
890 UnixFolder_Destroy(This
);
895 static HRESULT WINAPI
UnixFolder_IShellFolder2_ParseDisplayName(IShellFolder2
* iface
, HWND hwndOwner
,
896 LPBC pbc
, LPOLESTR lpszDisplayName
, ULONG
* pchEaten
, LPITEMIDLIST
* ppidl
,
897 ULONG
* pdwAttributes
)
899 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
902 TRACE("(iface=%p, hwndOwner=%p, pbc=%p, lpszDisplayName=%s, pchEaten=%p, ppidl=%p, "
903 "pdwAttributes=%p) stub\n", iface
, hwndOwner
, pbc
, debugstr_w(lpszDisplayName
),
904 pchEaten
, ppidl
, pdwAttributes
);
906 result
= UNIXFS_path_to_pidl(This
, pbc
, lpszDisplayName
, ppidl
);
907 if (SUCCEEDED(result
) && pdwAttributes
&& *pdwAttributes
)
909 IShellFolder
*pParentSF
;
910 LPCITEMIDLIST pidlLast
;
911 LPITEMIDLIST pidlComplete
= ILCombine(This
->m_pidlLocation
, *ppidl
);
914 hr
= SHBindToParent(pidlComplete
, &IID_IShellFolder
, (LPVOID
*)&pParentSF
, &pidlLast
);
916 FIXME("SHBindToParent failed! hr = %08x\n", hr
);
917 ILFree(pidlComplete
);
920 IShellFolder_GetAttributesOf(pParentSF
, 1, &pidlLast
, pdwAttributes
);
921 IShellFolder_Release(pParentSF
);
922 ILFree(pidlComplete
);
925 if (FAILED(result
)) TRACE("FAILED!\n");
929 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
);
931 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumObjects(IShellFolder2
* iface
, HWND hwndOwner
,
932 SHCONTF grfFlags
, IEnumIDList
** ppEnumIDList
)
934 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
935 IUnknown
*newIterator
;
938 TRACE("(iface=%p, hwndOwner=%p, grfFlags=%08x, ppEnumIDList=%p)\n",
939 iface
, hwndOwner
, grfFlags
, ppEnumIDList
);
941 if (!This
->m_pszPath
) {
942 WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
946 newIterator
= UnixSubFolderIterator_Constructor(This
, grfFlags
);
947 hr
= IUnknown_QueryInterface(newIterator
, &IID_IEnumIDList
, (void**)ppEnumIDList
);
948 IUnknown_Release(newIterator
);
953 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, const CLSID
*pCLSID
);
955 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToObject(IShellFolder2
* iface
, LPCITEMIDLIST pidl
,
956 LPBC pbcReserved
, REFIID riid
, void** ppvOut
)
958 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
959 IPersistFolder3
*persistFolder
;
961 const CLSID
*clsidChild
;
963 TRACE("(iface=%p, pidl=%p, pbcReserver=%p, riid=%p, ppvOut=%p)\n",
964 iface
, pidl
, pbcReserved
, riid
, ppvOut
);
966 if (_ILIsEmpty(pidl
))
969 /* Don't bind to files */
970 if (_ILIsValue(ILFindLastID(pidl
)))
971 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
973 if (IsEqualCLSID(This
->m_pCLSID
, &CLSID_FolderShortcut
)) {
974 /* Children of FolderShortcuts are ShellFSFolders on Windows.
975 * Unixfs' counterpart is UnixDosFolder. */
976 clsidChild
= &CLSID_UnixDosFolder
;
978 clsidChild
= This
->m_pCLSID
;
981 hr
= CreateUnixFolder(NULL
, &IID_IPersistFolder3
, (void**)&persistFolder
, clsidChild
);
982 if (FAILED(hr
)) return hr
;
983 hr
= IPersistFolder_QueryInterface(persistFolder
, riid
, ppvOut
);
986 UnixFolder
*subfolder
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, persistFolder
);
987 subfolder
->m_pidlLocation
= ILCombine(This
->m_pidlLocation
, pidl
);
988 hr
= UNIXFS_initialize_target_folder(subfolder
, This
->m_pszPath
, pidl
,
989 This
->m_dwAttributes
& SFGAO_FILESYSTEM
);
992 IPersistFolder3_Release(persistFolder
);
997 static HRESULT WINAPI
UnixFolder_IShellFolder2_BindToStorage(IShellFolder2
* This
, LPCITEMIDLIST pidl
,
998 LPBC pbcReserved
, REFIID riid
, void** ppvObj
)
1004 static HRESULT WINAPI
UnixFolder_IShellFolder2_CompareIDs(IShellFolder2
* iface
, LPARAM lParam
,
1005 LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
1007 BOOL isEmpty1
, isEmpty2
;
1008 HRESULT hr
= E_FAIL
;
1009 LPITEMIDLIST firstpidl
;
1013 TRACE("(iface=%p, lParam=%ld, pidl1=%p, pidl2=%p)\n", iface
, lParam
, pidl1
, pidl2
);
1015 isEmpty1
= _ILIsEmpty(pidl1
);
1016 isEmpty2
= _ILIsEmpty(pidl2
);
1018 if (isEmpty1
&& isEmpty2
)
1019 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
1021 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
1023 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
1025 if (_ILIsFolder(pidl1
) && !_ILIsFolder(pidl2
))
1026 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
1027 if (!_ILIsFolder(pidl1
) && _ILIsFolder(pidl2
))
1028 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
1030 compare
= CompareStringA(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
,
1031 _ILGetTextPointer(pidl1
), -1,
1032 _ILGetTextPointer(pidl2
), -1);
1034 if ((compare
== CSTR_LESS_THAN
) || (compare
== CSTR_GREATER_THAN
))
1035 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)((compare
== CSTR_LESS_THAN
)?-1:1));
1037 if (pidl1
->mkid
.cb
< pidl2
->mkid
.cb
)
1038 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
1039 else if (pidl1
->mkid
.cb
> pidl2
->mkid
.cb
)
1040 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
1042 firstpidl
= ILCloneFirst(pidl1
);
1043 pidl1
= ILGetNext(pidl1
);
1044 pidl2
= ILGetNext(pidl2
);
1046 isEmpty1
= _ILIsEmpty(pidl1
);
1047 isEmpty2
= _ILIsEmpty(pidl2
);
1049 if (isEmpty1
&& isEmpty2
)
1050 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
1052 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)-1);
1054 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (WORD
)1);
1055 else if (SUCCEEDED(IShellFolder2_BindToObject(iface
, firstpidl
, NULL
, &IID_IShellFolder
, (void**)&psf
))) {
1056 hr
= IShellFolder_CompareIDs(psf
, lParam
, pidl1
, pidl2
);
1057 IShellFolder2_Release(psf
);
1064 static HRESULT WINAPI
UnixFolder_IShellFolder2_CreateViewObject(IShellFolder2
* iface
, HWND hwndOwner
,
1065 REFIID riid
, void** ppv
)
1067 HRESULT hr
= E_INVALIDARG
;
1069 TRACE("(iface=%p, hwndOwner=%p, riid=%p, ppv=%p) stub\n", iface
, hwndOwner
, riid
, ppv
);
1071 if (!ppv
) return E_INVALIDARG
;
1074 if (IsEqualIID(&IID_IShellView
, riid
)) {
1075 LPSHELLVIEW pShellView
;
1077 pShellView
= IShellView_Constructor((IShellFolder
*)iface
);
1079 hr
= IShellView_QueryInterface(pShellView
, riid
, ppv
);
1080 IShellView_Release(pShellView
);
1082 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
1083 hr
= IShellFolder2_QueryInterface(iface
, &IID_IDropTarget
, ppv
);
1089 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetAttributesOf(IShellFolder2
* iface
, UINT cidl
,
1090 LPCITEMIDLIST
* apidl
, SFGAOF
* rgfInOut
)
1092 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
1095 TRACE("(iface=%p, cidl=%u, apidl=%p, rgfInOut=%p)\n", iface
, cidl
, apidl
, rgfInOut
);
1097 if (!rgfInOut
|| (cidl
&& !apidl
))
1098 return E_INVALIDARG
;
1101 *rgfInOut
&= This
->m_dwAttributes
;
1103 char szAbsolutePath
[FILENAME_MAX
], *pszRelativePath
;
1106 *rgfInOut
= SFGAO_CANCOPY
|SFGAO_CANMOVE
|SFGAO_CANLINK
|SFGAO_CANRENAME
|SFGAO_CANDELETE
|
1107 SFGAO_HASPROPSHEET
|SFGAO_DROPTARGET
|SFGAO_FILESYSTEM
;
1108 lstrcpyA(szAbsolutePath
, This
->m_pszPath
);
1109 pszRelativePath
= szAbsolutePath
+ lstrlenA(szAbsolutePath
);
1110 for (i
=0; i
<cidl
; i
++) {
1111 if (!(This
->m_dwAttributes
& SFGAO_FILESYSTEM
)) {
1113 if (!UNIXFS_filename_from_shitemid(apidl
[i
], pszRelativePath
))
1114 return E_INVALIDARG
;
1115 if (!(dos_name
= wine_get_dos_file_name( szAbsolutePath
)))
1116 *rgfInOut
&= ~SFGAO_FILESYSTEM
;
1118 HeapFree( GetProcessHeap(), 0, dos_name
);
1120 if (_ILIsFolder(apidl
[i
]))
1121 *rgfInOut
|= SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
;
1128 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2
* iface
, HWND hwndOwner
,
1129 UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
, UINT
* prgfInOut
, void** ppvOut
)
1131 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
1135 TRACE("(iface=%p, hwndOwner=%p, cidl=%d, apidl=%p, riid=%s, prgfInOut=%p, ppv=%p)\n",
1136 iface
, hwndOwner
, cidl
, apidl
, debugstr_guid(riid
), prgfInOut
, ppvOut
);
1138 if (!cidl
|| !apidl
|| !riid
|| !ppvOut
)
1139 return E_INVALIDARG
;
1141 for (i
=0; i
<cidl
; i
++)
1143 return E_INVALIDARG
;
1146 hr
= SHELL32_CreateExtensionUIObject(iface
, *apidl
, riid
, ppvOut
);
1151 if (IsEqualIID(&IID_IContextMenu
, riid
)) {
1152 *ppvOut
= ISvItemCm_Constructor((IShellFolder
*)iface
, This
->m_pidlLocation
, apidl
, cidl
);
1154 } else if (IsEqualIID(&IID_IDataObject
, riid
)) {
1155 *ppvOut
= IDataObject_Constructor(hwndOwner
, This
->m_pidlLocation
, apidl
, cidl
);
1157 } else if (IsEqualIID(&IID_IExtractIconA
, riid
)) {
1159 if (cidl
!= 1) return E_INVALIDARG
;
1160 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
1161 *ppvOut
= IExtractIconA_Constructor(pidl
);
1164 } else if (IsEqualIID(&IID_IExtractIconW
, riid
)) {
1166 if (cidl
!= 1) return E_INVALIDARG
;
1167 pidl
= ILCombine(This
->m_pidlLocation
, apidl
[0]);
1168 *ppvOut
= IExtractIconW_Constructor(pidl
);
1171 } else if (IsEqualIID(&IID_IDropTarget
, riid
)) {
1172 if (cidl
!= 1) return E_INVALIDARG
;
1173 return IShellFolder2_BindToObject(iface
, apidl
[0], NULL
, &IID_IDropTarget
, ppvOut
);
1174 } else if (IsEqualIID(&IID_IShellLinkW
, riid
)) {
1175 FIXME("IShellLinkW\n");
1177 } else if (IsEqualIID(&IID_IShellLinkA
, riid
)) {
1178 FIXME("IShellLinkA\n");
1181 FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid
));
1182 return E_NOINTERFACE
;
1186 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDisplayNameOf(IShellFolder2
* iface
,
1187 LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
* lpName
)
1189 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
1190 SHITEMID emptyIDL
= { 0, { 0 } };
1193 TRACE("(iface=%p, pidl=%p, uFlags=%x, lpName=%p)\n", iface
, pidl
, uFlags
, lpName
);
1195 if ((GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) &&
1196 (GET_SHGDN_RELATION(uFlags
) != SHGDN_INFOLDER
))
1198 if (_ILIsEmpty(pidl
)) {
1199 lpName
->uType
= STRRET_WSTR
;
1200 if (This
->m_dwPathMode
== PATHMODE_UNIX
) {
1201 UINT len
= MultiByteToWideChar(CP_UNIXCP
, 0, This
->m_pszPath
, -1, NULL
, 0);
1202 lpName
->u
.pOleStr
= SHAlloc(len
* sizeof(WCHAR
));
1203 if (!lpName
->u
.pOleStr
) return HRESULT_FROM_WIN32(GetLastError());
1204 MultiByteToWideChar(CP_UNIXCP
, 0, This
->m_pszPath
, -1, lpName
->u
.pOleStr
, len
);
1206 LPWSTR pwszDosFileName
= wine_get_dos_file_name(This
->m_pszPath
);
1207 if (!pwszDosFileName
) return HRESULT_FROM_WIN32(GetLastError());
1208 lpName
->u
.pOleStr
= SHAlloc((lstrlenW(pwszDosFileName
) + 1) * sizeof(WCHAR
));
1209 if (!lpName
->u
.pOleStr
) return HRESULT_FROM_WIN32(GetLastError());
1210 lstrcpyW(lpName
->u
.pOleStr
, pwszDosFileName
);
1211 PathRemoveBackslashW(lpName
->u
.pOleStr
);
1212 HeapFree(GetProcessHeap(), 0, pwszDosFileName
);
1214 } else if (_ILIsValue(pidl
)) {
1218 /* We are looking for the complete path to a file */
1220 /* Get the complete path for the current folder object */
1221 hr
= IShellFolder_GetDisplayNameOf(iface
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, &str
);
1222 if (SUCCEEDED(hr
)) {
1223 hr
= StrRetToStrW(&str
, NULL
, &path
);
1224 if (SUCCEEDED(hr
)) {
1226 /* Get the child filename */
1227 hr
= IShellFolder_GetDisplayNameOf(iface
, pidl
, SHGDN_FORPARSING
| SHGDN_INFOLDER
, &str
);
1228 if (SUCCEEDED(hr
)) {
1229 hr
= StrRetToStrW(&str
, NULL
, &file
);
1230 if (SUCCEEDED(hr
)) {
1231 static const WCHAR slashW
= '/';
1232 UINT len_path
= strlenW(path
), len_file
= strlenW(file
);
1234 /* Now, combine them */
1235 lpName
->uType
= STRRET_WSTR
;
1236 lpName
->u
.pOleStr
= SHAlloc( (len_path
+ len_file
+ 2)*sizeof(WCHAR
) );
1237 lstrcpyW(lpName
->u
.pOleStr
, path
);
1238 if (This
->m_dwPathMode
== PATHMODE_UNIX
&&
1239 lpName
->u
.pOleStr
[len_path
-1] != slashW
) {
1240 lpName
->u
.pOleStr
[len_path
] = slashW
;
1241 lpName
->u
.pOleStr
[len_path
+1] = '\0';
1243 PathAddBackslashW(lpName
->u
.pOleStr
);
1244 lstrcatW(lpName
->u
.pOleStr
, file
);
1246 CoTaskMemFree(file
);
1248 WARN("Failed to convert strret (file)\n");
1250 CoTaskMemFree(path
);
1252 WARN("Failed to convert strret (path)\n");
1255 IShellFolder
*pSubFolder
;
1257 hr
= IShellFolder_BindToObject(iface
, pidl
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
1258 if (SUCCEEDED(hr
)) {
1259 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, (LPITEMIDLIST
)&emptyIDL
, uFlags
, lpName
);
1260 IShellFolder_Release(pSubFolder
);
1261 } else if (FAILED(hr
) && !_ILIsPidlSimple(pidl
)) {
1262 LPITEMIDLIST pidl_parent
= ILClone(pidl
);
1263 LPITEMIDLIST pidl_child
= ILFindLastID(pidl
);
1265 /* Might be a file, try binding to its parent */
1266 ILRemoveLastID(pidl_parent
);
1267 hr
= IShellFolder_BindToObject(iface
, pidl_parent
, NULL
, &IID_IShellFolder
, (void**)&pSubFolder
);
1268 if (SUCCEEDED(hr
)) {
1269 hr
= IShellFolder_GetDisplayNameOf(pSubFolder
, pidl_child
, uFlags
, lpName
);
1270 IShellFolder_Release(pSubFolder
);
1272 ILFree(pidl_parent
);
1276 WCHAR wszFileName
[MAX_PATH
];
1277 if (!_ILSimpleGetTextW(pidl
, wszFileName
, MAX_PATH
)) return E_INVALIDARG
;
1278 lpName
->uType
= STRRET_WSTR
;
1279 lpName
->u
.pOleStr
= SHAlloc((lstrlenW(wszFileName
)+1)*sizeof(WCHAR
));
1280 if (!lpName
->u
.pOleStr
) return HRESULT_FROM_WIN32(GetLastError());
1281 lstrcpyW(lpName
->u
.pOleStr
, wszFileName
);
1282 if (!(GET_SHGDN_FOR(uFlags
) & SHGDN_FORPARSING
) && This
->m_dwPathMode
== PATHMODE_DOS
&&
1283 !_ILIsFolder(pidl
) && wszFileName
[0] != '.' && SHELL_FS_HideExtension(wszFileName
))
1285 PathRemoveExtensionW(lpName
->u
.pOleStr
);
1289 TRACE("--> %s\n", debugstr_w(lpName
->u
.pOleStr
));
1294 static HRESULT WINAPI
UnixFolder_IShellFolder2_SetNameOf(IShellFolder2
* iface
, HWND hwnd
,
1295 LPCITEMIDLIST pidl
, LPCOLESTR lpcwszName
, SHGDNF uFlags
, LPITEMIDLIST
* ppidlOut
)
1297 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
1299 static const WCHAR awcInvalidChars
[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
1300 char szSrc
[FILENAME_MAX
], szDest
[FILENAME_MAX
];
1301 WCHAR wszSrcRelative
[MAX_PATH
], *pwszExt
= NULL
;
1303 int cBasePathLen
= lstrlenA(This
->m_pszPath
), cNameLen
;
1304 struct stat statDest
;
1305 LPITEMIDLIST pidlSrc
, pidlDest
, pidlRelativeDest
;
1309 TRACE("(iface=%p, hwnd=%p, pidl=%p, lpcwszName=%s, uFlags=0x%08x, ppidlOut=%p)\n",
1310 iface
, hwnd
, pidl
, debugstr_w(lpcwszName
), uFlags
, ppidlOut
);
1312 /* prepare to fail */
1316 /* pidl has to contain a single non-empty SHITEMID */
1317 if (_ILIsDesktop(pidl
) || !_ILIsPidlSimple(pidl
) || !_ILGetTextPointer(pidl
))
1318 return E_INVALIDARG
;
1320 /* check for invalid characters in lpcwszName. */
1321 for (i
=0; i
< sizeof(awcInvalidChars
)/sizeof(*awcInvalidChars
); i
++)
1322 if (StrChrW(lpcwszName
, awcInvalidChars
[i
]))
1323 return HRESULT_FROM_WIN32(ERROR_CANCELLED
);
1325 /* build source path */
1326 memcpy(szSrc
, This
->m_pszPath
, cBasePathLen
);
1327 UNIXFS_filename_from_shitemid(pidl
, szSrc
+ cBasePathLen
);
1329 /* build destination path */
1330 memcpy(szDest
, This
->m_pszPath
, cBasePathLen
);
1331 WideCharToMultiByte(CP_UNIXCP
, 0, lpcwszName
, -1, szDest
+cBasePathLen
,
1332 FILENAME_MAX
-cBasePathLen
, NULL
, NULL
);
1334 /* If the filename's extension is hidden to the user, we have to append it. */
1335 if (!(uFlags
& SHGDN_FORPARSING
) &&
1336 _ILSimpleGetTextW(pidl
, wszSrcRelative
, MAX_PATH
) &&
1337 SHELL_FS_HideExtension(wszSrcRelative
))
1339 int cLenDest
= strlen(szDest
);
1340 pwszExt
= PathFindExtensionW(wszSrcRelative
);
1341 WideCharToMultiByte(CP_UNIXCP
, 0, pwszExt
, -1, szDest
+ cLenDest
,
1342 FILENAME_MAX
- cLenDest
, NULL
, NULL
);
1345 TRACE("src=%s dest=%s\n", szSrc
, szDest
);
1347 /* Fail, if destination does already exist */
1348 if (!stat(szDest
, &statDest
))
1351 /* Rename the file */
1352 if (rename(szSrc
, szDest
))
1355 /* Build a pidl for the path of the renamed file */
1356 cNameLen
= lstrlenW(lpcwszName
) + 1;
1358 cNameLen
+= lstrlenW(pwszExt
);
1359 lpwszName
= SHAlloc(cNameLen
*sizeof(WCHAR
)); /* due to const correctness. */
1360 lstrcpyW(lpwszName
, lpcwszName
);
1362 lstrcatW(lpwszName
, pwszExt
);
1364 hr
= IShellFolder2_ParseDisplayName(iface
, NULL
, NULL
, lpwszName
, NULL
, &pidlRelativeDest
, NULL
);
1367 rename(szDest
, szSrc
); /* Undo the renaming */
1370 pidlDest
= ILCombine(This
->m_pidlLocation
, pidlRelativeDest
);
1371 ILFree(pidlRelativeDest
);
1372 pidlSrc
= ILCombine(This
->m_pidlLocation
, pidl
);
1374 /* Inform the shell */
1375 if (_ILIsFolder(ILFindLastID(pidlDest
)))
1376 SHChangeNotify(SHCNE_RENAMEFOLDER
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
1378 SHChangeNotify(SHCNE_RENAMEITEM
, SHCNF_IDLIST
, pidlSrc
, pidlDest
);
1381 *ppidlOut
= ILClone(ILFindLastID(pidlDest
));
1389 static HRESULT WINAPI
UnixFolder_IShellFolder2_EnumSearches(IShellFolder2
* iface
,
1390 IEnumExtraSearch
**ppEnum
)
1396 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumn(IShellFolder2
* iface
,
1397 DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
1399 TRACE("(iface=%p,dwReserved=%x,pSort=%p,pDisplay=%p)\n", iface
, dwReserved
, pSort
, pDisplay
);
1409 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultColumnState(IShellFolder2
* iface
,
1410 UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
1416 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDefaultSearchGUID(IShellFolder2
* iface
,
1423 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsEx(IShellFolder2
* iface
,
1424 LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
1430 #define SHELLVIEWCOLUMNS 7
1432 static HRESULT WINAPI
UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2
* iface
,
1433 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
*psd
)
1435 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IShellFolder2
, iface
);
1436 HRESULT hr
= E_FAIL
;
1437 struct passwd
*pPasswd
;
1438 struct group
*pGroup
;
1439 struct stat statItem
;
1441 static const shvheader unixfs_header
[SHELLVIEWCOLUMNS
] = {
1442 {IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15},
1443 {IDS_SHV_COLUMN2
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
1444 {IDS_SHV_COLUMN3
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
1445 {IDS_SHV_COLUMN4
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 12},
1446 {IDS_SHV_COLUMN5
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 9},
1447 {IDS_SHV_COLUMN10
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7},
1448 {IDS_SHV_COLUMN11
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 7}
1451 TRACE("(iface=%p, pidl=%p, iColumn=%d, psd=%p) stub\n", iface
, pidl
, iColumn
, psd
);
1453 if (!psd
|| iColumn
>= SHELLVIEWCOLUMNS
)
1454 return E_INVALIDARG
;
1457 return SHELL32_GetColumnDetails(unixfs_header
, iColumn
, psd
);
1459 if (iColumn
== 4 || iColumn
== 5 || iColumn
== 6) {
1460 char szPath
[FILENAME_MAX
];
1461 strcpy(szPath
, This
->m_pszPath
);
1462 if (!UNIXFS_filename_from_shitemid(pidl
, szPath
+ strlen(szPath
)))
1463 return E_INVALIDARG
;
1464 if (stat(szPath
, &statItem
))
1465 return E_INVALIDARG
;
1468 psd
->str
.u
.cStr
[0] = '\0';
1469 psd
->str
.uType
= STRRET_CSTR
;
1473 hr
= IShellFolder2_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
|SHGDN_INFOLDER
, &psd
->str
);
1476 _ILGetFileSize(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1479 _ILGetFileType (pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1482 _ILGetFileDate(pidl
, psd
->str
.u
.cStr
, MAX_PATH
);
1485 psd
->str
.u
.cStr
[0] = S_ISDIR(statItem
.st_mode
) ? 'd' : '-';
1486 psd
->str
.u
.cStr
[1] = (statItem
.st_mode
& S_IRUSR
) ? 'r' : '-';
1487 psd
->str
.u
.cStr
[2] = (statItem
.st_mode
& S_IWUSR
) ? 'w' : '-';
1488 psd
->str
.u
.cStr
[3] = (statItem
.st_mode
& S_IXUSR
) ? 'x' : '-';
1489 psd
->str
.u
.cStr
[4] = (statItem
.st_mode
& S_IRGRP
) ? 'r' : '-';
1490 psd
->str
.u
.cStr
[5] = (statItem
.st_mode
& S_IWGRP
) ? 'w' : '-';
1491 psd
->str
.u
.cStr
[6] = (statItem
.st_mode
& S_IXGRP
) ? 'x' : '-';
1492 psd
->str
.u
.cStr
[7] = (statItem
.st_mode
& S_IROTH
) ? 'r' : '-';
1493 psd
->str
.u
.cStr
[8] = (statItem
.st_mode
& S_IWOTH
) ? 'w' : '-';
1494 psd
->str
.u
.cStr
[9] = (statItem
.st_mode
& S_IXOTH
) ? 'x' : '-';
1495 psd
->str
.u
.cStr
[10] = '\0';
1498 pPasswd
= getpwuid(statItem
.st_uid
);
1499 if (pPasswd
) strcpy(psd
->str
.u
.cStr
, pPasswd
->pw_name
);
1502 pGroup
= getgrgid(statItem
.st_gid
);
1503 if (pGroup
) strcpy(psd
->str
.u
.cStr
, pGroup
->gr_name
);
1510 static HRESULT WINAPI
UnixFolder_IShellFolder2_MapColumnToSCID(IShellFolder2
* iface
, UINT iColumn
,
1517 /* VTable for UnixFolder's IShellFolder2 interface.
1519 static const IShellFolder2Vtbl UnixFolder_IShellFolder2_Vtbl
= {
1520 UnixFolder_IShellFolder2_QueryInterface
,
1521 UnixFolder_IShellFolder2_AddRef
,
1522 UnixFolder_IShellFolder2_Release
,
1523 UnixFolder_IShellFolder2_ParseDisplayName
,
1524 UnixFolder_IShellFolder2_EnumObjects
,
1525 UnixFolder_IShellFolder2_BindToObject
,
1526 UnixFolder_IShellFolder2_BindToStorage
,
1527 UnixFolder_IShellFolder2_CompareIDs
,
1528 UnixFolder_IShellFolder2_CreateViewObject
,
1529 UnixFolder_IShellFolder2_GetAttributesOf
,
1530 UnixFolder_IShellFolder2_GetUIObjectOf
,
1531 UnixFolder_IShellFolder2_GetDisplayNameOf
,
1532 UnixFolder_IShellFolder2_SetNameOf
,
1533 UnixFolder_IShellFolder2_GetDefaultSearchGUID
,
1534 UnixFolder_IShellFolder2_EnumSearches
,
1535 UnixFolder_IShellFolder2_GetDefaultColumn
,
1536 UnixFolder_IShellFolder2_GetDefaultColumnState
,
1537 UnixFolder_IShellFolder2_GetDetailsEx
,
1538 UnixFolder_IShellFolder2_GetDetailsOf
,
1539 UnixFolder_IShellFolder2_MapColumnToSCID
1542 static HRESULT WINAPI
UnixFolder_IPersistFolder3_QueryInterface(IPersistFolder3
* iface
, REFIID riid
,
1545 return UnixFolder_IShellFolder2_QueryInterface(
1546 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
)), riid
, ppvObject
);
1549 static ULONG WINAPI
UnixFolder_IPersistFolder3_AddRef(IPersistFolder3
* iface
)
1551 return UnixFolder_IShellFolder2_AddRef(
1552 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
)));
1555 static ULONG WINAPI
UnixFolder_IPersistFolder3_Release(IPersistFolder3
* iface
)
1557 return UnixFolder_IShellFolder2_Release(
1558 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
)));
1561 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetClassID(IPersistFolder3
* iface
, CLSID
* pClassID
)
1563 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1565 TRACE("(iface=%p, pClassId=%p)\n", iface
, pClassID
);
1568 return E_INVALIDARG
;
1570 *pClassID
= *This
->m_pCLSID
;
1574 static HRESULT WINAPI
UnixFolder_IPersistFolder3_Initialize(IPersistFolder3
* iface
, LPCITEMIDLIST pidl
)
1576 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1577 LPCITEMIDLIST current
= pidl
;
1578 char szBasePath
[FILENAME_MAX
] = "/";
1580 TRACE("(iface=%p, pidl=%p)\n", iface
, pidl
);
1582 /* Find the UnixFolderClass root */
1583 while (current
->mkid
.cb
) {
1584 if ((_ILIsDrive(current
) && IsEqualCLSID(This
->m_pCLSID
, &CLSID_ShellFSFolder
)) ||
1585 (_ILIsSpecialFolder(current
) && IsEqualCLSID(This
->m_pCLSID
, _ILGetGUIDPointer(current
))))
1589 current
= ILGetNext(current
);
1592 if (current
->mkid
.cb
) {
1593 if (_ILIsDrive(current
)) {
1594 WCHAR wszDrive
[4] = { '?', ':', '\\', 0 };
1595 wszDrive
[0] = (WCHAR
)*_ILGetTextPointer(current
);
1596 if (!UNIXFS_get_unix_path(wszDrive
, szBasePath
))
1598 } else if (IsEqualIID(&CLSID_MyDocuments
, _ILGetGUIDPointer(current
))) {
1599 WCHAR wszMyDocumentsPath
[MAX_PATH
];
1600 if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath
, CSIDL_PERSONAL
, FALSE
))
1602 PathAddBackslashW(wszMyDocumentsPath
);
1603 if (!UNIXFS_get_unix_path(wszMyDocumentsPath
, szBasePath
))
1606 current
= ILGetNext(current
);
1607 } else if (_ILIsDesktop(pidl
) || _ILIsValue(pidl
) || _ILIsFolder(pidl
)) {
1608 /* Path rooted at Desktop */
1609 WCHAR wszDesktopPath
[MAX_PATH
];
1610 if (!SHGetSpecialFolderPathW(0, wszDesktopPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
))
1612 PathAddBackslashW(wszDesktopPath
);
1613 if (!UNIXFS_get_unix_path(wszDesktopPath
, szBasePath
))
1616 } else if (IsEqualCLSID(This
->m_pCLSID
, &CLSID_FolderShortcut
)) {
1617 /* FolderShortcuts' Initialize method only sets the ITEMIDLIST, which
1618 * specifies the location in the shell namespace, but leaves the
1619 * target folder (m_pszPath) alone. See unit tests in tests/shlfolder.c */
1620 This
->m_pidlLocation
= ILClone(pidl
);
1623 ERR("Unknown pidl type!\n");
1625 return E_INVALIDARG
;
1628 This
->m_pidlLocation
= ILClone(pidl
);
1629 return UNIXFS_initialize_target_folder(This
, szBasePath
, current
, 0);
1632 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetCurFolder(IPersistFolder3
* iface
, LPITEMIDLIST
* ppidl
)
1634 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1636 TRACE ("(iface=%p, ppidl=%p)\n", iface
, ppidl
);
1640 *ppidl
= ILClone (This
->m_pidlLocation
);
1644 static HRESULT WINAPI
UnixFolder_IPersistFolder3_InitializeEx(IPersistFolder3
*iface
, IBindCtx
*pbc
,
1645 LPCITEMIDLIST pidlRoot
, const PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1647 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistFolder3
, iface
);
1648 WCHAR wszTargetDosPath
[MAX_PATH
];
1649 char szTargetPath
[FILENAME_MAX
] = "";
1651 TRACE("(iface=%p, pbc=%p, pidlRoot=%p, ppfti=%p)\n", iface
, pbc
, pidlRoot
, ppfti
);
1653 /* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
1655 return IPersistFolder3_Initialize(iface
, pidlRoot
);
1657 if (ppfti
->csidl
!= -1) {
1658 if (FAILED(SHGetFolderPathW(0, ppfti
->csidl
, NULL
, 0, wszTargetDosPath
)) ||
1659 !UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
))
1663 } else if (*ppfti
->szTargetParsingName
) {
1664 lstrcpyW(wszTargetDosPath
, ppfti
->szTargetParsingName
);
1665 PathAddBackslashW(wszTargetDosPath
);
1666 if (!UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
)) {
1669 } else if (ppfti
->pidlTargetFolder
) {
1670 if (!SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTargetDosPath
) ||
1671 !UNIXFS_get_unix_path(wszTargetDosPath
, szTargetPath
))
1679 This
->m_pszPath
= SHAlloc(lstrlenA(szTargetPath
)+1);
1680 if (!This
->m_pszPath
)
1682 lstrcpyA(This
->m_pszPath
, szTargetPath
);
1683 This
->m_pidlLocation
= ILClone(pidlRoot
);
1684 This
->m_dwAttributes
= (ppfti
->dwAttributes
!= -1) ? ppfti
->dwAttributes
:
1685 (SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_CANRENAME
|SFGAO_FILESYSTEM
);
1690 static HRESULT WINAPI
UnixFolder_IPersistFolder3_GetFolderTargetInfo(IPersistFolder3
*iface
,
1691 PERSIST_FOLDER_TARGET_INFO
*ppfti
)
1693 FIXME("(iface=%p, ppfti=%p) stub\n", iface
, ppfti
);
1697 /* VTable for UnixFolder's IPersistFolder interface.
1699 static const IPersistFolder3Vtbl UnixFolder_IPersistFolder3_Vtbl
= {
1700 UnixFolder_IPersistFolder3_QueryInterface
,
1701 UnixFolder_IPersistFolder3_AddRef
,
1702 UnixFolder_IPersistFolder3_Release
,
1703 UnixFolder_IPersistFolder3_GetClassID
,
1704 UnixFolder_IPersistFolder3_Initialize
,
1705 UnixFolder_IPersistFolder3_GetCurFolder
,
1706 UnixFolder_IPersistFolder3_InitializeEx
,
1707 UnixFolder_IPersistFolder3_GetFolderTargetInfo
1710 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_QueryInterface(IPersistPropertyBag
* iface
,
1711 REFIID riid
, void** ppv
)
1713 return UnixFolder_IShellFolder2_QueryInterface(
1714 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)), riid
, ppv
);
1717 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_AddRef(IPersistPropertyBag
* iface
)
1719 return UnixFolder_IShellFolder2_AddRef(
1720 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)));
1723 static ULONG WINAPI
UnixFolder_IPersistPropertyBag_Release(IPersistPropertyBag
* iface
)
1725 return UnixFolder_IShellFolder2_Release(
1726 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)));
1729 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_GetClassID(IPersistPropertyBag
* iface
,
1732 return UnixFolder_IPersistFolder3_GetClassID(
1733 STATIC_CAST(IPersistFolder3
, ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
)), pClassID
);
1736 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_InitNew(IPersistPropertyBag
* iface
)
1742 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Load(IPersistPropertyBag
*iface
,
1743 IPropertyBag
*pPropertyBag
, IErrorLog
*pErrorLog
)
1745 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IPersistPropertyBag
, iface
);
1746 static const WCHAR wszTarget
[] = { 'T','a','r','g','e','t', 0 }, wszNull
[] = { 0 };
1747 PERSIST_FOLDER_TARGET_INFO pftiTarget
;
1751 TRACE("(iface=%p, pPropertyBag=%p, pErrorLog=%p)\n", iface
, pPropertyBag
, pErrorLog
);
1756 /* Get 'Target' property from the property bag. */
1757 V_VT(&var
) = VT_BSTR
;
1758 hr
= IPropertyBag_Read(pPropertyBag
, wszTarget
, &var
, NULL
);
1761 lstrcpyW(pftiTarget
.szTargetParsingName
, V_BSTR(&var
));
1762 SysFreeString(V_BSTR(&var
));
1764 pftiTarget
.pidlTargetFolder
= NULL
;
1765 lstrcpyW(pftiTarget
.szNetworkProvider
, wszNull
);
1766 pftiTarget
.dwAttributes
= -1;
1767 pftiTarget
.csidl
= -1;
1769 return UnixFolder_IPersistFolder3_InitializeEx(
1770 STATIC_CAST(IPersistFolder3
, This
), NULL
, NULL
, &pftiTarget
);
1773 static HRESULT WINAPI
UnixFolder_IPersistPropertyBag_Save(IPersistPropertyBag
*iface
,
1774 IPropertyBag
*pPropertyBag
, BOOL fClearDirty
, BOOL fSaveAllProperties
)
1780 /* VTable for UnixFolder's IPersistPropertyBag interface.
1782 static const IPersistPropertyBagVtbl UnixFolder_IPersistPropertyBag_Vtbl
= {
1783 UnixFolder_IPersistPropertyBag_QueryInterface
,
1784 UnixFolder_IPersistPropertyBag_AddRef
,
1785 UnixFolder_IPersistPropertyBag_Release
,
1786 UnixFolder_IPersistPropertyBag_GetClassID
,
1787 UnixFolder_IPersistPropertyBag_InitNew
,
1788 UnixFolder_IPersistPropertyBag_Load
,
1789 UnixFolder_IPersistPropertyBag_Save
1792 static HRESULT WINAPI
UnixFolder_ISFHelper_QueryInterface(ISFHelper
* iface
, REFIID riid
,
1795 return UnixFolder_IShellFolder2_QueryInterface(
1796 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, ISFHelper
, iface
)), riid
, ppvObject
);
1799 static ULONG WINAPI
UnixFolder_ISFHelper_AddRef(ISFHelper
* iface
)
1801 return UnixFolder_IShellFolder2_AddRef(
1802 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, ISFHelper
, iface
)));
1805 static ULONG WINAPI
UnixFolder_ISFHelper_Release(ISFHelper
* iface
)
1807 return UnixFolder_IShellFolder2_Release(
1808 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, ISFHelper
, iface
)));
1811 static HRESULT WINAPI
UnixFolder_ISFHelper_GetUniqueName(ISFHelper
* iface
, LPWSTR pwszName
, UINT uLen
)
1813 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1816 LPITEMIDLIST pidlElem
;
1819 WCHAR wszNewFolder
[25];
1820 static const WCHAR wszFormat
[] = { '%','s',' ','%','d',0 };
1822 TRACE("(iface=%p, pwszName=%p, uLen=%u)\n", iface
, pwszName
, uLen
);
1824 LoadStringW(shell32_hInstance
, IDS_NEWFOLDER
, wszNewFolder
, sizeof(wszNewFolder
)/sizeof(WCHAR
));
1826 if (uLen
< sizeof(wszNewFolder
)/sizeof(WCHAR
)+3)
1827 return E_INVALIDARG
;
1829 hr
= IShellFolder2_EnumObjects(STATIC_CAST(IShellFolder2
, This
), 0,
1830 SHCONTF_FOLDERS
|SHCONTF_NONFOLDERS
|SHCONTF_INCLUDEHIDDEN
, &pEnum
);
1831 if (SUCCEEDED(hr
)) {
1832 lstrcpynW(pwszName
, wszNewFolder
, uLen
);
1833 IEnumIDList_Reset(pEnum
);
1835 while ((IEnumIDList_Next(pEnum
, 1, &pidlElem
, &dwFetched
) == S_OK
) && (dwFetched
== 1)) {
1836 WCHAR wszTemp
[MAX_PATH
];
1837 _ILSimpleGetTextW(pidlElem
, wszTemp
, MAX_PATH
);
1838 if (!lstrcmpiW(wszTemp
, pwszName
)) {
1839 IEnumIDList_Reset(pEnum
);
1840 snprintfW(pwszName
, uLen
, wszFormat
, wszNewFolder
, i
++);
1847 IEnumIDList_Release(pEnum
);
1852 static HRESULT WINAPI
UnixFolder_ISFHelper_AddFolder(ISFHelper
* iface
, HWND hwnd
, LPCWSTR pwszName
,
1853 LPITEMIDLIST
* ppidlOut
)
1855 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1856 char szNewDir
[FILENAME_MAX
];
1859 TRACE("(iface=%p, hwnd=%p, pwszName=%s, ppidlOut=%p)\n",
1860 iface
, hwnd
, debugstr_w(pwszName
), ppidlOut
);
1865 if (!This
->m_pszPath
|| !(This
->m_dwAttributes
& SFGAO_FILESYSTEM
))
1868 lstrcpynA(szNewDir
, This
->m_pszPath
, FILENAME_MAX
);
1869 cBaseLen
= lstrlenA(szNewDir
);
1870 WideCharToMultiByte(CP_UNIXCP
, 0, pwszName
, -1, szNewDir
+cBaseLen
, FILENAME_MAX
-cBaseLen
, 0, 0);
1872 if (mkdir(szNewDir
, 0777)) {
1873 char szMessage
[256 + FILENAME_MAX
];
1874 char szCaption
[256];
1876 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_DENIED
, szCaption
, sizeof(szCaption
));
1877 sprintf(szMessage
, szCaption
, szNewDir
);
1878 LoadStringA(shell32_hInstance
, IDS_CREATEFOLDER_CAPTION
, szCaption
, sizeof(szCaption
));
1879 MessageBoxA(hwnd
, szMessage
, szCaption
, MB_OK
| MB_ICONEXCLAMATION
);
1883 LPITEMIDLIST pidlRelative
;
1885 /* Inform the shell */
1886 if (SUCCEEDED(UNIXFS_path_to_pidl(This
, NULL
, pwszName
, &pidlRelative
))) {
1887 LPITEMIDLIST pidlAbsolute
= ILCombine(This
->m_pidlLocation
, pidlRelative
);
1889 *ppidlOut
= pidlRelative
;
1891 ILFree(pidlRelative
);
1892 SHChangeNotify(SHCNE_MKDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
1893 ILFree(pidlAbsolute
);
1894 } else return E_FAIL
;
1900 * Delete specified files by converting the path to DOS paths and calling
1901 * SHFileOperationW. If an error occurs it returns an error code. If the paths can't
1902 * be converted, S_FALSE is returned. In such situation DeleteItems will try to delete
1903 * the files using syscalls
1905 static HRESULT
UNIXFS_delete_with_shfileop(UnixFolder
*This
, UINT cidl
, const LPCITEMIDLIST
*apidl
)
1907 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1908 LPWSTR wszPathsList
, wszListPos
;
1913 lstrcpyA(szAbsolute
, This
->m_pszPath
);
1914 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
1916 wszListPos
= wszPathsList
= HeapAlloc(GetProcessHeap(), 0, cidl
*MAX_PATH
*sizeof(WCHAR
)+1);
1917 if (wszPathsList
== NULL
)
1918 return E_OUTOFMEMORY
;
1919 for (i
=0; i
<cidl
; i
++) {
1922 if (!_ILIsFolder(apidl
[i
]) && !_ILIsValue(apidl
[i
]))
1924 if (!UNIXFS_filename_from_shitemid(apidl
[i
], pszRelative
))
1926 HeapFree(GetProcessHeap(), 0, wszPathsList
);
1927 return E_INVALIDARG
;
1929 wszDosPath
= wine_get_dos_file_name(szAbsolute
);
1930 if (wszDosPath
== NULL
|| lstrlenW(wszDosPath
) >= MAX_PATH
)
1932 HeapFree(GetProcessHeap(), 0, wszPathsList
);
1933 HeapFree(GetProcessHeap(), 0, wszDosPath
);
1936 lstrcpyW(wszListPos
, wszDosPath
);
1937 wszListPos
+= lstrlenW(wszListPos
)+1;
1938 HeapFree(GetProcessHeap(), 0, wszDosPath
);
1942 ZeroMemory(&op
, sizeof(op
));
1943 op
.hwnd
= GetActiveWindow();
1944 op
.wFunc
= FO_DELETE
;
1945 op
.pFrom
= wszPathsList
;
1946 op
.fFlags
= FOF_ALLOWUNDO
;
1947 if (!SHFileOperationW(&op
))
1949 WARN("SHFileOperationW failed\n");
1955 HeapFree(GetProcessHeap(), 0, wszPathsList
);
1959 static HRESULT
UNIXFS_delete_with_syscalls(UnixFolder
*This
, UINT cidl
, const LPCITEMIDLIST
*apidl
)
1961 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1962 static const WCHAR empty
[] = {0};
1965 if (!SHELL_ConfirmYesNoW(GetActiveWindow(), ASK_DELETE_SELECTED
, empty
))
1968 lstrcpyA(szAbsolute
, This
->m_pszPath
);
1969 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
1971 for (i
=0; i
<cidl
; i
++) {
1972 if (!UNIXFS_filename_from_shitemid(apidl
[i
], pszRelative
))
1973 return E_INVALIDARG
;
1974 if (_ILIsFolder(apidl
[i
])) {
1975 if (rmdir(szAbsolute
))
1977 } else if (_ILIsValue(apidl
[i
])) {
1978 if (unlink(szAbsolute
))
1985 static HRESULT WINAPI
UnixFolder_ISFHelper_DeleteItems(ISFHelper
* iface
, UINT cidl
,
1986 LPCITEMIDLIST
* apidl
)
1988 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
1989 char szAbsolute
[FILENAME_MAX
], *pszRelative
;
1990 LPITEMIDLIST pidlAbsolute
;
1995 TRACE("(iface=%p, cidl=%d, apidl=%p)\n", iface
, cidl
, apidl
);
1997 hr
= UNIXFS_delete_with_shfileop(This
, cidl
, apidl
);
1999 hr
= UNIXFS_delete_with_syscalls(This
, cidl
, apidl
);
2001 lstrcpyA(szAbsolute
, This
->m_pszPath
);
2002 pszRelative
= szAbsolute
+ lstrlenA(szAbsolute
);
2004 /* we need to manually send the notifies if the files doesn't exist */
2005 for (i
=0; i
<cidl
; i
++) {
2006 if (!UNIXFS_filename_from_shitemid(apidl
[i
], pszRelative
))
2008 pidlAbsolute
= ILCombine(This
->m_pidlLocation
, apidl
[i
]);
2009 if (stat(szAbsolute
, &st
))
2011 if (_ILIsFolder(apidl
[i
])) {
2012 SHChangeNotify(SHCNE_RMDIR
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
2013 } else if (_ILIsValue(apidl
[i
])) {
2014 SHChangeNotify(SHCNE_DELETE
, SHCNF_IDLIST
, pidlAbsolute
, NULL
);
2017 ILFree(pidlAbsolute
);
2023 static HRESULT WINAPI
UnixFolder_ISFHelper_CopyItems(ISFHelper
* iface
, IShellFolder
*psfFrom
,
2024 UINT cidl
, LPCITEMIDLIST
*apidl
)
2026 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, ISFHelper
, iface
);
2030 char szAbsoluteDst
[FILENAME_MAX
], *pszRelativeDst
;
2032 TRACE("(iface=%p, psfFrom=%p, cidl=%d, apidl=%p)\n", iface
, psfFrom
, cidl
, apidl
);
2034 if (!psfFrom
|| !cidl
|| !apidl
)
2035 return E_INVALIDARG
;
2037 /* All source items have to be filesystem items. */
2038 dwAttributes
= SFGAO_FILESYSTEM
;
2039 hr
= IShellFolder_GetAttributesOf(psfFrom
, cidl
, apidl
, &dwAttributes
);
2040 if (FAILED(hr
) || !(dwAttributes
& SFGAO_FILESYSTEM
))
2041 return E_INVALIDARG
;
2043 lstrcpyA(szAbsoluteDst
, This
->m_pszPath
);
2044 pszRelativeDst
= szAbsoluteDst
+ strlen(szAbsoluteDst
);
2046 for (i
=0; i
<cidl
; i
++) {
2047 WCHAR wszSrc
[MAX_PATH
];
2048 char szSrc
[FILENAME_MAX
];
2051 WCHAR
*pwszDosSrc
, *pwszDosDst
;
2053 /* Build the unix path of the current source item. */
2054 if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom
, apidl
[i
], SHGDN_FORPARSING
, &strret
)))
2056 if (FAILED(StrRetToBufW(&strret
, apidl
[i
], wszSrc
, MAX_PATH
)))
2058 if (!UNIXFS_get_unix_path(wszSrc
, szSrc
))
2061 /* Build the unix path of the current destination item */
2062 UNIXFS_filename_from_shitemid(apidl
[i
], pszRelativeDst
);
2064 pwszDosSrc
= wine_get_dos_file_name(szSrc
);
2065 pwszDosDst
= wine_get_dos_file_name(szAbsoluteDst
);
2067 if (pwszDosSrc
&& pwszDosDst
)
2068 res
= UNIXFS_copy(pwszDosSrc
, pwszDosDst
);
2070 res
= E_OUTOFMEMORY
;
2072 HeapFree(GetProcessHeap(), 0, pwszDosSrc
);
2073 HeapFree(GetProcessHeap(), 0, pwszDosDst
);
2081 /* VTable for UnixFolder's ISFHelper interface
2083 static const ISFHelperVtbl UnixFolder_ISFHelper_Vtbl
= {
2084 UnixFolder_ISFHelper_QueryInterface
,
2085 UnixFolder_ISFHelper_AddRef
,
2086 UnixFolder_ISFHelper_Release
,
2087 UnixFolder_ISFHelper_GetUniqueName
,
2088 UnixFolder_ISFHelper_AddFolder
,
2089 UnixFolder_ISFHelper_DeleteItems
,
2090 UnixFolder_ISFHelper_CopyItems
2093 static HRESULT WINAPI
UnixFolder_IDropTarget_QueryInterface(IDropTarget
* iface
, REFIID riid
,
2096 return UnixFolder_IShellFolder2_QueryInterface(
2097 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IDropTarget
, iface
)), riid
, ppvObject
);
2100 static ULONG WINAPI
UnixFolder_IDropTarget_AddRef(IDropTarget
* iface
)
2102 return UnixFolder_IShellFolder2_AddRef(
2103 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IDropTarget
, iface
)));
2106 static ULONG WINAPI
UnixFolder_IDropTarget_Release(IDropTarget
* iface
)
2108 return UnixFolder_IShellFolder2_Release(
2109 STATIC_CAST(IShellFolder2
, ADJUST_THIS(UnixFolder
, IDropTarget
, iface
)));
2112 #define HIDA_GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
2113 #define HIDA_GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
2115 static HRESULT WINAPI
UnixFolder_IDropTarget_DragEnter(IDropTarget
*iface
, IDataObject
*pDataObject
,
2116 DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
2118 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IDropTarget
, iface
);
2122 TRACE("(iface=%p, pDataObject=%p, dwKeyState=%08x, pt={.x=%d, .y=%d}, pdwEffect=%p)\n",
2123 iface
, pDataObject
, dwKeyState
, pt
.x
, pt
.y
, pdwEffect
);
2125 if (!pdwEffect
|| !pDataObject
)
2126 return E_INVALIDARG
;
2128 /* Compute a mask of supported drop-effects for this shellfolder object and the given data
2129 * object. Dropping is only supported on folders, which represent filesystem locations. One
2130 * can't drop on file objects. And the 'move' drop effect is only supported, if the source
2131 * folder is not identical to the target folder. */
2132 This
->m_dwDropEffectsMask
= DROPEFFECT_NONE
;
2133 InitFormatEtc(format
, cfShellIDList
, TYMED_HGLOBAL
);
2134 if ((This
->m_dwAttributes
& SFGAO_FILESYSTEM
) && /* Only drop to filesystem folders */
2135 _ILIsFolder(ILFindLastID(This
->m_pidlLocation
)) && /* Only drop to folders, not to files */
2136 SUCCEEDED(IDataObject_GetData(pDataObject
, &format
, &medium
))) /* Only ShellIDList format */
2138 LPIDA pidaShellIDList
= GlobalLock(medium
.u
.hGlobal
);
2139 This
->m_dwDropEffectsMask
|= DROPEFFECT_COPY
|DROPEFFECT_LINK
;
2141 if (pidaShellIDList
) { /* Files can only be moved between two different folders */
2142 if (!ILIsEqual(HIDA_GetPIDLFolder(pidaShellIDList
), This
->m_pidlLocation
))
2143 This
->m_dwDropEffectsMask
|= DROPEFFECT_MOVE
;
2144 GlobalUnlock(medium
.u
.hGlobal
);
2148 *pdwEffect
= KeyStateToDropEffect(dwKeyState
) & This
->m_dwDropEffectsMask
;
2153 static HRESULT WINAPI
UnixFolder_IDropTarget_DragOver(IDropTarget
*iface
, DWORD dwKeyState
,
2154 POINTL pt
, DWORD
*pdwEffect
)
2156 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IDropTarget
, iface
);
2158 TRACE("(iface=%p, dwKeyState=%08x, pt={.x=%d, .y=%d}, pdwEffect=%p)\n", iface
, dwKeyState
,
2159 pt
.x
, pt
.y
, pdwEffect
);
2162 return E_INVALIDARG
;
2164 *pdwEffect
= KeyStateToDropEffect(dwKeyState
) & This
->m_dwDropEffectsMask
;
2169 static HRESULT WINAPI
UnixFolder_IDropTarget_DragLeave(IDropTarget
*iface
) {
2170 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IDropTarget
, iface
);
2172 TRACE("(iface=%p)\n", iface
);
2174 This
->m_dwDropEffectsMask
= DROPEFFECT_NONE
;
2179 static HRESULT WINAPI
UnixFolder_IDropTarget_Drop(IDropTarget
*iface
, IDataObject
*pDataObject
,
2180 DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
2182 UnixFolder
*This
= ADJUST_THIS(UnixFolder
, IDropTarget
, iface
);
2187 TRACE("(iface=%p, pDataObject=%p, dwKeyState=%d, pt={.x=%d, .y=%d}, pdwEffect=%p) semi-stub\n",
2188 iface
, pDataObject
, dwKeyState
, pt
.x
, pt
.y
, pdwEffect
);
2190 InitFormatEtc(format
, cfShellIDList
, TYMED_HGLOBAL
);
2191 hr
= IDataObject_GetData(pDataObject
, &format
, &medium
);
2195 if (medium
.tymed
== TYMED_HGLOBAL
) {
2196 IShellFolder
*psfSourceFolder
, *psfDesktopFolder
;
2197 LPIDA pidaShellIDList
= GlobalLock(medium
.u
.hGlobal
);
2201 if (!pidaShellIDList
)
2202 return HRESULT_FROM_WIN32(GetLastError());
2204 hr
= SHGetDesktopFolder(&psfDesktopFolder
);
2206 GlobalUnlock(medium
.u
.hGlobal
);
2210 hr
= IShellFolder_BindToObject(psfDesktopFolder
, HIDA_GetPIDLFolder(pidaShellIDList
), NULL
,
2211 &IID_IShellFolder
, (LPVOID
*)&psfSourceFolder
);
2212 IShellFolder_Release(psfDesktopFolder
);
2214 GlobalUnlock(medium
.u
.hGlobal
);
2218 for (i
= 0; i
< pidaShellIDList
->cidl
; i
++) {
2219 WCHAR wszSourcePath
[MAX_PATH
];
2221 hr
= IShellFolder_GetDisplayNameOf(psfSourceFolder
, HIDA_GetPIDLItem(pidaShellIDList
, i
),
2222 SHGDN_FORPARSING
, &strret
);
2226 hr
= StrRetToBufW(&strret
, NULL
, wszSourcePath
, MAX_PATH
);
2230 switch (*pdwEffect
) {
2231 case DROPEFFECT_MOVE
:
2232 FIXME("Move %s to %s!\n", debugstr_w(wszSourcePath
), This
->m_pszPath
);
2234 case DROPEFFECT_COPY
:
2235 FIXME("Copy %s to %s!\n", debugstr_w(wszSourcePath
), This
->m_pszPath
);
2237 case DROPEFFECT_LINK
:
2238 FIXME("Link %s from %s!\n", debugstr_w(wszSourcePath
), This
->m_pszPath
);
2243 IShellFolder_Release(psfSourceFolder
);
2244 GlobalUnlock(medium
.u
.hGlobal
);
2251 /* VTable for UnixFolder's IDropTarget interface
2253 static const IDropTargetVtbl UnixFolder_IDropTarget_Vtbl
= {
2254 UnixFolder_IDropTarget_QueryInterface
,
2255 UnixFolder_IDropTarget_AddRef
,
2256 UnixFolder_IDropTarget_Release
,
2257 UnixFolder_IDropTarget_DragEnter
,
2258 UnixFolder_IDropTarget_DragOver
,
2259 UnixFolder_IDropTarget_DragLeave
,
2260 UnixFolder_IDropTarget_Drop
2263 /******************************************************************************
2264 * Unix[Dos]Folder_Constructor [Internal]
2267 * pUnkOuter [I] Outer class for aggregation. Currently ignored.
2268 * riid [I] Interface asked for by the client.
2269 * ppv [O] Pointer to an riid interface to the UnixFolder object.
2272 * Those are the only functions exported from shfldr_unixfs.c. They are called from
2273 * shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
2274 * compatible signature.
2276 * The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
2277 * means that paths are converted from dos to unix and back at the interfaces.
2279 static HRESULT
CreateUnixFolder(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
, const CLSID
*pCLSID
)
2281 HRESULT hr
= E_FAIL
;
2282 UnixFolder
*pUnixFolder
;
2285 FIXME("Aggregation not yet implemented!\n");
2286 return CLASS_E_NOAGGREGATION
;
2289 pUnixFolder
= SHAlloc((ULONG
)sizeof(UnixFolder
));
2292 pUnixFolder
->lpIShellFolder2Vtbl
= &UnixFolder_IShellFolder2_Vtbl
;
2293 pUnixFolder
->lpIPersistFolder3Vtbl
= &UnixFolder_IPersistFolder3_Vtbl
;
2294 pUnixFolder
->lpIPersistPropertyBagVtbl
= &UnixFolder_IPersistPropertyBag_Vtbl
;
2295 pUnixFolder
->lpISFHelperVtbl
= &UnixFolder_ISFHelper_Vtbl
;
2296 pUnixFolder
->lpIDropTargetVtbl
= &UnixFolder_IDropTarget_Vtbl
;
2297 pUnixFolder
->m_cRef
= 0;
2298 pUnixFolder
->m_pszPath
= NULL
;
2299 pUnixFolder
->m_pidlLocation
= NULL
;
2300 pUnixFolder
->m_dwPathMode
= IsEqualCLSID(&CLSID_UnixFolder
, pCLSID
) ? PATHMODE_UNIX
: PATHMODE_DOS
;
2301 pUnixFolder
->m_dwAttributes
= 0;
2302 pUnixFolder
->m_pCLSID
= pCLSID
;
2303 pUnixFolder
->m_dwDropEffectsMask
= DROPEFFECT_NONE
;
2305 UnixFolder_IShellFolder2_AddRef(STATIC_CAST(IShellFolder2
, pUnixFolder
));
2306 hr
= UnixFolder_IShellFolder2_QueryInterface(STATIC_CAST(IShellFolder2
, pUnixFolder
), riid
, ppv
);
2307 UnixFolder_IShellFolder2_Release(STATIC_CAST(IShellFolder2
, pUnixFolder
));
2312 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
2313 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
2314 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_UnixFolder
);
2317 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
2318 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
2319 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_UnixDosFolder
);
2322 HRESULT WINAPI
FolderShortcut_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
2323 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
2324 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_FolderShortcut
);
2327 HRESULT WINAPI
MyDocuments_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
) {
2328 TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter
, riid
, ppv
);
2329 return CreateUnixFolder(pUnkOuter
, riid
, ppv
, &CLSID_MyDocuments
);
2332 /******************************************************************************
2333 * UnixSubFolderIterator
2335 * Class whose heap based objects represent iterators over the sub-directories
2336 * of a given UnixFolder object.
2339 /* UnixSubFolderIterator object layout and typedef.
2341 typedef struct _UnixSubFolderIterator
{
2342 const IEnumIDListVtbl
*lpIEnumIDListVtbl
;
2346 char m_szFolder
[FILENAME_MAX
];
2347 } UnixSubFolderIterator
;
2349 static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator
*iterator
) {
2350 TRACE("(iterator=%p)\n", iterator
);
2352 if (iterator
->m_dirFolder
)
2353 closedir(iterator
->m_dirFolder
);
2357 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList
* iface
,
2358 REFIID riid
, void** ppv
)
2360 TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface
, riid
, ppv
);
2362 if (!ppv
) return E_INVALIDARG
;
2364 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumIDList
, riid
)) {
2368 return E_NOINTERFACE
;
2371 IEnumIDList_AddRef(iface
);
2375 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList
* iface
)
2377 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
2379 TRACE("(iface=%p)\n", iface
);
2381 return InterlockedIncrement(&This
->m_cRef
);
2384 static ULONG WINAPI
UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList
* iface
)
2386 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
2389 TRACE("(iface=%p)\n", iface
);
2391 cRef
= InterlockedDecrement(&This
->m_cRef
);
2394 UnixSubFolderIterator_Destroy(This
);
2399 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList
* iface
, ULONG celt
,
2400 LPITEMIDLIST
* rgelt
, ULONG
* pceltFetched
)
2402 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
2405 /* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
2406 if (This
->m_dirFolder
) {
2407 char *pszRelativePath
= This
->m_szFolder
+ lstrlenA(This
->m_szFolder
);
2408 struct dirent
*pDirEntry
;
2411 pDirEntry
= readdir(This
->m_dirFolder
);
2412 if (!pDirEntry
) break; /* No more entries */
2413 if (!strcmp(pDirEntry
->d_name
, ".") || !strcmp(pDirEntry
->d_name
, "..")) continue;
2415 /* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
2416 * and see if it passes the filter.
2418 lstrcpyA(pszRelativePath
, pDirEntry
->d_name
);
2420 UNIXFS_shitemid_len_from_filename(pszRelativePath
, NULL
, NULL
)+sizeof(USHORT
));
2421 if (!UNIXFS_build_shitemid(This
->m_szFolder
, NULL
, rgelt
[i
]) ||
2422 !UNIXFS_is_pidl_of_type(rgelt
[i
], This
->m_fFilter
))
2427 memset(((PBYTE
)rgelt
[i
])+rgelt
[i
]->mkid
.cb
, 0, sizeof(USHORT
));
2430 *pszRelativePath
= '\0'; /* Restore the original path in This->m_szFolder. */
2436 return (i
== 0) ? S_FALSE
: S_OK
;
2439 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList
* iface
, ULONG celt
)
2441 LPITEMIDLIST
*apidl
;
2445 TRACE("(iface=%p, celt=%d)\n", iface
, celt
);
2447 /* Call IEnumIDList::Next and delete the resulting pidls. */
2448 apidl
= SHAlloc(celt
* sizeof(LPITEMIDLIST
));
2449 hr
= IEnumIDList_Next(iface
, celt
, apidl
, &cFetched
);
2452 SHFree(apidl
[cFetched
]);
2458 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList
* iface
)
2460 UnixSubFolderIterator
*This
= ADJUST_THIS(UnixSubFolderIterator
, IEnumIDList
, iface
);
2462 TRACE("(iface=%p)\n", iface
);
2464 if (This
->m_dirFolder
)
2465 rewinddir(This
->m_dirFolder
);
2470 static HRESULT WINAPI
UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList
* This
,
2471 IEnumIDList
** ppenum
)
2477 /* VTable for UnixSubFolderIterator's IEnumIDList interface.
2479 static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl
= {
2480 UnixSubFolderIterator_IEnumIDList_QueryInterface
,
2481 UnixSubFolderIterator_IEnumIDList_AddRef
,
2482 UnixSubFolderIterator_IEnumIDList_Release
,
2483 UnixSubFolderIterator_IEnumIDList_Next
,
2484 UnixSubFolderIterator_IEnumIDList_Skip
,
2485 UnixSubFolderIterator_IEnumIDList_Reset
,
2486 UnixSubFolderIterator_IEnumIDList_Clone
2489 static IUnknown
*UnixSubFolderIterator_Constructor(UnixFolder
*pUnixFolder
, SHCONTF fFilter
) {
2490 UnixSubFolderIterator
*iterator
;
2492 TRACE("(pUnixFolder=%p)\n", pUnixFolder
);
2494 iterator
= SHAlloc((ULONG
)sizeof(UnixSubFolderIterator
));
2495 iterator
->lpIEnumIDListVtbl
= &UnixSubFolderIterator_IEnumIDList_Vtbl
;
2496 iterator
->m_cRef
= 0;
2497 iterator
->m_fFilter
= fFilter
;
2498 iterator
->m_dirFolder
= opendir(pUnixFolder
->m_pszPath
);
2499 lstrcpyA(iterator
->m_szFolder
, pUnixFolder
->m_pszPath
);
2501 UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList
*)iterator
);
2503 return (IUnknown
*)iterator
;
2506 #else /* __MINGW32__ || _MSC_VER */
2508 HRESULT WINAPI
UnixFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
)
2513 HRESULT WINAPI
UnixDosFolder_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
)
2518 HRESULT WINAPI
FolderShortcut_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
)
2523 HRESULT WINAPI
MyDocuments_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppv
)
2528 #endif /* __MINGW32__ || _MSC_VER */
2530 /******************************************************************************
2531 * UNIXFS_is_rooted_at_desktop [Internal]
2533 * Checks if the unixfs namespace extension is rooted at desktop level.
2536 * TRUE, if unixfs is rooted at desktop level
2539 BOOL
UNIXFS_is_rooted_at_desktop(void) {
2541 WCHAR wszRootedAtDesktop
[69 + CHARS_IN_GUID
] = {
2542 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
2543 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2544 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
2545 'N','a','m','e','S','p','a','c','e','\\',0 };
2547 if (StringFromGUID2(&CLSID_UnixDosFolder
, wszRootedAtDesktop
+ 69, CHARS_IN_GUID
) &&
2548 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszRootedAtDesktop
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)