- [Core] rework duplicate file processing [GUI/CLI]
This commit is contained in:
@@ -300,18 +300,44 @@ namespace AssetStudio.GUI
|
||||
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath)
|
||||
{
|
||||
var fileName = FixFileName(item.Text);
|
||||
fullPath = Path.Combine(dir, fileName + extension);
|
||||
fullPath = Path.Combine(dir, $"{fileName}{extension}");
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
return true;
|
||||
}
|
||||
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
|
||||
if (!File.Exists(fullPath))
|
||||
if (Properties.Settings.Default.allowDuplicates)
|
||||
{
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
fullPath = Path.Combine(dir, $"{fileName} ({i}){extension}");
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static bool TryExportFolder(string dir, AssetItem item, out string fullPath)
|
||||
{
|
||||
var fileName = FixFileName(item.Text);
|
||||
fullPath = Path.Combine(dir, fileName);
|
||||
if (!Directory.Exists(fullPath))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
return true;
|
||||
}
|
||||
if (Properties.Settings.Default.allowDuplicates)
|
||||
{
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
fullPath = Path.Combine(dir, $"{fileName} ({i})");
|
||||
if (!Directory.Exists(fullPath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool ExportAnimationClip(AssetItem item, string exportPath)
|
||||
@@ -328,11 +354,10 @@ namespace AssetStudio.GUI
|
||||
|
||||
public static bool ExportAnimator(AssetItem item, string exportPath, List<AssetItem> animationList = null)
|
||||
{
|
||||
var exportFullPath = Path.Combine(exportPath, item.Text, item.Text + ".fbx");
|
||||
if (File.Exists(exportFullPath))
|
||||
{
|
||||
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
|
||||
}
|
||||
if (!TryExportFolder(exportPath, item, out var exportFullPath))
|
||||
return false;
|
||||
|
||||
exportFullPath = Path.Combine(exportFullPath, item.Text + ".fbx");
|
||||
var m_Animator = (Animator)item.Asset;
|
||||
var options = new ModelConverter.Options()
|
||||
{
|
||||
@@ -351,17 +376,14 @@ namespace AssetStudio.GUI
|
||||
|
||||
public static bool ExportGameObject(AssetItem item, string exportPath, List <AssetItem> animationList = null)
|
||||
{
|
||||
var exportFullPath = Path.Combine(exportPath, item.Text, item.Text + ".fbx");
|
||||
if (File.Exists(exportFullPath))
|
||||
{
|
||||
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
|
||||
}
|
||||
if (!TryExportFolder(exportPath, item, out var exportFullPath))
|
||||
return false;
|
||||
|
||||
var m_GameObject = (GameObject)item.Asset;
|
||||
ExportGameObject(m_GameObject, exportFullPath, animationList);
|
||||
return true;
|
||||
return ExportGameObject(m_GameObject, exportFullPath, animationList);
|
||||
}
|
||||
|
||||
public static void ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null)
|
||||
public static bool ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null)
|
||||
{
|
||||
var options = new ModelConverter.Options()
|
||||
{
|
||||
@@ -374,8 +396,15 @@ namespace AssetStudio.GUI
|
||||
var convert = animationList != null
|
||||
? new ModelConverter(gameObject, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
|
||||
: new ModelConverter(gameObject, options);
|
||||
|
||||
if (convert.MeshList.Count == 0)
|
||||
{
|
||||
Logger.Info($"GameObject {gameObject.m_Name} has no mesh, skipping...");
|
||||
return false;
|
||||
}
|
||||
exportPath = exportPath + FixFileName(gameObject.m_Name) + ".fbx";
|
||||
ExportFbx(convert, exportPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null)
|
||||
|
||||
Reference in New Issue
Block a user