From de967527efd66a86631a595d7a1719ac13fe69ca Mon Sep 17 00:00:00 2001 From: middlered <98752512+MiddleRed@users.noreply.github.com> Date: Sun, 9 Nov 2025 21:05:59 +0800 Subject: [PATCH] [CLI] Add flag to allow removing container path prefix. - Added --strip-path-prefix flag --- AssetStudioCLI/Options/CLIOptions.cs | 16 +++++++++++++++ AssetStudioCLI/ReadMe.md | 3 +++ AssetStudioCLI/Studio.cs | 29 ++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index d0b93b2..f7375ae 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -125,6 +125,7 @@ namespace AssetStudioCLI.Options public static Option o_maxParallelExportTasks; public static Option o_exportAssetList; public static Option o_assemblyPath; + public static Option o_stripPathPrefix; public static Option o_unityVersion; public static Option f_decompressToDisk; public static Option f_notRestoreExtensionName; @@ -534,6 +535,14 @@ namespace AssetStudioCLI.Options optionExample: "", optionHelpGroup: HelpGroups.Advanced ); + o_stripPathPrefix = new GroupedOption + ( + optionDefaultValue: "", + optionName: "--strip-path-prefix ", + optionDescription: "Specify a path prefix to be stripped from exported asset paths\n", + optionExample: "Example: \"--strip-path-prefix assets/models/char/\"\n", + optionHelpGroup: HelpGroups.Advanced + ); o_unityVersion = new GroupedOption ( optionDefaultValue: null, @@ -1245,6 +1254,13 @@ namespace AssetStudioCLI.Options return; } break; + case "--strip-path-prefix": + o_stripPathPrefix.Value = Path.Combine(Path.GetDirectoryName(value), Path.GetFileName(value)); + if (!o_stripPathPrefix.Value.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + o_stripPathPrefix.Value += Path.DirectorySeparatorChar; + } + break; case "--unity-version": try { diff --git a/AssetStudioCLI/ReadMe.md b/AssetStudioCLI/ReadMe.md index 5e872ef..2706a54 100644 --- a/AssetStudioCLI/ReadMe.md +++ b/AssetStudioCLI/ReadMe.md @@ -186,6 +186,9 @@ Advanced Options: --assembly-folder Specify the path to the assembly folder + --strip-path-prefix Specify a path prefix to be stripped from exported asset paths + Example: "--strip-path-prefix assets/models/char/" + --unity-version Specify Unity version Example: "--unity-version 2017.4.39f1" diff --git a/AssetStudioCLI/Studio.cs b/AssetStudioCLI/Studio.cs index 93eaca8..0eb43c1 100644 --- a/AssetStudioCLI/Studio.cs +++ b/AssetStudioCLI/Studio.cs @@ -659,6 +659,26 @@ namespace AssetStudioCLI var parallelExportCount = CLIOptions.o_maxParallelExportTasks.Value; var toExportAssetDict = new ConcurrentDictionary(); var toParallelExportAssetDict = new ConcurrentDictionary(); + + if (CLIOptions.o_stripPathPrefix.Value != null) + { + foreach (var asset in parsedAssetsList) + { + var containerPath = asset.Container; + if (string.IsNullOrEmpty(containerPath)) + { + continue; + } + if (!Path.Combine(Path.GetDirectoryName(containerPath), Path.GetFileName(containerPath)).StartsWith(CLIOptions.o_stripPathPrefix.Value)) + { + Logger.Warning($"Asset container path \"{asset.Container}\" does not start with the specified path prefix \"{CLIOptions.o_stripPathPrefix.Value}\""); + Logger.Warning("strip path prefix option will be ignored."); + CLIOptions.o_stripPathPrefix.Value = null; + break; + } + } + } + Parallel.ForEach(parsedAssetsList, asset => { string exportPath; @@ -671,7 +691,12 @@ namespace AssetStudioCLI case AssetGroupOption.ContainerPathFull: if (!string.IsNullOrEmpty(asset.Container)) { - exportPath = Path.Combine(savePath, Path.GetDirectoryName(asset.Container)); + var containerPath = Path.GetDirectoryName(asset.Container); + if (CLIOptions.o_stripPathPrefix.Value != null) + { + containerPath = containerPath.Substring(CLIOptions.o_stripPathPrefix.Value.Length); + } + exportPath = Path.Combine(savePath, containerPath); if (groupOption == AssetGroupOption.ContainerPathFull) { exportPath = Path.Combine(exportPath, Path.GetFileNameWithoutExtension(asset.Container)); @@ -740,7 +765,7 @@ namespace AssetStudioCLI toExportAssetDict.TryAdd(asset, exportPath); } }); - + foreach (var toExportAsset in toExportAssetDict) { var asset = toExportAsset.Key;