wabbajack/Wabbajack.Common/FileSignatures/Signatures.tt
2020-09-02 16:14:56 -06:00

54 lines
1.5 KiB
Plaintext

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Text" #>
<#@ 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 string[] {"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 static class Definitions {
public enum FileType { <#
foreach (var nrow in rows.Select(r => r.EnumName).Distinct().OrderBy(r => r)) {
#>
<#= nrow #>,
<#} #>
}
public static (FileType, byte[])[] Signatures = {
<#
foreach (var row in rows)
{
#>
// <#= row.Description #>
(FileType.<#=row.EnumName #>, new byte[] {<#= string.Join(", ", row.Sig)#>}),
<#
}
#>
};}}