wabbajack/Wabbajack.Networking.WabbajackClientApi/CesiVFSCache.cs

57 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Net.Http;
2022-06-22 01:38:42 +00:00
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
2022-07-11 20:55:54 +00:00
using Wabbajack.Common;
using Wabbajack.DTOs.Streams;
2022-06-22 01:38:42 +00:00
using Wabbajack.DTOs.Vfs;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Networking.Http;
2022-07-11 20:55:54 +00:00
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
2022-06-22 01:38:42 +00:00
using Wabbajack.VFS.Interfaces;
namespace Wabbajack.Networking.WabbajackClientApi;
public class CesiVFSCache : IVfsCache
{
private readonly Client _client;
private readonly ILogger<CesiVFSCache> _logger;
2022-07-11 20:55:54 +00:00
private const int Threshold = 1024 * 1024 * 128;
2022-06-22 01:38:42 +00:00
public CesiVFSCache(ILogger<CesiVFSCache> logger, Client client)
{
_logger = logger;
_client = client;
}
2022-07-11 20:55:54 +00:00
public async Task<IndexedVirtualFile?> Get(Hash hash, IStreamFactory sf, CancellationToken token)
2022-06-22 01:38:42 +00:00
{
2022-07-11 20:55:54 +00:00
if (sf is not NativeFileStreamFactory nf)
return null;
if (nf.FullPath.Size() < Threshold) return null;
2022-06-22 01:38:42 +00:00
try
{
2022-06-27 18:55:34 +00:00
var result = await _client.GetCesiVfsEntry(hash, token);
_logger.LogInformation("Requesting CESI Information for: {Hash} - Found", hash.ToHex());
return result;
2022-06-22 01:38:42 +00:00
}
catch (Exception exception)
2022-06-22 01:38:42 +00:00
{
2022-06-27 18:55:34 +00:00
_logger.LogInformation("Requesting CESI Information for: {Hash} - Not Found", hash.ToHex());
2022-06-22 01:38:42 +00:00
return null;
}
}
public async Task Put(IndexedVirtualFile file, CancellationToken token)
{
return;
}
2022-08-19 23:59:29 +00:00
public async Task Clean()
{
return;
}
2022-06-22 01:38:42 +00:00
}