コード例 #1
0
ファイル: AdmDataConverter.cs プロジェクト: andreberg/TLII.IO
        private static AdmBlock ReadBlock(string name, ref AdmConverterContext context)
        {
            AdmBlock block = new AdmBlock();
            block.NameHash = name.StartsWith("0x") ? int.Parse(name.Remove(0, 2), NumberStyles.HexNumber) : HashUtility.GenerateHash(name);

            string line = "";
            while ((line = context.Reader.ReadLine()) != null)
            {
                context.LineNumber++;

                if (line.StartsWith("//") || line.StartsWith("#"))
                {
                    continue;
                }
                else if (line.StartsWith("<") && line.IndexOf(">") != -1 && line.IndexOf(":") != -1)
                {
                    block.Fields.Add(ReadField(line, ref context));
                }
                else 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);

                    block.Childs.Add(ReadBlock(line, ref context));
                }
                else
                {
                    throw new AdmConverterException(String.Format("Unknown line format! (Line: {0})", context.LineNumber));
                }
            }

            return block;
        }
コード例 #2
0
ファイル: AdmReader.cs プロジェクト: andreberg/TLII.IO
        private AdmBlock ReadBlock(ref AdmReadingContext context)
        {
            AdmBlock block = new AdmBlock();

            block.NameHash = _reader.ReadInt32();

            int fieldCount = _reader.ReadInt32();
            for (int i = 0; i < fieldCount; i++)
            {
                block.Fields.Add(ReadField(ref context));
            }

            int childCount = _reader.ReadInt32();
            for (int i = 0; i < childCount; i++)
            {
                block.Childs.Add(ReadBlock(ref context));
            }

            return block;
        }
コード例 #3
0
ファイル: AdmDataConverter.cs プロジェクト: andreberg/TLII.IO
        private static void AppendBlock(this StringBuilder builder, AdmBlock block, int depth = 0)
        {
            string name = GetStringFromKeyTable(block.NameHash);

            builder.AppendFormat("{0}[{1}]\r\n", new String(' ', depth * 3), name);

            foreach (var field in block.Fields)
            {
                builder.AppendField(field, depth + 1);
            }

            foreach (var subBlock in block.Childs)
            {
                builder.AppendBlock(subBlock, depth + 1);
            }

            builder.AppendFormat("{0}[/{1}]", new String(' ', depth * 3), name);

            if (depth > 0)
            {
                builder.AppendLine();
            }
        }
コード例 #4
0
ファイル: AdmWriter.cs プロジェクト: andreberg/TLII.IO
        private void GetStringsByBlock(ref Dictionary<int, string> result, AdmBlock block)
        {
            foreach(var field in block.Fields)
            {
                GetString(ref result, field);
            }

            foreach(var bl in block.Childs)
            {
                GetStringsByBlock(ref result, bl);
            }
        }
コード例 #5
0
ファイル: AdmWriter.cs プロジェクト: andreberg/TLII.IO
        private void WriteBlock(AdmBlock block)
        {
            _writer.Write(block.NameHash);
            
            _writer.Write(block.Fields.Count);
            foreach(var field in block.Fields)
            {
                WriteField(field);
            }

            _writer.Write(block.Childs.Count);
            foreach(var child in block.Childs)
            {
                WriteBlock(child);
            }
        }