- [Core] rework duplicate file processing [GUI/CLI]
This commit is contained in:
@@ -300,18 +300,45 @@ namespace AssetStudio.CLI
|
|||||||
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath)
|
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath)
|
||||||
{
|
{
|
||||||
var fileName = FixFileName(item.Text);
|
var fileName = FixFileName(item.Text);
|
||||||
fullPath = Path.Combine(dir, fileName + extension);
|
fullPath = Path.Combine(dir, $"{fileName}{extension}");
|
||||||
if (!File.Exists(fullPath))
|
if (!File.Exists(fullPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dir);
|
Directory.CreateDirectory(dir);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
|
if (Properties.Settings.Default.allowDuplicates)
|
||||||
if (!File.Exists(fullPath))
|
{
|
||||||
|
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,11 +356,9 @@ namespace AssetStudio.CLI
|
|||||||
|
|
||||||
public static bool ExportAnimator(AssetItem item, string exportPath, List<AssetItem> animationList = null)
|
public static bool ExportAnimator(AssetItem item, string exportPath, List<AssetItem> animationList = null)
|
||||||
{
|
{
|
||||||
var exportFullPath = Path.Combine(exportPath, item.Text, item.Text + ".fbx");
|
if (!TryExportFolder(exportPath, item, out var exportFullPath))
|
||||||
if (File.Exists(exportFullPath))
|
return false;
|
||||||
{
|
|
||||||
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
|
|
||||||
}
|
|
||||||
var m_Animator = (Animator)item.Asset;
|
var m_Animator = (Animator)item.Asset;
|
||||||
var options = new ModelConverter.Options()
|
var options = new ModelConverter.Options()
|
||||||
{
|
{
|
||||||
@@ -352,8 +377,10 @@ namespace AssetStudio.CLI
|
|||||||
|
|
||||||
public static bool ExportGameObject(AssetItem item, string exportPath, List <AssetItem> animationList = null)
|
public static bool ExportGameObject(AssetItem item, string exportPath, List <AssetItem> animationList = null)
|
||||||
{
|
{
|
||||||
|
if (!TryExportFolder(exportPath, item, out var exportFullPath))
|
||||||
|
return false;
|
||||||
|
|
||||||
var m_GameObject = (GameObject)item.Asset;
|
var m_GameObject = (GameObject)item.Asset;
|
||||||
exportPath = Path.Combine(exportPath, m_GameObject.m_Name) + Path.DirectorySeparatorChar;
|
|
||||||
return ExportGameObject(m_GameObject, exportPath, animationList);
|
return ExportGameObject(m_GameObject, exportPath, animationList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ namespace AssetStudio.CLI.Properties {
|
|||||||
public bool restoreExtensionName => AppSettings.Get("restoreExtensionName", true);
|
public bool restoreExtensionName => AppSettings.Get("restoreExtensionName", true);
|
||||||
public bool enableFileLogging => AppSettings.Get("enableFileLogging", false);
|
public bool enableFileLogging => AppSettings.Get("enableFileLogging", false);
|
||||||
public bool minimalAssetMap => AppSettings.Get("minimalAssetMap", true);
|
public bool minimalAssetMap => AppSettings.Get("minimalAssetMap", true);
|
||||||
|
public bool allowDuplicates => AppSettings.Get("allowDuplicates", false);
|
||||||
public string texs => AppSettings.Get("texs", string.Empty);
|
public string texs => AppSettings.Get("texs", string.Empty);
|
||||||
public string uvs => AppSettings.Get("uvs", string.Empty);
|
public string uvs => AppSettings.Get("uvs", string.Empty);
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,9 @@
|
|||||||
<setting name="enableVerbose" serializeAs="String">
|
<setting name="enableVerbose" serializeAs="String">
|
||||||
<value>False</value>
|
<value>False</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="allowDuplicates" serializeAs="String">
|
||||||
|
<value>False</value>
|
||||||
|
</setting>
|
||||||
<setting name="texs" serializeAs="String">
|
<setting name="texs" serializeAs="String">
|
||||||
<value>{}</value>
|
<value>{}</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
|||||||
@@ -300,18 +300,44 @@ namespace AssetStudio.GUI
|
|||||||
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath)
|
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath)
|
||||||
{
|
{
|
||||||
var fileName = FixFileName(item.Text);
|
var fileName = FixFileName(item.Text);
|
||||||
fullPath = Path.Combine(dir, fileName + extension);
|
fullPath = Path.Combine(dir, $"{fileName}{extension}");
|
||||||
if (!File.Exists(fullPath))
|
if (!File.Exists(fullPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dir);
|
Directory.CreateDirectory(dir);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
|
if (Properties.Settings.Default.allowDuplicates)
|
||||||
if (!File.Exists(fullPath))
|
{
|
||||||
|
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
public static bool ExportAnimationClip(AssetItem item, string exportPath)
|
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)
|
public static bool ExportAnimator(AssetItem item, string exportPath, List<AssetItem> animationList = null)
|
||||||
{
|
{
|
||||||
var exportFullPath = Path.Combine(exportPath, item.Text, item.Text + ".fbx");
|
if (!TryExportFolder(exportPath, item, out var exportFullPath))
|
||||||
if (File.Exists(exportFullPath))
|
return false;
|
||||||
{
|
|
||||||
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
|
exportFullPath = Path.Combine(exportFullPath, item.Text + ".fbx");
|
||||||
}
|
|
||||||
var m_Animator = (Animator)item.Asset;
|
var m_Animator = (Animator)item.Asset;
|
||||||
var options = new ModelConverter.Options()
|
var options = new ModelConverter.Options()
|
||||||
{
|
{
|
||||||
@@ -351,17 +376,14 @@ namespace AssetStudio.GUI
|
|||||||
|
|
||||||
public static bool ExportGameObject(AssetItem item, string exportPath, List <AssetItem> animationList = null)
|
public static bool ExportGameObject(AssetItem item, string exportPath, List <AssetItem> animationList = null)
|
||||||
{
|
{
|
||||||
var exportFullPath = Path.Combine(exportPath, item.Text, item.Text + ".fbx");
|
if (!TryExportFolder(exportPath, item, out var exportFullPath))
|
||||||
if (File.Exists(exportFullPath))
|
return false;
|
||||||
{
|
|
||||||
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
|
|
||||||
}
|
|
||||||
var m_GameObject = (GameObject)item.Asset;
|
var m_GameObject = (GameObject)item.Asset;
|
||||||
ExportGameObject(m_GameObject, exportFullPath, animationList);
|
return ExportGameObject(m_GameObject, exportFullPath, animationList);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
var options = new ModelConverter.Options()
|
||||||
{
|
{
|
||||||
@@ -374,8 +396,15 @@ namespace AssetStudio.GUI
|
|||||||
var convert = animationList != null
|
var convert = animationList != null
|
||||||
? new ModelConverter(gameObject, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
|
? new ModelConverter(gameObject, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
|
||||||
: new ModelConverter(gameObject, options);
|
: 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";
|
exportPath = exportPath + FixFileName(gameObject.m_Name) + ".fbx";
|
||||||
ExportFbx(convert, exportPath);
|
ExportFbx(convert, exportPath);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null)
|
public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null)
|
||||||
|
|||||||
15
AssetStudio.GUI/MainForm.Designer.cs
generated
15
AssetStudio.GUI/MainForm.Designer.cs
generated
@@ -173,6 +173,7 @@ namespace AssetStudio.GUI
|
|||||||
exportAnimatorwithselectedAnimationClipMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
exportAnimatorwithselectedAnimationClipMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
goToSceneHierarchyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
goToSceneHierarchyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
showOriginalFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
showOriginalFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
allowDuplicates = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
menuStrip1.SuspendLayout();
|
menuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
||||||
splitContainer1.Panel1.SuspendLayout();
|
splitContainer1.Panel1.SuspendLayout();
|
||||||
@@ -264,7 +265,7 @@ namespace AssetStudio.GUI
|
|||||||
//
|
//
|
||||||
// optionsToolStripMenuItem
|
// optionsToolStripMenuItem
|
||||||
//
|
//
|
||||||
optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { displayAll, toolStripSeparator10, enablePreview, enableModelPreview, modelsOnly, toolStripSeparator11, displayInfo, enableResolveDependencies, skipContainer, toolStripSeparator12, toolStripMenuItem14, specifyUnityCNKey, toolStripSeparator13, toolStripMenuItem18, toolStripMenuItem19, showExpOpt });
|
optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { displayAll, toolStripSeparator10, enablePreview, enableModelPreview, modelsOnly, toolStripSeparator11, displayInfo, enableResolveDependencies, allowDuplicates, skipContainer, toolStripSeparator12, toolStripMenuItem14, specifyUnityCNKey, toolStripSeparator13, toolStripMenuItem18, toolStripMenuItem19, showExpOpt });
|
||||||
optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
|
optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
|
||||||
optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
|
optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
|
||||||
optionsToolStripMenuItem.Text = "Options";
|
optionsToolStripMenuItem.Text = "Options";
|
||||||
@@ -659,7 +660,7 @@ namespace AssetStudio.GUI
|
|||||||
allToolStripMenuItem.CheckOnClick = true;
|
allToolStripMenuItem.CheckOnClick = true;
|
||||||
allToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
|
allToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||||
allToolStripMenuItem.Name = "allToolStripMenuItem";
|
allToolStripMenuItem.Name = "allToolStripMenuItem";
|
||||||
allToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
allToolStripMenuItem.Size = new System.Drawing.Size(88, 22);
|
||||||
allToolStripMenuItem.Text = "All";
|
allToolStripMenuItem.Text = "All";
|
||||||
allToolStripMenuItem.Click += typeToolStripMenuItem_Click;
|
allToolStripMenuItem.Click += typeToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@@ -1352,6 +1353,15 @@ namespace AssetStudio.GUI
|
|||||||
showOriginalFileToolStripMenuItem.Visible = false;
|
showOriginalFileToolStripMenuItem.Visible = false;
|
||||||
showOriginalFileToolStripMenuItem.Click += showOriginalFileToolStripMenuItem_Click;
|
showOriginalFileToolStripMenuItem.Click += showOriginalFileToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
// allowDuplicates
|
||||||
|
//
|
||||||
|
allowDuplicates.CheckOnClick = true;
|
||||||
|
allowDuplicates.Name = "allowDuplicates";
|
||||||
|
allowDuplicates.Size = new System.Drawing.Size(225, 22);
|
||||||
|
allowDuplicates.Text = "Allow duplicates";
|
||||||
|
allowDuplicates.ToolTipText = "Toggle the behaviour of exporting assets.\r\nEnable to allow assets with duplicate names to be exported.";
|
||||||
|
allowDuplicates.CheckedChanged += allowDuplicates_CheckedChanged;
|
||||||
|
//
|
||||||
// MainForm
|
// MainForm
|
||||||
//
|
//
|
||||||
AllowDrop = true;
|
AllowDrop = true;
|
||||||
@@ -1542,6 +1552,7 @@ namespace AssetStudio.GUI
|
|||||||
private System.Windows.Forms.ToolStripMenuItem sceneHierarchy;
|
private System.Windows.Forms.ToolStripMenuItem sceneHierarchy;
|
||||||
private System.Windows.Forms.ToolStripMenuItem assetMapTypeMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem assetMapTypeMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem loadCABMapToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem loadCABMapToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem allowDuplicates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ namespace AssetStudio.GUI
|
|||||||
enableModelPreview.Checked = Properties.Settings.Default.enableModelPreview;
|
enableModelPreview.Checked = Properties.Settings.Default.enableModelPreview;
|
||||||
modelsOnly.Checked = Properties.Settings.Default.modelsOnly;
|
modelsOnly.Checked = Properties.Settings.Default.modelsOnly;
|
||||||
enableResolveDependencies.Checked = Properties.Settings.Default.enableResolveDependencies;
|
enableResolveDependencies.Checked = Properties.Settings.Default.enableResolveDependencies;
|
||||||
|
allowDuplicates.Checked = Properties.Settings.Default.allowDuplicates;
|
||||||
skipContainer.Checked = Properties.Settings.Default.skipContainer;
|
skipContainer.Checked = Properties.Settings.Default.skipContainer;
|
||||||
assetsManager.ResolveDependencies = enableResolveDependencies.Checked;
|
assetsManager.ResolveDependencies = enableResolveDependencies.Checked;
|
||||||
SkipContainer = Properties.Settings.Default.skipContainer;
|
SkipContainer = Properties.Settings.Default.skipContainer;
|
||||||
@@ -2054,13 +2055,17 @@ namespace AssetStudio.GUI
|
|||||||
|
|
||||||
assetsManager.ResolveDependencies = enableResolveDependencies.Checked;
|
assetsManager.ResolveDependencies = enableResolveDependencies.Checked;
|
||||||
}
|
}
|
||||||
|
private void allowDuplicates_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Properties.Settings.Default.allowDuplicates = allowDuplicates.Checked;
|
||||||
|
Properties.Settings.Default.Save();
|
||||||
|
}
|
||||||
private void skipContainer_CheckedChanged(object sender, EventArgs e)
|
private void skipContainer_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Properties.Settings.Default.skipContainer = skipContainer.Checked;
|
Properties.Settings.Default.skipContainer = skipContainer.Checked;
|
||||||
Properties.Settings.Default.Save();
|
Properties.Settings.Default.Save();
|
||||||
|
|
||||||
SkipContainer = skipContainer.Checked;
|
SkipContainer = skipContainer.Checked;
|
||||||
|
|
||||||
}
|
}
|
||||||
private void assetMapTypeMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
private void assetMapTypeMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
12
AssetStudio.GUI/Properties/Settings.Designer.cs
generated
12
AssetStudio.GUI/Properties/Settings.Designer.cs
generated
@@ -469,5 +469,17 @@ namespace AssetStudio.GUI.Properties {
|
|||||||
this["uvs"] = value;
|
this["uvs"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||||
|
public bool allowDuplicates {
|
||||||
|
get {
|
||||||
|
return ((bool)(this["allowDuplicates"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["allowDuplicates"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,5 +113,8 @@
|
|||||||
<Setting Name="uvs" Type="System.String" Scope="User">
|
<Setting Name="uvs" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)">{"UV0":{"Item1":true,"Item2":0},"UV1":{"Item1":true,"Item2":1},"UV2":{"Item1":false,"Item2":0},"UV3":{"Item1":false,"Item2":0},"UV4":{"Item1":false,"Item2":0},"UV5":{"Item1":false,"Item2":0},"UV6":{"Item1":false,"Item2":0},"UV7":{"Item1":false,"Item2":0}}</Value>
|
<Value Profile="(Default)">{"UV0":{"Item1":true,"Item2":0},"UV1":{"Item1":true,"Item2":1},"UV2":{"Item1":false,"Item2":0},"UV3":{"Item1":false,"Item2":0},"UV4":{"Item1":false,"Item2":0},"UV5":{"Item1":false,"Item2":0},"UV6":{"Item1":false,"Item2":0},"UV7":{"Item1":false,"Item2":0}}</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="allowDuplicates" Type="System.Boolean" Scope="User">
|
||||||
|
<Value Profile="(Default)">False</Value>
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
Reference in New Issue
Block a user