mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-14 11:18:47 -05:00
[CLI] Add flag to allow removing container path prefix.
- Added --strip-path-prefix flag
This commit is contained in:
@@ -125,6 +125,7 @@ namespace AssetStudioCLI.Options
|
||||
public static Option<int> o_maxParallelExportTasks;
|
||||
public static Option<ExportListType> o_exportAssetList;
|
||||
public static Option<string> o_assemblyPath;
|
||||
public static Option<string> o_stripPathPrefix;
|
||||
public static Option<UnityVersion> o_unityVersion;
|
||||
public static Option<bool> f_decompressToDisk;
|
||||
public static Option<bool> f_notRestoreExtensionName;
|
||||
@@ -534,6 +535,14 @@ namespace AssetStudioCLI.Options
|
||||
optionExample: "",
|
||||
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>
|
||||
(
|
||||
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
|
||||
{
|
||||
|
||||
@@ -186,6 +186,9 @@ Advanced Options:
|
||||
|
||||
--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
|
||||
Example: "--unity-version 2017.4.39f1"
|
||||
|
||||
|
||||
@@ -659,6 +659,26 @@ namespace AssetStudioCLI
|
||||
var parallelExportCount = CLIOptions.o_maxParallelExportTasks.Value;
|
||||
var toExportAssetDict = 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 =>
|
||||
{
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user