- [Core] rework duplicate file processing [GUI/CLI]
This commit is contained in:
@@ -109,6 +109,9 @@
|
||||
<setting name="enableVerbose" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="allowDuplicates" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="texs" serializeAs="String">
|
||||
<value>{}</value>
|
||||
</setting>
|
||||
|
||||
@@ -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)
|
||||
|
||||
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();
|
||||
goToSceneHierarchyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
showOriginalFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
allowDuplicates = new System.Windows.Forms.ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
||||
splitContainer1.Panel1.SuspendLayout();
|
||||
@@ -264,7 +265,7 @@ namespace AssetStudio.GUI
|
||||
//
|
||||
// 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.Size = new System.Drawing.Size(61, 20);
|
||||
optionsToolStripMenuItem.Text = "Options";
|
||||
@@ -659,7 +660,7 @@ namespace AssetStudio.GUI
|
||||
allToolStripMenuItem.CheckOnClick = true;
|
||||
allToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
allToolStripMenuItem.Name = "allToolStripMenuItem";
|
||||
allToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
allToolStripMenuItem.Size = new System.Drawing.Size(88, 22);
|
||||
allToolStripMenuItem.Text = "All";
|
||||
allToolStripMenuItem.Click += typeToolStripMenuItem_Click;
|
||||
//
|
||||
@@ -1352,6 +1353,15 @@ namespace AssetStudio.GUI
|
||||
showOriginalFileToolStripMenuItem.Visible = false;
|
||||
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
|
||||
//
|
||||
AllowDrop = true;
|
||||
@@ -1542,6 +1552,7 @@ namespace AssetStudio.GUI
|
||||
private System.Windows.Forms.ToolStripMenuItem sceneHierarchy;
|
||||
private System.Windows.Forms.ToolStripMenuItem assetMapTypeMenuItem;
|
||||
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;
|
||||
modelsOnly.Checked = Properties.Settings.Default.modelsOnly;
|
||||
enableResolveDependencies.Checked = Properties.Settings.Default.enableResolveDependencies;
|
||||
allowDuplicates.Checked = Properties.Settings.Default.allowDuplicates;
|
||||
skipContainer.Checked = Properties.Settings.Default.skipContainer;
|
||||
assetsManager.ResolveDependencies = enableResolveDependencies.Checked;
|
||||
SkipContainer = Properties.Settings.Default.skipContainer;
|
||||
@@ -2054,13 +2055,17 @@ namespace AssetStudio.GUI
|
||||
|
||||
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)
|
||||
{
|
||||
Properties.Settings.Default.skipContainer = skipContainer.Checked;
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
SkipContainer = skipContainer.Checked;
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
[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">
|
||||
<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 Name="allowDuplicates" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
Reference in New Issue
Block a user