1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
55using System . Reflection ;
66using System . Runtime . Loader ;
7+ using System . Threading . Tasks ;
8+ using System . Windows . Forms ;
79using Flow . Launcher . Infrastructure ;
8- using Flow . Launcher . Infrastructure . Exception ;
910using Flow . Launcher . Infrastructure . Logger ;
1011using Flow . Launcher . Infrastructure . UserSettings ;
1112using Flow . Launcher . Plugin ;
@@ -29,6 +30,8 @@ public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSe
2930
3031 public static IEnumerable < PluginPair > DotNetPlugins ( List < PluginMetadata > source )
3132 {
33+ var erroredPlugins = new List < string > ( ) ;
34+
3235 var plugins = new List < PluginPair > ( ) ;
3336 var metadatas = source . Where ( o => AllowedLanguage . IsDotNet ( o . Language ) ) ;
3437
@@ -50,28 +53,44 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
5053 }
5154 catch ( Exception e )
5255 {
53- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Couldn't load assembly for { metadata . Name } ", e ) ;
56+ erroredPlugins . Add ( metadata . Name ) ;
57+
58+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Couldn't load assembly for the plugin: { metadata . Name } ", e ) ;
5459 return ;
5560 }
56- var types = assembly . GetTypes ( ) ;
61+
5762 Type type ;
5863 try
5964 {
65+ var types = assembly . GetTypes ( ) ;
66+
6067 type = types . First ( o => o . IsClass && ! o . IsAbstract && o . GetInterfaces ( ) . Contains ( typeof ( IPlugin ) ) ) ;
6168 }
6269 catch ( InvalidOperationException e )
6370 {
64- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't find class implement IPlugin for <{ metadata . Name } >", e ) ;
71+ erroredPlugins . Add ( metadata . Name ) ;
72+
73+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't find the required IPlugin interface for the plugin: <{ metadata . Name } >", e ) ;
74+ return ;
75+ }
76+ catch ( ReflectionTypeLoadException e )
77+ {
78+ erroredPlugins . Add ( metadata . Name ) ;
79+
80+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for the plugin: <{ metadata . Name } >", e ) ;
6581 return ;
6682 }
83+
6784 IPlugin plugin ;
6885 try
6986 {
7087 plugin = ( IPlugin ) Activator . CreateInstance ( type ) ;
7188 }
7289 catch ( Exception e )
7390 {
74- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't create instance for <{ metadata . Name } >", e ) ;
91+ erroredPlugins . Add ( metadata . Name ) ;
92+
93+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The following plugin has errored and can not be loaded: <{ metadata . Name } >", e ) ;
7594 return ;
7695 }
7796#endif
@@ -85,6 +104,26 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
85104 metadata . InitTime += milliseconds ;
86105
87106 }
107+
108+ if ( erroredPlugins . Count > 0 )
109+ {
110+ var errorPluginString = "" ;
111+
112+ var errorMessage = "The following "
113+ + ( erroredPlugins . Count > 1 ? "plugins have " : "plugin has " )
114+ + "errored and cannot be loaded:" ;
115+
116+ erroredPlugins . ForEach ( x => errorPluginString += x + Environment . NewLine ) ;
117+
118+ Task . Run ( ( ) =>
119+ {
120+ MessageBox . Show ( $ "{ errorMessage } { Environment . NewLine } { Environment . NewLine } " +
121+ $ "{ errorPluginString } { Environment . NewLine } { Environment . NewLine } " +
122+ $ "Please refer to the logs for more information", "" ,
123+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
124+ } ) ;
125+ }
126+
88127 return plugins ;
89128 }
90129
0 commit comments