diff --git a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs index 26b7eb5f2a..89754e26ea 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs @@ -17,7 +17,7 @@ using OpenRA.FileSystem; namespace OpenRA.Mods.Common.UpdateRules { - using YamlFileSet = List<(IReadWritePackage, string, List)>; + using YamlFileSet = List<(IReadWritePackage Package, string File, List Nodes)>; public static class UpdateUtils { @@ -219,19 +219,19 @@ namespace OpenRA.Mods.Common.UpdateRules var mapRulesNode = yaml.NodeWithKeyOrDefault("Rules"); if (mapRulesNode != null) foreach (var f in LoadExternalMapYaml(modData, mapRulesNode.Value, externalFilenames)) - if (!modRules.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2)) + if (!modRules.Any(m => m.Package == f.Package && m.File == f.File)) modRules.Add(f); var mapWeaponsNode = yaml.NodeWithKeyOrDefault("Weapons"); if (mapWeaponsNode != null) foreach (var f in LoadExternalMapYaml(modData, mapWeaponsNode.Value, externalFilenames)) - if (!modWeapons.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2)) + if (!modWeapons.Any(m => m.Package == f.Package && m.File == f.File)) modWeapons.Add(f); var mapSequencesNode = yaml.NodeWithKeyOrDefault("Sequences"); if (mapSequencesNode != null) foreach (var f in LoadExternalMapYaml(modData, mapSequencesNode.Value, externalFilenames)) - if (!modSequences.Any(m => m.Item1 == f.Item1 && m.Item2 == f.Item2)) + if (!modSequences.Any(m => m.Package == f.Package && m.File == f.File)) modSequences.Add(f); } } @@ -298,8 +298,8 @@ namespace OpenRA.Mods.Common.UpdateRules if (transform == null) yield break; - foreach (var file in files) - foreach (var node in file.Item3) + foreach (var (_, _, nodes) in files) + foreach (var node in nodes) if (node.Key != null) foreach (var manualStep in ApplyChromeTransformInner(modData, node, transform)) yield return manualStep; @@ -310,8 +310,8 @@ namespace OpenRA.Mods.Common.UpdateRules if (transform == null) yield break; - foreach (var file in files) - foreach (var node in file.Item3) + foreach (var (_, _, nodes) in files) + foreach (var node in nodes) if (node.Key != null) foreach (var manualStep in transform(modData, node)) yield return manualStep; @@ -328,14 +328,14 @@ namespace OpenRA.Mods.Common.UpdateRules { public static void Save(this YamlFileSet files) { - foreach (var file in files) + foreach (var (package, file, nodes) in files) { - if (file.Item1 == null) + if (package == null) continue; - var textData = Encoding.UTF8.GetBytes(file.Item3.WriteToString()); - if (!Enumerable.SequenceEqual(textData, file.Item1.GetStream(file.Item2).ReadAllBytes())) - file.Item1.Update(file.Item2, textData); + var textData = Encoding.UTF8.GetBytes(nodes.WriteToString()); + if (!Enumerable.SequenceEqual(textData, package.GetStream(file).ReadAllBytes())) + package.Update(file, textData); } } diff --git a/OpenRA.Game/UtilityCommands/ExtractChromeStrings.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs similarity index 96% rename from OpenRA.Game/UtilityCommands/ExtractChromeStrings.cs rename to OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs index 9f211ad99a..5038ff9e34 100644 --- a/OpenRA.Game/UtilityCommands/ExtractChromeStrings.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs @@ -14,10 +14,14 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.IO; using System.Linq; +using OpenRA.FileSystem; +using OpenRA.Mods.Common.UpdateRules; using OpenRA.Widgets; -namespace OpenRA.UtilityCommands +namespace OpenRA.Mods.Common.UtilityCommands { + using YamlFileSet = List<(IReadWritePackage Package, string File, List Nodes)>; + sealed class ExtractChromeStringsCommand : IUtilityCommand { string IUtilityCommand.Name { get { return "--extract-chrome-strings"; } } @@ -51,7 +55,8 @@ namespace OpenRA.UtilityCommands var unsortedCandidates = new List(); var groupedCandidates = new Dictionary, List>(); - var chromeFiles = new List<(string Path, List Nodes)>(); + + var yamlSet = new YamlFileSet(); // Get all translations. foreach (var chrome in layout) @@ -60,7 +65,7 @@ namespace OpenRA.UtilityCommands var chromePath = Path.Combine(chromePackage.Name, chromeName); var yaml = MiniYaml.FromFile(chromePath, false).ConvertAll(n => new MiniYamlNodeBuilder(n)); - chromeFiles.Add((chromePath, yaml)); + yamlSet.Add(((IReadWritePackage)chromePackage, chromeName, yaml)); var translationCandidates = new List(); foreach (var node in yaml) @@ -125,7 +130,7 @@ namespace OpenRA.UtilityCommands groupedCandidates[newHash] = new List() { candidate }; } - // Write to translation and yaml files. + // Write to translation files. Directory.CreateDirectory(Path.GetDirectoryName(fluentPath)); using (var fluentWriter = new StreamWriter(fluentPath, append: true)) { @@ -184,11 +189,7 @@ namespace OpenRA.UtilityCommands } } - foreach (var chromeFile in chromeFiles) - { - using (var chromeLayoutWriter = new StreamWriter(chromeFile.Path)) - chromeLayoutWriter.WriteLine(chromeFile.Nodes.WriteToString()); - } + yamlSet.Save(); } }