示例#1
0
        /// <summary>
        /// Reads and parses XML definitions file
        /// <exception cref="Exception">throw exceptions if couldn't readand parse XML file</exception>
        /// </summary>
        public static void UpdateRecordsInfo()
        {
            _records = new Dictionary <string, RecordInfo>();

            // load default value types
            TypeFactory.LoadValueTypes();
            TypeFactory64.LoadValueTypes();

            // load XML
            var doc = new XmlDocument();

            doc.Load("DatDefinitions.xml");

            // load records
            var nodes = doc.SelectNodes("//record");

            if (nodes == null)
            {
                throw new Exception("Not found type record definitions");
            }
            foreach (XmlNode node in nodes)
            {
                ProcessRecordDefinition(node);
            }
        }
示例#2
0
        public FieldData(FieldInfo fieldInfo, BinaryReader reader, bool dat64 = false)
        {
            x64       = dat64;
            FieldInfo = fieldInfo;
            var offset = reader.GetDataSectionOffset();
            var dict   = new Dictionary <string, object>();

            dict["offset"] = offset;
            if (x64)
            {
                Data = TypeFactory64.CreateData(fieldInfo.FieldType, reader, dict);
            }
            else
            {
                Data = TypeFactory.CreateData(fieldInfo.FieldType, reader, dict);
            }
        }
示例#3
0
        public ListData(ListDataType64 type, BinaryReader reader, Dictionary <string, object> options)
            : base(type)
        {
            x64 = true;

            if (!options.ContainsKey("count") || !options.ContainsKey("offset"))
            {
                throw new Exception("Wrong parameters for reading ListData");
            }

            ListType = type.ListType;

            // moving to start of list
            Offset = (int)options["offset"];
            reader.BaseStream.Seek(DatContainer.DataSectionOffset + Offset, SeekOrigin.Begin);

            Count  = (int)options["count"];
            List   = new List <AbstractData>(Count);
            Length = ListType.Width * Count;
            if (Count <= 0)
            {
                return;
            }

            // Count > 0
            var currentOffset = reader.GetDataSectionOffset();

            for (var i = 0; i < Count; ++i)
            {
                // given fixed size of ListType
                var listEntryOffset = currentOffset + i * ListType.Width;
                var dict            = new Dictionary <string, object>
                {
                    ["offset"] = listEntryOffset
                };
                var data = TypeFactory64.CreateData(ListType, reader, dict); ///wdaadawdafaf
                List.Add(data);
            }

            DatContainer.DataEntries[Offset] = this;
        }
示例#4
0
        private static void ProcessRecordDefinition(XmlNode node)
        {
            var file = GetAttributeValue(node, "file");

            if (file == null)
            {
                throw new Exception("Invalid XML: record has wrong attribute 'id' :" + node);
            }
            var lengthString = GetAttributeValue(node, "length");

            if (lengthString == null)
            {
                throw new Exception("Invalid XML: record has wrong attribute 'length' :" + node);
            }
            var length = Convert.ToInt32(lengthString);

            if (length == 0)
            {
                _records.Add(file, new RecordInfo(file, 0, null, false));
                _records.Add(file + ".dat64", new RecordInfo(file + ".dat64", 0, null, true));
                return;
            }

            // process fields of record
            var fields        = new List <FieldInfo>();
            var fields64      = new List <FieldInfo>();
            var index         = 0;
            var totalLength   = 0;
            var totalLength64 = 0;

            foreach (XmlNode field in node.ChildNodes)
            {
                if (field.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }

                var fieldName = field.LocalName;
                if (!fieldName.Equals("field"))
                {
                    throw new Exception("Invalid XML: <record> contain wrong elemnr: " + fieldName);
                }

                var fieldId = GetAttributeValue(field, "id");
                if (fieldId == null)
                {
                    throw new Exception("Invalid XML: field has wrong attribute 'id' :" + fieldName);
                }

                var fieldType = GetAttributeValue(field, "type");
                if (fieldType == null)
                {
                    throw new Exception("Invalid XML: couldn't  find type for field :" + fieldName);
                }
                var dataType   = TypeFactory.ParseType(fieldType);
                var dataType64 = TypeFactory64.ParseType(fieldType);

                var fieldDescription = GetAttributeValue(field, "description");

                var isUserString = GetAttributeValue(field, "isUser");
                var isUser       = !String.IsNullOrEmpty(isUserString);

                fields.Add(new FieldInfo(dataType, index, totalLength, fieldId, fieldDescription, isUser));
                fields64.Add(new FieldInfo(dataType64, index, totalLength64, fieldId, fieldDescription, isUser));
                index++;
                totalLength   += dataType.Width;
                totalLength64 += dataType64.Width;
            }

            // testing whether record's data is correct
            if (totalLength != length)
            {
                var error = "Total length of fields: " + totalLength + " not equal record length: " + length
                            + " for file: " + file;
                foreach (var field in fields)
                {
                    Console.WriteLine("{0} = {1}", field.FieldType.Name, field.FieldType.Width);
                }
                throw new Exception(error);
            }

            _records.Add(file, new RecordInfo(file, totalLength, fields, false));
            _records.Add(file + ".dat64", new RecordInfo(file + ".dat64", totalLength64, fields64, true));
        }
示例#5
0
        public PointerData(PointerDataType dataType, BinaryReader reader, Dictionary <string, object> options)
            : base(dataType)
        {
            if (!options.ContainsKey("offset"))
            {
                throw new Exception("Wrong parameters for reading ListData");
            }

            RefType = dataType.RefType;
            Length  = RefType.PointerWidth;

            // moving to start of pointer so that RefType can read it's own options from that point
            Offset = (int)options["offset"];
            reader.BaseStream.Seek(DatContainer.DataSectionOffset + Offset, SeekOrigin.Begin);

            // only RefType knows how to read it's parameters
            var refParams = RefType.ReadPointer(reader);

            var listDataType = RefType as ListDataType;

            if (listDataType != null)
            {
                RefData = (Length == 8) ? TypeFactory.CreateData(listDataType, reader, refParams) : TypeFactory64.CreateData(listDataType, reader, refParams); //8 or 16
            }
            else
            {
                RefData = (Length == 4) ? TypeFactory.CreateData(RefType, reader, refParams) : TypeFactory64.CreateData(RefType, reader, refParams); //4 or 8
            }
            DatContainer.DataPointers[Offset] = this;
        }