- [CLI] allow --types to decide class processing behaviour.
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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));
|
||||
|
||||
var classTypeFilter = Array.Empty<ClassIDType>();
|
||||
if (!o.TypeFilter.IsNullOrEmpty())
|
||||
{
|
||||
TypeFlags.SetTypes(JsonConvert.DeserializeObject<Dictionary<ClassIDType, (bool, bool)>>(Settings.Default.types));
|
||||
}
|
||||
else
|
||||
{
|
||||
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,13 +98,14 @@ namespace AssetStudio.CLI
|
||||
{
|
||||
TypeFlags.SetType(ClassIDType.GameObject, true, false);
|
||||
}
|
||||
if (Settings.Default.exportMaterials)
|
||||
{
|
||||
TypeFlags.SetType(ClassIDType.Material, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (o.GroupAssetsType == AssetGroupOption.ByContainer)
|
||||
{
|
||||
TypeFlags.SetType(ClassIDType.AssetBundle, true, false);
|
||||
}
|
||||
|
||||
assetsManager.Silent = o.Silent;
|
||||
assetsManager.Game = game;
|
||||
assetsManager.SpecifyUnityVersion = o.UnityVersion;
|
||||
@@ -102,24 +133,33 @@ namespace AssetStudio.CLI
|
||||
|
||||
if (o.MapOp.HasFlag(MapOpType.CABMap))
|
||||
{
|
||||
AssetsHelper.BuildCABMap(files, o.MapName, o.Input.FullName, game);
|
||||
}
|
||||
if (o.MapOp.HasFlag(MapOpType.Load))
|
||||
{
|
||||
AssetsHelper.LoadCABMapInternal(o.MapName);
|
||||
assetsManager.ResolveDependencies = true;
|
||||
if (o.MapOp.HasFlag(MapOpType.Load))
|
||||
{
|
||||
AssetsHelper.BuildCABMap(files, o.MapName, o.Input.FullName, game);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetsHelper.LoadCABMapInternal(o.MapName);
|
||||
assetsManager.ResolveDependencies = true;
|
||||
}
|
||||
}
|
||||
if (o.MapOp.HasFlag(MapOpType.AssetMap))
|
||||
{
|
||||
if (files.Length == 1)
|
||||
if (o.MapOp.HasFlag(MapOpType.Load))
|
||||
{
|
||||
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);
|
||||
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, 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();
|
||||
|
||||
Reference in New Issue
Block a user