JD2022-TU1/main/tools/apps/Packager/Tasks/AssetCookerTask.cs

164 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Packager.Parameters;
using Ubisoft;
namespace Packager.Tasks
{
[Category("Asset Cooker")]
public abstract class AssetCookerTask : ToolTask
{
protected bool BuildAtl { get; set; }
protected bool PackSgs { get; set; }
protected string BundleFile { get; set; }
protected string CommonFat { get; set; }
protected bool ComputeDependencies { get; set; }
protected bool Cook { get; set; }
protected bool OverrideScene { get; set; }
protected string OriginalScene { get; set; }
protected string ReplacementScene { get; set; }
protected bool CookList { get; set; }
protected string[] InputFiles { get; set; }
protected string MergeList { get; set; }
protected string OutputFile { get; set; }
protected string OutputDependenciesFolder { get; set; }
protected string ErrorOutputFile { get; set; }
protected bool Unique { get; set; }
protected string ExcludeFiles { get; set; }
protected bool Hidden { get; set; }
public int ForceMipmap { get; set; }
[Output("Files Cooked By The Engine", IOType.String)]
public ReferenceList CookedFileList = new ReferenceList();
[Input("Cache Key", IOCardinality.Single, IOType.GUID)]
public SingleReference CacheKey { get; set; }
protected AssetCookerTask()
{
BuildAtl = false;
PackSgs = false;
BundleFile = "";
CommonFat = "";
ComputeDependencies = false;
Cook = false;
OverrideScene = false;
OriginalScene = "";
ReplacementScene = "";
CookList = false;
InputFiles = new string[0];
MergeList = "";
OutputFile = "";
ErrorOutputFile = "";
ExcludeFiles = "";
Unique = false;
Hidden = false;
ForceMipmap = -1;
CacheKey = new SingleReference();
}
public string BuildCommandLineArgument<T>(string name, T value)
{
return $"{name}={value}";
}
public void LaunchAssetCooker(BuildConfiguration profile)
{
using (var assetCooker = new AssetCooker.AssetCooker())
{
Logger.LogInfo($"{nameof(AssetCooker.AssetCooker)} was created, its log file can be found at \"{assetCooker.Logger.LogFilePath}\".");
assetCooker.GetDependencies = ComputeDependencies;
assetCooker.Cook = Cook;
assetCooker.Unique = Unique;
assetCooker.BuildAtl = BuildAtl;
assetCooker.GenerateCookedList = CookList;
assetCooker.PackSgs = PackSgs;
assetCooker.Platform = profile.PlatformList[0].EnumParse<Parameters.Platform>(true);
assetCooker.CacheKey = CacheKey.Value;
assetCooker.RebaseEngineVersion = profile.RebaseEngineVersion;
assetCooker.DataVersion = profile.DataVersion;
if (OverrideScene)
{
assetCooker.OverrideScene = OverrideScene;
assetCooker.OriginalScene = OriginalScene;
assetCooker.ReplacementScene = ReplacementScene;
}
if (InputFiles.Length > 0)
assetCooker.Inputs = string.Join(",", InputFiles);
if (!string.IsNullOrEmpty(MergeList))
assetCooker.MergeList = MergeList;
if (!string.IsNullOrEmpty(OutputFile))
assetCooker.OutputFile = OutputFile;
if (!string.IsNullOrEmpty(OutputDependenciesFolder))
assetCooker.OutputDependenciesFolder = OutputDependenciesFolder;
if (!string.IsNullOrEmpty(BundleFile))
assetCooker.BundleOutput = BundleFile;
if (!string.IsNullOrEmpty(CommonFat))
assetCooker.CommonFat = CommonFat;
if (!string.IsNullOrEmpty(ExcludeFiles))
assetCooker.ExcludeFiles = ExcludeFiles;
if (ForceMipmap >= 0)
assetCooker.ForceMipMap = ForceMipmap;
assetCooker.CookLogicToBinary = profile.CookLogicToBinary;
try
{
assetCooker.Run();
if (CookList)
{
CookedFileList.CleanAdd(assetCooker.CookedFileList);
}
}
catch (Exception e)
{
this.Logger.LogException(e);
throw;
}
}
}
//Return a proxy file with content of fileList
protected string CreateMergeFile(IEnumerable<string> fileList)
{
return CreateProxyFile(GetContent(fileList));
}
protected void Start(BuildConfiguration profile)
{
LaunchAssetCooker(profile);
}
}
}