2021-09-27 12:42:46 +00:00
|
|
|
using System.CommandLine;
|
|
|
|
using System.CommandLine.Invocation;
|
2022-09-29 05:10:49 +00:00
|
|
|
using System.CommandLine.NamingConventionBinder;
|
2021-09-27 12:42:46 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
2020-06-20 22:51:47 +00:00
|
|
|
using System.Threading.Tasks;
|
2021-09-27 12:42:46 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-14 22:08:21 +00:00
|
|
|
using Wabbajack.CLI.Builder;
|
2021-09-27 12:42:46 +00:00
|
|
|
using Wabbajack.Hashing.xxHash64;
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
using Wabbajack.Paths.IO;
|
2020-06-20 22:51:47 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
2022-10-14 22:08:21 +00:00
|
|
|
public class HashFile
|
2020-06-20 22:51:47 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
private readonly ILogger<HashFile> _logger;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public HashFile(ILogger<HashFile> logger)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2022-10-01 01:35:36 +00:00
|
|
|
public static VerbDefinition Definition = new VerbDefinition("hash-file",
|
|
|
|
"Hashes a file with Wabbajack's hashing routines", new[]
|
|
|
|
{
|
|
|
|
new OptionDefinition(typeof(AbsolutePath), "i", "input", "Path to the file to hash")
|
|
|
|
});
|
2020-06-20 22:51:47 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public async Task<int> Run(AbsolutePath input)
|
|
|
|
{
|
|
|
|
await using var istream = input.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
var hash = await istream.HashingCopy(Stream.Null, CancellationToken.None);
|
|
|
|
_logger.LogInformation($"{input} hash: {hash} {hash.ToHex()} {(long) hash}");
|
|
|
|
return 0;
|
2020-06-20 22:51:47 +00:00
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|