mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-15 19:28:48 -05:00
Add option to export images in "assetName@hash" name format
- Redesigned spriteHelper & texture2DConverter - Improved speed of texture2D preview a bit
This commit is contained in:
@@ -13,6 +13,7 @@ namespace AssetStudioCLI
|
||||
public ClassIDType Type;
|
||||
public string Text;
|
||||
public string UniqueID;
|
||||
public ulong Hash;
|
||||
public GameObjectNode Node;
|
||||
|
||||
public AssetItem(Object asset)
|
||||
@@ -23,6 +24,7 @@ namespace AssetStudioCLI
|
||||
TypeString = Type.ToString();
|
||||
m_PathID = asset.m_PathID;
|
||||
FullSize = asset.byteSize;
|
||||
Hash = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace AssetStudioCLI.Options
|
||||
AssetName,
|
||||
AssetName_PathID,
|
||||
PathID,
|
||||
AssetName_Hash,
|
||||
}
|
||||
|
||||
internal enum ExportListType
|
||||
@@ -245,10 +246,11 @@ namespace AssetStudioCLI.Options
|
||||
optionDefaultValue: FilenameFormat.AssetName,
|
||||
optionName: "-f, --filename-format <value>",
|
||||
optionDescription: "Specify the file name format for exported assets\n" +
|
||||
"<Value: assetName(default) | assetName_pathID | pathID>\n" +
|
||||
"<Value: assetName(default) | assetName_pathID | pathID | assetName_hash>\n" +
|
||||
"AssetName - Asset file names will look like \"assetName.extension\"\n" +
|
||||
"AssetName_pathID - Asset file names will look like \"assetName @pathID.extension\"\n" +
|
||||
"PathID - Asset file names will look like \"pathID.extension\"\n",
|
||||
"PathID - Asset file names will look like \"pathID.extension\"\n" +
|
||||
"AssetName_hash - (images only) image names will look like \"assetName @hash.extension\"\n",
|
||||
optionExample: "Example: \"-f assetName_pathID\"\n",
|
||||
optionHelpGroup: HelpGroups.General
|
||||
);
|
||||
@@ -931,6 +933,9 @@ namespace AssetStudioCLI.Options
|
||||
case "pathid":
|
||||
o_filenameFormat.Value = FilenameFormat.PathID;
|
||||
break;
|
||||
case "assetname_hash":
|
||||
o_filenameFormat.Value = FilenameFormat.AssetName_Hash;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported file name format: [{value.Color(brightRed)}].\n");
|
||||
ShowOptionDescription(o_filenameFormat);
|
||||
|
||||
@@ -19,7 +19,10 @@ namespace AssetStudioCLI
|
||||
if (CLIOptions.convertTexture)
|
||||
{
|
||||
var type = CLIOptions.o_imageFormat.Value;
|
||||
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
|
||||
var converter = new Texture2DConverter(m_Texture2D);
|
||||
if (CLIOptions.o_filenameFormat.Value == FilenameFormat.AssetName_Hash)
|
||||
item.Hash = converter.GetTextureHash();
|
||||
if (!TryExportFile(exportPath, item, $".{type}", out var exportFullPath))
|
||||
return false;
|
||||
|
||||
if (CLIOptions.o_logLevel.Value <= LoggerEvent.Debug)
|
||||
@@ -45,7 +48,7 @@ namespace AssetStudioCLI
|
||||
debugLog += sb.ToString();
|
||||
}
|
||||
|
||||
if (!m_Texture2D.TryConvertToImage(flip: true, out var image))
|
||||
if (!converter.TryConvertToBgra32Image(flip: true, out var image))
|
||||
{
|
||||
Logger.Error($"{debugLog}Export error. Failed to convert texture \"{m_Texture2D.m_Name}\" into image");
|
||||
return false;
|
||||
@@ -74,11 +77,13 @@ namespace AssetStudioCLI
|
||||
{
|
||||
debugLog = "";
|
||||
var type = CLIOptions.o_imageFormat.Value;
|
||||
var alphaMask = SpriteMaskMode.On;
|
||||
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
|
||||
var converter = new SpriteConverter((Sprite)item.Asset);
|
||||
if (CLIOptions.o_filenameFormat.Value == FilenameFormat.AssetName_Hash)
|
||||
item.Hash = converter.GetSpriteHash();
|
||||
if (!TryExportFile(exportPath, item, $".{type}", out var exportFullPath))
|
||||
return false;
|
||||
var image = ((Sprite)item.Asset).GetImage(alphaMask);
|
||||
if (image != null)
|
||||
|
||||
if (converter.TryConvertToImage(out var image, maskMode: SpriteMaskMode.On))
|
||||
{
|
||||
using (image)
|
||||
{
|
||||
@@ -192,8 +197,12 @@ namespace AssetStudioCLI
|
||||
case FilenameFormat.PathID:
|
||||
fileName = item.m_PathID.ToString();
|
||||
break;
|
||||
case FilenameFormat.AssetName_Hash when item.Hash > 0:
|
||||
fileName = $"{fileName} @{item.Hash:x}";
|
||||
break;
|
||||
}
|
||||
fullPath = Path.Combine(dir, fileName + extension);
|
||||
extension = extension.ToLower();
|
||||
fullPath = Path.Combine(dir, $"{fileName}{extension}");
|
||||
if (ExportPathDict.TryAdd(fullPath, true))
|
||||
{
|
||||
if (CanWrite(fullPath, dir, canOverwrite))
|
||||
@@ -201,9 +210,9 @@ namespace AssetStudioCLI
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (filenameFormat == FilenameFormat.AssetName)
|
||||
else if (filenameFormat == FilenameFormat.AssetName || (filenameFormat == FilenameFormat.AssetName_Hash && item.Hash == 0))
|
||||
{
|
||||
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
|
||||
fullPath = Path.Combine(dir, $"{fileName}{item.UniqueID}{extension}");
|
||||
if (CanWrite(fullPath, dir, canOverwrite))
|
||||
{
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user