wabbajack/Wabbajack.Common/FileSignatures/Signatures.tt
2022-02-11 17:47:02 -07:00

55 lines
1.4 KiB
Plaintext

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#
byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
var files = new[] {"bsasigs.txt", "file_sigs_RAW.txt"};
var digits = new HashSet<char>("0123456789".ToArray());
var rows = files
.SelectMany(file => File.ReadAllLines(Path.Combine("./Definitions/", file)))
.Select(row => row.Split(','))
.SelectMany(row => row[2].Split('|').Select(e => new
{
EnumName = (digits.Contains(e.First()) ? "_" + e : e).Replace(".", ""),
Sig = row[1].Trim().Split(' ').Select(b => "0x" + b),
Description = row[0]
}));
#>
namespace Wabbajack.Common.FileSignatures {
public enum FileType { <#
foreach (var nrow in rows.Select(r => r.EnumName).Distinct().OrderBy(r => r))
{
#>
<#= nrow #>,
<#
}
#>
}
public static class Definitions {
public static (FileType, byte[])[] Signatures = {
<#
foreach (var row in rows)
{
#>
// <#= row.Description #>
(FileType.<#= row.EnumName #>, new byte[] {<#= string.Join(", ", row.Sig) #>}),
<#
}
#>
};}}