- [CLI] bug fixes
This commit is contained in:
@@ -5,6 +5,7 @@ using System.CommandLine;
|
|||||||
using System.CommandLine.Binding;
|
using System.CommandLine.Binding;
|
||||||
using System.CommandLine.Parsing;
|
using System.CommandLine.Parsing;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AssetStudio.CLI
|
namespace AssetStudio.CLI
|
||||||
{
|
{
|
||||||
@@ -93,8 +94,68 @@ namespace AssetStudio.CLI
|
|||||||
Silent = new Option<bool>("--silent", "Hide log messages.");
|
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.." };
|
LoggerFlags = new Option<LoggerEvent[]>("--logger_flags", "Flags to control toggle log events.") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Verbose|Debug|Info|etc.." };
|
||||||
TypeFilter = new Option<string[]>("--types", "Specify unity class type(s)") { AllowMultipleArgumentsPerToken = true, ArgumentHelpName = "Texture2D|Shader:Parse|Sprite:Both|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 };
|
NameFilter = new Option<Regex[]>("--names", result =>
|
||||||
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 };
|
{
|
||||||
|
var items = new List<Regex>();
|
||||||
|
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<Regex[]>("--containers", result =>
|
||||||
|
{
|
||||||
|
var items = new List<Regex>();
|
||||||
|
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<string>("--game", $"Specify Game.") { IsRequired = true };
|
GameName = new Option<string>("--game", $"Specify Game.") { IsRequired = true };
|
||||||
KeyIndex = new Option<int>("--key_index", "Specify key index.") { ArgumentHelpName = UnityCNManager.ToString() };
|
KeyIndex = new Option<int>("--key_index", "Specify key index.") { ArgumentHelpName = UnityCNManager.ToString() };
|
||||||
MapOp = new Option<MapOpType>("--map_op", "Specify which map to build.");
|
MapOp = new Option<MapOpType>("--map_op", "Specify which map to build.");
|
||||||
@@ -110,16 +171,7 @@ namespace AssetStudio.CLI
|
|||||||
|
|
||||||
Key = new Option<byte>("--key", result =>
|
Key = new Option<byte>("--key", result =>
|
||||||
{
|
{
|
||||||
var value = result.Tokens.Single().Value;
|
return ParseKey(result.Tokens.Single().Value);
|
||||||
if (value.StartsWith("0x"))
|
|
||||||
{
|
|
||||||
value = value[2..];
|
|
||||||
return Convert.ToByte(value, 0x10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return byte.Parse(value);
|
|
||||||
}
|
|
||||||
}, false, "XOR key to decrypt MiHoYoBinData.");
|
}, false, "XOR key to decrypt MiHoYoBinData.");
|
||||||
|
|
||||||
LoggerFlags.AddValidator(FilterValidator);
|
LoggerFlags.AddValidator(FilterValidator);
|
||||||
@@ -131,15 +183,7 @@ namespace AssetStudio.CLI
|
|||||||
var value = result.Tokens.Single().Value;
|
var value = result.Tokens.Single().Value;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (value.StartsWith("0x"))
|
ParseKey(value);
|
||||||
{
|
|
||||||
value = value.Substring(2);
|
|
||||||
Convert.ToByte(value, 0x10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
byte.Parse(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -157,6 +201,19 @@ namespace AssetStudio.CLI
|
|||||||
KeyIndex.SetDefaultValue(0);
|
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)
|
public void FilterValidator(OptionResult result)
|
||||||
{
|
{
|
||||||
var values = result.Tokens.Select(x => x.Value).ToArray();
|
var values = result.Tokens.Select(x => x.Value).ToArray();
|
||||||
|
|||||||
@@ -488,18 +488,21 @@ namespace AssetStudio
|
|||||||
else asset.Name = $"BinFile #{asset.PathID}";
|
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 (pptr.TryGet(out var obj))
|
||||||
if (containerFilters.IsNullOrEmpty() || containerFilters.Any(x => x.IsMatch(container)))
|
|
||||||
{
|
{
|
||||||
item.Container = container;
|
var item = objectAssetItemDic[obj];
|
||||||
}
|
if (containerFilters.Any(x => x.IsMatch(container)))
|
||||||
else
|
{
|
||||||
{
|
item.Container = container;
|
||||||
assets.Remove(item);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assets.Remove(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user