Update asset export logic

- Disabled saving files with a unique id if they already exist. A unique id will only be added to files with identical names during export.
- Added an option to overwrite exisisting files.
- Fixed support of multiple model export using "Export selected objects (split)" option. (#43)
This commit is contained in:
VaDiM
2025-08-17 11:23:07 +03:00
parent 52b0a21181
commit f0a69025fe
11 changed files with 149 additions and 46 deletions

View File

@ -10,7 +10,7 @@ namespace AssetStudioCLI
{
internal static class ParallelExporter
{
private static ConcurrentDictionary<string, bool> savePathHash = new ConcurrentDictionary<string, bool>();
private static readonly ConcurrentDictionary<string, bool> ExportPathDict = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
public static bool ExportTexture2D(AssetItem item, string exportPath, out string debugLog)
{
@ -184,6 +184,7 @@ namespace AssetStudioCLI
{
var fileName = FixFileName(item.Text);
var filenameFormat = CLIOptions.o_filenameFormat.Value;
var canOverwrite = CLIOptions.f_overwriteExisting.Value;
switch (filenameFormat)
{
case FilenameFormat.AssetName_PathID:
@ -194,17 +195,18 @@ namespace AssetStudioCLI
break;
}
fullPath = Path.Combine(dir, fileName + extension);
if (savePathHash.TryAdd(fullPath.ToLower(), true) && !File.Exists(fullPath))
if (ExportPathDict.TryAdd(fullPath, true))
{
Directory.CreateDirectory(dir);
return true;
if (CanWrite(fullPath, dir, canOverwrite))
{
return true;
}
}
if (filenameFormat == FilenameFormat.AssetName)
else if (filenameFormat == FilenameFormat.AssetName)
{
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
if (!File.Exists(fullPath))
if (CanWrite(fullPath, dir, canOverwrite))
{
Directory.CreateDirectory(dir);
return true;
}
}
@ -212,6 +214,14 @@ namespace AssetStudioCLI
return false;
}
private static bool CanWrite(string fullPath, string dir, bool canOverwrite)
{
if (!canOverwrite && File.Exists(fullPath))
return false;
Directory.CreateDirectory(dir);
return true;
}
public static bool ParallelExportConvertFile(AssetItem item, string exportPath, out string debugLog)
{
switch (item.Type)
@ -237,7 +247,7 @@ namespace AssetStudioCLI
public static void ClearHash()
{
savePathHash.Clear();
ExportPathDict.Clear();
}
}
}