VaDiM 2024-02-11 02:24:06 +03:00
parent 535153be6b
commit f90c0ecc00
7 changed files with 120 additions and 9 deletions

View File

@ -315,18 +315,31 @@ 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;
}
if (filenameFormat == FilenameFormat.AssetName)
{
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;
}

View File

@ -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<WorkMode> o_workMode;
public static Option<List<ClassIDType>> o_exportAssetTypes;
public static Option<AssetGroupOption> o_groupAssetsBy;
public static Option<FilenameFormat> o_filenameFormat;
public static Option<string> o_outputFolder;
public static Option<bool> 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<FilenameFormat>
(
optionDefaultValue: FilenameFormat.AssetName,
optionName: "-f, --filename-format <value>",
optionDescription: "Specify the file name format for exported assets\n" +
"<Value: assetName(default) | assetName_pathID | pathID>\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<string>
@ -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

View File

@ -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;
}
}

View File

@ -33,6 +33,7 @@ namespace AssetStudioGUI
var defaultMotionMode = Properties.Settings.Default.l2dMotionMode.ToString();
((RadioButton)l2dMotionExportMethodPanel.Controls.Cast<Control>().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<Control>().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();

View File

@ -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;
}
if (filenameFormatIndex == 0) //assetName
{
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;
}

View File

@ -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;
}
}
}
}

View File

@ -83,5 +83,8 @@
<Setting Name="buildTreeStructure" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="filenameFormat" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>