Add batch export option for all supported texture formats.
This commit is contained in:
parent
c3e070d981
commit
616a2604c4
@ -116,9 +116,11 @@ namespace FirstPlugin
|
||||
LoadBMD(BMDFile);
|
||||
}
|
||||
|
||||
private class BMDTextureFolder : STTextureFolder, ITextureIconLoader
|
||||
private class BMDTextureFolder : STTextureFolder, ITextureContainer
|
||||
{
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -272,13 +272,15 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public class TextureFolder : TreeNodeCustom, IContextMenuNode, ITextureIconLoader
|
||||
public class TextureFolder : TreeNodeCustom, IContextMenuNode, ITextureContainer
|
||||
{
|
||||
public TextureFolder(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public ToolStripItem[] GetContextMenuItems()
|
||||
{
|
||||
return new ToolStripItem[]
|
||||
@ -287,7 +289,7 @@ namespace FirstPlugin
|
||||
};
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -496,9 +496,11 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private class TextureFolder : STTextureFolder, ITextureIconLoader
|
||||
private class TextureFolder : STTextureFolder, ITextureContainer
|
||||
{
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ using Toolbox.Library.Forms;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class CTXB : TreeNodeFile, IFileFormat, ITextureIconLoader
|
||||
public class CTXB : TreeNodeFile, IFileFormat, ITextureContainer
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Archive;
|
||||
|
||||
@ -39,7 +39,9 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ using System.Drawing;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class G1T : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureIconLoader
|
||||
public class G1T : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Image;
|
||||
|
||||
@ -38,8 +38,9 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ namespace LayoutBXLYT
|
||||
{
|
||||
TPL tpl = (TPL)file.OpenFile();
|
||||
file.FileFormat = tpl;
|
||||
foreach (var tex in tpl.IconTextureList)
|
||||
foreach (var tex in tpl.TextureList)
|
||||
{
|
||||
//Only need the first texture
|
||||
if (!textures.ContainsKey(tex.Text))
|
||||
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace FirstPlugin.NLG
|
||||
{
|
||||
public class StrikersRLT : TreeNodeFile, IFileFormat, ITextureIconLoader
|
||||
public class StrikersRLT : TreeNodeFile, IFileFormat, ITextureContainer
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Image;
|
||||
|
||||
@ -37,7 +37,9 @@ namespace FirstPlugin.NLG
|
||||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ using FirstPlugin.Forms;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class BNTX : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureIconLoader
|
||||
public class BNTX : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer
|
||||
{
|
||||
public bool LoadIcons = false;
|
||||
|
||||
@ -58,7 +58,9 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => LoadIcons;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -563,7 +565,7 @@ namespace FirstPlugin
|
||||
public void LoadFile(Stream stream, string Name = "")
|
||||
{
|
||||
Textures = new Dictionary<string, TextureData>(StringComparer.InvariantCultureIgnoreCase);
|
||||
IconTextureList = new List<STGenericTexture>();
|
||||
TextureList = new List<STGenericTexture>();
|
||||
|
||||
BinaryTexFile = new BntxFile(stream);
|
||||
Text = BinaryTexFile.Name;
|
||||
|
@ -12,7 +12,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class CTPK : TreeNodeFile, IFileFormat, ITextureIconLoader
|
||||
public class CTPK : TreeNodeFile, IFileFormat, ITextureContainer
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Layout;
|
||||
|
||||
@ -31,7 +31,9 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ using Toolbox.Library.IO;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class TPL : TreeNodeFile, IFileFormat, ITextureIconLoader
|
||||
public class TPL : TreeNodeFile, IFileFormat, ITextureContainer
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Image;
|
||||
|
||||
@ -40,7 +40,9 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
public bool DisplayIcons => true;
|
||||
|
||||
public List<STGenericTexture> TextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -34,8 +34,7 @@ namespace Toolbox.Library
|
||||
reader.ReadUInt16();
|
||||
|
||||
IsValid = magicNumber == 0x789C || magicNumber == 0x78DA;
|
||||
if (IsValid)
|
||||
{
|
||||
if (IsValid) {
|
||||
startPosition = reader.Position - 4;
|
||||
break;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace Toolbox.Library
|
||||
{
|
||||
private readonly Dictionary<int, TreeNode> _treeNodes = new Dictionary<int, TreeNode>();
|
||||
|
||||
public List<ITextureIconLoader> TextureIcons = new List<ITextureIconLoader>();
|
||||
public List<ITextureContainer> TextureIcons = new List<ITextureContainer>();
|
||||
public List<ISingleTextureIconLoader> SingleTextureIcons = new List<ISingleTextureIconLoader>();
|
||||
|
||||
public TreeViewCustom()
|
||||
@ -113,7 +113,10 @@ namespace Toolbox.Library
|
||||
{
|
||||
for (int i = 0; i < TextureIcons.Count; i++)
|
||||
{
|
||||
foreach (TreeNode node in TextureIcons[i].IconTextureList)
|
||||
if (!TextureIcons[i].DisplayIcons)
|
||||
continue;
|
||||
|
||||
foreach (TreeNode node in TextureIcons[i].TextureList)
|
||||
{
|
||||
if (node is STGenericTexture)
|
||||
{
|
||||
@ -268,8 +271,11 @@ namespace Toolbox.Library
|
||||
Thread.Start();
|
||||
}
|
||||
|
||||
public void ReloadTextureIcons(ITextureIconLoader textureIconList)
|
||||
public void ReloadTextureIcons(ITextureContainer textureIconList)
|
||||
{
|
||||
if (!textureIconList.DisplayIcons)
|
||||
return;
|
||||
|
||||
if (Thread != null && Thread.IsAlive)
|
||||
Thread.Abort();
|
||||
|
||||
@ -280,7 +286,7 @@ namespace Toolbox.Library
|
||||
List<TreeNode> treeNodes = new List<TreeNode>();
|
||||
List<Image> imageIcons = new List<Image>();
|
||||
|
||||
foreach (TreeNode node in textureIconList.IconTextureList)
|
||||
foreach (TreeNode node in textureIconList.TextureList)
|
||||
{
|
||||
if (node is STGenericTexture)
|
||||
{
|
||||
|
@ -100,8 +100,8 @@ namespace Toolbox.Library.Forms
|
||||
AddNode((TreeNode)FileFormat);
|
||||
}
|
||||
|
||||
if (FileFormat is ITextureIconLoader) {
|
||||
ObjectTree.LoadGenericTextureIcons((ITextureIconLoader)FileFormat);
|
||||
if (FileFormat is ITextureContainer) {
|
||||
ObjectTree.LoadGenericTextureIcons((ITextureContainer)FileFormat);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -829,7 +829,7 @@ namespace Toolbox.Library.Forms
|
||||
treeViewCustom1.ReloadTextureIcons(texIcons, false);
|
||||
}
|
||||
|
||||
public void LoadGenericTextureIcons(ITextureIconLoader iconList) {
|
||||
public void LoadGenericTextureIcons(ITextureContainer iconList) {
|
||||
treeViewCustom1.TextureIcons.Add(iconList);
|
||||
treeViewCustom1.ReloadTextureIcons(iconList);
|
||||
}
|
||||
@ -870,9 +870,9 @@ namespace Toolbox.Library.Forms
|
||||
{
|
||||
if (e.Node == null) return;
|
||||
|
||||
else if (e.Node is ITextureIconLoader) {
|
||||
else if (e.Node is ITextureContainer) {
|
||||
treeViewCustom1.BeginUpdate();
|
||||
LoadGenericTextureIcons((ITextureIconLoader)e.Node);
|
||||
LoadGenericTextureIcons((ITextureContainer)e.Node);
|
||||
treeViewCustom1.EndUpdate();
|
||||
}
|
||||
else if (e.Node is ISingleTextureIconLoader) {
|
||||
|
@ -8,6 +8,8 @@ namespace Toolbox.Library
|
||||
{
|
||||
public interface ITextureContainer
|
||||
{
|
||||
Dictionary<string, STGenericTexture> Textures { get; set; }
|
||||
List<STGenericTexture> TextureList { get; set; }
|
||||
|
||||
bool DisplayIcons { get; }
|
||||
}
|
||||
}
|
||||
|
@ -6,15 +6,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Toolbox.Library
|
||||
{
|
||||
/// <summary>
|
||||
/// A texture list to display icons on a treeview
|
||||
/// Note these will load and attach an icon when the parent treenode is expanded!
|
||||
/// </summary>
|
||||
public interface ITextureIconLoader
|
||||
{
|
||||
List<STGenericTexture> IconTextureList { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reprenets a single texture that loads an icon.
|
||||
/// These will check both on expand, and on root
|
||||
|
@ -337,12 +337,15 @@ namespace Toolbox.Library.Rendering
|
||||
|
||||
foreach (var container in TextureContainers)
|
||||
{
|
||||
if (container.Textures.ContainsKey(activeTex))
|
||||
for (int i = 0; i < container.TextureList?.Count; i++)
|
||||
{
|
||||
BindGLTexture(tex, shader, container.Textures[activeTex]);
|
||||
if (activeTex == container.TextureList[i].Text)
|
||||
{
|
||||
BindGLTexture(tex, shader, container.TextureList[i]);
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tex.textureUnit + 1;
|
||||
}
|
||||
|
28
Toolbox/MainForm.Designer.cs
generated
28
Toolbox/MainForm.Designer.cs
generated
@ -44,6 +44,7 @@
|
||||
this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.compressionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.batchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.hashCalculatorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.experimentalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.windowsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.cascadeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@ -72,7 +73,7 @@
|
||||
this.stToolStrip1 = new Toolbox.Library.Forms.STToolStrip();
|
||||
this.saveToolStripButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.updateToolstrip = new System.Windows.Forms.ToolStripButton();
|
||||
this.hashCalculatorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.batchExportTexturesAllSupportedFormatsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.stPanel1.SuspendLayout();
|
||||
this.tabControlContextMenuStrip.SuspendLayout();
|
||||
@ -185,7 +186,8 @@
|
||||
this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.compressionToolStripMenuItem,
|
||||
this.batchToolStripMenuItem,
|
||||
this.hashCalculatorToolStripMenuItem});
|
||||
this.hashCalculatorToolStripMenuItem,
|
||||
this.batchExportTexturesAllSupportedFormatsToolStripMenuItem});
|
||||
this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
|
||||
this.toolsToolStripMenuItem.Size = new System.Drawing.Size(47, 21);
|
||||
this.toolsToolStripMenuItem.Text = "Tools";
|
||||
@ -193,16 +195,23 @@
|
||||
// compressionToolStripMenuItem
|
||||
//
|
||||
this.compressionToolStripMenuItem.Name = "compressionToolStripMenuItem";
|
||||
this.compressionToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.compressionToolStripMenuItem.Size = new System.Drawing.Size(315, 22);
|
||||
this.compressionToolStripMenuItem.Text = "Compression";
|
||||
//
|
||||
// batchToolStripMenuItem
|
||||
//
|
||||
this.batchToolStripMenuItem.Name = "batchToolStripMenuItem";
|
||||
this.batchToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.batchToolStripMenuItem.Size = new System.Drawing.Size(315, 22);
|
||||
this.batchToolStripMenuItem.Text = "Batch Set File Table";
|
||||
this.batchToolStripMenuItem.Click += new System.EventHandler(this.batchToolStripMenuItem_Click);
|
||||
//
|
||||
// hashCalculatorToolStripMenuItem
|
||||
//
|
||||
this.hashCalculatorToolStripMenuItem.Name = "hashCalculatorToolStripMenuItem";
|
||||
this.hashCalculatorToolStripMenuItem.Size = new System.Drawing.Size(315, 22);
|
||||
this.hashCalculatorToolStripMenuItem.Text = "Hash Calculator";
|
||||
this.hashCalculatorToolStripMenuItem.Click += new System.EventHandler(this.hashCalculatorToolStripMenuItem_Click);
|
||||
//
|
||||
// experimentalToolStripMenuItem
|
||||
//
|
||||
this.experimentalToolStripMenuItem.Name = "experimentalToolStripMenuItem";
|
||||
@ -465,12 +474,12 @@
|
||||
this.updateToolstrip.ToolTipText = "Update Tool";
|
||||
this.updateToolstrip.Click += new System.EventHandler(this.updateToolstrip_Click);
|
||||
//
|
||||
// hashCalculatorToolStripMenuItem
|
||||
// batchExportTexturesAllSupportedFormatsToolStripMenuItem
|
||||
//
|
||||
this.hashCalculatorToolStripMenuItem.Name = "hashCalculatorToolStripMenuItem";
|
||||
this.hashCalculatorToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.hashCalculatorToolStripMenuItem.Text = "Hash Calculator";
|
||||
this.hashCalculatorToolStripMenuItem.Click += new System.EventHandler(this.hashCalculatorToolStripMenuItem_Click);
|
||||
this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Name = "batchExportTexturesAllSupportedFormatsToolStripMenuItem";
|
||||
this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Size = new System.Drawing.Size(315, 22);
|
||||
this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Text = "Batch Export Textures (All Supported Formats)";
|
||||
this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Click += new System.EventHandler(this.batchExportTexturesAllSupportedFormatsToolStripMenuItem_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
@ -552,5 +561,6 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem openFolderToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem batchToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem hashCalculatorToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem batchExportTexturesAllSupportedFormatsToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -1343,5 +1343,89 @@ namespace Toolbox
|
||||
HashCalculatorForm form = new HashCalculatorForm();
|
||||
form.Show(this);
|
||||
}
|
||||
|
||||
private void batchExportTexturesAllSupportedFormatsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Multiselect = true;
|
||||
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
FolderSelectDialog folderDlg = new FolderSelectDialog();
|
||||
if (folderDlg.ShowDialog() == DialogResult.OK) {
|
||||
BatchExportTextures(ofd.FileNames, folderDlg.SelectedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BatchExportTextures(string[] files, string outputFolder)
|
||||
{
|
||||
List<string> Formats = new List<string>();
|
||||
Formats.Add("Portable Graphics Network (.png)");
|
||||
Formats.Add("Microsoft DDS (.dds)");
|
||||
Formats.Add("Joint Photographic Experts Group (.jpg)");
|
||||
Formats.Add("Bitmap Image (.bmp)");
|
||||
Formats.Add("Tagged Image File Format (.tiff)");
|
||||
Formats.Add("ASTC (.astc)");
|
||||
|
||||
List<string> failedFiles = new List<string>();
|
||||
|
||||
BatchFormatExport form = new BatchFormatExport(Formats);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string extension = form.GetSelectedExtension();
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileFormat = STFileLoader.OpenFileFormat(file);
|
||||
SearchFileFormat(fileFormat, extension, outputFolder);
|
||||
}
|
||||
catch
|
||||
{
|
||||
failedFiles.Add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failedFiles.Count > 0)
|
||||
{
|
||||
string detailList = "";
|
||||
foreach (var file in failedFiles)
|
||||
detailList += $"{file}\n";
|
||||
|
||||
STErrorDialog.Show("Some files failed to export! See detail list of failed files.", "Switch Toolbox", detailList);
|
||||
}
|
||||
else
|
||||
MessageBox.Show("Files batched successfully!");
|
||||
}
|
||||
|
||||
private void SearchFileFormat(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);
|
||||
else if (fileFormat is ITextureContainer)
|
||||
{
|
||||
foreach (STGenericTexture tex in ((ITextureContainer)fileFormat).TextureList) {
|
||||
ExportTexture(tex, $"{outputFolder}/{tex.Text}.{extension}");
|
||||
}
|
||||
}
|
||||
|
||||
fileFormat.Unload();
|
||||
}
|
||||
|
||||
private void ExportTexture(STGenericTexture tex, string filePath) {
|
||||
tex.Export(filePath);
|
||||
}
|
||||
|
||||
private void SearchArchive(IArchiveFile archiveFile, string extension, string outputFolder)
|
||||
{
|
||||
foreach (var file in archiveFile.Files)
|
||||
SearchFileFormat(file.OpenFile(), extension, outputFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user