static async Task Main(string[] args) { Console.WriteLine(DBCToolsExtensions.BuildToolsWelcomeMessage("CreateGDBC")); //Try to load configuration file Config = new ApplicationConfigurationLoader().BuildConfigFile(); DbcTypeParser dbcTypeParser = new DbcTypeParser(); Directory.CreateDirectory($"G{Config.DbcOutputPath}"); //For each implement DBCType we should try to build a DBC file for it. foreach (Type dbcType in dbcTypeParser.ComputeAllKnownDbcTypes()) { string dbcName = dbcTypeParser.GetDbcName(dbcType); IServiceProvider provider = new CreateGDbcContainerServiceBuilder(Config, dbcType).Build(); using (IServiceScope scope = provider.CreateScope()) { IDbcTargetFillable fillable = scope.ServiceProvider.GetService <IDbcTargetFillable>(); if (fillable == null) { throw new InvalidOperationException($"Failed to load Fillable for Type: {dbcType.Name}"); } await fillable.FillAsync(); using (Stream ms = scope.ServiceProvider.GetRequiredService <Stream>()) { //it is important to reset this position //Since we're 20 bytes in after likely writing the header last //Though the above statement could change, either way we want to be at the begining. ms.Position = 0; //It is possible nothing has been written, this is kinda hacky to put this //and leak this in a couple places. But it means no entires were found. if (ms.Length == 0) { continue; } //Once everything has been filled we should create the file using (FileStream fs = new FileStream($"G{Config.DbcOutputPath}/{dbcName}.gdbc", FileMode.CreateNew, FileAccess.ReadWrite)) { await ms.CopyToAsync(fs); } } } } Console.WriteLine("Finished. Press any key!"); }
public static void Test_DBC_File_Converts_To_Table_Back_To_Same_DBC_File(Type t) { //arrange DbcTypeParser parser = new DbcTypeParser(); string dbcType = parser.GetDbcName(t); string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DBC", $"{dbcType}.dbc"); if (!File.Exists(filePath)) { Assert.Inconclusive($"No DBC file test into provided for Type: {t.Name}"); } ApplicationConfiguration config = new ApplicationConfiguration("test", true, LogLevel.Debug, Path.Combine(TestContext.CurrentContext.TestDirectory, "DBC"), "DBC_OUTPUT", "MPQ", "patch-6", "JSON"); //If we have a DBC file then we should prepare the DBC to Database stuff //so we can create an in memory database using (MockCreateDatabaseContainerServiceBuilder databaseCreatorContainer = new MockCreateDatabaseContainerServiceBuilder(config, dbcType, filePath)) { IServiceProvider databaseCreatorServiceProvider = databaseCreatorContainer.Build(); databaseCreatorServiceProvider.GetService <IDbcTargetFillable>().Fill(); //At this point the inmemory database is filled. MockedCreateDbcContainerServiceBuilder dbcCreatorContainer = new MockedCreateDbcContainerServiceBuilder(config, t, databaseCreatorServiceProvider.GetService <DbContext>()); IServiceProvider dbcCreatorServiceProvider = dbcCreatorContainer.Build(); dbcCreatorServiceProvider.GetService <IDbcTargetFillable>().Fill(); //At this point the DBC file should be in DbContext and the table should have //been loaded and turned back into a DBC file. Meaning we can now compare streams using (FileStream MockedFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) using (BinaryReader binaryRead2 = new BinaryReader(dbcCreatorServiceProvider.GetService <Stream>())) using (BinaryReader binaryRead1 = new BinaryReader(MockedFileStream)) { binaryRead2.BaseStream.Position = 0; binaryRead1.BaseStream.Position = 0; byte[] originalBytes = binaryRead1.ReadBytes((int)MockedFileStream.Length); byte[] outputBytes = binaryRead2.ReadBytes((int)binaryRead2.BaseStream.Length); Assert.AreEqual(originalBytes.Length, outputBytes.Length, $"Mismatch length on DBC to SQL to DBC for Type: {dbcType}"); for (int i = 0; i < originalBytes.Length; i++) { Assert.AreEqual(originalBytes[i], outputBytes[i], $"Mismatched value on DBC to SQL to DBC for Type: {dbcType} for Index: {i}"); } } } }