From 14ffe3c6757f086dc4fbd360caa4f70801ad82d2 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 5 Jun 2025 11:38:08 +0800 Subject: [PATCH] Handle more exceptions --- .../Views/PreviewPanel.xaml.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs index e4a9e5bb2..5c0832871 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs @@ -107,6 +107,16 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged var fileInfo = new FileInfo(filePath); return ResultManager.ToReadableSize(fileInfo.Length, 2); } + catch (FileNotFoundException) + { + Main.Context.API.LogError(ClassName, $"File not found: {filePath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } + catch (UnauthorizedAccessException) + { + Main.Context.API.LogError(ClassName, $"Access denied to file: {filePath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } catch (Exception e) { Main.Context.API.LogException(ClassName, $"Failed to get file size for {filePath}", e); @@ -128,6 +138,16 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged if (showFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}"; return result; } + catch (FileNotFoundException) + { + Main.Context.API.LogError(ClassName, $"File not found: {filePath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } + catch (UnauthorizedAccessException) + { + Main.Context.API.LogError(ClassName, $"Access denied to file: {filePath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } catch (Exception e) { Main.Context.API.LogException(ClassName, $"Failed to get file created date for {filePath}", e); @@ -149,6 +169,16 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged if (showFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}"; return result; } + catch (FileNotFoundException) + { + Main.Context.API.LogError(ClassName, $"File not found: {filePath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } + catch (UnauthorizedAccessException) + { + Main.Context.API.LogError(ClassName, $"Access denied to file: {filePath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } catch (Exception e) { Main.Context.API.LogException(ClassName, $"Failed to get file modified date for {filePath}", e); @@ -171,6 +201,16 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged return ResultManager.ToReadableSize(size, 2); } + catch (FileNotFoundException) + { + Main.Context.API.LogError(ClassName, $"Folder not found: {folderPath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } + catch (UnauthorizedAccessException) + { + Main.Context.API.LogError(ClassName, $"Access denied to folder: {folderPath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } catch (OperationCanceledException) { Main.Context.API.LogError(ClassName, $"Operation timed out while calculating folder size for {folderPath}"); @@ -197,6 +237,16 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged if (showFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}"; return result; } + catch (FileNotFoundException) + { + Main.Context.API.LogError(ClassName, $"Folder not found: {folderPath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } + catch (UnauthorizedAccessException) + { + Main.Context.API.LogError(ClassName, $"Access denied to folder: {folderPath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } catch (Exception e) { Main.Context.API.LogException(ClassName, $"Failed to get folder created date for {folderPath}", e); @@ -218,6 +268,16 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged if (showFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}"; return result; } + catch (FileNotFoundException) + { + Main.Context.API.LogError(ClassName, $"Folder not found: {folderPath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } + catch (UnauthorizedAccessException) + { + Main.Context.API.LogError(ClassName, $"Access denied to folder: {folderPath}"); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } catch (Exception e) { Main.Context.API.LogException(ClassName, $"Failed to get folder modified date for {folderPath}", e);