File tree 3 files changed +44
-30
lines changed 3 files changed +44
-30
lines changed Original file line number Diff line number Diff line change @@ -41,22 +41,10 @@ public async Task ExecuteAsync(object? parameter = null)
41
41
if ( await confirmationDialog . TryShowAsync ( ) is not ContentDialogResult . Primary )
42
42
return ;
43
43
44
- //using var sop = new ShellFileOperations { Options = GetDeleteOpFlags(hideUI) };
45
- //HRESULT hr = HRESULT.S_OK;
44
+ bool result = await WindowsRecycleBinService . RestoreAllAsync ( ) ;
46
45
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 )
60
48
{
61
49
var errorDialog = new ContentDialog ( )
62
50
{
@@ -69,17 +57,6 @@ public async Task ExecuteAsync(object? parameter = null)
69
57
70
58
await errorDialog . TryShowAsync ( ) ;
71
59
}
72
- finally
73
- {
74
- try
75
- {
76
- // Call the undocumented function to reset the icon.
77
- //SHUpdateRecycleBinIcon();
78
- }
79
- catch
80
- {
81
- }
82
- }
83
60
}
84
61
}
85
62
}
Original file line number Diff line number Diff line change @@ -17,6 +17,6 @@ public interface IWindowsRecycleBinService : ITrashWatcher
17
17
18
18
Task < bool > DeleteAllAsync ( ) ;
19
19
20
- bool RestoreAll ( ) ;
20
+ Task < bool > RestoreAllAsync ( ) ;
21
21
}
22
22
}
Original file line number Diff line number Diff line change 3
3
4
4
using System . Security . Principal ;
5
5
using Windows . Win32 ;
6
+ using Windows . Win32 . Foundation ;
6
7
7
8
namespace Files . App . Services
8
9
{
@@ -81,16 +82,52 @@ public async Task<bool> DeleteAllAsync()
81
82
PInvoke . SHEmptyRecycleBin (
82
83
new ( ) ,
83
84
string . Empty ,
84
- 0x00000001 | 0x00000002 /*SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI*/ )
85
+ 0x00000001 | 0x00000002 /* SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI */ )
85
86
. Succeeded ) ;
86
87
87
88
return fRes ;
88
89
}
89
90
90
91
/// <inheritdoc/>
91
- public bool RestoreAll ( )
92
+ public async Task < bool > RestoreAllAsync ( )
92
93
{
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
+ }
94
131
}
95
132
96
133
/// <inheritdoc/>
You can’t perform that action at this time.
0 commit comments