From da216dace8e8925abbdc097766fb05be149875b2 Mon Sep 17 00:00:00 2001 From: VaDiM Date: Mon, 22 May 2023 22:26:29 +0300 Subject: [PATCH] Improve "Restore TextAsset extension name" option - If checked, AssetStudio will first try to find an extension in an asset's name and only then in its container. If no extension is found, ".txt" will be used --- AssetStudioCLI/Exporter.cs | 13 +++++++++++-- AssetStudioCLI/Options/CLIOptions.cs | 2 +- AssetStudioGUI/ExportOptions.Designer.cs | 7 ++++--- AssetStudioGUI/Exporter.cs | 15 ++++++++++++--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/AssetStudioCLI/Exporter.cs b/AssetStudioCLI/Exporter.cs index a8c4a6b..fef11a0 100644 --- a/AssetStudioCLI/Exporter.cs +++ b/AssetStudioCLI/Exporter.cs @@ -138,11 +138,20 @@ namespace AssetStudioCLI { var m_TextAsset = (TextAsset)item.Asset; var extension = ".txt"; + var assetExtension = Path.GetExtension(m_TextAsset.m_Name); if (!options.f_notRestoreExtensionName.Value) { - if (!string.IsNullOrEmpty(item.Container)) + if (!string.IsNullOrEmpty(assetExtension)) { - extension = Path.GetExtension(item.Container); + extension = ""; + } + else if (!string.IsNullOrEmpty(item.Container)) + { + var ext = Path.GetExtension(item.Container); + if (!string.IsNullOrEmpty(item.Container)) + { + extension = ext; + } } } if (!TryExportFile(exportPath, item, extension, out var exportFullPath)) diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 5147ec7..892a30d 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -293,7 +293,7 @@ namespace AssetStudioCLI.Options ( optionDefaultValue: false, optionName: "--not-restore-extension", - optionDescription: "(Flag) If specified, AssetStudio will not try to restore TextAssets extension name, \nand will just export all TextAssets with the \".txt\" extension", + optionDescription: "(Flag) If specified, AssetStudio will not try to use/restore original TextAsset\nextension name, and will just export all TextAssets with the \".txt\" extension", optionHelpGroup: HelpGroups.Advanced, isFlag: true ); diff --git a/AssetStudioGUI/ExportOptions.Designer.cs b/AssetStudioGUI/ExportOptions.Designer.cs index d2c37ab..a99aa21 100644 --- a/AssetStudioGUI/ExportOptions.Designer.cs +++ b/AssetStudioGUI/ExportOptions.Designer.cs @@ -142,9 +142,10 @@ this.restoreExtensionName.CheckState = System.Windows.Forms.CheckState.Checked; this.restoreExtensionName.Location = new System.Drawing.Point(6, 63); this.restoreExtensionName.Name = "restoreExtensionName"; - this.restoreExtensionName.Size = new System.Drawing.Size(190, 17); + this.restoreExtensionName.Size = new System.Drawing.Size(275, 17); this.restoreExtensionName.TabIndex = 9; - this.restoreExtensionName.Text = "Restore TextAsset extension name"; + this.restoreExtensionName.Text = "Try to restore/Use original TextAsset extension name"; + this.exportUvsTooltip.SetToolTip(this.restoreExtensionName, "If not checked, AssetStudio will export all TextAssets with the \".txt\" extension"); this.restoreExtensionName.UseVisualStyleBackColor = true; // // assetGroupOptions @@ -508,7 +509,7 @@ this.MinimizeBox = false; this.Name = "ExportOptions"; this.ShowIcon = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Export options"; this.TopMost = true; this.groupBox1.ResumeLayout(false); diff --git a/AssetStudioGUI/Exporter.cs b/AssetStudioGUI/Exporter.cs index 700e456..1621bc7 100644 --- a/AssetStudioGUI/Exporter.cs +++ b/AssetStudioGUI/Exporter.cs @@ -75,13 +75,22 @@ namespace AssetStudioGUI public static bool ExportTextAsset(AssetItem item, string exportPath) { - var m_TextAsset = (TextAsset)(item.Asset); + var m_TextAsset = (TextAsset)item.Asset; var extension = ".txt"; + var assetExtension = Path.GetExtension(m_TextAsset.m_Name); if (Properties.Settings.Default.restoreExtensionName) { - if (!string.IsNullOrEmpty(item.Container)) + if (!string.IsNullOrEmpty(assetExtension)) { - extension = Path.GetExtension(item.Container); + extension = ""; + } + else if (!string.IsNullOrEmpty(item.Container)) + { + var ext = Path.GetExtension(item.Container); + if (!string.IsNullOrEmpty(item.Container)) + { + extension = ext; + } } } if (!TryExportFile(exportPath, item, extension, out var exportFullPath))