mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-15 19:28:48 -05:00
Add JsonDump option
This commit is contained in:
@@ -372,6 +372,19 @@ namespace AssetStudioCLI
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ExportJsonDumpFile(AssetItem item, string exportPath)
|
||||
{
|
||||
if (!TryExportFile(exportPath, item, ".json", out var exportFullPath, mode: "JsonDump"))
|
||||
return false;
|
||||
var m_Type = item.Asset is MonoBehaviour m_MonoBehaviour
|
||||
? m_MonoBehaviour.serializedType.m_Type ?? m_MonoBehaviour.ConvertToTypeTree(Studio.assemblyLoader)
|
||||
: null;
|
||||
var jsonDoc = item.Asset.ToJsonDoc(m_Type);
|
||||
var str = System.Text.Json.JsonSerializer.Serialize(jsonDoc, Object.JsonOptions);
|
||||
File.WriteAllText(exportFullPath, str);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExportConvertFile(AssetItem item, string exportPath)
|
||||
{
|
||||
switch (item.Type)
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace AssetStudioCLI.Options
|
||||
Export,
|
||||
ExportRaw,
|
||||
Dump,
|
||||
JsonDump,
|
||||
Info,
|
||||
Live2D,
|
||||
SplitObjects,
|
||||
@@ -209,11 +210,12 @@ namespace AssetStudioCLI.Options
|
||||
optionDefaultValue: WorkMode.Export,
|
||||
optionName: "-m, --mode <value>",
|
||||
optionDescription: "Specify working mode\n" +
|
||||
"<Value: extract | export(default) | exportRaw | dump | info | live2d |\nsplitObjects | animator>\n" +
|
||||
"<Value: extract | export(default) | exportRaw | dump | jsonDump | info |\nlive2d | splitObjects | animator>\n" +
|
||||
"Extract - Extract(Decompress) asset bundles\n" +
|
||||
"Export - Convert and export assets\n" +
|
||||
"ExportRaw - Export raw assets\n" +
|
||||
"Dump - Generate json dumps of loaded asset\n" +
|
||||
"Dump - Generate txt dumps of loaded asset\n" +
|
||||
"JsonDump - Generate json dumps of loaded asset\n" +
|
||||
"Info - Load file(s) and show the number of available for export assets\n" +
|
||||
"Live2D - Export Live2D Cubism models\n" +
|
||||
"SplitObjects - Export all model objects (split) (fbx)\n" +
|
||||
@@ -706,6 +708,9 @@ namespace AssetStudioCLI.Options
|
||||
case "dump":
|
||||
o_workMode.Value = WorkMode.Dump;
|
||||
break;
|
||||
case "jsondump":
|
||||
o_workMode.Value = WorkMode.JsonDump;
|
||||
break;
|
||||
case "info":
|
||||
o_workMode.Value = WorkMode.Info;
|
||||
o_exportAssetTypes.Value.Add(ClassIDType.Animator);
|
||||
@@ -821,6 +826,7 @@ namespace AssetStudioCLI.Options
|
||||
{
|
||||
case WorkMode.ExportRaw:
|
||||
case WorkMode.Dump:
|
||||
case WorkMode.JsonDump:
|
||||
case WorkMode.Info:
|
||||
f_loadAllAssets.Value = true;
|
||||
flagIndexes.Add(i);
|
||||
@@ -1493,8 +1499,12 @@ namespace AssetStudioCLI.Options
|
||||
{
|
||||
switch (o_workMode.Value)
|
||||
{
|
||||
case WorkMode.ExportRaw:
|
||||
case WorkMode.Dump:
|
||||
case WorkMode.JsonDump:
|
||||
return f_loadAllAssets.Value && o_exportAssetTypes.Value == o_exportAssetTypes.DefaultValue
|
||||
? $"# Dump Asset Type(s): All"
|
||||
: $"# Dump Asset Type(s): {string.Join(", ", o_exportAssetTypes.Value)}";
|
||||
case WorkMode.ExportRaw:
|
||||
case WorkMode.Info:
|
||||
return f_loadAllAssets.Value && o_exportAssetTypes.Value == o_exportAssetTypes.DefaultValue
|
||||
? $"# Export Asset Type(s): All"
|
||||
@@ -1538,6 +1548,7 @@ namespace AssetStudioCLI.Options
|
||||
case WorkMode.Export:
|
||||
case WorkMode.ExportRaw:
|
||||
case WorkMode.Dump:
|
||||
case WorkMode.JsonDump:
|
||||
case WorkMode.Info:
|
||||
if (o_workMode.Value != WorkMode.Export)
|
||||
{
|
||||
|
||||
+21
-16
@@ -11,7 +11,6 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using static AssetStudioCLI.Exporter;
|
||||
using Ansi = AssetStudio.ColorConsole;
|
||||
|
||||
namespace AssetStudioCLI
|
||||
@@ -628,6 +627,7 @@ namespace AssetStudioCLI
|
||||
|
||||
public static void ExportAssets()
|
||||
{
|
||||
var workMode = CLIOptions.o_workMode.Value;
|
||||
var savePath = CLIOptions.o_outputFolder.Value;
|
||||
var toExportCount = parsedAssetsList.Count;
|
||||
var exportedCount = 0;
|
||||
@@ -636,6 +636,7 @@ namespace AssetStudioCLI
|
||||
var parallelExportCount = CLIOptions.o_maxParallelExportTasks.Value;
|
||||
var toExportAssetDict = new ConcurrentDictionary<AssetItem, string>();
|
||||
var toParallelExportAssetDict = new ConcurrentDictionary<AssetItem, string>();
|
||||
var modeStr = workMode == WorkMode.Dump || workMode == WorkMode.JsonDump ? "Dump" : "Export";
|
||||
|
||||
if (CLIOptions.o_stripPathPrefix.Value != null)
|
||||
{
|
||||
@@ -715,7 +716,7 @@ namespace AssetStudioCLI
|
||||
}
|
||||
exportPath += Path.DirectorySeparatorChar;
|
||||
|
||||
if (CLIOptions.o_workMode.Value == WorkMode.Export)
|
||||
if (workMode == WorkMode.Export)
|
||||
{
|
||||
switch (asset.Type)
|
||||
{
|
||||
@@ -754,32 +755,36 @@ namespace AssetStudioCLI
|
||||
var isExported = false;
|
||||
try
|
||||
{
|
||||
switch (CLIOptions.o_workMode.Value)
|
||||
switch (workMode)
|
||||
{
|
||||
case WorkMode.ExportRaw:
|
||||
Logger.Debug($"{CLIOptions.o_workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = ExportRawFile(asset, exportPath);
|
||||
Logger.Debug($"{workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = Exporter.ExportRawFile(asset, exportPath);
|
||||
break;
|
||||
case WorkMode.Dump:
|
||||
Logger.Debug($"{CLIOptions.o_workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = ExportDumpFile(asset, exportPath);
|
||||
Logger.Debug($"{workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = Exporter.ExportDumpFile(asset, exportPath);
|
||||
break;
|
||||
case WorkMode.JsonDump:
|
||||
Logger.Debug($"{workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = Exporter.ExportJsonDumpFile(asset, exportPath);
|
||||
break;
|
||||
case WorkMode.Export:
|
||||
Logger.Debug($"{CLIOptions.o_workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = ExportConvertFile(asset, exportPath);
|
||||
Logger.Debug($"{workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
isExported = Exporter.ExportConvertFile(asset, exportPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error($"{asset.SourceFile.originalPath ?? asset.SourceFile.fullName}: [{$"{asset.Type}: {asset.Text}".Color(Ansi.BrightRed)}] : Export error\n{ex}");
|
||||
Logger.Error($"{asset.SourceFile.originalPath ?? asset.SourceFile.fullName}: [{$"{asset.Type}: {asset.Text}".Color(Ansi.BrightRed)}] : {modeStr} error\n{ex}");
|
||||
}
|
||||
|
||||
if (isExported)
|
||||
{
|
||||
exportedCount++;
|
||||
}
|
||||
Console.Write($"Exported [{exportedCount}/{toExportCount}]\r");
|
||||
Console.Write($"{modeStr}ed [{exportedCount}/{toExportCount}]\r");
|
||||
}
|
||||
Exporter.ClearHash();
|
||||
|
||||
@@ -793,7 +798,7 @@ namespace AssetStudioCLI
|
||||
{
|
||||
Interlocked.Increment(ref exportedCount);
|
||||
Logger.Debug(debugLog);
|
||||
Console.Write($"Exported [{exportedCount}/{toExportCount}]\r");
|
||||
Console.Write($"{modeStr}ed [{exportedCount}/{toExportCount}]\r");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -806,12 +811,12 @@ namespace AssetStudioCLI
|
||||
|
||||
if (exportedCount == 0)
|
||||
{
|
||||
Logger.Default.Log(LoggerEvent.Info, "Nothing exported.", ignoreLevel: true);
|
||||
Logger.Default.Log(LoggerEvent.Info, $"Nothing {modeStr.ToLower()}ed.", ignoreLevel: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var outPath = CLIOptions.o_outputFolder.Value.ColorIf(toExportCount > exportedCount, Ansi.BrightYellow, Ansi.BrightGreen);
|
||||
Logger.Default.Log(LoggerEvent.Info, $"Finished exporting {exportedCount} asset(s) to \"{outPath}\".", ignoreLevel: true);
|
||||
Logger.Default.Log(LoggerEvent.Info, $"Finished {modeStr.ToLower()}ing {exportedCount} asset(s) to \"{outPath}\".", ignoreLevel: true);
|
||||
}
|
||||
|
||||
if (toExportCount > exportedCount)
|
||||
@@ -911,7 +916,7 @@ namespace AssetStudioCLI
|
||||
foreach (var gameObjectNode in exportableObjects)
|
||||
{
|
||||
var gameObject = gameObjectNode.gameObject;
|
||||
var filename = FixFileName(gameObject.m_Name);
|
||||
var filename = Exporter.FixFileName(gameObject.m_Name);
|
||||
var targetPath = $"{savePath}{filename}{Path.DirectorySeparatorChar}";
|
||||
//重名文件处理
|
||||
for (int i = 1; ; i++)
|
||||
@@ -931,7 +936,7 @@ namespace AssetStudioCLI
|
||||
Progress.Report(k, exportableCount);
|
||||
try
|
||||
{
|
||||
ExportGameObject(gameObject, targetPath);
|
||||
Exporter.ExportGameObject(gameObject, targetPath);
|
||||
Logger.Debug($"{gameObject.type} \"{filename}\" saved to \"{targetPath}\"");
|
||||
exportedCount++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user