Exemplo n.º 1
0
 public static void SetTranslateOptions(TranslateOption setScriptOption, TranslateOption setLtxOption, TranslateOption setXmlOption, TranslateOption setStringOption,
                                        bool setLazyMode)
 {
     scriptOption = setScriptOption;
     ltxOption    = setLtxOption;
     xmlOption    = setXmlOption;
     stringOption = setStringOption;
     lazyMode     = setLazyMode;
 }
Exemplo n.º 2
0
        private static int IterateFiles(TranslateOption translateOption, string path, string filePattern, Regex pattern)
        {
            if (translateOption == TranslateOption.Skip)
            {
                return(-1);
            }
            if (translateOption == TranslateOption.Auto)
            {
                translateForm.DisableControls();
            }
            else
            {
                translateForm.EnableControls();
            }
            if (!Directory.Exists(@"input\" + path))
            {
                translateForm.SetStatus(@"Directory input\" + path + " not found, skipping...");
                return(-1);
            }
            int fileCount = 0;

            string[] filePaths = Directory.GetFiles(@"input\" + path + @"\", filePattern, SearchOption.AllDirectories);
            currentMode = translateOption;
            int howMany = 0;

            foreach (string filePath in filePaths)
            {
                currentFile = Regex.Match(filePath, @".+\\(.+)").Groups[1].Value;
                fileType    = Regex.Match(currentFile, @".+\.(.+)").Groups[1].Value.ToLower();
                string fileText, newText;
                fileCount++;
                currentFile = Regex.Match(filePath, @".+\\(.+)").Groups[1].Value;
                translateForm.SetCurrentFile(filePath + " (" + fileCount + "/" + filePaths.Length + ")");
                if (doneFiles.ContainsKey(filePath))
                {
                    fileText = doneFiles[filePath];
                }
                else
                {
                    fileText = File.ReadAllText(filePath, RU_ENCODING);
                }
                translateForm.SetFileText(fileText);

                // Find all comments to prune overlapping matches later
                moreComments = Regex.Matches("a", "b"); // Hack to make empty MatchCollection
                switch (fileType)
                {
                case "ltx":
                    comments = Regex.Matches(fileText, ";.+");
                    break;

                case "xml":
                    comments = Regex.Matches(fileText, "<!--.+?-->", RegexOptions.Singleline);
                    break;

                case "script":
                    comments     = Regex.Matches(fileText, @"--(?!\[\[).+");
                    moreComments = Regex.Matches(fileText, @"--\[\[.+?\]\]", RegexOptions.Singleline);
                    break;

                default:
                    continue;     // GetFiles does some bullshit where *.ltx returns file.ltx~ (for instance) so avoid that
                }

                newText = pattern.Replace(fileText, matchEvaluator);
                if (newText != fileText)
                {
                    howMany++;
                    doneFiles[filePath] = newText;
                    string where        = @"output\" + Regex.Match(filePath.Substring(5), @".+\\");
                    Directory.CreateDirectory(where);
                    File.WriteAllText(@"output\" + filePath.Substring(5), newText, RU_ENCODING);
                }
            }
            return(howMany);
        }