2 * Trash virtual folder support. The trashing engine is implemented in trash.c
4 * Copyright (C) 2006 Mikolaj Zalewski
5 * Copyright 2011 Jay Yang
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
38 #include "shellfolder.h"
40 #include "knownfolders.h"
41 #include "wine/debug.h"
43 #include "shell32_main.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(recyclebin
);
59 static const columninfo RecycleBinColumns
[] =
61 {IDS_SHV_COLUMN1
, &FMTID_Storage
, PID_STG_NAME
, SHCOLSTATE_TYPE_STR
|SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 30},
62 {IDS_SHV_COLUMN_DELFROM
, &FMTID_Displaced
, PID_DISPLACED_FROM
, SHCOLSTATE_TYPE_STR
|SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 30},
63 {IDS_SHV_COLUMN_DELDATE
, &FMTID_Displaced
, PID_DISPLACED_DATE
, SHCOLSTATE_TYPE_DATE
|SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 20},
64 {IDS_SHV_COLUMN2
, &FMTID_Storage
, PID_STG_SIZE
, SHCOLSTATE_TYPE_INT
|SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 20},
65 {IDS_SHV_COLUMN3
, &FMTID_Storage
, PID_STG_STORAGETYPE
,SHCOLSTATE_TYPE_INT
|SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 20},
66 {IDS_SHV_COLUMN4
, &FMTID_Storage
, PID_STG_WRITETIME
, SHCOLSTATE_TYPE_DATE
|SHCOLSTATE_ONBYDEFAULT
, LVCFMT_LEFT
, 20},
67 /* {"creation time", &FMTID_Storage, PID_STG_CREATETIME, SHCOLSTATE_TYPE_DATE, LVCFMT_LEFT, 20}, */
68 /* {"attribs", &FMTID_Storage, PID_STG_ATTRIBUTES, SHCOLSTATE_TYPE_STR, LVCFMT_LEFT, 20}, */
72 #define COLUMN_DELFROM 1
73 #define COLUMN_DATEDEL 2
76 #define COLUMN_MTIME 5
78 #define COLUMNS_COUNT 6
80 static HRESULT
FormatDateTime(LPWSTR buffer
, int size
, FILETIME ft
)
86 FileTimeToLocalFileTime(&ft
, &lft
);
87 FileTimeToSystemTime(&lft
, &time
);
89 ret
= GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &time
, NULL
, buffer
, size
);
90 if (ret
>0 && ret
<size
)
92 /* Append space + time without seconds */
94 GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, &buffer
[ret
], size
- ret
);
97 return (ret
!=0 ? E_FAIL
: S_OK
);
100 typedef struct tagRecycleBinMenu
102 IContextMenu2 IContextMenu2_iface
;
107 IShellFolder2
*folder
;
110 static const IContextMenu2Vtbl recycleBinMenuVtbl
;
112 static RecycleBinMenu
*impl_from_IContextMenu2(IContextMenu2
*iface
)
114 return CONTAINING_RECORD(iface
, RecycleBinMenu
, IContextMenu2_iface
);
117 static IContextMenu2
* RecycleBinMenu_Constructor(UINT cidl
, LPCITEMIDLIST
*apidl
, IShellFolder2
*folder
)
119 RecycleBinMenu
*This
= SHAlloc(sizeof(RecycleBinMenu
));
120 TRACE("(%u,%p)\n",cidl
,apidl
);
121 This
->IContextMenu2_iface
.lpVtbl
= &recycleBinMenuVtbl
;
123 This
->apidl
= _ILCopyaPidl(apidl
,cidl
);
124 IShellFolder2_AddRef(folder
);
125 This
->folder
= folder
;
127 return &This
->IContextMenu2_iface
;
130 static HRESULT WINAPI
RecycleBinMenu_QueryInterface(IContextMenu2
*iface
,
134 RecycleBinMenu
*This
= impl_from_IContextMenu2(iface
);
135 TRACE("(%p, %s, %p) - stub\n", This
, debugstr_guid(riid
), ppvObject
);
139 static ULONG WINAPI
RecycleBinMenu_AddRef(IContextMenu2
*iface
)
141 RecycleBinMenu
*This
= impl_from_IContextMenu2(iface
);
142 TRACE("(%p)\n", This
);
143 return InterlockedIncrement(&This
->refCount
);
147 static ULONG WINAPI
RecycleBinMenu_Release(IContextMenu2
*iface
)
149 RecycleBinMenu
*This
= impl_from_IContextMenu2(iface
);
151 TRACE("(%p)\n", This
);
152 result
= InterlockedDecrement(&This
->refCount
);
155 TRACE("Destroying object\n");
156 _ILFreeaPidl(This
->apidl
,This
->cidl
);
157 IShellFolder2_Release(This
->folder
);
163 static HRESULT WINAPI
RecycleBinMenu_QueryContextMenu(IContextMenu2
*iface
,
170 HMENU menures
= LoadMenuW(shell32_hInstance
,MAKEINTRESOURCEW(MENU_RECYCLEBIN
));
171 if(uFlags
& CMF_DEFAULTONLY
)
174 UINT idMax
= Shell_MergeMenus(hmenu
,GetSubMenu(menures
,0),indexMenu
,idCmdFirst
,idCmdLast
,MM_SUBMENUSHAVEIDS
);
175 TRACE("Added %d id(s)\n",idMax
-idCmdFirst
);
176 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, idMax
-idCmdFirst
+1);
180 static void DoErase(RecycleBinMenu
*This
)
183 IShellFolder2_QueryInterface(This
->folder
,&IID_ISFHelper
,(void**)&helper
);
185 ISFHelper_DeleteItems(helper
,This
->cidl
,(LPCITEMIDLIST
*)This
->apidl
);
188 static void DoRestore(RecycleBinMenu
*This
)
193 for(i
=0;i
<This
->cidl
;i
++)
195 WIN32_FIND_DATAW data
;
196 TRASH_UnpackItemID(&((This
->apidl
[i
])->mkid
),&data
);
197 if(PathFileExistsW(data
.cFileName
))
199 PIDLIST_ABSOLUTE dest_pidl
= ILCreateFromPathW(data
.cFileName
);
202 if(_ILIsFolder(ILFindLastID(dest_pidl
)))
203 LoadStringW(shell32_hInstance
, IDS_RECYCLEBIN_OVERWRITEFOLDER
, message
, ARRAY_SIZE(message
));
205 LoadStringW(shell32_hInstance
, IDS_RECYCLEBIN_OVERWRITEFILE
, message
, ARRAY_SIZE(message
));
206 LoadStringW(shell32_hInstance
, IDS_RECYCLEBIN_OVERWRITE_CAPTION
, caption
, ARRAY_SIZE(caption
));
208 if(ShellMessageBoxW(shell32_hInstance
,GetActiveWindow(),message
,
209 caption
,MB_YESNO
|MB_ICONEXCLAMATION
,
210 data
.cFileName
)!=IDYES
)
213 if(SUCCEEDED(TRASH_RestoreItem(This
->apidl
[i
])))
215 IPersistFolder2
*persist
;
216 LPITEMIDLIST root_pidl
;
217 PIDLIST_ABSOLUTE dest_pidl
= ILCreateFromPathW(data
.cFileName
);
218 BOOL is_folder
= _ILIsFolder(ILFindLastID(dest_pidl
));
219 IShellFolder2_QueryInterface(This
->folder
,&IID_IPersistFolder2
,
221 IPersistFolder2_GetCurFolder(persist
,&root_pidl
);
222 SHChangeNotify(is_folder
? SHCNE_RMDIR
: SHCNE_DELETE
,
223 SHCNF_IDLIST
,ILCombine(root_pidl
,This
->apidl
[i
]),0);
224 SHChangeNotify(is_folder
? SHCNE_MKDIR
: SHCNE_CREATE
,
225 SHCNF_IDLIST
,dest_pidl
,0);
232 static HRESULT WINAPI
RecycleBinMenu_InvokeCommand(IContextMenu2
*iface
,
233 LPCMINVOKECOMMANDINFO pici
)
235 RecycleBinMenu
*This
= impl_from_IContextMenu2(iface
);
236 LPCSTR verb
= pici
->lpVerb
;
237 if(IS_INTRESOURCE(verb
))
241 case IDM_RECYCLEBIN_ERASE
:
244 case IDM_RECYCLEBIN_RESTORE
:
254 static HRESULT WINAPI
RecycleBinMenu_GetCommandString(IContextMenu2
*iface
,
261 TRACE("(%p, %lu, %u, %p, %s, %u) - stub\n",iface
,idCmd
,uType
,pwReserved
,debugstr_a(pszName
),cchMax
);
265 static HRESULT WINAPI
RecycleBinMenu_HandleMenuMsg(IContextMenu2
*iface
,
266 UINT uMsg
, WPARAM wParam
,
269 TRACE("(%p, %u, 0x%lx, 0x%lx) - stub\n",iface
,uMsg
,wParam
,lParam
);
274 static const IContextMenu2Vtbl recycleBinMenuVtbl
=
276 RecycleBinMenu_QueryInterface
,
277 RecycleBinMenu_AddRef
,
278 RecycleBinMenu_Release
,
279 RecycleBinMenu_QueryContextMenu
,
280 RecycleBinMenu_InvokeCommand
,
281 RecycleBinMenu_GetCommandString
,
282 RecycleBinMenu_HandleMenuMsg
,
289 typedef struct tagRecycleBin
291 IShellFolder2 IShellFolder2_iface
;
292 IPersistFolder2 IPersistFolder2_iface
;
293 ISFHelper ISFHelper_iface
;
299 static const IShellFolder2Vtbl recycleBinVtbl
;
300 static const IPersistFolder2Vtbl recycleBinPersistVtbl
;
301 static const ISFHelperVtbl sfhelperVtbl
;
303 static inline RecycleBin
*impl_from_IShellFolder2(IShellFolder2
*iface
)
305 return CONTAINING_RECORD(iface
, RecycleBin
, IShellFolder2_iface
);
308 static RecycleBin
*impl_from_IPersistFolder2(IPersistFolder2
*iface
)
310 return CONTAINING_RECORD(iface
, RecycleBin
, IPersistFolder2_iface
);
313 static RecycleBin
*impl_from_ISFHelper(ISFHelper
*iface
)
315 return CONTAINING_RECORD(iface
, RecycleBin
, ISFHelper_iface
);
318 static void RecycleBin_Destructor(RecycleBin
*This
);
320 HRESULT WINAPI
RecycleBin_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppOutput
)
325 return CLASS_E_NOAGGREGATION
;
327 obj
= SHAlloc(sizeof(RecycleBin
));
329 return E_OUTOFMEMORY
;
330 ZeroMemory(obj
, sizeof(RecycleBin
));
331 obj
->IShellFolder2_iface
.lpVtbl
= &recycleBinVtbl
;
332 obj
->IPersistFolder2_iface
.lpVtbl
= &recycleBinPersistVtbl
;
333 obj
->ISFHelper_iface
.lpVtbl
= &sfhelperVtbl
;
334 if (FAILED(ret
= IPersistFolder2_QueryInterface(&obj
->IPersistFolder2_iface
, riid
, ppOutput
)))
336 RecycleBin_Destructor(obj
);
339 /* InterlockedIncrement(&objCount);*/
343 static void RecycleBin_Destructor(RecycleBin
*This
)
345 /* InterlockedDecrement(&objCount);*/
350 static HRESULT WINAPI
RecycleBin_QueryInterface(IShellFolder2
*iface
, REFIID riid
, void **ppvObject
)
352 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
353 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
356 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IShellFolder
)
357 || IsEqualGUID(riid
, &IID_IShellFolder2
))
358 *ppvObject
= &This
->IShellFolder2_iface
;
360 if (IsEqualGUID(riid
, &IID_IPersist
) || IsEqualGUID(riid
, &IID_IPersistFolder
)
361 || IsEqualGUID(riid
, &IID_IPersistFolder2
))
362 *ppvObject
= &This
->IPersistFolder2_iface
;
363 if (IsEqualGUID(riid
, &IID_ISFHelper
))
364 *ppvObject
= &This
->ISFHelper_iface
;
366 if (*ppvObject
!= NULL
)
368 IUnknown_AddRef((IUnknown
*)*ppvObject
);
371 WARN("no interface %s\n", debugstr_guid(riid
));
372 return E_NOINTERFACE
;
375 static ULONG WINAPI
RecycleBin_AddRef(IShellFolder2
*iface
)
377 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
378 TRACE("(%p)\n", This
);
379 return InterlockedIncrement(&This
->refCount
);
382 static ULONG WINAPI
RecycleBin_Release(IShellFolder2
*iface
)
384 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
387 TRACE("(%p)\n", This
);
388 result
= InterlockedDecrement(&This
->refCount
);
391 TRACE("Destroy object\n");
392 RecycleBin_Destructor(This
);
397 static HRESULT WINAPI
RecycleBin_ParseDisplayName(IShellFolder2
*This
, HWND hwnd
, LPBC pbc
,
398 LPOLESTR pszDisplayName
, ULONG
*pchEaten
, LPITEMIDLIST
*ppidl
,
399 ULONG
*pdwAttributes
)
405 static HRESULT WINAPI
RecycleBin_EnumObjects(IShellFolder2
*iface
, HWND hwnd
, SHCONTF grfFlags
, IEnumIDList
**ppenumIDList
)
407 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
408 IEnumIDListImpl
*list
;
410 HRESULT ret
= E_OUTOFMEMORY
;
414 TRACE("(%p, %p, %x, %p)\n", This
, hwnd
, grfFlags
, ppenumIDList
);
416 *ppenumIDList
= NULL
;
417 list
= IEnumIDList_Constructor();
419 return E_OUTOFMEMORY
;
421 if (grfFlags
& SHCONTF_NONFOLDERS
)
423 if (FAILED(ret
= TRASH_EnumItems(NULL
, &pidls
, &pidls_count
)))
425 for (i
=0; i
<pidls_count
; i
++)
426 if (!AddToEnumList(list
, pidls
[i
]))
430 *ppenumIDList
= &list
->IEnumIDList_iface
;
435 IEnumIDList_Release(&list
->IEnumIDList_iface
);
436 for (; i
<pidls_count
; i
++)
442 static HRESULT WINAPI
RecycleBin_BindToObject(IShellFolder2
*This
, LPCITEMIDLIST pidl
, LPBC pbc
, REFIID riid
, void **ppv
)
444 FIXME("(%p, %p, %p, %s, %p) - stub\n", This
, pidl
, pbc
, debugstr_guid(riid
), ppv
);
448 static HRESULT WINAPI
RecycleBin_BindToStorage(IShellFolder2
*This
, LPCITEMIDLIST pidl
, LPBC pbc
, REFIID riid
, void **ppv
)
450 FIXME("(%p, %p, %p, %s, %p) - stub\n", This
, pidl
, pbc
, debugstr_guid(riid
), ppv
);
454 static HRESULT WINAPI
RecycleBin_CompareIDs(IShellFolder2
*iface
, LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
456 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
460 TRACE("(%p, %p, %p, %p)\n", This
, (void *)lParam
, pidl1
, pidl2
);
461 if (pidl1
->mkid
.cb
!= pidl2
->mkid
.cb
)
462 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, pidl1
->mkid
.cb
- pidl2
->mkid
.cb
);
463 /* Looks too complicated, but in optimized memcpy we might get
464 * a 32bit wide difference and would truncate it to 16 bit, so
465 * erroneously returning equality. */
466 ret
= memcmp(pidl1
->mkid
.abID
, pidl2
->mkid
.abID
, pidl1
->mkid
.cb
);
467 if (ret
< 0) ret
= -1;
468 if (ret
> 0) ret
= 1;
469 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (unsigned short)ret
);
472 static HRESULT WINAPI
RecycleBin_CreateViewObject(IShellFolder2
*iface
, HWND hwndOwner
, REFIID riid
, void **ppv
)
474 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
476 TRACE("(%p, %p, %s, %p)\n", This
, hwndOwner
, debugstr_guid(riid
), ppv
);
479 if (IsEqualGUID(riid
, &IID_IShellView
))
484 ZeroMemory(&sfv
, sizeof(sfv
));
485 sfv
.cbSize
= sizeof(sfv
);
486 sfv
.pshf
= (IShellFolder
*)&This
->IShellFolder2_iface
;
488 TRACE("Calling SHCreateShellFolderViewEx\n");
489 ret
= SHCreateShellFolderViewEx(&sfv
, &tmp
);
490 TRACE("Result: %08x, output: %p\n", (unsigned int)ret
, tmp
);
495 return E_NOINTERFACE
;
498 static HRESULT WINAPI
RecycleBin_GetAttributesOf(IShellFolder2
*This
, UINT cidl
, LPCITEMIDLIST
*apidl
,
501 TRACE("(%p, %d, {%p, ...}, {%x})\n", This
, cidl
, apidl
[0], *rgfInOut
);
502 *rgfInOut
&= SFGAO_CANMOVE
|SFGAO_CANDELETE
|SFGAO_HASPROPSHEET
|SFGAO_FILESYSTEM
;
506 static HRESULT WINAPI
RecycleBin_GetUIObjectOf(IShellFolder2
*iface
, HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
*apidl
,
507 REFIID riid
, UINT
*rgfReserved
, void **ppv
)
509 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
511 if(IsEqualGUID(riid
, &IID_IContextMenu
) || IsEqualGUID(riid
, &IID_IContextMenu2
))
513 TRACE("(%p, %p, %d, {%p, ...}, %s, %p, %p)\n", This
, hwndOwner
, cidl
, apidl
[0], debugstr_guid(riid
), rgfReserved
, ppv
);
514 *ppv
= RecycleBinMenu_Constructor(cidl
,apidl
,&(This
->IShellFolder2_iface
));
517 FIXME("(%p, %p, %d, {%p, ...}, %s, %p, %p): stub!\n", iface
, hwndOwner
, cidl
, apidl
[0], debugstr_guid(riid
), rgfReserved
, ppv
);
522 static HRESULT WINAPI
RecycleBin_GetDisplayNameOf(IShellFolder2
*This
, LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
*pName
)
524 WIN32_FIND_DATAW data
;
526 TRACE("(%p, %p, %x, %p)\n", This
, pidl
, uFlags
, pName
);
527 TRASH_UnpackItemID(&pidl
->mkid
, &data
);
528 pName
->uType
= STRRET_WSTR
;
529 return SHStrDupW(PathFindFileNameW(data
.cFileName
), &pName
->u
.pOleStr
);
532 static HRESULT WINAPI
RecycleBin_SetNameOf(IShellFolder2
*This
, HWND hwnd
, LPCITEMIDLIST pidl
, LPCOLESTR pszName
,
533 SHGDNF uFlags
, LPITEMIDLIST
*ppidlOut
)
536 return E_FAIL
; /* not supported */
539 static HRESULT WINAPI
RecycleBin_GetClassID(IPersistFolder2
*This
, CLSID
*pClassID
)
541 TRACE("(%p, %p)\n", This
, pClassID
);
542 if (This
== NULL
|| pClassID
== NULL
)
544 *pClassID
= CLSID_RecycleBin
;
548 static HRESULT WINAPI
RecycleBin_Initialize(IPersistFolder2
*iface
, LPCITEMIDLIST pidl
)
550 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
551 TRACE("(%p, %p)\n", This
, pidl
);
553 This
->pidl
= ILClone(pidl
);
554 if (This
->pidl
== NULL
)
555 return E_OUTOFMEMORY
;
559 static HRESULT WINAPI
RecycleBin_GetCurFolder(IPersistFolder2
*iface
, LPITEMIDLIST
*ppidl
)
561 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
563 *ppidl
= ILClone(This
->pidl
);
567 static HRESULT WINAPI
RecycleBin_GetDefaultSearchGUID(IShellFolder2
*iface
, GUID
*guid
)
569 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
570 TRACE("(%p)->(%p)\n", This
, guid
);
574 static HRESULT WINAPI
RecycleBin_EnumSearches(IShellFolder2
*iface
, IEnumExtraSearch
**ppEnum
)
581 static HRESULT WINAPI
RecycleBin_GetDefaultColumn(IShellFolder2
*iface
, DWORD reserved
, ULONG
*sort
, ULONG
*display
)
583 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
585 TRACE("(%p)->(%#x, %p, %p)\n", This
, reserved
, sort
, display
);
590 static HRESULT WINAPI
RecycleBin_GetDefaultColumnState(IShellFolder2
*iface
, UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
592 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
593 TRACE("(%p, %d, %p)\n", This
, iColumn
, pcsFlags
);
594 if (iColumn
>= COLUMNS_COUNT
)
596 *pcsFlags
= RecycleBinColumns
[iColumn
].pcsFlags
;
600 static HRESULT WINAPI
RecycleBin_GetDetailsEx(IShellFolder2
*iface
, LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
606 static HRESULT WINAPI
RecycleBin_GetDetailsOf(IShellFolder2
*iface
, LPCITEMIDLIST pidl
, UINT iColumn
, LPSHELLDETAILS pDetails
)
608 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
609 WIN32_FIND_DATAW data
;
610 WCHAR buffer
[MAX_PATH
];
612 TRACE("(%p, %p, %d, %p)\n", This
, pidl
, iColumn
, pDetails
);
613 if (iColumn
>= COLUMNS_COUNT
)
615 pDetails
->fmt
= RecycleBinColumns
[iColumn
].fmt
;
616 pDetails
->cxChar
= RecycleBinColumns
[iColumn
].cxChars
;
619 pDetails
->str
.uType
= STRRET_WSTR
;
620 LoadStringW(shell32_hInstance
, RecycleBinColumns
[iColumn
].column_name_id
, buffer
, MAX_PATH
);
621 return SHStrDupW(buffer
, &pDetails
->str
.u
.pOleStr
);
624 if (iColumn
== COLUMN_NAME
)
625 return RecycleBin_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
, &pDetails
->str
);
627 TRASH_UnpackItemID(&pidl
->mkid
, &data
);
631 FormatDateTime(buffer
, MAX_PATH
, data
.ftLastAccessTime
);
634 lstrcpyW(buffer
, data
.cFileName
);
635 PathRemoveFileSpecW(buffer
);
638 StrFormatKBSizeW(((LONGLONG
)data
.nFileSizeHigh
<<32)|data
.nFileSizeLow
, buffer
, MAX_PATH
);
641 FormatDateTime(buffer
, MAX_PATH
, data
.ftLastWriteTime
);
651 pDetails
->str
.uType
= STRRET_WSTR
;
652 return SHStrDupW(buffer
, &pDetails
->str
.u
.pOleStr
);
655 static HRESULT WINAPI
RecycleBin_MapColumnToSCID(IShellFolder2
*iface
, UINT iColumn
, SHCOLUMNID
*pscid
)
657 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
658 TRACE("(%p, %d, %p)\n", This
, iColumn
, pscid
);
659 if (iColumn
>=COLUMNS_COUNT
)
661 pscid
->fmtid
= *RecycleBinColumns
[iColumn
].fmtId
;
662 pscid
->pid
= RecycleBinColumns
[iColumn
].pid
;
666 static const IShellFolder2Vtbl recycleBinVtbl
=
669 RecycleBin_QueryInterface
,
674 RecycleBin_ParseDisplayName
,
675 RecycleBin_EnumObjects
,
676 RecycleBin_BindToObject
,
677 RecycleBin_BindToStorage
,
678 RecycleBin_CompareIDs
,
679 RecycleBin_CreateViewObject
,
680 RecycleBin_GetAttributesOf
,
681 RecycleBin_GetUIObjectOf
,
682 RecycleBin_GetDisplayNameOf
,
683 RecycleBin_SetNameOf
,
686 RecycleBin_GetDefaultSearchGUID
,
687 RecycleBin_EnumSearches
,
688 RecycleBin_GetDefaultColumn
,
689 RecycleBin_GetDefaultColumnState
,
690 RecycleBin_GetDetailsEx
,
691 RecycleBin_GetDetailsOf
,
692 RecycleBin_MapColumnToSCID
695 static HRESULT WINAPI
RecycleBin_IPersistFolder2_QueryInterface(IPersistFolder2
*iface
, REFIID riid
,
698 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
700 return IShellFolder2_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObject
);
703 static ULONG WINAPI
RecycleBin_IPersistFolder2_AddRef(IPersistFolder2
*iface
)
705 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
707 return IShellFolder2_AddRef(&This
->IShellFolder2_iface
);
710 static ULONG WINAPI
RecycleBin_IPersistFolder2_Release(IPersistFolder2
*iface
)
712 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
714 return IShellFolder2_Release(&This
->IShellFolder2_iface
);
717 static const IPersistFolder2Vtbl recycleBinPersistVtbl
=
720 RecycleBin_IPersistFolder2_QueryInterface
,
721 RecycleBin_IPersistFolder2_AddRef
,
722 RecycleBin_IPersistFolder2_Release
,
725 RecycleBin_GetClassID
,
727 RecycleBin_Initialize
,
728 /* IPersistFolder2 */
729 RecycleBin_GetCurFolder
732 static HRESULT WINAPI
RecycleBin_ISFHelper_QueryInterface(ISFHelper
*iface
, REFIID riid
,
735 RecycleBin
*This
= impl_from_ISFHelper(iface
);
737 return IShellFolder2_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObject
);
740 static ULONG WINAPI
RecycleBin_ISFHelper_AddRef(ISFHelper
*iface
)
742 RecycleBin
*This
= impl_from_ISFHelper(iface
);
744 return IShellFolder2_AddRef(&This
->IShellFolder2_iface
);
747 static ULONG WINAPI
RecycleBin_ISFHelper_Release(ISFHelper
*iface
)
749 RecycleBin
*This
= impl_from_ISFHelper(iface
);
751 return IShellFolder2_Release(&This
->IShellFolder2_iface
);
754 static HRESULT WINAPI
RecycleBin_GetUniqueName(ISFHelper
*iface
,LPWSTR lpName
,
760 static HRESULT WINAPI
RecycleBin_AddFolder(ISFHelper
* iface
, HWND hwnd
,
762 LPITEMIDLIST
* ppidlOut
)
764 /*Adding folders doesn't make sense in the recycle bin*/
768 static HRESULT
erase_items(HWND parent
,const LPCITEMIDLIST
* apidl
, UINT cidl
, BOOL confirm
)
772 LPITEMIDLIST recyclebin
;
785 WIN32_FIND_DATAW data
;
786 TRASH_UnpackItemID(&((*apidl
)->mkid
),&data
);
787 lstrcpynW(arg
,data
.cFileName
,MAX_PATH
);
788 LoadStringW(shell32_hInstance
, IDS_RECYCLEBIN_ERASEITEM
, message
, ARRAY_SIZE(message
));
793 static const WCHAR format
[]={'%','u','\0'};
794 LoadStringW(shell32_hInstance
, IDS_RECYCLEBIN_ERASEMULTIPLE
, message
, ARRAY_SIZE(message
));
795 sprintfW(arg
,format
,cidl
);
800 LoadStringW(shell32_hInstance
, IDS_RECYCLEBIN_ERASE_CAPTION
, caption
, ARRAY_SIZE(caption
));
801 if(ShellMessageBoxW(shell32_hInstance
,parent
,message
,caption
,
802 MB_YESNO
|MB_ICONEXCLAMATION
,arg
)!=IDYES
)
806 SHGetFolderLocation(parent
,CSIDL_BITBUCKET
,0,0,&recyclebin
);
809 if(SUCCEEDED(TRASH_EraseItem(apidl
[i
])))
810 SHChangeNotify(SHCNE_DELETE
,SHCNF_IDLIST
,
811 ILCombine(recyclebin
,apidl
[i
]),0);
817 static HRESULT WINAPI
RecycleBin_DeleteItems(ISFHelper
* iface
, UINT cidl
,
818 LPCITEMIDLIST
* apidl
)
820 TRACE("(%p,%u,%p)\n",iface
,cidl
,apidl
);
821 return erase_items(GetActiveWindow(),apidl
,cidl
,TRUE
);
824 static HRESULT WINAPI
RecycleBin_CopyItems(ISFHelper
* iface
,
825 IShellFolder
* pSFFrom
,
826 UINT cidl
, LPCITEMIDLIST
* apidl
)
831 static const ISFHelperVtbl sfhelperVtbl
=
833 RecycleBin_ISFHelper_QueryInterface
,
834 RecycleBin_ISFHelper_AddRef
,
835 RecycleBin_ISFHelper_Release
,
836 RecycleBin_GetUniqueName
,
837 RecycleBin_AddFolder
,
838 RecycleBin_DeleteItems
,
842 HRESULT WINAPI
SHQueryRecycleBinA(LPCSTR pszRootPath
, LPSHQUERYRBINFO pSHQueryRBInfo
)
844 WCHAR wszRootPath
[MAX_PATH
];
845 MultiByteToWideChar(CP_ACP
, 0, pszRootPath
, -1, wszRootPath
, MAX_PATH
);
846 return SHQueryRecycleBinW(wszRootPath
, pSHQueryRBInfo
);
849 HRESULT WINAPI
SHQueryRecycleBinW(LPCWSTR pszRootPath
, LPSHQUERYRBINFO pSHQueryRBInfo
)
856 TRACE("(%s, %p)\n", debugstr_w(pszRootPath
), pSHQueryRBInfo
);
858 hr
= TRASH_EnumItems(pszRootPath
, &apidl
, &cidl
);
861 pSHQueryRBInfo
->i64NumItems
= cidl
;
862 pSHQueryRBInfo
->i64Size
= 0;
865 WIN32_FIND_DATAW data
;
866 TRASH_UnpackItemID(&((apidl
[i
])->mkid
),&data
);
867 pSHQueryRBInfo
->i64Size
+= ((DWORDLONG
)data
.nFileSizeHigh
<< 32) + data
.nFileSizeLow
;
874 HRESULT WINAPI
SHEmptyRecycleBinA(HWND hwnd
, LPCSTR pszRootPath
, DWORD dwFlags
)
876 WCHAR wszRootPath
[MAX_PATH
];
877 MultiByteToWideChar(CP_ACP
, 0, pszRootPath
, -1, wszRootPath
, MAX_PATH
);
878 return SHEmptyRecycleBinW(hwnd
, wszRootPath
, dwFlags
);
881 #define SHERB_NOCONFIRMATION 1
882 #define SHERB_NOPROGRESSUI 2
883 #define SHERB_NOSOUND 4
885 HRESULT WINAPI
SHEmptyRecycleBinW(HWND hwnd
, LPCWSTR pszRootPath
, DWORD dwFlags
)
892 TRACE("(%p, %s, 0x%08x)\n", hwnd
, debugstr_w(pszRootPath
) , dwFlags
);
894 ret
= TRASH_EnumItems(pszRootPath
, &apidl
, &cidl
);
898 ret
= erase_items(hwnd
,(const LPCITEMIDLIST
*)apidl
,cidl
,!(dwFlags
& SHERB_NOCONFIRMATION
));
905 /*************************************************************************
906 * SHUpdateRecycleBinIcon [SHELL32.@]
910 HRESULT WINAPI
SHUpdateRecycleBinIcon(void)