mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge pull request #394 from daemitus/PluginLoadReason
This commit is contained in:
commit
a5abe091da
7 changed files with 62 additions and 19 deletions
|
|
@ -83,7 +83,7 @@ namespace Dalamud.Interface.Internal.Scratchpad
|
||||||
{
|
{
|
||||||
var script = CSharpScript.Create(code, options);
|
var script = CSharpScript.Create(code, options);
|
||||||
|
|
||||||
var pi = new DalamudPluginInterface(this.dalamud, "Scratch-" + doc.Id, null);
|
var pi = new DalamudPluginInterface(this.dalamud, "Scratch-" + doc.Id, null, PluginLoadReason.Unknown);
|
||||||
var plugin = script.ContinueWith<IDalamudPlugin>("return new ScratchPlugin() as IDalamudPlugin;")
|
var plugin = script.ContinueWith<IDalamudPlugin>("return new ScratchPlugin() as IDalamudPlugin;")
|
||||||
.RunAsync().GetAwaiter().GetResult().ReturnValue;
|
.RunAsync().GetAwaiter().GetResult().ReturnValue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -548,8 +548,8 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
private void DrawIpcDebug()
|
private void DrawIpcDebug()
|
||||||
{
|
{
|
||||||
var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null);
|
var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null, PluginLoadReason.Unknown);
|
||||||
var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null);
|
var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null, PluginLoadReason.Unknown);
|
||||||
|
|
||||||
if (ImGui.Button("Add test sub"))
|
if (ImGui.Button("Add test sub"))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ using CheapLoc;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin.Internal;
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Plugin.Internal.Exceptions;
|
using Dalamud.Plugin.Internal.Exceptions;
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
|
|
@ -526,7 +527,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
{
|
{
|
||||||
this.installStatus = OperationStatus.InProgress;
|
this.installStatus = OperationStatus.InProgress;
|
||||||
|
|
||||||
Task.Run(() => this.dalamud.PluginManager.InstallPlugin(manifest, useTesting))
|
Task.Run(() => this.dalamud.PluginManager.InstallPlugin(manifest, useTesting, PluginLoadReason.Installer))
|
||||||
.ContinueWith(task =>
|
.ContinueWith(task =>
|
||||||
{
|
{
|
||||||
// There is no need to set as Complete for an individual plugin installation
|
// There is no need to set as Complete for an individual plugin installation
|
||||||
|
|
@ -743,7 +744,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
if (!enableTask.Result)
|
if (!enableTask.Result)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var loadTask = Task.Run(() => plugin.Load())
|
var loadTask = Task.Run(() => plugin.Load(PluginLoadReason.Installer))
|
||||||
.ContinueWith(this.DisplayErrorContinuation, Locs.ErrorModal_LoadFail(plugin.Name));
|
.ContinueWith(this.DisplayErrorContinuation, Locs.ErrorModal_LoadFail(plugin.Name));
|
||||||
|
|
||||||
loadTask.Wait();
|
loadTask.Wait();
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ namespace Dalamud.Plugin
|
||||||
/// <param name="dalamud">The dalamud instance to expose.</param>
|
/// <param name="dalamud">The dalamud instance to expose.</param>
|
||||||
/// <param name="pluginName">The internal name of the plugin.</param>
|
/// <param name="pluginName">The internal name of the plugin.</param>
|
||||||
/// <param name="assemblyLocation">The equivalent of what Assembly.GetExecutingAssembly().Location should return.</param>
|
/// <param name="assemblyLocation">The equivalent of what Assembly.GetExecutingAssembly().Location should return.</param>
|
||||||
internal DalamudPluginInterface(Dalamud dalamud, string pluginName, string assemblyLocation)
|
/// <param name="reason">The reason the plugin was loaded.</param>
|
||||||
|
internal DalamudPluginInterface(Dalamud dalamud, string pluginName, string assemblyLocation, PluginLoadReason reason)
|
||||||
{
|
{
|
||||||
this.CommandManager = dalamud.CommandManager;
|
this.CommandManager = dalamud.CommandManager;
|
||||||
this.Framework = dalamud.Framework;
|
this.Framework = dalamud.Framework;
|
||||||
|
|
@ -50,6 +51,7 @@ namespace Dalamud.Plugin
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.configs = dalamud.PluginManager.PluginConfigs;
|
this.configs = dalamud.PluginManager.PluginConfigs;
|
||||||
this.AssemblyLocation = assemblyLocation;
|
this.AssemblyLocation = assemblyLocation;
|
||||||
|
this.Reason = reason;
|
||||||
|
|
||||||
this.GeneralChatType = this.dalamud.Configuration.GeneralChatType;
|
this.GeneralChatType = this.dalamud.Configuration.GeneralChatType;
|
||||||
this.Sanitizer = new Sanitizer(this.Data.Language);
|
this.Sanitizer = new Sanitizer(this.Data.Language);
|
||||||
|
|
@ -81,6 +83,11 @@ namespace Dalamud.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event LanguageChangedDelegate OnLanguageChanged;
|
public event LanguageChangedDelegate OnLanguageChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the reason this plugin was loaded.
|
||||||
|
/// </summary>
|
||||||
|
public PluginLoadReason Reason { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin assembly location.
|
/// Gets the plugin assembly location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
public PluginState State { get; protected set; } = PluginState.Unloaded;
|
public PluginState State { get; protected set; } = PluginState.Unloaded;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the AssemblyName plugin, populated during <see cref="Load(bool)"/>.
|
/// Gets the AssemblyName plugin, populated during <see cref="Load(PluginLoadReason, bool)"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Plugin type.</returns>
|
/// <returns>Plugin type.</returns>
|
||||||
public AssemblyName AssemblyName { get; private set; } = null;
|
public AssemblyName AssemblyName { get; private set; } = null;
|
||||||
|
|
@ -188,8 +188,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load this plugin.
|
/// Load this plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="reason">The reason why this plugin is being loaded.</param>
|
||||||
/// <param name="reloading">Load while reloading.</param>
|
/// <param name="reloading">Load while reloading.</param>
|
||||||
public void Load(bool reloading = false)
|
public void Load(PluginLoadReason reason, bool reloading = false)
|
||||||
{
|
{
|
||||||
// Allowed: Unloaded
|
// Allowed: Unloaded
|
||||||
switch (this.State)
|
switch (this.State)
|
||||||
|
|
@ -271,7 +272,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
this.Manifest.Save(this.manifestFile);
|
this.Manifest.Save(this.manifestFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.DalamudInterface = new DalamudPluginInterface(this.dalamud, this.pluginAssembly.GetName().Name, this.DllFile.FullName);
|
this.DalamudInterface = new DalamudPluginInterface(this.dalamud, this.pluginAssembly.GetName().Name, this.DllFile.FullName, reason);
|
||||||
|
|
||||||
if (this.IsDev)
|
if (this.IsDev)
|
||||||
{
|
{
|
||||||
|
|
@ -365,7 +366,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
public void Reload()
|
public void Reload()
|
||||||
{
|
{
|
||||||
this.Unload(true);
|
this.Unload(true);
|
||||||
this.Load(true);
|
this.Load(PluginLoadReason.Reload, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.LoadPlugin(pluginDef.DllFile, pluginDef.Manifest, pluginDef.IsDev, isBoot: true);
|
this.LoadPlugin(pluginDef.DllFile, pluginDef.Manifest, PluginLoadReason.Boot, pluginDef.IsDev, isBoot: true);
|
||||||
}
|
}
|
||||||
catch (InvalidPluginException)
|
catch (InvalidPluginException)
|
||||||
{
|
{
|
||||||
|
|
@ -230,8 +230,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.Unload();
|
plugin.Reload();
|
||||||
plugin.Load();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -300,7 +299,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Add them to the list and let the user decide, nothing is auto-loaded.
|
// Add them to the list and let the user decide, nothing is auto-loaded.
|
||||||
this.LoadPlugin(dllFile, manifest, isDev: true, doNotLoad: true);
|
this.LoadPlugin(dllFile, manifest, PluginLoadReason.Installer, isDev: true, doNotLoad: true);
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
catch (InvalidPluginException)
|
catch (InvalidPluginException)
|
||||||
|
|
@ -322,7 +321,8 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repoManifest">The plugin definition.</param>
|
/// <param name="repoManifest">The plugin definition.</param>
|
||||||
/// <param name="useTesting">If the testing version should be used.</param>
|
/// <param name="useTesting">If the testing version should be used.</param>
|
||||||
public void InstallPlugin(RemotePluginManifest repoManifest, bool useTesting)
|
/// <param name="reason">The reason this plugin was loaded.</param>
|
||||||
|
public void InstallPlugin(RemotePluginManifest repoManifest, bool useTesting, PluginLoadReason reason)
|
||||||
{
|
{
|
||||||
Log.Debug($"Installing plugin {repoManifest.Name} (testing={useTesting})");
|
Log.Debug($"Installing plugin {repoManifest.Name} (testing={useTesting})");
|
||||||
|
|
||||||
|
|
@ -413,7 +413,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
Log.Information($"Installed plugin {manifest.Name} (testing={useTesting})");
|
Log.Information($"Installed plugin {manifest.Name} (testing={useTesting})");
|
||||||
|
|
||||||
this.LoadPlugin(dllFile, manifest);
|
this.LoadPlugin(dllFile, manifest, reason);
|
||||||
|
|
||||||
this.NotifyInstalledPluginsChanged();
|
this.NotifyInstalledPluginsChanged();
|
||||||
}
|
}
|
||||||
|
|
@ -423,10 +423,11 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dllFile">The <see cref="FileInfo"/> associated with the main assembly of this plugin.</param>
|
/// <param name="dllFile">The <see cref="FileInfo"/> associated with the main assembly of this plugin.</param>
|
||||||
/// <param name="manifest">The already loaded definition, if available.</param>
|
/// <param name="manifest">The already loaded definition, if available.</param>
|
||||||
|
/// <param name="reason">The reason this plugin was loaded.</param>
|
||||||
/// <param name="isDev">If this plugin should support development features.</param>
|
/// <param name="isDev">If this plugin should support development features.</param>
|
||||||
/// <param name="isBoot">If this plugin is being loaded at boot.</param>
|
/// <param name="isBoot">If this plugin is being loaded at boot.</param>
|
||||||
/// <param name="doNotLoad">Don't load the plugin, just don't do it.</param>
|
/// <param name="doNotLoad">Don't load the plugin, just don't do it.</param>
|
||||||
public void LoadPlugin(FileInfo dllFile, LocalPluginManifest manifest, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
|
public void LoadPlugin(FileInfo dllFile, LocalPluginManifest manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
|
||||||
{
|
{
|
||||||
var name = manifest?.Name ?? dllFile.Name;
|
var name = manifest?.Name ?? dllFile.Name;
|
||||||
var loadPlugin = !doNotLoad;
|
var loadPlugin = !doNotLoad;
|
||||||
|
|
@ -454,7 +455,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
if (plugin.IsDisabled)
|
if (plugin.IsDisabled)
|
||||||
plugin.Enable();
|
plugin.Enable();
|
||||||
|
|
||||||
plugin.Load();
|
plugin.Load(reason);
|
||||||
}
|
}
|
||||||
catch (InvalidPluginException)
|
catch (InvalidPluginException)
|
||||||
{
|
{
|
||||||
|
|
@ -653,7 +654,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.InstallPlugin(metadata.UpdateManifest, metadata.UseTesting);
|
this.InstallPlugin(metadata.UpdateManifest, metadata.UseTesting, PluginLoadReason.Update);
|
||||||
listChanged = true;
|
listChanged = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
33
Dalamud/Plugin/PluginLoadReason.cs
Normal file
33
Dalamud/Plugin/PluginLoadReason.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
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 it was just updated.
|
||||||
|
/// </summary>
|
||||||
|
Update,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This plugin was loaded because it was told to reload.
|
||||||
|
/// </summary>
|
||||||
|
Reload,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This plugin was loaded because the game was started or Dalamud was reinjected.
|
||||||
|
/// </summary>
|
||||||
|
Boot,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue