mirror of
https://github.com/araxiaonline/WoWDBDefs.git
synced 2026-06-13 11:42:48 -04:00
105 lines
4.0 KiB
C#
105 lines
4.0 KiB
C#
using DBDefsLib;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using static DBDefsLib.Structs;
|
|
|
|
namespace DBDefsTest
|
|
{
|
|
class Program
|
|
{
|
|
public static Dictionary<string, DBDefinition> definitionCache = new Dictionary<string, DBDefinition>();
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
if (args.Length < 1)
|
|
{
|
|
Console.WriteLine("Usage: <definitionsdir>");
|
|
Environment.Exit(1);
|
|
}
|
|
|
|
var definitionDir = args[0];
|
|
|
|
var rewrite = false;
|
|
var verbose = true;
|
|
|
|
if (args.Length >= 2 && args[1] == "true")
|
|
rewrite = true;
|
|
if (args.Length >= 3 && args[2] == "false")
|
|
verbose = false;
|
|
|
|
var errorEncountered = new List<string>();
|
|
|
|
foreach (var file in Directory.GetFiles(definitionDir))
|
|
{
|
|
var dbName = Path.GetFileNameWithoutExtension(file);
|
|
|
|
var reader = new DBDReader();
|
|
try
|
|
{
|
|
definitionCache.Add(dbName, reader.Read(file, true));
|
|
|
|
if (verbose)
|
|
Console.WriteLine("Read " + definitionCache[dbName].versionDefinitions.Length + " versions and " + definitionCache[dbName].columnDefinitions.Count + " columns for " + dbName);
|
|
|
|
if (rewrite)
|
|
{
|
|
var writer = new DBDWriter();
|
|
writer.Save(definitionCache[dbName], Path.Combine(definitionDir, dbName + ".dbd"));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorEncountered.Add(dbName);
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("Failed to read " + dbName + ": " + ex);
|
|
Console.ResetColor();
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Read " + definitionCache.Count + " database definitions!");
|
|
|
|
var foreignKeys = 0;
|
|
foreach (var definition in definitionCache)
|
|
{
|
|
foreach (var columnDefinition in definition.Value.columnDefinitions)
|
|
{
|
|
if (!string.IsNullOrEmpty(columnDefinition.Value.foreignTable) || !string.IsNullOrEmpty(columnDefinition.Value.foreignColumn))
|
|
{
|
|
if (definitionCache.ContainsKey(columnDefinition.Value.foreignTable) && definitionCache[columnDefinition.Value.foreignTable].columnDefinitions.ContainsKey(columnDefinition.Value.foreignColumn))
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
//Console.WriteLine(definition.Key + "." + columnDefinition.Key + " has a foreign key to " + columnDefinition.Value.foreignTable + "." + columnDefinition.Value.foreignColumn);
|
|
}
|
|
else
|
|
{
|
|
errorEncountered.Add(definition.Key);
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine(definition.Key + "." + columnDefinition.Key + " has a foreign key to " + columnDefinition.Value.foreignTable + "." + columnDefinition.Value.foreignColumn + " WHICH DOES NOT EXIST!");
|
|
}
|
|
|
|
foreignKeys++;
|
|
|
|
Console.ResetColor();
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Checked " + foreignKeys + " foreign keys!");
|
|
|
|
if (errorEncountered.Count != 0)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("There have been errors in the following dbds:");
|
|
foreach (var dbName in errorEncountered)
|
|
Console.WriteLine (" - " + dbName);
|
|
Environment.Exit(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Done");
|
|
}
|
|
}
|
|
}
|
|
}
|