public void AddDictionary(string file)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException();
            }

            var openFile = new Yarhl.IO.TextReader(
                DataStreamFactory.FromFile(file, FileOpenMode.Read));

            if (openFile.Stream.Length == 0)
            {
                throw new Exception("The file is empty.");
            }

            var separatorLine = openFile.ReadLine();

            if (!separatorLine.Contains("separator="))
            {
                throw new Exception("The separator has not been set.");
            }

            if (separatorLine.Length != 11)
            {
                throw new Exception("The separator not support multiple chars like == or ::");
            }

            var separator = separatorLine[10];

            do
            {
                var line = openFile.ReadLine();

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var textSplit = line.Split(separator);

                if (textSplit.Length != 2)
                {
                    throw new Exception("The original or modified string contains the separator or is missing, please check your separator.");
                }

                replacer.Add(textSplit[0], textSplit[1]);
            } while (!openFile.Stream.EndOfStream);
        }
Ejemplo n.º 2
0
        public Rpy Convert(BinaryFormat source)
        {
            //Check if the dictionary exist
            if (File.Exists(CharactersFile))
            {
                GenerateFontMap(CharactersFile);
            }

            result = new Rpy();
            reader = new TextReader(source.Stream, Encoding.UTF8);

            //Check if a Rpy file
            var check = reader.ReadLine();

            if (!check.Contains("# TODO: Translation updated at "))
            {
                throw new NotRpyFile();
            }

            //Initialize the Count
            Count = 0;
            do
            {
                if (!string.IsNullOrEmpty(reader.PeekLine()))
                {
                    if (reader.PeekLine().Contains("strings") && !result.IsSelection)
                    {
                        result.IsSelection = true;
                        //Skip the white line

                        var line = reader.ReadLine().Split(' ');
                        result.Language = line[1];
                        reader.ReadLine();
                    }

                    if (result.IsSelection)
                    {
                        result.Variables.Add(reader.ReadLine());
                        result.Names.Add("Selection");
                        reader.ReadToToken("\"");
                        ReadTextToTranslateD();
                    }
                    else
                    {
                        //Read the two variables
                        variable = reader.ReadLine() + "|" + reader.ReadLine() + "|";
                        reader.ReadLine();
                        reader.ReadToToken("#");
                        var line = reader.ReadLine();
                        ReadTextToTranslate(line, false);
                        ReadTextToTranslate(reader.ReadLine(), true);
                        result.Variables.Add(variable);

                        /*string name = reader.ReadToToken("\"");
                         * variable += name;
                         * result.Names.Add(CheckName(name));
                         * ReadTextToTranslate();
                         * ;*/
                    }
                    variable = "";
                    Count++;
                }
                else
                {
                    reader.ReadLine();
                }
            }while (!reader.Stream.EndOfStream);

            return(result);
        }