mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Add de/compile + settings
This commit is contained in:
@@ -23,7 +23,7 @@ public class CompileCommand : Command<CompileCommand.Settings>
|
|||||||
CompilerInput[] compilands = new CompilerInput[settings.Compilands.Length];
|
CompilerInput[] compilands = new CompilerInput[settings.Compilands.Length];
|
||||||
for (int c = 0; c < settings.Compilands.Length; c++)
|
for (int c = 0; c < settings.Compilands.Length; c++)
|
||||||
{
|
{
|
||||||
string sourcePath = settings.Compilands[0];
|
string sourcePath = settings.Compilands[c];
|
||||||
compilands[c] = new()
|
compilands[c] = new()
|
||||||
{
|
{
|
||||||
SourceFileName = sourcePath,
|
SourceFileName = sourcePath,
|
||||||
@@ -88,26 +88,10 @@ public class CompileCommand : Command<CompileCommand.Settings>
|
|||||||
return Path.Combine(outputDir, Path.ChangeExtension(sourceFilePath, ".uib"));
|
return Path.Combine(outputDir, Path.ChangeExtension(sourceFilePath, ".uib"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class Settings : CommandSettings
|
public sealed class Settings : CompilerSettings
|
||||||
{
|
{
|
||||||
[Description("The source files to compile.")]
|
[Description("The source files to compile.")]
|
||||||
[CommandArgument(0, "[compilands]")]
|
[CommandArgument(0, "[compilands]")]
|
||||||
public required string[] Compilands { get; init; }
|
public required string[] Compilands { get; init; }
|
||||||
|
|
||||||
[Description("Directories to search for imported files in.")]
|
|
||||||
[CommandOption("-I <VALUES>")]
|
|
||||||
public required string[] IncludeDirectories { get; init; }
|
|
||||||
|
|
||||||
[Description("A shared binary data table to compile with.")]
|
|
||||||
[CommandOption("-t|--dataTable")]
|
|
||||||
public string? DataTable { get; init; }
|
|
||||||
|
|
||||||
[Description("The directory to output to.")]
|
|
||||||
[CommandOption("-o|--output <outputDir>")]
|
|
||||||
public string? OutputDir { get; init; }
|
|
||||||
|
|
||||||
[CommandOption("--verbose")]
|
|
||||||
[DefaultValue(false)]
|
|
||||||
public bool Verbose { get; init; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
using Microsoft.Iris.Asm;
|
using Microsoft.Iris.Asm;
|
||||||
using Microsoft.Iris.Debug;
|
using Microsoft.Iris.Debug;
|
||||||
using Microsoft.Iris.Markup;
|
using Microsoft.Iris.Markup;
|
||||||
|
using Microsoft.Iris.Session;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using Spectre.Console.Cli;
|
using Spectre.Console.Cli;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Runtime.Loader;
|
||||||
|
|
||||||
namespace UIXC.Commands;
|
namespace UIXC.Commands;
|
||||||
|
|
||||||
@@ -29,6 +31,43 @@ public class DecompileCommand : Command<DecompileCommand.Settings>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorManager.OnErrors += (errors) =>
|
||||||
|
{
|
||||||
|
foreach (ErrorRecord error in errors)
|
||||||
|
{
|
||||||
|
var (color, type) = error.Warning
|
||||||
|
? ("yellow", "WARN") : ("red", "ERROR");
|
||||||
|
|
||||||
|
AnsiConsole.MarkupLineInterpolated($"[{color}]{type}: {error.Message}[/]");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var givenPath in settings.Assemblies ?? [])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var assemblyPath = givenPath;
|
||||||
|
if (!Path.IsPathFullyQualified(givenPath))
|
||||||
|
{
|
||||||
|
assemblyPath = Path.GetFullPath(givenPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteException(ex);
|
||||||
|
if (!AnsiConsole.Ask("Do you want to continue?", false))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var redirectOption in settings.ImportRedirects ?? [])
|
||||||
|
{
|
||||||
|
var parts = redirectOption.Split('>');
|
||||||
|
MarkupSystem.AddImportRedirect(parts[0], parts[1]);
|
||||||
|
}
|
||||||
|
|
||||||
MarkupSystem.Startup(true);
|
MarkupSystem.Startup(true);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
@@ -77,37 +116,22 @@ public class DecompileCommand : Command<DecompileCommand.Settings>
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetOutputPath(Settings settings, string inputFilePath)
|
private static string GetOutputPath(Settings settings, string inputFilePath)
|
||||||
{
|
{
|
||||||
var outputDir = settings.OutputDir ?? Environment.CurrentDirectory;
|
var outputDir = settings.OutputDir ?? Environment.CurrentDirectory;
|
||||||
return Path.Combine(outputDir, Path.ChangeExtension(inputFilePath, settings.Language.GetExtension()));
|
return Path.Combine(outputDir, Path.ChangeExtension(inputFilePath, settings.Language.GetExtension()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class Settings : CommandSettings
|
public sealed class Settings : CompilerSettings
|
||||||
{
|
{
|
||||||
[Description("The UIB files to decompile.")]
|
[Description("The UIB files to decompile.")]
|
||||||
[CommandArgument(0, "[inputs]")]
|
[CommandArgument(0, "[inputs]")]
|
||||||
public required string[] Inputs { get; init; }
|
public required string[] Inputs { get; init; }
|
||||||
|
|
||||||
[Description("Directories to search for imported files in.")]
|
|
||||||
[CommandOption("-I <VALUES>")]
|
|
||||||
public required string[] IncludeDirectories { get; init; }
|
|
||||||
|
|
||||||
[Description("A shared binary data table to decompile with.")]
|
|
||||||
[CommandOption("-t|--dataTable")]
|
|
||||||
public string? DataTable { get; init; }
|
|
||||||
|
|
||||||
[Description("The directory to output to.")]
|
|
||||||
[CommandOption("-o|--output <outputDir>")]
|
|
||||||
public string? OutputDir { get; init; }
|
|
||||||
|
|
||||||
// TODO: Enum options
|
// TODO: Enum options
|
||||||
[Description("The language to decompile to.")]
|
[Description("The language to decompile to.")]
|
||||||
[CommandOption("-l|--lang <lang>")]
|
[CommandOption("-l|--lang <lang>")]
|
||||||
public SourceLanguage Language { get; init; } = SourceLanguage.Asm;
|
public SourceLanguage Language { get; init; } = SourceLanguage.Asm;
|
||||||
|
|
||||||
[CommandOption("--verbose")]
|
|
||||||
[DefaultValue(false)]
|
|
||||||
public bool Verbose { get; init; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Spectre.Console.Cli;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace UIXC;
|
||||||
|
|
||||||
|
public abstract class CommonSettings : CommandSettings
|
||||||
|
{
|
||||||
|
[CommandOption("--verbose")]
|
||||||
|
[DefaultValue(false)]
|
||||||
|
public bool Verbose { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class CompilerSettings : CommonSettings
|
||||||
|
{
|
||||||
|
[Description("The directory to output to.")]
|
||||||
|
[CommandOption("-o|--output <outputDir>")]
|
||||||
|
public string? OutputDir { get; init; }
|
||||||
|
|
||||||
|
[Description("The shared binary data table to use.")]
|
||||||
|
[CommandOption("-t|--dataTable")]
|
||||||
|
public string? DataTable { get; init; }
|
||||||
|
|
||||||
|
[Description("Directories to search for imported files in.")]
|
||||||
|
[CommandOption("-I <VALUES>")]
|
||||||
|
public required string[] IncludeDirectories { get; init; }
|
||||||
|
|
||||||
|
[Description("External assemblies to load.")]
|
||||||
|
[CommandOption("-A <VALUES>")]
|
||||||
|
public required string[] Assemblies { get; init; }
|
||||||
|
|
||||||
|
[Description("Redirects imports.")]
|
||||||
|
[CommandOption("--ir <VALUES>")]
|
||||||
|
public required string[] ImportRedirects { get; init; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user