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 1/3] 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 1efc8997204..5e24b9dc8ee 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -231,36 +231,41 @@ private bool ClearCacheFolder() } }); - // 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) + // 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 => { - App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); - success = false; - } - }); + 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 + { + 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; } From ec182ade398544605da0a90bc7afadf65ef575be Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 19:18:11 +0800 Subject: [PATCH 2/3] Fix property changed event --- .../SettingPages/ViewModels/SettingsPaneAboutViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 5e24b9dc8ee..7a6a1d91bec 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -263,10 +263,10 @@ private bool ClearCacheFolder() App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); success = false; } - - OnPropertyChanged(nameof(CacheFolderSize)); } + OnPropertyChanged(nameof(CacheFolderSize)); + return success; } From 4bea4101a1c5a7e13f8befa7ef33b0bafe98e1e7 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 18 Sep 2025 21:40:37 +1000 Subject: [PATCH 3/3] add comment for cache folder size refresh event --- .../SettingPages/ViewModels/SettingsPaneAboutViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 7a6a1d91bec..647b367013c 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -265,6 +265,7 @@ private bool ClearCacheFolder() } } + // Raise regardless to cover scenario where size needs to be recalculated if the folder is manually removed on disk. OnPropertyChanged(nameof(CacheFolderSize)); return success;