public DBCDStorage(DBReader reader, ReadOnlyDictionary <int, T> storage, DBCDInfo info) : base(new Dictionary <int, DBCDRow>()) { this.info = info; this.fieldAccessor = new FieldAccessor(typeof(T), info.availableColumns); this.reader = reader; this.storage = storage; foreach (var record in storage) { base.Dictionary.Add(record.Key, new DBCDRow(record.Key, record.Value, fieldAccessor)); } }
public DBCDStorage(Stream stream, DBCDInfo info) : this(new DBReader(stream), info) { }
public DBCDStorage(DBReader dbReader, DBCDInfo info) : this(dbReader, new ReadOnlyDictionary <int, T>(dbReader.GetRecords <T>()), info) { }
internal Tuple <Type, DBCDInfo> Build(DBReader dbcReader, Stream dbd, string name, string build) { var dbdReader = new DBDReader(); if (name == null) { name = Guid.NewGuid().ToString(); } var databaseDefinition = dbdReader.Read(dbd); Structs.VersionDefinitions?versionDefinition = null; if (!string.IsNullOrWhiteSpace(build)) { var dbBuild = new Build(build); locStringSize = GetLocStringSize(dbBuild); Utils.GetVersionDefinitionByBuild(databaseDefinition, dbBuild, out versionDefinition); } if (versionDefinition == null && dbcReader.LayoutHash != 0) { var layoutHash = dbcReader.LayoutHash.ToString("X8"); Utils.GetVersionDefinitionByLayoutHash(databaseDefinition, layoutHash, out versionDefinition); } if (versionDefinition == null) { throw new FileNotFoundException("No definition found for " + name); } if (locStringSize > 1 && (int)locale >= locStringSize) { throw new FormatException("Invalid locale for " + name); } var typeBuilder = moduleBuilder.DefineType(name, TypeAttributes.Public); var fields = versionDefinition.Value.definitions; var columns = new List <string>(fields.Length); bool localiseStrings = locale != Locale.None; foreach (var fieldDefinition in fields) { var columnDefinition = databaseDefinition.columnDefinitions[fieldDefinition.name]; bool isLocalisedString = columnDefinition.type == "locstring" && locStringSize > 1; var fieldType = FieldDefinitionToType(fieldDefinition, columnDefinition, localiseStrings); var field = typeBuilder.DefineField(fieldDefinition.name, fieldType, FieldAttributes.Public); columns.Add(fieldDefinition.name); if (fieldDefinition.isID) { AddAttribute <IndexAttribute>(field, fieldDefinition.isNonInline); } if (fieldDefinition.arrLength > 1) { AddAttribute <CardinalityAttribute>(field, fieldDefinition.arrLength); } if (isLocalisedString) { if (localiseStrings) { AddAttribute <LocaleAttribute>(field, (int)locale, locStringSize); } else { AddAttribute <CardinalityAttribute>(field, locStringSize); // add locstring mask field typeBuilder.DefineField(fieldDefinition.name + "_mask", typeof(uint), FieldAttributes.Public); columns.Add(fieldDefinition.name + "_mask"); } } } var type = typeBuilder.CreateTypeInfo(); var info = new DBCDInfo { availableColumns = columns.ToArray(), tableName = name }; return(new Tuple <Type, DBCDInfo>(type, info)); }