2022-07-02 00:01:40 +00:00
|
|
|
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
|
|
|
}
|
2022-07-02 00:01:40 +00:00
|
|
|
catch (Exception exception)
|
2022-06-22 01:38:42 +00:00
|
|
|
{
|
2022-10-07 22:57:12 +00:00
|
|
|
_logger.LogInformation(exception, "Requesting CESI Information for: {Hash} - Not Found", hash.ToHex());
|
2022-06-22 01:38:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:57:12 +00:00
|
|
|
public Task Put(IndexedVirtualFile file, CancellationToken token)
|
2022-06-22 01:38:42 +00:00
|
|
|
{
|
2022-10-07 22:57:12 +00:00
|
|
|
return Task.CompletedTask;
|
2022-06-22 01:38:42 +00:00
|
|
|
}
|
2022-08-19 23:59:29 +00:00
|
|
|
|
2022-10-07 22:57:12 +00:00
|
|
|
public Task Clean()
|
2022-08-19 23:59:29 +00:00
|
|
|
{
|
2022-10-07 22:57:12 +00:00
|
|
|
return Task.CompletedTask;
|
2022-08-19 23:59:29 +00:00
|
|
|
}
|
2022-06-22 01:38:42 +00:00
|
|
|
}
|