@@ -42,18 +42,26 @@ public List<T> Make<T>() where T : class, IPluginType
4242 . ToList ( ) ;
4343 }
4444
45- public static List < Plugin > Discover < T > ( ) where T : IPluginType
45+ public static List < Plugin > Load < T > ( ) where T : IPluginType
4646 {
47- var logger = LogManager . GetCurrentClassLogger ( ) ;
48- var discoveredAssemblies = InEngineSettings . Make ( ) . PluginDirectories . SelectMany ( x => {
49- if ( ! Directory . Exists ( x ) ) {
50- logger . Warn ( "Plugin directory does not exist: " + x ) ;
51- return new List < Assembly > ( ) ;
52- }
53- return Directory . GetFiles ( x , "*.dll" ) . Select ( y => Assembly . LoadFrom ( y ) ) ;
54- } ) ;
5547 var pluginList = new List < Plugin > ( ) ;
56- foreach ( var assembly in discoveredAssemblies )
48+ var logger = LogManager . GetCurrentClassLogger ( ) ;
49+
50+ logger . Debug ( "Loading core plugin..." ) ;
51+ try
52+ {
53+ pluginList . Add ( new Plugin ( Assembly . GetExecutingAssembly ( ) ) ) ;
54+ }
55+ catch ( Exception exception )
56+ {
57+ logger . Error ( exception , "Error loading InEngine.Core plugin." ) ;
58+ }
59+
60+ var assemblies = InEngineSettings
61+ . Make ( )
62+ . Plugins
63+ . Select ( x => Assembly . LoadFrom ( $ "{ x } .dll") ) ;
64+ foreach ( var assembly in assemblies )
5765 {
5866 try
5967 {
@@ -62,9 +70,11 @@ public static List<Plugin> Discover<T>() where T : IPluginType
6270 }
6371 catch ( Exception exception )
6472 {
65- logger . Error ( exception , "Error discovering plugins" ) ;
73+ logger . Error ( exception , "Error loading plugins. " ) ;
6674 }
6775 }
76+ if ( ! pluginList . Any ( ) )
77+ throw new PluginNotFoundException ( "There are no plugins available." ) ;
6878 return pluginList . OrderBy ( x => x . Name ) . ToList ( ) ;
6979 }
7080
0 commit comments