diff --git a/AssetStudio.CLI/Components/CommandLine.cs b/AssetStudio.CLI/Components/CommandLine.cs index 4765f10..63291c0 100644 --- a/AssetStudio.CLI/Components/CommandLine.cs +++ b/AssetStudio.CLI/Components/CommandLine.cs @@ -5,6 +5,7 @@ using System.CommandLine; using System.CommandLine.Binding; using System.CommandLine.Parsing; using System.Text.RegularExpressions; +using System.Collections.Generic; namespace AssetStudio.CLI { @@ -93,8 +94,68 @@ namespace AssetStudio.CLI 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|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 }; + NameFilter = new Option("--names", result => + { + var items = new List(); + var value = result.Tokens.Single().Value; + if (File.Exists(value)) + { + var lines = File.ReadLines(value); + foreach (var line in lines) + { + if (string.IsNullOrWhiteSpace(line)) + { + continue; + } + + try + { + items.Add(new Regex(line, RegexOptions.IgnoreCase)); + } + catch (ArgumentException e) + { + continue; + } + } + } + else + { + items.AddRange(result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray()); + } + + return items.ToArray(); + }, false, "Specify name regex filter(s).") { AllowMultipleArgumentsPerToken = true }; + ContainerFilter = new Option("--containers", result => + { + var items = new List(); + var value = result.Tokens.Single().Value; + if (File.Exists(value)) + { + var lines = File.ReadLines(value); + foreach(var line in lines) + { + if (string.IsNullOrWhiteSpace(line)) + { + continue; + } + + try + { + items.Add(new Regex(line, RegexOptions.IgnoreCase)); + } + catch (ArgumentException e) + { + continue; + } + } + } + else + { + items.AddRange(result.Tokens.Select(x => new Regex(x.Value, RegexOptions.IgnoreCase)).ToArray()); + } + + return items.ToArray(); + }, false, "Specify container regex filter(s).") { AllowMultipleArgumentsPerToken = true }; GameName = new Option("--game", $"Specify Game.") { IsRequired = true }; KeyIndex = new Option("--key_index", "Specify key index.") { ArgumentHelpName = UnityCNManager.ToString() }; MapOp = new Option("--map_op", "Specify which map to build."); @@ -110,16 +171,7 @@ namespace AssetStudio.CLI Key = new Option("--key", result => { - var value = result.Tokens.Single().Value; - if (value.StartsWith("0x")) - { - value = value[2..]; - return Convert.ToByte(value, 0x10); - } - else - { - return byte.Parse(value); - } + return ParseKey(result.Tokens.Single().Value); }, false, "XOR key to decrypt MiHoYoBinData."); LoggerFlags.AddValidator(FilterValidator); @@ -131,15 +183,7 @@ namespace AssetStudio.CLI var value = result.Tokens.Single().Value; try { - if (value.StartsWith("0x")) - { - value = value.Substring(2); - Convert.ToByte(value, 0x10); - } - else - { - byte.Parse(value); - } + ParseKey(value); } catch (Exception e) { @@ -156,6 +200,19 @@ namespace AssetStudio.CLI MapType.SetDefaultValue(ExportListType.XML); KeyIndex.SetDefaultValue(0); } + + public byte ParseKey(string value) + { + if (value.StartsWith("0x")) + { + value = value[2..]; + return Convert.ToByte(value, 0x10); + } + else + { + return byte.Parse(value); + } + } public void FilterValidator(OptionResult result) { diff --git a/AssetStudio/AssetsHelper.cs b/AssetStudio/AssetsHelper.cs index 9e70e7f..95e4439 100644 --- a/AssetStudio/AssetsHelper.cs +++ b/AssetStudio/AssetsHelper.cs @@ -488,18 +488,21 @@ namespace AssetStudio else asset.Name = $"BinFile #{asset.PathID}"; } } - foreach ((var pptr, var container) in containers) + if (!containerFilters.IsNullOrEmpty()) { - if (pptr.TryGet(out var obj)) + foreach ((var pptr, var container) in containers) { - var item = objectAssetItemDic[obj]; - if (containerFilters.IsNullOrEmpty() || containerFilters.Any(x => x.IsMatch(container))) + if (pptr.TryGet(out var obj)) { - item.Container = container; - } - else - { - assets.Remove(item); + var item = objectAssetItemDic[obj]; + if (containerFilters.Any(x => x.IsMatch(container))) + { + item.Container = container; + } + else + { + assets.Remove(item); + } } } }