diff --git a/AssetStudio.CLI/Components/CommandLine.cs b/AssetStudio.CLI/Components/CommandLine.cs index 13b70f0..4765f10 100644 --- a/AssetStudio.CLI/Components/CommandLine.cs +++ b/AssetStudio.CLI/Components/CommandLine.cs @@ -49,7 +49,7 @@ public class Options { 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 @@ public class OptionsBinder : BinderBase { public readonly Option Silent; public readonly Option LoggerFlags; - public readonly Option TypeFilter; + public readonly Option TypeFilter; public readonly Option NameFilter; public readonly Option ContainerFilter; public readonly Option GameName; @@ -92,7 +92,7 @@ public OptionsBinder() { Silent = new Option("--silent", "Hide log messages."); LoggerFlags = new Option("--logger_flags", "Flags to control toggle log events.") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Verbose|Debug|Info|etc.." }; - TypeFilter = new Option("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Sprite|etc.." }; + TypeFilter = new Option("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Shader:Parse|Sprite:Both|etc.." }; NameFilter = new Option("--names", result => result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray(), false, "Specify name regex filter(s).") { AllowMultipleArgumentsPerToken = true }; ContainerFilter = new Option("--containers", result => result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray(), false, "Specify container regex filter(s).") { AllowMultipleArgumentsPerToken = true }; GameName = new Option("--game", $"Specify Game.") { IsRequired = true }; diff --git a/AssetStudio.CLI/Program.cs b/AssetStudio.CLI/Program.cs index e7b0da9..f5caf3c 100644 --- a/AssetStudio.CLI/Program.cs +++ b/AssetStudio.CLI/Program.cs @@ -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 @@ public static void Run(Options o) AssetsHelper.Minimal = Settings.Default.minimalAssetMap; AssetsHelper.SetUnityVersion(o.UnityVersion); - if (o.TypeFilter == null) - { - TypeFlags.SetTypes(JsonConvert.DeserializeObject>(Settings.Default.types)); - } - else + TypeFlags.SetTypes(JsonConvert.DeserializeObject>(Settings.Default.types)); + + var classTypeFilter = Array.Empty(); + if (!o.TypeFilter.IsNullOrEmpty()) { - foreach (var type in o.TypeFilter) + var classTypeFilterList = new List(); + 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 @@ public static void Run(Options o) { 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 @@ public static void Run(Options o) 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 @@ public static void Run(Options o) 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();