- [CLI] allow --types to decide class processing behaviour.

This commit is contained in:
Razmoth
2024-02-06 20:24:00 +04:00
parent 983da00e83
commit 5597235af6
2 changed files with 66 additions and 26 deletions

View File

@@ -49,7 +49,7 @@ namespace AssetStudio.CLI
{
public bool Silent { get; set; }
public LoggerEvent[] LoggerFlags { get; set; }
public ClassIDType[] TypeFilter { get; set; }
public string[] TypeFilter { get; set; }
public Regex[] NameFilter { get; set; }
public Regex[] ContainerFilter { get; set; }
public string GameName { get; set; }
@@ -71,7 +71,7 @@ namespace AssetStudio.CLI
{
public readonly Option<bool> Silent;
public readonly Option<LoggerEvent[]> LoggerFlags;
public readonly Option<ClassIDType[]> TypeFilter;
public readonly Option<string[]> TypeFilter;
public readonly Option<Regex[]> NameFilter;
public readonly Option<Regex[]> ContainerFilter;
public readonly Option<string> GameName;
@@ -92,7 +92,7 @@ namespace AssetStudio.CLI
{
Silent = new Option<bool>("--silent", "Hide log messages.");
LoggerFlags = new Option<LoggerEvent[]>("--logger_flags", "Flags to control toggle log events.") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Verbose|Debug|Info|etc.." };
TypeFilter = new Option<ClassIDType[]>("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Sprite|etc.." };
TypeFilter = new Option<string[]>("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Shader:Parse|Sprite:Both|etc.." };
NameFilter = new Option<Regex[]>("--names", result => result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray(), false, "Specify name regex filter(s).") { AllowMultipleArgumentsPerToken = true };
ContainerFilter = new Option<Regex[]>("--containers", result => result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray(), false, "Specify container regex filter(s).") { AllowMultipleArgumentsPerToken = true };
GameName = new Option<string>("--game", $"Specify Game.") { IsRequired = true };

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using AssetStudio.CLI.Properties;
using Newtonsoft.Json;
using static AssetStudio.CLI.Studio;
@@ -46,20 +45,51 @@ namespace AssetStudio.CLI
AssetsHelper.Minimal = Settings.Default.minimalAssetMap;
AssetsHelper.SetUnityVersion(o.UnityVersion);
if (o.TypeFilter == null)
{
TypeFlags.SetTypes(JsonConvert.DeserializeObject<Dictionary<ClassIDType, (bool, bool)>>(Settings.Default.types));
}
else
var classTypeFilter = Array.Empty<ClassIDType>();
if (!o.TypeFilter.IsNullOrEmpty())
{
foreach (var type in o.TypeFilter)
var classTypeFilterList = new List<ClassIDType>();
for (int i = 0; i < o.TypeFilter.Length; i++)
{
TypeFlags.SetType(type, true, true);
var typeStr = o.TypeFilter[i];
var type = ClassIDType.UnknownType;
var flag = TypeFlag.Both;
try
{
if (typeStr.Contains(':'))
{
var param = typeStr.Split(':');
flag = (TypeFlag)Enum.Parse(typeof(TypeFlag), param[1]);
typeStr = param[0];
}
type = (ClassIDType)Enum.Parse(typeof(ClassIDType), typeStr);
TypeFlags.SetType(type, flag.HasFlag(TypeFlag.Parse), flag.HasFlag(TypeFlag.Export));
classTypeFilterList.Add(type);
}
catch(Exception e)
{
Logger.Error($"{typeStr} has invalid format, skipping...");
continue;
}
}
classTypeFilter = classTypeFilterList.ToArray();
if (ClassIDType.GameObject.CanExport() || ClassIDType.Animator.CanExport())
{
TypeFlags.SetType(ClassIDType.Texture2D, true, false);
if (Settings.Default.exportMaterials)
{
TypeFlags.SetType(ClassIDType.Material, true, false);
}
if (ClassIDType.GameObject.CanExport())
{
TypeFlags.SetType(ClassIDType.Animator, true, false);
@@ -68,11 +98,12 @@ namespace AssetStudio.CLI
{
TypeFlags.SetType(ClassIDType.GameObject, true, false);
}
if (Settings.Default.exportMaterials)
}
}
if (o.GroupAssetsType == AssetGroupOption.ByContainer)
{
TypeFlags.SetType(ClassIDType.Material, true, false);
}
}
TypeFlags.SetType(ClassIDType.AssetBundle, true, false);
}
assetsManager.Silent = o.Silent;
@@ -101,25 +132,34 @@ namespace AssetStudio.CLI
Logger.Info($"Found {files.Length} files");
if (o.MapOp.HasFlag(MapOpType.CABMap))
{
if (o.MapOp.HasFlag(MapOpType.Load))
{
AssetsHelper.BuildCABMap(files, o.MapName, o.Input.FullName, game);
}
if (o.MapOp.HasFlag(MapOpType.Load))
else
{
AssetsHelper.LoadCABMapInternal(o.MapName);
assetsManager.ResolveDependencies = true;
}
}
if (o.MapOp.HasFlag(MapOpType.AssetMap))
{
if (o.MapOp.HasFlag(MapOpType.Load))
{
}
else
{
if (files.Length == 1)
{
throw new Exception("Unable to build AssetMap with input_path as a file !!");
}
AssetsHelper.BuildAssetMap(files, o.MapName, game, o.Output.FullName, o.MapType, o.TypeFilter, o.NameFilter, o.ContainerFilter);
AssetsHelper.BuildAssetMap(files, o.MapName, game, o.Output.FullName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
}
}
if (o.MapOp.HasFlag(MapOpType.Both))
{
AssetsHelper.BuildBoth(files, o.MapName, o.Input.FullName, game, o.Output.FullName, o.MapType, o.TypeFilter, o.NameFilter, o.ContainerFilter);
AssetsHelper.BuildBoth(files, o.MapName, o.Input.FullName, game, o.Output.FullName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
}
if (o.MapOp.Equals(MapOpType.None) || o.MapOp.HasFlag(MapOpType.Load))
{
@@ -135,7 +175,7 @@ namespace AssetStudio.CLI
assetsManager.LoadFiles(file);
if (assetsManager.assetsFileList.Count > 0)
{
BuildAssetData(o.TypeFilter, o.NameFilter, o.ContainerFilter, ref i);
BuildAssetData(classTypeFilter, o.NameFilter, o.ContainerFilter, ref i);
ExportAssets(o.Output.FullName, exportableAssets, o.GroupAssetsType, o.AssetExportType);
}
exportableAssets.Clear();