Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="TpsRecord"/> by partially copying the previous one.
        /// </summary>
        /// <param name="previous">The previous record.</param>
        /// <param name="rx">The data to read from.</param>
        public TpsRecord(TpsRecord previous, RandomAccess rx)
        {
            if (previous == null)
            {
                throw new ArgumentNullException(nameof(previous));
            }

            if (rx == null)
            {
                throw new ArgumentNullException(nameof(rx));
            }

            Flags = rx.Byte();

            if ((Flags & 0x80) != 0)
            {
                RecordLength = rx.ShortLE();
            }
            else
            {
                RecordLength = previous.RecordLength;
            }

            if ((Flags & 0x40) != 0)
            {
                HeaderLength = rx.ShortLE();
            }
            else
            {
                HeaderLength = previous.HeaderLength;
            }

            int copy = Flags & 0x3F;

            var newData = new List <byte>(RecordLength);

            newData.AddRange(previous.Data.GetData().Take(copy));
            newData.AddRange(rx.ReadBytes(RecordLength - copy));

            Data = new RandomAccess(newData.ToArray());

            if (Data.Length != RecordLength)
            {
                throw new ArgumentException("Data and record length mismatch.");
            }

            BuildHeader();
        }
Ejemplo n.º 2
0
        public void ParseRecords()
        {
            var rx = GetUncompressedData();

            Records.Clear();

            // Skip pages with non 0x00 flags as they don't seem to contain TpsRecords.
            if (Flags == 0x00)
            {
                rx.PushPosition();

                try
                {
                    TpsRecord previousRecord = null;

                    do
                    {
                        TpsRecord currentRecord = null;

                        if (previousRecord is null)
                        {
                            currentRecord = new TpsRecord(rx);
                        }
                        else
                        {
                            currentRecord = new TpsRecord(previousRecord, rx);
                        }

                        Records.Add(currentRecord);

                        previousRecord = currentRecord;
                    }while (!rx.IsAtEnd && Records.Count < RecordCount);
                }
                finally
                {
                    rx.PopPosition();
                }
            }
        }