mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Remove LoadFromAssemblyPath hack from compiler command
This commit is contained in:
@@ -41,18 +41,25 @@ public class CompileCommand : CompilerCommandBase<CompileCommand.Settings>
|
||||
|
||||
// Configure error and warning messages
|
||||
BeginErrorReporting(new IrisSourceRepository(compilands, dataTableInput));
|
||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.Markup, byte.MaxValue);
|
||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.MarkupCompiler, byte.MaxValue);
|
||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.Tool, byte.MaxValue);
|
||||
TraceSettings.Current.OnWriteLine += (line) =>
|
||||
|
||||
if (settings.Verbose)
|
||||
{
|
||||
AnsiConsole.MarkupLineInterpolated($"[grey]{line}[/]");
|
||||
};
|
||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.Markup, byte.MaxValue);
|
||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.MarkupCompiler, byte.MaxValue);
|
||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.Tool, byte.MaxValue);
|
||||
TraceSettings.Current.OnWriteLine += (line) =>
|
||||
{
|
||||
AnsiConsole.MarkupLineInterpolated($"[grey]{line}[/]");
|
||||
};
|
||||
}
|
||||
|
||||
MarkupSystem.Startup(true);
|
||||
Assembler.RegisterLoader();
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(@"C:\Program Files\Zune\UIXcontrols.dll");
|
||||
var loadAssembliesResult = LoadAssemblies(settings);
|
||||
if (loadAssembliesResult < 0)
|
||||
return loadAssembliesResult;
|
||||
|
||||
var success = MarkupCompiler.Compile(compilands, dataTableInput ?? default);
|
||||
|
||||
StopErrorReporting();
|
||||
|
||||
@@ -3,11 +3,15 @@ using Microsoft.Iris.Session;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Cli;
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.Loader;
|
||||
|
||||
namespace UIXC.Commands;
|
||||
|
||||
public abstract class CompilerCommandBase<TSettings> : Command<TSettings> where TSettings : CompilerSettings
|
||||
{
|
||||
private string[]? _searchPaths;
|
||||
|
||||
public Report? Report { get; private set; }
|
||||
|
||||
protected void BeginErrorReporting(IrisSourceRepository repo)
|
||||
@@ -52,4 +56,62 @@ public abstract class CompilerCommandBase<TSettings> : Command<TSettings> where
|
||||
{
|
||||
ErrorManager.OnErrors -= OnError;
|
||||
}
|
||||
|
||||
protected static string ResolvePath(string givenPath, ICollection<string> searchPaths)
|
||||
{
|
||||
if (!TryResolvePath(givenPath, searchPaths, out var assemblyPath))
|
||||
throw new FileNotFoundException(null, givenPath);
|
||||
return assemblyPath;
|
||||
}
|
||||
|
||||
protected static bool TryResolvePath(string givenPath, ICollection<string> searchPaths, [NotNullWhen(true)] out string? absolutePath)
|
||||
{
|
||||
if (Path.IsPathFullyQualified(givenPath))
|
||||
{
|
||||
absolutePath = givenPath;
|
||||
return Path.Exists(absolutePath);
|
||||
}
|
||||
|
||||
absolutePath = null;
|
||||
if (searchPaths.Count == 0)
|
||||
return false;
|
||||
|
||||
foreach (var searchPath in searchPaths)
|
||||
{
|
||||
absolutePath = Path.GetFullPath(givenPath, searchPath);
|
||||
if (Path.Exists(absolutePath))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[MemberNotNull(nameof(_searchPaths))]
|
||||
protected string[] GetSearchPaths(TSettings settings)
|
||||
{
|
||||
return _searchPaths ??= settings.IncludeDirectories.Prepend(Environment.CurrentDirectory).ToArray();
|
||||
}
|
||||
|
||||
[MemberNotNull(nameof(_searchPaths))]
|
||||
protected int LoadAssemblies(TSettings settings)
|
||||
{
|
||||
GetSearchPaths(settings);
|
||||
|
||||
foreach (var givenPath in settings.Assemblies ?? [])
|
||||
{
|
||||
try
|
||||
{
|
||||
var assemblyPath = ResolvePath(givenPath, _searchPaths);
|
||||
_ = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.WriteException(ex);
|
||||
if (!AnsiConsole.Confirm("Do you want to continue?", false))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,22 +34,9 @@ public class DecompileCommand : CompilerCommandBase<DecompileCommand.Settings>
|
||||
|
||||
BeginErrorReporting(new IrisSourceRepository(settings.Inputs));
|
||||
|
||||
var searchPaths = settings.IncludeDirectories.Prepend(Environment.CurrentDirectory).ToArray();
|
||||
|
||||
foreach (var givenPath in settings.Assemblies ?? [])
|
||||
{
|
||||
try
|
||||
{
|
||||
var assemblyPath = ResolvePath(givenPath, searchPaths);
|
||||
_ = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.WriteException(ex);
|
||||
if (!AnsiConsole.Confirm("Do you want to continue?", false))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
var loadAssembliesResult = LoadAssemblies(settings);
|
||||
if (loadAssembliesResult < 0)
|
||||
return loadAssembliesResult;
|
||||
|
||||
foreach (var redirectOption in settings.ImportRedirects ?? [])
|
||||
{
|
||||
@@ -66,7 +53,7 @@ public class DecompileCommand : CompilerCommandBase<DecompileCommand.Settings>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!TryResolvePath(input, searchPaths, out var inputPath))
|
||||
if (!TryResolvePath(input, GetSearchPaths(settings), out var inputPath))
|
||||
inputPath = input;
|
||||
|
||||
if (!inputPath.Contains("://"))
|
||||
@@ -118,41 +105,12 @@ public class DecompileCommand : CompilerCommandBase<DecompileCommand.Settings>
|
||||
var fileName = Path.GetFileName(inputFilePath);//.Replace('!', '/');
|
||||
var outputFile = Path.Combine(settings.OutputDir, Path.ChangeExtension(fileName, settings.Language.GetExtension()));
|
||||
|
||||
var outputDir = Path.GetDirectoryName(outputFile);
|
||||
var outputDir = Path.GetDirectoryName(outputFile)!;
|
||||
Directory.CreateDirectory(outputDir);
|
||||
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
private static string ResolvePath(string givenPath, ICollection<string> searchPaths)
|
||||
{
|
||||
if (!TryResolvePath(givenPath, searchPaths, out var assemblyPath))
|
||||
throw new FileNotFoundException(null, givenPath);
|
||||
return assemblyPath;
|
||||
}
|
||||
|
||||
private static bool TryResolvePath(string givenPath, ICollection<string> searchPaths, [NotNullWhen(true)] out string? absolutePath)
|
||||
{
|
||||
if (Path.IsPathFullyQualified(givenPath))
|
||||
{
|
||||
absolutePath = givenPath;
|
||||
return Path.Exists(absolutePath);
|
||||
}
|
||||
|
||||
absolutePath = null;
|
||||
if (searchPaths.Count == 0)
|
||||
return false;
|
||||
|
||||
foreach (var searchPath in searchPaths)
|
||||
{
|
||||
absolutePath = Path.GetFullPath(givenPath, searchPath);
|
||||
if (Path.Exists(absolutePath))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public sealed class Settings : CompilerSettings
|
||||
{
|
||||
[Description("The UIB files to decompile.")]
|
||||
|
||||
Reference in New Issue
Block a user