mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix DirectoryNotFoundException when deleting cache twice
This commit is contained in:
parent
820304ce19
commit
35a5e27e2d
1 changed files with 32 additions and 27 deletions
|
|
@ -231,36 +231,41 @@ public partial class SettingsPaneAboutViewModel : BaseModel
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Firstly, delete plugin cache directories
|
// Check if plugin cache directory exists before attempting to delete
|
||||||
pluginCacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
|
// Or it will throw DirectoryNotFoundException in `pluginCacheDirectory.EnumerateDirectories`
|
||||||
.ToList()
|
if (pluginCacheDirectory.Exists)
|
||||||
.ForEach(dir =>
|
{
|
||||||
|
// 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
|
dir.Delete(recursive: false);
|
||||||
{
|
}
|
||||||
// Plugin may create directories in its cache directory
|
catch (Exception e)
|
||||||
dir.Delete(recursive: true);
|
{
|
||||||
}
|
App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e);
|
||||||
catch (Exception e)
|
success = false;
|
||||||
{
|
}
|
||||||
App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e);
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Then, delete plugin directory
|
OnPropertyChanged(nameof(CacheFolderSize));
|
||||||
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;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue