// Copyright Epic Games, Inc. All Rights Reserved. using AutomationTool; using EpicGames.BuildGraph; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using EpicGames.Core; using UnrealBuildTool; namespace AutomationTool.Tasks { /// /// Parameters for a ModifyConfig task /// public class ModifyConfigTaskParameters { /// /// Path to the config file /// [TaskParameter(ValidationType = TaskParameterValidationType.FileSpec)] public string File; /// /// The section name to modify /// [TaskParameter] public string Section; /// /// The property name to set /// [TaskParameter] public string Key; /// /// The property value to set /// [TaskParameter] public string Value; /// /// Tag to be applied to the extracted files /// [TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)] public string Tag; } /// /// Modifies a config file /// [TaskElement("ModifyConfig", typeof(ModifyConfigTaskParameters))] public class ModifyConfigTask : BgTaskImpl { /// /// Parameters for this task /// ModifyConfigTaskParameters Parameters; /// /// Constructor /// /// Parameters for this task public ModifyConfigTask(ModifyConfigTaskParameters InParameters) { Parameters = InParameters; } /// /// Execute the task. /// /// Information about the current job /// Set of build products produced by this node. /// Mapping from tag names to the set of files they include public override Task ExecuteAsync(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { FileReference ConfigFileLocation = ResolveFile(Parameters.File); ConfigFile ConfigFile; if(FileReference.Exists(ConfigFileLocation)) { ConfigFile = new ConfigFile(ConfigFileLocation); } else { ConfigFile = new ConfigFile(); } ConfigFileSection Section = ConfigFile.FindOrAddSection(Parameters.Section); Section.Lines.RemoveAll(x => String.Compare(x.Key, Parameters.Key, StringComparison.OrdinalIgnoreCase) == 0); Section.Lines.Add(new ConfigLine(ConfigLineAction.Set, Parameters.Key, Parameters.Value)); FileReference.MakeWriteable(ConfigFileLocation); ConfigFile.Write(ConfigFileLocation); // Apply the optional tag to the produced archive foreach (string TagName in FindTagNamesFromList(Parameters.Tag)) { FindOrAddTagSet(TagNameToFileSet, TagName).Add(ConfigFileLocation); } // Add the archive to the set of build products BuildProducts.Add(ConfigFileLocation); return Task.CompletedTask; } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter Writer) { Write(Writer, Parameters); } /// /// Find all the tags which are used as inputs to this task /// /// The tag names which are read by this task public override IEnumerable FindConsumedTagNames() { return FindTagNamesFromFilespec(Parameters.File); } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { return FindTagNamesFromList(Parameters.Tag); } } }