Skip to content

Commit

Permalink
enable neo core to remove the assembly file if user delete a plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y committed Apr 21, 2022
1 parent a031dc1 commit abee993
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/neo/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public abstract class Plugin : IDisposable
/// </summary>
public static readonly List<Plugin> Plugins = new();

/// <summary>
/// Assemblies of plugin files
/// </summary>
public static readonly Dictionary<string, (Assembly, int)> Assemblies = new();

internal static readonly List<ILogPlugin> Loggers = new();
internal static readonly Dictionary<string, IStorageProvider> Storages = new();
internal static readonly List<IPersistencePlugin> PersistencePlugins = new();
Expand Down Expand Up @@ -197,19 +202,27 @@ private static void LoadPlugin(Assembly assembly)
internal static void LoadPlugins()
{
if (!Directory.Exists(PluginsDirectory)) return;
List<Assembly> assemblies = new();
foreach (string rootPath in Directory.GetDirectories(PluginsDirectory))
{
foreach (var filename in Directory.EnumerateFiles(rootPath, "*.dll", SearchOption.TopDirectoryOnly))
{
try
{
assemblies.Add(Assembly.Load(File.ReadAllBytes(filename)));
if (Assemblies.ContainsKey(filename))
{
Assemblies[filename] = (Assemblies[filename].Item1, Assemblies[filename].Item2 + 1);
}
else
{
var assembly = Assembly.Load(File.ReadAllBytes(filename));
Assemblies.Add(filename, (assembly, 1));
LoadPlugin(assembly);
}
}
catch { }
}
}
foreach (Assembly assembly in assemblies)
foreach (var (_, (assembly, _)) in Assemblies)
{
LoadPlugin(assembly);
}
Expand Down

0 comments on commit abee993

Please sign in to comment.