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,6 +41,9 @@ public class CompileCommand : CompilerCommandBase<CompileCommand.Settings>
|
|||||||
|
|
||||||
// Configure error and warning messages
|
// Configure error and warning messages
|
||||||
BeginErrorReporting(new IrisSourceRepository(compilands, dataTableInput));
|
BeginErrorReporting(new IrisSourceRepository(compilands, dataTableInput));
|
||||||
|
|
||||||
|
if (settings.Verbose)
|
||||||
|
{
|
||||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.Markup, byte.MaxValue);
|
TraceSettings.Current.SetCategoryLevel(TraceCategory.Markup, byte.MaxValue);
|
||||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.MarkupCompiler, byte.MaxValue);
|
TraceSettings.Current.SetCategoryLevel(TraceCategory.MarkupCompiler, byte.MaxValue);
|
||||||
TraceSettings.Current.SetCategoryLevel(TraceCategory.Tool, byte.MaxValue);
|
TraceSettings.Current.SetCategoryLevel(TraceCategory.Tool, byte.MaxValue);
|
||||||
@@ -48,11 +51,15 @@ public class CompileCommand : CompilerCommandBase<CompileCommand.Settings>
|
|||||||
{
|
{
|
||||||
AnsiConsole.MarkupLineInterpolated($"[grey]{line}[/]");
|
AnsiConsole.MarkupLineInterpolated($"[grey]{line}[/]");
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
MarkupSystem.Startup(true);
|
MarkupSystem.Startup(true);
|
||||||
Assembler.RegisterLoader();
|
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);
|
var success = MarkupCompiler.Compile(compilands, dataTableInput ?? default);
|
||||||
|
|
||||||
StopErrorReporting();
|
StopErrorReporting();
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ using Microsoft.Iris.Session;
|
|||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using Spectre.Console.Cli;
|
using Spectre.Console.Cli;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Runtime.Loader;
|
||||||
|
|
||||||
namespace UIXC.Commands;
|
namespace UIXC.Commands;
|
||||||
|
|
||||||
public abstract class CompilerCommandBase<TSettings> : Command<TSettings> where TSettings : CompilerSettings
|
public abstract class CompilerCommandBase<TSettings> : Command<TSettings> where TSettings : CompilerSettings
|
||||||
{
|
{
|
||||||
|
private string[]? _searchPaths;
|
||||||
|
|
||||||
public Report? Report { get; private set; }
|
public Report? Report { get; private set; }
|
||||||
|
|
||||||
protected void BeginErrorReporting(IrisSourceRepository repo)
|
protected void BeginErrorReporting(IrisSourceRepository repo)
|
||||||
@@ -52,4 +56,62 @@ public abstract class CompilerCommandBase<TSettings> : Command<TSettings> where
|
|||||||
{
|
{
|
||||||
ErrorManager.OnErrors -= OnError;
|
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));
|
BeginErrorReporting(new IrisSourceRepository(settings.Inputs));
|
||||||
|
|
||||||
var searchPaths = settings.IncludeDirectories.Prepend(Environment.CurrentDirectory).ToArray();
|
var loadAssembliesResult = LoadAssemblies(settings);
|
||||||
|
if (loadAssembliesResult < 0)
|
||||||
foreach (var givenPath in settings.Assemblies ?? [])
|
return loadAssembliesResult;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var redirectOption in settings.ImportRedirects ?? [])
|
foreach (var redirectOption in settings.ImportRedirects ?? [])
|
||||||
{
|
{
|
||||||
@@ -66,7 +53,7 @@ public class DecompileCommand : CompilerCommandBase<DecompileCommand.Settings>
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!TryResolvePath(input, searchPaths, out var inputPath))
|
if (!TryResolvePath(input, GetSearchPaths(settings), out var inputPath))
|
||||||
inputPath = input;
|
inputPath = input;
|
||||||
|
|
||||||
if (!inputPath.Contains("://"))
|
if (!inputPath.Contains("://"))
|
||||||
@@ -118,41 +105,12 @@ public class DecompileCommand : CompilerCommandBase<DecompileCommand.Settings>
|
|||||||
var fileName = Path.GetFileName(inputFilePath);//.Replace('!', '/');
|
var fileName = Path.GetFileName(inputFilePath);//.Replace('!', '/');
|
||||||
var outputFile = Path.Combine(settings.OutputDir, Path.ChangeExtension(fileName, settings.Language.GetExtension()));
|
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);
|
Directory.CreateDirectory(outputDir);
|
||||||
|
|
||||||
return outputFile;
|
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
|
public sealed class Settings : CompilerSettings
|
||||||
{
|
{
|
||||||
[Description("The UIB files to decompile.")]
|
[Description("The UIB files to decompile.")]
|
||||||
|
|||||||
Reference in New Issue
Block a user