-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginLoader.cs
More file actions
55 lines (49 loc) · 2.03 KB
/
PluginLoader.cs
File metadata and controls
55 lines (49 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Spectre.Console;
namespace NShell.Shell.Plugins
{
/// <summary>
/// <c>PluginLoader</c> manage all about loading, parse, execute plugins.
/// </summary>
public class PluginLoader
{
private string PluginFolderPath { get; set; } = $"/home/{Environment.UserName}/.nshell/plugins";
public string[] PluginList { get; set; }
public int NumberOfPlugins { get; set; }
public static PluginLoader Instance { get; private set; } = null!;
/// <summary>
/// Load all plugins into <c>~/.nshell/plugins</c> folder.
/// </summary>
public void LoadPlugins()
{
if (Path.Exists(PluginFolderPath))
{
var PluginList = Directory.GetFiles(
PluginFolderPath,
"*.dll",
SearchOption.AllDirectories);
if (PluginList.Length > 0)
{
NumberOfPlugins = PluginList.Length;
foreach (var plugin in PluginList)
{
AnsiConsole.MarkupLine($"\t[[[green]+[/]]] - Loading plugin : [yellow]{plugin}[/].");
}
AnsiConsole.MarkupLine($"[bold grey]→ Total plugins loaded:[/] [bold green]{NumberOfPlugins}[/]");
}
else
{
NumberOfPlugins = 0;
AnsiConsole.MarkupLine($"\t[[[yellow]*[/]]] - No plugins found.");
AnsiConsole.MarkupLine($"[bold grey]→ Total plugins loaded:[/] [bold yellow]{NumberOfPlugins}[/]");
}
}
else
{
PluginList = [];
AnsiConsole.MarkupLine($"\t[[[red]-[/]]] - Plugin directory doesn't exist.");
AnsiConsole.MarkupLine($"\t[[[yellow]*[/]]] - Creating plugins directory.");
Directory.CreateDirectory(PluginFolderPath);
}
}
}
}