77using System . IO ;
88using System . Linq ;
99using System . Security . Cryptography ;
10+ using DBDefsLib . Constants ;
1011
1112namespace DBDTest
1213{
@@ -20,82 +21,113 @@ class Program
2021
2122 static void Main ( string [ ] args )
2223 {
23- if ( args . Length < 2 )
24- {
25- Console . WriteLine ( "Usage: <input (definitions dir or bdbd)> <dbcdir>" ) ;
26- Environment . Exit ( 1 ) ;
27- }
24+ var dbdmReader = new DBDMReader ( ) ;
25+ var mappingDefinition = dbdmReader . Read ( args [ 0 ] ) ;
2826
29- var inputDir = args [ 0 ] ;
30- dbcDir = args [ 1 ] ;
31-
32- if ( Directory . Exists ( inputDir ) )
27+ var metaDirectory = Path . GetDirectoryName ( args [ 0 ] ) ;
28+ foreach ( var definition in mappingDefinition )
3329 {
34- if ( ! Directory . Exists ( dbcDir ) )
35- {
36- throw new DirectoryNotFoundException ( "Directory " + dbcDir + " does not exist!" ) ;
37- }
30+ if ( definition . meta is MetaType . COLOR )
31+ continue ;
3832
39- var sw = new Stopwatch ( ) ;
40- sw . Start ( ) ;
41- foreach ( var file in Directory . GetFiles ( inputDir ) )
42- {
43- var reader = new DBDReader ( ) ;
44- definitionCache . Add ( Path . GetFileNameWithoutExtension ( file ) . ToLower ( ) , reader . Read ( file ) ) ;
45- }
46- sw . Stop ( ) ;
47- Console . WriteLine ( "Read " + definitionCache . Count + " database definitions from DBDs in " + sw . ElapsedMilliseconds + "ms!" ) ;
48- }
49- else if ( File . Exists ( inputDir ) && inputDir . EndsWith ( ".bdbd" , StringComparison . InvariantCultureIgnoreCase ) )
50- {
51- var sw = new Stopwatch ( ) ;
52- sw . Start ( ) ;
53- using ( var stream = File . OpenRead ( inputDir ) )
54- {
55- var defs = BDBDReader . Read ( stream ) ;
56- foreach ( var def in defs )
57- {
58- definitionCache . Add ( def . Key . ToLower ( ) , def . Value . dbd ) ;
59- }
60- }
61- sw . Stop ( ) ;
62- Console . WriteLine ( "Read " + definitionCache . Count + " database definitions from BDBD in " + sw . ElapsedMilliseconds + "ms!" ) ;
63- }
33+ var extension = definition . meta == MetaType . ENUM ? ".dbde" : ".dbdf" ;
34+ var directoryName = definition . meta == MetaType . ENUM ? "enums" : "flags" ;
6435
65- var builds = new List < Build > ( ) ;
36+ var parseFile = Path . Combine ( metaDirectory ! , directoryName , $ "{ definition . metaValue } { extension } ") ;
37+ if ( ! File . Exists ( parseFile ) )
38+ continue ;
6639
67- foreach ( var dir in Directory . GetDirectories ( dbcDir ) )
68- {
69- builds . Add ( new Build ( dir . Replace ( dbcDir + "\\ " , "" ) ) ) ;
70- }
71-
72- builds . Sort ( ) ;
73-
74- foreach ( var build in builds )
75- {
76- if ( build . expansion != 8 || build . major != 2 ) continue ;
77-
78- Console . WriteLine ( "Checking " + build + ".." ) ;
79- if ( Directory . Exists ( Path . Combine ( dbcDir , build . ToString ( ) , "DBFilesClient" ) ) )
40+ try
8041 {
81- foreach ( var file in Directory . GetFiles ( Path . Combine ( dbcDir , build . ToString ( ) , "DBFilesClient" ) ) )
82- {
83- LoadDBC ( file ) ;
84- }
42+ var enumReader = new DBDEnumReader ( ) ;
43+ var enumDef = enumReader . Read ( parseFile , definition . meta ) ;
44+ Console . WriteLine ( $ "[{ definition . meta } ] { definition . metaValue } : { enumDef . entries . Count } entries") ;
8545 }
86- else
46+ catch ( Exception e )
8747 {
88- foreach ( var file in Directory . GetFiles ( Path . Combine ( dbcDir , build . ToString ( ) ) ) )
89- {
90- LoadDBC ( file ) ;
91- }
48+ Console . ForegroundColor = ConsoleColor . Red ;
49+ Console . WriteLine ( $ "[ERROR] Failed to read { parseFile } : { e . Message } " ) ;
50+ Console . ResetColor ( ) ;
51+ foundError = true ;
9252 }
9353 }
9454
95- if ( foundError )
96- {
97- Environment . Exit ( 1 ) ;
98- }
55+ // if (args.Length < 2)
56+ // {
57+ // Console.WriteLine("Usage: <input (definitions dir or bdbd)> <dbcdir>");
58+ // Environment.Exit(1);
59+ // }
60+ //
61+ // var inputDir = args[0];
62+ // dbcDir = args[1];
63+ //
64+ // if (Directory.Exists(inputDir))
65+ // {
66+ // if (!Directory.Exists(dbcDir))
67+ // {
68+ // throw new DirectoryNotFoundException("Directory " + dbcDir + " does not exist!");
69+ // }
70+ //
71+ // var sw = new Stopwatch();
72+ // sw.Start();
73+ // foreach (var file in Directory.GetFiles(inputDir))
74+ // {
75+ // var reader = new DBDReader();
76+ // definitionCache.Add(Path.GetFileNameWithoutExtension(file).ToLower(), reader.Read(file));
77+ // }
78+ // sw.Stop();
79+ // Console.WriteLine("Read " + definitionCache.Count + " database definitions from DBDs in " + sw.ElapsedMilliseconds + "ms!");
80+ // }
81+ // else if (File.Exists(inputDir) && inputDir.EndsWith(".bdbd", StringComparison.InvariantCultureIgnoreCase))
82+ // {
83+ // var sw = new Stopwatch();
84+ // sw.Start();
85+ // using (var stream = File.OpenRead(inputDir))
86+ // {
87+ // var defs = BDBDReader.Read(stream);
88+ // foreach(var def in defs)
89+ // {
90+ // definitionCache.Add(def.Key.ToLower(), def.Value.dbd);
91+ // }
92+ // }
93+ // sw.Stop();
94+ // Console.WriteLine("Read " + definitionCache.Count + " database definitions from BDBD in " + sw.ElapsedMilliseconds + "ms!");
95+ // }
96+ //
97+ // var builds = new List<Build>();
98+ //
99+ // foreach (var dir in Directory.GetDirectories(dbcDir))
100+ // {
101+ // builds.Add(new Build(dir.Replace(dbcDir + "\\", "")));
102+ // }
103+ //
104+ // builds.Sort();
105+ //
106+ // foreach(var build in builds)
107+ // {
108+ // if (build.expansion != 8 || build.major != 2) continue;
109+ //
110+ // Console.WriteLine("Checking " + build + "..");
111+ // if (Directory.Exists(Path.Combine(dbcDir, build.ToString(), "DBFilesClient")))
112+ // {
113+ // foreach (var file in Directory.GetFiles(Path.Combine(dbcDir, build.ToString(), "DBFilesClient")))
114+ // {
115+ // LoadDBC(file);
116+ // }
117+ // }
118+ // else
119+ // {
120+ // foreach (var file in Directory.GetFiles(Path.Combine(dbcDir, build.ToString())))
121+ // {
122+ // LoadDBC(file);
123+ // }
124+ // }
125+ // }
126+ //
127+ // if (foundError)
128+ // {
129+ // Environment.Exit(1);
130+ // }
99131 }
100132
101133 static void LoadDBC ( string filename )
0 commit comments