Skip to content

Commit dcff960

Browse files
authored
Fix: Fixed potential crash when restoring from Recycle Bin (#13902)
1 parent f7fa6fa commit dcff960

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3605,4 +3605,7 @@
36053605
<data name="OpenOnStartupDisabled" xml:space="preserve">
36063606
<value>The option to open Files on Windows Startup is not available due to your system settings or group policy. To re-enable, open the startup page in Task Manager.</value>
36073607
</data>
3608+
<data name="FailedToRestore" xml:space="preserve">
3609+
<value>Failed to restore items from Recycle Bin</value>
3610+
</data>
36083611
</root>

src/Files.App/Utils/RecycleBin/RecycleBinHelpers.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ await ConfirmEmptyBinDialog.TryShowAsync() == ContentDialogResult.Primary)
7979

8080
public static async Task RestoreRecycleBinAsync()
8181
{
82-
var ConfirmEmptyBinDialog = new ContentDialog()
82+
var confirmEmptyBinDialog = new ContentDialog()
8383
{
8484
Title = "ConfirmRestoreBinDialogTitle".GetLocalizedResource(),
8585
Content = "ConfirmRestoreBinDialogContent".GetLocalizedResource(),
@@ -88,11 +88,30 @@ public static async Task RestoreRecycleBinAsync()
8888
DefaultButton = ContentDialogButton.Primary
8989
};
9090

91-
ContentDialogResult result = await ConfirmEmptyBinDialog.TryShowAsync();
91+
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
92+
confirmEmptyBinDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;
93+
94+
ContentDialogResult result = await confirmEmptyBinDialog.TryShowAsync();
9295

9396
if (result == ContentDialogResult.Primary)
9497
{
95-
Vanara.Windows.Shell.RecycleBin.RestoreAll();
98+
try
99+
{
100+
Vanara.Windows.Shell.RecycleBin.RestoreAll();
101+
}
102+
catch (Exception)
103+
{
104+
var errorDialog = new ContentDialog()
105+
{
106+
Title = "FailedToRestore".GetLocalizedResource(),
107+
PrimaryButtonText = "OK".GetLocalizedResource(),
108+
};
109+
110+
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
111+
errorDialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;
112+
113+
await errorDialog.TryShowAsync();
114+
}
96115
}
97116
}
98117

0 commit comments

Comments
 (0)