From 35a5e27e2d10f19b1f689e989d4efbf92d28a78f Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 19:15:22 +0800 Subject: [PATCH] Fix DirectoryNotFoundException when deleting cache twice --- .../ViewModels/SettingsPaneAboutViewModel.cs | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 1efc89972..5e24b9dc8 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -231,36 +231,41 @@ public partial class SettingsPaneAboutViewModel : BaseModel } }); - // Firstly, delete plugin cache directories - pluginCacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly) - .ToList() - .ForEach(dir => + // Check if plugin cache directory exists before attempting to delete + // Or it will throw DirectoryNotFoundException in `pluginCacheDirectory.EnumerateDirectories` + if (pluginCacheDirectory.Exists) + { + // Firstly, delete plugin cache directories + pluginCacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly) + .ToList() + .ForEach(dir => + { + try + { + // Plugin may create directories in its cache directory + dir.Delete(recursive: true); + } + catch (Exception e) + { + App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); + success = false; + } + }); + + // Then, delete plugin directory + var dir = pluginCacheDirectory; + try { - try - { - // Plugin may create directories in its cache directory - dir.Delete(recursive: true); - } - catch (Exception e) - { - App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); - success = false; - } - }); + dir.Delete(recursive: false); + } + catch (Exception e) + { + App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); + success = false; + } - // Then, delete plugin directory - var dir = GetPluginCacheDir(); - try - { - dir.Delete(recursive: false); + OnPropertyChanged(nameof(CacheFolderSize)); } - catch (Exception e) - { - App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); - success = false; - } - - OnPropertyChanged(nameof(CacheFolderSize)); return success; }