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 IShellFolder_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
,
204 message
,sizeof(message
)/sizeof(WCHAR
));
206 LoadStringW(shell32_hInstance
,IDS_RECYCLEBIN_OVERWRITEFILE
,
207 message
,sizeof(message
)/sizeof(WCHAR
));
208 LoadStringW(shell32_hInstance
,IDS_RECYCLEBIN_OVERWRITE_CAPTION
,
209 caption
,sizeof(caption
)/sizeof(WCHAR
));
211 if(ShellMessageBoxW(shell32_hInstance
,GetActiveWindow(),message
,
212 caption
,MB_YESNO
|MB_ICONEXCLAMATION
,
213 data
.cFileName
)!=IDYES
)
216 if(SUCCEEDED(TRASH_RestoreItem(This
->apidl
[i
])))
218 IPersistFolder2
*persist
;
219 LPITEMIDLIST root_pidl
;
220 PIDLIST_ABSOLUTE dest_pidl
= ILCreateFromPathW(data
.cFileName
);
221 BOOL is_folder
= _ILIsFolder(ILFindLastID(dest_pidl
));
222 IShellFolder2_QueryInterface(This
->folder
,&IID_IPersistFolder2
,
224 IPersistFolder2_GetCurFolder(persist
,&root_pidl
);
225 SHChangeNotify(is_folder
? SHCNE_RMDIR
: SHCNE_DELETE
,
226 SHCNF_IDLIST
,ILCombine(root_pidl
,This
->apidl
[i
]),0);
227 SHChangeNotify(is_folder
? SHCNE_MKDIR
: SHCNE_CREATE
,
228 SHCNF_IDLIST
,dest_pidl
,0);
235 static HRESULT WINAPI
RecycleBinMenu_InvokeCommand(IContextMenu2
*iface
,
236 LPCMINVOKECOMMANDINFO pici
)
238 RecycleBinMenu
*This
= impl_from_IContextMenu2(iface
);
239 LPCSTR verb
= pici
->lpVerb
;
240 if(IS_INTRESOURCE(verb
))
244 case IDM_RECYCLEBIN_ERASE
:
247 case IDM_RECYCLEBIN_RESTORE
:
257 static HRESULT WINAPI
RecycleBinMenu_GetCommandString(IContextMenu2
*iface
,
264 TRACE("(%p, %lu, %u, %p, %s, %u) - stub\n",iface
,idCmd
,uType
,pwReserved
,debugstr_a(pszName
),cchMax
);
268 static HRESULT WINAPI
RecycleBinMenu_HandleMenuMsg(IContextMenu2
*iface
,
269 UINT uMsg
, WPARAM wParam
,
272 TRACE("(%p, %u, 0x%lx, 0x%lx) - stub\n",iface
,uMsg
,wParam
,lParam
);
277 static const IContextMenu2Vtbl recycleBinMenuVtbl
=
279 RecycleBinMenu_QueryInterface
,
280 RecycleBinMenu_AddRef
,
281 RecycleBinMenu_Release
,
282 RecycleBinMenu_QueryContextMenu
,
283 RecycleBinMenu_InvokeCommand
,
284 RecycleBinMenu_GetCommandString
,
285 RecycleBinMenu_HandleMenuMsg
,
292 typedef struct tagRecycleBin
294 IShellFolder2 IShellFolder2_iface
;
295 IPersistFolder2 IPersistFolder2_iface
;
296 ISFHelper ISFHelper_iface
;
302 static const IShellFolder2Vtbl recycleBinVtbl
;
303 static const IPersistFolder2Vtbl recycleBinPersistVtbl
;
304 static const ISFHelperVtbl sfhelperVtbl
;
306 static inline RecycleBin
*impl_from_IShellFolder2(IShellFolder2
*iface
)
308 return CONTAINING_RECORD(iface
, RecycleBin
, IShellFolder2_iface
);
311 static RecycleBin
*impl_from_IPersistFolder2(IPersistFolder2
*iface
)
313 return CONTAINING_RECORD(iface
, RecycleBin
, IPersistFolder2_iface
);
316 static RecycleBin
*impl_from_ISFHelper(ISFHelper
*iface
)
318 return CONTAINING_RECORD(iface
, RecycleBin
, ISFHelper_iface
);
321 static void RecycleBin_Destructor(RecycleBin
*This
);
323 HRESULT WINAPI
RecycleBin_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppOutput
)
328 return CLASS_E_NOAGGREGATION
;
330 obj
= SHAlloc(sizeof(RecycleBin
));
332 return E_OUTOFMEMORY
;
333 ZeroMemory(obj
, sizeof(RecycleBin
));
334 obj
->IShellFolder2_iface
.lpVtbl
= &recycleBinVtbl
;
335 obj
->IPersistFolder2_iface
.lpVtbl
= &recycleBinPersistVtbl
;
336 obj
->ISFHelper_iface
.lpVtbl
= &sfhelperVtbl
;
337 if (FAILED(ret
= IPersistFolder2_QueryInterface(&obj
->IPersistFolder2_iface
, riid
, ppOutput
)))
339 RecycleBin_Destructor(obj
);
342 /* InterlockedIncrement(&objCount);*/
346 static void RecycleBin_Destructor(RecycleBin
*This
)
348 /* InterlockedDecrement(&objCount);*/
353 static HRESULT WINAPI
RecycleBin_QueryInterface(IShellFolder2
*iface
, REFIID riid
, void **ppvObject
)
355 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
356 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
359 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IShellFolder
)
360 || IsEqualGUID(riid
, &IID_IShellFolder2
))
363 if (IsEqualGUID(riid
, &IID_IPersist
) || IsEqualGUID(riid
, &IID_IPersistFolder
)
364 || IsEqualGUID(riid
, &IID_IPersistFolder2
))
365 *ppvObject
= &This
->IPersistFolder2_iface
;
366 if (IsEqualGUID(riid
, &IID_ISFHelper
))
367 *ppvObject
= &This
->ISFHelper_iface
;
369 if (*ppvObject
!= NULL
)
371 IUnknown_AddRef((IUnknown
*)*ppvObject
);
374 WARN("no interface %s\n", debugstr_guid(riid
));
375 return E_NOINTERFACE
;
378 static ULONG WINAPI
RecycleBin_AddRef(IShellFolder2
*iface
)
380 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
381 TRACE("(%p)\n", This
);
382 return InterlockedIncrement(&This
->refCount
);
385 static ULONG WINAPI
RecycleBin_Release(IShellFolder2
*iface
)
387 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
390 TRACE("(%p)\n", This
);
391 result
= InterlockedDecrement(&This
->refCount
);
394 TRACE("Destroy object\n");
395 RecycleBin_Destructor(This
);
400 static HRESULT WINAPI
RecycleBin_ParseDisplayName(IShellFolder2
*This
, HWND hwnd
, LPBC pbc
,
401 LPOLESTR pszDisplayName
, ULONG
*pchEaten
, LPITEMIDLIST
*ppidl
,
402 ULONG
*pdwAttributes
)
408 static HRESULT WINAPI
RecycleBin_EnumObjects(IShellFolder2
*iface
, HWND hwnd
, SHCONTF grfFlags
, IEnumIDList
**ppenumIDList
)
410 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
411 IEnumIDListImpl
*list
;
413 HRESULT ret
= E_OUTOFMEMORY
;
417 TRACE("(%p, %p, %x, %p)\n", This
, hwnd
, grfFlags
, ppenumIDList
);
419 *ppenumIDList
= NULL
;
420 list
= IEnumIDList_Constructor();
422 return E_OUTOFMEMORY
;
424 if (grfFlags
& SHCONTF_NONFOLDERS
)
426 if (FAILED(ret
= TRASH_EnumItems(&pidls
, &pidls_count
)))
428 for (i
=0; i
<pidls_count
; i
++)
429 if (!AddToEnumList(list
, pidls
[i
]))
433 *ppenumIDList
= &list
->IEnumIDList_iface
;
438 IEnumIDList_Release(&list
->IEnumIDList_iface
);
439 for (; i
<pidls_count
; i
++)
445 static HRESULT WINAPI
RecycleBin_BindToObject(IShellFolder2
*This
, LPCITEMIDLIST pidl
, LPBC pbc
, REFIID riid
, void **ppv
)
447 FIXME("(%p, %p, %p, %s, %p) - stub\n", This
, pidl
, pbc
, debugstr_guid(riid
), ppv
);
451 static HRESULT WINAPI
RecycleBin_BindToStorage(IShellFolder2
*This
, LPCITEMIDLIST pidl
, LPBC pbc
, REFIID riid
, void **ppv
)
453 FIXME("(%p, %p, %p, %s, %p) - stub\n", This
, pidl
, pbc
, debugstr_guid(riid
), ppv
);
457 static HRESULT WINAPI
RecycleBin_CompareIDs(IShellFolder2
*iface
, LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
459 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
462 TRACE("(%p, %p, %p, %p)\n", This
, (void *)lParam
, pidl1
, pidl2
);
463 if (pidl1
->mkid
.cb
!= pidl2
->mkid
.cb
)
464 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, pidl1
->mkid
.cb
- pidl2
->mkid
.cb
);
465 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (unsigned short)memcmp(pidl1
->mkid
.abID
, pidl2
->mkid
.abID
, pidl1
->mkid
.cb
));
468 static HRESULT WINAPI
RecycleBin_CreateViewObject(IShellFolder2
*iface
, HWND hwndOwner
, REFIID riid
, void **ppv
)
470 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
472 TRACE("(%p, %p, %s, %p)\n", This
, hwndOwner
, debugstr_guid(riid
), ppv
);
475 if (IsEqualGUID(riid
, &IID_IShellView
))
480 ZeroMemory(&sfv
, sizeof(sfv
));
481 sfv
.cbSize
= sizeof(sfv
);
482 sfv
.pshf
= (IShellFolder
*)This
;
484 TRACE("Calling SHCreateShellFolderViewEx\n");
485 ret
= SHCreateShellFolderViewEx(&sfv
, &tmp
);
486 TRACE("Result: %08x, output: %p\n", (unsigned int)ret
, tmp
);
491 return E_NOINTERFACE
;
494 static HRESULT WINAPI
RecycleBin_GetAttributesOf(IShellFolder2
*This
, UINT cidl
, LPCITEMIDLIST
*apidl
,
497 TRACE("(%p, %d, {%p, ...}, {%x})\n", This
, cidl
, apidl
[0], *rgfInOut
);
498 *rgfInOut
&= SFGAO_CANMOVE
|SFGAO_CANDELETE
|SFGAO_HASPROPSHEET
|SFGAO_FILESYSTEM
;
502 static HRESULT WINAPI
RecycleBin_GetUIObjectOf(IShellFolder2
*iface
, HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
*apidl
,
503 REFIID riid
, UINT
*rgfReserved
, void **ppv
)
505 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
507 if(IsEqualGUID(riid
, &IID_IContextMenu
) || IsEqualGUID(riid
, &IID_IContextMenu2
))
509 TRACE("(%p, %p, %d, {%p, ...}, %s, %p, %p)\n", This
, hwndOwner
, cidl
, apidl
[0], debugstr_guid(riid
), rgfReserved
, ppv
);
510 *ppv
= RecycleBinMenu_Constructor(cidl
,apidl
,&(This
->IShellFolder2_iface
));
513 FIXME("(%p, %p, %d, {%p, ...}, %s, %p, %p): stub!\n", iface
, hwndOwner
, cidl
, apidl
[0], debugstr_guid(riid
), rgfReserved
, ppv
);
518 static HRESULT WINAPI
RecycleBin_GetDisplayNameOf(IShellFolder2
*This
, LPCITEMIDLIST pidl
, SHGDNF uFlags
, STRRET
*pName
)
520 WIN32_FIND_DATAW data
;
522 TRACE("(%p, %p, %x, %p)\n", This
, pidl
, uFlags
, pName
);
523 TRASH_UnpackItemID(&pidl
->mkid
, &data
);
524 pName
->uType
= STRRET_WSTR
;
525 pName
->u
.pOleStr
= StrDupW(PathFindFileNameW(data
.cFileName
));
526 if (pName
->u
.pOleStr
== NULL
)
527 return E_OUTOFMEMORY
;
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
*pguid
)
573 static HRESULT WINAPI
RecycleBin_EnumSearches(IShellFolder2
*iface
, IEnumExtraSearch
**ppEnum
)
580 static HRESULT WINAPI
RecycleBin_GetDefaultColumn(IShellFolder2
*iface
, DWORD dwReserved
, ULONG
*pSort
, ULONG
*pDisplay
)
582 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
583 TRACE("(%p, %x, %p, %p)\n", This
, dwReserved
, pSort
, pDisplay
);
589 static HRESULT WINAPI
RecycleBin_GetDefaultColumnState(IShellFolder2
*iface
, UINT iColumn
, SHCOLSTATEF
*pcsFlags
)
591 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
592 TRACE("(%p, %d, %p)\n", This
, iColumn
, pcsFlags
);
593 if (iColumn
>= COLUMNS_COUNT
)
595 *pcsFlags
= RecycleBinColumns
[iColumn
].pcsFlags
;
599 static HRESULT WINAPI
RecycleBin_GetDetailsEx(IShellFolder2
*iface
, LPCITEMIDLIST pidl
, const SHCOLUMNID
*pscid
, VARIANT
*pv
)
605 static HRESULT WINAPI
RecycleBin_GetDetailsOf(IShellFolder2
*iface
, LPCITEMIDLIST pidl
, UINT iColumn
, LPSHELLDETAILS pDetails
)
607 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
608 WIN32_FIND_DATAW data
;
609 WCHAR buffer
[MAX_PATH
];
611 TRACE("(%p, %p, %d, %p)\n", This
, pidl
, iColumn
, pDetails
);
612 if (iColumn
>= COLUMNS_COUNT
)
614 pDetails
->fmt
= RecycleBinColumns
[iColumn
].fmt
;
615 pDetails
->cxChar
= RecycleBinColumns
[iColumn
].cxChars
;
618 pDetails
->str
.uType
= STRRET_WSTR
;
619 LoadStringW(shell32_hInstance
, RecycleBinColumns
[iColumn
].column_name_id
, buffer
, MAX_PATH
);
620 return SHStrDupW(buffer
, &pDetails
->str
.u
.pOleStr
);
623 if (iColumn
== COLUMN_NAME
)
624 return RecycleBin_GetDisplayNameOf(iface
, pidl
, SHGDN_NORMAL
, &pDetails
->str
);
626 TRASH_UnpackItemID(&pidl
->mkid
, &data
);
630 FormatDateTime(buffer
, MAX_PATH
, data
.ftLastAccessTime
);
633 lstrcpyW(buffer
, data
.cFileName
);
634 PathRemoveFileSpecW(buffer
);
637 StrFormatKBSizeW(((LONGLONG
)data
.nFileSizeHigh
<<32)|data
.nFileSizeLow
, buffer
, MAX_PATH
);
640 FormatDateTime(buffer
, MAX_PATH
, data
.ftLastWriteTime
);
650 pDetails
->str
.uType
= STRRET_WSTR
;
651 return SHStrDupW(buffer
, &pDetails
->str
.u
.pOleStr
);
654 static HRESULT WINAPI
RecycleBin_MapColumnToSCID(IShellFolder2
*iface
, UINT iColumn
, SHCOLUMNID
*pscid
)
656 RecycleBin
*This
= impl_from_IShellFolder2(iface
);
657 TRACE("(%p, %d, %p)\n", This
, iColumn
, pscid
);
658 if (iColumn
>=COLUMNS_COUNT
)
660 pscid
->fmtid
= *RecycleBinColumns
[iColumn
].fmtId
;
661 pscid
->pid
= RecycleBinColumns
[iColumn
].pid
;
665 static const IShellFolder2Vtbl recycleBinVtbl
=
668 RecycleBin_QueryInterface
,
673 RecycleBin_ParseDisplayName
,
674 RecycleBin_EnumObjects
,
675 RecycleBin_BindToObject
,
676 RecycleBin_BindToStorage
,
677 RecycleBin_CompareIDs
,
678 RecycleBin_CreateViewObject
,
679 RecycleBin_GetAttributesOf
,
680 RecycleBin_GetUIObjectOf
,
681 RecycleBin_GetDisplayNameOf
,
682 RecycleBin_SetNameOf
,
685 RecycleBin_GetDefaultSearchGUID
,
686 RecycleBin_EnumSearches
,
687 RecycleBin_GetDefaultColumn
,
688 RecycleBin_GetDefaultColumnState
,
689 RecycleBin_GetDetailsEx
,
690 RecycleBin_GetDetailsOf
,
691 RecycleBin_MapColumnToSCID
694 static HRESULT WINAPI
RecycleBin_IPersistFolder2_QueryInterface(IPersistFolder2
*iface
, REFIID riid
,
697 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
699 return RecycleBin_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObject
);
702 static ULONG WINAPI
RecycleBin_IPersistFolder2_AddRef(IPersistFolder2
*iface
)
704 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
706 return RecycleBin_AddRef(&This
->IShellFolder2_iface
);
709 static ULONG WINAPI
RecycleBin_IPersistFolder2_Release(IPersistFolder2
*iface
)
711 RecycleBin
*This
= impl_from_IPersistFolder2(iface
);
713 return RecycleBin_Release(&This
->IShellFolder2_iface
);
716 static const IPersistFolder2Vtbl recycleBinPersistVtbl
=
719 RecycleBin_IPersistFolder2_QueryInterface
,
720 RecycleBin_IPersistFolder2_AddRef
,
721 RecycleBin_IPersistFolder2_Release
,
724 RecycleBin_GetClassID
,
726 RecycleBin_Initialize
,
727 /* IPersistFolder2 */
728 RecycleBin_GetCurFolder
731 static HRESULT WINAPI
RecycleBin_ISFHelper_QueryInterface(ISFHelper
*iface
, REFIID riid
,
734 RecycleBin
*This
= impl_from_ISFHelper(iface
);
736 return RecycleBin_QueryInterface(&This
->IShellFolder2_iface
, riid
, ppvObject
);
739 static ULONG WINAPI
RecycleBin_ISFHelper_AddRef(ISFHelper
*iface
)
741 RecycleBin
*This
= impl_from_ISFHelper(iface
);
743 return RecycleBin_AddRef(&This
->IShellFolder2_iface
);
746 static ULONG WINAPI
RecycleBin_ISFHelper_Release(ISFHelper
*iface
)
748 RecycleBin
*This
= impl_from_ISFHelper(iface
);
750 return RecycleBin_Release(&This
->IShellFolder2_iface
);
753 static HRESULT WINAPI
RecycleBin_GetUniqueName(ISFHelper
*iface
,LPWSTR lpName
,
759 static HRESULT WINAPI
RecycleBin_AddFolder(ISFHelper
* iface
, HWND hwnd
,
761 LPITEMIDLIST
* ppidlOut
)
763 /*Adding folders doesn't make sense in the recycle bin*/
767 static HRESULT
erase_items(HWND parent
,const LPCITEMIDLIST
* apidl
, UINT cidl
, BOOL confirm
)
771 LPITEMIDLIST recyclebin
;
784 WIN32_FIND_DATAW data
;
785 TRASH_UnpackItemID(&((*apidl
)->mkid
),&data
);
786 lstrcpynW(arg
,data
.cFileName
,MAX_PATH
);
787 LoadStringW(shell32_hInstance
,IDS_RECYCLEBIN_ERASEITEM
,message
,
788 sizeof(message
)/sizeof(WCHAR
));
793 static const WCHAR format
[]={'%','u','\0'};
794 LoadStringW(shell32_hInstance
,IDS_RECYCLEBIN_ERASEMULTIPLE
,
795 message
,sizeof(message
)/sizeof(WCHAR
));
796 sprintfW(arg
,format
,cidl
);
801 LoadStringW(shell32_hInstance
,IDS_RECYCLEBIN_ERASE_CAPTION
,caption
,
802 sizeof(caption
)/sizeof(WCHAR
));
803 if(ShellMessageBoxW(shell32_hInstance
,parent
,message
,caption
,
804 MB_YESNO
|MB_ICONEXCLAMATION
,arg
)!=IDYES
)
808 SHGetFolderLocation(parent
,CSIDL_BITBUCKET
,0,0,&recyclebin
);
811 if(SUCCEEDED(TRASH_EraseItem(apidl
[i
])))
812 SHChangeNotify(SHCNE_DELETE
,SHCNF_IDLIST
,
813 ILCombine(recyclebin
,apidl
[i
]),0);
819 static HRESULT WINAPI
RecycleBin_DeleteItems(ISFHelper
* iface
, UINT cidl
,
820 LPCITEMIDLIST
* apidl
)
822 TRACE("(%p,%u,%p)\n",iface
,cidl
,apidl
);
823 return erase_items(GetActiveWindow(),apidl
,cidl
,TRUE
);
826 static HRESULT WINAPI
RecycleBin_CopyItems(ISFHelper
* iface
,
827 IShellFolder
* pSFFrom
,
828 UINT cidl
, LPCITEMIDLIST
* apidl
)
833 static const ISFHelperVtbl sfhelperVtbl
=
835 RecycleBin_ISFHelper_QueryInterface
,
836 RecycleBin_ISFHelper_AddRef
,
837 RecycleBin_ISFHelper_Release
,
838 RecycleBin_GetUniqueName
,
839 RecycleBin_AddFolder
,
840 RecycleBin_DeleteItems
,
844 HRESULT WINAPI
SHQueryRecycleBinA(LPCSTR pszRootPath
, LPSHQUERYRBINFO pSHQueryRBInfo
)
846 WCHAR wszRootPath
[MAX_PATH
];
847 MultiByteToWideChar(CP_ACP
, 0, pszRootPath
, -1, wszRootPath
, MAX_PATH
);
848 return SHQueryRecycleBinW(wszRootPath
, pSHQueryRBInfo
);
851 HRESULT WINAPI
SHQueryRecycleBinW(LPCWSTR pszRootPath
, LPSHQUERYRBINFO pSHQueryRBInfo
)
856 TRACE("(%s, %p)\n", debugstr_w(pszRootPath
), pSHQueryRBInfo
);
857 FIXME("Ignoring pszRootPath=%s\n",debugstr_w(pszRootPath
));
859 TRASH_EnumItems(&apidl
,&cidl
);
860 pSHQueryRBInfo
->i64NumItems
= cidl
;
861 pSHQueryRBInfo
->i64Size
= 0;
864 WIN32_FIND_DATAW data
;
865 TRASH_UnpackItemID(&((apidl
[i
])->mkid
),&data
);
866 pSHQueryRBInfo
->i64Size
+= ((DWORDLONG
)data
.nFileSizeHigh
<< 32) + data
.nFileSizeLow
;
873 HRESULT WINAPI
SHEmptyRecycleBinA(HWND hwnd
, LPCSTR pszRootPath
, DWORD dwFlags
)
875 WCHAR wszRootPath
[MAX_PATH
];
876 MultiByteToWideChar(CP_ACP
, 0, pszRootPath
, -1, wszRootPath
, MAX_PATH
);
877 return SHEmptyRecycleBinW(hwnd
, wszRootPath
, dwFlags
);
880 #define SHERB_NOCONFIRMATION 1
881 #define SHERB_NOPROGRESSUI 2
882 #define SHERB_NOSOUND 4
884 HRESULT WINAPI
SHEmptyRecycleBinW(HWND hwnd
, LPCWSTR pszRootPath
, DWORD dwFlags
)
890 TRACE("(%p, %s, 0x%08x)\n", hwnd
, debugstr_w(pszRootPath
) , dwFlags
);
891 FIXME("Ignoring pszRootPath=%s\n",debugstr_w(pszRootPath
));
892 TRASH_EnumItems(&apidl
,&cidl
);
893 ret
= erase_items(hwnd
,(const LPCITEMIDLIST
*)apidl
,cidl
,!(dwFlags
& SHERB_NOCONFIRMATION
));
900 /*************************************************************************
901 * SHUpdateRecycleBinIcon [SHELL32.@]
905 HRESULT WINAPI
SHUpdateRecycleBinIcon(void)