Skip to content

Commit fe89937

Browse files
committed
Update
1 parent 59fc68a commit fe89937

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

src/Files.App/Actions/FileSystem/EmptyRecycleBinAction.cs

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Xaml.Controls;
5-
using Vanara.PInvoke;
65
using Windows.Foundation.Metadata;
76

87
namespace Files.App.Actions
@@ -55,19 +54,12 @@ await confirmationDialog.TryShowAsync() is ContentDialogResult.Primary)
5554
{
5655
var banner = StatusCenterHelper.AddCard_EmptyRecycleBin(ReturnResult.InProgress);
5756

58-
bool bResult = await Task.Run(() =>
59-
Shell32.SHEmptyRecycleBin(
60-
IntPtr.Zero,
61-
null,
62-
Shell32.SHERB.SHERB_NOCONFIRMATION | Shell32.SHERB.SHERB_NOPROGRESSUI)
63-
.Succeeded);
57+
bool bResult = await WindowsRecycleBinService.DeleteAllAsync();
6458

6559
StatusCenterViewModel.RemoveItem(banner);
6660

67-
if (bResult)
68-
StatusCenterHelper.AddCard_EmptyRecycleBin(ReturnResult.Success);
69-
else
70-
StatusCenterHelper.AddCard_EmptyRecycleBin(ReturnResult.Failed);
61+
// Post a status based on the result
62+
StatusCenterHelper.AddCard_EmptyRecycleBin(bResult ? ReturnResult.Success : ReturnResult.Failed);
7163
}
7264
}
7365

src/Files.App/Actions/FileSystem/RestoreAllRecycleBinAction.cs

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Xaml.Controls;
5-
using Vanara.Windows.Shell;
65
using Windows.Foundation.Metadata;
76

87
namespace Files.App.Actions
@@ -42,9 +41,20 @@ public async Task ExecuteAsync(object? parameter = null)
4241
if (await confirmationDialog.TryShowAsync() is not ContentDialogResult.Primary)
4342
return;
4443

44+
//using var sop = new ShellFileOperations { Options = GetDeleteOpFlags(hideUI) };
45+
//HRESULT hr = HRESULT.S_OK;
46+
4547
try
4648
{
47-
RecycleBin.RestoreAll();
49+
//foreach (var item in deletedItems)
50+
//{
51+
// if (item.Parent != ShellFolderInstance) throw new InvalidOperationException("Unable to restore a ShellItem that is not in the Recycle Bin.");
52+
// // Manually create a ShellFolder instance to the original location.
53+
// using var sf = new ShellFolder(Path.GetDirectoryName(item.Name)!);
54+
// sop.QueueMoveOperation(item, sf, Path.GetFileName(item.Name));
55+
//}
56+
//sop.PerformOperations();
57+
//hr.ThrowIfFailed();
4858
}
4959
catch (Exception)
5060
{
@@ -59,6 +69,17 @@ public async Task ExecuteAsync(object? parameter = null)
5969

6070
await errorDialog.TryShowAsync();
6171
}
72+
finally
73+
{
74+
try
75+
{
76+
// Call the undocumented function to reset the icon.
77+
//SHUpdateRecycleBinIcon();
78+
}
79+
catch
80+
{
81+
}
82+
}
6283
}
6384
}
6485
}

src/Files.App/Data/Contracts/IWindowsRecycleBinService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IWindowsRecycleBinService : ITrashWatcher
1515

1616
bool HasItems();
1717

18-
bool DeleteAll();
18+
Task<bool> DeleteAllAsync();
1919

2020
bool RestoreAll();
2121
}

src/Files.App/NativeMethods.txt

+1
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ D3D11CreateDevice
7070
IDXGIDevice
7171
DCompositionCreateDevice
7272
IDCompositionDevice
73+
SHEmptyRecycleBin

src/Files.App/Services/Windows/WindowsRecycleBinService.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using System.Security.Principal;
5+
using Windows.Win32;
56

67
namespace Files.App.Services
78
{
@@ -74,9 +75,16 @@ public bool HasItems()
7475
}
7576

7677
/// <inheritdoc/>
77-
public bool DeleteAll()
78+
public async Task<bool> DeleteAllAsync()
7879
{
79-
return true;
80+
bool fRes = await Task.Run(() =>
81+
PInvoke.SHEmptyRecycleBin(
82+
new(),
83+
string.Empty,
84+
0x00000001 | 0x00000002 /*SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI*/)
85+
.Succeeded);
86+
87+
return fRes;
8088
}
8189

8290
/// <inheritdoc/>

0 commit comments

Comments
 (0)