Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
- [CLI] allow --types to decide class processing behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
Razmoth committed Feb 6, 2024
1 parent 983da00 commit 5597235
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
6 changes: 3 additions & 3 deletions AssetStudio.CLI/Components/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -71,7 +71,7 @@ public class OptionsBinder : BinderBase<Options>
{
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;
Expand All @@ -92,7 +92,7 @@ public OptionsBinder()
{
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 };
Expand Down
86 changes: 63 additions & 23 deletions AssetStudio.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Dictionary<ClassIDType, (bool, bool)>>(Settings.Default.types));
}
else
TypeFlags.SetTypes(JsonConvert.DeserializeObject<Dictionary<ClassIDType, (bool, bool)>>(Settings.Default.types));

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);
Expand All @@ -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;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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();
Expand Down

0 comments on commit 5597235

Please sign in to comment.