0
0
mirror of https://github.com/sp-tarkov/installer.git synced 2025-02-12 16:10:45 -05:00

add clear metadata cache method to download cache helper

This commit is contained in:
IsWaffle 2025-01-03 15:09:26 -05:00
parent df6a60286b
commit 9517625487
2 changed files with 22 additions and 33 deletions

View File

@ -59,39 +59,8 @@ public partial class WhyCacheThoughDialog : UserControl
public void ClearCachedMetaData() public void ClearCachedMetaData()
{ {
var cachedMetadata = var allDeleted = DownloadCacheHelper.ClearMetadataCache();
new DirectoryInfo(DownloadCacheHelper.CachePath).GetFiles("*.json", SearchOption.TopDirectoryOnly); var message = allDeleted ? "cached metadata removed" : "some files could not be removed. Check logs";
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";
AdditionalInfo = message; AdditionalInfo = message;
AdditionalInfoColor = allDeleted ? "green" : "red"; AdditionalInfoColor = allDeleted ? "green" : "red";
Log.Information(message); Log.Information(message);

View File

@ -42,6 +42,26 @@ public static class DownloadCacheHelper
return DirectorySizeHelper.SizeSuffix(cacheSize); 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;
}
/// <summary> /// <summary>
/// Check if a file in the cache already exists /// Check if a file in the cache already exists