public List <UniversalPlugin> LoadPlugins(string PluginDirectory) { returnPlugins = new List <UniversalPlugin>(); string pluginDataDirectory = Path.Combine(PluginDirectory, "Data"); ILogger.AddWhitespace(); if (!Directory.Exists(pluginDataDirectory)) { Directory.CreateDirectory(pluginDataDirectory); } if (Directory.Exists(PluginDirectory)) { string[] files = Directory.GetFiles(PluginDirectory); foreach (string file in files) { if (file.EndsWith(".dll")) { Assembly.LoadFile(Path.GetFullPath(file)); } } } else { Directory.CreateDirectory(PluginDirectory); } Type interfaceType = typeof(IUniversalPlugin); Type[] types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass).ToArray(); foreach (Type type in types) { try { IUniversalPlugin plugin = (IUniversalPlugin)Activator.CreateInstance(type); UniversalPlugin pluginInstance = new UniversalPlugin(plugin); pluginInstance.core = plugin; ILogger.AddToLog(ILogger.Levels.INFO, "Initializing [" + pluginInstance.core.Name + "]"); pluginInstance.core.SetUniversalPluginAPI(pluginInstance); pluginInstance.core.Initialize(Path.Combine(pluginDataDirectory, pluginInstance.core.Name), pluginInstance); returnPlugins.Add(pluginInstance); ILogger.AddToLog(ILogger.Levels.INFO, "Plugin [" + pluginInstance.core.Name + "] Fully loaded!"); } catch (Exception e) { //Tried to load the assembly instance } } ILogger.AddWhitespace(); return(returnPlugins); }
public UniversalPlugin(IUniversalPlugin InterfaceClass) { core = InterfaceClass; core.SetUniversalPluginAPI(this); }