mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
feat: load plugings with load order <= 0 asynchronously
This commit is contained in:
parent
0c5db3d0e6
commit
6356ad53b9
2 changed files with 39 additions and 7 deletions
|
|
@ -2,7 +2,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
using Dalamud.Game;
|
using Dalamud.Game;
|
||||||
|
|
@ -325,7 +325,9 @@ namespace Dalamud
|
||||||
this,
|
this,
|
||||||
this.StartInfo.PluginDirectory,
|
this.StartInfo.PluginDirectory,
|
||||||
this.StartInfo.DefaultPluginDirectory);
|
this.StartInfo.DefaultPluginDirectory);
|
||||||
this.PluginManager.LoadPlugins();
|
this.PluginManager.LoadSynchronousPlugins();
|
||||||
|
|
||||||
|
Task.Run(() => this.PluginManager.LoadDeferredPlugins());
|
||||||
|
|
||||||
Log.Information("[T3] PM OK!");
|
Log.Information("[T3] PM OK!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,12 @@ namespace Dalamud.Plugin
|
||||||
this.Plugins.Clear();
|
this.Plugins.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<(FileInfo dllFile, PluginDefinition definition, bool isRaw)> deferredPlugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load all regular and dev plugins.
|
/// Load plugins that need to be loaded synchronously and prepare plugins that can be loaded asynchronously.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadPlugins()
|
public void LoadSynchronousPlugins()
|
||||||
{
|
{
|
||||||
var loadDirectories = new List<(DirectoryInfo dirInfo, bool isRaw)>
|
var loadDirectories = new List<(DirectoryInfo dirInfo, bool isRaw)>
|
||||||
{
|
{
|
||||||
|
|
@ -147,8 +149,36 @@ namespace Dalamud.Plugin
|
||||||
return prio2.CompareTo(prio1);
|
return prio2.CompareTo(prio1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pass preloaded definitions to LoadPluginFromAssembly, because we already loaded them anyways
|
this.deferredPlugins = pluginDefs.Where(x => x.definition?.LoadPriority <= 0);
|
||||||
foreach (var (dllFile, definition, isRaw) in pluginDefs)
|
|
||||||
|
// Pass preloaded definitions for "synchronous load" plugins to LoadPluginFromAssembly, because we already loaded them anyways
|
||||||
|
foreach (var (dllFile, definition, isRaw) in pluginDefs.Where(x => x.definition?.LoadPriority > 0))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.LoadPluginFromAssembly(dllFile, isRaw, PluginLoadReason.Boot, definition);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, $"Plugin load for {dllFile.FullName} failed.");
|
||||||
|
if (ex is ReflectionTypeLoadException typeLoadException)
|
||||||
|
{
|
||||||
|
foreach (var exception in typeLoadException.LoaderExceptions)
|
||||||
|
{
|
||||||
|
Log.Error(exception, "LoaderException:");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadDeferredPlugins()
|
||||||
|
{
|
||||||
|
if (this.deferredPlugins == null)
|
||||||
|
throw new Exception("Synchronous plugins need to be loaded before deferred plugins.");
|
||||||
|
|
||||||
|
// Pass preloaded definitions for "deferred load" plugins to LoadPluginFromAssembly, because we already loaded them anyways
|
||||||
|
foreach (var (dllFile, definition, isRaw) in this.deferredPlugins)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -343,7 +373,7 @@ namespace Dalamud.Plugin
|
||||||
public void ReloadPlugins()
|
public void ReloadPlugins()
|
||||||
{
|
{
|
||||||
this.UnloadPlugins();
|
this.UnloadPlugins();
|
||||||
this.LoadPlugins();
|
this.LoadSynchronousPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BannedPlugin
|
private class BannedPlugin
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue