5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
7 * Copyright 2019 Katayama Hirofumi MZ
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
28 HKEY
OpenKeyFromFileType(PCUIDLIST_RELATIVE pidl
, LPCWSTR KeyName
)
32 if (!_ILIsValue(pidl
))
34 ERR("Invalid pidl!\n");
38 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
41 ERR("Invalid pidl!\n");
45 LPWSTR pExtension
= PathFindExtensionW(pDataW
->wszName
);
46 if (!pExtension
|| *pExtension
== NULL
)
48 WARN("No extension for %S!\n", pDataW
->wszName
);
52 WCHAR FullName
[MAX_PATH
];
53 DWORD dwSize
= sizeof(FullName
);
54 wsprintf(FullName
, L
"%s\\%s", pExtension
, KeyName
);
56 LONG res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, FullName
, 0, KEY_READ
, &hkey
);
60 res
= RegGetValueW(HKEY_CLASSES_ROOT
, pExtension
, NULL
, RRF_RT_REG_SZ
, NULL
, FullName
, &dwSize
);
63 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
);
67 wcscat(FullName
, L
"\\");
68 wcscat(FullName
, KeyName
);
71 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, FullName
, 0, KEY_READ
, &hkey
);
73 WARN("Could not open key %S for extension %S\n", KeyName
, pExtension
);
78 HRESULT
GetCLSIDForFileType(PCUIDLIST_RELATIVE pidl
, LPCWSTR KeyName
, CLSID
* pclsid
)
80 HKEY hkeyProgId
= OpenKeyFromFileType(pidl
, KeyName
);
83 WARN("OpenKeyFromFileType failed for key %S\n", KeyName
);
87 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
88 DWORD dwSize
= sizeof(wszCLSIDValue
);
89 LONG res
= RegGetValueW(hkeyProgId
, NULL
, NULL
, RRF_RT_REG_SZ
, NULL
, wszCLSIDValue
, &dwSize
);
90 RegCloseKey(hkeyProgId
);
93 ERR("OpenKeyFromFileType succeeded but RegGetValueW failed\n");
99 res
= RegGetValueW(HKEY_LOCAL_MACHINE
,
100 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved",
106 if (res
!= ERROR_SUCCESS
)
108 ERR("DropHandler extension %S not approved\n", wszName
);
109 return E_ACCESSDENIED
;
114 if (RegGetValueW(HKEY_LOCAL_MACHINE
,
115 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Blocked",
120 NULL
) == ERROR_SUCCESS
)
122 ERR("Extension %S not approved\n", wszCLSIDValue
);
123 return E_ACCESSDENIED
;
126 HRESULT hres
= CLSIDFromString (wszCLSIDValue
, pclsid
);
127 if (FAILED_UNEXPECTEDLY(hres
))
134 getDefaultIconLocation(LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT uFlags
)
136 static const WCHAR folder
[] = { 'F', 'o', 'l', 'd', 'e', 'r', 0 };
138 if (!HCR_GetIconW(folder
, szIconFile
, NULL
, cchMax
, piIndex
))
140 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
141 *piIndex
= -IDI_SHELL_FOLDER
;
144 if (uFlags
& GIL_OPENICON
)
156 static const WCHAR s_shellClassInfo
[] = { '.', 'S', 'h', 'e', 'l', 'l', 'C', 'l', 'a', 's', 's', 'I', 'n', 'f', 'o', 0 };
159 getShellClassInfo(LPCWSTR Entry
, LPWSTR pszValue
, DWORD cchValueLen
, LPCWSTR IniFile
)
161 return GetPrivateProfileStringW(s_shellClassInfo
, Entry
, NULL
, pszValue
, cchValueLen
, IniFile
);
165 getIconLocationForFolder(IShellFolder
* psf
, PCITEMID_CHILD pidl
, UINT uFlags
,
166 LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
169 WCHAR wszPath
[MAX_PATH
];
170 WCHAR wszIniFullPath
[MAX_PATH
];
171 static const WCHAR iconFile
[] = { 'I', 'c', 'o', 'n', 'F', 'i', 'l', 'e', 0 };
172 static const WCHAR clsid
[] = { 'C', 'L', 'S', 'I', 'D', 0 };
173 static const WCHAR clsid2
[] = { 'C', 'L', 'S', 'I', 'D', '2', 0 };
174 static const WCHAR iconIndex
[] = { 'I', 'c', 'o', 'n', 'I', 'n', 'd', 'e', 'x', 0 };
175 static const WCHAR iconResource
[] = { 'I', 'c', 'o', 'n', 'R', 'e', 's', 'o', 'u', 'r', 'c', 'e', 0 };
176 static const WCHAR wszDesktopIni
[] = { 'd','e','s','k','t','o','p','.','i','n','i',0 };
178 if (uFlags
& GIL_DEFAULTICON
)
182 if (!ILGetDisplayNameExW(psf
, pidl
, wszPath
, 0))
184 if (!PathIsDirectoryW(wszPath
))
187 // read-only or system folder?
188 dwFileAttrs
= _ILGetFileAttributes(ILFindLastID(pidl
), NULL
, 0);
189 if ((dwFileAttrs
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)) == 0)
192 // build the full path of ini file
193 StringCchCopyW(wszIniFullPath
, _countof(wszIniFullPath
), wszPath
);
194 PathAppendW(wszIniFullPath
, wszDesktopIni
);
196 WCHAR wszValue
[MAX_PATH
], wszTemp
[MAX_PATH
];
197 if (getShellClassInfo(iconFile
, wszValue
, _countof(wszValue
), wszIniFullPath
))
199 // wszValue --> wszTemp
200 ExpandEnvironmentStringsW(wszValue
, wszTemp
, _countof(wszTemp
));
202 // wszPath + wszTemp --> wszPath
203 if (PathIsRelativeW(wszTemp
))
204 PathAppendW(wszPath
, wszTemp
);
206 StringCchCopyW(wszPath
, _countof(wszPath
), wszTemp
);
208 // wszPath --> szIconFile
209 GetFullPathNameW(wszPath
, cchMax
, szIconFile
, NULL
);
211 *piIndex
= GetPrivateProfileIntW(s_shellClassInfo
, iconIndex
, 0, wszIniFullPath
);
214 else if (getShellClassInfo(clsid
, wszValue
, _countof(wszValue
), wszIniFullPath
) &&
215 HCR_GetIconW(wszValue
, szIconFile
, NULL
, cchMax
, piIndex
))
219 else if (getShellClassInfo(clsid2
, wszValue
, _countof(wszValue
), wszIniFullPath
) &&
220 HCR_GetIconW(wszValue
, szIconFile
, NULL
, cchMax
, piIndex
))
224 else if (getShellClassInfo(iconResource
, wszValue
, _countof(wszValue
), wszIniFullPath
))
226 // wszValue --> wszTemp
227 ExpandEnvironmentStringsW(wszValue
, wszTemp
, _countof(wszTemp
));
229 // parse the icon location
230 *piIndex
= PathParseIconLocationW(wszTemp
);
232 // wszPath + wszTemp --> wszPath
233 if (PathIsRelativeW(wszTemp
))
234 PathAppendW(wszPath
, wszTemp
);
236 StringCchCopyW(wszPath
, _countof(wszPath
), wszTemp
);
238 // wszPath --> szIconFile
239 GetFullPathNameW(wszPath
, cchMax
, szIconFile
, NULL
);
244 return getDefaultIconLocation(szIconFile
, cchMax
, piIndex
, uFlags
);
247 HRESULT
CFSExtractIcon_CreateInstance(IShellFolder
* psf
, LPCITEMIDLIST pidl
, REFIID iid
, LPVOID
* ppvOut
)
249 CComPtr
<IDefaultExtractIconInit
> initIcon
;
252 UINT flags
= 0; // FIXME: Use it!
253 WCHAR wTemp
[MAX_PATH
] = L
"";
255 hr
= SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit
,&initIcon
));
259 if (_ILIsFolder (pidl
))
261 if (SUCCEEDED(getIconLocationForFolder(psf
,
262 pidl
, 0, wTemp
, _countof(wTemp
),
266 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
267 // FIXME: if/when getIconLocationForFolder does something for
268 // GIL_FORSHORTCUT, code below should be uncommented. and
269 // the following line removed.
270 initIcon
->SetShortcutIcon(wTemp
, icon_idx
);
272 if (SUCCEEDED(getIconLocationForFolder(psf
,
273 pidl
, GIL_DEFAULTICON
, wTemp
, _countof(wTemp
),
277 initIcon
->SetDefaultIcon(wTemp
, icon_idx
);
279 // if (SUCCEEDED(getIconLocationForFolder(psf,
280 // pidl, GIL_FORSHORTCUT, wTemp, _countof(wTemp),
284 // initIcon->SetShortcutIcon(wTemp, icon_idx);
286 if (SUCCEEDED(getIconLocationForFolder(psf
,
287 pidl
, GIL_OPENICON
, wTemp
, _countof(wTemp
),
291 initIcon
->SetOpenIcon(wTemp
, icon_idx
);
296 HKEY hkey
= OpenKeyFromFileType(pidl
, L
"DefaultIcon");
298 WARN("Could not open DefaultIcon key!\n");
300 DWORD dwSize
= sizeof(wTemp
);
301 if (hkey
&& !SHQueryValueExW(hkey
, NULL
, NULL
, NULL
, wTemp
, &dwSize
))
304 if (ParseFieldW (wTemp
, 2, sNum
, 5))
305 icon_idx
= _wtoi(sNum
);
307 icon_idx
= 0; /* sometimes the icon number is missing */
308 ParseFieldW (wTemp
, 1, wTemp
, MAX_PATH
);
309 PathUnquoteSpacesW(wTemp
);
311 if (!wcscmp(L
"%1", wTemp
)) /* icon is in the file */
313 ILGetDisplayNameExW(psf
, pidl
, wTemp
, 0);
317 initIcon
->SetNormalIcon(wTemp
, icon_idx
);
321 initIcon
->SetNormalIcon(swShell32Name
, 0);
328 return initIcon
->QueryInterface(iid
, ppvOut
);
332 CFileSysEnum should do an initial FindFirstFile and do a FindNextFile as each file is
333 returned by Next. When the enumerator is created, it can do numerous additional operations
334 including formatting a drive, reconnecting a network share drive, and requesting a disk
335 be inserted in a removable drive.
338 /***********************************************************************
339 * IShellFolder implementation
343 public CEnumIDListBase
349 HRESULT WINAPI
Initialize(LPWSTR sPathTarget
, DWORD dwFlags
);
351 BEGIN_COM_MAP(CFileSysEnum
)
352 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList
, IEnumIDList
)
356 CFileSysEnum::CFileSysEnum()
360 CFileSysEnum::~CFileSysEnum()
364 HRESULT WINAPI
CFileSysEnum::Initialize(LPWSTR lpszPath
, DWORD dwFlags
)
366 WIN32_FIND_DATAW stffile
;
368 WCHAR szPath
[MAX_PATH
];
369 BOOL succeeded
= TRUE
;
370 static const WCHAR stars
[] = { '*','.','*',0 };
371 static const WCHAR dot
[] = { '.',0 };
372 static const WCHAR dotdot
[] = { '.','.',0 };
374 TRACE("(%p)->(path=%s flags=0x%08x)\n", this, debugstr_w(lpszPath
), dwFlags
);
376 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
378 wcscpy(szPath
, lpszPath
);
379 PathAddBackslashW(szPath
);
380 wcscat(szPath
,stars
);
382 hFile
= FindFirstFileW(szPath
,&stffile
);
383 if ( hFile
!= INVALID_HANDLE_VALUE
)
385 BOOL findFinished
= FALSE
;
389 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
390 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
392 LPITEMIDLIST pidl
= NULL
;
394 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
395 dwFlags
& SHCONTF_FOLDERS
&&
396 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
398 pidl
= _ILCreateFromFindDataW(&stffile
);
399 succeeded
= succeeded
&& AddToEnumList(pidl
);
401 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
402 && dwFlags
& SHCONTF_NONFOLDERS
)
404 pidl
= _ILCreateFromFindDataW(&stffile
);
405 succeeded
= succeeded
&& AddToEnumList(pidl
);
410 if (!FindNextFileW(hFile
, &stffile
))
412 if (GetLastError() == ERROR_NO_MORE_FILES
)
418 } while (succeeded
&& !findFinished
);
425 CFSFolder::CFSFolder()
427 pclsid
= (CLSID
*)&CLSID_ShellFSFolder
;
430 m_bGroupPolicyActive
= 0;
433 CFSFolder::~CFSFolder()
435 TRACE("-- destroying IShellFolder(%p)\n", this);
442 static const shvheader GenericSFHeader
[] = {
443 {IDS_SHV_COLUMN_NAME
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 15},
444 {IDS_SHV_COLUMN_COMMENTS
, SHCOLSTATE_TYPE_STR
, LVCFMT_LEFT
, 0},
445 {IDS_SHV_COLUMN_TYPE
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 10},
446 {IDS_SHV_COLUMN_SIZE
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10},
447 {IDS_SHV_COLUMN_MODIFIED
, SHCOLSTATE_TYPE_DATE
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 12},
448 {IDS_SHV_COLUMN_ATTRIBUTES
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 10}
451 #define GENERICSHELLVIEWCOLUMNS 6
453 /**************************************************************************
454 * SHELL32_CreatePidlFromBindCtx [internal]
456 * If the caller bound File System Bind Data, assume it is the
457 * find data for the path.
458 * This allows binding of paths that don't exist.
460 LPITEMIDLIST
SHELL32_CreatePidlFromBindCtx(IBindCtx
*pbc
, LPCWSTR path
)
462 IFileSystemBindData
*fsbd
= NULL
;
463 LPITEMIDLIST pidl
= NULL
;
464 IUnknown
*param
= NULL
;
465 WIN32_FIND_DATAW wfd
;
468 TRACE("%p %s\n", pbc
, debugstr_w(path
));
473 /* see if the caller bound File System Bind Data */
474 r
= pbc
->GetObjectParam((LPOLESTR
)STR_FILE_SYS_BIND_DATA
, ¶m
);
478 r
= param
->QueryInterface(IID_PPV_ARG(IFileSystemBindData
,&fsbd
));
481 r
= fsbd
->GetFindData(&wfd
);
484 lstrcpynW(&wfd
.cFileName
[0], path
, MAX_PATH
);
485 pidl
= _ILCreateFromFindDataW(&wfd
);
493 void SHELL32_GetCLSIDForDirectory(LPCWSTR pwszDir
, CLSID
* pclsidFolder
)
495 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
496 WCHAR wszDesktopIni
[MAX_PATH
];
497 StringCchCopyW(wszDesktopIni
, MAX_PATH
, pwszDir
);
498 StringCchCatW(wszDesktopIni
, MAX_PATH
, L
"\\desktop.ini");
500 if (GetPrivateProfileStringW(L
".ShellClassInfo",
507 CLSIDFromString (wszCLSIDValue
, pclsidFolder
);
511 HRESULT
SHELL32_GetFSItemAttributes(IShellFolder
* psf
, LPCITEMIDLIST pidl
, LPDWORD pdwAttributes
)
513 DWORD dwFileAttributes
, dwShellAttributes
;
515 if (!_ILIsFolder(pidl
) && !_ILIsValue(pidl
))
517 ERR("Got wrong type of pidl!\n");
518 *pdwAttributes
&= SFGAO_CANLINK
;
522 dwFileAttributes
= _ILGetFileAttributes(pidl
, NULL
, 0);
524 /* Set common attributes */
525 dwShellAttributes
= SFGAO_CANCOPY
| SFGAO_CANMOVE
| SFGAO_CANLINK
| SFGAO_CANRENAME
| SFGAO_CANDELETE
|
526 SFGAO_HASPROPSHEET
| SFGAO_DROPTARGET
| SFGAO_FILESYSTEM
;
528 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
529 dwShellAttributes
|= (SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
| SFGAO_FILESYSANCESTOR
| SFGAO_STORAGEANCESTOR
| SFGAO_STORAGE
);
531 dwShellAttributes
|= SFGAO_STREAM
;
533 if (dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
534 dwShellAttributes
|= SFGAO_HIDDEN
;
536 if (dwFileAttributes
& FILE_ATTRIBUTE_READONLY
)
537 dwShellAttributes
|= SFGAO_READONLY
;
539 if (SFGAO_LINK
& *pdwAttributes
)
543 if (_ILGetExtension(pidl
, ext
, MAX_PATH
) && !lstrcmpiA(ext
, "lnk"))
544 dwShellAttributes
|= SFGAO_LINK
;
547 if (SFGAO_HASSUBFOLDER
& *pdwAttributes
)
549 CComPtr
<IShellFolder
> psf2
;
550 if (SUCCEEDED(psf
->BindToObject(pidl
, 0, IID_PPV_ARG(IShellFolder
, &psf2
))))
552 CComPtr
<IEnumIDList
> pEnumIL
;
553 if (SUCCEEDED(psf2
->EnumObjects(0, SHCONTF_FOLDERS
, &pEnumIL
)))
555 if (pEnumIL
->Skip(1) == S_OK
)
556 dwShellAttributes
|= SFGAO_HASSUBFOLDER
;
561 *pdwAttributes
= dwShellAttributes
;
563 TRACE ("-- 0x%08x\n", *pdwAttributes
);
567 /**************************************************************************
568 * CFSFolder::ParseDisplayName {SHELL32}
570 * Parse a display name.
573 * hwndOwner [in] Parent window for any message's
574 * pbc [in] optional FileSystemBindData context
575 * lpszDisplayName [in] Unicode displayname.
576 * pchEaten [out] (unicode) characters processed
577 * ppidl [out] complex pidl to item
578 * pdwAttributes [out] items attributes
581 * Every folder tries to parse only its own (the leftmost) pidl and creates a
582 * subfolder to evaluate the remaining parts.
583 * Now we can parse into namespaces implemented by shell extensions
585 * Behaviour on win98: lpszDisplayName=NULL -> crash
586 * lpszDisplayName="" -> returns mycoputer-pidl
589 * pdwAttributes is not set
590 * pchEaten is not set like in windows
592 HRESULT WINAPI
CFSFolder::ParseDisplayName(HWND hwndOwner
,
594 LPOLESTR lpszDisplayName
,
595 DWORD
*pchEaten
, PIDLIST_RELATIVE
*ppidl
,
596 DWORD
*pdwAttributes
)
598 HRESULT hr
= E_INVALIDARG
;
599 LPCWSTR szNext
= NULL
;
600 WCHAR szElement
[MAX_PATH
];
601 WCHAR szPath
[MAX_PATH
];
602 LPITEMIDLIST pidlTemp
= NULL
;
605 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
606 this, hwndOwner
, pbc
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
607 pchEaten
, ppidl
, pdwAttributes
);
612 if (!lpszDisplayName
)
621 *pchEaten
= 0; /* strange but like the original */
623 if (*lpszDisplayName
)
625 /* get the next element */
626 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
628 pidlTemp
= SHELL32_CreatePidlFromBindCtx(pbc
, szElement
);
629 if (pidlTemp
!= NULL
)
631 /* We are creating an id list without ensuring that the items exist.
632 If we have a remaining path, this must be a folder.
633 We have to do it now because it is set as a file by default */
636 pidlTemp
->mkid
.abID
[0] = PT_FOLDER
;
642 /* build the full pathname to the element */
643 lstrcpynW(szPath
, sPathTarget
, MAX_PATH
- 1);
644 PathAddBackslashW(szPath
);
645 len
= wcslen(szPath
);
646 lstrcpynW(szPath
+ len
, szElement
, MAX_PATH
- len
);
649 hr
= _ILCreateFromPathW(szPath
, &pidlTemp
);
654 if (szNext
&& *szNext
)
656 /* try to analyse the next element */
657 hr
= SHELL32_ParseNextElement(this, hwndOwner
, pbc
,
658 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
662 /* it's the last element */
663 if (pdwAttributes
&& *pdwAttributes
)
664 hr
= SHELL32_GetFSItemAttributes(this, pidlTemp
, pdwAttributes
);
674 TRACE("(%p)->(-- pidl=%p ret=0x%08x)\n", this, ppidl
? *ppidl
: 0, hr
);
679 /**************************************************************************
680 * CFSFolder::EnumObjects
682 * HWND hwndOwner, //[in ] Parent Window
683 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
684 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
686 HRESULT WINAPI
CFSFolder::EnumObjects(
689 LPENUMIDLIST
*ppEnumIDList
)
691 return ShellObjectCreatorInit
<CFileSysEnum
>(sPathTarget
, dwFlags
, IID_PPV_ARG(IEnumIDList
, ppEnumIDList
));
694 /**************************************************************************
695 * CFSFolder::BindToObject
697 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
698 * LPBC pbc, //[in ] optional FileSystemBindData context
699 * REFIID riid, //[in ] Initial Interface
700 * LPVOID* ppvObject //[out] Interface*
702 HRESULT WINAPI
CFSFolder::BindToObject(
703 PCUIDLIST_RELATIVE pidl
,
708 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", this, pidl
, pbc
,
709 shdebugstr_guid(&riid
), ppvOut
);
711 CComPtr
<IShellFolder
> pSF
;
714 if (!pidlRoot
|| !ppvOut
|| !pidl
|| !pidl
->mkid
.cb
)
716 ERR("CFSFolder::BindToObject: Invalid parameters\n");
720 /* Get the pidl data */
721 FileStruct
* pData
= &_ILGetDataPointer(pidl
)->u
.file
;
722 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
726 ERR("CFSFolder::BindToObject: Invalid pidl!\n");
732 /* Create the target folder info */
733 PERSIST_FOLDER_TARGET_INFO pfti
= {0};
734 pfti
.dwAttributes
= -1;
736 PathCombineW(pfti
.szTargetParsingName
, sPathTarget
, pDataW
->wszName
);
738 /* Get the CLSID to bind to */
740 if (_ILIsFolder(pidl
))
742 clsidFolder
= CLSID_ShellFSFolder
;
744 if ((pData
->uFileAttribs
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)) != 0)
745 SHELL32_GetCLSIDForDirectory(pfti
.szTargetParsingName
, &clsidFolder
);
749 hr
= GetCLSIDForFileType(pidl
, L
"CLSID", &clsidFolder
);
751 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
756 hr
= SHELL32_BindToSF(pidlRoot
, &pfti
, pidl
, &clsidFolder
, riid
, ppvOut
);
757 if (FAILED_UNEXPECTEDLY(hr
))
760 TRACE ("-- returning (%p) %08x\n", *ppvOut
, hr
);
766 /**************************************************************************
767 * CFSFolder::BindToStorage
769 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
770 * LPBC pbc, //[in ] reserved
771 * REFIID riid, //[in ] Initial storage interface
772 * LPVOID* ppvObject //[out] Interface* returned
774 HRESULT WINAPI
CFSFolder::BindToStorage(
775 PCUIDLIST_RELATIVE pidl
,
780 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", this, pidl
, pbcReserved
,
781 shdebugstr_guid (&riid
), ppvOut
);
787 /**************************************************************************
788 * CFSFolder::CompareIDs
791 HRESULT WINAPI
CFSFolder::CompareIDs(LPARAM lParam
,
792 PCUIDLIST_RELATIVE pidl1
,
793 PCUIDLIST_RELATIVE pidl2
)
795 LPPIDLDATA pData1
= _ILGetDataPointer(pidl1
);
796 LPPIDLDATA pData2
= _ILGetDataPointer(pidl2
);
797 FileStructW
* pDataW1
= _ILGetFileStructW(pidl1
);
798 FileStructW
* pDataW2
= _ILGetFileStructW(pidl2
);
799 BOOL bIsFolder1
= _ILIsFolder(pidl1
);
800 BOOL bIsFolder2
= _ILIsFolder(pidl2
);
801 LPWSTR pExtension1
, pExtension2
;
803 if (!pDataW1
|| !pDataW2
|| LOWORD(lParam
) >= GENERICSHELLVIEWCOLUMNS
)
806 /* When sorting between a File and a Folder, the Folder gets sorted first */
807 if (bIsFolder1
!= bIsFolder2
)
809 return MAKE_COMPARE_HRESULT(bIsFolder1
? -1 : 1);
813 switch (LOWORD(lParam
))
816 result
= wcsicmp(pDataW1
->wszName
, pDataW2
->wszName
);
818 case 1: /* Comments */
822 pExtension1
= PathFindExtensionW(pDataW1
->wszName
);
823 pExtension2
= PathFindExtensionW(pDataW2
->wszName
);
824 result
= wcsicmp(pExtension1
, pExtension2
);
827 result
= pData1
->u
.file
.dwFileSize
- pData2
->u
.file
.dwFileSize
;
829 case 4: /* Modified */
830 result
= pData1
->u
.file
.uFileDate
- pData2
->u
.file
.uFileDate
;
832 result
= pData1
->u
.file
.uFileTime
- pData2
->u
.file
.uFileTime
;
834 case 5: /* Attributes */
835 return SHELL32_CompareDetails(this, lParam
, pidl1
, pidl2
);
839 return SHELL32_CompareChildren(this, lParam
, pidl1
, pidl2
);
841 return MAKE_COMPARE_HRESULT(result
);
844 /**************************************************************************
845 * CFSFolder::CreateViewObject
847 HRESULT WINAPI
CFSFolder::CreateViewObject(HWND hwndOwner
,
848 REFIID riid
, LPVOID
* ppvOut
)
850 CComPtr
<IShellView
> pShellView
;
851 HRESULT hr
= E_INVALIDARG
;
853 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", this, hwndOwner
, shdebugstr_guid (&riid
),
860 if (IsEqualIID (riid
, IID_IDropTarget
))
861 hr
= CFSDropTarget_CreateInstance(sPathTarget
, riid
, ppvOut
);
862 else if (IsEqualIID (riid
, IID_IContextMenu
))
866 AddClassKeyToArray(L
"Directory\\Background", hKeys
, &cKeys
);
869 dcm
.hwnd
= hwndOwner
;
871 dcm
.pidlFolder
= pidlRoot
;
877 dcm
.punkAssociationInfo
= NULL
;
878 hr
= SHCreateDefaultContextMenu (&dcm
, riid
, ppvOut
);
880 else if (IsEqualIID (riid
, IID_IShellView
))
882 SFV_CREATE sfvparams
= {sizeof(SFV_CREATE
), this, NULL
, this};
883 hr
= SHCreateShellFolderView(&sfvparams
, (IShellView
**)ppvOut
);
886 TRACE("-- (%p)->(interface=%p)\n", this, ppvOut
);
890 /**************************************************************************
891 * CFSFolder::GetAttributesOf
894 * UINT cidl, //[in ] num elements in pidl array
895 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
896 * ULONG* rgfInOut) //[out] result array
899 HRESULT WINAPI
CFSFolder::GetAttributesOf(UINT cidl
,
900 PCUITEMID_CHILD_ARRAY apidl
, DWORD
* rgfInOut
)
914 LPCITEMIDLIST rpidl
= ILFindLastID(pidlRoot
);
916 if (_ILIsFolder(rpidl
) || _ILIsValue(rpidl
))
918 SHELL32_GetFSItemAttributes(this, rpidl
, rgfInOut
);
920 else if (_ILIsDrive(rpidl
))
922 IShellFolder
*psfParent
= NULL
;
923 hr
= SHBindToParent(pidlRoot
, IID_PPV_ARG(IShellFolder
, &psfParent
), NULL
);
926 hr
= psfParent
->GetAttributesOf(1, &rpidl
, (SFGAOF
*)rgfInOut
);
927 psfParent
->Release();
932 ERR("Got and unknown pidl!\n");
937 while (cidl
> 0 && *apidl
)
940 if(_ILIsFolder(*apidl
) || _ILIsValue(*apidl
))
941 SHELL32_GetFSItemAttributes(this, *apidl
, rgfInOut
);
943 ERR("Got an unknown type of pidl!!!\n");
948 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
949 *rgfInOut
&= ~SFGAO_VALIDATE
;
951 TRACE("-- result=0x%08x\n", *rgfInOut
);
956 /**************************************************************************
957 * CFSFolder::GetUIObjectOf
960 * HWND hwndOwner, //[in ] Parent window for any output
961 * UINT cidl, //[in ] array size
962 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
963 * REFIID riid, //[in ] Requested Interface
964 * UINT* prgfInOut, //[ ] reserved
965 * LPVOID* ppvObject) //[out] Resulting Interface
968 * This function gets asked to return "view objects" for one or more (multiple
970 * The viewobject typically is an COM object with one of the following
972 * IExtractIcon,IDataObject,IContextMenu
973 * In order to support icon positions in the default Listview your DataObject
974 * must implement the SetData method (in addition to GetData :) - the shell
975 * passes a barely documented "Icon positions" structure to SetData when the
976 * drag starts, and GetData's it if the drop is in another explorer window that
977 * needs the positions.
979 HRESULT WINAPI
CFSFolder::GetUIObjectOf(HWND hwndOwner
,
980 UINT cidl
, PCUITEMID_CHILD_ARRAY apidl
,
981 REFIID riid
, UINT
* prgfInOut
,
985 HRESULT hr
= E_INVALIDARG
;
987 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
988 this, hwndOwner
, cidl
, apidl
, shdebugstr_guid (&riid
), prgfInOut
, ppvOut
);
994 if (cidl
== 1 && _ILIsValue(apidl
[0]))
996 hr
= _CreateExtensionUIObject(apidl
[0], riid
, ppvOut
);
1001 if (IsEqualIID(riid
, IID_IContextMenu
) && (cidl
>= 1))
1005 AddFSClassKeysToArray(apidl
[0], hKeys
, &cKeys
);
1008 dcm
.hwnd
= hwndOwner
;
1010 dcm
.pidlFolder
= pidlRoot
;
1016 dcm
.punkAssociationInfo
= NULL
;
1017 hr
= SHCreateDefaultContextMenu (&dcm
, riid
, &pObj
);
1019 else if (IsEqualIID (riid
, IID_IDataObject
))
1023 hr
= IDataObject_Constructor (hwndOwner
, pidlRoot
, apidl
, cidl
, (IDataObject
**)&pObj
);
1030 else if ((IsEqualIID (riid
, IID_IExtractIconA
) || IsEqualIID (riid
, IID_IExtractIconW
)) && (cidl
== 1))
1032 if (_ILIsValue(apidl
[0]))
1033 hr
= _GetIconHandler(apidl
[0], riid
, (LPVOID
*)&pObj
);
1035 hr
= CFSExtractIcon_CreateInstance(this, apidl
[0], riid
, &pObj
);
1037 else if (IsEqualIID (riid
, IID_IDropTarget
))
1039 /* only interested in attempting to bind to shell folders, not files (except exe), so if we fail, rebind to root */
1040 if (cidl
!= 1 || FAILED(hr
= this->_GetDropTarget(apidl
[0], (LPVOID
*) &pObj
)))
1042 hr
= CFSDropTarget_CreateInstance(sPathTarget
, riid
, (LPVOID
*) &pObj
);
1048 if (SUCCEEDED(hr
) && !pObj
)
1053 TRACE("(%p)->hr=0x%08x\n", this, hr
);
1057 static const WCHAR AdvancedW
[] = L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced";
1058 static const WCHAR HideFileExtW
[] = L
"HideFileExt";
1059 static const WCHAR NeverShowExtW
[] = L
"NeverShowExt";
1061 /******************************************************************************
1062 * SHELL_FS_HideExtension [Internal]
1064 * Query the registry if the filename extension of a given path should be
1068 * szPath [I] Relative or absolute path of a file
1071 * TRUE, if the filename's extension should be hidden
1074 BOOL
SHELL_FS_HideExtension(LPWSTR szPath
)
1078 DWORD dwDataSize
= sizeof (DWORD
);
1079 BOOL doHide
= FALSE
; /* The default value is FALSE (win98 at least) */
1081 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, AdvancedW
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0)) {
1082 if (!RegQueryValueExW(hKey
, HideFileExtW
, 0, 0, (LPBYTE
) &dwData
, &dwDataSize
))
1088 LPWSTR ext
= PathFindExtensionW(szPath
);
1091 WCHAR classname
[MAX_PATH
];
1092 LONG classlen
= sizeof(classname
);
1094 if (!RegQueryValueW(HKEY_CLASSES_ROOT
, ext
, classname
, &classlen
))
1095 if (!RegOpenKeyW(HKEY_CLASSES_ROOT
, classname
, &hKey
)) {
1096 if (!RegQueryValueExW(hKey
, NeverShowExtW
, 0, NULL
, NULL
, NULL
))
1105 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath
, DWORD dwFlags
)
1107 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
1108 if (!(dwFlags
& SHGDN_FORPARSING
) &&
1109 ((dwFlags
& SHGDN_INFOLDER
) || (dwFlags
== SHGDN_NORMAL
))) {
1110 if (SHELL_FS_HideExtension(szPath
) && szPath
[0] != '.')
1111 PathRemoveExtensionW(szPath
);
1115 /**************************************************************************
1116 * CFSFolder::GetDisplayNameOf
1117 * Retrieves the display name for the specified file object or subfolder
1120 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
1121 * DWORD dwFlags, //[in ] SHGNO formatting flags
1122 * LPSTRRET lpName) //[out] Returned display name
1125 * if the name is in the pidl the ret value should be a STRRET_OFFSET
1128 HRESULT WINAPI
CFSFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl
,
1129 DWORD dwFlags
, LPSTRRET strRet
)
1132 return E_INVALIDARG
;
1134 /* If it is a complex pidl, let the child handle it */
1135 if (!_ILIsPidlSimple (pidl
)) /* complex pidl */
1137 return SHELL32_GetDisplayNameOfChild(this, pidl
, dwFlags
, strRet
);
1139 else if (pidl
&& !pidl
->mkid
.cb
) /* empty pidl */
1141 /* If it is an empty pidl return only the path of the folder */
1142 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
1143 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
1146 return SHSetStrRet(strRet
, sPathTarget
);
1148 return E_INVALIDARG
;
1152 LPWSTR pszPath
= (LPWSTR
)CoTaskMemAlloc((MAX_PATH
+ 1) * sizeof(WCHAR
));
1154 return E_OUTOFMEMORY
;
1156 if ((GET_SHGDN_FOR(dwFlags
) & SHGDN_FORPARSING
) &&
1157 (GET_SHGDN_RELATION(dwFlags
) != SHGDN_INFOLDER
) &&
1160 lstrcpynW(pszPath
, sPathTarget
, MAX_PATH
);
1161 PathAddBackslashW(pszPath
);
1162 len
= wcslen(pszPath
);
1164 _ILSimpleGetTextW(pidl
, pszPath
+ len
, MAX_PATH
+ 1 - len
);
1165 if (!_ILIsFolder(pidl
)) SHELL_FS_ProcessDisplayFilename(pszPath
, dwFlags
);
1167 strRet
->uType
= STRRET_WSTR
;
1168 strRet
->pOleStr
= pszPath
;
1170 TRACE ("-- (%p)->(%s)\n", this, strRet
->uType
== STRRET_CSTR
? strRet
->cStr
: debugstr_w(strRet
->pOleStr
));
1174 /**************************************************************************
1175 * CFSFolder::SetNameOf
1176 * Changes the name of a file object or subfolder, possibly changing its item
1177 * identifier in the process.
1180 * HWND hwndOwner, //[in ] Owner window for output
1181 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
1182 * LPCOLESTR lpszName, //[in ] the items new display name
1183 * DWORD dwFlags, //[in ] SHGNO formatting flags
1184 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
1186 HRESULT WINAPI
CFSFolder::SetNameOf(
1188 PCUITEMID_CHILD pidl
,
1191 PITEMID_CHILD
*pPidlOut
)
1193 WCHAR szSrc
[MAX_PATH
+ 1], szDest
[MAX_PATH
+ 1];
1194 BOOL bIsFolder
= _ILIsFolder (ILFindLastID (pidl
));
1196 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", this, hwndOwner
, pidl
,
1197 debugstr_w (lpName
), dwFlags
, pPidlOut
);
1199 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
1202 ERR("Got garbage pidl\n");
1203 return E_INVALIDARG
;
1206 /* build source path */
1207 PathCombineW(szSrc
, sPathTarget
, pDataW
->wszName
);
1209 /* build destination path */
1210 if (dwFlags
== SHGDN_NORMAL
|| dwFlags
& SHGDN_INFOLDER
)
1211 PathCombineW(szDest
, sPathTarget
, lpName
);
1213 lstrcpynW(szDest
, lpName
, MAX_PATH
);
1215 if(!(dwFlags
& SHGDN_FORPARSING
) && SHELL_FS_HideExtension(szSrc
)) {
1216 WCHAR
*ext
= PathFindExtensionW(szSrc
);
1218 INT len
= wcslen(szDest
);
1219 lstrcpynW(szDest
+ len
, ext
, MAX_PATH
- len
);
1223 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc
), debugstr_w(szDest
));
1224 if (!wcscmp(szSrc
, szDest
))
1226 /* src and destination is the same */
1229 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
1234 if (MoveFileW (szSrc
, szDest
))
1239 hr
= _ILCreateFromPathW(szDest
, pPidlOut
);
1241 SHChangeNotify (bIsFolder
? SHCNE_RENAMEFOLDER
: SHCNE_RENAMEITEM
,
1242 SHCNF_PATHW
, szSrc
, szDest
);
1250 HRESULT WINAPI
CFSFolder::GetDefaultSearchGUID(GUID
* pguid
)
1252 FIXME ("(%p)\n", this);
1256 HRESULT WINAPI
CFSFolder::EnumSearches(IEnumExtraSearch
** ppenum
)
1258 FIXME ("(%p)\n", this);
1262 HRESULT WINAPI
CFSFolder::GetDefaultColumn(DWORD dwRes
,
1263 ULONG
* pSort
, ULONG
* pDisplay
)
1265 TRACE ("(%p)\n", this);
1275 HRESULT WINAPI
CFSFolder::GetDefaultColumnState(UINT iColumn
,
1278 TRACE ("(%p)\n", this);
1280 if (!pcsFlags
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1281 return E_INVALIDARG
;
1283 *pcsFlags
= GenericSFHeader
[iColumn
].pcsFlags
;
1288 HRESULT WINAPI
CFSFolder::GetDetailsEx(PCUITEMID_CHILD pidl
,
1289 const SHCOLUMNID
* pscid
, VARIANT
* pv
)
1291 FIXME ("(%p)\n", this);
1296 HRESULT WINAPI
CFSFolder::GetDetailsOf(PCUITEMID_CHILD pidl
,
1297 UINT iColumn
, SHELLDETAILS
* psd
)
1299 HRESULT hr
= E_FAIL
;
1301 TRACE ("(%p)->(%p %i %p)\n", this, pidl
, iColumn
, psd
);
1303 if (!psd
|| iColumn
>= GENERICSHELLVIEWCOLUMNS
)
1304 return E_INVALIDARG
;
1308 /* the header titles */
1309 psd
->fmt
= GenericSFHeader
[iColumn
].fmt
;
1310 psd
->cxChar
= GenericSFHeader
[iColumn
].cxChar
;
1311 return SHSetStrRet(&psd
->str
, GenericSFHeader
[iColumn
].colnameid
);
1316 psd
->str
.uType
= STRRET_CSTR
;
1317 /* the data from the pidl */
1321 hr
= GetDisplayNameOf (pidl
, SHGDN_NORMAL
| SHGDN_INFOLDER
, &psd
->str
);
1323 case 1: /* FIXME: comments */
1324 psd
->str
.cStr
[0] = 0;
1327 _ILGetFileType(pidl
, psd
->str
.cStr
, MAX_PATH
);
1330 _ILGetFileSize(pidl
, psd
->str
.cStr
, MAX_PATH
);
1333 _ILGetFileDate(pidl
, psd
->str
.cStr
, MAX_PATH
);
1335 case 5: /* attributes */
1336 _ILGetFileAttributes(pidl
, psd
->str
.cStr
, MAX_PATH
);
1344 HRESULT WINAPI
CFSFolder::MapColumnToSCID (UINT column
,
1347 FIXME ("(%p)\n", this);
1351 /************************************************************************
1352 * CFSFolder::GetClassID
1354 HRESULT WINAPI
CFSFolder::GetClassID(CLSID
* lpClassId
)
1356 TRACE ("(%p)\n", this);
1361 *lpClassId
= *pclsid
;
1366 /************************************************************************
1367 * CFSFolder::Initialize
1370 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1372 HRESULT WINAPI
CFSFolder::Initialize(LPCITEMIDLIST pidl
)
1374 WCHAR wszTemp
[MAX_PATH
];
1376 TRACE ("(%p)->(%p)\n", this, pidl
);
1378 SHFree (pidlRoot
); /* free the old pidl */
1379 pidlRoot
= ILClone (pidl
); /* set my pidl */
1381 SHFree (sPathTarget
);
1385 if (SHGetPathFromIDListW (pidl
, wszTemp
))
1387 int len
= wcslen(wszTemp
);
1388 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1390 return E_OUTOFMEMORY
;
1391 memcpy(sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1394 TRACE ("--(%p)->(%s)\n", this, debugstr_w(sPathTarget
));
1398 /**************************************************************************
1399 * CFSFolder::GetCurFolder
1401 HRESULT WINAPI
CFSFolder::GetCurFolder(PIDLIST_ABSOLUTE
* pidl
)
1403 TRACE ("(%p)->(%p)\n", this, pidl
);
1408 *pidl
= ILClone(pidlRoot
);
1412 /**************************************************************************
1413 * CFSFolder::InitializeEx
1415 * FIXME: error handling
1417 HRESULT WINAPI
CFSFolder::InitializeEx(IBindCtx
* pbc
, LPCITEMIDLIST pidlRootx
,
1418 const PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1420 WCHAR wszTemp
[MAX_PATH
];
1422 TRACE("(%p)->(%p,%p,%p)\n", this, pbc
, pidlRootx
, ppfti
);
1424 TRACE("--%p %s %s 0x%08x 0x%08x\n",
1425 ppfti
->pidlTargetFolder
, debugstr_w (ppfti
->szTargetParsingName
),
1426 debugstr_w (ppfti
->szNetworkProvider
), ppfti
->dwAttributes
,
1430 if (ppfti
&& ppfti
->pidlTargetFolder
)
1431 pdump(ppfti
->pidlTargetFolder
);
1434 __SHFreeAndNil(&pidlRoot
); /* free the old */
1436 __SHFreeAndNil(&sPathTarget
);
1439 * Root path and pidl
1441 pidlRoot
= ILClone(pidlRootx
);
1444 * the target folder is spezified in csidl OR pidlTargetFolder OR
1445 * szTargetParsingName
1449 if (ppfti
->csidl
!= -1)
1451 if (SHGetSpecialFolderPathW(0, wszTemp
, ppfti
->csidl
,
1452 ppfti
->csidl
& CSIDL_FLAG_CREATE
)) {
1453 int len
= wcslen(wszTemp
);
1454 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1456 return E_OUTOFMEMORY
;
1457 memcpy(sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1460 else if (ppfti
->szTargetParsingName
[0])
1462 int len
= wcslen(ppfti
->szTargetParsingName
);
1463 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1465 return E_OUTOFMEMORY
;
1466 memcpy(sPathTarget
, ppfti
->szTargetParsingName
,
1467 (len
+ 1) * sizeof(WCHAR
));
1469 else if (ppfti
->pidlTargetFolder
)
1471 if (SHGetPathFromIDListW(ppfti
->pidlTargetFolder
, wszTemp
))
1473 int len
= wcslen(wszTemp
);
1474 sPathTarget
= (WCHAR
*)SHAlloc((len
+ 1) * sizeof(WCHAR
));
1476 return E_OUTOFMEMORY
;
1477 memcpy(sPathTarget
, wszTemp
, (len
+ 1) * sizeof(WCHAR
));
1482 TRACE("--(%p)->(target=%s)\n", this, debugstr_w(sPathTarget
));
1484 return (sPathTarget
) ? S_OK
: E_FAIL
;
1487 HRESULT WINAPI
CFSFolder::GetFolderTargetInfo(PERSIST_FOLDER_TARGET_INFO
* ppfti
)
1489 FIXME("(%p)->(%p)\n", this, ppfti
);
1490 ZeroMemory(ppfti
, sizeof (*ppfti
));
1494 HRESULT
CFSFolder::_CreateExtensionUIObject(PCUIDLIST_RELATIVE pidl
, REFIID riid
, LPVOID
*ppvOut
)
1496 static const WCHAR formatW
[] = {'S','h','e','l','l','E','x','\\',
1497 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
1498 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
1499 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
1500 WCHAR buf
[MAX_PATH
];
1502 sprintfW(buf
, formatW
, riid
.Data1
, riid
.Data2
, riid
.Data3
,
1503 riid
.Data4
[0], riid
.Data4
[1], riid
.Data4
[2], riid
.Data4
[3],
1504 riid
.Data4
[4], riid
.Data4
[5], riid
.Data4
[6], riid
.Data4
[7]);
1509 hr
= GetCLSIDForFileType(pidl
, buf
, &clsid
);
1513 hr
= _CreateShellExtInstance(&clsid
, pidl
, riid
, ppvOut
);
1514 if (FAILED_UNEXPECTEDLY(hr
))
1520 HRESULT
CFSFolder::_GetDropTarget(LPCITEMIDLIST pidl
, LPVOID
*ppvOut
)
1524 TRACE("CFSFolder::_GetDropTarget entered\n");
1526 if (_ILIsFolder (pidl
))
1528 CComPtr
<IShellFolder
> psfChild
;
1529 hr
= this->BindToObject(pidl
, NULL
, IID_PPV_ARG(IShellFolder
, &psfChild
));
1530 if (FAILED_UNEXPECTEDLY(hr
))
1533 return psfChild
->CreateViewObject(NULL
, IID_IDropTarget
, ppvOut
);
1537 hr
= GetCLSIDForFileType(pidl
, L
"shellex\\DropHandler", &clsid
);
1541 hr
= _CreateShellExtInstance(&clsid
, pidl
, IID_IDropTarget
, ppvOut
);
1542 if (FAILED_UNEXPECTEDLY(hr
))
1548 HRESULT
CFSFolder::_GetIconHandler(LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
1553 hr
= GetCLSIDForFileType(pidl
, L
"shellex\\IconHandler", &clsid
);
1557 hr
= _CreateShellExtInstance(&clsid
, pidl
, riid
, ppvOut
);
1558 if (FAILED_UNEXPECTEDLY(hr
))
1564 HRESULT
CFSFolder::_CreateShellExtInstance(const CLSID
*pclsid
, LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppvOut
)
1567 WCHAR wszPath
[MAX_PATH
];
1569 FileStructW
* pDataW
= _ILGetFileStructW(pidl
);
1572 ERR("Got garbage pidl\n");
1573 return E_INVALIDARG
;
1576 PathCombineW(wszPath
, sPathTarget
, pDataW
->wszName
);
1578 CComPtr
<IPersistFile
> pp
;
1579 hr
= SHCoCreateInstance(NULL
, pclsid
, NULL
, IID_PPV_ARG(IPersistFile
, &pp
));
1580 if (FAILED_UNEXPECTEDLY(hr
))
1583 pp
->Load(wszPath
, 0);
1585 hr
= pp
->QueryInterface(riid
, ppvOut
);
1588 ERR("Failed to query for interface IID_IShellExtInit hr %x pclsid %s\n", hr
, wine_dbgstr_guid(pclsid
));
1594 HRESULT WINAPI
CFSFolder::CallBack(IShellFolder
*psf
, HWND hwndOwner
, IDataObject
*pdtobj
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1596 if (uMsg
!= DFM_MERGECONTEXTMENU
&& uMsg
!= DFM_INVOKECOMMAND
)
1599 /* no data object means no selection */
1602 if (uMsg
== DFM_INVOKECOMMAND
&& wParam
== 0)
1604 PUITEMID_CHILD pidlChild
= ILClone(ILFindLastID(pidlRoot
));
1605 LPITEMIDLIST pidlParent
= ILClone(pidlRoot
);
1606 ILRemoveLastID(pidlParent
);
1607 HRESULT hr
= SH_ShowPropertiesDialog(sPathTarget
, pidlParent
, &pidlChild
);
1609 ERR("SH_ShowPropertiesDialog failed\n");
1613 else if (uMsg
== DFM_MERGECONTEXTMENU
)
1615 QCMINFO
*pqcminfo
= (QCMINFO
*)lParam
;
1616 HMENU hpopup
= CreatePopupMenu();
1617 _InsertMenuItemW(hpopup
, 0, TRUE
, 0, MFT_STRING
, MAKEINTRESOURCEW(IDS_PROPERTIES
), MFS_ENABLED
);
1618 Shell_MergeMenus(pqcminfo
->hmenu
, hpopup
, pqcminfo
->indexMenu
++, pqcminfo
->idCmdFirst
, pqcminfo
->idCmdLast
, MM_ADDSEPARATOR
);
1619 DestroyMenu(hpopup
);
1625 if (uMsg
!= DFM_INVOKECOMMAND
|| wParam
!= DFM_CMD_PROPERTIES
)
1628 return Shell_DefaultContextMenuCallBack(this, pdtobj
);
1631 static HBITMAP
DoLoadPicture(LPCWSTR pszFileName
)
1633 // create stream from file
1635 CComPtr
<IStream
> pStream
;
1636 hr
= SHCreateStreamOnFileEx(pszFileName
, STGM_READ
, FILE_ATTRIBUTE_NORMAL
,
1637 FALSE
, NULL
, &pStream
);
1643 CComPtr
<IPicture
> pPicture
;
1644 OleLoadPicture(pStream
, 0, FALSE
, IID_IPicture
, (LPVOID
*)&pPicture
);
1646 // get the bitmap handle
1649 pPicture
->get_Handle((OLE_HANDLE
*)&hbm
);
1651 // copy the bitmap handle
1652 hbm
= (HBITMAP
)CopyImage(hbm
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
1658 HRESULT WINAPI
CFSFolder::GetCustomViewInfo(ULONG unknown
, SFVM_CUSTOMVIEWINFO_DATA
*data
)
1664 if (data
->cbSize
!= sizeof(*data
))
1666 // NOTE: You have to set the cbData member before SFVM_GET_CUSTOMVIEWINFO call.
1667 return E_INVALIDARG
;
1670 data
->hbmBack
= NULL
;
1671 data
->clrText
= CLR_INVALID
;
1672 data
->clrTextBack
= CLR_INVALID
;
1674 WCHAR szPath
[MAX_PATH
], szIniFile
[MAX_PATH
];
1676 // does the folder exists?
1677 if (!SHGetPathFromIDListW(pidlRoot
, szPath
) || !PathIsDirectoryW(szPath
))
1679 return E_INVALIDARG
;
1682 // don't use custom view in network path for security
1683 if (PathIsNetworkPath(szPath
))
1685 return E_ACCESSDENIED
;
1688 // build the ini file path
1689 StringCchCopyW(szIniFile
, _countof(szIniFile
), szPath
);
1690 PathAppend(szIniFile
, L
"desktop.ini");
1692 static LPCWSTR TheGUID
= L
"{BE098140-A513-11D0-A3A4-00C04FD706EC}";
1693 static LPCWSTR Space
= L
" \t\n\r\f\v";
1695 // get info from ini file
1696 WCHAR szImage
[MAX_PATH
], szText
[64];
1699 szImage
[0] = UNICODE_NULL
;
1700 GetPrivateProfileStringW(TheGUID
, L
"IconArea_Image", L
"", szImage
, _countof(szImage
), szIniFile
);
1703 StrTrimW(szImage
, Space
);
1704 if (PathIsRelativeW(szImage
))
1706 PathAppendW(szPath
, szImage
);
1707 StringCchCopyW(szImage
, _countof(szImage
), szPath
);
1709 data
->hbmBack
= DoLoadPicture(szImage
);
1712 // load the text color
1713 szText
[0] = UNICODE_NULL
;
1714 GetPrivateProfileStringW(TheGUID
, L
"IconArea_Text", L
"", szText
, _countof(szText
), szIniFile
);
1717 StrTrimW(szText
, Space
);
1719 LPWSTR pchEnd
= NULL
;
1720 COLORREF cr
= (wcstol(szText
, &pchEnd
, 0) & 0xFFFFFF);
1722 if (pchEnd
&& !*pchEnd
)
1726 // load the text background color
1727 szText
[0] = UNICODE_NULL
;
1728 GetPrivateProfileStringW(TheGUID
, L
"IconArea_TextBackground", L
"", szText
, _countof(szText
), szIniFile
);
1731 StrTrimW(szText
, Space
);
1733 LPWSTR pchEnd
= NULL
;
1734 COLORREF cr
= (wcstol(szText
, &pchEnd
, 0) & 0xFFFFFF);
1736 if (pchEnd
&& !*pchEnd
)
1737 data
->clrTextBack
= cr
;
1740 if (data
->hbmBack
!= NULL
|| data
->clrText
!= CLR_INVALID
|| data
->clrTextBack
!= CLR_INVALID
)
1746 HRESULT WINAPI
CFSFolder::MessageSFVCB(UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1748 HRESULT hr
= E_NOTIMPL
;
1751 case SFVM_GET_CUSTOMVIEWINFO
:
1752 hr
= GetCustomViewInfo((ULONG
)wParam
, (SFVM_CUSTOMVIEWINFO_DATA
*)lParam
);