Primary Content Extraction

* Resolves #504
This commit is contained in:
ds5678 2024-07-20 10:52:03 -07:00
parent 958f3f311d
commit 0781208f81
6 changed files with 75 additions and 8 deletions

View File

@ -85,6 +85,8 @@
"export_in_progress": "Exporting Asset Files\n{0}%\n{1}/{2}",
"export_in_progress_no_file_count_yet": "Exporting Asset Files\n0.0%\n?/?",
"export_preparing": "Preparing for Export...\nThis might take a minute.",
"export_primary_content": "Export Primary Content",
"export_unity_project": "Export Unity Project",
"format": "Format",
"frequency": "Frequency",
"game_object": "GameObject",

View File

@ -439,6 +439,16 @@ partial class Localization
/// </summary>
public static string ExportPreparing => Get("export_preparing");
/// <summary>
/// Export Primary Content
/// </summary>
public static string ExportPrimaryContent => Get("export_primary_content");
/// <summary>
/// Export Unity Project
/// </summary>
public static string ExportUnityProject => Get("export_unity_project");
/// <summary>
/// Format
/// </summary>

View File

@ -1,4 +1,5 @@
using AssetRipper.Assets.Bundles;
using AssetRipper.Export.PrimaryContent;
using AssetRipper.Export.UnityProjects;
using AssetRipper.Export.UnityProjects.Configuration;
using AssetRipper.Import.Logging;
@ -47,7 +48,7 @@ public static class GameFileLoader
GameData = ExportHandler.LoadAndProcess(paths);
}
public static void Export(string path)
public static void ExportUnityProject(string path)
{
if (IsLoaded)
{
@ -57,6 +58,20 @@ public static class GameFileLoader
}
}
public static void ExportPrimaryContent(string path)
{
if (IsLoaded)
{
Directory.Delete(path, true);
Directory.CreateDirectory(path);
Logger.Info(LogCategory.Export, "Starting export");
Logger.Info(LogCategory.Export, $"Attempting to export assets to {path}...");
Settings.ExportRootPath = path;
PrimaryContentExporter.CreateDefault(GameData).Export(GameBundle, Settings);
Logger.Info(LogCategory.Export, "Finished exporting assets");
}
}
private static LibraryConfiguration LoadSettings()
{
LibraryConfiguration settings = new();

View File

@ -64,7 +64,7 @@ public static class Commands
}
}
public readonly struct Export : ICommand
public readonly struct ExportUnityProject : ICommand
{
static async Task<string?> ICommand.Execute(HttpRequest request)
{
@ -82,7 +82,31 @@ public static class Commands
if (!string.IsNullOrEmpty(path))
{
GameFileLoader.Export(path);
GameFileLoader.ExportUnityProject(path);
}
return null;
}
}
public readonly struct ExportPrimaryContent : ICommand
{
static async Task<string?> ICommand.Execute(HttpRequest request)
{
IFormCollection form = await request.ReadFormAsync();
string? path;
if (form.TryGetValue("Path", out StringValues values))
{
path = values;
}
else
{
return CommandsPath;
}
if (!string.IsNullOrEmpty(path))
{
GameFileLoader.ExportPrimaryContent(path);
}
return null;
}

View File

@ -38,14 +38,29 @@ public sealed class CommandsPage : VuePage
}
using (new P(writer).End())
{
using (new Form(writer).WithAction("/Export").WithMethod("post").End())
using (new Form(writer).End())
{
new Input(writer).WithClass("form-control").WithType("text").WithName("Path")
.WithCustomAttribute("v-model", "export_path")
.WithCustomAttribute("@input", "handleExportPathChange").Close();
new Input(writer).WithCustomAttribute("v-if", "export_path_has_files").WithType("submit").WithClass("btn btn-danger").WithValue(Localization.MenuExport).Close();
new Button(writer).WithCustomAttribute("v-else-if", "export_path === ''").WithClass("btn btn-primary").WithCustomAttribute("disabled").Close(Localization.MenuExport);
new Input(writer).WithCustomAttribute("v-else").WithType("submit").WithClass("btn btn-primary").WithValue(Localization.MenuExport).Close();
}
using (new Form(writer).WithAction("/Export/UnityProject").WithMethod("post").End())
{
new Input(writer).WithType("hidden").WithName("Path").WithCustomAttribute("v-model", "export_path").Close();
new Input(writer).WithCustomAttribute("v-if", "export_path_has_files").WithType("submit").WithClass("btn btn-danger").WithValue(Localization.ExportUnityProject).Close();
new Button(writer).WithCustomAttribute("v-else-if", "export_path === ''").WithClass("btn btn-primary").WithCustomAttribute("disabled").Close(Localization.ExportUnityProject);
new Input(writer).WithCustomAttribute("v-else").WithType("submit").WithClass("btn btn-primary").WithValue(Localization.ExportUnityProject).Close();
}
using (new Form(writer).WithAction("/Export/PrimaryContent").WithMethod("post").End())
{
new Input(writer).WithType("hidden").WithName("Path").WithCustomAttribute("v-model", "export_path").Close();
new Input(writer).WithCustomAttribute("v-if", "export_path_has_files").WithType("submit").WithClass("btn btn-danger").WithValue(Localization.ExportPrimaryContent).Close();
new Button(writer).WithCustomAttribute("v-else-if", "export_path === ''").WithClass("btn btn-primary").WithCustomAttribute("disabled").Close(Localization.ExportPrimaryContent);
new Input(writer).WithCustomAttribute("v-else").WithType("submit").WithClass("btn btn-primary").WithValue(Localization.ExportPrimaryContent).Close();
}
if (Dialogs.Supported)

View File

@ -185,7 +185,8 @@ public static class WebApplicationLauncher
});
//Commands
app.MapPost("/Export", Commands.HandleCommand<Commands.Export>);
app.MapPost("/Export/UnityProject", Commands.HandleCommand<Commands.ExportUnityProject>);
app.MapPost("/Export/PrimaryContent", Commands.HandleCommand<Commands.ExportPrimaryContent>);
app.MapPost("/LoadFile", Commands.HandleCommand<Commands.LoadFile>);
app.MapPost("/LoadFolder", Commands.HandleCommand<Commands.LoadFolder>);
app.MapPost("/Reset", Commands.HandleCommand<Commands.Reset>);