diff --git a/WDBXEditor/Reader/FileTypes/WDC1.cs b/WDBXEditor/Reader/FileTypes/WDC1.cs index c913b13..2c08447 100644 --- a/WDBXEditor/Reader/FileTypes/WDC1.cs +++ b/WDBXEditor/Reader/FileTypes/WDC1.cs @@ -23,7 +23,7 @@ public class WDC1 : WDB6 public List ColumnMeta; public RelationShipData RelationShipData; - public Dictionary MinMaxValues; + //public Dictionary MinMaxValues; protected int[] columnSizes; protected byte[] recordData; @@ -202,9 +202,7 @@ public override void ReadHeader(ref BinaryReader dbReader, string signature) FieldStructure.Add(new FieldStructureEntry(0, 0)); ColumnMeta.Add(new ColumnStructureEntry()); } - - var max = offsetmap.OrderByDescending(x => x.Item1).First(); - + // Record Data BitStream bitStream = new BitStream(recordData); for (int i = 0; i < RecordCount; i++) @@ -399,59 +397,59 @@ public void LoadDefinitionSizes(DBEntry entry) public void SetColumnMinMaxValues(DBEntry entry) { - MinMaxValues = new Dictionary(); - int column = 0; - for (int i = 0; i < ColumnMeta.Count; i++) - { - // get the column type - skip strings - var type = entry.Data.Columns[column].DataType; - if (type == typeof(string)) - { - column += ColumnMeta[i].ArraySize; - continue; - } - - int bits = ColumnMeta[i].CompressionType == CompressionType.None ? FieldStructure[i].BitCount : ColumnMeta[i].BitWidth; - if ((bits & (bits - 1)) == 0 && bits >= 8) // power of two and >= sizeof(byte) means a standard type - { - column += ColumnMeta[i].ArraySize; - continue; - } - - // calculate the min and max values - bool signed = Convert.ToBoolean(type.GetField("MinValue").GetValue(null)); - bool isfloat = type == typeof(float); - - //bool metaSigned = ColumnMeta[i].CompressionType == CompressionType.Immediate && (ColumnMeta[i].Cardinality & 1) == 1; - //if (ColumnMeta[i].CompressionType == CompressionType.Immediate && metaSigned != signed && i != IdIndex && !isfloat) - // throw new Exception($"Invalid sign for column {i}"); - - object max = signed ? long.MaxValue >> (64 - bits) : (object)(ulong.MaxValue >> (64 - bits)); - object min = signed ? long.MinValue >> (64 - bits) : 0; - if (isfloat) - { - max = BitConverter.ToSingle(BitConverter.GetBytes((dynamic)max), 0); - min = BitConverter.ToSingle(BitConverter.GetBytes((dynamic)min), 0); - } - - for (int j = 0; j < ColumnMeta[i].ArraySize; j++) - { - entry.Data.Columns[column].ExtendedProperties.Add("MaxValue", max); - if (signed || isfloat) - entry.Data.Columns[column].ExtendedProperties.Add("MinValue", min); - - MinMax minmax = new MinMax() - { - Signed = signed, - MaxVal = max, - MinVal = min, - IsSingle = isfloat - }; - - MinMaxValues[column] = minmax; - column++; - } - } + //MinMaxValues = new Dictionary(); + //int column = 0; + //for (int i = 0; i < ColumnMeta.Count; i++) + //{ + // // get the column type - skip strings + // var type = entry.Data.Columns[column].DataType; + // if (type == typeof(string)) + // { + // column += ColumnMeta[i].ArraySize; + // continue; + // } + + // int bits = ColumnMeta[i].CompressionType == CompressionType.None ? FieldStructure[i].BitCount : ColumnMeta[i].BitWidth; + // if ((bits & (bits - 1)) == 0 && bits >= 8) // power of two and >= sizeof(byte) means a standard type + // { + // column += ColumnMeta[i].ArraySize; + // continue; + // } + + // // calculate the min and max values + // bool signed = Convert.ToBoolean(type.GetField("MinValue").GetValue(null)); + // bool isfloat = type == typeof(float); + + // //bool metaSigned = ColumnMeta[i].CompressionType == CompressionType.Immediate && (ColumnMeta[i].Cardinality & 1) == 1; + // //if (ColumnMeta[i].CompressionType == CompressionType.Immediate && metaSigned != signed && i != IdIndex && !isfloat) + // // throw new Exception($"Invalid sign for column {i}"); + + // object max = signed ? long.MaxValue >> (64 - bits) : (object)(ulong.MaxValue >> (64 - bits)); + // object min = signed ? long.MinValue >> (64 - bits) : 0; + // if (isfloat) + // { + // max = BitConverter.ToSingle(BitConverter.GetBytes((dynamic)max), 0); + // min = BitConverter.ToSingle(BitConverter.GetBytes((dynamic)min), 0); + // } + + // for (int j = 0; j < ColumnMeta[i].ArraySize; j++) + // { + // entry.Data.Columns[column].ExtendedProperties.Add("MaxValue", max); + // if (signed || isfloat) + // entry.Data.Columns[column].ExtendedProperties.Add("MinValue", min); + + // MinMax minmax = new MinMax() + // { + // Signed = signed, + // MaxVal = max, + // MinVal = min, + // IsSingle = isfloat + // }; + + // MinMaxValues[column] = minmax; + // column++; + // } + //} } public void AddRelationshipColumn(DBEntry entry) diff --git a/WDBXEditor/Storage/DBEntry.cs b/WDBXEditor/Storage/DBEntry.cs index 242d7e2..8dce90b 100644 --- a/WDBXEditor/Storage/DBEntry.cs +++ b/WDBXEditor/Storage/DBEntry.cs @@ -837,37 +837,37 @@ private bool ValidateMinMaxValues(DataTable importTable, out string error) { error = ""; - if (Header is WDC1 header) - { - foreach (var minmax in header.MinMaxValues) - { - Func compare = (x, min, max) => x < min || x > max; - - bool errored = false; - - var values = importTable.Rows.Cast().Select(x => x.ItemArray[minmax.Key]); - if (minmax.Value.IsSingle) - { - errored = values.Any(x => compare((float)Convert.ChangeType(x, typeof(float)), minmax.Value.MinVal, minmax.Value.MaxVal)); - } - else if (minmax.Value.Signed) - { - errored = values.Any(x => compare((long)Convert.ChangeType(x, typeof(long)), minmax.Value.MinVal, minmax.Value.MaxVal)); - } - else - { - errored = values.Any(x => compare((ulong)Convert.ChangeType(x, typeof(ulong)), minmax.Value.MinVal, minmax.Value.MaxVal)); - } - - if (errored) - { - error = $"Import Failed: Imported data has out of range values for {Data.Columns[minmax.Key].ColumnName}.\n" + - $"(Min: {minmax.Value.MinVal}, Max: {minmax.Value.MaxVal})"; - - return false; - } - } - } + //if (Header is WDC1 header) + //{ + // foreach (var minmax in header.MinMaxValues) + // { + // Func compare = (x, min, max) => x < min || x > max; + + // bool errored = false; + + // var values = importTable.Rows.Cast().Select(x => x.ItemArray[minmax.Key]); + // if (minmax.Value.IsSingle) + // { + // errored = values.Any(x => compare((float)Convert.ChangeType(x, typeof(float)), minmax.Value.MinVal, minmax.Value.MaxVal)); + // } + // else if (minmax.Value.Signed) + // { + // errored = values.Any(x => compare((long)Convert.ChangeType(x, typeof(long)), minmax.Value.MinVal, minmax.Value.MaxVal)); + // } + // else + // { + // errored = values.Any(x => compare((ulong)Convert.ChangeType(x, typeof(ulong)), minmax.Value.MinVal, minmax.Value.MaxVal)); + // } + + // if (errored) + // { + // error = $"Import Failed: Imported data has out of range values for {Data.Columns[minmax.Key].ColumnName}.\n" + + // $"(Min: {minmax.Value.MinVal}, Max: {minmax.Value.MaxVal})"; + + // return false; + // } + // } + //} return true; }