Skip to content

Commit 950a7f5

Browse files
authored
Merge pull request #3499 from Flow-Launcher/clear_cache_freeze_page
Fix clean cache issue
2 parents f45e6ac + 541e198 commit 950a7f5

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ private bool ClearLogFolder()
186186
{
187187
try
188188
{
189-
dir.Delete(true);
189+
// Log folders are the last level of folders
190+
dir.Delete(recursive: false);
190191
}
191192
catch (Exception e)
192193
{
@@ -214,6 +215,7 @@ private bool ClearCacheFolder()
214215
{
215216
var success = true;
216217
var cacheDirectory = GetCacheDir();
218+
var pluginCacheDirectory = GetPluginCacheDir();
217219
var cacheFiles = GetCacheFiles();
218220

219221
cacheFiles.ForEach(f =>
@@ -229,13 +231,15 @@ private bool ClearCacheFolder()
229231
}
230232
});
231233

232-
cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
234+
// Firstly, delete plugin cache directories
235+
pluginCacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
233236
.ToList()
234237
.ForEach(dir =>
235238
{
236239
try
237240
{
238-
dir.Delete(true);
241+
// Plugin may create directories in its cache directory
242+
dir.Delete(recursive: true);
239243
}
240244
catch (Exception e)
241245
{
@@ -244,6 +248,18 @@ private bool ClearCacheFolder()
244248
}
245249
});
246250

251+
// Then, delete plugin directory
252+
var dir = GetPluginCacheDir();
253+
try
254+
{
255+
dir.Delete(recursive: false);
256+
}
257+
catch (Exception e)
258+
{
259+
App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e);
260+
success = false;
261+
}
262+
247263
OnPropertyChanged(nameof(CacheFolderSize));
248264

249265
return success;
@@ -254,6 +270,11 @@ private static DirectoryInfo GetCacheDir()
254270
return new DirectoryInfo(DataLocation.CacheDirectory);
255271
}
256272

273+
private static DirectoryInfo GetPluginCacheDir()
274+
{
275+
return new DirectoryInfo(DataLocation.PluginCacheDirectory);
276+
}
277+
257278
private static List<FileInfo> GetCacheFiles()
258279
{
259280
return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();

0 commit comments

Comments
 (0)