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

@ -9,10 +9,13 @@ namespace AssetStudioGUI
{
internal static class Exporter
{
private static readonly HashSet<string> ExportPathHashSet = new HashSet<string>(System.StringComparer.OrdinalIgnoreCase);
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath, string mode = "Export")
{
var fileName = FixFileName(item.Text);
var filenameFormatIndex = Properties.Settings.Default.filenameFormat;
var canOverwrite = Properties.Settings.Default.overwriteExistingFiles;
switch (filenameFormatIndex)
{
case 1: //assetName@pathID
@ -23,17 +26,18 @@ namespace AssetStudioGUI
break;
}
fullPath = Path.Combine(dir, fileName + extension);
if (!File.Exists(fullPath))
if (ExportPathHashSet.Add(fullPath))
{
Directory.CreateDirectory(dir);
return true;
if (CanWrite(fullPath, dir, canOverwrite))
{
return true;
}
}
if (filenameFormatIndex == 0) //assetName
else if (filenameFormatIndex == 0) //assetName
{
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
if (!File.Exists(fullPath))
if (CanWrite(fullPath, dir, canOverwrite))
{
Directory.CreateDirectory(dir);
return true;
}
}
@ -41,6 +45,14 @@ namespace AssetStudioGUI
return false;
}
private static bool CanWrite(string fullPath, string dir, bool canOverwrite)
{
if (!canOverwrite && File.Exists(fullPath))
return false;
Directory.CreateDirectory(dir);
return true;
}
private static bool ExportVideoClip(AssetItem item, string exportPath)
{
var m_VideoClip = (VideoClip)item.Asset;
@ -349,5 +361,10 @@ namespace AssetStudioGUI
? Path.GetRandomFileName()
: Path.GetInvalidFileNameChars().Aggregate(str, (current, c) => current.Replace(c, '_'));
}
public static void ClearHash()
{
ExportPathHashSet.Clear();
}
}
}