diff --git a/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs b/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs index 1a3d4d4..e9435ca 100644 --- a/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs +++ b/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs @@ -59,39 +59,8 @@ public partial class WhyCacheThoughDialog : UserControl public void ClearCachedMetaData() { - var cachedMetadata = - new DirectoryInfo(DownloadCacheHelper.CachePath).GetFiles("*.json", SearchOption.TopDirectoryOnly); - - var message = "no cached metadata to remove"; - - if (cachedMetadata.Length == 0) - { - AdditionalInfo = message; - AdditionalInfoColor = "dodgerblue"; - Log.Information(message); - return; - } - - var allDeleted = true; - - foreach (var file in cachedMetadata) - { - try - { - file.Delete(); - file.Refresh(); - if (file.Exists) - { - allDeleted = false; - } - } - catch (Exception ex) - { - Log.Error(ex, $"Failed to delete cached metadata file: {file.Name}"); - } - } - - message = allDeleted ? "cached metadata removed" : "some files could not be removed. Check logs"; + var allDeleted = DownloadCacheHelper.ClearMetadataCache(); + var message = allDeleted ? "cached metadata removed" : "some files could not be removed. Check logs"; AdditionalInfo = message; AdditionalInfoColor = allDeleted ? "green" : "red"; Log.Information(message); diff --git a/SPTInstaller/Helpers/DownloadCacheHelper.cs b/SPTInstaller/Helpers/DownloadCacheHelper.cs index 3843030..1666e71 100644 --- a/SPTInstaller/Helpers/DownloadCacheHelper.cs +++ b/SPTInstaller/Helpers/DownloadCacheHelper.cs @@ -42,6 +42,26 @@ public static class DownloadCacheHelper return DirectorySizeHelper.SizeSuffix(cacheSize); } + + + public static bool ClearMetadataCache() + { + var metaData = new DirectoryInfo(CachePath).GetFiles("*.json", SearchOption.TopDirectoryOnly); + var allDeleted = true; + + foreach (var file in metaData) + { + file.Delete(); + file.Refresh(); + + if (file.Exists) + { + allDeleted = false; + } + } + + return allDeleted; + } /// /// Check if a file in the cache already exists