-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (51 loc) · 1.65 KB
/
Program.cs
File metadata and controls
60 lines (51 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Parsing;
using System.Security.Cryptography;
using Serilog;
namespace ModShardChecksum;
internal static class Program
{
public static void MainCommand(string filename)
{
if (Path.GetExtension(filename) != ".win")
{
Log.Error(
"A .win file was expected, got {{{0}}} instead",
filename
);
return;
}
using MD5 md5 = MD5.Create();
using FileStream stream = File.OpenRead(filename);
string hash = Convert.ToHexString(md5.ComputeHash(stream));
Log.Information("Hash: {{{0}}}", hash);
}
static async Task Main(string[] args)
{
// create File and Console (controlledby a switch) sinks
LoggerConfiguration logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console();
Log.Logger = logger.CreateLogger();
Option<string> nameOption = new("--file")
{
Description = "Name of the output.",
IsRequired = true
};
nameOption.AddAlias("-f");
RootCommand rootCommand = new("Computing the checksum of file.")
{
nameOption,
};
rootCommand.SetHandler(MainCommand, nameOption);
CommandLineBuilder commandLineBuilder = new(rootCommand);
commandLineBuilder.AddMiddleware(async (context, next) =>
{
await next(context);
});
commandLineBuilder.UseDefaults();
Parser parser = commandLineBuilder.Build();
await parser.InvokeAsync(args);
}
}