Merge remote-tracking branch 'origin/master' into apiX-rollup

This commit is contained in:
github-actions[bot] 2024-06-08 23:34:08 +00:00
commit 4e331b1d85
28 changed files with 1320 additions and 341 deletions

View file

@ -2,5 +2,12 @@
namespace Dalamud.Plugin;
/// <summary>
/// State of an installed plugin.
/// </summary>
/// <param name="Name">The name of the plugin.</param>
/// <param name="InternalName">The internal name of the plugin.</param>
/// <param name="IsLoaded">Whether or not the plugin is loaded.</param>
/// <param name="Version">The version of the plugin.</param>
[Api10ToDo("Refactor into an interface, add wrappers for OpenMainUI and OpenConfigUI")]
public record InstalledPluginState(string Name, string InternalName, bool IsLoaded, Version Version);

View file

@ -178,7 +178,6 @@ internal class LocalPlugin : IDisposable
/// Gets a value indicating whether or not this plugin is orphaned(belongs to a repo) or not.
/// </summary>
public bool IsOrphaned => !this.IsDev &&
!this.manifest.InstalledFromUrl.IsNullOrEmpty() && // TODO(api8): Remove this, all plugins will have a proper flag
this.GetSourceRepository() == null;
/// <summary>
@ -413,28 +412,39 @@ internal class LocalPlugin : IDisposable
this.ServiceScope = ioc.GetScope();
this.ServiceScope.RegisterPrivateScopes(this); // Add this LocalPlugin as a private scope, so services can get it
if (this.manifest.LoadSync && this.manifest.LoadRequiredState is 0 or 1)
try
{
this.instance = await framework.RunOnFrameworkThread(
() => this.ServiceScope.CreateAsync(this.pluginType!, this.DalamudInterface!)) as IDalamudPlugin;
if (this.manifest.LoadSync && this.manifest.LoadRequiredState is 0 or 1)
{
this.instance = await framework.RunOnFrameworkThread(
() => this.ServiceScope.CreateAsync(
this.pluginType!,
this.DalamudInterface!)) as IDalamudPlugin;
}
else
{
this.instance =
await this.ServiceScope.CreateAsync(this.pluginType!, this.DalamudInterface!) as IDalamudPlugin;
}
}
else
catch (Exception ex)
{
this.instance =
await this.ServiceScope.CreateAsync(this.pluginType!, this.DalamudInterface!) as IDalamudPlugin;
Log.Error(ex, "Exception in plugin constructor");
this.instance = null;
}
if (this.instance == null)
{
this.State = PluginState.LoadError;
this.DalamudInterface.DisposeInternal();
this.UnloadAndDisposeState();
Log.Error(
$"Error while loading {this.Name}, failed to bind and call the plugin constructor");
"Error while loading {PluginName}, failed to bind and call the plugin constructor", this.InternalName);
return;
}
this.State = PluginState.Loaded;
Log.Information($"Finished loading {this.DllFile.Name}");
Log.Information("Finished loading {PluginName}", this.InternalName);
}
catch (Exception ex)
{
@ -444,7 +454,7 @@ internal class LocalPlugin : IDisposable
if (ex is PluginPreconditionFailedException)
Log.Warning(ex.Message);
else
Log.Error(ex, $"Error while loading {this.Name}");
Log.Error(ex, "Error while loading {PluginName}", this.InternalName);
throw;
}
@ -499,15 +509,7 @@ internal class LocalPlugin : IDisposable
await framework.RunOnFrameworkThread(() => this.instance?.Dispose());
this.instance = null;
this.DalamudInterface?.DisposeInternal();
this.DalamudInterface = null;
this.ServiceScope?.Dispose();
this.ServiceScope = null;
this.pluginType = null;
this.pluginAssembly = null;
this.UnloadAndDisposeState();
if (!reloading)
{
@ -676,4 +678,19 @@ internal class LocalPlugin : IDisposable
throw new InvalidPluginException(this.DllFile);
}
}
private void UnloadAndDisposeState()
{
if (this.instance != null)
throw new InvalidOperationException("Plugin instance should be disposed at this point");
this.DalamudInterface?.DisposeInternal();
this.DalamudInterface = null;
this.ServiceScope?.Dispose();
this.ServiceScope = null;
this.pluginType = null;
this.pluginAssembly = null;
}
}

View file

@ -36,7 +36,7 @@ internal record LocalPluginManifest : PluginManifest, ILocalPluginManifest
/// <summary>
/// Gets a value indicating whether this manifest is associated with a plugin that was installed from a third party
/// repo. Unless the manifest has been manually modified, this is determined by the InstalledFromUrl being null.
/// repo.
/// </summary>
public bool IsThirdParty => !this.InstalledFromUrl.IsNullOrEmpty() && this.InstalledFromUrl != SpecialPluginSource.MainRepo;

View file

@ -1,26 +0,0 @@
using System.IO;
namespace Dalamud.Plugin.Internal.Types;
internal record PluginPatchData
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginPatchData"/> class.
/// </summary>
/// <param name="dllFile">DLL file being loaded.</param>
public PluginPatchData(FileSystemInfo dllFile)
{
this.Location = dllFile.FullName;
this.CodeBase = new Uri(dllFile.FullName).AbsoluteUri;
}
/// <summary>
/// Gets simulated Assembly.Location output.
/// </summary>
public string Location { get; }
/// <summary>
/// Gets simulated Assembly.CodeBase output.
/// </summary>
public string CodeBase { get; }
}

