2021-10-13 03:59:54 +00:00
|
|
|
|
using Wabbajack.Downloaders.Interfaces;
|
|
|
|
|
using Wabbajack.DTOs;
|
|
|
|
|
using Wabbajack.DTOs.DownloadStates;
|
|
|
|
|
using Wabbajack.DTOs.Validation;
|
|
|
|
|
using Wabbajack.Hashing.xxHash64;
|
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
|
using Wabbajack.Paths.IO;
|
|
|
|
|
using Wabbajack.RateLimiter;
|
|
|
|
|
using Wabbajack.VFS;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Downloaders.GameFile;
|
|
|
|
|
|
|
|
|
|
public class GameFileDownloader : ADownloader<GameFileSource>
|
|
|
|
|
{
|
|
|
|
|
private readonly FileHashCache _hashCache;
|
2021-10-23 16:51:17 +00:00
|
|
|
|
private readonly IGameLocator _locator;
|
2021-10-13 03:59:54 +00:00
|
|
|
|
|
|
|
|
|
public GameFileDownloader(IGameLocator locator, FileHashCache hashCache)
|
|
|
|
|
{
|
|
|
|
|
_locator = locator;
|
|
|
|
|
_hashCache = hashCache;
|
|
|
|
|
}
|
2021-10-23 16:51:17 +00:00
|
|
|
|
|
|
|
|
|
public override Priority Priority => Priority.Normal;
|
|
|
|
|
|
|
|
|
|
public override Task<Hash> Download(Archive archive, GameFileSource state, AbsolutePath destination, IJob job,
|
|
|
|
|
CancellationToken token)
|
2021-10-13 03:59:54 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task<bool> Prepare()
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDownloadState? Resolve(IReadOnlyDictionary<string, string> iniData)
|
|
|
|
|
{
|
|
|
|
|
if (!iniData.TryGetValue("gameName", out var gameName) || !iniData.TryGetValue("gameFile", out var gameFile) ||
|
|
|
|
|
!GameRegistry.TryGetByFuzzyName(gameName, out var game)) return null;
|
|
|
|
|
|
|
|
|
|
return new GameFileSource
|
|
|
|
|
{
|
|
|
|
|
Game = game.Game,
|
|
|
|
|
GameFile = gameFile.ToRelativePath()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
|
public override async Task<bool> Verify(Archive archive, GameFileSource archiveState, IJob job,
|
|
|
|
|
CancellationToken token)
|
2021-10-13 03:59:54 +00:00
|
|
|
|
{
|
|
|
|
|
var fp = archiveState.GameFile.RelativeTo(_locator.GameLocation(archiveState.Game));
|
|
|
|
|
if (!fp.FileExists()) return false;
|
|
|
|
|
return await _hashCache.FileHashCachedAsync(fp, token) == archive.Hash;
|
|
|
|
|
}
|
2021-10-23 16:51:17 +00:00
|
|
|
|
|
2021-10-13 03:59:54 +00:00
|
|
|
|
public override IEnumerable<string> MetaIni(Archive a, GameFileSource state)
|
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
$"gameName={state.Game}",
|
|
|
|
|
$"gameFile={state.GameFile}"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|