From d40367a860f086e8435f9fc2cda1189fc51c10ae Mon Sep 17 00:00:00 2001 From: Ani <115020168+drawbyperpetual@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:46:20 +0200 Subject: [PATCH] [FileLocksmith]Show process files in modal dialog to fix crash (#33804) ## Summary of the Pull Request To prevent a crash, show the individual files of a process within a modal dialog rather than as inline text. Please see the linked issue for more details. ## Detailed Description of the Pull Request / Additional comments - Removed inline list of process files. - Added "Show files" button to expander to show list of process files as a modal dialog. This dialog has the same design as the one used to display the list of selected folders within the same application. - Added unhandled exception hander to application similar to our other applications. ![image](https://github.com/user-attachments/assets/52eddfcc-5e10-40a3-94b2-68bbfb607f1d) ![image](https://github.com/user-attachments/assets/ff996e32-36f6-41a9-a9f0-6dda7a93d09a) --- .../FileLocksmithXAML/App.xaml.cs | 7 +++++ .../FileLocksmithXAML/Views/MainPage.xaml | 27 +++++++++---------- .../FileLocksmithXAML/Views/MainPage.xaml.cs | 12 ++++++++- .../Strings/en-us/Resources.resw | 11 ++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs index 15312c5969..63d2c27c20 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs @@ -25,6 +25,8 @@ namespace FileLocksmithUI Logger.InitializeLogger("\\File Locksmith\\FileLocksmithUI\\Logs"); this.InitializeComponent(); + + UnhandledException += App_UnhandledException; } /// @@ -55,6 +57,11 @@ namespace FileLocksmithUI _window.Activate(); } + private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) + { + Logger.LogError("Unhandled exception", e.Exception); + } + private Window _window; } } diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml index 697858f8f9..472318a93a 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml @@ -141,27 +141,16 @@ IsTextSelectionEnabled="True" Text="{x:Bind user}" /> - + - - - - - - - + @@ -200,5 +189,13 @@ Text="{x:Bind ViewModel.PathsToString, Mode=OneWay}" TextWrapping="Wrap" /> + + + + + diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs index 6a98692941..a1bab74f42 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System; +using FileLocksmith.Interop; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using PowerToys.FileLocksmithUI.ViewModels; @@ -19,9 +21,17 @@ namespace PowerToys.FileLocksmithUI.Views DataContext = ViewModel; } - private async void ShowSelectedPathsButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) + private async void ShowSelectedPathsButton_Click(object sender, RoutedEventArgs e) { await SelectedFilesListDialog.ShowAsync(); } + + private async void ShowProcessFiles_Click(object sender, RoutedEventArgs e) + { + var processResult = (ProcessResult)((FrameworkElement)sender).DataContext; + ProcessFilesListDialogTextBlock.Text = string.Join(Environment.NewLine, processResult.files); + + await ProcessFilesListDialog.ShowAsync(); + } } } diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Strings/en-us/Resources.resw b/src/modules/FileLocksmith/FileLocksmithUI/Strings/en-us/Resources.resw index 2b56f59919..12f5278295 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Strings/en-us/Resources.resw +++ b/src/modules/FileLocksmith/FileLocksmithUI/Strings/en-us/Resources.resw @@ -130,6 +130,13 @@ Files + + Files + + + Close + As in, close a dialog prompt. + Click to see the entire list of paths. Paths as in file paths that were selected for the utility to check. @@ -164,4 +171,8 @@ Administrator: File Locksmith Title of the window when running as administrator. + + Show files + Show files for the selected process + \ No newline at end of file