Add additional batch export settings

This commit is contained in:
KillzXGaming 2019-11-10 13:00:20 -05:00
parent 678cbb7bdb
commit 4eb5ee8d37
3 changed files with 75 additions and 16 deletions

View file

@ -29,15 +29,20 @@
private void InitializeComponent()
{
this.comboBox1 = new Toolbox.Library.Forms.STComboBox();
this.button1 = new System.Windows.Forms.Button();
this.OkButton = new System.Windows.Forms.Button();
this.button1 = new Toolbox.Library.Forms.STButton();
this.OkButton = new Toolbox.Library.Forms.STButton();
this.chkSeperateTextureContainers = new Toolbox.Library.Forms.STCheckBox();
this.chkSeperateArchives = new Toolbox.Library.Forms.STCheckBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.DropDownStyle = Toolbox.Library.Forms.STComboBox.STDropDownStyle;
this.comboBox1.BorderColor = System.Drawing.Color.Empty;
this.comboBox1.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
this.comboBox1.ButtonColor = System.Drawing.Color.Empty;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(12, 41);
this.comboBox1.IsReadOnly = false;
this.comboBox1.Location = new System.Drawing.Point(12, 12);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(222, 21);
this.comboBox1.TabIndex = 0;
@ -47,7 +52,6 @@
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.ForeColor = System.Drawing.Color.White;
this.button1.Location = new System.Drawing.Point(171, 96);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(63, 23);
@ -59,7 +63,6 @@
//
this.OkButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.OkButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.OkButton.ForeColor = System.Drawing.Color.White;
this.OkButton.Location = new System.Drawing.Point(86, 96);
this.OkButton.Name = "OkButton";
this.OkButton.Size = new System.Drawing.Size(63, 23);
@ -68,25 +71,53 @@
this.OkButton.UseVisualStyleBackColor = true;
this.OkButton.Click += new System.EventHandler(this.OkButton_Click);
//
// TextureFormatExport
// chkSeperateTextureContainers
//
this.chkSeperateTextureContainers.AutoSize = true;
this.chkSeperateTextureContainers.Checked = true;
this.chkSeperateTextureContainers.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkSeperateTextureContainers.Location = new System.Drawing.Point(12, 39);
this.chkSeperateTextureContainers.Name = "chkSeperateTextureContainers";
this.chkSeperateTextureContainers.Size = new System.Drawing.Size(180, 17);
this.chkSeperateTextureContainers.TabIndex = 3;
this.chkSeperateTextureContainers.Text = "Use Folders for Texture Archives";
this.chkSeperateTextureContainers.UseVisualStyleBackColor = true;
//
// chkSeperateArchives
//
this.chkSeperateArchives.AutoSize = true;
this.chkSeperateArchives.Checked = true;
this.chkSeperateArchives.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkSeperateArchives.Location = new System.Drawing.Point(12, 62);
this.chkSeperateArchives.Name = "chkSeperateArchives";
this.chkSeperateArchives.Size = new System.Drawing.Size(160, 17);
this.chkSeperateArchives.TabIndex = 4;
this.chkSeperateArchives.Text = "Use Folders for Archive Files";
this.chkSeperateArchives.UseVisualStyleBackColor = true;
//
// BatchFormatExport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.ClientSize = new System.Drawing.Size(246, 131);
this.Controls.Add(this.chkSeperateArchives);
this.Controls.Add(this.chkSeperateTextureContainers);
this.Controls.Add(this.OkButton);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Name = "TextureFormatExport";
this.Name = "BatchFormatExport";
this.Text = "TextureFormatExport";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Toolbox.Library.Forms.STComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button OkButton;
private Toolbox.Library.Forms.STButton button1;
private Toolbox.Library.Forms.STButton OkButton;
private Forms.STCheckBox chkSeperateTextureContainers;
private Forms.STCheckBox chkSeperateArchives;
}
}

View file

@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Toolbox.Library.Forms;
namespace Toolbox.Library
{
@ -14,6 +15,14 @@ namespace Toolbox.Library
{
public int Index = 0;
public Settings BatchSettings = new Settings();
public class Settings
{
public bool SeperateTextureContainers;
public bool SeperateArchiveFiles;
}
public BatchFormatExport(List<string> Formats)
{
InitializeComponent();
@ -23,6 +32,9 @@ namespace Toolbox.Library
comboBox1.SelectedIndex = 0;
BackColor = FormThemes.BaseTheme.FormBackColor;
ForeColor = FormThemes.BaseTheme.FormForeColor;
Index = 0;
}
@ -47,6 +59,9 @@ namespace Toolbox.Library
private void OkButton_Click(object sender, EventArgs e)
{
BatchSettings.SeperateTextureContainers = chkSeperateTextureContainers.Checked;
BatchSettings.SeperateArchiveFiles = chkSeperateArchives.Checked;
this.Close();
}

View file

@ -1379,7 +1379,7 @@ namespace Toolbox
try
{
var fileFormat = STFileLoader.OpenFileFormat(file);
SearchFileFormat(fileFormat, extension, outputFolder);
SearchFileFormat(form.BatchSettings, fileFormat, extension, outputFolder);
}
catch
{
@ -1400,16 +1400,23 @@ namespace Toolbox
MessageBox.Show("Files batched successfully!");
}
private void SearchFileFormat(IFileFormat fileFormat, string extension, string outputFolder)
private void SearchFileFormat(BatchFormatExport.Settings settings, IFileFormat fileFormat, string extension, string outputFolder)
{
if (fileFormat == null) return;
if (fileFormat is STGenericTexture)
ExportTexture(((STGenericTexture)fileFormat), $"{outputFolder}/{fileFormat.FileName}.{extension}");
else if (fileFormat is IArchiveFile)
SearchArchive((IArchiveFile)fileFormat, extension, outputFolder);
SearchArchive(settings, (IArchiveFile)fileFormat, extension, outputFolder);
else if (fileFormat is ITextureContainer)
{
if (settings.SeperateTextureContainers)
{
outputFolder = Path.Combine(outputFolder, fileFormat.FileName);
if (!Directory.Exists(outputFolder))
Directory.CreateDirectory(outputFolder);
}
foreach (STGenericTexture tex in ((ITextureContainer)fileFormat).TextureList) {
ExportTexture(tex, $"{outputFolder}/{tex.Text}.{extension}");
}
@ -1422,10 +1429,16 @@ namespace Toolbox
tex.Export(filePath);
}
private void SearchArchive(IArchiveFile archiveFile, string extension, string outputFolder)
private void SearchArchive(BatchFormatExport.Settings settings, IArchiveFile archiveFile, string extension, string outputFolder)
{
string ArchiveFilePath = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(((IFileFormat)archiveFile).FileName));
if (!Directory.Exists(ArchiveFilePath))
Directory.CreateDirectory(ArchiveFilePath);
else
ArchiveFilePath = outputFolder;
foreach (var file in archiveFile.Files)
SearchFileFormat(file.OpenFile(), extension, outputFolder);
SearchFileFormat(settings, file.OpenFile(), extension, ArchiveFilePath);
}
}
}