diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 231d14d5551..00f40b00957 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -186,7 +186,8 @@ private bool ClearLogFolder() { try { - dir.Delete(true); + // Log folders are the last level of folders + dir.Delete(recursive: false); } catch (Exception e) { @@ -214,6 +215,7 @@ private bool ClearCacheFolder() { var success = true; var cacheDirectory = GetCacheDir(); + var pluginCacheDirectory = GetPluginCacheDir(); var cacheFiles = GetCacheFiles(); cacheFiles.ForEach(f => @@ -229,13 +231,15 @@ private bool ClearCacheFolder() } }); - cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly) + // Firstly, delete plugin cache directories + pluginCacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly) .ToList() .ForEach(dir => { try { - dir.Delete(true); + // Plugin may create directories in its cache directory + dir.Delete(recursive: true); } catch (Exception e) { @@ -244,6 +248,18 @@ private bool ClearCacheFolder() } }); + // Then, delete plugin directory + var dir = GetPluginCacheDir(); + try + { + dir.Delete(recursive: false); + } + catch (Exception e) + { + App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e); + success = false; + } + OnPropertyChanged(nameof(CacheFolderSize)); return success; @@ -254,6 +270,11 @@ private static DirectoryInfo GetCacheDir() return new DirectoryInfo(DataLocation.CacheDirectory); } + private static DirectoryInfo GetPluginCacheDir() + { + return new DirectoryInfo(DataLocation.PluginCacheDirectory); + } + private static List GetCacheFiles() { return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();