|
|
|
|
| using System;
|
| using System.Collections.Generic;
|
| using System.IO;
|
| using System.Linq;
|
| using System.Text;
|
| using System.Threading;
|
| using System.Threading.Tasks;
|
| using AutomationTool;
|
| using EpicGame;
|
| using EpicGames.Core;
|
| using Microsoft.Extensions.Logging;
|
|
|
| using static AutomationTool.CommandUtils;
|
|
|
| namespace LyraTest
|
| {
|
| [Help("Updates the Audit_InCook collections.")]
|
| [RequireP4]
|
| public class Lyra_UpdateAuditCollections : BuildCommand
|
| {
|
| public override void ExecuteBuild()
|
| {
|
| Logger.LogInformation("************************* UpdateAuditCollections");
|
|
|
|
|
| string CollectionName = "Audit_InCook";
|
| string ManifestFilename = "Manifest_UFSFiles_Win64.txt";
|
|
|
|
|
| string UFSFilename = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LogFolder, ManifestFilename);
|
| if (!CommandUtils.FileExists_NoExceptions(UFSFilename))
|
| {
|
| UFSFilename = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LogFolder, "..", "..", ManifestFilename);
|
| }
|
|
|
| Logger.LogInformation("Attempting to use UFS manifest {UFSFilename} (exists={Arg1})", UFSFilename, CommandUtils.FileExists_NoExceptions(UFSFilename));
|
|
|
| UpdateInCookAuditCollection(CollectionName, UFSFilename);
|
| }
|
|
|
|
|
| static string AssetExtension = ".uasset";
|
| static string MapExtention = ".umap";
|
|
|
| static string EngineFolderName = "Engine/Content";
|
| static string EnginePluginFolderName = "Engine/Plugins/";
|
|
|
|
|
| static string GameFolderName = "Lyra/Content";
|
| static string GamePluginFolderName = "Lyra/Plugins/";
|
| static string GameProjectDirectory = "Samples/Games/Lyra";
|
|
|
| static public void UpdateInCookAuditCollection(string CollectionName, string UFSFilename)
|
| {
|
| if (!CommandUtils.FileExists_NoExceptions(UFSFilename))
|
| {
|
| Logger.LogWarning("{Text}", "Could not update audit collection, missing file: " + UFSFilename);
|
| return;
|
| }
|
|
|
| int WorkingCL = -1;
|
| if (CommandUtils.P4Enabled)
|
| {
|
| WorkingCL = CommandUtils.P4.CreateChange(CommandUtils.P4Env.Client, String.Format("Updated " + CollectionName + " collection using CL {0}\n#skipci\n#okforgithub public", P4Env.Changelist));
|
| }
|
|
|
| var CollectionFilenameLocal = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, GameProjectDirectory, "Content", "Collections", CollectionName + ".collection");
|
| if (!InternalUtils.SafeCreateDirectory(Path.GetDirectoryName(CollectionFilenameLocal)))
|
| {
|
| Logger.LogWarning("Could not create directory {Arg0}", Path.GetDirectoryName(CollectionFilenameLocal));
|
| return;
|
| }
|
|
|
| bool bNeedsAdd = false;
|
| if (WorkingCL > 0)
|
| {
|
|
|
| if (!CommandUtils.FileExists_NoExceptions(CollectionFilenameLocal))
|
| {
|
| bNeedsAdd = true;
|
| }
|
| else
|
| {
|
| CommandUtils.P4.Edit(WorkingCL, CollectionFilenameLocal);
|
| }
|
| }
|
|
|
|
|
| StreamReader ManifestFile = null;
|
| StreamWriter CollectionFile = null;
|
| try
|
| {
|
| CollectionFile = new StreamWriter(CollectionFilenameLocal);
|
| CollectionFile.WriteLine("FileVersion:1");
|
| CollectionFile.WriteLine("Type:Static");
|
| CollectionFile.WriteLine("");
|
|
|
| string Line = "";
|
| ManifestFile = new StreamReader(UFSFilename);
|
| while ((Line = ManifestFile.ReadLine()) != null)
|
| {
|
| string[] Tokens = Line.Split('\t');
|
| if (Tokens.Length > 1)
|
| {
|
| string UFSPath = Tokens[0];
|
| UFSPath = UFSPath.Trim('\"');
|
| bool bIsAsset = UFSPath.EndsWith(AssetExtension, StringComparison.InvariantCultureIgnoreCase);
|
| bool bIsMap = !bIsAsset && UFSPath.EndsWith(MapExtention, StringComparison.InvariantCultureIgnoreCase);
|
| if (bIsAsset || bIsMap)
|
| {
|
| bool bIsGame = UFSPath.StartsWith(GameFolderName);
|
| bool bIsEngine = UFSPath.StartsWith(EngineFolderName);
|
| bool bIsGamePlugin = UFSPath.StartsWith(GamePluginFolderName);
|
| bool bIsEnginePlugin = UFSPath.StartsWith(EnginePluginFolderName);
|
| if (bIsGame || bIsEngine || bIsGamePlugin || bIsEnginePlugin)
|
| {
|
| string ObjectPath = UFSPath;
|
|
|
| bool bValidPath = true;
|
| if (bIsGame)
|
| {
|
| ObjectPath = "/Game" + ObjectPath.Substring(GameFolderName.Length);
|
| }
|
| else if (bIsEngine)
|
| {
|
| ObjectPath = "/Engine" + ObjectPath.Substring(EngineFolderName.Length);
|
| }
|
| else if (bIsGamePlugin || bIsEnginePlugin)
|
| {
|
| int ContentIdx = ObjectPath.IndexOf("/Content/");
|
| if (ContentIdx != -1)
|
| {
|
| int PluginIdx = ObjectPath.LastIndexOf("/", ContentIdx - 1);
|
| if (PluginIdx == -1)
|
| {
|
| PluginIdx = 0;
|
| }
|
| else
|
| {
|
|
|
| PluginIdx++;
|
| }
|
|
|
| DirectoryReference PluginRoot = new DirectoryReference(ObjectPath.Substring(0, ContentIdx));
|
| string PluginName = "";
|
| foreach (FileReference PluginFile in CommandUtils.FindFiles("*.uplugin", false, PluginRoot))
|
| {
|
| PluginName = PluginFile.GetFileNameWithoutAnyExtensions();
|
| break;
|
| }
|
| if (string.IsNullOrEmpty(PluginName))
|
| {
|
|
|
| PluginName = ObjectPath.Substring(PluginIdx, ContentIdx - PluginIdx);
|
| }
|
| if (PluginName.Length > 0)
|
| {
|
| int PathStartIdx = ContentIdx + "/Content/".Length;
|
| ObjectPath = "/" + PluginName + "/" + ObjectPath.Substring(PathStartIdx);
|
| }
|
| else
|
| {
|
| Logger.LogWarning("{Text}", "Could not add asset to collection. No plugin name. Path:" + UFSPath);
|
| bValidPath = false;
|
| }
|
| }
|
| else
|
| {
|
| Logger.LogWarning("{Text}", "Could not add asset to collection. No content folder. Path:" + UFSPath);
|
| bValidPath = false;
|
| }
|
| }
|
|
|
| if (bValidPath)
|
| {
|
| string ObjectName = Path.GetFileNameWithoutExtension(ObjectPath);
|
| ObjectPath = Path.GetDirectoryName(ObjectPath) + "/" + ObjectName + "." + ObjectName;
|
|
|
| ObjectPath = ObjectPath.Replace('\\', '/');
|
|
|
| CollectionFile.WriteLine(ObjectPath);
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| }
|
| catch (Exception Ex)
|
| {
|
| Logger.LogInformation("Did not update InCook collection. {Arg0}", Ex.Message);
|
| }
|
| finally
|
| {
|
| if (ManifestFile != null)
|
| {
|
| ManifestFile.Close();
|
| }
|
|
|
| if (CollectionFile != null)
|
| {
|
| CollectionFile.Close();
|
| if (bNeedsAdd)
|
| {
|
| CommandUtils.P4.Add(WorkingCL, CollectionFilenameLocal);
|
| }
|
| }
|
| }
|
|
|
| if (WorkingCL > 0)
|
| {
|
|
|
| int SubmittedCL;
|
| CommandUtils.P4.Submit(WorkingCL, out SubmittedCL, true, true);
|
| }
|
|
|
| }
|
| }
|
| }
|
|
|