mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-11-12 23:32:42 -05:00
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:
@ -10,10 +10,13 @@ namespace AssetStudioCLI
|
||||
{
|
||||
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 filenameFormat = CLIOptions.o_filenameFormat.Value;
|
||||
var canOverwrite = CLIOptions.f_overwriteExisting.Value;
|
||||
switch (filenameFormat)
|
||||
{
|
||||
case FilenameFormat.AssetName_PathID:
|
||||
@ -24,17 +27,18 @@ namespace AssetStudioCLI
|
||||
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 (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;
|
||||
}
|
||||
}
|
||||
@ -42,6 +46,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;
|
||||
}
|
||||
|
||||
private static bool ExportVideoClip(AssetItem item, string exportPath)
|
||||
{
|
||||
var m_VideoClip = (VideoClip)item.Asset;
|
||||
@ -387,5 +399,10 @@ namespace AssetStudioCLI
|
||||
? Path.GetRandomFileName()
|
||||
: Path.GetInvalidFileNameChars().Aggregate(str, (current, c) => current.Replace(c, '_'));
|
||||
}
|
||||
|
||||
public static void ClearHash()
|
||||
{
|
||||
ExportPathHashSet.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user