|
| 1 | +using FlipnoteDesktop.Environment.Canvas; |
| 2 | +using FlipnoteDesktop.Windows; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Reflection; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using System.Windows.Controls; |
| 10 | + |
| 11 | +namespace FlipnoteDesktop.External.Plugins |
| 12 | +{ |
| 13 | + internal static class PluginManager |
| 14 | + { |
| 15 | + public static void ImportPlugins(string dllpath) |
| 16 | + { |
| 17 | + try |
| 18 | + { |
| 19 | + Assembly assembly = Assembly.LoadFrom(dllpath); |
| 20 | + Type type = assembly.GetType("FDHeader.Metadata"); |
| 21 | + var asm_name = type.GetField("PluginName").GetValue(null) as string; |
| 22 | + var exports = type.GetField("Exports").GetValue(null) as List<string>; |
| 23 | + for (int i = 0, cnt = exports.Count; i < cnt; i++) |
| 24 | + { |
| 25 | + try |
| 26 | + { |
| 27 | + var _class = assembly.GetType(exports[i]); |
| 28 | + if(_class.IsSubclassOf(typeof(Generator))) |
| 29 | + { |
| 30 | + Plugins.Add(new PluginData(asm_name, exports[i], PluginTypes.Generator, _class)); |
| 31 | + } |
| 32 | + } |
| 33 | + catch(TypeLoadException) |
| 34 | + { |
| 35 | + Plugins.Add(PluginData.Failed(asm_name, exports[i])); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + catch(Exception) |
| 40 | + { |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public static List<PluginData> Plugins = new List<PluginData>(); |
| 45 | + |
| 46 | + public static void Populate(MainWindow wnd) |
| 47 | + { |
| 48 | + for (int i = 0, cnt = Plugins.Count; i < cnt; i++) |
| 49 | + { |
| 50 | + if(Plugins[i].PluginType==PluginTypes.Generator) |
| 51 | + { |
| 52 | + var item = new MenuItem(); |
| 53 | + item.Header = Plugins[i].PluginName; |
| 54 | + item.Tag = Plugins[i].Class; |
| 55 | + item.Click += wnd.GeneratorMenuItem_Click; |
| 56 | + wnd.GeneratorsMenuItem.Items.Add(item); |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments