From f90c0ecc0006b3689457ff9122e2544ef323b541 Mon Sep 17 00:00:00 2001 From: VaDiM Date: Sun, 11 Feb 2024 02:24:06 +0300 Subject: [PATCH] Add option to export assets with PathID in filename (#25) https://github.com/Perfare/AssetStudio/issues/1050 https://github.com/Perfare/AssetStudio/issues/975 https://github.com/Perfare/AssetStudio/issues/762 --- AssetStudioCLI/Exporter.cs | 21 ++++++++-- AssetStudioCLI/Options/CLIOptions.cs | 41 ++++++++++++++++++- AssetStudioGUI/ExportOptions.Designer.cs | 28 +++++++++++++ AssetStudioGUI/ExportOptions.cs | 2 + AssetStudioGUI/Exporter.cs | 22 ++++++++-- .../Properties/Settings.Designer.cs | 12 ++++++ AssetStudioGUI/Properties/Settings.settings | 3 ++ 7 files changed, 120 insertions(+), 9 deletions(-) diff --git a/AssetStudioCLI/Exporter.cs b/AssetStudioCLI/Exporter.cs index 8b1289e..e44e389 100644 --- a/AssetStudioCLI/Exporter.cs +++ b/AssetStudioCLI/Exporter.cs @@ -315,17 +315,30 @@ namespace AssetStudioCLI private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath) { var fileName = FixFileName(item.Text); + var filenameFormat = CLIOptions.o_filenameFormat.Value; + switch (filenameFormat) + { + case FilenameFormat.AssetName_PathID: + fileName = $"{fileName} @{item.m_PathID}"; + break; + case FilenameFormat.PathID: + fileName = item.m_PathID.ToString(); + break; + } 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 (filenameFormat == FilenameFormat.AssetName) { - Directory.CreateDirectory(dir); - return true; + fullPath = Path.Combine(dir, fileName + item.UniqueID + extension); + if (!File.Exists(fullPath)) + { + Directory.CreateDirectory(dir); + return true; + } } Logger.Error($"Export error. File \"{fullPath.Color(ColorConsole.BrightRed)}\" already exist"); return false; diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 362325d..73cea34 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -37,6 +37,13 @@ namespace AssetStudioCLI.Options SourceFileName, } + internal enum FilenameFormat + { + AssetName, + AssetName_PathID, + PathID, + } + internal enum ExportListType { None, @@ -75,6 +82,7 @@ namespace AssetStudioCLI.Options public static Option o_workMode; public static Option> o_exportAssetTypes; public static Option o_groupAssetsBy; + public static Option o_filenameFormat; public static Option o_outputFolder; public static Option o_displayHelp; //logger @@ -200,7 +208,19 @@ namespace AssetStudioCLI.Options "Container - Group exported assets by container path\n" + "ContainerFull - Group exported assets by full container path (e.g. with prefab name)\n" + "Filename - Group exported assets by source file name\n", - optionExample: "Example: \"-g container\"\n", + optionExample: "Example: \"-g containerFull\"\n", + optionHelpGroup: HelpGroups.General + ); + o_filenameFormat = new GroupedOption + ( + optionDefaultValue: FilenameFormat.AssetName, + optionName: "-f, --filename-format ", + optionDescription: "Specify the file name format for exported assets\n" + + "\n" + + "AssetName - Asset file names will look like \"assetName.extension\"\n" + + "AssetName_pathID - Asset file names will look like \"assetName @pathID.extension\"\n" + + "PathID - Asset file names will look like \"pathID.extension\"\n", + optionExample: "Example: \"-f assetName_pathID\"\n", optionHelpGroup: HelpGroups.General ); o_outputFolder = new GroupedOption @@ -629,6 +649,25 @@ namespace AssetStudioCLI.Options return; } break; + case "-f": + case "--filename-format": + switch (value.ToLower()) + { + case "assetname": + o_filenameFormat.Value = FilenameFormat.AssetName; + break; + case "assetname_pathid": + o_filenameFormat.Value = FilenameFormat.AssetName_PathID; + break; + case "pathid": + o_filenameFormat.Value = FilenameFormat.PathID; + break; + default: + Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option}] option. Unsupported file name format: [{value.Color(brightRed)}].\n"); + ShowOptionDescription(o_filenameFormat.Description); + return; + } + break; case "-o": case "--output": try diff --git a/AssetStudioGUI/ExportOptions.Designer.cs b/AssetStudioGUI/ExportOptions.Designer.cs index c446b82..14ad708 100644 --- a/AssetStudioGUI/ExportOptions.Designer.cs +++ b/AssetStudioGUI/ExportOptions.Designer.cs @@ -32,6 +32,8 @@ this.OKbutton = new System.Windows.Forms.Button(); this.Cancel = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.filenameFormatLabel = new System.Windows.Forms.Label(); + this.filenameFormatComboBox = new System.Windows.Forms.ComboBox(); this.exportSpriteWithAlphaMask = new System.Windows.Forms.CheckBox(); this.openAfterExport = new System.Windows.Forms.CheckBox(); this.restoreExtensionName = new System.Windows.Forms.CheckBox(); @@ -104,6 +106,8 @@ // groupBox1 // this.groupBox1.AutoSize = true; + this.groupBox1.Controls.Add(this.filenameFormatLabel); + this.groupBox1.Controls.Add(this.filenameFormatComboBox); this.groupBox1.Controls.Add(this.exportSpriteWithAlphaMask); this.groupBox1.Controls.Add(this.openAfterExport); this.groupBox1.Controls.Add(this.restoreExtensionName); @@ -119,6 +123,28 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Export"; // + // filenameFormatLabel + // + this.filenameFormatLabel.AutoSize = true; + this.filenameFormatLabel.Location = new System.Drawing.Point(177, 18); + this.filenameFormatLabel.Name = "filenameFormatLabel"; + this.filenameFormatLabel.Size = new System.Drawing.Size(84, 13); + this.filenameFormatLabel.TabIndex = 10; + this.filenameFormatLabel.Text = "File name format"; + // + // filenameFormatComboBox + // + this.filenameFormatComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.filenameFormatComboBox.FormattingEnabled = true; + this.filenameFormatComboBox.Items.AddRange(new object[] { + "assetName", + "assetName@pathID", + "pathID"}); + this.filenameFormatComboBox.Location = new System.Drawing.Point(177, 35); + this.filenameFormatComboBox.Name = "filenameFormatComboBox"; + this.filenameFormatComboBox.Size = new System.Drawing.Size(118, 21); + this.filenameFormatComboBox.TabIndex = 9; + // // exportSpriteWithAlphaMask // this.exportSpriteWithAlphaMask.AutoSize = true; @@ -646,5 +672,7 @@ private System.Windows.Forms.RadioButton l2dAnimationClipRadioButton; private System.Windows.Forms.RadioButton l2dMonoBehaviourRadioButton; private System.Windows.Forms.Panel l2dMotionExportMethodPanel; + private System.Windows.Forms.ComboBox filenameFormatComboBox; + private System.Windows.Forms.Label filenameFormatLabel; } } \ No newline at end of file diff --git a/AssetStudioGUI/ExportOptions.cs b/AssetStudioGUI/ExportOptions.cs index 00407cc..ec5242d 100644 --- a/AssetStudioGUI/ExportOptions.cs +++ b/AssetStudioGUI/ExportOptions.cs @@ -33,6 +33,7 @@ namespace AssetStudioGUI var defaultMotionMode = Properties.Settings.Default.l2dMotionMode.ToString(); ((RadioButton)l2dMotionExportMethodPanel.Controls.Cast().First(x => x.AccessibleName == defaultMotionMode)).Checked = true; l2dForceBezierCheckBox.Checked = Properties.Settings.Default.l2dForceBezier; + filenameFormatComboBox.SelectedIndex = Properties.Settings.Default.filenameFormat; } private void OKbutton_Click(object sender, EventArgs e) @@ -60,6 +61,7 @@ namespace AssetStudioGUI var checkedMotionMode = (RadioButton)l2dMotionExportMethodPanel.Controls.Cast().First(x => ((RadioButton)x).Checked); Properties.Settings.Default.l2dMotionMode = (CubismLive2DExtractor.Live2DMotionMode)Enum.Parse(typeof(CubismLive2DExtractor.Live2DMotionMode), checkedMotionMode.AccessibleName); Properties.Settings.Default.l2dForceBezier = l2dForceBezierCheckBox.Checked; + Properties.Settings.Default.filenameFormat = filenameFormatComboBox.SelectedIndex; Properties.Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); diff --git a/AssetStudioGUI/Exporter.cs b/AssetStudioGUI/Exporter.cs index 1621bc7..b81ccaa 100644 --- a/AssetStudioGUI/Exporter.cs +++ b/AssetStudioGUI/Exporter.cs @@ -269,18 +269,32 @@ namespace AssetStudioGUI private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath) { var fileName = FixFileName(item.Text); + var filenameFormatIndex = Properties.Settings.Default.filenameFormat; + switch (filenameFormatIndex) + { + case 1: //assetName@pathID + fileName = $"{fileName} @{item.m_PathID}"; + break; + case 2: //pathID + fileName = item.m_PathID.ToString(); + break; + } 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 (filenameFormatIndex == 0) //assetName { - Directory.CreateDirectory(dir); - return true; + fullPath = Path.Combine(dir, fileName + item.UniqueID + extension); + if (!File.Exists(fullPath)) + { + Directory.CreateDirectory(dir); + return true; + } } + Logger.Warning($"Export error. File \"{fullPath.Color(ColorConsole.BrightYellow)}\" already exist"); return false; } diff --git a/AssetStudioGUI/Properties/Settings.Designer.cs b/AssetStudioGUI/Properties/Settings.Designer.cs index ba4564d..9ce6082 100644 --- a/AssetStudioGUI/Properties/Settings.Designer.cs +++ b/AssetStudioGUI/Properties/Settings.Designer.cs @@ -346,5 +346,17 @@ namespace AssetStudioGUI.Properties { this["buildTreeStructure"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int filenameFormat { + get { + return ((int)(this["filenameFormat"])); + } + set { + this["filenameFormat"] = value; + } + } } } diff --git a/AssetStudioGUI/Properties/Settings.settings b/AssetStudioGUI/Properties/Settings.settings index 203d1ad..7594d73 100644 --- a/AssetStudioGUI/Properties/Settings.settings +++ b/AssetStudioGUI/Properties/Settings.settings @@ -83,5 +83,8 @@ True + + 0 + \ No newline at end of file