add assembly resolver to help with more permissive plugin references to iw4madmin libraries

This commit is contained in:
RaidMax 2023-05-27 14:01:16 -05:00
parent 35c4bbd2d5
commit 399e082b61

View File

@ -61,6 +61,19 @@ namespace IW4MAdmin.Application
public static async Task Main(string[] args) public static async Task Main(string[] args)
{ {
AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory); AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory);
AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) =>
{
var libraryName = eventArgs.Name.Split(",").First();
var overrides = new[] { nameof(SharedLibraryCore), nameof(Stats) };
if (!overrides.Contains(libraryName))
{
return AppDomain.CurrentDomain.GetAssemblies().First(asm => asm.FullName == eventArgs.Name);
}
// added to be a bit more permissive with plugin references
return AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(asm => asm.FullName?.StartsWith(libraryName) ?? false);
};
Console.OutputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8;
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
@ -413,9 +426,9 @@ namespace IW4MAdmin.Application
commandConfigHandler.BuildAsync().GetAwaiter().GetResult(); commandConfigHandler.BuildAsync().GetAwaiter().GetResult();
var appConfig = appConfigHandler.Configuration(); var appConfig = appConfigHandler.Configuration();
var masterUri = Utilities.IsDevelopment var masterUri = /*Utilities.IsDevelopment
? new Uri("http://127.0.0.1:8080") ? new Uri("http://127.0.0.1:8080")
: appConfig?.MasterUrl ?? new ApplicationConfiguration().MasterUrl; : appConfig?.MasterUrl ?? */new ApplicationConfiguration().MasterUrl;
var httpClient = new HttpClient var httpClient = new HttpClient
{ {
BaseAddress = masterUri, BaseAddress = masterUri,