internal static ProgramBlock Read(Mdf mdf, Stream stream) { var block = new ProgramBlock(mdf); block.Read(stream); if (block.Identifier != "PR") { throw new FormatException(); } var data = new byte[block.Size - 4]; var read = stream.Read(data, 0, data.Length); if (read != data.Length) { throw new FormatException(); } block.data = data; return(block); }
internal static HeaderBlock Read(Mdf mdf, Stream stream) { var block = new HeaderBlock(mdf); block.Read(stream); var data = new byte[block.Size - 4]; var read = stream.Read(data, 0, data.Length); if (read != data.Length) { throw new FormatException(); } block.DataGroupsCount = BitConverter.ToUInt16(data, 12); block.Date = mdf.IDBlock.Encoding.GetString(data, 14, 10).Humanize(); block.Time = mdf.IDBlock.Encoding.GetString(data, 24, 8).Humanize(); block.Author = mdf.IDBlock.Encoding.GetString(data, 32, 32).Humanize(); block.Organization = mdf.IDBlock.Encoding.GetString(data, 64, 32).Humanize(); block.Project = mdf.IDBlock.Encoding.GetString(data, 96, 32).Humanize(); block.Subject = mdf.IDBlock.Encoding.GetString(data, 128, 32).Humanize(); if (mdf.IDBlock.Version >= 320) { block.TimeStamp = BitConverter.ToUInt64(data, 160); block.UTCTimeOffset = BitConverter.ToInt16(data, 168); block.TimeQuality = (TimeQuality)BitConverter.ToUInt16(data, 170); block.TimerIdentification = mdf.IDBlock.Encoding.GetString(data, 172, 32).Humanize(); } else { block.TimeStamp = 0; block.UTCTimeOffset = 0; block.TimeQuality = 0; block.TimerIdentification = ""; } var ptrFirstDataGroup = BitConverter.ToUInt32(data, 0); var ptrTextBlock = BitConverter.ToUInt32(data, 4); var ptrProgramBlock = BitConverter.ToUInt32(data, 8); // Check if ptrTextBlock is null if (ptrTextBlock != 0) { stream.Position = ptrTextBlock; block.FileComment = TextBlock.Read(mdf, stream); } // Check if ptrProgramBlock is null if (ptrProgramBlock != 0) { stream.Position = ptrProgramBlock; block.ProgramBlock = ProgramBlock.Read(mdf, stream); } // Check if ptrFirstDataGroup is null if (ptrFirstDataGroup != 0) { mdf.DataGroups.Read(DataGroupBlock.Read(mdf, stream, ptrFirstDataGroup)); } return(block); }