Skip to content

Commit 9236263

Browse files
committed
C#: Validate dbdf/dbde files
1 parent a805107 commit 9236263

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

code/C#/DBDefsValidator/Program.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DBDefsLib;
2+
using DBDefsLib.Constants;
23
using DBDefsLib.Structs;
34
using System;
45
using System.Collections.Generic;
@@ -209,8 +210,6 @@ static void Main(string[] args)
209210

210211
foreach (var mapping in mappings)
211212
{
212-
// TODO: Enum/flag file validation
213-
214213
if (!definitionCache.TryGetValue(mapping.tableName, out var dbDef))
215214
{
216215
errorEncountered.Add(mapping.tableName);
@@ -226,6 +225,36 @@ static void Main(string[] args)
226225
Console.ResetColor();
227226
}
228227

228+
if (mapping.meta == MetaType.COLOR)
229+
continue;
230+
231+
// Flags without file definitions are allowed
232+
if (string.IsNullOrEmpty(mapping.metaValue))
233+
continue;
234+
235+
var dir = mapping.meta == MetaType.ENUM ? "enums" : "flags";
236+
var ext = mapping.meta == MetaType.ENUM ? ".dbde" : ".dbdf";
237+
var path = Path.Combine(metaDirectory, dir, $"{mapping.metaValue}{ext}");
238+
239+
if (File.Exists(path))
240+
{
241+
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
242+
{
243+
try
244+
{
245+
var dbdeReader = new DBDEnumReader();
246+
var enumDef = dbdeReader.Read(fs, mapping.meta);
247+
}
248+
catch (Exception ex)
249+
{
250+
errorEncountered.Add(mapping.metaValue);
251+
Console.ForegroundColor = ConsoleColor.Red;
252+
Console.WriteLine($"Failed to read {mapping.metaValue} for mapping {mapping.tableName}::{mapping.columnName}: " + ex);
253+
Console.ResetColor();
254+
}
255+
}
256+
}
257+
229258
// TODO: Conditional table/column validation
230259
}
231260
}

0 commit comments

Comments
 (0)