Skip to content

Fix: Fixed potential crash when opening properties for recent files #14535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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