mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-21 16:09:19 +01:00
fix: only create load context for plugins that are actually supposed to load
This commit is contained in:
parent
0cc9de9fab
commit
daeec9a13f
1 changed files with 55 additions and 49 deletions
|
|
@ -64,54 +64,6 @@ internal class LocalPlugin : IDisposable
|
||||||
this.DllFile = dllFile;
|
this.DllFile = dllFile;
|
||||||
this.State = PluginState.Unloaded;
|
this.State = PluginState.Unloaded;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.loader = PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig);
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, "Loader.CreateFromAssemblyFile() failed");
|
|
||||||
this.State = PluginState.DependencyResolutionFailed;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.pluginAssembly = this.loader.LoadDefaultAssembly();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
this.pluginAssembly = null;
|
|
||||||
this.pluginType = null;
|
|
||||||
this.loader.Dispose();
|
|
||||||
|
|
||||||
Log.Error(ex, $"Not a plugin: {this.DllFile.FullName}");
|
|
||||||
throw new InvalidPluginException(this.DllFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin)));
|
|
||||||
}
|
|
||||||
catch (ReflectionTypeLoadException ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, $"Could not load one or more types when searching for IDalamudPlugin: {this.DllFile.FullName}");
|
|
||||||
// Something blew up when parsing types, but we still want to look for IDalamudPlugin. Let Load() handle the error.
|
|
||||||
this.pluginType = ex.Types.FirstOrDefault(type => type != null && type.IsAssignableTo(typeof(IDalamudPlugin)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.pluginType == default)
|
|
||||||
{
|
|
||||||
this.pluginAssembly = null;
|
|
||||||
this.pluginType = null;
|
|
||||||
this.loader.Dispose();
|
|
||||||
|
|
||||||
Log.Error($"Nothing inherits from IDalamudPlugin: {this.DllFile.FullName}");
|
|
||||||
throw new InvalidPluginException(this.DllFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
var assemblyVersion = this.pluginAssembly.GetName().Version;
|
|
||||||
|
|
||||||
// Although it is conditionally used here, we need to set the initial value regardless.
|
// Although it is conditionally used here, we need to set the initial value regardless.
|
||||||
this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
||||||
|
|
||||||
|
|
@ -123,7 +75,7 @@ internal class LocalPlugin : IDisposable
|
||||||
Author = "developer",
|
Author = "developer",
|
||||||
Name = Path.GetFileNameWithoutExtension(this.DllFile.Name),
|
Name = Path.GetFileNameWithoutExtension(this.DllFile.Name),
|
||||||
InternalName = Path.GetFileNameWithoutExtension(this.DllFile.Name),
|
InternalName = Path.GetFileNameWithoutExtension(this.DllFile.Name),
|
||||||
AssemblyVersion = assemblyVersion ?? new Version("1.0.0.0"),
|
AssemblyVersion = new Version("1.0.0.0"),
|
||||||
Description = string.Empty,
|
Description = string.Empty,
|
||||||
ApplicableVersion = GameVersion.Any,
|
ApplicableVersion = GameVersion.Any,
|
||||||
DalamudApiLevel = PluginManager.DalamudApiLevel,
|
DalamudApiLevel = PluginManager.DalamudApiLevel,
|
||||||
|
|
@ -411,6 +363,8 @@ internal class LocalPlugin : IDisposable
|
||||||
this.State = PluginState.Loading;
|
this.State = PluginState.Loading;
|
||||||
Log.Information($"Loading {this.DllFile.Name}");
|
Log.Information($"Loading {this.DllFile.Name}");
|
||||||
|
|
||||||
|
this.EnsureLoader();
|
||||||
|
|
||||||
if (this.DllFile.DirectoryName != null &&
|
if (this.DllFile.DirectoryName != null &&
|
||||||
File.Exists(Path.Combine(this.DllFile.DirectoryName, "Dalamud.dll")))
|
File.Exists(Path.Combine(this.DllFile.DirectoryName, "Dalamud.dll")))
|
||||||
{
|
{
|
||||||
|
|
@ -700,4 +654,56 @@ internal class LocalPlugin : IDisposable
|
||||||
config.SharedAssemblies.Add(typeof(Lumina.GameData).Assembly.GetName());
|
config.SharedAssemblies.Add(typeof(Lumina.GameData).Assembly.GetName());
|
||||||
config.SharedAssemblies.Add(typeof(Lumina.Excel.ExcelSheetImpl).Assembly.GetName());
|
config.SharedAssemblies.Add(typeof(Lumina.Excel.ExcelSheetImpl).Assembly.GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EnsureLoader()
|
||||||
|
{
|
||||||
|
if (this.loader != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.loader = PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig);
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Loader.CreateFromAssemblyFile() failed");
|
||||||
|
this.State = PluginState.DependencyResolutionFailed;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.pluginAssembly = this.loader.LoadDefaultAssembly();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.pluginAssembly = null;
|
||||||
|
this.pluginType = null;
|
||||||
|
this.loader.Dispose();
|
||||||
|
|
||||||
|
Log.Error(ex, $"Not a plugin: {this.DllFile.FullName}");
|
||||||
|
throw new InvalidPluginException(this.DllFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin)));
|
||||||
|
}
|
||||||
|
catch (ReflectionTypeLoadException ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, $"Could not load one or more types when searching for IDalamudPlugin: {this.DllFile.FullName}");
|
||||||
|
// Something blew up when parsing types, but we still want to look for IDalamudPlugin. Let Load() handle the error.
|
||||||
|
this.pluginType = ex.Types.FirstOrDefault(type => type != null && type.IsAssignableTo(typeof(IDalamudPlugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pluginType == default)
|
||||||
|
{
|
||||||
|
this.pluginAssembly = null;
|
||||||
|
this.pluginType = null;
|
||||||
|
this.loader.Dispose();
|
||||||
|
|
||||||
|
Log.Error($"Nothing inherits from IDalamudPlugin: {this.DllFile.FullName}");
|
||||||
|
throw new InvalidPluginException(this.DllFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue