private void LoadAddons() { try { var registry = _container.Resolve <Registry>(); _container.Register(BuiltinEventConfig.LoadConfig(Config)); // Make sure the event sources are ready before we load any overlays. registry.StartEventSource(new MiniParseEventSource(_container)); registry.StartEventSource(new EnmityEventSource(_container)); registry.RegisterOverlay <MiniParseOverlay>(); registry.RegisterOverlay <SpellTimerOverlay>(); registry.RegisterOverlay <LabelOverlay>(); var version = typeof(PluginMain).Assembly.GetName().Version; var Addons = new List <IOverlayAddonV2>(); var foundCactbot = false; foreach (var plugin in ActGlobals.oFormActMain.ActPlugins) { if (plugin.pluginObj == null) { continue; } try { if (plugin.pluginObj.GetType().GetInterface(typeof(IOverlayAddonV2).FullName) != null) { try { var addon = (IOverlayAddonV2)plugin.pluginObj; addon.Init(); if (addon.ToString() == "Cactbot.PluginLoader") { foundCactbot = true; } _logger.Log(LogLevel.Info, "LoadAddons: {0}: Initialized {1}", plugin.lblPluginTitle.Text, addon.ToString()); } catch (Exception e) { _logger.Log(LogLevel.Error, "LoadAddons: {0}: {1}", plugin.lblPluginTitle.Text, e); } } } catch (Exception e) { _logger.Log(LogLevel.Error, "LoadAddons: {0}: {1}", plugin.lblPluginTitle.Text, e); } } if (!foundCactbot) { if (File.Exists(OfflineCactbotConfigHtmlFile)) { _logger.Log(LogLevel.Info, "LoadAddons: Enabling builtin Cactbot event source."); registry.StartEventSource(new CactbotEventSource(_container)); } else { _logger.Log(LogLevel.Info, "Cactbot offline config files not found, don't enable cactbot event source"); } } registry.StartEventSources(); } catch (Exception e) { _logger.Log(LogLevel.Error, "LoadAddons: {0}", e); Trace.WriteLine("LoadAddons: " + e.ToString()); } }
/// <summary> /// アドオンを読み込みます。 /// </summary> private void LoadAddons() { try { // <プラグイン本体があるディレクトリ>\plugins\*.dll を検索する var directory = Path.Combine(PluginDirectory, "addons"); if (!Directory.Exists(directory)) { try { Directory.CreateDirectory(directory); } catch (Exception e) { Logger.Log(LogLevel.Error, "LoadAddons: {0}", e); } } Registry.Register(BuiltinEventConfig.LoadConfig(Config)); // Make sure the event sources are ready before we load any overlays. Registry.RegisterEventSource <MiniParseEventSource>(); Registry.RegisterEventSource <EnmityEventSource>(); Registry.StartEventSources(); Registry.RegisterOverlay <MiniParseOverlay>(); Registry.RegisterOverlay <SpellTimerOverlay>(); Registry.RegisterOverlay <LabelOverlay>(); var version = typeof(PluginMain).Assembly.GetName().Version; var Addons = new List <IOverlayAddonV2>(); foreach (var plugin in ActGlobals.oFormActMain.ActPlugins) { if (plugin.pluginObj == null) { continue; } try { if (plugin.pluginObj.GetType().GetInterface(typeof(IOverlayAddonV2).FullName) != null) { try { // プラグインのインスタンスを生成し、アドオンリストに追加する var addon = (IOverlayAddonV2)plugin.pluginObj; addon.Init(); Logger.Log(LogLevel.Info, "LoadAddons: {0}: Initialized", plugin.lblPluginTitle.Text); } catch (Exception e) { Logger.Log(LogLevel.Error, "LoadAddons: {0}: {1}", plugin.lblPluginTitle.Text, e); } } } catch (Exception e) { Logger.Log(LogLevel.Error, "LoadAddons: {0}: {1}", plugin.lblPluginTitle.Text, e); } } foreach (var pluginFile in Directory.GetFiles(directory, "*.dll")) { try { Logger.Log(LogLevel.Info, "LoadAddons: {0}", pluginFile); // アセンブリが見つかったら読み込む var asm = Assembly.LoadFrom(pluginFile); var incompatible = asm.GetReferencedAssemblies().Where(a => a.FullName != null && a.FullName.StartsWith("Xilium.CefGlue")).Count() > 0; if (incompatible) { Logger.Log(LogLevel.Error, "LoadAddons: Skipped {0} because it's incompatible with this version of OverlayPlugin.", asm.FullName); continue; } // アセンブリから IOverlayAddon を実装した public クラスを列挙し... var types = asm.GetExportedTypes().Where(t => t.GetInterface(typeof(IOverlayAddonV2).FullName) != null && t.IsClass); foreach (var type in types) { try { // プラグインのインスタンスを生成し、アドオンリストに追加する var addon = (IOverlayAddonV2)asm.CreateInstance(type.FullName); addon.Init(); Logger.Log(LogLevel.Info, "LoadAddons: {0}: Initialized", type.FullName); } catch (Exception e) { Logger.Log(LogLevel.Error, "LoadAddons: {0}: {1}", type.FullName, e); } } } catch (Exception e) { Logger.Log(LogLevel.Error, "LoadAddons: {0}: {1}", pluginFile, e); } } } catch (Exception e) { Logger.Log(LogLevel.Error, "LoadAddons: {0}", e); } }