5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
27 HKEY
OpenKeyFromFileType(PCUIDLIST_RELATIVE pidl
, LPCWSTR KeyName
)
31 if (!_ILIsValue(pidl
))
33 ERR("Invalid pidl!\n");
37 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
40 ERR("Invalid pidl!\n");
44 LPWSTR pExtension
= PathFindExtensionW(pDataW
->wszName
);
45 if (!pExtension
|| *pExtension
== NULL
)
47 WARN("No extension for %S!\n", pDataW
->wszName
);
51 WCHAR FullName
[MAX_PATH
];
52 DWORD dwSize
= sizeof(FullName
);
53 wsprintf(FullName
, L
"%s\\%s", pExtension
, KeyName
);
55 LONG res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, FullName
, 0, KEY_READ
, &hkey
);
59 res
= RegGetValueW(HKEY_CLASSES_ROOT
, pExtension
, NULL
, RRF_RT_REG_SZ
, NULL
, FullName
, &dwSize
);
62 WARN("Failed to get progid for file %S, extension %S (%x), address %x, pidl: %x, error %d\n", pDataW
->wszName
, pExtension
, pExtension
, &dwSize
, pidl
, res
);
66 wcscat(FullName
, L
"\\");
67 wcscat(FullName
, KeyName
);
70 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, FullName
, 0, KEY_READ
, &hkey
);
72 WARN("Could not open key %S for extension %S\n", KeyName
, pExtension
);
77 HRESULT
GetCLSIDForFileType(PCUIDLIST_RELATIVE pidl
, LPCWSTR KeyName
, CLSID
* pclsid
)
79 HKEY hkeyProgId
= OpenKeyFromFileType(pidl
, KeyName
);
82 WARN("OpenKeyFromFileType failed for key %S\n", KeyName
);
86 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
87 DWORD dwSize
= sizeof(wszCLSIDValue
);
88 LONG res
= RegGetValueW(hkeyProgId
, NULL
, NULL
, RRF_RT_REG_SZ
, NULL
, wszCLSIDValue
, &dwSize
);
89 RegCloseKey(hkeyProgId
);
92 ERR("OpenKeyFromFileType succeeded but RegGetValueW failed\n");
98 res
= RegGetValueW(HKEY_LOCAL_MACHINE
,
99 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved",
105 if (res
!= ERROR_SUCCESS
)
107 ERR("DropHandler extension %S not approved\n", wszName
);
108 return E_ACCESSDENIED
;
113 if (RegGetValueW(HKEY_LOCAL_MACHINE
,
114 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Blocked",
119 NULL
) == ERROR_SUCCESS
)
121 ERR("Extension %S not approved\n", wszCLSIDValue
);
122 return E_ACCESSDENIED
;
125 HRESULT hres
= CLSIDFromString (wszCLSIDValue
, pclsid
);
126 if (FAILED_UNEXPECTEDLY(hres
))
133 getDefaultIconLocation(LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT uFlags
)
135 static const WCHAR folder
[] = { 'F', 'o', 'l', 'd', 'e', 'r', 0 };
137 if (!HCR_GetIconW(folder
, szIconFile
, NULL
, cchMax
, piIndex
))
139 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
140 *piIndex
= -IDI_SHELL_FOLDER
;
143 if (uFlags
& GIL_OPENICON
)
155 static const WCHAR s_shellClassInfo
[] = { '.', 'S', 'h', 'e', 'l', 'l', 'C', 'l', 'a', 's', 's', 'I', 'n', 'f', 'o', 0 };
158 getShellClassInfo(LPCWSTR Entry
, LPWSTR pszValue
, DWORD cchValueLen
, LPCWSTR IniFile
)
160 return GetPrivateProfileStringW(s_shellClassInfo
, Entry
, NULL
, pszValue
, cchValueLen
, IniFile
);
164 getIconLocationForFolder(IShellFolder
* psf
, PCITEMID_CHILD pidl
, UINT uFlags
,
165 LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
168 WCHAR wszPath
[MAX_PATH
];
169 WCHAR wszIniFullPath
[MAX_PATH
];
170 static const WCHAR iconFile
[] = { 'I', 'c', 'o', 'n', 'F', 'i', 'l', 'e', 0 };
171 static const WCHAR clsid
[] = { 'C', 'L', 'S', 'I', 'D', 0 };
172 static const WCHAR clsid2
[] = { 'C', 'L', 'S', 'I', 'D', '2', 0 };
173 static const WCHAR iconIndex
[] = { 'I', 'c', 'o', 'n', 'I', 'n', 'd', 'e', 'x', 0 };
174 static const WCHAR iconResource
[] = { 'I', 'c', 'o', 'n', 'R', 'e', 's', 'o', 'u', 'r', 'c', 'e', 0 };
175 static const WCHAR wszDesktopIni
[] = { 'd','e','s','k','t','o','p','.','i','n','i',0 };
177 if (uFlags
& GIL_DEFAULTICON
)
181 if (!ILGetDisplayNameExW(psf
, pidl
, wszPath
, 0))
183 if (!PathIsDirectoryW(wszPath
))
186 // read-only or system folder?
187 dwFileAttrs
= _ILGetFileAttributes(ILFindLastID(pidl
), NULL
, 0);
188 if ((dwFileAttrs
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)) == 0)
191 // build the full path of ini file
192 StringCchCopyW(wszIniFullPath
, _countof(wszIniFullPath
), wszPath
);
193 PathAppendW(wszIniFullPath
, wszDesktopIni
);
195 WCHAR wszValue
[MAX_PATH
], wszTemp
[MAX_PATH
];
196 if (getShellClassInfo(iconFile
, wszValue
, _countof(wszValue
), wszIniFullPath
))
198 // wszValue --> wszTemp
199 ExpandEnvironmentStringsW(wszValue
, wszTemp
, _countof(wszTemp
));
201 // wszPath + wszTemp --> wszPath
202 if (PathIsRelativeW(wszTemp
))
203 PathAppendW(wszPath
, wszTemp
);
205 StringCchCopyW(wszPath
, _countof(wszPath
), wszTemp
);
207 // wszPath --> szIconFile
208 GetFullPathNameW(wszPath
, cchMax
, szIconFile
, NULL
);
210 *piIndex
= GetPrivateProfileIntW(s_shellClassInfo
, iconIndex
, 0, wszIniFullPath
);
213 else if (getShellClassInfo(clsid
, wszValue
, _countof(wszValue
), wszIniFullPath
) &&
214 HCR_GetIconW(wszValue
, szIconFile
, NULL
, cchMax
, piIndex
))
218 else if (getShellClassInfo(clsid2
, wszValue
, _countof(wszValue
), wszIniFullPath
) &&
219 HCR_GetIconW(wszValue
, szIconFile
, NULL
, cchMax
, piIndex
))
223 else if (getShellClassInfo(iconResource
, wszValue
, _countof(wszValue
), wszIniFullPath
))
225 // wszValue --> wszTemp
226 ExpandEnvironmentStringsW(wszValue
, wszTemp
, _countof(wszTemp
));
228 // parse the icon location
229 *piIndex
= PathParseIconLocationW(wszTemp
);
231 // wszPath + wszTemp --> wszPath
232 if (PathIsRelativeW(wszTemp
))
233 PathAppendW(wszPath
, wszTemp
);
235 StringCchCopyW(wszPath
, _countof(wszPath
), wszTemp
);
237 // wszPath --> szIconFile
238 GetFullPathNameW(wszPath
, cchMax
, szIconFile
, NULL
);
243 return getDefaultIconLocation(szIconFile
, cchMax
, piIndex
, uFlags
);
246 HRESULT
CFSExtractIcon_CreateInstance(IShellFolder
* psf
, LPCITEMIDLIST pidl
, REFIID iid
, LPVOID
* ppvOut
)
248 CComPtr
<IDefaultExtractIconInit
> initIcon
;
251 UINT flags
= 0; // FIXME: Use it!
252 WCHAR wTemp
[MAX_PATH
] = L
"";
254 hr
= SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit
,&initIcon
));
258 if (_ILIsFolder (pidl
))
260 if (SUCCEEDED(getIconLocationForFolder(psf
,
261 pidl
, 0, wTemp
, _countof(wTemp
),
265 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
266 // FIXME: if/when getIconLocationForFolder does something for
267 // GIL_FORSHORTCUT, code below should be uncommented. and
268 // the following line removed.
269 initIcon
->SetShortcutIcon(wTemp
, icon_idx
);
271 if (SUCCEEDED(getIconLocationForFolder(psf
,
272 pidl
, GIL_DEFAULTICON
, wTemp
, _countof(wTemp
),
276 initIcon
->SetDefaultIcon(wTemp
, icon_idx
);
278 // if (SUCCEEDED(getIconLocationForFolder(psf,
279 // pidl, GIL_FORSHORTCUT, wTemp, _countof(wTemp),
283 // initIcon->SetShortcutIcon(wTemp, icon_idx);
285 if (SUCCEEDED(getIconLocationForFolder(psf
,
286 pidl
, GIL_OPENICON
, wTemp
, _countof(wTemp
),
290 initIcon
->SetOpenIcon(wTemp
, icon_idx
);
295 HKEY hkey
= OpenKeyFromFileType(pidl
, L
"DefaultIcon");
297 WARN("Could not open DefaultIcon key!\n");
299 DWORD dwSize
= sizeof(wTemp
);
300 if (hkey
&& !SHQueryValueExW(hkey
, NULL
, NULL
, NULL
, wTemp
, &dwSize
))
303 if (ParseFieldW (wTemp
, 2, sNum
, 5))
304 icon_idx
= _wtoi(sNum
);
306 icon_idx
= 0; /* sometimes the icon number is missing */
307 ParseFieldW (wTemp
, 1, wTemp
, MAX_PATH
);
308 PathUnquoteSpacesW(wTemp
);
310 if (!wcscmp(L
"%1", wTemp
)) /* icon is in the file */
312 ILGetDisplayNameExW(psf
, pidl
, wTemp
, 0);
316 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
320 initIcon
->SetNormalIcon(swShell32Name
, 0);
327 return initIcon
->QueryInterface(iid
, ppvOut
);
331 CFileSysEnum should do an initial FindFirstFile and do a FindNextFile as each file is
332 returned by Next. When the enumerator is created, it can do numerous additional operations
333 including formatting a drive, reconnecting a network share drive, and requesting a disk
334 be inserted in a removable drive.
337 /***********************************************************************
338 * IShellFolder implementation
342 public CEnumIDListBase
348 HRESULT WINAPI
Initialize(LPWSTR sPathTarget
, DWORD dwFlags
);
350 BEGIN_COM_MAP(CFileSysEnum
)
351 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList
, IEnumIDList
)
355 CFileSysEnum::CFileSysEnum()
359 CFileSysEnum::~CFileSysEnum()
363 HRESULT WINAPI
CFileSysEnum::Initialize(LPWSTR lpszPath
, DWORD dwFlags
)
365 WIN32_FIND_DATAW stffile
;
367 WCHAR szPath
[MAX_PATH
];
368 BOOL succeeded
= TRUE
;
369 static const WCHAR stars
[] = { '*','.','*',0 };
370 static const WCHAR dot
[] = { '.',0 };
371 static const WCHAR dotdot
[] = { '.','.',0 };
373 TRACE("(%p)->(path=%s flags=0x%08x)\n", this, debugstr_w(lpszPath
), dwFlags
);
375 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
377 wcscpy(szPath
, lpszPath
);
378 PathAddBackslashW(szPath
);
379 wcscat(szPath
,stars
);
381 hFile
= FindFirstFileW(szPath
,&stffile
);
382 if ( hFile
!= INVALID_HANDLE_VALUE
)
384 BOOL findFinished
= FALSE
;
388 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
389 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
391 LPITEMIDLIST pidl
= NULL
;
393 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
394 dwFlags
& SHCONTF_FOLDERS
&&
395 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
397 pidl
= _ILCreateFromFindDataW(&stffile
);
398 succeeded
= succeeded
&& AddToEnumList(pidl
);
400 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
401 && dwFlags
& SHCONTF_NONFOLDERS
)
403 pidl
= _ILCreateFromFindDataW(&stffile
);
404 succeeded
= succeeded
&& AddToEnumList(pidl
);
409 if (!FindNextFileW(hFile
, &stffile
))
411 if (GetLastError() == ERROR_NO_MORE_FILES
)
417 } while (succeeded
&& !findFinished
);
424 CFSFolder::CFSFolder()
426 pclsid
= (CLSID
*)&CLSID_ShellFSFolder
;
429 m_bGroupPolicyActive
= 0;
432 CFSFolder::~CFSFolder()
434 TRACE("-- destroying IShellFolder(%p)\n", this);
441 static const shvheader GenericSFHeader
[] = {
442 {IDS_SHV_COLUMN_NAME
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 15},
443 {IDS_SHV_COLUMN_COMMENTS
, SHCOLSTATE_TYPE_STR
, LVCFMT_LEFT
, 0},
444 {IDS_SHV_COLUMN_TYPE
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 10},
445 {IDS_SHV_COLUMN_SIZE
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
446 {IDS_SHV_COLUMN_MODIFIED
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 12},
447 {IDS_SHV_COLUMN_ATTRIBUTES
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 10}
450 #define GENERICSHELLVIEWCOLUMNS 6
452 /**************************************************************************
453 * SHELL32_CreatePidlFromBindCtx [internal]
455 * If the caller bound File System Bind Data, assume it is the
456 * find data for the path.
457 * This allows binding of paths that don't exist.
459 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
461 IFileSystemBindData
*fsbd
= NULL
;
462 LPITEMIDLIST pidl
= NULL
;
463 IUnknown
*param
= NULL
;
464 WIN32_FIND_DATAW wfd
;
467 TRACE("%p %s\n", pbc
, debugstr_w(path
));
472 /* see if the caller bound File System Bind Data */
473 r
= pbc
->GetObjectParam((LPOLESTR
)STR_FILE_SYS_BIND_DATA
, ¶m
);
477 r
= param
->QueryInterface(IID_PPV_ARG(IFileSystemBindData
,&fsbd
));
480 r
= fsbd
->GetFindData(&wfd
);
483 lstrcpynW(&wfd
.cFileName
[0], path
, MAX_PATH
);
484 pidl
= _ILCreateFromFindDataW(&wfd
);
492 void SHELL32_GetCLSIDForDirectory(LPCWSTR pwszDir
, CLSID
* pclsidFolder
)
494 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
495 WCHAR wszDesktopIni
[MAX_PATH
];
496 StringCchCopyW(wszDesktopIni
, MAX_PATH
, pwszDir
);
497 StringCchCatW(wszDesktopIni
, MAX_PATH
, L
"\\desktop.ini");
499 if (GetPrivateProfileStringW(L
".ShellClassInfo",
506 CLSIDFromString (wszCLSIDValue
, pclsidFolder
);
510 HRESULT
SHELL32_GetFSItemAttributes(IShellFolder
* psf
, LPCITEMIDLIST pidl
, LPDWORD pdwAttributes
)
512 DWORD dwFileAttributes
, dwShellAttributes
;
514 if (!_ILIsFolder(pidl
) && !_ILIsValue(pidl
))
516 ERR("Got wrong type of pidl!\n");
517 *pdwAttributes
&= SFGAO_CANLINK
;
521 dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
523 /* Set common attributes */
524 dwShellAttributes
= SFGAO_CANCOPY
| SFGAO_CANMOVE
| SFGAO_CANLINK
| SFGAO_CANRENAME
| SFGAO_CANDELETE
|
525 SFGAO_HASPROPSHEET
| SFGAO_DROPTARGET
| SFGAO_FILESYSTEM
;
527 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
528 dwShellAttributes
|= (SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
| SFGAO_FILESYSANCESTOR
| SFGAO_STORAGEANCESTOR
| SFGAO_STORAGE
);
530 dwShellAttributes
|= SFGAO_STREAM
;
532 if (dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
533 dwShellAttributes
|= SFGAO_HIDDEN
;
535 if (dwFileAttributes
& FILE_ATTRIBUTE_READONLY
)
536 dwShellAttributes
|= SFGAO_READONLY
;
538 if (SFGAO_LINK
& *pdwAttributes
)
542 if (_ILGetExtension(pidl
, ext
, MAX_PATH
) && !lstrcmpiA(ext
, "lnk"))
543 dwShellAttributes
|= SFGAO_LINK
;
546 if (SFGAO_HASSUBFOLDER
& *pdwAttributes
)
548 CComPtr
<IShellFolder
> psf2
;
549 if (SUCCEEDED(psf
->BindToObject(pidl
, 0, IID_PPV_ARG(IShellFolder
, &psf2
))))
551 CComPtr
<IEnumIDList
> pEnumIL
;
552 if (SUCCEEDED(psf2
->EnumObjects(0, SHCONTF_FOLDERS
, &pEnumIL
)))
554 if (pEnumIL
->Skip(1) == S_OK
)
555 dwShellAttributes
|= SFGAO_HASSUBFOLDER
;
560 *pdwAttributes
= dwShellAttributes
;
562 TRACE ("-- 0x%08x\n", *pdwAttributes
);
566 /**************************************************************************
567 * CFSFolder::ParseDisplayName {SHELL32}
569 * Parse a display name.
572 * hwndOwner [in] Parent window for any message's
573 * pbc [in] optional FileSystemBindData context
574 * lpszDisplayName [in] Unicode displayname.
575 * pchEaten [out] (unicode) characters processed
576 * ppidl [out] complex pidl to item
577 * pdwAttributes [out] items attributes
580 * Every folder tries to parse only its own (the leftmost) pidl and creates a
581 * subfolder to evaluate the remaining parts.
582 * Now we can parse into namespaces implemented by shell extensions
584 * Behaviour on win98: lpszDisplayName=NULL -> crash
585 * lpszDisplayName="" -> returns mycoputer-pidl
588 * pdwAttributes is not set
589 * pchEaten is not set like in windows
591 HRESULT WINAPI
CFSFolder::ParseDisplayName(HWND hwndOwner
,
593 LPOLESTR lpszDisplayName
,
594 DWORD
*pchEaten
, PIDLIST_RELATIVE
*ppidl
,
595 DWORD
*pdwAttributes
)
597 HRESULT hr
= E_INVALIDARG
;
598 LPCWSTR szNext
= NULL
;
599 WCHAR szElement
[MAX_PATH
];
600 WCHAR szPath
[MAX_PATH
];
601 LPITEMIDLIST pidlTemp
= NULL
;
604 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
605 this, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
606 pchEaten
, ppidl
, pdwAttributes
);
611 if (!lpszDisplayName
)
620 *pchEaten
= 0; /* strange but like the original */
622 if (*lpszDisplayName
)
624 /* get the next element */
625 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
627 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, szElement
);
628 if (pidlTemp
!= NULL
)
630 /* We are creating an id list without ensuring that the items exist.
631 If we have a remaining path, this must be a folder.
632 We have to do it now because it is set as a file by default */
635 pidlTemp
->mkid
.abID
[0] = PT_FOLDER
;
641 /* build the full pathname to the element */
642 lstrcpynW(szPath
, sPathTarget
, MAX_PATH
- 1);
643 PathAddBackslashW(szPath
);
644 len
= wcslen(szPath
);
645 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
648 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
653 if (szNext
&& *szNext
)
655 /* try to analyse the next element */
656 hr
= SHELL32_ParseNextElement(this, hwndOwner
, pbc
,
657 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
661 /* it's the last element */
662 if (pdwAttributes
&& *pdwAttributes
)
663 hr
= SHELL32_GetFSItemAttributes(this, pidlTemp
, pdwAttributes
);
673 TRACE("(%p)->(-- pidl=%p ret=0x%08x)\n", this, ppidl
? *ppidl
: 0, hr
);
678 /**************************************************************************
679 * CFSFolder::EnumObjects
681 * HWND hwndOwner, //[in ] Parent Window
682 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
683 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
685 HRESULT WINAPI
CFSFolder::EnumObjects(
688 LPENUMIDLIST
*ppEnumIDList
)
690 return ShellObjectCreatorInit
<CFileSysEnum
>(sPathTarget
, dwFlags
, IID_PPV_ARG(IEnumIDList
, ppEnumIDList
));
693 /**************************************************************************
694 * CFSFolder::BindToObject
696 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
697 * LPBC pbc, //[in ] optional FileSystemBindData context
698 * REFIID riid, //[in ] Initial Interface
699 * LPVOID* ppvObject //[out] Interface*
701 HRESULT WINAPI
CFSFolder::BindToObject(
702 PCUIDLIST_RELATIVE pidl
,
707 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", this, pidl
, pbc
,
708 shdebugstr_guid(&riid
), ppvOut
);
710 CComPtr
<IShellFolder
> pSF
;
713 if (!pidlRoot
|| !ppvOut
|| !pidl
|| !pidl
->mkid
.cb
)
715 ERR("CFSFolder::BindToObject: Invalid parameters\n");
719 /* Get the pidl data */
720 FileStruct
* pData
= &_ILGetDataPointer(pidl
)->u
.file
;
721 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
725 ERR("CFSFolder::BindToObject: Invalid pidl!\n");
731 /* Create the target folder info */
732 PERSIST_FOLDER_TARGET_INFO pfti
= {0};
733 pfti
.dwAttributes
= -1;
735 PathCombineW(pfti
.szTargetParsingName
, sPathTarget
, pDataW
->wszName
);
737 /* Get the CLSID to bind to */
739 if (_ILIsFolder(pidl
))
741 clsidFolder
= CLSID_ShellFSFolder
;
743 if ((pData
->uFileAttribs
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)) != 0)
744 SHELL32_GetCLSIDForDirectory(pfti
.szTargetParsingName
, &clsidFolder
);
748 hr
= GetCLSIDForFileType(pidl
, L
"CLSID", &clsidFolder
);
750 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
755 hr
= SHELL32_BindToSF(pidlRoot
, &pfti
, pidl
, &clsidFolder
, riid
, ppvOut
);
756 if (FAILED_UNEXPECTEDLY(hr
))
759 TRACE ("-- returning (%p) %08x\n", *ppvOut
, hr
);
765 /**************************************************************************
766 * CFSFolder::BindToStorage
768 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
769 * LPBC pbc, //[in ] reserved
770 * REFIID riid, //[in ] Initial storage interface
771 * LPVOID* ppvObject //[out] Interface* returned
773 HRESULT WINAPI
CFSFolder::BindToStorage(
774 PCUIDLIST_RELATIVE pidl
,
779 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", this, pidl
, pbcReserved
,
780 shdebugstr_guid (&riid
), ppvOut
);
786 /**************************************************************************
787 * CFSFolder::CompareIDs
790 HRESULT WINAPI
CFSFolder::CompareIDs(LPARAM lParam
,
791 PCUIDLIST_RELATIVE pidl1
,
792 PCUIDLIST_RELATIVE pidl2
)
794 LPPIDLDATA pData1
= _ILGetDataPointer(pidl1
);
795 LPPIDLDATA pData2
= _ILGetDataPointer(pidl2
);
796 FileStructW
* pDataW1
= _ILGetFileStructW(pidl1
);
797 FileStructW
* pDataW2
= _ILGetFileStructW(pidl2
);
798 BOOL bIsFolder1
= _ILIsFolder(pidl1
);
799 BOOL bIsFolder2
= _ILIsFolder(pidl2
);
800 LPWSTR pExtension1
, pExtension2
;
802 if (!pDataW1
|| !pDataW2
|| LOWORD(lParam
) >= GENERICSHELLVIEWCOLUMNS
)
805 /* When sorting between a File and a Folder, the Folder gets sorted first */
806 if (bIsFolder1
!= bIsFolder2
)
808 return MAKE_COMPARE_HRESULT(bIsFolder1
? -1 : 1);
812 switch (LOWORD(lParam
))
815 result
= wcsicmp(pDataW1
->wszName
, pDataW2
->wszName
);
817 case 1: /* Comments */
821 pExtension1
= PathFindExtensionW(pDataW1
->wszName
);
822 pExtension2
= PathFindExtensionW(pDataW2
->wszName
);
823 result
= wcsicmp(pExtension1
, pExtension2
);
826 result
= pData1
->u
.file
.dwFileSize
- pData2
->u
.file
.dwFileSize
;
828 case 4: /* Modified */
829 result
= pData1
->u
.file
.uFileDate
- pData2
->u
.file
.uFileDate
;
831 result
= pData1
->u
.file
.uFileTime
- pData2
->u
.file
.uFileTime
;
833 case 5: /* Attributes */
834 return SHELL32_CompareDetails(this, lParam
, pidl1
, pidl2
);
838 return SHELL32_CompareChildren(this, lParam
, pidl1
, pidl2
);
840 return MAKE_COMPARE_HRESULT(result
);
843 /**************************************************************************
844 * CFSFolder::CreateViewObject
846 HRESULT WINAPI
CFSFolder::CreateViewObject(HWND hwndOwner
,
847 REFIID riid
, LPVOID
* ppvOut
)
849 CComPtr
<IShellView
> pShellView
;
850 HRESULT hr
= E_INVALIDARG
;
852 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", this, hwndOwner
, shdebugstr_guid (&riid
),
859 if (IsEqualIID (riid
, IID_IDropTarget
))
860 hr
= CFSDropTarget_CreateInstance(sPathTarget
, riid
, ppvOut
);
861 else if (IsEqualIID (riid
, IID_IContextMenu
))
865 AddClassKeyToArray(L
"Directory\\Background", hKeys
, &cKeys
);
868 dcm
.hwnd
= hwndOwner
;
870 dcm
.pidlFolder
= pidlRoot
;
876 dcm
.punkAssociationInfo
= NULL
;
877 hr
= SHCreateDefaultContextMenu (&dcm
, riid
, ppvOut
);
879 else if (IsEqualIID (riid
, IID_IShellView
))
881 SFV_CREATE sfvparams
= {sizeof(SFV_CREATE
), this};
882 hr
= SHCreateShellFolderView(&sfvparams
, (IShellView
**)ppvOut
);
885 TRACE("-- (%p)->(interface=%p)\n", this, ppvOut
);
889 /**************************************************************************
890 * CFSFolder::GetAttributesOf
893 * UINT cidl, //[in ] num elements in pidl array
894 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
895 * ULONG* rgfInOut) //[out] result array
898 HRESULT WINAPI
CFSFolder::GetAttributesOf(UINT cidl
,
899 PCUITEMID_CHILD_ARRAY apidl
, DWORD
* rgfInOut
)
913 LPCITEMIDLIST rpidl
= ILFindLastID(pidlRoot
);
915 if (_ILIsFolder(rpidl
) || _ILIsValue(rpidl
))
917 SHELL32_GetFSItemAttributes(this, rpidl
, rgfInOut
);
919 else if (_ILIsDrive(rpidl
))
921 IShellFolder
*psfParent
= NULL
;
922 hr
= SHBindToParent(pidlRoot
, IID_PPV_ARG(IShellFolder
, &psfParent
), NULL
);
925 hr
= psfParent
->GetAttributesOf(1, &rpidl
, (SFGAOF
*)rgfInOut
);
926 psfParent
->Release();
931 ERR("Got and unknown pidl!\n");
936 while (cidl
> 0 && *apidl
)
939 if(_ILIsFolder(*apidl
) || _ILIsValue(*apidl
))
940 SHELL32_GetFSItemAttributes(this, *apidl
, rgfInOut
);
942 ERR("Got an unknown type of pidl!!!\n");
947 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
948 *rgfInOut
&= ~SFGAO_VALIDATE
;
950 TRACE("-- result=0x%08x\n", *rgfInOut
);
955 /**************************************************************************
956 * CFSFolder::GetUIObjectOf
959 * HWND hwndOwner, //[in ] Parent window for any output
960 * UINT cidl, //[in ] array size
961 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
962 * REFIID riid, //[in ] Requested Interface
963 * UINT* prgfInOut, //[ ] reserved
964 * LPVOID* ppvObject) //[out] Resulting Interface
967 * This function gets asked to return "view objects" for one or more (multiple
969 * The viewobject typically is an COM object with one of the following
971 * IExtractIcon,IDataObject,IContextMenu
972 * In order to support icon positions in the default Listview your DataObject
973 * must implement the SetData method (in addition to GetData :) - the shell
974 * passes a barely documented "Icon positions" structure to SetData when the
975 * drag starts, and GetData's it if the drop is in another explorer window that
976 * needs the positions.
978 HRESULT WINAPI
CFSFolder::GetUIObjectOf(HWND hwndOwner
,
979 UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
,
980 REFIID riid
, UINT
* prgfInOut
,
984 HRESULT hr
= E_INVALIDARG
;
986 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
987 this, hwndOwner
, cidl
, apidl
, shdebugstr_guid (&riid
), prgfInOut
, ppvOut
);
993 if (cidl
== 1 && _ILIsValue(apidl
[0]))
995 hr
= _CreateExtensionUIObject(apidl
[0], riid
, ppvOut
);
1000 if (IsEqualIID(riid
, IID_IContextMenu
) && (cidl
>= 1))
1004 AddFSClassKeysToArray(apidl
[0], hKeys
, &cKeys
);
1007 dcm
.hwnd
= hwndOwner
;
1009 dcm
.pidlFolder
= pidlRoot
;
1015 dcm
.punkAssociationInfo
= NULL
;
1016 hr
= SHCreateDefaultContextMenu (&dcm
, riid
, &pObj
);
1018 else if (IsEqualIID (riid
, IID_IDataObject
))
1022 hr
= IDataObject_Constructor (hwndOwner
, pidlRoot
, apidl
, cidl
, (IDataObject
**)&pObj
);
1029 else if ((IsEqualIID (riid
, IID_IExtractIconA
) || IsEqualIID (riid
, IID_IExtractIconW
)) && (cidl
== 1))
1031 if (_ILIsValue(apidl
[0]))
1032 hr
= _GetIconHandler(apidl
[0], riid
, (LPVOID
*)&pObj
);
1034 hr
= CFSExtractIcon_CreateInstance(this, apidl
[0], riid
, &pObj
);
1036 else if (IsEqualIID (riid
, IID_IDropTarget
))
1038 /* only interested in attempting to bind to shell folders, not files (except exe), so if we fail, rebind to root */
1039 if (cidl
!= 1 || FAILED(hr
= this->_GetDropTarget(apidl
[0], (LPVOID
*) &pObj
)))
1041 hr
= CFSDropTarget_CreateInstance(sPathTarget
, riid
, (LPVOID
*) &pObj
);
1047 if (SUCCEEDED(hr
) && !pObj
)
1052 TRACE("(%p)->hr=0x%08x\n", this, hr
);
1056 static const WCHAR AdvancedW
[] = L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced";
1057 static const WCHAR HideFileExtW
[] = L
"HideFileExt";
1058 static const WCHAR NeverShowExtW
[] = L
"NeverShowExt";
1060 /******************************************************************************
1061 * SHELL_FS_HideExtension [Internal]
1063 * Query the registry if the filename extension of a given path should be
1067 * szPath [I] Relative or absolute path of a file
1070 * TRUE, if the filename's extension should be hidden
1073 BOOL
SHELL_FS_HideExtension(LPWSTR szPath
)
1077 DWORD dwDataSize
= sizeof (DWORD
);
1078 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
1080 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
1081 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
1087 LPWSTR ext
= PathFindExtensionW(szPath
);
1090 WCHAR classname
[MAX_PATH
];
1091 LONG classlen
= sizeof(classname
);
1093 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
1094 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
1095 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
1104 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
1106 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
1107 if (!(dwFlags
& SHGDN_FORPARSING
) &&
1108 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
1109 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
1110 PathRemoveExtensionW(szPath
);
1114 /**************************************************************************
1115 * CFSFolder::GetDisplayNameOf
1116 * Retrieves the display name for the specified file object or subfolder
1119 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
1120 * DWORD dwFlags, //[in ] SHGNO formatting flags
1121 * LPSTRRET lpName) //[out] Returned display name
1124 * if the name is in the pidl the ret value should be a STRRET_OFFSET
1127 HRESULT WINAPI
CFSFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl
,
1128 DWORD dwFlags
, LPSTRRET strRet
)
1131 return E_INVALIDARG
;
1133 /* If it is a complex pidl, let the child handle it */
1134 if (!_ILIsPidlSimple (pidl
)) /* complex pidl */
1136 return SHELL32_GetDisplayNameOfChild(this, pidl
, dwFlags
, strRet
);
1138 else if (pidl
&& !pidl
->mkid
.cb
) /* empty pidl */
1140 /* If it is an empty pidl return only the path of the folder */
1141 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
1142 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
1145 return SHSetStrRet(strRet
, sPathTarget
);
1147 return E_INVALIDARG
;
1151 LPWSTR pszPath
= (LPWSTR
)CoTaskMemAlloc((MAX_PATH
+ 1) * sizeof(WCHAR
));
1153 return E_OUTOFMEMORY
;
1155 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
1156 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
1159 lstrcpynW(pszPath
, sPathTarget
, MAX_PATH
);
1160 PathAddBackslashW(pszPath
);
1161 len
= wcslen(pszPath
);
1163 _ILSimpleGetTextW(pidl
, pszPath
+ len
, MAX_PATH
+ 1 - len
);
1164 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
1166 strRet
->uType
= STRRET_WSTR
;
1167 strRet
->pOleStr
= pszPath
;
1169 TRACE ("-- (%p)->(%s)\n", this, strRet
->uType
== STRRET_CSTR
? strRet
->cStr
: debugstr_w(strRet
->pOleStr
));
1173 /**************************************************************************
1174 * CFSFolder::SetNameOf
1175 * Changes the name of a file object or subfolder, possibly changing its item
1176 * identifier in the process.
1179 * HWND hwndOwner, //[in ] Owner window for output
1180 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
1181 * LPCOLESTR lpszName, //[in ] the items new display name
1182 * DWORD dwFlags, //[in ] SHGNO formatting flags
1183 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
1185 HRESULT WINAPI
CFSFolder::SetNameOf(
1187 PCUITEMID_CHILD pidl
,
1190 PITEMID_CHILD
*pPidlOut
)
1192 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
1193 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
1195 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", this, hwndOwner
, pidl
,
1196 debugstr_w (lpName
), dwFlags
, pPidlOut
);
1198 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
1201 ERR("Got garbage pidl\n");
1202 return E_INVALIDARG
;
1205 /* build source path */
1206 PathCombineW(szSrc
, sPathTarget
, pDataW
->wszName
);
1208 /* build destination path */
1209 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
)
1210 PathCombineW(szDest
, sPathTarget
, lpName
);
1212 lstrcpynW(szDest
, lpName
, MAX_PATH
);
1214 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
1215 WCHAR
*ext
= PathFindExtensionW(szSrc
);
1217 INT len
= wcslen(szDest
);
1218 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
1222 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
1223 if (!wcscmp(szSrc
, szDest
))
1225 /* src and destination is the same */
1228 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
1233 if (MoveFileW (szSrc
, szDest
))
1238 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
1240 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
1241 SHCNF_PATHW
, szSrc
, szDest
);
1249 HRESULT WINAPI
CFSFolder::GetDefaultSearchGUID(GUID
* pguid
)
1251 FIXME ("(%p)\n", this);
1255 HRESULT WINAPI
CFSFolder::EnumSearches(IEnumExtraSearch
** ppenum
)
1257 FIXME ("(%p)\n", this);
1261 HRESULT WINAPI
CFSFolder::GetDefaultColumn(DWORD dwRes
,
1262 ULONG
* pSort
, ULONG
* pDisplay
)
1264 TRACE ("(%p)\n", this);
1274 HRESULT WINAPI
CFSFolder::GetDefaultColumnState(UINT iColumn
,
1277 TRACE ("(%p)\n", this);
1279 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1280 return E_INVALIDARG
;
1282 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
1287 HRESULT WINAPI
CFSFolder::GetDetailsEx(PCUITEMID_CHILD pidl
,
1288 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
1290 FIXME ("(%p)\n", this);
1295 HRESULT WINAPI
CFSFolder::GetDetailsOf(PCUITEMID_CHILD pidl
,
1296 UINT iColumn
, SHELLDETAILS
* psd
)
1298 HRESULT hr
= E_FAIL
;
1300 TRACE ("(%p)->(%p %i %p)\n", this, pidl
, iColumn
, psd
);
1302 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1303 return E_INVALIDARG
;
1307 /* the header titles */
1308 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
1309 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
1310 return SHSetStrRet(&psd
->str
, GenericSFHeader
[iColumn
].colnameid
);
1315 psd
->str
.uType
= STRRET_CSTR
;
1316 /* the data from the pidl */
1320 hr
= GetDisplayNameOf (pidl
, SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
1322 case 1: /* FIXME: comments */
1323 psd
->str
.cStr
[0] = 0;
1326 _ILGetFileType(pidl
, psd
->str
.cStr
, MAX_PATH
);
1329 _ILGetFileSize(pidl
, psd
->str
.cStr
, MAX_PATH
);
1332 _ILGetFileDate(pidl
, psd
->str
.cStr
, MAX_PATH
);
1334 case 5: /* attributes */
1335 _ILGetFileAttributes(pidl
, psd
->str
.cStr
, MAX_PATH
);
1343 HRESULT WINAPI
CFSFolder::MapColumnToSCID (UINT column
,
1346 FIXME ("(%p)\n", this);
1350 /************************************************************************
1351 * CFSFolder::GetClassID
1353 HRESULT WINAPI
CFSFolder::GetClassID(CLSID
* lpClassId
)
1355 TRACE ("(%p)\n", this);
1360 *lpClassId
= *pclsid
;
1365 /************************************************************************
1366 * CFSFolder::Initialize
1369 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1371 HRESULT WINAPI
CFSFolder::Initialize(LPCITEMIDLIST pidl
)
1373 WCHAR wszTemp
[MAX_PATH
];
1375 TRACE ("(%p)->(%p)\n", this, pidl
);
1377 SHFree (pidlRoot
); /* free the old pidl */
1378 pidlRoot
= ILClone (pidl
); /* set my pidl */
1380 SHFree (sPathTarget
);
1384 if (SHGetPathFromIDListW (pidl
, wszTemp
))
1386 int len
= wcslen(wszTemp
);
1387 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1389 return E_OUTOFMEMORY
;
1390 memcpy(sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1393 TRACE ("--(%p)->(%s)\n", this, debugstr_w(sPathTarget
));
1397 /**************************************************************************
1398 * CFSFolder::GetCurFolder
1400 HRESULT WINAPI
CFSFolder::GetCurFolder(LPITEMIDLIST
* pidl
)
1402 TRACE ("(%p)->(%p)\n", this, pidl
);
1407 *pidl
= ILClone(pidlRoot
);
1411 /**************************************************************************
1412 * CFSFolder::InitializeEx
1414 * FIXME: error handling
1416 HRESULT WINAPI
CFSFolder::InitializeEx(IBindCtx
* pbc
, LPCITEMIDLIST pidlRootx
,
1417 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1419 WCHAR wszTemp
[MAX_PATH
];
1421 TRACE("(%p)->(%p,%p,%p)\n", this, pbc
, pidlRootx
, ppfti
);
1423 TRACE("--%p %s %s 0x%08x 0x%08x\n",
1424 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1425 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1429 if (ppfti
&& ppfti
->pidlTargetFolder
)
1430 pdump(ppfti
->pidlTargetFolder
);
1433 __SHFreeAndNil(&pidlRoot
); /* free the old */
1435 __SHFreeAndNil(&sPathTarget
);
1438 * Root path and pidl
1440 pidlRoot
= ILClone(pidlRootx
);
1443 * the target folder is spezified in csidl OR pidlTargetFolder OR
1444 * szTargetParsingName
1448 if (ppfti
->csidl
!= -1)
1450 if (SHGetSpecialFolderPathW(0, wszTemp
, ppfti
->csidl
,
1451 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1452 int len
= wcslen(wszTemp
);
1453 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1455 return E_OUTOFMEMORY
;
1456 memcpy(sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1459 else if (ppfti
->szTargetParsingName
[0])
1461 int len
= wcslen(ppfti
->szTargetParsingName
);
1462 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1464 return E_OUTOFMEMORY
;
1465 memcpy(sPathTarget
, ppfti
->szTargetParsingName
,
1466 (len
+ 1) * sizeof(WCHAR
));
1468 else if (ppfti
->pidlTargetFolder
)
1470 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
))
1472 int len
= wcslen(wszTemp
);
1473 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1475 return E_OUTOFMEMORY
;
1476 memcpy(sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1481 TRACE("--(%p)->(target=%s)\n", this, debugstr_w(sPathTarget
));
1483 return (sPathTarget
) ? S_OK
: E_FAIL
;
1486 HRESULT WINAPI
CFSFolder::GetFolderTargetInfo(PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1488 FIXME("(%p)->(%p)\n", this, ppfti
);
1489 ZeroMemory(ppfti
, sizeof (*ppfti
));
1493 HRESULT
CFSFolder::_CreateExtensionUIObject(PCUIDLIST_RELATIVE pidl
, REFIID riid
, LPVOID
*ppvOut
)
1495 static const WCHAR formatW
[] = {'S','h','e','l','l','E','x','\\',
1496 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
1497 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
1498 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
1499 WCHAR buf
[MAX_PATH
];
1501 sprintfW(buf
, formatW
, riid
.Data1
, riid
.Data2
, riid
.Data3
,
1502 riid
.Data4
[0], riid
.Data4
[1], riid
.Data4
[2], riid
.Data4
[3],
1503 riid
.Data4
[4], riid
.Data4
[5], riid
.Data4
[6], riid
.Data4
[7]);
1508 hr
= GetCLSIDForFileType(pidl
, buf
, &clsid
);
1512 hr
= _CreateShellExtInstance(&clsid
, pidl
, riid
, ppvOut
);
1513 if (FAILED_UNEXPECTEDLY(hr
))
1519 HRESULT
CFSFolder::_GetDropTarget(LPCITEMIDLIST pidl
, LPVOID
*ppvOut
)
1523 TRACE("CFSFolder::_GetDropTarget entered\n");
1525 if (_ILIsFolder (pidl
))
1527 CComPtr
<IShellFolder
> psfChild
;
1528 hr
= this->BindToObject(pidl
, NULL
, IID_PPV_ARG(IShellFolder
, &psfChild
));
1529 if (FAILED_UNEXPECTEDLY(hr
))
1532 return psfChild
->CreateViewObject(NULL
, IID_IDropTarget
, ppvOut
);
1536 hr
= GetCLSIDForFileType(pidl
, L
"shellex\\DropHandler", &clsid
);
1540 hr
= _CreateShellExtInstance(&clsid
, pidl
, IID_IDropTarget
, ppvOut
);
1541 if (FAILED_UNEXPECTEDLY(hr
))
1547 HRESULT
CFSFolder::_GetIconHandler(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
1552 hr
= GetCLSIDForFileType(pidl
, L
"shellex\\IconHandler", &clsid
);
1556 hr
= _CreateShellExtInstance(&clsid
, pidl
, riid
, ppvOut
);
1557 if (FAILED_UNEXPECTEDLY(hr
))
1563 HRESULT
CFSFolder::_CreateShellExtInstance(const CLSID
*pclsid
, LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
1566 WCHAR wszPath
[MAX_PATH
];
1568 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
1571 ERR("Got garbage pidl\n");
1572 return E_INVALIDARG
;
1575 PathCombineW(wszPath
, sPathTarget
, pDataW
->wszName
);
1577 CComPtr
<IPersistFile
> pp
;
1578 hr
= SHCoCreateInstance(NULL
, pclsid
, NULL
, IID_PPV_ARG(IPersistFile
, &pp
));
1579 if (FAILED_UNEXPECTEDLY(hr
))
1582 pp
->Load(wszPath
, 0);
1584 hr
= pp
->QueryInterface(riid
, ppvOut
);
1587 ERR("Failed to query for interface IID_IShellExtInit hr %x pclsid %s\n", hr
, wine_dbgstr_guid(pclsid
));
1593 HRESULT WINAPI
CFSFolder::CallBack(IShellFolder
*psf
, HWND hwndOwner
, IDataObject
*pdtobj
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1595 if (uMsg
!= DFM_MERGECONTEXTMENU
&& uMsg
!= DFM_INVOKECOMMAND
)
1598 /* no data object means no selection */
1601 if (uMsg
== DFM_INVOKECOMMAND
&& wParam
== 0)
1603 PUITEMID_CHILD pidlChild
= ILClone(ILFindLastID(pidlRoot
));
1604 LPITEMIDLIST pidlParent
= ILClone(pidlRoot
);
1605 ILRemoveLastID(pidlParent
);
1606 HRESULT hr
= SH_ShowPropertiesDialog(sPathTarget
, pidlParent
, &pidlChild
);
1608 ERR("SH_ShowPropertiesDialog failed\n");
1612 else if (uMsg
== DFM_MERGECONTEXTMENU
)
1614 QCMINFO
*pqcminfo
= (QCMINFO
*)lParam
;
1615 HMENU hpopup
= CreatePopupMenu();
1616 _InsertMenuItemW(hpopup
, 0, TRUE
, 0, MFT_STRING
, MAKEINTRESOURCEW(IDS_PROPERTIES
), MFS_ENABLED
);
1617 Shell_MergeMenus(pqcminfo
->hmenu
, hpopup
, pqcminfo
->indexMenu
++, pqcminfo
->idCmdFirst
, pqcminfo
->idCmdLast
, MM_ADDSEPARATOR
);
1618 DestroyMenu(hpopup
);
1624 if (uMsg
!= DFM_INVOKECOMMAND
|| wParam
!= DFM_CMD_PROPERTIES
)
1627 PIDLIST_ABSOLUTE pidlFolder
;
1628 PUITEMID_CHILD
*apidl
;
1630 HRESULT hr
= SH_GetApidlFromDataObject(pdtobj
, &pidlFolder
, &apidl
, &cidl
);
1631 if (FAILED_UNEXPECTEDLY(hr
))
1635 ERR("SHMultiFileProperties is not yet implemented\n");
1638 hr
= GetDisplayNameOf(apidl
[0], SHGDN_FORPARSING
, &strFile
);
1641 hr
= SH_ShowPropertiesDialog(strFile
.pOleStr
, pidlFolder
, apidl
);
1643 ERR("SH_ShowPropertiesDialog failed\n");
1647 ERR("Failed to get display name\n");
1651 _ILFreeaPidl(apidl
, cidl
);