wabbajack/Wabbajack.Common/FileSignatures/Signatures.tt

55 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#
2020-09-02 22:14:56 +00:00
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();
}
2021-10-23 16:51:17 +00:00
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(".", ""),
2021-09-27 12:42:46 +00:00
Sig = row[1].Trim().Split(' ').Select(b => "0x" + b),
Description = row[0]
}));
2021-09-27 12:42:46 +00:00
#>
namespace Wabbajack.Common.FileSignatures {
2021-09-27 12:42:46 +00:00
public enum FileType { <#
foreach (var nrow in rows.Select(r => r.EnumName).Distinct().OrderBy(r => r))
{
#>
<#= nrow #>,
2021-09-27 12:42:46 +00:00
<#
}
2021-09-27 12:42:46 +00:00
#>
}
public static class Definitions {
public static (FileType, byte[])[] Signatures = {
<#
2021-09-27 12:42:46 +00:00
foreach (var row in rows)
{
2021-09-27 12:42:46 +00:00
#>
// <#= row.Description #>
2021-09-27 12:42:46 +00:00
(FileType.<#= row.EnumName #>, new byte[] {<#= string.Join(", ", row.Sig) #>}),
<#
}
#>
};}}