Skip to content

Commit

Permalink
Fix: Fixed potential crash when opening properties for recent files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Jan 24, 2024
1 parent 46c0f2b commit ee80ce7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@
<data name="FileNotFoundDialog.Text" xml:space="preserve">
<value>The file you are attempting to access may have been moved or deleted.</value>
</data>
<data name="CannotAccessPropertiesTitle" xml:space="preserve">
<value>Cannot open properties for this file</value>
</data>
<data name="CannotAccessPropertiesContent" xml:space="preserve">
<value>The file you are attempting to access may have been moved or deleted.</value>
</data>
<data name="FileNotFoundDialog.Title" xml:space="preserve">
<value>File Not Found</value>
</data>
Expand Down
24 changes: 22 additions & 2 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Specialized;
using System.IO;
using System.Runtime.CompilerServices;
using Windows.Foundation.Metadata;
using Windows.System;

namespace Files.App.UserControls.Widgets
Expand Down Expand Up @@ -247,8 +248,27 @@ private void OpenProperties(RecentItem item)
flyoutClosed = async (s, e) =>
{
flyout!.Closed -= flyoutClosed;
var listedItem = await UniversalStorageEnumerator.AddFileAsync(await BaseStorageFile.GetFileFromPathAsync(item.Path), null, default);
FilePropertiesHelpers.OpenPropertiesWindow(listedItem, associatedInstance);

BaseStorageFile file = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(item.Path));
if (file is null)
{
ContentDialog dialog = new()
{
Title = "CannotAccessPropertiesTitle".GetLocalizedResource(),
Content = "CannotAccessPropertiesContent".GetLocalizedResource(),
PrimaryButtonText = "Ok".GetLocalizedResource()
};

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
dialog.XamlRoot = MainWindow.Instance.Content.XamlRoot;

await dialog.TryShowAsync();
}
else
{
var listedItem = await UniversalStorageEnumerator.AddFileAsync(file, null, default);
FilePropertiesHelpers.OpenPropertiesWindow(listedItem, associatedInstance);
}
};
flyout!.Closed += flyoutClosed;
}
Expand Down

0 comments on commit ee80ce7

Please sign in to comment.