public AdmData Read() { _stream.Seek(0, SeekOrigin.Begin); AdmData data = new AdmData(); AdmReadingContext context = new AdmReadingContext(); try { data.Version = _reader.ReadInt32(); int stringTableCount = _reader.ReadInt32(); for (int i = 0; i < stringTableCount; i++) { ReadStringTableEntry(ref context); } data.MainBlock = ReadBlock(ref context); } catch (Exception e) { throw new AdmReaderException("Failed to read raw file.", e); } return data; }
public static string GetString(AdmData data) { StringBuilder builder = new StringBuilder(); builder.AppendBlock(data.MainBlock); return builder.ToString(); }
public static AdmData GetData(string data) { AdmData admData = new AdmData(); var context = new AdmConverterContext(); context.Reader = new StringReader(data); string line = ""; while ((line = context.Reader.ReadLine()) != null) { context.LineNumber++; if (line.StartsWith("[") && line.EndsWith("]")) { if (line.StartsWith("[/")) { line = line.Substring(2, line.Length - 3); if (line != context.BlockStack.Pop()) { throw new AdmConverterException(String.Format("Can't close outer block before inner! (Line: {0})", context.LineNumber)); } break; } line = line.Substring(1, line.Length - 2); context.BlockStack.Push(line); admData.MainBlock = ReadBlock(line, ref context); } } context.Reader.Close(); context.Reader.Dispose(); return admData; }
public AdmWriter(AdmData file) { _file = file; }