[CLI] Add flag to allow removing container path prefix.

- Added --strip-path-prefix flag
This commit is contained in:
middlered
2025-11-09 21:05:59 +08:00
parent aa5768850b
commit de967527ef
3 changed files with 46 additions and 2 deletions
+16
View File
@@ -125,6 +125,7 @@ namespace AssetStudioCLI.Options
public static Option<int> o_maxParallelExportTasks; public static Option<int> o_maxParallelExportTasks;
public static Option<ExportListType> o_exportAssetList; public static Option<ExportListType> o_exportAssetList;
public static Option<string> o_assemblyPath; public static Option<string> o_assemblyPath;
public static Option<string> o_stripPathPrefix;
public static Option<UnityVersion> o_unityVersion; public static Option<UnityVersion> o_unityVersion;
public static Option<bool> f_decompressToDisk; public static Option<bool> f_decompressToDisk;
public static Option<bool> f_notRestoreExtensionName; public static Option<bool> f_notRestoreExtensionName;
@@ -534,6 +535,14 @@ namespace AssetStudioCLI.Options
optionExample: "", optionExample: "",
optionHelpGroup: HelpGroups.Advanced optionHelpGroup: HelpGroups.Advanced
); );
o_stripPathPrefix = new GroupedOption<string>
(
optionDefaultValue: "",
optionName: "--strip-path-prefix <path>",
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<UnityVersion> o_unityVersion = new GroupedOption<UnityVersion>
( (
optionDefaultValue: null, optionDefaultValue: null,
@@ -1245,6 +1254,13 @@ namespace AssetStudioCLI.Options
return; return;
} }
break; 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": case "--unity-version":
try try
{ {
+3
View File
@@ -186,6 +186,9 @@ Advanced Options:
--assembly-folder <path> Specify the path to the assembly folder --assembly-folder <path> Specify the path to the assembly folder
--strip-path-prefix <path> Specify a path prefix to be stripped from exported asset paths
Example: "--strip-path-prefix assets/models/char/"
--unity-version <text> Specify Unity version --unity-version <text> Specify Unity version
Example: "--unity-version 2017.4.39f1" Example: "--unity-version 2017.4.39f1"
+26 -1
View File
@@ -659,6 +659,26 @@ namespace AssetStudioCLI
var parallelExportCount = CLIOptions.o_maxParallelExportTasks.Value; var parallelExportCount = CLIOptions.o_maxParallelExportTasks.Value;
var toExportAssetDict = new ConcurrentDictionary<AssetItem, string>(); var toExportAssetDict = new ConcurrentDictionary<AssetItem, string>();
var toParallelExportAssetDict = new ConcurrentDictionary<AssetItem, string>(); var toParallelExportAssetDict = new ConcurrentDictionary<AssetItem, string>();
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 => Parallel.ForEach(parsedAssetsList, asset =>
{ {
string exportPath; string exportPath;
@@ -671,7 +691,12 @@ namespace AssetStudioCLI
case AssetGroupOption.ContainerPathFull: case AssetGroupOption.ContainerPathFull:
if (!string.IsNullOrEmpty(asset.Container)) 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) if (groupOption == AssetGroupOption.ContainerPathFull)
{ {
exportPath = Path.Combine(exportPath, Path.GetFileNameWithoutExtension(asset.Container)); exportPath = Path.Combine(exportPath, Path.GetFileNameWithoutExtension(asset.Container));