From c50c8130c2c6d42e20d56fb9de3eb57c1f128a96 Mon Sep 17 00:00:00 2001 From: Andrey Lemin Date: Sun, 20 Sep 2020 16:02:32 +0300 Subject: [PATCH] Add some changes for some reason --- Elevator.Subtranslator.Reporter/Program.cs | 77 +++++++++++----------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/Elevator.Subtranslator.Reporter/Program.cs b/Elevator.Subtranslator.Reporter/Program.cs index 54571e2..59c706a 100644 --- a/Elevator.Subtranslator.Reporter/Program.cs +++ b/Elevator.Subtranslator.Reporter/Program.cs @@ -5,8 +5,8 @@ using System.Linq; using System.Xml.Linq; using Elevator.Subtranslator.Common; -using Elevator.Subtranslator.Common.JoinExtensions; using System.Xml; +using System.Text.RegularExpressions; namespace Elevator.Subtranslator.Reporter { @@ -23,16 +23,16 @@ class Options public string ReportPath { get; set; } } - class GroupedResult + class Entry { - public string GroupName { get; private set; } + public string Category { get; private set; } public string Key { get; private set; } public string EtalonValue { get; private set; } public string TargetValue { get; private set; } - public GroupedResult(string groupName, string key, string etalon, string target) + public Entry(string category, string key, string etalon, string target) { - GroupName = groupName; + Category = category; Key = key; EtalonValue = etalon; TargetValue = target; @@ -59,43 +59,41 @@ static void Main(string[] args) InjectionPathComparer injComparer = new InjectionPathComparer(); DefTypeComparer defTypeComparer = new DefTypeComparer(); - List keyedEntries = ReadCommentedKeyedValues(Path.Combine(options.TargetPath, "Keyed")).ToList(); - List injectedEntries = ReadCommentedInjections(Path.Combine(options.TargetPath, "DefInjected")).Where(inj => !exceptions.Contains(inj.GroupName, defTypeComparer)).ToList(); - - List> keyedGroupedResult = keyedEntries.GroupBy(inj => inj.GroupName).ToList(); - List> injectedGroupedResult = injectedEntries.GroupBy(inj => inj.GroupName).ToList(); + List keyedEntries = ReadCommentedKeyedValues(Path.Combine(options.TargetPath, "Keyed")).ToList(); + List injectedEntries = ReadCommentedInjections(Path.Combine(options.TargetPath, "DefInjected")).Where(inj => !exceptions.Contains(inj.Category, defTypeComparer)).ToList(); using (StreamWriter sw = File.CreateText(options.ReportPath)) { - sw.WriteLine(); - sw.WriteLine("Injected items:"); + WriteEntriesGrouped(injectedEntries.Concat(keyedEntries), sw); + sw.Close(); + } + } - foreach (IGrouping group in injectedGroupedResult) - { - sw.WriteLine(); - sw.WriteLine(group.Key); - foreach (GroupedResult result in group) - { - sw.WriteLine("{0}\t{1}\t{2}", result.Key, result.EtalonValue, result.TargetValue); - } - } - sw.WriteLine(); - sw.WriteLine("Keyed items:"); + static void WriteEntriesGrouped(IEnumerable entries, StreamWriter sw) + { + List> groupedEntries = entries.GroupBy(inj => inj.Category).ToList(); - foreach (IGrouping group in keyedGroupedResult) + foreach (IGrouping group in groupedEntries) + { + sw.WriteLine(group.Key); + foreach (Entry entry in group) { - sw.WriteLine(); - sw.WriteLine(group.Key); - foreach (GroupedResult result in group) - { - sw.WriteLine("{0}\t{1}\t{2}", result.Key, result.EtalonValue, result.TargetValue); - } + sw.WriteLine($"{entry.Key}\t{entry.EtalonValue}\t{entry.TargetValue}"); } - sw.Close(); } } - static IEnumerable ReadCommentedKeyedValues(string path) + static void WriteEntriesDirect(IEnumerable entries, StreamWriter sw) + { + foreach (Entry entry in entries) + { + sw.WriteLine($"{entry.Category}\t{entry.Key}\t{entry.EtalonValue}\t{entry.TargetValue}"); + } + } + + private static readonly Regex _englishComment = new Regex(@"^ EN: (.*?) $", RegexOptions.Compiled); + + static IEnumerable ReadCommentedKeyedValues(string path) { DirectoryInfo keyedDir = new DirectoryInfo(path); foreach (FileInfo file in keyedDir.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly)) @@ -119,16 +117,16 @@ static IEnumerable ReadCommentedKeyedValues(string path) foreach (XElement keyedElement in languageData.Elements()) { XComment comment = keyedElement.PreviousNode as XComment; - string etalon = comment == null ? string.Empty : comment.Value.Replace(" EN: ", string.Empty); - yield return new GroupedResult(file.Name, keyedElement.Name.LocalName, etalon, keyedElement.Value); + string etalon = comment == null ? string.Empty : _englishComment.Match(comment.Value).Groups[1].Value; + yield return new Entry(file.Name, keyedElement.Name.LocalName, etalon, keyedElement.Value); } } } - static IEnumerable ReadCommentedInjections(string injectionsDirPath) + static IEnumerable ReadCommentedInjections(string injectionsDirPath) { - List results = new List(); + List results = new List(); DirectoryInfo injectionsDir = new DirectoryInfo(injectionsDirPath); foreach (DirectoryInfo injectionTypeDir in injectionsDir.EnumerateDirectories()) @@ -144,8 +142,9 @@ static IEnumerable ReadCommentedInjections(string injectionsDirPa foreach (XElement injection in languageData.Elements()) { XComment comment = injection.PreviousNode as XComment; - string etalon = comment == null ? string.Empty : comment.Value.Replace(" EN: ", string.Empty); - results.Add(new GroupedResult(defType, injection.Name.LocalName, etalon, injection.Value)); + + string etalon = comment == null ? string.Empty : _englishComment.Match(comment.Value).Groups[1].Value; + results.Add(new Entry(defType, injection.Name.LocalName, etalon, injection.Value)); } } catch (Exception ex) @@ -159,7 +158,5 @@ static IEnumerable ReadCommentedInjections(string injectionsDirPa } return results; } - - } }