Skip to content

Commit bfbd8d4

Browse files
committed
Update
1 parent e9fe01f commit bfbd8d4

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,10 @@ public async Task ExecuteAsync(object? parameter = null)
4141
if (await confirmationDialog.TryShowAsync() is not ContentDialogResult.Primary)
4242
return;
4343

44-
//using var sop = new ShellFileOperations { Options = GetDeleteOpFlags(hideUI) };
45-
//HRESULT hr = HRESULT.S_OK;
44+
bool result = await WindowsRecycleBinService.RestoreAllAsync();
4645

47-
try
48-
{
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();
58-
}
59-
catch (Exception)
46+
// Show error dialog when failed
47+
if (!result)
6048
{
6149
var errorDialog = new ContentDialog()
6250
{
@@ -69,17 +57,6 @@ public async Task ExecuteAsync(object? parameter = null)
6957

7058
await errorDialog.TryShowAsync();
7159
}
72-
finally
73-
{
74-
try
75-
{
76-
// Call the undocumented function to reset the icon.
77-
//SHUpdateRecycleBinIcon();
78-
}
79-
catch
80-
{
81-
}
82-
}
8360
}
8461
}
8562
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public interface IWindowsRecycleBinService : ITrashWatcher
1717

1818
Task<bool> DeleteAllAsync();
1919

20-
bool RestoreAll();
20+
Task<bool> RestoreAllAsync();
2121
}
2222
}

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Security.Principal;
55
using Windows.Win32;
6+
using Windows.Win32.Foundation;
67

78
namespace Files.App.Services
89
{
@@ -81,16 +82,52 @@ public async Task<bool> DeleteAllAsync()
8182
PInvoke.SHEmptyRecycleBin(
8283
new(),
8384
string.Empty,
84-
0x00000001 | 0x00000002 /*SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI*/)
85+
0x00000001 | 0x00000002 /* SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI */)
8586
.Succeeded);
8687

8788
return fRes;
8889
}
8990

9091
/// <inheritdoc/>
91-
public bool RestoreAll()
92+
public async Task<bool> RestoreAllAsync()
9293
{
93-
return true;
94+
try
95+
{
96+
bool fRes = await Task.Run(() =>
97+
{
98+
HRESULT hr = (HRESULT)0; /* S_OK */
99+
100+
//using var sop = new ShellFileOperations { Options = GetDeleteOpFlags(hideUI) };
101+
//foreach (var item in deletedItems)
102+
//{
103+
// if (item.Parent != ShellFolderInstance) throw new InvalidOperationException("Unable to restore a ShellItem that is not in the Recycle Bin.");
104+
// // Manually create a ShellFolder instance to the original location.
105+
// using var sf = new ShellFolder(Path.GetDirectoryName(item.Name)!);
106+
// sop.QueueMoveOperation(item, sf, Path.GetFileName(item.Name));
107+
//}
108+
//sop.PerformOperations();
109+
//hr.ThrowIfFailed();
110+
111+
return true;
112+
});
113+
114+
return fRes;
115+
}
116+
catch
117+
{
118+
return false;
119+
}
120+
finally
121+
{
122+
try
123+
{
124+
// Reset the icon.
125+
//Win32PInvoke.SHUpdateRecycleBinIcon();
126+
}
127+
catch
128+
{
129+
}
130+
}
94131
}
95132

96133
/// <inheritdoc/>

0 commit comments

Comments
 (0)