mirror of
https://github.com/sp-tarkov/installer.git
synced 2025-02-12 15:50:45 -05:00
add clear metadata cache method to download cache helper
This commit is contained in:
parent
df6a60286b
commit
9517625487
@ -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);
|
||||
|
@ -43,6 +43,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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a file in the cache already exists
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user