Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -214,6 +215,7 @@ private bool ClearCacheFolder()
{
var success = true;
var cacheDirectory = GetCacheDir();
var pluginCacheDirectory = GetPluginCacheDir();
var cacheFiles = GetCacheFiles();

cacheFiles.ForEach(f =>
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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<FileInfo> GetCacheFiles()
{
return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();
Expand Down
Loading