Script_Text_Editor.Data.SavedTranslationFormatProvider.SavedTranslationFormatProvider C# (CSharp) Method

SavedTranslationFormatProvider() private method

private SavedTranslationFormatProvider ( string filename ) : System
filename string
return System
        internal SavedTranslationFormatProvider(string filename)
        {
            string[] lines;
            using (var sr = new StreamReader(filename))
            {
                lines = sr.ReadToEnd().Replace("\r\n", "\n").Split('\n');
                sr.Close();
            }

            //check
            if (lines[0].IndexOf("Translation file") == -1)
                throw new Exception("这似乎不是一个有效的存档。");

            //format line
            if (lines[0].EndsWith(" [Version 2]"))
                _isNewVersion = true;

            //time info
            _totalTime = _isNewVersion ? TimeSpan.Parse(lines[1]) : TimeSpan.Zero;

            //script path
            _scriptPath = lines[2];

            //encoding
            _encoding = Int32.Parse(lines[3]);

            //last editing line
            _lastLine = Int32.Parse(lines[4]);

            //text lines
            if (_isNewVersion)
            {
                for (int i = 5; i < lines.Length - 1; i++)
                {
                    string l = lines[i];

                    if (l.Length < 7) //eg. <00001>
                        continue;

                    int index = Int32.Parse(l.Substring(1, 5));
                    string text = l.Substring(7);

                    _lines.Add(new LineInfo(index, text));
                }
            }
            else
            {
                for (int i = 5; i < lines.Length - 1; i++)
                {
                    string l = lines[i];

                    _lines.Add(new LineInfo(-1, l));
                }
            }
        }