private static string GetSectionLabel(TapDataBlock dataBlock) { string sectionLabel = null; switch (dataBlock.Type) { case TapDataBlockType.StandardHeader: TapHeader header = (TapHeader)dataBlock; switch (header.HeaderType) { case TapHeaderType.ProgramHeader: ProgramHeader programHeader = (ProgramHeader)header; sectionLabel = "Program header : " + programHeader.GetProperties(); break; case TapHeaderType.ByteArrayHeader: ByteArrayHeader byteArrayHeader = (ByteArrayHeader)header; sectionLabel = "Byte array header : " + byteArrayHeader.GetProperties(); break; case TapHeaderType.StringArrayHeader: AlphanumArrayHeader stringArrayHeader = (AlphanumArrayHeader)header; sectionLabel = "String array header : " + stringArrayHeader.GetProperties(); break; case TapHeaderType.NumberArrayHeader: AlphanumArrayHeader numberArrayHeader = (AlphanumArrayHeader)header; sectionLabel = "Number array header : " + numberArrayHeader.GetProperties(); break; } break; case TapDataBlockType.StandardDataBlock: sectionLabel = "Standard data block : " + dataBlock.DataLength + " bytes"; break; case TapDataBlockType.CustomDataBlock: sectionLabel = "Custom data block : " + dataBlock.DataLength + " bytes"; break; case TapDataBlockType.FragmentedDataBlock: sectionLabel = "Fragmented data block : " + dataBlock.DataLength + " bytes"; break; } if (dataBlock.HasInvalidChecksum) { sectionLabel += " [invalid checksum]"; } return(sectionLabel); }
internal static TapDataBlock ReadTapDataBlock(BinaryReader fileReader, int dataLengthBytesCount) { // Data block length int dataLength = fileReader.ReadUInt16(); if (dataLengthBytesCount == 3) { dataLength += (fileReader.ReadByte() * 256 * 256); } // Read tape data block byte[] tapeData = null; if (dataLength > 0) { tapeData = fileReader.ReadBytes(dataLength); } TapDataBlock tapDataBlock = null; if (dataLength > 0) { byte flag = tapeData[0]; // Standard header if (flag == 0 && dataLength == 19) { using (BinaryReader headerReader = new BinaryReader(new MemoryStream(tapeData))) { headerReader.ReadByte(); // flag byte dataType = headerReader.ReadByte(); TapHeaderType headerType = TapHeader.GetTapHeaderTypeFromDataType(dataType); switch (headerType) { case TapHeaderType.ProgramHeader: tapDataBlock = new ProgramHeader(); break; case TapHeaderType.NumberArrayHeader: case TapHeaderType.StringArrayHeader: tapDataBlock = new AlphanumArrayHeader(dataType); break; default: //case TapHeaderType.ByteArrayHeader: tapDataBlock = new ByteArrayHeader(); break; } TapHeader tapHeader = (TapHeader)tapDataBlock; tapHeader.FileName = Encoding.GetEncoding("ISO-8859-1").GetString(headerReader.ReadBytes(10)); tapHeader.FollowingDataLength = headerReader.ReadUInt16(); switch (headerType) { case TapHeaderType.ProgramHeader: ReadProgramHeader(headerReader, (ProgramHeader)tapDataBlock); break; case TapHeaderType.NumberArrayHeader: case TapHeaderType.StringArrayHeader: ReadAlphanumArrayHeader(headerReader, (AlphanumArrayHeader)tapDataBlock); break; default: //case TapHeaderType.ByteArrayHeader: ReadByteArrayHeader(headerReader, (ByteArrayHeader)tapDataBlock); break; } } } // Anonymous data block else { tapDataBlock = new TapDataBlock(); tapDataBlock.Flag = flag; } tapDataBlock.DataLength = dataLength; tapDataBlock.TapeData = tapeData; if (dataLength >= 2) { tapDataBlock.CheckSum = tapeData[dataLength-1]; tapDataBlock.HasInvalidChecksum = !CheckIfChecksumIsValid(tapDataBlock); } } return tapDataBlock; }
internal static TapDataBlock ReadTapDataBlock(BinaryReader fileReader, int dataLengthBytesCount) { // Data block length int dataLength = fileReader.ReadUInt16(); if (dataLengthBytesCount == 3) { dataLength += (fileReader.ReadByte() * 256 * 256); } // Read tape data block byte[] tapeData = null; if (dataLength > 0) { tapeData = fileReader.ReadBytes(dataLength); } TapDataBlock tapDataBlock = null; if (dataLength > 0) { byte flag = tapeData[0]; // Standard header if (flag == 0 && dataLength == 19) { using (BinaryReader headerReader = new BinaryReader(new MemoryStream(tapeData))) { headerReader.ReadByte(); // flag byte dataType = headerReader.ReadByte(); TapHeaderType headerType = TapHeader.GetTapHeaderTypeFromDataType(dataType); switch (headerType) { case TapHeaderType.ProgramHeader: tapDataBlock = new ProgramHeader(); break; case TapHeaderType.NumberArrayHeader: case TapHeaderType.StringArrayHeader: tapDataBlock = new AlphanumArrayHeader(dataType); break; default: //case TapHeaderType.ByteArrayHeader: tapDataBlock = new ByteArrayHeader(); break; } TapHeader tapHeader = (TapHeader)tapDataBlock; tapHeader.FileName = Encoding.GetEncoding("ISO-8859-1").GetString(headerReader.ReadBytes(10)); tapHeader.FollowingDataLength = headerReader.ReadUInt16(); switch (headerType) { case TapHeaderType.ProgramHeader: ReadProgramHeader(headerReader, (ProgramHeader)tapDataBlock); break; case TapHeaderType.NumberArrayHeader: case TapHeaderType.StringArrayHeader: ReadAlphanumArrayHeader(headerReader, (AlphanumArrayHeader)tapDataBlock); break; default: //case TapHeaderType.ByteArrayHeader: ReadByteArrayHeader(headerReader, (ByteArrayHeader)tapDataBlock); break; } } } // Anonymous data block else { tapDataBlock = new TapDataBlock(); tapDataBlock.Flag = flag; } tapDataBlock.DataLength = dataLength; tapDataBlock.TapeData = tapeData; if (dataLength >= 2) { tapDataBlock.CheckSum = tapeData[dataLength - 1]; tapDataBlock.HasInvalidChecksum = !CheckIfChecksumIsValid(tapDataBlock); } } return(tapDataBlock); }
private static void ReadProgramHeader(BinaryReader fileReader, ProgramHeader programHeader) { programHeader.AutostartLine = fileReader.ReadUInt16(); programHeader.ProgramLength = fileReader.ReadUInt16(); }