View file

@ -0,0 +1,130 @@
using System.Diagnostics.CodeAnalysis;
using Dalamud.Console;
namespace Dalamud.Plugin.Services;
/// <summary>
/// Provides functions to register console commands and variables.
/// </summary>
[Experimental("Dalamud001")]
public interface IConsole
{
/// <summary>
/// Gets this plugin's namespace prefix, derived off its internal name.
/// This is the prefix that all commands and variables registered by this plugin will have.
/// If the internal name is "SamplePlugin", the prefix will be "sampleplugin.".
/// </summary>
public string Prefix { get; }
/// <summary>
/// Add a command to the console.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <param name="description">A description of the command.</param>
/// <param name="func">Function to invoke when the command has been called. Must return a <see cref="bool"/> indicating success.</param>
/// <returns>The added command.</returns>
public IConsoleCommand AddCommand(string name, string description, Func<bool> func);
/// <summary>
/// Add a command to the console.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <param name="description">A description of the command.</param>
/// <param name="func">Function to invoke when the command has been called. Must return a <see cref="bool"/> indicating success.</param>
/// <typeparam name="T1">The first argument to the command.</typeparam>
/// <returns>The added command.</returns>
public IConsoleCommand AddCommand<T1>(string name, string description, Func<bool, T1> func);
/// <summary>
/// Add a command to the console.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <param name="description">A description of the command.</param>
/// <param name="func">Function to invoke when the command has been called. Must return a <see cref="bool"/> indicating success.</param>
/// <typeparam name="T1">The first argument to the command.</typeparam>
/// <typeparam name="T2">The second argument to the command.</typeparam>
/// <returns>The added command.</returns>
public IConsoleCommand AddCommand<T1, T2>(string name, string description, Func<bool, T1, T2> func);
/// <summary>
/// Add a command to the console.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <param name="description">A description of the command.</param>
/// <param name="func">Function to invoke when the command has been called. Must return a <see cref="bool"/> indicating success.</param>
/// <typeparam name="T1">The first argument to the command.</typeparam>
/// <typeparam name="T2">The second argument to the command.</typeparam>
/// <typeparam name="T3">The third argument to the command.</typeparam>
/// <returns>The added command.</returns>
public IConsoleCommand AddCommand<T1, T2, T3>(string name, string description, Func<bool, T1, T2, T3> func);
/// <summary>
/// Add a command to the console.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <param name="description">A description of the command.</param>
/// <param name="func">Function to invoke when the command has been called. Must return a <see cref="bool"/> indicating success.</param>
/// <typeparam name="T1">The first argument to the command.</typeparam>
/// <typeparam name="T2">The second argument to the command.</typeparam>
/// <typeparam name="T3">The third argument to the command.</typeparam>
/// <typeparam name="T4">The fourth argument to the command.</typeparam>
/// <returns>The added command.</returns>
public IConsoleCommand AddCommand<T1, T2, T3, T4>(
string name, string description, Func<bool, T1, T2, T3, T4> func);
/// <summary>
/// Add a command to the console.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <param name="description">A description of the command.</param>
/// <param name="func">Function to invoke when the command has been called. Must return a <see cref="bool"/> indicating success.</param>
/// <typeparam name="T1">The first argument to the command.</typeparam>
/// <typeparam name="T2">The second argument to the command.</typeparam>
/// <typeparam name="T3">The third argument to the command.</typeparam>
/// <typeparam name="T4">The fourth argument to the command.</typeparam>
/// <typeparam name="T5">The fifth argument to the command.</typeparam>
/// <returns>The added command.</returns>
public IConsoleCommand AddCommand<T1, T2, T3, T4, T5>(
string name, string description, Func<bool, T1, T2, T3, T4, T5> func);
/// <summary>
/// Add a variable to the console.
/// </summary>
/// <param name="name">The name of the variable.</param>
/// <param name="description">A description of the variable.</param>
/// <param name="defaultValue">The default value of the variable.</param>
/// <typeparam name="T">The type of the variable.</typeparam>
/// <returns>The added variable.</returns>
public IConsoleVariable<T> AddVariable<T>(string name, string description, T defaultValue);
/// <summary>
/// Add an alias to a console entry.
/// </summary>
/// <param name="name">The name of the entry to add an alias for.</param>
/// <param name="alias">The alias to use.</param>
/// <returns>The added alias.</returns>
public IConsoleEntry AddAlias(string name, string alias);
/// <summary>
/// Get the value of a variable.
/// </summary>
/// <param name="name">The name of the variable.</param>
/// <typeparam name="T">The type of the variable.</typeparam>
/// <returns>The value of the variable.</returns>
public T GetVariable<T>(string name);
/// <summary>
/// Set the value of a variable.
/// </summary>
/// <param name="name">The name of the variable.</param>
/// <param name="value">The value to set.</param>
/// <typeparam name="T">The type of the value to set.</typeparam>
public void SetVariable<T>(string name, T value);
/// <summary>
/// Remove an entry from the console.
/// </summary>
/// <param name="entry">The entry to remove.</param>
public void RemoveEntry(IConsoleEntry entry);
}