// Copyright Epic Games, Inc. All Rights Reserved. using System.Xml; namespace UnrealBuildTool { /// /// Resource writer for VC app manifest generator /// public class UEResXWriter { /// /// Create a new resource writer at the given path /// public UEResXWriter(string InPath) { Filename = InPath; Document = new XmlDocument(); Document.AppendChild(Document.CreateXmlDeclaration("1.0", "utf-8", null)); RootElement = Document.CreateElement("root"); Document.AppendChild(RootElement); RootElement.AppendChild(CreateEntry("resheader", "resmimetype", "text/microsoft-resx", null)); RootElement.AppendChild(CreateEntry("resheader", "version", "2.0", null)); RootElement.AppendChild(CreateEntry("resheader", "reader", typeof(UEResXReader).AssemblyQualifiedName!, null)); RootElement.AppendChild(CreateEntry("resheader", "writer", typeof(UEResXWriter).AssemblyQualifiedName!, null)); } /// /// Closes the writer /// public void Close() { Document.Save(Filename); } /// /// Add the given resource reference /// public void AddResource(string InName, string InValue) { RootElement.AppendChild(CreateEntry("data", InName, InValue, "preserve")); } private XmlNode CreateEntry(string InRootName, string InName, string InValue, string? InSpace) { XmlElement Value = Document.CreateElement("value"); Value.InnerText = InValue; XmlElement Data = Document.CreateElement("data"); { XmlAttribute Attr = Document.CreateAttribute("name"); Attr.Value = InName; Data.Attributes.Append(Attr); } if (!System.String.IsNullOrEmpty(InSpace)) { XmlAttribute Attr = Document.CreateAttribute("xml:space"); Attr.Value = "preserve"; Data.Attributes.Append(Attr); } Data.AppendChild(Value); return Data; } private string Filename; private XmlDocument Document; private XmlElement RootElement; } }