2005-03-09 17:41:17 +01:00
|
|
|
/*
|
|
|
|
* UNIXFS - Shell namespace extension for the unix filesystem
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Michael Jung
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-09 17:41:17 +01:00
|
|
|
*/
|
|
|
|
|
2005-11-02 12:43:20 +01:00
|
|
|
/*
|
|
|
|
* As you know, windows and unix do have a different philosophy with regard to
|
|
|
|
* the question of how a filesystem should be laid out. While we unix geeks
|
|
|
|
* learned to love the 'one-tree-rooted-at-/' approach, windows has in fact
|
|
|
|
* a whole forest of filesystem trees, each of which is typically identified by
|
|
|
|
* a drive letter.
|
|
|
|
*
|
|
|
|
* We would like wine to integrate as smoothly as possible (that is without
|
|
|
|
* sacrificing win32 compatibility) into the unix environment. For the
|
|
|
|
* filesystem question, this means we really would like those windows
|
|
|
|
* applications to work with unix path- and file-names. Unfortunately, this
|
|
|
|
* seems to be impossible in general. Therefore we have those symbolic links
|
|
|
|
* in wine's 'dosdevices' directory, which are used to simulate drives
|
|
|
|
* to keep windows applications happy. And as a consequence, we have those
|
|
|
|
* drive letters show up now and then in GUI applications running under wine,
|
|
|
|
* which gets the unix hardcore fans all angry, shouting at us @#!&$%* wine
|
|
|
|
* hackers that we are seducing the big companies not to port their applications
|
|
|
|
* to unix.
|
|
|
|
*
|
|
|
|
* DOS paths do appear at various places in GUI applications. Sometimes, they
|
|
|
|
* show up in the title bar of an application's window. They tend to accumulate
|
|
|
|
* in the most-recently-used section of the file-menu. And I've even seen some
|
|
|
|
* in a configuration dialog's edit control. In those examples, wine can't do a
|
2008-01-16 12:20:50 +01:00
|
|
|
* lot about this, since path-names can't be told apart from ordinary strings
|
2005-11-02 12:43:20 +01:00
|
|
|
* here. That's different in the file dialogs, though.
|
|
|
|
*
|
|
|
|
* With the introduction of the 'shell' in win32, Microsoft established an
|
|
|
|
* abstraction layer on top of the filesystem, called the shell namespace (I was
|
2012-05-15 10:15:32 +02:00
|
|
|
* told that GNOME's virtual filesystem is conceptually similar). In the shell
|
2005-11-02 12:43:20 +01:00
|
|
|
* namespace, one doesn't use ascii- or unicode-strings to uniquely identify
|
|
|
|
* objects. Instead Microsoft introduced item-identifier-lists (The c type is
|
|
|
|
* called ITEMIDLIST) as an abstraction of path-names. As you probably would
|
|
|
|
* have guessed, an item-identifier-list is a list of item-identifiers (whose
|
|
|
|
* c type's funny name is SHITEMID), which are opaque binary objects. This means
|
|
|
|
* that no application (apart from Microsoft Office) should make any assumptions
|
|
|
|
* on the internal structure of these SHITEMIDs.
|
|
|
|
*
|
|
|
|
* Since the user prefers to be presented the good-old DOS file-names instead of
|
|
|
|
* binary ITEMIDLISTs, a translation method between string-based file-names and
|
|
|
|
* ITEMIDLISTs was established. At the core of this are the COM-Interface
|
|
|
|
* IShellFolder and especially it's methods ParseDisplayName and
|
|
|
|
* GetDisplayNameOf. Basically, you give a DOS-path (let's say C:\windows) to
|
|
|
|
* ParseDisplayName and get a SHITEMID similar to <Desktop|My Computer|C:|windows|>.
|
|
|
|
* Since it's opaque, you can't see the 'C', the 'windows' and the other stuff.
|
|
|
|
* You can only figure out that the ITEMIDLIST is composed of four SHITEMIDS.
|
|
|
|
* The file dialog applies IShellFolder's BindToObject method to bind to each of
|
|
|
|
* those four objects (Desktop, My Computer, C: and windows. All of them have to
|
|
|
|
* implement the IShellFolder interface.) and asks them how they would like to be
|
|
|
|
* displayed (basically their icon and the string displayed). If the file dialog
|
|
|
|
* asks <Desktop|My Computer|C:|windows> which sub-objects it contains (via
|
|
|
|
* EnumObjects) it gets a list of opaque SHITEMIDs, which can be concatenated to
|
|
|
|
* <Desktop|...|windows> to build a new ITEMIDLIST and browse, for instance,
|
|
|
|
* into <system32>. This means the file dialog browses the shell namespace by
|
|
|
|
* identifying objects via ITEMIDLISTs. Once the user has selected a location to
|
|
|
|
* save his valuable file, the file dialog calls IShellFolder's GetDisplayNameOf
|
|
|
|
* method to translate the ITEMIDLIST back to a DOS filename.
|
|
|
|
*
|
|
|
|
* It seems that one intention of the shell namespace concept was to make it
|
|
|
|
* possible to have objects in the namespace, which don't have any counterpart
|
|
|
|
* in the filesystem. The 'My Computer' shell folder object is one instance
|
|
|
|
* which comes to mind (Go try to save a file into 'My Computer' on windows.)
|
|
|
|
* So, to make matters a little more complex, before the file dialog asks a
|
|
|
|
* shell namespace object for it's DOS path, it asks if it actually has one.
|
|
|
|
* This is done via the IShellFolder::GetAttributesOf method, which sets the
|
|
|
|
* SFGAO_FILESYSTEM if - and only if - it has.
|
|
|
|
*
|
|
|
|
* The two things, described in the previous two paragraphs, are what unixfs is
|
|
|
|
* based on. So basically, if UnixDosFolder's ParseDisplayName method is called
|
|
|
|
* with a 'c:\windows' path-name, it doesn't return an
|
|
|
|
* <Desktop|My Computer|C:|windows|> ITEMIDLIST. Instead, it uses
|
|
|
|
* shell32's wine_get_unix_path_name and the _posix_ (which means not the win32)
|
|
|
|
* fileio api's to figure out that c: is mapped to - let's say -
|
|
|
|
* /home/mjung/.wine/drive_c and then constructs a
|
|
|
|
* <Desktop|/|home|mjung|.wine|drive_c> ITEMIDLIST. Which is what the file
|
|
|
|
* dialog uses to display the folder and file objects, which is why you see a
|
|
|
|
* unix path. When the user has found a nice place for his file and hits the
|
|
|
|
* save button, the ITEMIDLIST of the selected folder object is passed to
|
|
|
|
* GetDisplayNameOf, which returns a _DOS_ path name
|
|
|
|
* (like H:\home_of_my_new_file out of <|Desktop|/|home|mjung|home_of_my_new_file|>).
|
|
|
|
* Unixfs basically mounts your dos devices together in order to construct
|
|
|
|
* a copy of your unix filesystem structure.
|
|
|
|
*
|
|
|
|
* But what if none of the symbolic links in 'dosdevices' points to '/', you
|
|
|
|
* might ask ("And I don't want wine have access to my complete hard drive, you
|
|
|
|
* *%&1#!"). No problem, as I stated above, unixfs uses the _posix_ apis to
|
|
|
|
* construct the ITEMIDLISTs. Folders, which aren't accessible via a drive letter,
|
2008-01-16 12:20:50 +01:00
|
|
|
* don't have the SFGAO_FILESYSTEM flag set. So the file dialogs shouldn't allow
|
2005-11-02 12:43:20 +01:00
|
|
|
* the user to select such a folder for file storage (And if it does anyhow, it
|
|
|
|
* will not be able to return a valid path, since there is none). Think of those
|
|
|
|
* folders as a hierarchy of 'My Computer'-like folders, which happen to be a
|
|
|
|
* shadow of your unix filesystem tree. And since all of this stuff doesn't
|
|
|
|
* change anything at all in wine's fileio api's, windows applications will have
|
|
|
|
* no more access rights as they had before.
|
|
|
|
*
|
2008-01-16 12:20:50 +01:00
|
|
|
* To sum it all up, you can still safely run wine with you root account (Just
|
2005-11-02 12:43:20 +01:00
|
|
|
* kidding, don't do it.)
|
|
|
|
*
|
|
|
|
* If you are now standing in front of your computer, shouting hotly
|
|
|
|
* "I am not convinced, Mr. Rumsfeld^H^H^H^H^H^H^H^H^H^H^H^H", fire up regedit
|
|
|
|
* and delete HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\
|
|
|
|
* Explorer\Desktop\Namespace\{9D20AAE8-0625-44B0-9CA7-71889C2254D9} and you
|
|
|
|
* will be back in the pre-unixfs days.
|
|
|
|
*/
|
|
|
|
|
2005-05-06 18:22:54 +02:00
|
|
|
#include "config.h"
|
2005-08-03 23:25:10 +02:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2005-04-27 10:12:08 +02:00
|
|
|
#include <limits.h>
|
2010-07-21 21:04:22 +02:00
|
|
|
#include <errno.h>
|
2008-10-19 18:55:13 +02:00
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
# include <dirent.h>
|
|
|
|
#endif
|
2006-01-31 12:20:58 +01:00
|
|
|
#include <stdlib.h>
|
2005-06-17 22:56:02 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2005-05-06 18:22:54 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
# include <pwd.h>
|
|
|
|
#endif
|
2008-12-09 17:09:42 +01:00
|
|
|
#ifdef HAVE_GRP_H
|
|
|
|
# include <grp.h>
|
|
|
|
#endif
|
2005-03-09 17:41:17 +01:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "objbase.h"
|
2005-04-25 12:56:29 +02:00
|
|
|
#include "winreg.h"
|
2005-06-17 14:12:35 +02:00
|
|
|
#include "shlwapi.h"
|
2005-04-25 12:56:29 +02:00
|
|
|
#include "winternl.h"
|
2005-03-09 17:41:17 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "shell32_main.h"
|
2005-07-05 22:55:43 +02:00
|
|
|
#include "shellfolder.h"
|
2005-04-12 13:58:05 +02:00
|
|
|
#include "shfldr.h"
|
|
|
|
#include "shresdef.h"
|
2005-04-22 23:29:17 +02:00
|
|
|
#include "pidl.h"
|
2010-03-05 13:04:58 +01:00
|
|
|
#include "debughlp.h"
|
2005-03-09 17:41:17 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
2008-12-09 17:10:10 +01:00
|
|
|
#if !defined(__MINGW32__) && !defined(_MSC_VER)
|
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
#define ADJUST_THIS(c,m,p) ((c*)(((long)p)-(long)&(((c*)0)->lp##m##Vtbl)))
|
|
|
|
#define STATIC_CAST(i,p) ((i*)&p->lp##i##Vtbl)
|
|
|
|
|
2006-01-03 13:23:59 +01:00
|
|
|
#define LEN_SHITEMID_FIXED_PART ((USHORT) \
|
|
|
|
( sizeof(USHORT) /* SHITEMID's cb field. */ \
|
|
|
|
+ sizeof(PIDLTYPE) /* PIDLDATA's type field. */ \
|
|
|
|
+ sizeof(FileStruct) /* Well, the FileStruct. */ \
|
|
|
|
- sizeof(char) /* One char too much in FileStruct. */ \
|
|
|
|
+ sizeof(FileStructW) /* You name it. */ \
|
|
|
|
- sizeof(WCHAR) /* One WCHAR too much in FileStructW. */ \
|
|
|
|
+ sizeof(WORD) )) /* Offset of FileStructW field in PIDL. */
|
2005-04-25 12:56:29 +02:00
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
#define PATHMODE_UNIX 0
|
|
|
|
#define PATHMODE_DOS 1
|
|
|
|
|
2010-07-21 21:04:22 +02:00
|
|
|
static const WCHAR wFileSystemBindData[] = {
|
|
|
|
'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
typedef struct {
|
|
|
|
IShellFolder2 IShellFolder2_iface;
|
|
|
|
IPersistFolder3 IPersistFolder3_iface;
|
|
|
|
IPersistPropertyBag IPersistPropertyBag_iface;
|
|
|
|
IDropTarget IDropTarget_iface;
|
|
|
|
ISFHelper ISFHelper_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
2006-01-03 13:23:59 +01:00
|
|
|
CHAR *m_pszPath; /* Target path of the shell folder (CP_UNIXCP) */
|
2005-11-05 11:44:28 +01:00
|
|
|
LPITEMIDLIST m_pidlLocation; /* Location in the shell namespace */
|
2005-11-28 20:40:50 +01:00
|
|
|
DWORD m_dwPathMode;
|
|
|
|
DWORD m_dwAttributes;
|
|
|
|
const CLSID *m_pCLSID;
|
|
|
|
DWORD m_dwDropEffectsMask;
|
2005-05-24 13:45:47 +02:00
|
|
|
} UnixFolder;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static inline UnixFolder *impl_from_IShellFolder2(IShellFolder2 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, UnixFolder, IShellFolder2_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline UnixFolder *impl_from_IPersistFolder3(IPersistFolder3 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, UnixFolder, IPersistFolder3_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline UnixFolder *impl_from_IPersistPropertyBag(IPersistPropertyBag *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, UnixFolder, IPersistPropertyBag_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline UnixFolder *impl_from_ISFHelper(ISFHelper *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, UnixFolder, ISFHelper_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline UnixFolder *impl_from_IDropTarget(IDropTarget *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, UnixFolder, IDropTarget_iface);
|
|
|
|
}
|
|
|
|
|
2005-11-28 20:40:50 +01:00
|
|
|
/* Will hold the registered clipboard format identifier for ITEMIDLISTS. */
|
|
|
|
static UINT cfShellIDList = 0;
|
|
|
|
|
2005-04-25 12:56:29 +02:00
|
|
|
/******************************************************************************
|
2006-01-03 13:23:59 +01:00
|
|
|
* UNIXFS_filename_from_shitemid [Internal]
|
|
|
|
*
|
|
|
|
* Get CP_UNIXCP encoded filename corresponding to the first item of a pidl
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pidl [I] A simple SHITEMID
|
|
|
|
* pszPathElement [O] Filename in CP_UNIXCP encoding will be stored here
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Number of bytes necessary to store the CP_UNIXCP encoded filename
|
|
|
|
* _without_ the terminating NUL.
|
|
|
|
* Failure: 0
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Size of the buffer at pszPathElement has to be FILENAME_MAX. pszPathElement
|
|
|
|
* may be NULL, if you are only interested in the return value.
|
|
|
|
*/
|
|
|
|
static int UNIXFS_filename_from_shitemid(LPCITEMIDLIST pidl, char* pszPathElement) {
|
|
|
|
FileStructW *pFileStructW = _ILGetFileStructW(pidl);
|
|
|
|
int cLen = 0;
|
|
|
|
|
|
|
|
if (pFileStructW) {
|
|
|
|
cLen = WideCharToMultiByte(CP_UNIXCP, 0, pFileStructW->wszName, -1, pszPathElement,
|
|
|
|
pszPathElement ? FILENAME_MAX : 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
/* There might be pidls slipping in from shfldr_fs.c, which don't contain the
|
|
|
|
* FileStructW field. In this case, we have to convert from CP_ACP to CP_UNIXCP. */
|
|
|
|
char *pszText = _ILGetTextPointer(pidl);
|
|
|
|
WCHAR *pwszPathElement = NULL;
|
|
|
|
int cWideChars;
|
|
|
|
|
|
|
|
cWideChars = MultiByteToWideChar(CP_ACP, 0, pszText, -1, NULL, 0);
|
|
|
|
if (!cWideChars) goto cleanup;
|
|
|
|
|
|
|
|
pwszPathElement = SHAlloc(cWideChars * sizeof(WCHAR));
|
|
|
|
if (!pwszPathElement) goto cleanup;
|
|
|
|
|
|
|
|
cWideChars = MultiByteToWideChar(CP_ACP, 0, pszText, -1, pwszPathElement, cWideChars);
|
|
|
|
if (!cWideChars) goto cleanup;
|
|
|
|
|
|
|
|
cLen = WideCharToMultiByte(CP_UNIXCP, 0, pwszPathElement, -1, pszPathElement,
|
|
|
|
pszPathElement ? FILENAME_MAX : 0, 0, 0);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
SHFree(pwszPathElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cLen) cLen--; /* Don't count terminating NUL! */
|
|
|
|
return cLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_shitemid_len_from_filename [Internal]
|
|
|
|
*
|
|
|
|
* Computes the necessary length of a pidl to hold a path element
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* szPathElement [I] The path element string in CP_UNIXCP encoding.
|
|
|
|
* ppszPathElement [O] Path element string in CP_ACP encoding.
|
|
|
|
* ppwszPathElement [O] Path element string as WCHAR string.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Length in bytes of a SHITEMID representing szPathElement
|
|
|
|
* Failure: 0
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Provide NULL values if not interested in pp(w)szPathElement. Otherwise
|
|
|
|
* caller is responsible to free ppszPathElement and ppwszPathElement with
|
|
|
|
* SHFree.
|
|
|
|
*/
|
|
|
|
static USHORT UNIXFS_shitemid_len_from_filename(
|
|
|
|
const char *szPathElement, char **ppszPathElement, WCHAR **ppwszPathElement)
|
|
|
|
{
|
|
|
|
USHORT cbPidlLen = 0;
|
|
|
|
WCHAR *pwszPathElement = NULL;
|
|
|
|
char *pszPathElement = NULL;
|
|
|
|
int cWideChars, cChars;
|
|
|
|
|
|
|
|
/* There and Back Again: A Hobbit's Holiday. CP_UNIXCP might be some ANSI
|
|
|
|
* codepage or it might be a real multi-byte encoding like utf-8. There is no
|
|
|
|
* other way to figure out the length of the corresponding WCHAR and CP_ACP
|
|
|
|
* strings without actually doing the full CP_UNIXCP -> WCHAR -> CP_ACP cycle. */
|
|
|
|
|
|
|
|
cWideChars = MultiByteToWideChar(CP_UNIXCP, 0, szPathElement, -1, NULL, 0);
|
|
|
|
if (!cWideChars) goto cleanup;
|
|
|
|
|
|
|
|
pwszPathElement = SHAlloc(cWideChars * sizeof(WCHAR));
|
|
|
|
if (!pwszPathElement) goto cleanup;
|
|
|
|
|
|
|
|
cWideChars = MultiByteToWideChar(CP_UNIXCP, 0, szPathElement, -1, pwszPathElement, cWideChars);
|
|
|
|
if (!cWideChars) goto cleanup;
|
|
|
|
|
|
|
|
cChars = WideCharToMultiByte(CP_ACP, 0, pwszPathElement, -1, NULL, 0, 0, 0);
|
|
|
|
if (!cChars) goto cleanup;
|
|
|
|
|
|
|
|
pszPathElement = SHAlloc(cChars);
|
|
|
|
if (!pszPathElement) goto cleanup;
|
|
|
|
|
|
|
|
cChars = WideCharToMultiByte(CP_ACP, 0, pwszPathElement, -1, pszPathElement, cChars, 0, 0);
|
|
|
|
if (!cChars) goto cleanup;
|
|
|
|
|
|
|
|
/* (cChars & 0x1) is for the potential alignment byte */
|
|
|
|
cbPidlLen = LEN_SHITEMID_FIXED_PART + cChars + (cChars & 0x1) + cWideChars * sizeof(WCHAR);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (cbPidlLen && ppszPathElement)
|
|
|
|
*ppszPathElement = pszPathElement;
|
|
|
|
else
|
|
|
|
SHFree(pszPathElement);
|
|
|
|
|
|
|
|
if (cbPidlLen && ppwszPathElement)
|
|
|
|
*ppwszPathElement = pwszPathElement;
|
|
|
|
else
|
|
|
|
SHFree(pwszPathElement);
|
|
|
|
|
|
|
|
return cbPidlLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_is_pidl_of_type [Internal]
|
2005-04-25 12:56:29 +02:00
|
|
|
*
|
|
|
|
* Checks for the first SHITEMID of an ITEMIDLIST if it passes a filter.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pIDL [I] The ITEMIDLIST to be checked.
|
|
|
|
* fFilter [I] Shell condition flags, which specify the filter.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE, if pIDL is accepted by fFilter
|
|
|
|
* FALSE, otherwise
|
|
|
|
*/
|
2007-10-29 22:51:02 +01:00
|
|
|
static inline BOOL UNIXFS_is_pidl_of_type(LPCITEMIDLIST pIDL, SHCONTF fFilter) {
|
|
|
|
const PIDLDATA *pIDLData = _ILGetDataPointer(pIDL);
|
2005-06-10 21:31:59 +02:00
|
|
|
if (!(fFilter & SHCONTF_INCLUDEHIDDEN) && pIDLData &&
|
|
|
|
(pIDLData->u.file.uFileAttribs & FILE_ATTRIBUTE_HIDDEN))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-25 12:56:29 +02:00
|
|
|
if (_ILIsFolder(pIDL) && (fFilter & SHCONTF_FOLDERS)) return TRUE;
|
|
|
|
if (_ILIsValue(pIDL) && (fFilter & SHCONTF_NONFOLDERS)) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-04-22 23:29:17 +02:00
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
/******************************************************************************
|
2005-06-06 21:37:47 +02:00
|
|
|
* UNIXFS_get_unix_path [Internal]
|
2005-05-24 13:45:47 +02:00
|
|
|
*
|
2006-01-31 12:20:58 +01:00
|
|
|
* Convert an absolute dos path to an absolute unix path.
|
|
|
|
* Evaluate "/.", "/.." and the symbolic links in $WINEPREFIX/dosdevices.
|
2005-05-24 13:45:47 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2005-06-06 21:37:47 +02:00
|
|
|
* pszDosPath [I] An absolute dos path
|
2005-05-24 13:45:47 +02:00
|
|
|
* pszCanonicalPath [O] Buffer of length FILENAME_MAX. Will receive the canonical path.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success, TRUE
|
2013-10-29 15:57:31 +01:00
|
|
|
* Failure, FALSE - Path not existent, too long, insufficient rights, too many symlinks
|
2005-05-24 13:45:47 +02:00
|
|
|
*/
|
2005-06-06 21:37:47 +02:00
|
|
|
static BOOL UNIXFS_get_unix_path(LPCWSTR pszDosPath, char *pszCanonicalPath)
|
2005-05-24 13:45:47 +02:00
|
|
|
{
|
2013-10-01 00:06:50 +02:00
|
|
|
char *pPathTail, *pElement, *pCanonicalTail, szPath[FILENAME_MAX], *pszUnixPath, mb_path[FILENAME_MAX];
|
|
|
|
BOOL has_failed = FALSE;
|
2011-10-24 19:18:16 +02:00
|
|
|
WCHAR wszDrive[] = { '?', ':', '\\', 0 }, dospath[MAX_PATH], *dospath_end;
|
2006-01-31 12:20:58 +01:00
|
|
|
int cDriveSymlinkLen;
|
2011-07-29 01:29:39 +02:00
|
|
|
void *redir;
|
|
|
|
|
2005-06-06 21:37:47 +02:00
|
|
|
TRACE("(pszDosPath=%s, pszCanonicalPath=%p)\n", debugstr_w(pszDosPath), pszCanonicalPath);
|
2006-02-02 13:20:49 +01:00
|
|
|
|
2005-06-06 21:37:47 +02:00
|
|
|
if (!pszDosPath || pszDosPath[1] != ':')
|
2005-05-24 13:45:47 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2006-01-31 12:20:58 +01:00
|
|
|
/* Get the canonicalized unix path corresponding to the drive letter. */
|
|
|
|
wszDrive[0] = pszDosPath[0];
|
|
|
|
pszUnixPath = wine_get_unix_file_name(wszDrive);
|
|
|
|
if (!pszUnixPath) return FALSE;
|
|
|
|
cDriveSymlinkLen = strlen(pszUnixPath);
|
2006-02-02 13:20:49 +01:00
|
|
|
pElement = realpath(pszUnixPath, szPath);
|
2006-01-31 12:20:58 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pszUnixPath);
|
|
|
|
if (!pElement) return FALSE;
|
2006-01-31 18:03:45 +01:00
|
|
|
if (szPath[strlen(szPath)-1] != '/') strcat(szPath, "/");
|
2006-01-31 12:20:58 +01:00
|
|
|
|
|
|
|
/* Append the part relative to the drive symbolic link target. */
|
2010-11-11 22:58:12 +01:00
|
|
|
lstrcpyW(dospath, pszDosPath);
|
|
|
|
dospath_end = dospath + lstrlenW(dospath);
|
2010-11-17 18:56:13 +01:00
|
|
|
/* search for the most valid UNIX path possible, then append missing
|
|
|
|
* path parts */
|
2011-07-29 01:29:39 +02:00
|
|
|
Wow64DisableWow64FsRedirection(&redir);
|
2010-11-11 22:58:12 +01:00
|
|
|
while(!(pszUnixPath = wine_get_unix_file_name(dospath))){
|
2010-11-17 18:56:13 +01:00
|
|
|
if(has_failed){
|
2010-11-11 22:58:12 +01:00
|
|
|
*dospath_end = '/';
|
2010-11-17 18:56:13 +01:00
|
|
|
--dospath_end;
|
|
|
|
}else
|
2013-10-01 00:06:50 +02:00
|
|
|
has_failed = TRUE;
|
2010-11-17 18:56:13 +01:00
|
|
|
while(*dospath_end != '\\' && *dospath_end != '/'){
|
2010-11-11 22:58:12 +01:00
|
|
|
--dospath_end;
|
2010-11-17 18:56:13 +01:00
|
|
|
if(dospath_end < dospath)
|
|
|
|
break;
|
|
|
|
}
|
2010-11-11 22:58:12 +01:00
|
|
|
*dospath_end = '\0';
|
|
|
|
}
|
2011-07-29 01:29:39 +02:00
|
|
|
Wow64RevertWow64FsRedirection(redir);
|
2010-11-17 18:56:13 +01:00
|
|
|
if(dospath_end < dospath)
|
|
|
|
return FALSE;
|
2006-01-31 12:20:58 +01:00
|
|
|
strcat(szPath, pszUnixPath + cDriveSymlinkLen);
|
2005-06-06 21:37:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pszUnixPath);
|
2010-11-11 22:58:12 +01:00
|
|
|
|
|
|
|
if(has_failed && WideCharToMultiByte(CP_UNIXCP, 0, dospath_end + 1, -1,
|
|
|
|
mb_path, FILENAME_MAX, NULL, NULL) > 0){
|
|
|
|
strcat(szPath, "/");
|
|
|
|
strcat(szPath, mb_path);
|
|
|
|
}
|
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
/* pCanonicalTail always points to the end of the canonical path constructed
|
|
|
|
* thus far. pPathTail points to the still to be processed part of the input
|
|
|
|
* path. pElement points to the path element currently investigated.
|
|
|
|
*/
|
|
|
|
*pszCanonicalPath = '\0';
|
|
|
|
pCanonicalTail = pszCanonicalPath;
|
|
|
|
pPathTail = szPath;
|
|
|
|
|
|
|
|
do {
|
|
|
|
char cTemp;
|
|
|
|
|
|
|
|
pElement = pPathTail;
|
|
|
|
pPathTail = strchr(pPathTail+1, '/');
|
|
|
|
if (!pPathTail) /* Last path element may not be terminated by '/'. */
|
|
|
|
pPathTail = pElement + strlen(pElement);
|
|
|
|
/* Temporarily terminate the current path element. Will be restored later. */
|
|
|
|
cTemp = *pPathTail;
|
|
|
|
*pPathTail = '\0';
|
|
|
|
|
|
|
|
/* Skip "/." path elements */
|
|
|
|
if (!strcmp("/.", pElement)) {
|
|
|
|
*pPathTail = cTemp;
|
2006-01-31 12:20:58 +01:00
|
|
|
} else if (!strcmp("/..", pElement)) {
|
|
|
|
/* Remove last element in canonical path for "/.." elements, then skip. */
|
2005-05-24 13:45:47 +02:00
|
|
|
char *pTemp = strrchr(pszCanonicalPath, '/');
|
|
|
|
if (pTemp)
|
|
|
|
pCanonicalTail = pTemp;
|
|
|
|
*pCanonicalTail = '\0';
|
|
|
|
*pPathTail = cTemp;
|
|
|
|
} else {
|
2006-01-31 12:20:58 +01:00
|
|
|
/* Directory or file. Copy to canonical path */
|
2005-05-24 13:45:47 +02:00
|
|
|
if (pCanonicalTail - pszCanonicalPath + pPathTail - pElement + 1 > FILENAME_MAX)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy(pCanonicalTail, pElement, pPathTail - pElement + 1);
|
|
|
|
pCanonicalTail += pPathTail - pElement;
|
|
|
|
*pPathTail = cTemp;
|
|
|
|
}
|
2005-06-30 12:59:51 +02:00
|
|
|
} while (pPathTail[0] == '/');
|
2005-05-24 13:45:47 +02:00
|
|
|
|
|
|
|
TRACE("--> %s\n", debugstr_a(pszCanonicalPath));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-10 21:31:59 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_build_shitemid [Internal]
|
|
|
|
*
|
|
|
|
* Constructs a new SHITEMID for the last component of path 'pszUnixPath' into
|
2005-07-11 12:24:09 +02:00
|
|
|
* buffer 'pIDL'.
|
2005-06-10 21:31:59 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2007-12-18 09:48:16 +01:00
|
|
|
* pszUnixPath [I] An absolute path. The SHITEMID will be built for the last component.
|
2010-07-21 21:04:22 +02:00
|
|
|
* pbc [I] Bind context for this action, used to determine if the file must exist
|
2005-06-10 21:31:59 +02:00
|
|
|
* pIDL [O] SHITEMID will be constructed here.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to the terminating '\0' character of path.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Minimum size of pIDL is SHITEMID_LEN_FROM_NAME_LEN(strlen(last_component_of_path)).
|
|
|
|
* If what you need is a PIDLLIST with a single SHITEMID, don't forget to append
|
|
|
|
* a 0 USHORT value.
|
|
|
|
*/
|
2011-01-13 15:31:52 +01:00
|
|
|
static char* UNIXFS_build_shitemid(char *pszUnixPath, BOOL bMustExist, WIN32_FIND_DATAW *pFindData, void *pIDL) {
|
2005-06-10 21:31:59 +02:00
|
|
|
LPPIDLDATA pIDLData;
|
|
|
|
struct stat fileStat;
|
2011-01-13 15:31:52 +01:00
|
|
|
WIN32_FIND_DATAW findData;
|
2006-01-03 13:23:59 +01:00
|
|
|
char *pszComponentU, *pszComponentA;
|
|
|
|
WCHAR *pwszComponentW;
|
|
|
|
int cComponentULen, cComponentALen;
|
|
|
|
USHORT cbLen;
|
|
|
|
FileStructW *pFileStructW;
|
|
|
|
WORD uOffsetW, *pOffsetW;
|
2010-07-21 21:04:22 +02:00
|
|
|
|
2012-06-02 10:35:21 +02:00
|
|
|
TRACE("(pszUnixPath=%s, bMustExist=%s, pFindData=%p, pIDL=%p)\n",
|
2011-01-13 15:31:52 +01:00
|
|
|
debugstr_a(pszUnixPath), bMustExist ? "T" : "F", pFindData, pIDL);
|
2010-07-21 21:04:22 +02:00
|
|
|
|
2011-01-13 15:31:52 +01:00
|
|
|
if (pFindData)
|
|
|
|
memcpy(&findData, pFindData, sizeof(WIN32_FIND_DATAW));
|
|
|
|
else {
|
|
|
|
memset(&findData, 0, sizeof(WIN32_FIND_DATAW));
|
|
|
|
findData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
2010-07-21 21:04:22 +02:00
|
|
|
}
|
2005-06-10 21:31:59 +02:00
|
|
|
|
|
|
|
/* We are only interested in regular files and directories. */
|
2010-07-21 21:04:22 +02:00
|
|
|
if (stat(pszUnixPath, &fileStat)){
|
2011-01-13 15:31:52 +01:00
|
|
|
if (bMustExist || errno != ENOENT)
|
2010-07-21 21:04:22 +02:00
|
|
|
return NULL;
|
2011-01-13 15:31:52 +01:00
|
|
|
} else {
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
if (S_ISDIR(fileStat.st_mode))
|
|
|
|
findData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
else if (S_ISREG(fileStat.st_mode))
|
|
|
|
findData.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
|
|
|
|
else
|
2010-07-21 21:04:22 +02:00
|
|
|
return NULL;
|
2011-01-13 15:31:52 +01:00
|
|
|
|
|
|
|
findData.nFileSizeLow = (DWORD)fileStat.st_size;
|
|
|
|
findData.nFileSizeHigh = fileStat.st_size >> 32;
|
|
|
|
|
|
|
|
RtlSecondsSince1970ToTime(fileStat.st_mtime, &time);
|
|
|
|
findData.ftLastWriteTime.dwLowDateTime = time.u.LowPart;
|
|
|
|
findData.ftLastWriteTime.dwHighDateTime = time.u.HighPart;
|
|
|
|
RtlSecondsSince1970ToTime(fileStat.st_atime, &time);
|
|
|
|
findData.ftLastAccessTime.dwLowDateTime = time.u.LowPart;
|
|
|
|
findData.ftLastAccessTime.dwHighDateTime = time.u.HighPart;
|
|
|
|
}
|
2005-06-10 21:31:59 +02:00
|
|
|
|
2006-01-03 13:23:59 +01:00
|
|
|
/* Compute the SHITEMID's length and wipe it. */
|
|
|
|
pszComponentU = strrchr(pszUnixPath, '/') + 1;
|
|
|
|
cComponentULen = strlen(pszComponentU);
|
|
|
|
cbLen = UNIXFS_shitemid_len_from_filename(pszComponentU, &pszComponentA, &pwszComponentW);
|
|
|
|
if (!cbLen) return NULL;
|
|
|
|
memset(pIDL, 0, cbLen);
|
|
|
|
((LPSHITEMID)pIDL)->cb = cbLen;
|
|
|
|
|
2005-06-10 21:31:59 +02:00
|
|
|
/* Set shell32's standard SHITEMID data fields. */
|
2009-02-18 22:46:39 +01:00
|
|
|
pIDLData = _ILGetDataPointer(pIDL);
|
2011-01-13 15:31:52 +01:00
|
|
|
pIDLData->type = (findData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
|
|
|
|
pIDLData->u.file.dwFileSize = findData.nFileSizeLow;
|
|
|
|
FileTimeToDosDateTime(&findData.ftLastWriteTime, &pIDLData->u.file.uFileDate,
|
|
|
|
&pIDLData->u.file.uFileTime);
|
2005-06-10 21:31:59 +02:00
|
|
|
pIDLData->u.file.uFileAttribs = 0;
|
2011-01-13 15:31:52 +01:00
|
|
|
pIDLData->u.file.uFileAttribs |= findData.dwFileAttributes;
|
2006-01-03 13:23:59 +01:00
|
|
|
if (pszComponentU[0] == '.') pIDLData->u.file.uFileAttribs |= FILE_ATTRIBUTE_HIDDEN;
|
|
|
|
cComponentALen = lstrlenA(pszComponentA) + 1;
|
|
|
|
memcpy(pIDLData->u.file.szNames, pszComponentA, cComponentALen);
|
|
|
|
|
|
|
|
pFileStructW = (FileStructW*)(pIDLData->u.file.szNames + cComponentALen + (cComponentALen & 0x1));
|
|
|
|
uOffsetW = (WORD)(((LPBYTE)pFileStructW) - ((LPBYTE)pIDL));
|
|
|
|
pFileStructW->cbLen = cbLen - uOffsetW;
|
2011-01-13 15:31:52 +01:00
|
|
|
FileTimeToDosDateTime(&findData.ftLastWriteTime, &pFileStructW->uCreationDate,
|
2006-01-03 13:23:59 +01:00
|
|
|
&pFileStructW->uCreationTime);
|
2011-01-13 15:31:52 +01:00
|
|
|
FileTimeToDosDateTime(&findData.ftLastAccessTime, &pFileStructW->uLastAccessDate,
|
2006-01-03 13:23:59 +01:00
|
|
|
&pFileStructW->uLastAccessTime);
|
|
|
|
lstrcpyW(pFileStructW->wszName, pwszComponentW);
|
|
|
|
|
|
|
|
pOffsetW = (WORD*)(((LPBYTE)pIDL) + cbLen - sizeof(WORD));
|
|
|
|
*pOffsetW = uOffsetW;
|
|
|
|
|
|
|
|
SHFree(pszComponentA);
|
|
|
|
SHFree(pwszComponentW);
|
|
|
|
|
|
|
|
return pszComponentU + cComponentULen;
|
2005-06-10 21:31:59 +02:00
|
|
|
}
|
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_path_to_pidl [Internal]
|
|
|
|
*
|
|
|
|
* PARAMS
|
2005-05-24 13:45:47 +02:00
|
|
|
* pUnixFolder [I] If path is relative, pUnixFolder represents the base path
|
2008-01-16 12:20:50 +01:00
|
|
|
* path [I] An absolute unix or dos path or a path relative to pUnixFolder
|
2005-05-24 13:45:47 +02:00
|
|
|
* ppidl [O] The corresponding ITEMIDLIST. Release with SHFree/ILFree
|
2005-03-09 17:41:17 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2008-10-10 18:11:53 +02:00
|
|
|
* Success: S_OK
|
|
|
|
* Failure: Error code, invalid params or out of memory
|
2005-05-24 13:45:47 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* pUnixFolder also carries the information if the path is expected to be unix or dos.
|
2005-03-09 17:41:17 +01:00
|
|
|
*/
|
2010-07-21 21:04:22 +02:00
|
|
|
static HRESULT UNIXFS_path_to_pidl(UnixFolder *pUnixFolder, LPBC pbc, const WCHAR *path,
|
|
|
|
LPITEMIDLIST *ppidl) {
|
2005-03-09 17:41:17 +01:00
|
|
|
LPITEMIDLIST pidl;
|
2006-01-03 13:23:59 +01:00
|
|
|
int cPidlLen, cPathLen;
|
|
|
|
char *pSlash, *pNextSlash, szCompletePath[FILENAME_MAX], *pNextPathElement, *pszAPath;
|
|
|
|
WCHAR *pwszPath;
|
2011-01-13 15:31:52 +01:00
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
BOOL must_exist = TRUE;
|
2005-05-24 13:45:47 +02:00
|
|
|
|
2010-07-21 21:04:22 +02:00
|
|
|
TRACE("pUnixFolder=%p, pbc=%p, path=%s, ppidl=%p\n", pUnixFolder, pbc, debugstr_w(path), ppidl);
|
2005-05-24 13:45:47 +02:00
|
|
|
|
|
|
|
if (!ppidl || !path)
|
2008-10-10 18:11:53 +02:00
|
|
|
return E_INVALIDARG;
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
/* Build an absolute path and let pNextPathElement point to the interesting
|
|
|
|
* relative sub-path. We need the absolute path to call 'stat', but the pidl
|
|
|
|
* will only contain the relative part.
|
|
|
|
*/
|
|
|
|
if ((pUnixFolder->m_dwPathMode == PATHMODE_DOS) && (path[1] == ':'))
|
|
|
|
{
|
|
|
|
/* Absolute dos path. Convert to unix */
|
2005-06-06 21:37:47 +02:00
|
|
|
if (!UNIXFS_get_unix_path(path, szCompletePath))
|
2008-10-10 18:11:53 +02:00
|
|
|
return E_FAIL;
|
2005-06-27 20:46:36 +02:00
|
|
|
pNextPathElement = szCompletePath;
|
2005-05-24 13:45:47 +02:00
|
|
|
}
|
|
|
|
else if ((pUnixFolder->m_dwPathMode == PATHMODE_UNIX) && (path[0] == '/'))
|
|
|
|
{
|
|
|
|
/* Absolute unix path. Just convert to ANSI. */
|
2005-07-18 15:13:42 +02:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath, FILENAME_MAX, NULL, NULL);
|
2005-06-27 20:46:36 +02:00
|
|
|
pNextPathElement = szCompletePath;
|
2005-05-24 13:45:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Relative dos or unix path. Concat with this folder's path */
|
|
|
|
int cBasePathLen = strlen(pUnixFolder->m_pszPath);
|
|
|
|
memcpy(szCompletePath, pUnixFolder->m_pszPath, cBasePathLen);
|
2005-07-18 15:13:42 +02:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, path, -1, szCompletePath + cBasePathLen,
|
2005-05-24 13:45:47 +02:00
|
|
|
FILENAME_MAX - cBasePathLen, NULL, NULL);
|
2005-06-27 20:46:36 +02:00
|
|
|
pNextPathElement = szCompletePath + cBasePathLen - 1;
|
2005-05-24 13:45:47 +02:00
|
|
|
|
|
|
|
/* If in dos mode, replace '\' with '/' */
|
|
|
|
if (pUnixFolder->m_dwPathMode == PATHMODE_DOS) {
|
|
|
|
char *pBackslash = strchr(pNextPathElement, '\\');
|
|
|
|
while (pBackslash) {
|
|
|
|
*pBackslash = '/';
|
|
|
|
pBackslash = strchr(pBackslash, '\\');
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 21:33:01 +02:00
|
|
|
}
|
2005-05-24 13:45:47 +02:00
|
|
|
|
2005-06-30 12:59:51 +02:00
|
|
|
/* Special case for the root folder. */
|
|
|
|
if (!strcmp(szCompletePath, "/")) {
|
2008-11-05 23:00:50 +01:00
|
|
|
*ppidl = pidl = SHAlloc(sizeof(USHORT));
|
2008-10-10 18:11:53 +02:00
|
|
|
if (!pidl) return E_FAIL;
|
2005-06-30 12:59:51 +02:00
|
|
|
pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
|
2008-10-10 18:11:53 +02:00
|
|
|
return S_OK;
|
2005-06-30 12:59:51 +02:00
|
|
|
}
|
|
|
|
|
2005-06-27 20:46:36 +02:00
|
|
|
/* Remove trailing slash, if present */
|
|
|
|
cPathLen = strlen(szCompletePath);
|
|
|
|
if (szCompletePath[cPathLen-1] == '/')
|
|
|
|
szCompletePath[cPathLen-1] = '\0';
|
|
|
|
|
|
|
|
if ((szCompletePath[0] != '/') || (pNextPathElement[0] != '/')) {
|
|
|
|
ERR("szCompletePath: %s, pNextPathElment: %s\n", szCompletePath, pNextPathElement);
|
2008-10-10 18:11:53 +02:00
|
|
|
return E_FAIL;
|
2005-06-27 20:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* At this point, we have an absolute unix path in szCompletePath
|
|
|
|
* and the relative portion of it in pNextPathElement. Both starting with '/'
|
|
|
|
* and _not_ terminated by a '/'. */
|
|
|
|
TRACE("complete path: %s, relative path: %s\n", szCompletePath, pNextPathElement);
|
2005-05-07 14:17:02 +02:00
|
|
|
|
2006-01-03 13:23:59 +01:00
|
|
|
/* Convert to CP_ACP and WCHAR */
|
|
|
|
if (!UNIXFS_shitemid_len_from_filename(pNextPathElement, &pszAPath, &pwszPath))
|
2008-10-10 18:11:53 +02:00
|
|
|
return E_FAIL;
|
2006-01-03 13:23:59 +01:00
|
|
|
|
|
|
|
/* Compute the length of the complete ITEMIDLIST */
|
|
|
|
cPidlLen = 0;
|
|
|
|
pSlash = pszAPath;
|
2005-06-27 20:46:36 +02:00
|
|
|
while (pSlash) {
|
2006-01-03 13:23:59 +01:00
|
|
|
pNextSlash = strchr(pSlash+1, '/');
|
|
|
|
cPidlLen += LEN_SHITEMID_FIXED_PART + /* Fixed part length plus potential alignment byte. */
|
|
|
|
(pNextSlash ? (pNextSlash - pSlash) & 0x1 : lstrlenA(pSlash) & 0x1);
|
|
|
|
pSlash = pNextSlash;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
2006-01-03 13:23:59 +01:00
|
|
|
|
|
|
|
/* The USHORT is for the ITEMIDLIST terminator. The NUL terminators for the sub-path-strings
|
|
|
|
* are accounted for by the '/' separators, which are not stored in the SHITEMIDs. Above we
|
|
|
|
* have ensured that the number of '/'s exactly matches the number of sub-path-strings. */
|
|
|
|
cPidlLen += lstrlenA(pszAPath) + lstrlenW(pwszPath) * sizeof(WCHAR) + sizeof(USHORT);
|
|
|
|
|
|
|
|
SHFree(pszAPath);
|
|
|
|
SHFree(pwszPath);
|
|
|
|
|
2008-11-05 23:00:50 +01:00
|
|
|
*ppidl = pidl = SHAlloc(cPidlLen);
|
2008-10-10 18:11:53 +02:00
|
|
|
if (!pidl) return E_FAIL;
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2011-01-13 15:31:52 +01:00
|
|
|
if (pbc) {
|
|
|
|
IUnknown *unk;
|
|
|
|
IFileSystemBindData *fsb;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &unk);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IFileSystemBindData, (LPVOID*)&fsb);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = IFileSystemBindData_GetFindData(fsb, &find_data);
|
|
|
|
if (FAILED(hr))
|
|
|
|
memset(&find_data, 0, sizeof(WIN32_FIND_DATAW));
|
|
|
|
|
|
|
|
must_exist = FALSE;
|
|
|
|
IFileSystemBindData_Release(fsb);
|
|
|
|
}
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-22 23:29:17 +02:00
|
|
|
/* Concatenate the SHITEMIDs of the sub-directories. */
|
2005-05-09 21:33:01 +02:00
|
|
|
while (*pNextPathElement) {
|
2005-06-27 20:46:36 +02:00
|
|
|
pSlash = strchr(pNextPathElement+1, '/');
|
2005-06-10 21:31:59 +02:00
|
|
|
if (pSlash) *pSlash = '\0';
|
2011-01-13 15:31:52 +01:00
|
|
|
pNextPathElement = UNIXFS_build_shitemid(szCompletePath, must_exist,
|
|
|
|
must_exist&&!pSlash ? &find_data : NULL, pidl);
|
2005-06-10 21:31:59 +02:00
|
|
|
if (pSlash) *pSlash = '/';
|
|
|
|
|
|
|
|
if (!pNextPathElement) {
|
2005-09-07 15:28:38 +02:00
|
|
|
SHFree(*ppidl);
|
2006-02-22 12:04:02 +01:00
|
|
|
*ppidl = NULL;
|
2008-10-10 18:11:53 +02:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
2005-04-25 12:56:29 +02:00
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
pidl = ILGetNext(pidl);
|
|
|
|
}
|
|
|
|
pidl->mkid.cb = 0; /* Terminate the ITEMIDLIST */
|
2005-05-24 13:45:47 +02:00
|
|
|
|
2005-09-02 13:18:00 +02:00
|
|
|
if ((char *)pidl-(char *)*ppidl+sizeof(USHORT) != cPidlLen) /* We've corrupted the heap :( */
|
2005-06-27 20:46:36 +02:00
|
|
|
ERR("Computed length of pidl incorrect. Please report.\n");
|
2005-05-24 13:45:47 +02:00
|
|
|
|
2008-10-10 18:11:53 +02:00
|
|
|
return S_OK;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2005-11-05 11:44:28 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_initialize_target_folder [Internal]
|
|
|
|
*
|
|
|
|
* Initialize the m_pszPath member of an UnixFolder, given an absolute unix
|
|
|
|
* base path and a relative ITEMIDLIST. Leave the m_pidlLocation member, which
|
|
|
|
* specifies the location in the shell namespace alone.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* This [IO] The UnixFolder, whose target path is to be initialized
|
|
|
|
* szBasePath [I] The absolute base path
|
|
|
|
* pidlSubFolder [I] Relative part of the path, given as an ITEMIDLIST
|
|
|
|
* dwAttributes [I] Attributes to add to the Folders m_dwAttributes member
|
|
|
|
* (Used to pass the SFGAO_FILESYSTEM flag down the path)
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK,
|
|
|
|
* Failure: E_FAIL
|
|
|
|
*/
|
|
|
|
static HRESULT UNIXFS_initialize_target_folder(UnixFolder *This, const char *szBasePath,
|
|
|
|
LPCITEMIDLIST pidlSubFolder, DWORD dwAttributes)
|
|
|
|
{
|
|
|
|
LPCITEMIDLIST current = pidlSubFolder;
|
|
|
|
DWORD dwPathLen = strlen(szBasePath)+1;
|
|
|
|
char *pNextDir;
|
2007-10-18 14:11:43 +02:00
|
|
|
WCHAR *dos_name;
|
|
|
|
|
2005-11-05 11:44:28 +01:00
|
|
|
/* Determine the path's length bytes */
|
2010-08-02 14:33:40 +02:00
|
|
|
while (!_ILIsEmpty(current)) {
|
2006-01-03 13:23:59 +01:00
|
|
|
dwPathLen += UNIXFS_filename_from_shitemid(current, NULL) + 1; /* For the '/' */
|
2005-11-05 11:44:28 +01:00
|
|
|
current = ILGetNext(current);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Build the path and compute the attributes*/
|
|
|
|
This->m_dwAttributes =
|
|
|
|
dwAttributes|SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME;
|
|
|
|
This->m_pszPath = pNextDir = SHAlloc(dwPathLen);
|
|
|
|
if (!This->m_pszPath) {
|
|
|
|
WARN("SHAlloc failed!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
current = pidlSubFolder;
|
|
|
|
strcpy(pNextDir, szBasePath);
|
|
|
|
pNextDir += strlen(szBasePath);
|
|
|
|
if (This->m_dwPathMode == PATHMODE_UNIX || IsEqualCLSID(&CLSID_MyDocuments, This->m_pCLSID))
|
|
|
|
This->m_dwAttributes |= SFGAO_FILESYSTEM;
|
2010-08-02 14:33:40 +02:00
|
|
|
while (!_ILIsEmpty(current)) {
|
2006-01-03 13:23:59 +01:00
|
|
|
pNextDir += UNIXFS_filename_from_shitemid(current, pNextDir);
|
2005-11-05 11:44:28 +01:00
|
|
|
*pNextDir++ = '/';
|
|
|
|
current = ILGetNext(current);
|
|
|
|
}
|
|
|
|
*pNextDir='\0';
|
2007-10-18 14:11:43 +02:00
|
|
|
|
|
|
|
if (!(This->m_dwAttributes & SFGAO_FILESYSTEM) &&
|
|
|
|
((dos_name = wine_get_dos_file_name(This->m_pszPath))))
|
|
|
|
{
|
|
|
|
This->m_dwAttributes |= SFGAO_FILESYSTEM;
|
|
|
|
HeapFree( GetProcessHeap(), 0, dos_name );
|
|
|
|
}
|
|
|
|
|
2005-11-05 11:44:28 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-20 20:54:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_copy [Internal]
|
|
|
|
*
|
|
|
|
* Copy pwszDosSrc to pwszDosDst.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pwszDosSrc [I] absolute path of the source
|
|
|
|
* pwszDosDst [I] absolute path of the destination
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK,
|
|
|
|
* Failure: E_FAIL
|
|
|
|
*/
|
|
|
|
static HRESULT UNIXFS_copy(LPCWSTR pwszDosSrc, LPCWSTR pwszDosDst)
|
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTW op;
|
|
|
|
LPWSTR pwszSrc, pwszDst;
|
|
|
|
HRESULT res = E_OUTOFMEMORY;
|
|
|
|
UINT iSrcLen, iDstLen;
|
|
|
|
|
|
|
|
if (!pwszDosSrc || !pwszDosDst)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
iSrcLen = lstrlenW(pwszDosSrc);
|
|
|
|
iDstLen = lstrlenW(pwszDosDst);
|
|
|
|
pwszSrc = HeapAlloc(GetProcessHeap(), 0, (iSrcLen + 2) * sizeof(WCHAR));
|
|
|
|
pwszDst = HeapAlloc(GetProcessHeap(), 0, (iDstLen + 2) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (pwszSrc && pwszDst) {
|
|
|
|
lstrcpyW(pwszSrc, pwszDosSrc);
|
|
|
|
lstrcpyW(pwszDst, pwszDosDst);
|
|
|
|
/* double null termination */
|
|
|
|
pwszSrc[iSrcLen + 1] = 0;
|
|
|
|
pwszDst[iDstLen + 1] = 0;
|
|
|
|
|
|
|
|
ZeroMemory(&op, sizeof(op));
|
|
|
|
op.hwnd = GetActiveWindow();
|
|
|
|
op.wFunc = FO_COPY;
|
|
|
|
op.pFrom = pwszSrc;
|
|
|
|
op.pTo = pwszDst;
|
|
|
|
op.fFlags = FOF_ALLOWUNDO;
|
|
|
|
if (!SHFileOperationW(&op))
|
|
|
|
{
|
|
|
|
WARN("SHFileOperationW failed\n");
|
|
|
|
res = E_FAIL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pwszSrc);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pwszDst);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UnixFolder
|
|
|
|
*
|
|
|
|
* Class whose heap based instances represent unix filesystem directories.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void UnixFolder_Destroy(UnixFolder *pUnixFolder) {
|
|
|
|
TRACE("(pUnixFolder=%p)\n", pUnixFolder);
|
|
|
|
|
|
|
|
SHFree(pUnixFolder->m_pszPath);
|
|
|
|
ILFree(pUnixFolder->m_pidlLocation);
|
|
|
|
SHFree(pUnixFolder);
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_QueryInterface(IShellFolder2 *iface, REFIID riid,
|
2005-03-09 17:41:17 +01:00
|
|
|
void **ppv)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, shdebugstr_guid(riid), ppv);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IShellFolder, riid) ||
|
2005-04-12 13:58:05 +02:00
|
|
|
IsEqualIID(&IID_IShellFolder2, riid))
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
*ppv = &This->IShellFolder2_iface;
|
|
|
|
} else if (IsEqualIID(&IID_IPersistFolder3, riid) ||
|
|
|
|
IsEqualIID(&IID_IPersistFolder2, riid) ||
|
|
|
|
IsEqualIID(&IID_IPersistFolder, riid) ||
|
|
|
|
IsEqualIID(&IID_IPersist, riid))
|
2005-05-12 11:56:04 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
*ppv = &This->IPersistFolder3_iface;
|
2005-08-19 15:58:52 +02:00
|
|
|
} else if (IsEqualIID(&IID_IPersistPropertyBag, riid)) {
|
2012-01-11 12:52:39 +01:00
|
|
|
*ppv = &This->IPersistPropertyBag_iface;
|
2005-07-05 22:55:43 +02:00
|
|
|
} else if (IsEqualIID(&IID_ISFHelper, riid)) {
|
2012-01-11 12:52:39 +01:00
|
|
|
*ppv = &This->ISFHelper_iface;
|
2005-11-28 10:36:04 +01:00
|
|
|
} else if (IsEqualIID(&IID_IDropTarget, riid)) {
|
2012-01-11 12:52:39 +01:00
|
|
|
*ppv = &This->IDropTarget_iface;
|
2005-11-28 20:40:50 +01:00
|
|
|
if (!cfShellIDList)
|
2008-06-18 17:04:46 +02:00
|
|
|
cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
|
2005-03-09 17:41:17 +01:00
|
|
|
} else {
|
|
|
|
*ppv = NULL;
|
2010-07-21 21:49:13 +02:00
|
|
|
TRACE("Unimplemented interface %s\n", shdebugstr_guid(riid));
|
2005-03-09 17:41:17 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI ShellFolder2_AddRef(IShellFolder2 *iface)
|
|
|
|
{
|
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
|
|
|
return ref;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI ShellFolder2_Release(IShellFolder2 *iface)
|
|
|
|
{
|
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
2005-03-09 17:41:17 +01:00
|
|
|
UnixFolder_Destroy(This);
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
return ref;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_ParseDisplayName(IShellFolder2* iface, HWND hwndOwner,
|
|
|
|
LPBC pbc, LPOLESTR display_name, ULONG* pchEaten, LPITEMIDLIST* ppidl,
|
|
|
|
ULONG* attrs)
|
2005-03-09 17:41:17 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2008-10-10 18:11:53 +02:00
|
|
|
HRESULT result;
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %p %s %p %p %p)\n", This, hwndOwner, pbc, debugstr_w(display_name),
|
|
|
|
pchEaten, ppidl, attrs);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
result = UNIXFS_path_to_pidl(This, pbc, display_name, ppidl);
|
|
|
|
if (SUCCEEDED(result) && attrs && *attrs)
|
2005-05-12 11:56:04 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
IShellFolder *parent;
|
2005-07-05 12:58:11 +02:00
|
|
|
LPCITEMIDLIST pidlLast;
|
2006-01-14 17:10:53 +01:00
|
|
|
LPITEMIDLIST pidlComplete = ILCombine(This->m_pidlLocation, *ppidl);
|
2005-07-05 12:58:11 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
hr = SHBindToParent(pidlComplete, &IID_IShellFolder, (void**)&parent, &pidlLast);
|
2006-01-14 17:10:53 +01:00
|
|
|
if (FAILED(hr)) {
|
2012-01-11 12:52:39 +01:00
|
|
|
FIXME("SHBindToParent failed! hr = 0x%08x\n", hr);
|
2006-01-14 17:10:53 +01:00
|
|
|
ILFree(pidlComplete);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2012-01-11 12:52:39 +01:00
|
|
|
IShellFolder_GetAttributesOf(parent, 1, &pidlLast, attrs);
|
|
|
|
IShellFolder_Release(parent);
|
2006-01-14 17:10:53 +01:00
|
|
|
ILFree(pidlComplete);
|
2005-05-12 11:56:04 +02:00
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2008-10-10 18:11:53 +02:00
|
|
|
if (FAILED(result)) TRACE("FAILED!\n");
|
|
|
|
return result;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2005-07-12 19:00:36 +02:00
|
|
|
static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_EnumObjects(IShellFolder2* iface, HWND hwndOwner,
|
2005-03-09 17:41:17 +01:00
|
|
|
SHCONTF grfFlags, IEnumIDList** ppEnumIDList)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-03-09 17:41:17 +01:00
|
|
|
IUnknown *newIterator;
|
|
|
|
HRESULT hr;
|
2012-01-11 12:52:39 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p 0x%08x %p)\n", This, hwndOwner, grfFlags, ppEnumIDList);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-11-01 19:06:18 +01:00
|
|
|
if (!This->m_pszPath) {
|
2005-11-03 14:17:32 +01:00
|
|
|
WARN("EnumObjects called on uninitialized UnixFolder-object!\n");
|
|
|
|
return E_UNEXPECTED;
|
2005-11-01 19:06:18 +01:00
|
|
|
}
|
|
|
|
|
2005-07-12 19:00:36 +02:00
|
|
|
newIterator = UnixSubFolderIterator_Constructor(This, grfFlags);
|
2005-03-09 17:41:17 +01:00
|
|
|
hr = IUnknown_QueryInterface(newIterator, &IID_IEnumIDList, (void**)ppEnumIDList);
|
|
|
|
IUnknown_Release(newIterator);
|
2012-01-11 12:52:39 +01:00
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-08-30 11:58:21 +02:00
|
|
|
static HRESULT CreateUnixFolder(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv, const CLSID *pCLSID);
|
2005-08-26 12:05:34 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_BindToObject(IShellFolder2* iface, LPCITEMIDLIST pidl,
|
2005-03-09 17:41:17 +01:00
|
|
|
LPBC pbcReserved, REFIID riid, void** ppvOut)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-07-20 12:44:54 +02:00
|
|
|
IPersistFolder3 *persistFolder;
|
2005-11-05 11:44:28 +01:00
|
|
|
const CLSID *clsidChild;
|
2012-01-11 12:52:39 +01:00
|
|
|
HRESULT hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %p %s %p)\n", This, pidl, pbcReserved, debugstr_guid(riid), ppvOut);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2010-08-02 14:33:40 +02:00
|
|
|
if (_ILIsEmpty(pidl))
|
2005-06-06 21:37:47 +02:00
|
|
|
return E_INVALIDARG;
|
2005-11-05 11:44:28 +01:00
|
|
|
|
2010-11-08 00:22:12 +01:00
|
|
|
/* Don't bind to files */
|
|
|
|
if (_ILIsValue(ILFindLastID(pidl)))
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
|
|
|
|
2005-11-05 11:44:28 +01:00
|
|
|
if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
|
|
|
|
/* Children of FolderShortcuts are ShellFSFolders on Windows.
|
|
|
|
* Unixfs' counterpart is UnixDosFolder. */
|
|
|
|
clsidChild = &CLSID_UnixDosFolder;
|
|
|
|
} else {
|
|
|
|
clsidChild = This->m_pCLSID;
|
|
|
|
}
|
2008-01-19 17:54:28 +01:00
|
|
|
|
2005-11-05 11:44:28 +01:00
|
|
|
hr = CreateUnixFolder(NULL, &IID_IPersistFolder3, (void**)&persistFolder, clsidChild);
|
2008-10-08 01:32:38 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
2012-07-29 10:51:05 +02:00
|
|
|
hr = IPersistFolder3_QueryInterface(persistFolder, riid, ppvOut);
|
2008-01-19 17:54:28 +01:00
|
|
|
|
2005-08-30 11:58:21 +02:00
|
|
|
if (SUCCEEDED(hr)) {
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *subfolder = impl_from_IPersistFolder3(persistFolder);
|
2005-11-05 11:44:28 +01:00
|
|
|
subfolder->m_pidlLocation = ILCombine(This->m_pidlLocation, pidl);
|
|
|
|
hr = UNIXFS_initialize_target_folder(subfolder, This->m_pszPath, pidl,
|
|
|
|
This->m_dwAttributes & SFGAO_FILESYSTEM);
|
|
|
|
}
|
|
|
|
|
2005-07-20 12:44:54 +02:00
|
|
|
IPersistFolder3_Release(persistFolder);
|
2005-08-30 11:58:21 +02:00
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_BindToStorage(IShellFolder2* iface, LPCITEMIDLIST pidl,
|
2005-03-09 17:41:17 +01:00
|
|
|
LPBC pbcReserved, REFIID riid, void** ppvObj)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
FIXME("(%p)->(%p %p %s %p): stub\n", This, pidl, pbcReserved, debugstr_guid(riid), ppvObj);
|
2005-03-09 17:41:17 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_CompareIDs(IShellFolder2* iface, LPARAM lParam,
|
2005-03-09 17:41:17 +01:00
|
|
|
LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-04-13 13:01:10 +02:00
|
|
|
BOOL isEmpty1, isEmpty2;
|
|
|
|
HRESULT hr = E_FAIL;
|
2011-01-15 19:42:59 +01:00
|
|
|
LPCITEMIDLIST firstpidl;
|
2005-04-13 13:01:10 +02:00
|
|
|
IShellFolder2 *psf;
|
|
|
|
int compare;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%ld %p %p)\n", This, lParam, pidl1, pidl2);
|
2005-04-13 13:01:10 +02:00
|
|
|
|
2010-08-02 14:33:40 +02:00
|
|
|
isEmpty1 = _ILIsEmpty(pidl1);
|
|
|
|
isEmpty2 = _ILIsEmpty(pidl2);
|
2005-04-13 13:01:10 +02:00
|
|
|
|
|
|
|
if (isEmpty1 && isEmpty2)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
|
|
|
|
else if (isEmpty1)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
|
|
|
|
else if (isEmpty2)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
|
|
|
|
|
2005-04-22 23:29:17 +02:00
|
|
|
compare = CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
|
2006-01-03 13:23:59 +01:00
|
|
|
_ILGetTextPointer(pidl1), -1,
|
|
|
|
_ILGetTextPointer(pidl2), -1);
|
2011-01-13 15:32:07 +01:00
|
|
|
|
|
|
|
if ((compare != CSTR_EQUAL) && _ILIsFolder(pidl1) && !_ILIsFolder(pidl2))
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
|
|
|
|
if ((compare != CSTR_EQUAL) && !_ILIsFolder(pidl1) && _ILIsFolder(pidl2))
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
|
|
|
|
|
2005-04-13 13:01:10 +02:00
|
|
|
if ((compare == CSTR_LESS_THAN) || (compare == CSTR_GREATER_THAN))
|
2005-05-24 13:45:47 +02:00
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)((compare == CSTR_LESS_THAN)?-1:1));
|
2005-04-13 13:01:10 +02:00
|
|
|
|
|
|
|
if (pidl1->mkid.cb < pidl2->mkid.cb)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
|
|
|
|
else if (pidl1->mkid.cb > pidl2->mkid.cb)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
|
|
|
|
|
2011-01-15 19:42:59 +01:00
|
|
|
firstpidl = pidl1;
|
2005-04-13 13:01:10 +02:00
|
|
|
pidl1 = ILGetNext(pidl1);
|
|
|
|
pidl2 = ILGetNext(pidl2);
|
2010-11-08 00:22:10 +01:00
|
|
|
|
|
|
|
isEmpty1 = _ILIsEmpty(pidl1);
|
|
|
|
isEmpty2 = _ILIsEmpty(pidl2);
|
|
|
|
|
|
|
|
if (isEmpty1 && isEmpty2)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
|
|
|
|
else if (isEmpty1)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)-1);
|
|
|
|
else if (isEmpty2)
|
|
|
|
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (WORD)1);
|
|
|
|
else if (SUCCEEDED(IShellFolder2_BindToObject(iface, firstpidl, NULL, &IID_IShellFolder, (void**)&psf))) {
|
2012-07-29 10:51:05 +02:00
|
|
|
hr = IShellFolder2_CompareIDs(psf, lParam, pidl1, pidl2);
|
2005-04-13 13:01:10 +02:00
|
|
|
IShellFolder2_Release(psf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_CreateViewObject(IShellFolder2* iface, HWND hwndOwner,
|
2005-04-12 13:58:05 +02:00
|
|
|
REFIID riid, void** ppv)
|
2005-03-09 17:41:17 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-04-12 13:58:05 +02:00
|
|
|
HRESULT hr = E_INVALIDARG;
|
2012-01-11 12:52:39 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %s %p)\n", This, hwndOwner, debugstr_guid(riid), ppv);
|
|
|
|
|
2005-04-12 13:58:05 +02:00
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
*ppv = NULL;
|
2012-01-11 12:52:39 +01:00
|
|
|
|
2005-04-12 13:58:05 +02:00
|
|
|
if (IsEqualIID(&IID_IShellView, riid)) {
|
2012-01-11 12:52:39 +01:00
|
|
|
IShellView *view;
|
2005-04-12 13:58:05 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
view = IShellView_Constructor((IShellFolder*)iface);
|
|
|
|
if (view) {
|
|
|
|
hr = IShellView_QueryInterface(view, riid, ppv);
|
|
|
|
IShellView_Release(view);
|
2005-04-12 13:58:05 +02:00
|
|
|
}
|
2005-11-28 10:36:04 +01:00
|
|
|
} else if (IsEqualIID(&IID_IDropTarget, riid)) {
|
|
|
|
hr = IShellFolder2_QueryInterface(iface, &IID_IDropTarget, ppv);
|
|
|
|
}
|
2012-01-11 12:52:39 +01:00
|
|
|
|
2005-04-12 13:58:05 +02:00
|
|
|
return hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetAttributesOf(IShellFolder2* iface, UINT cidl,
|
2005-03-09 17:41:17 +01:00
|
|
|
LPCITEMIDLIST* apidl, SFGAOF* rgfInOut)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-07-11 12:24:09 +02:00
|
|
|
HRESULT hr = S_OK;
|
2005-04-25 12:56:29 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%u %p %p)\n", This, cidl, apidl, rgfInOut);
|
2005-06-25 19:56:13 +02:00
|
|
|
|
|
|
|
if (!rgfInOut || (cidl && !apidl))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (cidl == 0) {
|
2005-07-11 12:24:09 +02:00
|
|
|
*rgfInOut &= This->m_dwAttributes;
|
2005-06-25 19:56:13 +02:00
|
|
|
} else {
|
2005-07-11 12:24:09 +02:00
|
|
|
char szAbsolutePath[FILENAME_MAX], *pszRelativePath;
|
2005-06-25 19:56:13 +02:00
|
|
|
UINT i;
|
2005-07-11 12:24:09 +02:00
|
|
|
|
2005-11-03 10:56:07 +01:00
|
|
|
*rgfInOut = SFGAO_CANCOPY|SFGAO_CANMOVE|SFGAO_CANLINK|SFGAO_CANRENAME|SFGAO_CANDELETE|
|
|
|
|
SFGAO_HASPROPSHEET|SFGAO_DROPTARGET|SFGAO_FILESYSTEM;
|
2005-07-11 12:24:09 +02:00
|
|
|
lstrcpyA(szAbsolutePath, This->m_pszPath);
|
|
|
|
pszRelativePath = szAbsolutePath + lstrlenA(szAbsolutePath);
|
2005-06-25 19:56:13 +02:00
|
|
|
for (i=0; i<cidl; i++) {
|
2005-11-03 10:56:07 +01:00
|
|
|
if (!(This->m_dwAttributes & SFGAO_FILESYSTEM)) {
|
2007-10-18 14:11:43 +02:00
|
|
|
WCHAR *dos_name;
|
2006-01-03 13:23:59 +01:00
|
|
|
if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelativePath))
|
|
|
|
return E_INVALIDARG;
|
2007-10-18 14:11:43 +02:00
|
|
|
if (!(dos_name = wine_get_dos_file_name( szAbsolutePath )))
|
2005-07-11 12:24:09 +02:00
|
|
|
*rgfInOut &= ~SFGAO_FILESYSTEM;
|
2007-10-18 14:11:43 +02:00
|
|
|
else
|
|
|
|
HeapFree( GetProcessHeap(), 0, dos_name );
|
2005-07-11 12:24:09 +02:00
|
|
|
}
|
2005-11-03 10:56:07 +01:00
|
|
|
if (_ILIsFolder(apidl[i]))
|
|
|
|
*rgfInOut |= SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR;
|
2005-06-25 19:56:13 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-11 12:52:39 +01:00
|
|
|
|
2005-07-11 12:24:09 +02:00
|
|
|
return hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetUIObjectOf(IShellFolder2* iface, HWND hwndOwner,
|
2005-03-09 17:41:17 +01:00
|
|
|
UINT cidl, LPCITEMIDLIST* apidl, REFIID riid, UINT* prgfInOut, void** ppvOut)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2010-11-10 14:19:29 +01:00
|
|
|
HRESULT hr;
|
2012-01-11 12:52:39 +01:00
|
|
|
UINT i;
|
2005-04-12 13:58:05 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %d %p riid=%s %p %p)\n",
|
|
|
|
This, hwndOwner, cidl, apidl, debugstr_guid(riid), prgfInOut, ppvOut);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-11-28 10:36:04 +01:00
|
|
|
if (!cidl || !apidl || !riid || !ppvOut)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (i=0; i<cidl; i++)
|
|
|
|
if (!apidl[i])
|
|
|
|
return E_INVALIDARG;
|
2010-11-10 14:19:29 +01:00
|
|
|
|
|
|
|
if(cidl == 1) {
|
|
|
|
hr = SHELL32_CreateExtensionUIObject(iface, *apidl, riid, ppvOut);
|
|
|
|
if(hr != S_FALSE)
|
|
|
|
return hr;
|
|
|
|
}
|
2012-01-11 03:02:03 +01:00
|
|
|
|
2005-04-12 13:58:05 +02:00
|
|
|
if (IsEqualIID(&IID_IContextMenu, riid)) {
|
2012-01-11 03:02:03 +01:00
|
|
|
return ItemMenu_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl, riid, ppvOut);
|
2005-04-12 13:58:05 +02:00
|
|
|
} else if (IsEqualIID(&IID_IDataObject, riid)) {
|
|
|
|
*ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl);
|
|
|
|
return S_OK;
|
|
|
|
} else if (IsEqualIID(&IID_IExtractIconA, riid)) {
|
2005-06-09 11:43:18 +02:00
|
|
|
LPITEMIDLIST pidl;
|
2005-11-28 10:36:04 +01:00
|
|
|
if (cidl != 1) return E_INVALIDARG;
|
2005-06-09 11:43:18 +02:00
|
|
|
pidl = ILCombine(This->m_pidlLocation, apidl[0]);
|
2009-02-18 22:46:39 +01:00
|
|
|
*ppvOut = IExtractIconA_Constructor(pidl);
|
2005-06-09 11:43:18 +02:00
|
|
|
SHFree(pidl);
|
|
|
|
return S_OK;
|
2005-04-12 13:58:05 +02:00
|
|
|
} else if (IsEqualIID(&IID_IExtractIconW, riid)) {
|
2005-06-09 11:43:18 +02:00
|
|
|
LPITEMIDLIST pidl;
|
2005-11-28 10:36:04 +01:00
|
|
|
if (cidl != 1) return E_INVALIDARG;
|
2005-06-09 11:43:18 +02:00
|
|
|
pidl = ILCombine(This->m_pidlLocation, apidl[0]);
|
2009-02-18 22:46:39 +01:00
|
|
|
*ppvOut = IExtractIconW_Constructor(pidl);
|
2005-06-09 11:43:18 +02:00
|
|
|
SHFree(pidl);
|
2005-03-09 17:41:17 +01:00
|
|
|
return S_OK;
|
2005-04-12 13:58:05 +02:00
|
|
|
} else if (IsEqualIID(&IID_IDropTarget, riid)) {
|
2005-11-28 10:36:04 +01:00
|
|
|
if (cidl != 1) return E_INVALIDARG;
|
|
|
|
return IShellFolder2_BindToObject(iface, apidl[0], NULL, &IID_IDropTarget, ppvOut);
|
2005-04-12 13:58:05 +02:00
|
|
|
} else if (IsEqualIID(&IID_IShellLinkW, riid)) {
|
|
|
|
FIXME("IShellLinkW\n");
|
|
|
|
return E_FAIL;
|
|
|
|
} else if (IsEqualIID(&IID_IShellLinkA, riid)) {
|
|
|
|
FIXME("IShellLinkA\n");
|
|
|
|
return E_FAIL;
|
|
|
|
} else {
|
|
|
|
FIXME("Unknown interface %s in GetUIObjectOf\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetDisplayNameOf(IShellFolder2* iface,
|
2005-03-09 17:41:17 +01:00
|
|
|
LPCITEMIDLIST pidl, SHGDNF uFlags, STRRET* lpName)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2010-11-08 00:22:11 +01:00
|
|
|
SHITEMID emptyIDL = { 0, { 0 } };
|
2005-05-07 14:17:02 +02:00
|
|
|
HRESULT hr = S_OK;
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p 0x%x %p)\n", This, pidl, uFlags, lpName);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-05-23 18:31:42 +02:00
|
|
|
if ((GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) &&
|
2005-05-07 14:17:02 +02:00
|
|
|
(GET_SHGDN_RELATION(uFlags) != SHGDN_INFOLDER))
|
|
|
|
{
|
2010-08-02 14:33:40 +02:00
|
|
|
if (_ILIsEmpty(pidl)) {
|
2006-01-03 13:23:59 +01:00
|
|
|
lpName->uType = STRRET_WSTR;
|
2005-08-12 12:32:47 +02:00
|
|
|
if (This->m_dwPathMode == PATHMODE_UNIX) {
|
2006-01-03 13:23:59 +01:00
|
|
|
UINT len = MultiByteToWideChar(CP_UNIXCP, 0, This->m_pszPath, -1, NULL, 0);
|
|
|
|
lpName->u.pOleStr = SHAlloc(len * sizeof(WCHAR));
|
|
|
|
if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, This->m_pszPath, -1, lpName->u.pOleStr, len);
|
2005-08-12 12:32:47 +02:00
|
|
|
} else {
|
2006-01-03 13:23:59 +01:00
|
|
|
LPWSTR pwszDosFileName = wine_get_dos_file_name(This->m_pszPath);
|
|
|
|
if (!pwszDosFileName) return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
lpName->u.pOleStr = SHAlloc((lstrlenW(pwszDosFileName) + 1) * sizeof(WCHAR));
|
|
|
|
if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
lstrcpyW(lpName->u.pOleStr, pwszDosFileName);
|
|
|
|
PathRemoveBackslashW(lpName->u.pOleStr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pwszDosFileName);
|
2005-05-24 13:45:47 +02:00
|
|
|
}
|
2010-11-08 00:22:11 +01:00
|
|
|
} else if (_ILIsValue(pidl)) {
|
|
|
|
STRRET str;
|
|
|
|
PWSTR path, file;
|
|
|
|
|
|
|
|
/* We are looking for the complete path to a file */
|
|
|
|
|
|
|
|
/* Get the complete path for the current folder object */
|
2012-07-29 10:51:05 +02:00
|
|
|
hr = IShellFolder2_GetDisplayNameOf(iface, (LPITEMIDLIST)&emptyIDL, uFlags, &str);
|
2010-11-08 00:22:11 +01:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = StrRetToStrW(&str, NULL, &path);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
|
|
|
|
/* Get the child filename */
|
2012-07-29 10:51:05 +02:00
|
|
|
hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_FORPARSING | SHGDN_INFOLDER, &str);
|
2010-11-08 00:22:11 +01:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = StrRetToStrW(&str, NULL, &file);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
static const WCHAR slashW = '/';
|
|
|
|
UINT len_path = strlenW(path), len_file = strlenW(file);
|
|
|
|
|
|
|
|
/* Now, combine them */
|
|
|
|
lpName->uType = STRRET_WSTR;
|
|
|
|
lpName->u.pOleStr = SHAlloc( (len_path + len_file + 2)*sizeof(WCHAR) );
|
|
|
|
lstrcpyW(lpName->u.pOleStr, path);
|
|
|
|
if (This->m_dwPathMode == PATHMODE_UNIX &&
|
|
|
|
lpName->u.pOleStr[len_path-1] != slashW) {
|
|
|
|
lpName->u.pOleStr[len_path] = slashW;
|
|
|
|
lpName->u.pOleStr[len_path+1] = '\0';
|
|
|
|
} else
|
|
|
|
PathAddBackslashW(lpName->u.pOleStr);
|
|
|
|
lstrcatW(lpName->u.pOleStr, file);
|
|
|
|
|
|
|
|
CoTaskMemFree(file);
|
|
|
|
} else
|
|
|
|
WARN("Failed to convert strret (file)\n");
|
|
|
|
}
|
|
|
|
CoTaskMemFree(path);
|
|
|
|
} else
|
|
|
|
WARN("Failed to convert strret (path)\n");
|
|
|
|
}
|
2005-05-07 14:17:02 +02:00
|
|
|
} else {
|
|
|
|
IShellFolder *pSubFolder;
|
|
|
|
|
2012-07-29 10:51:05 +02:00
|
|
|
hr = IShellFolder2_BindToObject(iface, pidl, NULL, &IID_IShellFolder, (void**)&pSubFolder);
|
2010-11-08 00:22:11 +01:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = IShellFolder_GetDisplayNameOf(pSubFolder, (LPITEMIDLIST)&emptyIDL, uFlags, lpName);
|
|
|
|
IShellFolder_Release(pSubFolder);
|
|
|
|
} else if (FAILED(hr) && !_ILIsPidlSimple(pidl)) {
|
|
|
|
LPITEMIDLIST pidl_parent = ILClone(pidl);
|
|
|
|
LPITEMIDLIST pidl_child = ILFindLastID(pidl);
|
|
|
|
|
|
|
|
/* Might be a file, try binding to its parent */
|
|
|
|
ILRemoveLastID(pidl_parent);
|
2012-07-29 10:51:05 +02:00
|
|
|
hr = IShellFolder2_BindToObject(iface, pidl_parent, NULL, &IID_IShellFolder, (void**)&pSubFolder);
|
2010-11-08 00:22:11 +01:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
hr = IShellFolder_GetDisplayNameOf(pSubFolder, pidl_child, uFlags, lpName);
|
|
|
|
IShellFolder_Release(pSubFolder);
|
|
|
|
}
|
|
|
|
ILFree(pidl_parent);
|
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
} else {
|
2006-01-03 13:23:59 +01:00
|
|
|
WCHAR wszFileName[MAX_PATH];
|
|
|
|
if (!_ILSimpleGetTextW(pidl, wszFileName, MAX_PATH)) return E_INVALIDARG;
|
|
|
|
lpName->uType = STRRET_WSTR;
|
|
|
|
lpName->u.pOleStr = SHAlloc((lstrlenW(wszFileName)+1)*sizeof(WCHAR));
|
|
|
|
if (!lpName->u.pOleStr) return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
lstrcpyW(lpName->u.pOleStr, wszFileName);
|
|
|
|
if (!(GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING) && This->m_dwPathMode == PATHMODE_DOS &&
|
|
|
|
!_ILIsFolder(pidl) && wszFileName[0] != '.' && SHELL_FS_HideExtension(wszFileName))
|
|
|
|
{
|
|
|
|
PathRemoveExtensionW(lpName->u.pOleStr);
|
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2006-01-03 13:23:59 +01:00
|
|
|
TRACE("--> %s\n", debugstr_w(lpName->u.pOleStr));
|
2005-05-24 13:45:47 +02:00
|
|
|
|
2005-05-07 14:17:02 +02:00
|
|
|
return hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_SetNameOf(IShellFolder2* iface, HWND hwnd,
|
2006-01-16 20:37:51 +01:00
|
|
|
LPCITEMIDLIST pidl, LPCOLESTR lpcwszName, SHGDNF uFlags, LPITEMIDLIST* ppidlOut)
|
2005-03-09 17:41:17 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-07-05 18:18:00 +02:00
|
|
|
|
2006-01-16 20:37:51 +01:00
|
|
|
static const WCHAR awcInvalidChars[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
|
2005-08-12 12:32:47 +02:00
|
|
|
char szSrc[FILENAME_MAX], szDest[FILENAME_MAX];
|
2010-06-28 16:35:36 +02:00
|
|
|
WCHAR wszSrcRelative[MAX_PATH], *pwszExt = NULL;
|
2008-11-11 23:27:29 +01:00
|
|
|
unsigned int i;
|
2010-06-28 16:35:36 +02:00
|
|
|
int cBasePathLen = lstrlenA(This->m_pszPath), cNameLen;
|
2005-07-05 18:18:00 +02:00
|
|
|
struct stat statDest;
|
2006-01-16 20:37:51 +01:00
|
|
|
LPITEMIDLIST pidlSrc, pidlDest, pidlRelativeDest;
|
|
|
|
LPOLESTR lpwszName;
|
|
|
|
HRESULT hr;
|
2005-07-18 11:12:20 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %p %s 0x%08x %p)\n", This, hwnd, pidl, debugstr_w(lpcwszName), uFlags, ppidlOut);
|
2005-07-05 18:18:00 +02:00
|
|
|
|
2006-01-16 20:37:51 +01:00
|
|
|
/* prepare to fail */
|
2005-07-05 18:18:00 +02:00
|
|
|
if (ppidlOut)
|
|
|
|
*ppidlOut = NULL;
|
|
|
|
|
2006-01-16 20:37:51 +01:00
|
|
|
/* pidl has to contain a single non-empty SHITEMID */
|
|
|
|
if (_ILIsDesktop(pidl) || !_ILIsPidlSimple(pidl) || !_ILGetTextPointer(pidl))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* check for invalid characters in lpcwszName. */
|
|
|
|
for (i=0; i < sizeof(awcInvalidChars)/sizeof(*awcInvalidChars); i++)
|
|
|
|
if (StrChrW(lpcwszName, awcInvalidChars[i]))
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_CANCELLED);
|
|
|
|
|
2005-07-05 18:18:00 +02:00
|
|
|
/* build source path */
|
|
|
|
memcpy(szSrc, This->m_pszPath, cBasePathLen);
|
2006-01-03 13:23:59 +01:00
|
|
|
UNIXFS_filename_from_shitemid(pidl, szSrc + cBasePathLen);
|
2005-07-05 18:18:00 +02:00
|
|
|
|
|
|
|
/* build destination path */
|
2006-01-16 20:37:51 +01:00
|
|
|
memcpy(szDest, This->m_pszPath, cBasePathLen);
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, lpcwszName, -1, szDest+cBasePathLen,
|
|
|
|
FILENAME_MAX-cBasePathLen, NULL, NULL);
|
|
|
|
|
|
|
|
/* If the filename's extension is hidden to the user, we have to append it. */
|
|
|
|
if (!(uFlags & SHGDN_FORPARSING) &&
|
|
|
|
_ILSimpleGetTextW(pidl, wszSrcRelative, MAX_PATH) &&
|
|
|
|
SHELL_FS_HideExtension(wszSrcRelative))
|
|
|
|
{
|
|
|
|
int cLenDest = strlen(szDest);
|
2010-06-28 16:35:36 +02:00
|
|
|
pwszExt = PathFindExtensionW(wszSrcRelative);
|
2006-01-16 20:37:51 +01:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, pwszExt, -1, szDest + cLenDest,
|
|
|
|
FILENAME_MAX - cLenDest, NULL, NULL);
|
|
|
|
}
|
2005-07-05 18:18:00 +02:00
|
|
|
|
|
|
|
TRACE("src=%s dest=%s\n", szSrc, szDest);
|
|
|
|
|
|
|
|
/* Fail, if destination does already exist */
|
|
|
|
if (!stat(szDest, &statDest))
|
|
|
|
return E_FAIL;
|
2005-07-18 11:12:20 +02:00
|
|
|
|
|
|
|
/* Rename the file */
|
|
|
|
if (rename(szSrc, szDest))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/* Build a pidl for the path of the renamed file */
|
2010-06-28 16:35:36 +02:00
|
|
|
cNameLen = lstrlenW(lpcwszName) + 1;
|
|
|
|
if(pwszExt)
|
|
|
|
cNameLen += lstrlenW(pwszExt);
|
|
|
|
lpwszName = SHAlloc(cNameLen*sizeof(WCHAR)); /* due to const correctness. */
|
2006-01-16 20:37:51 +01:00
|
|
|
lstrcpyW(lpwszName, lpcwszName);
|
2010-06-28 16:35:36 +02:00
|
|
|
if(pwszExt)
|
|
|
|
lstrcatW(lpwszName, pwszExt);
|
|
|
|
|
2006-01-16 20:37:51 +01:00
|
|
|
hr = IShellFolder2_ParseDisplayName(iface, NULL, NULL, lpwszName, NULL, &pidlRelativeDest, NULL);
|
|
|
|
SHFree(lpwszName);
|
|
|
|
if (FAILED(hr)) {
|
2005-07-18 11:12:20 +02:00
|
|
|
rename(szDest, szSrc); /* Undo the renaming */
|
|
|
|
return E_FAIL;
|
2005-07-05 18:18:00 +02:00
|
|
|
}
|
2006-01-16 20:37:51 +01:00
|
|
|
pidlDest = ILCombine(This->m_pidlLocation, pidlRelativeDest);
|
|
|
|
ILFree(pidlRelativeDest);
|
|
|
|
pidlSrc = ILCombine(This->m_pidlLocation, pidl);
|
2005-07-18 11:12:20 +02:00
|
|
|
|
|
|
|
/* Inform the shell */
|
|
|
|
if (_ILIsFolder(ILFindLastID(pidlDest)))
|
|
|
|
SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_IDLIST, pidlSrc, pidlDest);
|
|
|
|
else
|
|
|
|
SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_IDLIST, pidlSrc, pidlDest);
|
|
|
|
|
|
|
|
if (ppidlOut)
|
2006-01-16 20:37:51 +01:00
|
|
|
*ppidlOut = ILClone(ILFindLastID(pidlDest));
|
|
|
|
|
|
|
|
ILFree(pidlSrc);
|
|
|
|
ILFree(pidlDest);
|
2005-07-18 11:12:20 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_EnumSearches(IShellFolder2* iface, IEnumExtraSearch **ppEnum)
|
2005-04-12 13:58:05 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, ppEnum);
|
2005-04-12 13:58:05 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetDefaultColumn(IShellFolder2* iface,
|
|
|
|
DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
|
2005-04-12 13:58:05 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(0x%x %p %p)\n", This, dwReserved, pSort, pDisplay);
|
2009-02-14 00:07:32 +01:00
|
|
|
|
|
|
|
if (pSort)
|
|
|
|
*pSort = 0;
|
|
|
|
if (pDisplay)
|
|
|
|
*pDisplay = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
2005-04-12 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetDefaultColumnState(IShellFolder2* iface,
|
|
|
|
UINT column, SHCOLSTATEF *flags)
|
2005-04-12 13:58:05 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
FIXME("(%p)->(%u %p): stub\n", This, column, flags);
|
2005-04-12 13:58:05 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetDefaultSearchGUID(IShellFolder2* iface,
|
|
|
|
GUID *guid)
|
2005-04-12 13:58:05 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, guid);
|
2005-04-12 13:58:05 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetDetailsEx(IShellFolder2* iface,
|
2005-04-12 13:58:05 +02:00
|
|
|
LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
FIXME("(%p)->(%p %p %p): stub\n", This, pidl, pscid, pv);
|
2005-04-12 13:58:05 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2005-07-15 13:43:25 +02:00
|
|
|
#define SHELLVIEWCOLUMNS 7
|
2005-04-25 12:56:29 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_GetDetailsOf(IShellFolder2* iface,
|
2005-04-12 13:58:05 +02:00
|
|
|
LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
2005-04-12 13:58:05 +02:00
|
|
|
HRESULT hr = E_FAIL;
|
2005-04-25 12:56:29 +02:00
|
|
|
struct passwd *pPasswd;
|
|
|
|
struct group *pGroup;
|
2010-04-18 16:04:25 +02:00
|
|
|
struct stat statItem;
|
|
|
|
|
|
|
|
static const shvheader unixfs_header[SHELLVIEWCOLUMNS] = {
|
2005-04-25 12:56:29 +02:00
|
|
|
{IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
|
2005-07-15 13:43:25 +02:00
|
|
|
{IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
|
|
|
|
{IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
|
|
|
|
{IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
|
|
|
|
{IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 9},
|
2005-04-25 12:56:29 +02:00
|
|
|
{IDS_SHV_COLUMN10, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7},
|
2005-07-15 13:43:25 +02:00
|
|
|
{IDS_SHV_COLUMN11, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 7}
|
2005-04-25 12:56:29 +02:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %d %p)\n", This, pidl, iColumn, psd);
|
2005-04-12 13:58:05 +02:00
|
|
|
|
2005-04-25 12:56:29 +02:00
|
|
|
if (!psd || iColumn >= SHELLVIEWCOLUMNS)
|
2005-04-12 13:58:05 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2010-04-18 16:04:25 +02:00
|
|
|
if (!pidl)
|
|
|
|
return SHELL32_GetColumnDetails(unixfs_header, iColumn, psd);
|
|
|
|
|
|
|
|
if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
|
|
|
|
char szPath[FILENAME_MAX];
|
|
|
|
strcpy(szPath, This->m_pszPath);
|
|
|
|
if (!UNIXFS_filename_from_shitemid(pidl, szPath + strlen(szPath)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (stat(szPath, &statItem))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
psd->str.u.cStr[0] = '\0';
|
|
|
|
psd->str.uType = STRRET_CSTR;
|
|
|
|
|
|
|
|
switch (iColumn) {
|
|
|
|
case 0:
|
|
|
|
hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
|
|
|
|
psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
|
|
|
|
psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
|
|
|
|
psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
|
|
|
|
psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
|
|
|
|
psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
|
|
|
|
psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
|
|
|
|
psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
|
|
|
|
psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
|
|
|
|
psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
|
|
|
|
psd->str.u.cStr[10] = '\0';
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
pPasswd = getpwuid(statItem.st_uid);
|
|
|
|
if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
pGroup = getgrgid(statItem.st_gid);
|
|
|
|
if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
|
|
|
|
break;
|
2005-04-12 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI ShellFolder2_MapColumnToSCID(IShellFolder2* iface, UINT column,
|
|
|
|
SHCOLUMNID *pscid)
|
2005-04-12 13:58:05 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IShellFolder2(iface);
|
|
|
|
FIXME("(%p)->(%u %p): stub\n", This, column, pscid);
|
2005-04-12 13:58:05 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static const IShellFolder2Vtbl ShellFolder2Vtbl = {
|
|
|
|
ShellFolder2_QueryInterface,
|
|
|
|
ShellFolder2_AddRef,
|
|
|
|
ShellFolder2_Release,
|
|
|
|
ShellFolder2_ParseDisplayName,
|
|
|
|
ShellFolder2_EnumObjects,
|
|
|
|
ShellFolder2_BindToObject,
|
|
|
|
ShellFolder2_BindToStorage,
|
|
|
|
ShellFolder2_CompareIDs,
|
|
|
|
ShellFolder2_CreateViewObject,
|
|
|
|
ShellFolder2_GetAttributesOf,
|
|
|
|
ShellFolder2_GetUIObjectOf,
|
|
|
|
ShellFolder2_GetDisplayNameOf,
|
|
|
|
ShellFolder2_SetNameOf,
|
|
|
|
ShellFolder2_GetDefaultSearchGUID,
|
|
|
|
ShellFolder2_EnumSearches,
|
|
|
|
ShellFolder2_GetDefaultColumn,
|
|
|
|
ShellFolder2_GetDefaultColumnState,
|
|
|
|
ShellFolder2_GetDetailsEx,
|
|
|
|
ShellFolder2_GetDetailsOf,
|
|
|
|
ShellFolder2_MapColumnToSCID
|
2005-03-09 17:41:17 +01:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistFolder3_QueryInterface(IPersistFolder3* iface, REFIID riid,
|
2005-03-09 17:41:17 +01:00
|
|
|
void** ppvObject)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
|
|
|
return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppvObject);
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI PersistFolder3_AddRef(IPersistFolder3* iface)
|
2005-03-09 17:41:17 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
|
|
|
return IShellFolder2_AddRef(&This->IShellFolder2_iface);
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI PersistFolder3_Release(IPersistFolder3* iface)
|
2005-03-09 17:41:17 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
|
|
|
return IShellFolder2_Release(&This->IShellFolder2_iface);
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistFolder3_GetClassID(IPersistFolder3* iface, CLSID* pClassID)
|
|
|
|
{
|
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
2005-08-19 12:01:07 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pClassID);
|
2005-08-19 12:01:07 +02:00
|
|
|
|
|
|
|
if (!pClassID)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-03-17 22:36:59 +01:00
|
|
|
*pClassID = *This->m_pCLSID;
|
2005-08-19 12:01:07 +02:00
|
|
|
return S_OK;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistFolder3_Initialize(IPersistFolder3* iface, LPCITEMIDLIST pidl)
|
2005-03-09 17:41:17 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
2005-11-05 11:44:28 +01:00
|
|
|
LPCITEMIDLIST current = pidl;
|
|
|
|
char szBasePath[FILENAME_MAX] = "/";
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pidl);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-07-11 12:24:09 +02:00
|
|
|
/* Find the UnixFolderClass root */
|
|
|
|
while (current->mkid.cb) {
|
2006-01-17 15:58:52 +01:00
|
|
|
if ((_ILIsDrive(current) && IsEqualCLSID(This->m_pCLSID, &CLSID_ShellFSFolder)) ||
|
|
|
|
(_ILIsSpecialFolder(current) && IsEqualCLSID(This->m_pCLSID, _ILGetGUIDPointer(current))))
|
|
|
|
{
|
2005-07-11 12:24:09 +02:00
|
|
|
break;
|
2006-01-17 15:58:52 +01:00
|
|
|
}
|
2005-07-11 12:24:09 +02:00
|
|
|
current = ILGetNext(current);
|
|
|
|
}
|
2005-06-25 19:56:13 +02:00
|
|
|
|
2009-11-19 09:10:03 +01:00
|
|
|
if (current->mkid.cb) {
|
2006-01-17 15:58:52 +01:00
|
|
|
if (_ILIsDrive(current)) {
|
2011-11-22 23:00:39 +01:00
|
|
|
WCHAR wszDrive[] = { '?', ':', '\\', 0 };
|
2006-01-17 15:58:52 +01:00
|
|
|
wszDrive[0] = (WCHAR)*_ILGetTextPointer(current);
|
|
|
|
if (!UNIXFS_get_unix_path(wszDrive, szBasePath))
|
|
|
|
return E_FAIL;
|
|
|
|
} else if (IsEqualIID(&CLSID_MyDocuments, _ILGetGUIDPointer(current))) {
|
2005-08-26 12:05:34 +02:00
|
|
|
WCHAR wszMyDocumentsPath[MAX_PATH];
|
|
|
|
if (!SHGetSpecialFolderPathW(0, wszMyDocumentsPath, CSIDL_PERSONAL, FALSE))
|
|
|
|
return E_FAIL;
|
|
|
|
PathAddBackslashW(wszMyDocumentsPath);
|
|
|
|
if (!UNIXFS_get_unix_path(wszMyDocumentsPath, szBasePath))
|
|
|
|
return E_FAIL;
|
2005-11-05 11:44:28 +01:00
|
|
|
}
|
|
|
|
current = ILGetNext(current);
|
2005-07-11 12:24:09 +02:00
|
|
|
} else if (_ILIsDesktop(pidl) || _ILIsValue(pidl) || _ILIsFolder(pidl)) {
|
|
|
|
/* Path rooted at Desktop */
|
|
|
|
WCHAR wszDesktopPath[MAX_PATH];
|
2005-08-26 12:05:34 +02:00
|
|
|
if (!SHGetSpecialFolderPathW(0, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE))
|
|
|
|
return E_FAIL;
|
2005-07-11 12:24:09 +02:00
|
|
|
PathAddBackslashW(wszDesktopPath);
|
|
|
|
if (!UNIXFS_get_unix_path(wszDesktopPath, szBasePath))
|
|
|
|
return E_FAIL;
|
2005-11-05 11:44:28 +01:00
|
|
|
current = pidl;
|
|
|
|
} else if (IsEqualCLSID(This->m_pCLSID, &CLSID_FolderShortcut)) {
|
|
|
|
/* FolderShortcuts' Initialize method only sets the ITEMIDLIST, which
|
|
|
|
* specifies the location in the shell namespace, but leaves the
|
|
|
|
* target folder (m_pszPath) alone. See unit tests in tests/shlfolder.c */
|
|
|
|
This->m_pidlLocation = ILClone(pidl);
|
|
|
|
return S_OK;
|
2005-07-11 12:24:09 +02:00
|
|
|
} else {
|
|
|
|
ERR("Unknown pidl type!\n");
|
|
|
|
pdump(pidl);
|
|
|
|
return E_INVALIDARG;
|
2005-06-21 11:42:38 +02:00
|
|
|
}
|
2005-11-05 11:44:28 +01:00
|
|
|
|
2005-07-11 12:24:09 +02:00
|
|
|
This->m_pidlLocation = ILClone(pidl);
|
2005-11-05 11:44:28 +01:00
|
|
|
return UNIXFS_initialize_target_folder(This, szBasePath, current, 0);
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistFolder3_GetCurFolder(IPersistFolder3* iface, LPITEMIDLIST* ppidl)
|
2005-05-12 11:56:04 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
2005-05-24 13:45:47 +02:00
|
|
|
|
|
|
|
TRACE ("(iface=%p, ppidl=%p)\n", iface, ppidl);
|
2005-05-12 11:56:04 +02:00
|
|
|
|
|
|
|
if (!ppidl)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppidl = ILClone (This->m_pidlLocation);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2005-07-20 12:44:54 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistFolder3_InitializeEx(IPersistFolder3 *iface, IBindCtx *pbc,
|
2005-07-20 12:44:54 +02:00
|
|
|
LPCITEMIDLIST pidlRoot, const PERSIST_FOLDER_TARGET_INFO *ppfti)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
2005-07-20 12:44:54 +02:00
|
|
|
WCHAR wszTargetDosPath[MAX_PATH];
|
|
|
|
char szTargetPath[FILENAME_MAX] = "";
|
2005-05-24 13:45:47 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %p %p)\n", This, pbc, pidlRoot, ppfti);
|
2005-07-20 12:44:54 +02:00
|
|
|
|
|
|
|
/* If no PERSIST_FOLDER_TARGET_INFO is given InitializeEx is equivalent to Initialize. */
|
|
|
|
if (!ppfti)
|
|
|
|
return IPersistFolder3_Initialize(iface, pidlRoot);
|
|
|
|
|
|
|
|
if (ppfti->csidl != -1) {
|
2005-09-07 15:28:38 +02:00
|
|
|
if (FAILED(SHGetFolderPathW(0, ppfti->csidl, NULL, 0, wszTargetDosPath)) ||
|
|
|
|
!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
|
|
|
|
{
|
|
|
|
return E_FAIL;
|
2005-07-20 12:44:54 +02:00
|
|
|
}
|
|
|
|
} else if (*ppfti->szTargetParsingName) {
|
2005-11-05 11:44:28 +01:00
|
|
|
lstrcpyW(wszTargetDosPath, ppfti->szTargetParsingName);
|
|
|
|
PathAddBackslashW(wszTargetDosPath);
|
|
|
|
if (!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath)) {
|
2005-09-07 15:28:38 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2005-07-20 12:44:54 +02:00
|
|
|
} else if (ppfti->pidlTargetFolder) {
|
2005-09-07 15:28:38 +02:00
|
|
|
if (!SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTargetDosPath) ||
|
|
|
|
!UNIXFS_get_unix_path(wszTargetDosPath, szTargetPath))
|
|
|
|
{
|
|
|
|
return E_FAIL;
|
2005-07-20 12:44:54 +02:00
|
|
|
}
|
2005-09-07 15:28:38 +02:00
|
|
|
} else {
|
|
|
|
return E_FAIL;
|
2005-07-20 12:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
This->m_pszPath = SHAlloc(lstrlenA(szTargetPath)+1);
|
|
|
|
if (!This->m_pszPath)
|
|
|
|
return E_FAIL;
|
|
|
|
lstrcpyA(This->m_pszPath, szTargetPath);
|
|
|
|
This->m_pidlLocation = ILClone(pidlRoot);
|
2005-09-07 15:28:38 +02:00
|
|
|
This->m_dwAttributes = (ppfti->dwAttributes != -1) ? ppfti->dwAttributes :
|
|
|
|
(SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|SFGAO_CANRENAME|SFGAO_FILESYSTEM);
|
2005-07-20 12:44:54 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistFolder3_GetFolderTargetInfo(IPersistFolder3 *iface,
|
2005-07-20 12:44:54 +02:00
|
|
|
PERSIST_FOLDER_TARGET_INFO *ppfti)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistFolder3(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, ppfti);
|
2005-07-20 12:44:54 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static const IPersistFolder3Vtbl PersistFolder3Vtbl = {
|
|
|
|
PersistFolder3_QueryInterface,
|
|
|
|
PersistFolder3_AddRef,
|
|
|
|
PersistFolder3_Release,
|
|
|
|
PersistFolder3_GetClassID,
|
|
|
|
PersistFolder3_Initialize,
|
|
|
|
PersistFolder3_GetCurFolder,
|
|
|
|
PersistFolder3_InitializeEx,
|
|
|
|
PersistFolder3_GetFolderTargetInfo
|
2005-03-09 17:41:17 +01:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistPropertyBag_QueryInterface(IPersistPropertyBag* iface,
|
2005-11-28 20:40:50 +01:00
|
|
|
REFIID riid, void** ppv)
|
2005-08-19 15:58:52 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppv);
|
2005-08-19 15:58:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI PersistPropertyBag_AddRef(IPersistPropertyBag* iface)
|
2005-08-19 15:58:52 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IShellFolder2_AddRef(&This->IShellFolder2_iface);
|
2005-08-19 15:58:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI PersistPropertyBag_Release(IPersistPropertyBag* iface)
|
2005-08-19 15:58:52 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IShellFolder2_Release(&This->IShellFolder2_iface);
|
2005-08-19 15:58:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistPropertyBag_GetClassID(IPersistPropertyBag* iface, CLSID* pClassID)
|
2005-08-19 15:58:52 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IPersistFolder3_GetClassID(&This->IPersistFolder3_iface, pClassID);
|
2005-08-19 15:58:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistPropertyBag_InitNew(IPersistPropertyBag* iface)
|
2005-08-19 15:58:52 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
2005-08-19 15:58:52 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistPropertyBag_Load(IPersistPropertyBag *iface,
|
2005-08-19 15:58:52 +02:00
|
|
|
IPropertyBag *pPropertyBag, IErrorLog *pErrorLog)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
|
2005-10-27 14:09:59 +02:00
|
|
|
static const WCHAR wszTarget[] = { 'T','a','r','g','e','t', 0 }, wszNull[] = { 0 };
|
|
|
|
PERSIST_FOLDER_TARGET_INFO pftiTarget;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %p)\n", This, pPropertyBag, pErrorLog);
|
2005-10-27 14:09:59 +02:00
|
|
|
|
|
|
|
if (!pPropertyBag)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
/* Get 'Target' property from the property bag. */
|
|
|
|
V_VT(&var) = VT_BSTR;
|
|
|
|
hr = IPropertyBag_Read(pPropertyBag, wszTarget, &var, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return E_FAIL;
|
|
|
|
lstrcpyW(pftiTarget.szTargetParsingName, V_BSTR(&var));
|
|
|
|
SysFreeString(V_BSTR(&var));
|
|
|
|
|
|
|
|
pftiTarget.pidlTargetFolder = NULL;
|
|
|
|
lstrcpyW(pftiTarget.szNetworkProvider, wszNull);
|
|
|
|
pftiTarget.dwAttributes = -1;
|
|
|
|
pftiTarget.csidl = -1;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
return IPersistFolder3_InitializeEx(&This->IPersistFolder3_iface, NULL, NULL, &pftiTarget);
|
2005-08-19 15:58:52 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI PersistPropertyBag_Save(IPersistPropertyBag *iface,
|
2005-08-19 15:58:52 +02:00
|
|
|
IPropertyBag *pPropertyBag, BOOL fClearDirty, BOOL fSaveAllProperties)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
FIXME("(%p): stub\n", This);
|
2005-08-19 15:58:52 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static const IPersistPropertyBagVtbl PersistPropertyBagVtbl = {
|
|
|
|
PersistPropertyBag_QueryInterface,
|
|
|
|
PersistPropertyBag_AddRef,
|
|
|
|
PersistPropertyBag_Release,
|
|
|
|
PersistPropertyBag_GetClassID,
|
|
|
|
PersistPropertyBag_InitNew,
|
|
|
|
PersistPropertyBag_Load,
|
|
|
|
PersistPropertyBag_Save
|
2005-08-19 15:58:52 +02:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI SFHelper_QueryInterface(ISFHelper* iface, REFIID riid, void** ppvObject)
|
2005-07-05 22:55:43 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
|
|
|
return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppvObject);
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI SFHelper_AddRef(ISFHelper* iface)
|
2005-07-05 22:55:43 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
|
|
|
return IShellFolder2_AddRef(&This->IShellFolder2_iface);
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI SFHelper_Release(ISFHelper* iface)
|
2005-07-05 22:55:43 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
|
|
|
return IShellFolder2_Release(&This->IShellFolder2_iface);
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI SFHelper_GetUniqueName(ISFHelper* iface, LPWSTR pwszName, UINT uLen)
|
2005-07-05 22:55:43 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
2005-07-06 13:11:00 +02:00
|
|
|
IEnumIDList *pEnum;
|
|
|
|
HRESULT hr;
|
|
|
|
LPITEMIDLIST pidlElem;
|
|
|
|
DWORD dwFetched;
|
|
|
|
int i;
|
2007-12-06 10:20:48 +01:00
|
|
|
WCHAR wszNewFolder[25];
|
2006-03-05 13:25:23 +01:00
|
|
|
static const WCHAR wszFormat[] = { '%','s',' ','%','d',0 };
|
2005-07-06 13:11:00 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %u)\n", This, pwszName, uLen);
|
2007-12-06 10:20:48 +01:00
|
|
|
|
|
|
|
LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, sizeof(wszNewFolder)/sizeof(WCHAR));
|
|
|
|
|
2006-03-05 13:25:23 +01:00
|
|
|
if (uLen < sizeof(wszNewFolder)/sizeof(WCHAR)+3)
|
2005-07-06 13:11:00 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
hr = IShellFolder2_EnumObjects(&This->IShellFolder2_iface, 0,
|
2005-07-06 13:11:00 +02:00
|
|
|
SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN, &pEnum);
|
|
|
|
if (SUCCEEDED(hr)) {
|
2006-03-05 13:25:23 +01:00
|
|
|
lstrcpynW(pwszName, wszNewFolder, uLen);
|
2005-07-06 13:11:00 +02:00
|
|
|
IEnumIDList_Reset(pEnum);
|
|
|
|
i = 2;
|
|
|
|
while ((IEnumIDList_Next(pEnum, 1, &pidlElem, &dwFetched) == S_OK) && (dwFetched == 1)) {
|
2006-03-05 13:25:23 +01:00
|
|
|
WCHAR wszTemp[MAX_PATH];
|
|
|
|
_ILSimpleGetTextW(pidlElem, wszTemp, MAX_PATH);
|
|
|
|
if (!lstrcmpiW(wszTemp, pwszName)) {
|
2005-07-06 13:11:00 +02:00
|
|
|
IEnumIDList_Reset(pEnum);
|
2006-03-05 13:25:23 +01:00
|
|
|
snprintfW(pwszName, uLen, wszFormat, wszNewFolder, i++);
|
2005-07-06 13:11:00 +02:00
|
|
|
if (i > 99) {
|
|
|
|
hr = E_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IEnumIDList_Release(pEnum);
|
|
|
|
}
|
|
|
|
return hr;
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI SFHelper_AddFolder(ISFHelper* iface, HWND hwnd, LPCWSTR pwszName,
|
2005-07-05 22:55:43 +02:00
|
|
|
LPITEMIDLIST* ppidlOut)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
2005-07-06 13:11:00 +02:00
|
|
|
char szNewDir[FILENAME_MAX];
|
2006-03-05 13:25:23 +01:00
|
|
|
int cBaseLen;
|
2005-07-06 13:11:00 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %s %p)\n", This, hwnd, debugstr_w(pwszName), ppidlOut);
|
2005-07-06 13:11:00 +02:00
|
|
|
|
|
|
|
if (ppidlOut)
|
|
|
|
*ppidlOut = NULL;
|
|
|
|
|
2006-03-05 13:25:23 +01:00
|
|
|
if (!This->m_pszPath || !(This->m_dwAttributes & SFGAO_FILESYSTEM))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
lstrcpynA(szNewDir, This->m_pszPath, FILENAME_MAX);
|
|
|
|
cBaseLen = lstrlenA(szNewDir);
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, pwszName, -1, szNewDir+cBaseLen, FILENAME_MAX-cBaseLen, 0, 0);
|
|
|
|
|
2008-02-04 15:25:18 +01:00
|
|
|
if (mkdir(szNewDir, 0777)) {
|
2005-07-06 13:11:00 +02:00
|
|
|
char szMessage[256 + FILENAME_MAX];
|
|
|
|
char szCaption[256];
|
|
|
|
|
|
|
|
LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, szCaption, sizeof(szCaption));
|
|
|
|
sprintf(szMessage, szCaption, szNewDir);
|
|
|
|
LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, szCaption, sizeof(szCaption));
|
|
|
|
MessageBoxA(hwnd, szMessage, szCaption, MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
} else {
|
|
|
|
LPITEMIDLIST pidlRelative;
|
|
|
|
|
|
|
|
/* Inform the shell */
|
2010-07-21 21:04:22 +02:00
|
|
|
if (SUCCEEDED(UNIXFS_path_to_pidl(This, NULL, pwszName, &pidlRelative))) {
|
2005-07-06 13:11:00 +02:00
|
|
|
LPITEMIDLIST pidlAbsolute = ILCombine(This->m_pidlLocation, pidlRelative);
|
|
|
|
if (ppidlOut)
|
|
|
|
*ppidlOut = pidlRelative;
|
|
|
|
else
|
|
|
|
ILFree(pidlRelative);
|
|
|
|
SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
|
|
|
|
ILFree(pidlAbsolute);
|
2006-02-22 12:04:02 +01:00
|
|
|
} else return E_FAIL;
|
2005-07-06 13:11:00 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2006-07-06 20:38:37 +02:00
|
|
|
/*
|
|
|
|
* Delete specified files by converting the path to DOS paths and calling
|
|
|
|
* SHFileOperationW. If an error occurs it returns an error code. If the paths can't
|
|
|
|
* be converted, S_FALSE is returned. In such situation DeleteItems will try to delete
|
|
|
|
* the files using syscalls
|
|
|
|
*/
|
2007-10-29 22:51:02 +01:00
|
|
|
static HRESULT UNIXFS_delete_with_shfileop(UnixFolder *This, UINT cidl, const LPCITEMIDLIST *apidl)
|
2006-07-06 20:38:37 +02:00
|
|
|
{
|
|
|
|
char szAbsolute[FILENAME_MAX], *pszRelative;
|
|
|
|
LPWSTR wszPathsList, wszListPos;
|
|
|
|
SHFILEOPSTRUCTW op;
|
|
|
|
HRESULT ret;
|
2008-11-11 23:27:29 +01:00
|
|
|
UINT i;
|
2006-07-06 20:38:37 +02:00
|
|
|
|
|
|
|
lstrcpyA(szAbsolute, This->m_pszPath);
|
|
|
|
pszRelative = szAbsolute + lstrlenA(szAbsolute);
|
|
|
|
|
|
|
|
wszListPos = wszPathsList = HeapAlloc(GetProcessHeap(), 0, cidl*MAX_PATH*sizeof(WCHAR)+1);
|
|
|
|
if (wszPathsList == NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
for (i=0; i<cidl; i++) {
|
|
|
|
LPWSTR wszDosPath;
|
|
|
|
|
|
|
|
if (!_ILIsFolder(apidl[i]) && !_ILIsValue(apidl[i]))
|
|
|
|
continue;
|
|
|
|
if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszPathsList);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
wszDosPath = wine_get_dos_file_name(szAbsolute);
|
|
|
|
if (wszDosPath == NULL || lstrlenW(wszDosPath) >= MAX_PATH)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszPathsList);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDosPath);
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
lstrcpyW(wszListPos, wszDosPath);
|
|
|
|
wszListPos += lstrlenW(wszListPos)+1;
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDosPath);
|
|
|
|
}
|
|
|
|
*wszListPos = 0;
|
|
|
|
|
|
|
|
ZeroMemory(&op, sizeof(op));
|
|
|
|
op.hwnd = GetActiveWindow();
|
|
|
|
op.wFunc = FO_DELETE;
|
|
|
|
op.pFrom = wszPathsList;
|
2006-07-19 18:37:02 +02:00
|
|
|
op.fFlags = FOF_ALLOWUNDO;
|
2006-07-06 20:38:37 +02:00
|
|
|
if (!SHFileOperationW(&op))
|
|
|
|
{
|
|
|
|
WARN("SHFileOperationW failed\n");
|
|
|
|
ret = E_FAIL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = S_OK;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszPathsList);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-29 22:51:02 +01:00
|
|
|
static HRESULT UNIXFS_delete_with_syscalls(UnixFolder *This, UINT cidl, const LPCITEMIDLIST *apidl)
|
2006-07-06 20:38:37 +02:00
|
|
|
{
|
|
|
|
char szAbsolute[FILENAME_MAX], *pszRelative;
|
2006-07-06 20:46:21 +02:00
|
|
|
static const WCHAR empty[] = {0};
|
2008-11-11 23:27:29 +01:00
|
|
|
UINT i;
|
2006-07-06 20:38:37 +02:00
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
if (!SHELL_ConfirmYesNoW(GetActiveWindow(), ASK_DELETE_SELECTED, empty))
|
2006-07-06 20:46:21 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2006-07-06 20:38:37 +02:00
|
|
|
lstrcpyA(szAbsolute, This->m_pszPath);
|
|
|
|
pszRelative = szAbsolute + lstrlenA(szAbsolute);
|
|
|
|
|
|
|
|
for (i=0; i<cidl; i++) {
|
|
|
|
if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (_ILIsFolder(apidl[i])) {
|
|
|
|
if (rmdir(szAbsolute))
|
|
|
|
return E_FAIL;
|
|
|
|
} else if (_ILIsValue(apidl[i])) {
|
|
|
|
if (unlink(szAbsolute))
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI SFHelper_DeleteItems(ISFHelper* iface, UINT cidl, LPCITEMIDLIST* apidl)
|
2005-07-05 22:55:43 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
2005-07-06 17:43:51 +02:00
|
|
|
char szAbsolute[FILENAME_MAX], *pszRelative;
|
|
|
|
LPITEMIDLIST pidlAbsolute;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
UINT i;
|
2006-07-06 20:38:37 +02:00
|
|
|
struct stat st;
|
2005-07-06 17:43:51 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%d %p)\n", This, cidl, apidl);
|
2005-07-06 17:43:51 +02:00
|
|
|
|
2006-07-06 20:38:37 +02:00
|
|
|
hr = UNIXFS_delete_with_shfileop(This, cidl, apidl);
|
|
|
|
if (hr == S_FALSE)
|
|
|
|
hr = UNIXFS_delete_with_syscalls(This, cidl, apidl);
|
|
|
|
|
2005-07-06 17:43:51 +02:00
|
|
|
lstrcpyA(szAbsolute, This->m_pszPath);
|
|
|
|
pszRelative = szAbsolute + lstrlenA(szAbsolute);
|
|
|
|
|
2006-07-06 20:38:37 +02:00
|
|
|
/* we need to manually send the notifies if the files doesn't exist */
|
|
|
|
for (i=0; i<cidl; i++) {
|
2006-01-03 13:23:59 +01:00
|
|
|
if (!UNIXFS_filename_from_shitemid(apidl[i], pszRelative))
|
2006-07-06 20:38:37 +02:00
|
|
|
continue;
|
2005-07-06 17:43:51 +02:00
|
|
|
pidlAbsolute = ILCombine(This->m_pidlLocation, apidl[i]);
|
2006-07-06 20:38:37 +02:00
|
|
|
if (stat(szAbsolute, &st))
|
|
|
|
{
|
|
|
|
if (_ILIsFolder(apidl[i])) {
|
2005-07-06 17:43:51 +02:00
|
|
|
SHChangeNotify(SHCNE_RMDIR, SHCNF_IDLIST, pidlAbsolute, NULL);
|
2006-07-06 20:38:37 +02:00
|
|
|
} else if (_ILIsValue(apidl[i])) {
|
2005-07-06 17:43:51 +02:00
|
|
|
SHChangeNotify(SHCNE_DELETE, SHCNF_IDLIST, pidlAbsolute, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ILFree(pidlAbsolute);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI SFHelper_CopyItems(ISFHelper* iface, IShellFolder *psfFrom,
|
2005-07-05 22:55:43 +02:00
|
|
|
UINT cidl, LPCITEMIDLIST *apidl)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_ISFHelper(iface);
|
2005-07-08 16:18:14 +02:00
|
|
|
DWORD dwAttributes;
|
|
|
|
UINT i;
|
|
|
|
HRESULT hr;
|
|
|
|
char szAbsoluteDst[FILENAME_MAX], *pszRelativeDst;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %d %p)\n", This, psfFrom, cidl, apidl);
|
2005-07-08 16:18:14 +02:00
|
|
|
|
|
|
|
if (!psfFrom || !cidl || !apidl)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* All source items have to be filesystem items. */
|
|
|
|
dwAttributes = SFGAO_FILESYSTEM;
|
|
|
|
hr = IShellFolder_GetAttributesOf(psfFrom, cidl, apidl, &dwAttributes);
|
|
|
|
if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
lstrcpyA(szAbsoluteDst, This->m_pszPath);
|
|
|
|
pszRelativeDst = szAbsoluteDst + strlen(szAbsoluteDst);
|
|
|
|
|
|
|
|
for (i=0; i<cidl; i++) {
|
|
|
|
WCHAR wszSrc[MAX_PATH];
|
|
|
|
char szSrc[FILENAME_MAX];
|
|
|
|
STRRET strret;
|
2007-11-20 20:54:58 +01:00
|
|
|
HRESULT res;
|
|
|
|
WCHAR *pwszDosSrc, *pwszDosDst;
|
2005-07-08 16:18:14 +02:00
|
|
|
|
|
|
|
/* Build the unix path of the current source item. */
|
|
|
|
if (FAILED(IShellFolder_GetDisplayNameOf(psfFrom, apidl[i], SHGDN_FORPARSING, &strret)))
|
|
|
|
return E_FAIL;
|
|
|
|
if (FAILED(StrRetToBufW(&strret, apidl[i], wszSrc, MAX_PATH)))
|
|
|
|
return E_FAIL;
|
|
|
|
if (!UNIXFS_get_unix_path(wszSrc, szSrc))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/* Build the unix path of the current destination item */
|
2006-01-03 13:23:59 +01:00
|
|
|
UNIXFS_filename_from_shitemid(apidl[i], pszRelativeDst);
|
2005-07-08 16:18:14 +02:00
|
|
|
|
2007-11-20 20:54:58 +01:00
|
|
|
pwszDosSrc = wine_get_dos_file_name(szSrc);
|
|
|
|
pwszDosDst = wine_get_dos_file_name(szAbsoluteDst);
|
|
|
|
|
|
|
|
if (pwszDosSrc && pwszDosDst)
|
|
|
|
res = UNIXFS_copy(pwszDosSrc, pwszDosDst);
|
|
|
|
else
|
|
|
|
res = E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pwszDosSrc);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pwszDosDst);
|
|
|
|
|
|
|
|
if (res != S_OK)
|
|
|
|
return res;
|
2005-07-08 16:18:14 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2005-07-05 22:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static const ISFHelperVtbl SFHelperVtbl = {
|
|
|
|
SFHelper_QueryInterface,
|
|
|
|
SFHelper_AddRef,
|
|
|
|
SFHelper_Release,
|
|
|
|
SFHelper_GetUniqueName,
|
|
|
|
SFHelper_AddFolder,
|
|
|
|
SFHelper_DeleteItems,
|
|
|
|
SFHelper_CopyItems
|
2005-07-05 22:55:43 +02:00
|
|
|
};
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI DropTarget_QueryInterface(IDropTarget* iface, REFIID riid, void** ppvObject)
|
2005-11-28 10:36:04 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
|
|
|
return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppvObject);
|
2005-11-28 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI DropTarget_AddRef(IDropTarget* iface)
|
2005-11-28 10:36:04 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
|
|
|
return IShellFolder2_AddRef(&This->IShellFolder2_iface);
|
2005-11-28 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static ULONG WINAPI DropTarget_Release(IDropTarget* iface)
|
2005-11-28 10:36:04 +01:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
|
|
|
return IShellFolder2_Release(&This->IShellFolder2_iface);
|
2005-11-28 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2005-11-28 20:40:50 +01:00
|
|
|
#define HIDA_GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0])
|
|
|
|
#define HIDA_GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1])
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI DropTarget_DragEnter(IDropTarget *iface, IDataObject *pDataObject,
|
2005-11-28 10:36:04 +01:00
|
|
|
DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
2005-11-28 20:40:50 +01:00
|
|
|
FORMATETC format;
|
|
|
|
STGMEDIUM medium;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p 0x%08x {.x=%d, .y=%d} %p)\n", This, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
|
2005-11-28 10:36:04 +01:00
|
|
|
|
2005-11-28 20:40:50 +01:00
|
|
|
if (!pdwEffect || !pDataObject)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* Compute a mask of supported drop-effects for this shellfolder object and the given data
|
|
|
|
* object. Dropping is only supported on folders, which represent filesystem locations. One
|
|
|
|
* can't drop on file objects. And the 'move' drop effect is only supported, if the source
|
|
|
|
* folder is not identical to the target folder. */
|
|
|
|
This->m_dwDropEffectsMask = DROPEFFECT_NONE;
|
|
|
|
InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
|
|
|
|
if ((This->m_dwAttributes & SFGAO_FILESYSTEM) && /* Only drop to filesystem folders */
|
|
|
|
_ILIsFolder(ILFindLastID(This->m_pidlLocation)) && /* Only drop to folders, not to files */
|
|
|
|
SUCCEEDED(IDataObject_GetData(pDataObject, &format, &medium))) /* Only ShellIDList format */
|
|
|
|
{
|
|
|
|
LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
|
|
|
|
This->m_dwDropEffectsMask |= DROPEFFECT_COPY|DROPEFFECT_LINK;
|
|
|
|
|
|
|
|
if (pidaShellIDList) { /* Files can only be moved between two different folders */
|
|
|
|
if (!ILIsEqual(HIDA_GetPIDLFolder(pidaShellIDList), This->m_pidlLocation))
|
|
|
|
This->m_dwDropEffectsMask |= DROPEFFECT_MOVE;
|
|
|
|
GlobalUnlock(medium.u.hGlobal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
|
|
|
|
|
|
|
|
return S_OK;
|
2005-11-28 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI DropTarget_DragOver(IDropTarget *iface, DWORD dwKeyState,
|
2005-11-28 10:36:04 +01:00
|
|
|
POINTL pt, DWORD *pdwEffect)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(0x%08x {.x=%d, .y=%d} %p)\n", This, dwKeyState, pt.x, pt.y, pdwEffect);
|
2005-11-28 10:36:04 +01:00
|
|
|
|
2005-11-28 20:40:50 +01:00
|
|
|
if (!pdwEffect)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*pdwEffect = KeyStateToDropEffect(dwKeyState) & This->m_dwDropEffectsMask;
|
|
|
|
|
|
|
|
return S_OK;
|
2005-11-28 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI DropTarget_DragLeave(IDropTarget *iface)
|
|
|
|
{
|
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2005-11-28 20:40:50 +01:00
|
|
|
This->m_dwDropEffectsMask = DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
2005-11-28 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT WINAPI DropTarget_Drop(IDropTarget *iface, IDataObject *pDataObject,
|
2005-11-28 10:36:04 +01:00
|
|
|
DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
|
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This = impl_from_IDropTarget(iface);
|
2005-11-28 20:40:50 +01:00
|
|
|
FORMATETC format;
|
|
|
|
STGMEDIUM medium;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
TRACE("(%p)->(%p %d {.x=%d, .y=%d} %p) semi-stub\n",
|
|
|
|
This, pDataObject, dwKeyState, pt.x, pt.y, pdwEffect);
|
2005-11-28 20:40:50 +01:00
|
|
|
|
|
|
|
InitFormatEtc(format, cfShellIDList, TYMED_HGLOBAL);
|
|
|
|
hr = IDataObject_GetData(pDataObject, &format, &medium);
|
2008-10-08 01:32:38 +02:00
|
|
|
if (FAILED(hr))
|
2005-11-28 20:40:50 +01:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (medium.tymed == TYMED_HGLOBAL) {
|
|
|
|
IShellFolder *psfSourceFolder, *psfDesktopFolder;
|
|
|
|
LPIDA pidaShellIDList = GlobalLock(medium.u.hGlobal);
|
|
|
|
STRRET strret;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (!pidaShellIDList)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2005-11-28 10:36:04 +01:00
|
|
|
|
2005-11-28 20:40:50 +01:00
|
|
|
hr = SHGetDesktopFolder(&psfDesktopFolder);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
GlobalUnlock(medium.u.hGlobal);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellFolder_BindToObject(psfDesktopFolder, HIDA_GetPIDLFolder(pidaShellIDList), NULL,
|
|
|
|
&IID_IShellFolder, (LPVOID*)&psfSourceFolder);
|
|
|
|
IShellFolder_Release(psfDesktopFolder);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
GlobalUnlock(medium.u.hGlobal);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pidaShellIDList->cidl; i++) {
|
|
|
|
WCHAR wszSourcePath[MAX_PATH];
|
|
|
|
|
|
|
|
hr = IShellFolder_GetDisplayNameOf(psfSourceFolder, HIDA_GetPIDLItem(pidaShellIDList, i),
|
|
|
|
SHGDN_FORPARSING, &strret);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = StrRetToBufW(&strret, NULL, wszSourcePath, MAX_PATH);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (*pdwEffect) {
|
|
|
|
case DROPEFFECT_MOVE:
|
|
|
|
FIXME("Move %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
|
|
|
|
break;
|
|
|
|
case DROPEFFECT_COPY:
|
|
|
|
FIXME("Copy %s to %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
|
|
|
|
break;
|
|
|
|
case DROPEFFECT_LINK:
|
|
|
|
FIXME("Link %s from %s!\n", debugstr_w(wszSourcePath), This->m_pszPath);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IShellFolder_Release(psfSourceFolder);
|
|
|
|
GlobalUnlock(medium.u.hGlobal);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-11-28 10:36:04 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
static const IDropTargetVtbl DropTargetVtbl = {
|
|
|
|
DropTarget_QueryInterface,
|
|
|
|
DropTarget_AddRef,
|
|
|
|
DropTarget_Release,
|
|
|
|
DropTarget_DragEnter,
|
|
|
|
DropTarget_DragOver,
|
|
|
|
DropTarget_DragLeave,
|
|
|
|
DropTarget_Drop
|
2005-11-28 10:36:04 +01:00
|
|
|
};
|
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
/******************************************************************************
|
2005-05-24 13:45:47 +02:00
|
|
|
* Unix[Dos]Folder_Constructor [Internal]
|
2005-03-09 17:41:17 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pUnkOuter [I] Outer class for aggregation. Currently ignored.
|
|
|
|
* riid [I] Interface asked for by the client.
|
|
|
|
* ppv [O] Pointer to an riid interface to the UnixFolder object.
|
|
|
|
*
|
|
|
|
* NOTES
|
2005-05-24 13:45:47 +02:00
|
|
|
* Those are the only functions exported from shfldr_unixfs.c. They are called from
|
|
|
|
* shellole.c's default class factory and thus have to exhibit a LPFNCREATEINSTANCE
|
2005-03-09 17:41:17 +01:00
|
|
|
* compatible signature.
|
2005-05-24 13:45:47 +02:00
|
|
|
*
|
|
|
|
* The UnixDosFolder_Constructor sets the dwPathMode member to PATHMODE_DOS. This
|
|
|
|
* means that paths are converted from dos to unix and back at the interfaces.
|
2005-03-09 17:41:17 +01:00
|
|
|
*/
|
2012-01-11 12:52:39 +01:00
|
|
|
static HRESULT CreateUnixFolder(IUnknown *outer, REFIID riid, void **ppv, const CLSID *clsid)
|
2005-08-19 12:01:07 +02:00
|
|
|
{
|
2012-01-11 12:52:39 +01:00
|
|
|
UnixFolder *This;
|
|
|
|
HRESULT hr;
|
2005-09-07 15:28:38 +02:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
if (outer) {
|
2005-09-07 15:28:38 +02:00
|
|
|
FIXME("Aggregation not yet implemented!\n");
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2012-01-11 12:52:39 +01:00
|
|
|
This = SHAlloc((ULONG)sizeof(UnixFolder));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IShellFolder2_iface.lpVtbl = &ShellFolder2Vtbl;
|
|
|
|
This->IPersistFolder3_iface.lpVtbl = &PersistFolder3Vtbl;
|
|
|
|
This->IPersistPropertyBag_iface.lpVtbl = &PersistPropertyBagVtbl;
|
|
|
|
This->ISFHelper_iface.lpVtbl = &SFHelperVtbl;
|
|
|
|
This->IDropTarget_iface.lpVtbl = &DropTargetVtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
This->m_pszPath = NULL;
|
|
|
|
This->m_pidlLocation = NULL;
|
|
|
|
This->m_dwPathMode = IsEqualCLSID(&CLSID_UnixFolder, clsid) ? PATHMODE_UNIX : PATHMODE_DOS;
|
|
|
|
This->m_dwAttributes = 0;
|
|
|
|
This->m_pCLSID = clsid;
|
|
|
|
This->m_dwDropEffectsMask = DROPEFFECT_NONE;
|
|
|
|
|
|
|
|
hr = IShellFolder2_QueryInterface(&This->IShellFolder2_iface, riid, ppv);
|
|
|
|
IShellFolder2_Release(&This->IShellFolder2_iface);
|
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
|
|
|
|
TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
|
2005-08-30 11:58:21 +02:00
|
|
|
return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixFolder);
|
2005-05-24 13:45:47 +02:00
|
|
|
}
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-05-24 13:45:47 +02:00
|
|
|
HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
|
|
|
|
TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
|
2005-08-30 11:58:21 +02:00
|
|
|
return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_UnixDosFolder);
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
2005-08-19 15:58:52 +02:00
|
|
|
HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
|
|
|
|
TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
|
2005-08-30 11:58:21 +02:00
|
|
|
return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_FolderShortcut);
|
2005-08-19 15:58:52 +02:00
|
|
|
}
|
|
|
|
|
2005-08-26 12:05:34 +02:00
|
|
|
HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv) {
|
|
|
|
TRACE("(pUnkOuter=%p, riid=%p, ppv=%p)\n", pUnkOuter, riid, ppv);
|
2005-08-30 11:58:21 +02:00
|
|
|
return CreateUnixFolder(pUnkOuter, riid, ppv, &CLSID_MyDocuments);
|
2005-08-26 12:05:34 +02:00
|
|
|
}
|
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* UnixSubFolderIterator
|
|
|
|
*
|
|
|
|
* Class whose heap based objects represent iterators over the sub-directories
|
|
|
|
* of a given UnixFolder object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* UnixSubFolderIterator object layout and typedef.
|
|
|
|
*/
|
|
|
|
typedef struct _UnixSubFolderIterator {
|
|
|
|
const IEnumIDListVtbl *lpIEnumIDListVtbl;
|
2005-07-03 14:03:35 +02:00
|
|
|
LONG m_cRef;
|
2005-04-25 12:56:29 +02:00
|
|
|
SHCONTF m_fFilter;
|
2005-07-12 19:00:36 +02:00
|
|
|
DIR *m_dirFolder;
|
|
|
|
char m_szFolder[FILENAME_MAX];
|
2005-03-09 17:41:17 +01:00
|
|
|
} UnixSubFolderIterator;
|
|
|
|
|
|
|
|
static void UnixSubFolderIterator_Destroy(UnixSubFolderIterator *iterator) {
|
|
|
|
TRACE("(iterator=%p)\n", iterator);
|
2005-07-12 19:00:36 +02:00
|
|
|
|
|
|
|
if (iterator->m_dirFolder)
|
|
|
|
closedir(iterator->m_dirFolder);
|
2005-03-09 17:41:17 +01:00
|
|
|
SHFree(iterator);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_QueryInterface(IEnumIDList* iface,
|
|
|
|
REFIID riid, void** ppv)
|
|
|
|
{
|
|
|
|
TRACE("(iface=%p, riid=%p, ppv=%p)\n", iface, riid, ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumIDList, riid)) {
|
|
|
|
*ppv = iface;
|
|
|
|
} else {
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumIDList_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_AddRef(IEnumIDList* iface)
|
|
|
|
{
|
|
|
|
UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
|
|
|
|
|
|
|
|
TRACE("(iface=%p)\n", iface);
|
|
|
|
|
|
|
|
return InterlockedIncrement(&This->m_cRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI UnixSubFolderIterator_IEnumIDList_Release(IEnumIDList* iface)
|
|
|
|
{
|
|
|
|
UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
|
|
|
|
ULONG cRef;
|
|
|
|
|
|
|
|
TRACE("(iface=%p)\n", iface);
|
|
|
|
|
|
|
|
cRef = InterlockedDecrement(&This->m_cRef);
|
|
|
|
|
|
|
|
if (!cRef)
|
|
|
|
UnixSubFolderIterator_Destroy(This);
|
|
|
|
|
|
|
|
return cRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Next(IEnumIDList* iface, ULONG celt,
|
|
|
|
LPITEMIDLIST* rgelt, ULONG* pceltFetched)
|
|
|
|
{
|
|
|
|
UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
|
2005-07-12 19:00:36 +02:00
|
|
|
ULONG i = 0;
|
|
|
|
|
|
|
|
/* This->m_dirFolder will be NULL if the user doesn't have access rights for the dir. */
|
|
|
|
if (This->m_dirFolder) {
|
|
|
|
char *pszRelativePath = This->m_szFolder + lstrlenA(This->m_szFolder);
|
|
|
|
struct dirent *pDirEntry;
|
|
|
|
|
|
|
|
while (i < celt) {
|
|
|
|
pDirEntry = readdir(This->m_dirFolder);
|
|
|
|
if (!pDirEntry) break; /* No more entries */
|
|
|
|
if (!strcmp(pDirEntry->d_name, ".") || !strcmp(pDirEntry->d_name, "..")) continue;
|
|
|
|
|
|
|
|
/* Temporarily build absolute path in This->m_szFolder. Then construct a pidl
|
|
|
|
* and see if it passes the filter.
|
|
|
|
*/
|
|
|
|
lstrcpyA(pszRelativePath, pDirEntry->d_name);
|
2009-02-18 22:46:39 +01:00
|
|
|
rgelt[i] = SHAlloc(
|
2006-01-03 13:23:59 +01:00
|
|
|
UNIXFS_shitemid_len_from_filename(pszRelativePath, NULL, NULL)+sizeof(USHORT));
|
2011-01-13 15:31:52 +01:00
|
|
|
if (!UNIXFS_build_shitemid(This->m_szFolder, TRUE, NULL, rgelt[i]) ||
|
2005-07-12 19:00:36 +02:00
|
|
|
!UNIXFS_is_pidl_of_type(rgelt[i], This->m_fFilter))
|
|
|
|
{
|
|
|
|
SHFree(rgelt[i]);
|
2011-10-19 21:11:32 +02:00
|
|
|
rgelt[i] = NULL;
|
2005-07-12 19:00:36 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memset(((PBYTE)rgelt[i])+rgelt[i]->mkid.cb, 0, sizeof(USHORT));
|
2005-04-25 12:56:29 +02:00
|
|
|
i++;
|
|
|
|
}
|
2005-07-12 19:00:36 +02:00
|
|
|
*pszRelativePath = '\0'; /* Restore the original path in This->m_szFolder. */
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
2005-07-12 19:00:36 +02:00
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
if (pceltFetched)
|
|
|
|
*pceltFetched = i;
|
|
|
|
|
2005-07-08 13:30:18 +02:00
|
|
|
return (i == 0) ? S_FALSE : S_OK;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
2005-07-12 19:00:36 +02:00
|
|
|
|
2005-03-09 17:41:17 +01:00
|
|
|
static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Skip(IEnumIDList* iface, ULONG celt)
|
|
|
|
{
|
2005-07-12 19:00:36 +02:00
|
|
|
LPITEMIDLIST *apidl;
|
|
|
|
ULONG cFetched;
|
|
|
|
HRESULT hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2006-10-07 20:18:14 +02:00
|
|
|
TRACE("(iface=%p, celt=%d)\n", iface, celt);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
2005-07-12 19:00:36 +02:00
|
|
|
/* Call IEnumIDList::Next and delete the resulting pidls. */
|
2008-11-05 23:00:50 +01:00
|
|
|
apidl = SHAlloc(celt * sizeof(LPITEMIDLIST));
|
2005-07-12 19:00:36 +02:00
|
|
|
hr = IEnumIDList_Next(iface, celt, apidl, &cFetched);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
while (cFetched--)
|
|
|
|
SHFree(apidl[cFetched]);
|
|
|
|
SHFree(apidl);
|
|
|
|
|
|
|
|
return hr;
|
2005-03-09 17:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Reset(IEnumIDList* iface)
|
|
|
|
{
|
|
|
|
UnixSubFolderIterator *This = ADJUST_THIS(UnixSubFolderIterator, IEnumIDList, iface);
|
|
|
|
|
|
|
|
TRACE("(iface=%p)\n", iface);
|
|
|
|
|
2005-07-12 19:00:36 +02:00
|
|
|
if (This->m_dirFolder)
|
|
|
|
rewinddir(This->m_dirFolder);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI UnixSubFolderIterator_IEnumIDList_Clone(IEnumIDList* This,
|
|
|
|
IEnumIDList** ppenum)
|
|
|
|
{
|
2005-08-30 11:58:21 +02:00
|
|
|
FIXME("stub\n");
|
2005-03-09 17:41:17 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VTable for UnixSubFolderIterator's IEnumIDList interface.
|
|
|
|
*/
|
|
|
|
static const IEnumIDListVtbl UnixSubFolderIterator_IEnumIDList_Vtbl = {
|
|
|
|
UnixSubFolderIterator_IEnumIDList_QueryInterface,
|
|
|
|
UnixSubFolderIterator_IEnumIDList_AddRef,
|
|
|
|
UnixSubFolderIterator_IEnumIDList_Release,
|
|
|
|
UnixSubFolderIterator_IEnumIDList_Next,
|
|
|
|
UnixSubFolderIterator_IEnumIDList_Skip,
|
|
|
|
UnixSubFolderIterator_IEnumIDList_Reset,
|
|
|
|
UnixSubFolderIterator_IEnumIDList_Clone
|
|
|
|
};
|
|
|
|
|
2005-07-12 19:00:36 +02:00
|
|
|
static IUnknown *UnixSubFolderIterator_Constructor(UnixFolder *pUnixFolder, SHCONTF fFilter) {
|
2005-03-09 17:41:17 +01:00
|
|
|
UnixSubFolderIterator *iterator;
|
|
|
|
|
|
|
|
TRACE("(pUnixFolder=%p)\n", pUnixFolder);
|
|
|
|
|
|
|
|
iterator = SHAlloc((ULONG)sizeof(UnixSubFolderIterator));
|
|
|
|
iterator->lpIEnumIDListVtbl = &UnixSubFolderIterator_IEnumIDList_Vtbl;
|
|
|
|
iterator->m_cRef = 0;
|
2005-04-25 12:56:29 +02:00
|
|
|
iterator->m_fFilter = fFilter;
|
2005-07-12 19:00:36 +02:00
|
|
|
iterator->m_dirFolder = opendir(pUnixFolder->m_pszPath);
|
|
|
|
lstrcpyA(iterator->m_szFolder, pUnixFolder->m_pszPath);
|
2005-03-09 17:41:17 +01:00
|
|
|
|
|
|
|
UnixSubFolderIterator_IEnumIDList_AddRef((IEnumIDList*)iterator);
|
|
|
|
|
|
|
|
return (IUnknown*)iterator;
|
|
|
|
}
|
2008-12-09 17:10:10 +01:00
|
|
|
|
|
|
|
#else /* __MINGW32__ || _MSC_VER */
|
|
|
|
|
|
|
|
HRESULT WINAPI UnixFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI UnixDosFolder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI FolderShortcut_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MyDocuments_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __MINGW32__ || _MSC_VER */
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* UNIXFS_is_rooted_at_desktop [Internal]
|
|
|
|
*
|
|
|
|
* Checks if the unixfs namespace extension is rooted at desktop level.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE, if unixfs is rooted at desktop level
|
|
|
|
* FALSE, if not.
|
|
|
|
*/
|
|
|
|
BOOL UNIXFS_is_rooted_at_desktop(void) {
|
|
|
|
HKEY hKey;
|
|
|
|
WCHAR wszRootedAtDesktop[69 + CHARS_IN_GUID] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
|
|
|
|
'N','a','m','e','S','p','a','c','e','\\',0 };
|
|
|
|
|
|
|
|
if (StringFromGUID2(&CLSID_UnixDosFolder, wszRootedAtDesktop + 69, CHARS_IN_GUID) &&
|
|
|
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRootedAtDesktop, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|