public override bool Search(string searchString, string path = "") { var tempFile = System.IO.Path.GetTempFileName(); LuaTool.Decompile(Path, tempFile); var result = base.Search(EncodeText(searchString), tempFile); System.IO.File.Delete(tempFile); return(result); }
public override void Rebuild(string outputFolder) { var outputPath = System.IO.Path.Combine(outputFolder, RelativePath); Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath)); var subtitles = GetSubtitles(); var inputTempFile = System.IO.Path.GetTempFileName(); LuaTool.Decompile(Path, inputTempFile); var lines = System.IO.File.ReadAllLines(inputTempFile); System.IO.File.Delete(inputTempFile); var output = new List <string>(lines.Length); foreach (var line in lines) { if (!line.StartsWith("text = {")) { output.Add(line); continue; } var strings = new List <string>(); var regex = new Regex( @"\[\""(?<Tag>[^""]+)\""\]\s=\s\""(?<Text>[^""]*)\"""); var match = regex.Match(line); while (match.Success) { var tag = match.Groups["Tag"].Value; var sub = subtitles.First(x => (x as LuaSubtitle)?.Id == tag); strings.Add($"[\"{tag}\"] = \"{EncodeText(sub.Translation)}\""); match = match.NextMatch(); } output.Add($"text = {{{string.Join(", ", strings)}}}"); } var outputTempFile = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllLines(outputTempFile, output); LuaTool.Compile(outputTempFile, outputPath); System.IO.File.Delete(outputTempFile); }
protected override IList <Subtitle> GetSubtitles() { var tempFile = System.IO.Path.GetTempFileName(); LuaTool.Decompile(Path, tempFile); var result = new List <Subtitle>(); if (System.IO.File.Exists(tempFile)) { var lines = System.IO.File.ReadAllLines(tempFile); System.IO.File.Delete(tempFile); foreach (var line in lines) { if (!line.StartsWith("text = {")) { continue; } var regex = new Regex( @"\[\""(?<Tag>[^""]+)\""\]\s=\s\""(?<Text>[^""]*)\"""); var match = regex.Match(line); while (match.Success) { var tag = match.Groups["Tag"].Value; var text = DecodeText(match.Groups["Text"].Value); var sub = new LuaSubtitle { Id = tag, Text = text, Loaded = text, Translation = text, Offset = 0, }; sub.PropertyChanged += SubtitlePropertyChanged; result.Add(sub); match = match.NextMatch(); } } LoadChanges(result); } return(result); }