SessionZero-Client/tools/szpack/UnpackCommand.cs

55 lines
2.2 KiB
C#

/*
* WARNING:
* This tool was created by an LLM based on the SessionZero shared lib project, therefore it is subject to errors and does not reflect the architecture of the SessionZero project.
* It was created to be used as a quick and dirty validation tool for the szpack format.
*/
using SessionZero.Shared.Services;
using Spectre.Console;
using Spectre.Console.Cli;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace SessionZero.Tools.Packer;
public class UnpackSettings : CommandSettings
{
[CommandArgument(0, "<input>")]
[Description("The path to the .szpack file.")]
public required string Input { get; init; }
[CommandOption("-o|--output")]
[Description("The directory where the pack will be extracted.")]
[DefaultValue("unpacked")]
public string Output { get; init; } = "unpacked";
}
public class UnpackCommand : AsyncCommand<UnpackSettings>
{
public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [NotNull] UnpackSettings settings, CancellationToken cancellationToken)
{
AnsiConsole.MarkupLine($"\n[bold white on blue] --- Unpacking Datapack: {settings.Input} --- [/]");
try
{
// Unpack the archive
DatapackService.UnpackDatapack(settings.Input, settings.Output);
AnsiConsole.MarkupLine($"[green]✅ Successfully unpacked archive to: {settings.Output}[/]");
// Load and display the core data
var datapack = await DatapackService.LoadDatapackMetadataAsync(settings.Output);
AnsiConsole.MarkupLine("\n[bold]--- Datapack Info (szpack.json) ---[/]");
AnsiConsole.MarkupLine($"[yellow]ID:[/]\t\t{datapack.Id}");
AnsiConsole.MarkupLine($"[yellow]Name:[/]\t{datapack.Name}");
AnsiConsole.MarkupLine($"[yellow]Version:[/]\t{datapack.Version}");
AnsiConsole.MarkupLine($"[yellow]Author:[/]\t{datapack.Author}");
return 0;
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"\n[bold white on red]❌ ERROR:[/] Failed to unpack or load datapack. Details: {ex.Message}");
return 1;
}
}
}