Skip to content

Commit 700b6fc

Browse files
committed
Make plugin directory configurable
1 parent 7ad1fcf commit 700b6fc

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

src/InEngine.Core/InEngineSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
23
using InEngine.Core.Queue;
34
using Microsoft.Extensions.Configuration;
45

@@ -8,6 +9,7 @@ public class InEngineSettings
89
{
910
public static string BasePath { get; set; } = Directory.GetCurrentDirectory();
1011
public static string ConfigurationFile { get; set; } = "appsettings.json";
12+
public List<string> PluginDirectories { get; set; }
1113
public QueueSettings Queue { get; set; }
1214

1315
public static InEngineSettings Make()

src/InEngine.Core/Plugin.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ public List<T> Make<T>() where T : class, IPluginType
4343

4444
public static List<Plugin> Discover<T>() where T : IPluginType
4545
{
46-
var discoveredAssemblies = Directory
47-
.GetFiles(".", "*.dll")
48-
.Select(x => Assembly.LoadFrom(x));
46+
var logger = LogManager.GetCurrentClassLogger();
47+
var discoveredAssemblies = InEngineSettings.Make().PluginDirectories.SelectMany(x => {
48+
if (!Directory.Exists(x)) {
49+
logger.Warn("Plugin directory does not exist: " + x);
50+
return new List<Assembly>();
51+
}
52+
return Directory.GetFiles(x, "*.dll").Select(y => Assembly.LoadFrom(y));
53+
});
4954
var pluginList = new List<Plugin>();
5055
foreach (var assembly in discoveredAssemblies)
5156
{
@@ -56,10 +61,10 @@ public static List<Plugin> Discover<T>() where T : IPluginType
5661
}
5762
catch (Exception exception)
5863
{
59-
LogManager.GetCurrentClassLogger().Error(exception, "Error discovering plugins");
64+
logger.Error(exception, "Error discovering plugins");
6065
}
6166
}
62-
return pluginList;
67+
return pluginList.OrderBy(x => x.Name).ToList();
6368
}
6469

6570
public ICommand CreateCommandInstance(string fullCommandName)

src/InEngine/InEngine.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<ProjectReference Include="..\InEngine.Core\InEngine.Core.csproj" />
9+
<ProjectReference Include="..\InEngine.Commands\InEngine.Commands.csproj" />
910
</ItemGroup>
1011
<ItemGroup>
1112
<PackageReference Include="NETStandard.Library" Version="2.0.1" />
@@ -33,6 +34,9 @@
3334
<None Update="appsettings.json">
3435
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3536
</None>
37+
<None Update="Plugins\README.md">
38+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
39+
</None>
3640
</ItemGroup>
3741
<ItemGroup>
3842
<Compile Include="..\SharedAssemblyInfo.cs">

src/InEngine/Plugins/.gitkeep

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/InEngine/Plugins/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is the default location for 3rd party plugins.

src/InEngine/appsettings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"InEngine": {
3+
"PluginDirectories": [ ".", "Plugins" ],
34
"Queue": {
5+
"CompressionEnabled": true,
46
"PrimaryQueueConsumers": 16,
57
"SecondaryQueueConsumers": 4,
68
"QueueName": "InEngine:Queue",

0 commit comments

Comments
 (0)