mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
feat: add PluginLoadReason to plugin interface
This commit is contained in:
parent
fe76d1e31a
commit
a9b388f9de
5 changed files with 43 additions and 8 deletions
|
|
@ -182,8 +182,8 @@ namespace Dalamud.Interface
|
||||||
|
|
||||||
// Subscriptions
|
// Subscriptions
|
||||||
case 5:
|
case 5:
|
||||||
var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null);
|
var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null, PluginLoadReason.Boot);
|
||||||
var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null);
|
var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null, PluginLoadReason.Boot);
|
||||||
|
|
||||||
if (ImGui.Button("Add test sub")) i1.Subscribe("DalamudTestPub", o => {
|
if (ImGui.Button("Add test sub")) i1.Subscribe("DalamudTestPub", o => {
|
||||||
dynamic msg = o;
|
dynamic msg = o;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,11 @@ namespace Dalamud.Plugin
|
||||||
/// This class acts as an interface to various objects needed to interact with Dalamud and the game.
|
/// This class acts as an interface to various objects needed to interact with Dalamud and the game.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DalamudPluginInterface : IDisposable {
|
public class DalamudPluginInterface : IDisposable {
|
||||||
|
/// <summary>
|
||||||
|
/// The reason this plugin was loaded.
|
||||||
|
/// </summary>
|
||||||
|
public PluginLoadReason Reason { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The CommandManager object that allows you to add and remove custom chat commands.
|
/// The CommandManager object that allows you to add and remove custom chat commands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -65,7 +70,8 @@ namespace Dalamud.Plugin
|
||||||
/// Set up the interface and populate all fields needed.
|
/// Set up the interface and populate all fields needed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dalamud"></param>
|
/// <param name="dalamud"></param>
|
||||||
public DalamudPluginInterface(Dalamud dalamud, string pluginName, PluginConfigurations configs) {
|
internal DalamudPluginInterface(Dalamud dalamud, string pluginName, PluginConfigurations configs, PluginLoadReason reason) {
|
||||||
|
Reason = reason;
|
||||||
this.CommandManager = dalamud.CommandManager;
|
this.CommandManager = dalamud.CommandManager;
|
||||||
this.Framework = dalamud.Framework;
|
this.Framework = dalamud.Framework;
|
||||||
this.ClientState = dalamud.ClientState;
|
this.ClientState = dalamud.ClientState;
|
||||||
|
|
|
||||||
29
Dalamud/Plugin/PluginLoadReason.cs
Normal file
29
Dalamud/Plugin/PluginLoadReason.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Dalamud.Plugin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This enum reflects reasons for loading a plugin.
|
||||||
|
/// </summary>
|
||||||
|
public enum PluginLoadReason
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// We don't know why this plugin was loaded.
|
||||||
|
/// </summary>
|
||||||
|
Unknown,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This plugin was loaded because it was installed with the plugin installer.
|
||||||
|
/// </summary>
|
||||||
|
Installer,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This plugin was loaded because the game was started or Dalamud was reinjected.
|
||||||
|
/// </summary>
|
||||||
|
Boot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ namespace Dalamud.Plugin
|
||||||
this.Plugins.Remove(thisPlugin);
|
this.Plugins.Remove(thisPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LoadPluginFromAssembly(FileInfo dllFile, bool raw) {
|
public bool LoadPluginFromAssembly(FileInfo dllFile, bool raw, PluginLoadReason reason) {
|
||||||
Log.Information("Loading plugin at {0}", dllFile.Directory.FullName);
|
Log.Information("Loading plugin at {0}", dllFile.Directory.FullName);
|
||||||
|
|
||||||
// If this entire folder has been marked as a disabled plugin, don't even try to load anything
|
// If this entire folder has been marked as a disabled plugin, don't even try to load anything
|
||||||
|
|
@ -170,7 +170,7 @@ namespace Dalamud.Plugin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs);
|
var dalamudInterface = new DalamudPluginInterface(this.dalamud, type.Assembly.GetName().Name, this.pluginConfigs, reason);
|
||||||
plugin.Initialize(dalamudInterface);
|
plugin.Initialize(dalamudInterface);
|
||||||
|
|
||||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||||
|
|
@ -194,7 +194,7 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
foreach (var dllFile in pluginDlls) {
|
foreach (var dllFile in pluginDlls) {
|
||||||
try {
|
try {
|
||||||
LoadPluginFromAssembly(dllFile, raw);
|
LoadPluginFromAssembly(dllFile, raw, PluginLoadReason.Boot);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.Error(ex, $"Plugin load for {dllFile.FullName} failed.");
|
Log.Error(ex, $"Plugin load for {dllFile.FullName} failed.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ namespace Dalamud.Plugin
|
||||||
if (disabledFile.Exists)
|
if (disabledFile.Exists)
|
||||||
disabledFile.Delete();
|
disabledFile.Delete();
|
||||||
|
|
||||||
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false);
|
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false, PluginLoadReason.Installer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dllFile.Exists && !enableAfterInstall) {
|
if (dllFile.Exists && !enableAfterInstall) {
|
||||||
|
|
@ -105,7 +105,7 @@ namespace Dalamud.Plugin
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false);
|
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false, PluginLoadReason.Installer);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue