Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
Adds exporter for list of assets to XML (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
notjosh authored Apr 17, 2021
1 parent 6f7b772 commit 251854c
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 16 deletions.
50 changes: 49 additions & 1 deletion AssetStudioGUI/AssetStudioGUIForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 62 additions & 14 deletions AssetStudioGUI/AssetStudioGUIForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -1513,13 +1528,13 @@ private void ExportAssets(int type, ExportType exportType)
List<AssetItem> 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;
}
Expand All @@ -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<AssetItem> 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()
{
Expand Down
59 changes: 58 additions & 1 deletion AssetStudioGUI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -442,6 +454,51 @@ public static void ExportAssets(string savePath, List<AssetItem> toExportAssets,
});
}

public static void ExportAssetsList(string savePath, List<AssetItem> 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 =>
Expand Down

0 comments on commit 251854c

Please sign in to comment.