Example #1
0
        /// <summary>
        /// Reads the contents of the <see cref="EhfaStructure" /> from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
        /// <exception cref="System.ArgumentException">The stream is invalid.</exception>
        public virtual void Read(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream), "The stream is null.");
            }

            try
            {
                foreach (DictionaryEntry structureItem in _type.Items)
                {
                    IEhfaObject     value = null;
                    IEhfaObjectType item  = (IEhfaObjectType)structureItem.Value;

                    if (item is EhfaPrimitiveType)
                    {
                        value = new EhfaObject(item as EhfaPrimitiveType);
                        value.Read(stream);
                        _objects.Add((String)structureItem.Key, value);
                    }
                    else if (item is EhfaStructureType)
                    {
                        if (item.DataPlacement == DataPlacement.Internal)
                        {
                            value = new EhfaStructure(item as EhfaStructureType);
                            value.Read(stream);
                            _objects.Add((String)structureItem.Key, value);
                        }

                        if (item.DataPlacement != DataPlacement.Internal)
                        {
                            Byte[] temp = new Byte[4];
                            stream.Read(temp, 0, 4);
                            Int32 objectRepeatCount = (Int32)EndianBitConverter.ToUInt32(temp, ByteOrder.LittleEndian);
                            stream.Read(temp, 0, 4);
                            UInt32 pointer = EndianBitConverter.ToUInt32(temp, ByteOrder.LittleEndian);

                            _objectLocations[(String)structureItem.Key] = new List <IEhfaObject>();

                            if (objectRepeatCount == 0)
                            {
                                continue;
                            }

                            while (objectRepeatCount-- > 0)
                            {
                                value = new EhfaStructure(item as EhfaStructureType);
                                value.Read(stream);
                                _objectLocations[(String)structureItem.Key].Add(value as EhfaStructure);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("The stream is invalid.", nameof(stream), ex);
            }
        }
Example #2
0
        /// <summary>
        /// Reads the data of the <see cref="EhfaEntry" />.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>The structure within the entry.</returns>
        public EhfaStructure ReadData(Stream stream)
        {
            if (Data != null)
            {
                return(Data);
            }

            if (DataLocation == 0)
            {
                return(null);
            }

            Data = new EhfaStructure(Dictionary[DataType]);
            stream.Seek(DataLocation, SeekOrigin.Begin);

            Data.Read(stream);

            return(Data);
        }