public BufferReader ReadBuffer(int length) { if (length < 0) { throw new ArgumentOutOfRangeException("length"); } if (length > endIndex - index) { throw new EndOfStreamException(); } BufferReader subReader = new BufferReader(buffer, index, length, encoding); index += length; return(subReader); }
// TODO: compression is topic/database independent, so move them // into a separate namespace/class. static HelpTopic DecompileTopic(byte[] buffer, char controlCharacter) { HelpTopic topic = new HelpTopic(); BufferReader reader = new BufferReader(buffer, Graphic437); while (!reader.IsEOF) { HelpLine line = null; try { DecodeLine(reader, out line); } catch (Exception) { if (line != null) { topic.Lines.Add(line); } throw; } bool isCommand = true; try { isCommand = HelpCommandConverter.ProcessCommand( line.Text, controlCharacter, topic); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format( "Unable to process command '{0}': {1}", line.Text, ex.Message)); } if (!isCommand) { topic.Lines.Add(line); } } return(topic); }
internal static void DecodeLine(BufferReader reader, out HelpLine line) { line = null; // Read text length in bytes. int textLength = reader.ReadByte(); string text = reader.ReadFixedLengthString(textLength - 1); line = new HelpLine(text); // Read byte count of attributes. int attrLength = reader.ReadByte(); BufferReader attrReader = reader.ReadBuffer(attrLength - 1); DecodeLineAttributes(line, attrReader); // Read hyperlinks. while (!attrReader.IsEOF) { DecodeLineHyperlink(line, attrReader); } }
private static void DecodeLineHyperlink(HelpLine line, BufferReader reader) { // Read link location. int linkStartIndex = reader.ReadByte(); // one-base, inclusive int linkEndIndex = reader.ReadByte(); // one-base, inclusive if (linkStartIndex == 0 || linkStartIndex > linkEndIndex) { throw new InvalidDataException("Invalid link location."); } if (linkEndIndex > line.Length) { System.Diagnostics.Debug.WriteLine(string.Format( "WARNING: Link end {0} is past line end {1}.", linkEndIndex, line.Length)); linkEndIndex = line.Length; } //if (linkStartIndex // Read NULL-terminated context string. string context = reader.ReadNullTerminatedString(); if (context == "") // link is WORD topic index { int numContext = reader.ReadUInt16(); // 0x8000 | topicIndex context = "@L" + numContext.ToString("X4"); } // Add hyperlink to the line. HelpUri link = new HelpUri(context); for (int j = linkStartIndex; j <= linkEndIndex; j++) { line.Attributes[j - 1] = new TextAttribute(line.Attributes[j - 1].Style, link); } }