Пример #1
0
        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);
        }
Пример #2
0
        private static void ConvertFile(string fileName)
        {
            var reader = new AdmReader(fileName);

            AdmData data = null;

            try
            {
                data = reader.Read();
            }
            catch (AdmReaderException e)
            {
                _hasErrored = true;
                Console.WriteLine("File: {0}", fileName);
                Console.WriteLine(e.Message);
                Console.WriteLine("Reason: {0}", e.InnerException.Message);
                return;
            }

            string content = AdmDataConverter.GetString(data);

            string outputPath = _outputDir != "" ? Path.Combine(_outputDir, fileName + ".txt") : fileName + ".txt";

            File.WriteAllText(outputPath, content);
            Console.WriteLine("Converted {0} into a human readable format", Path.GetFileName(fileName));
        }
Пример #3
0
        public static string GetString(AdmData data)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendBlock(data.MainBlock);

            return(builder.ToString());
        }
Пример #4
0
        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);
        }
Пример #5
0
 public AdmWriter(AdmData file)
 {
     _file = file;
 }