From 251854cc41ff08c7fd14d25c43ae9fa2fad887a4 Mon Sep 17 00:00:00 2001 From: Joshua May Date: Sat, 17 Apr 2021 19:27:15 +0200 Subject: [PATCH] Adds exporter for list of assets to XML (#710) --- AssetStudioGUI/AssetStudioGUIForm.Designer.cs | 50 +++++++++++- AssetStudioGUI/AssetStudioGUIForm.cs | 76 +++++++++++++++---- AssetStudioGUI/Studio.cs | 59 +++++++++++++- 3 files changed, 169 insertions(+), 16 deletions(-) diff --git a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs index 156e8085..6adce6d9 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs @@ -64,6 +64,11 @@ private void InitializeComponent() this.toolStripMenuItem7 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem8 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem9 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripMenuItem10 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem11 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem12 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem13 = new System.Windows.Forms.ToolStripMenuItem(); this.filterTypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.allToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.debugMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -314,7 +319,9 @@ private void InitializeComponent() this.exportAnimatorWithSelectedAnimationClipToolStripMenuItem, this.toolStripSeparator4, this.toolStripMenuItem2, - this.toolStripMenuItem3}); + this.toolStripMenuItem3, + this.toolStripSeparator2, + this.toolStripMenuItem10}); this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; this.exportToolStripMenuItem.Size = new System.Drawing.Size(58, 21); this.exportToolStripMenuItem.Text = "Export"; @@ -419,6 +426,42 @@ private void InitializeComponent() this.toolStripMenuItem9.Text = "Filtered assets"; this.toolStripMenuItem9.Click += new System.EventHandler(this.toolStripMenuItem9_Click); // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(396, 6); + // + // toolStripMenuItem10 + // + this.toolStripMenuItem10.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem11, + this.toolStripMenuItem12, + this.toolStripMenuItem13}); + this.toolStripMenuItem10.Name = "toolStripMenuItem10"; + this.toolStripMenuItem10.Size = new System.Drawing.Size(399, 34); + this.toolStripMenuItem10.Text = "Asset list to XML"; + // + // toolStripMenuItem11 + // + this.toolStripMenuItem11.Name = "toolStripMenuItem11"; + this.toolStripMenuItem11.Size = new System.Drawing.Size(270, 34); + this.toolStripMenuItem11.Text = "All assets"; + this.toolStripMenuItem11.Click += new System.EventHandler(this.toolStripMenuItem11_Click); + // + // toolStripMenuItem12 + // + this.toolStripMenuItem12.Name = "toolStripMenuItem12"; + this.toolStripMenuItem12.Size = new System.Drawing.Size(270, 34); + this.toolStripMenuItem12.Text = "Selected assets"; + this.toolStripMenuItem12.Click += new System.EventHandler(this.toolStripMenuItem12_Click); + // + // toolStripMenuItem13 + // + this.toolStripMenuItem13.Name = "toolStripMenuItem13"; + this.toolStripMenuItem13.Size = new System.Drawing.Size(270, 34); + this.toolStripMenuItem13.Text = "Filtered assets"; + this.toolStripMenuItem13.Click += new System.EventHandler(this.toolStripMenuItem13_Click); + // // filterTypeToolStripMenuItem // this.filterTypeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -1130,6 +1173,11 @@ private void InitializeComponent() private System.Windows.Forms.TabPage tabPage4; private System.Windows.Forms.TabPage tabPage5; private System.Windows.Forms.TextBox dumpTextBox; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem10; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem11; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem12; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem13; } } diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index d9f8f2e2..b665cd12 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -1274,7 +1274,7 @@ private void copyToolStripMenuItem_Click(object sender, EventArgs e) private void exportSelectedAssetsToolStripMenuItem_Click(object sender, EventArgs e) { - ExportAssets(2, ExportType.Convert); + ExportAssets(ExportFilter.Selected, ExportType.Convert); } private void showOriginalFileToolStripMenuItem_Click(object sender, EventArgs e) @@ -1398,47 +1398,62 @@ private void goToSceneHierarchyToolStripMenuItem_Click(object sender, EventArgs private void exportAllAssetsMenuItem_Click(object sender, EventArgs e) { - ExportAssets(1, ExportType.Convert); + ExportAssets(ExportFilter.All, ExportType.Convert); } private void exportSelectedAssetsMenuItem_Click(object sender, EventArgs e) { - ExportAssets(2, ExportType.Convert); + ExportAssets(ExportFilter.Selected, ExportType.Convert); } private void exportFilteredAssetsMenuItem_Click(object sender, EventArgs e) { - ExportAssets(3, ExportType.Convert); + ExportAssets(ExportFilter.Filtered, ExportType.Convert); } private void toolStripMenuItem4_Click(object sender, EventArgs e) { - ExportAssets(1, ExportType.Raw); + ExportAssets(ExportFilter.All, ExportType.Raw); } private void toolStripMenuItem5_Click(object sender, EventArgs e) { - ExportAssets(2, ExportType.Raw); + ExportAssets(ExportFilter.Selected, ExportType.Raw); } private void toolStripMenuItem6_Click(object sender, EventArgs e) { - ExportAssets(3, ExportType.Raw); + ExportAssets(ExportFilter.Filtered, ExportType.Raw); } private void toolStripMenuItem7_Click(object sender, EventArgs e) { - ExportAssets(1, ExportType.Dump); + ExportAssets(ExportFilter.All, ExportType.Dump); } private void toolStripMenuItem8_Click(object sender, EventArgs e) { - ExportAssets(2, ExportType.Dump); + ExportAssets(ExportFilter.Selected, ExportType.Dump); } private void toolStripMenuItem9_Click(object sender, EventArgs e) { - ExportAssets(3, ExportType.Dump); + ExportAssets(ExportFilter.Filtered, ExportType.Dump); + } + + private void toolStripMenuItem11_Click(object sender, EventArgs e) + { + ExportAssetsList(ExportFilter.All); + } + + private void toolStripMenuItem12_Click(object sender, EventArgs e) + { + ExportAssetsList(ExportFilter.Selected); + } + + private void toolStripMenuItem13_Click(object sender, EventArgs e) + { + ExportAssetsList(ExportFilter.Filtered); } private void exportAllObjectssplitToolStripMenuItem1_Click(object sender, EventArgs e) @@ -1501,7 +1516,7 @@ private void FilterAssetList() assetListView.EndUpdate(); } - private void ExportAssets(int type, ExportType exportType) + private void ExportAssets(ExportFilter type, ExportType exportType) { if (exportableAssets.Count > 0) { @@ -1513,13 +1528,13 @@ private void ExportAssets(int type, ExportType exportType) List toExportAssets = null; switch (type) { - case 1: //All Assets + case ExportFilter.All: toExportAssets = exportableAssets; break; - case 2: //Selected Assets + case ExportFilter.Selected: toExportAssets = GetSelectedAssets(); break; - case 3: //Filtered Assets + case ExportFilter.Filtered: toExportAssets = visibleAssets; break; } @@ -1532,6 +1547,39 @@ private void ExportAssets(int type, ExportType exportType) } } + private void ExportAssetsList(ExportFilter type) + { + // XXX: Only exporting as XML for now, but would JSON(/CSV/other) be useful too? + + if (exportableAssets.Count > 0) + { + var saveFolderDialog = new OpenFolderDialog(); + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) + { + timer.Stop(); + + List toExportAssets = null; + switch (type) + { + case ExportFilter.All: + toExportAssets = exportableAssets; + break; + case ExportFilter.Selected: + toExportAssets = GetSelectedAssets(); + break; + case ExportFilter.Filtered: + toExportAssets = visibleAssets; + break; + } + Studio.ExportAssetsList(saveFolderDialog.Folder, toExportAssets, ExportListType.XML); + } + } + else + { + StatusStripUpdate("No exportable assets loaded"); + } + } + #region FMOD private void FMODinit() { diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index fdbc260d..c301d3d5 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -5,9 +5,9 @@ using System.Globalization; using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Windows.Forms; +using System.Xml.Linq; using static AssetStudioGUI.Exporter; using Object = AssetStudio.Object; @@ -20,6 +20,18 @@ internal enum ExportType Dump } + internal enum ExportFilter + { + All, + Selected, + Filtered + } + + internal enum ExportListType + { + XML + } + internal static class Studio { public static AssetsManager assetsManager = new AssetsManager(); @@ -442,6 +454,51 @@ public static void ExportAssets(string savePath, List toExportAssets, }); } + public static void ExportAssetsList(string savePath, List toExportAssets, ExportListType exportListType) + { + ThreadPool.QueueUserWorkItem(state => + { + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); + + Progress.Reset(); + + switch (exportListType) + { + case ExportListType.XML: + var filename = Path.Combine(savePath, "assets.xml"); + var doc = new XDocument( + new XElement("Assets", + new XAttribute("filename", filename), + new XAttribute("createdAt", DateTime.UtcNow.ToString("s")), + toExportAssets.Select( + asset => new XElement("Asset", + new XElement("Name", asset.Text), + new XElement("Container", asset.Container), + new XElement("Type", new XAttribute("id", (int)asset.Type), asset.TypeString), + new XElement("PathID", asset.m_PathID), + new XElement("Source", asset.SourceFile.fullName), + new XElement("Size", asset.FullSize) + ) + ) + ) + ); + + doc.Save(filename); + + break; + } + + var statusText = $"Finished exporting asset list with {toExportAssets.Count()} items."; + + StatusStripUpdate(statusText); + + if (Properties.Settings.Default.openAfterExport && toExportAssets.Count() > 0) + { + Process.Start(savePath); + } + }); + } + public static void ExportSplitObjects(string savePath, TreeNodeCollection nodes) { ThreadPool.QueueUserWorkItem(state =>