private void LoadPlugins() { foreach (string pluginFile in availablePlugins) { Assembly pluginAssembly = null; try { Log.Debug("PluginsNew: loadPlugins {0}", pluginFile); pluginAssembly = Assembly.LoadFrom(pluginFile); } catch (BadImageFormatException) { Log.Warn("PluginsNew: {0} has a bad image format", pluginFile); } if (pluginAssembly != null) { try { Type[] exportedTypes = pluginAssembly.GetExportedTypes(); List <object> NonSetupWindows = new List <object>(); foreach (Type type in exportedTypes) { bool isPlugin = (type.GetInterface("MediaPortal.GUI.Library.ISetupForm") != null); bool isGuiWindow = ((type.IsClass) && (type.IsSubclassOf(typeof(GUIWindow)))); // an abstract class cannot be instanciated if (type.IsAbstract) { continue; } bool isIncompatible = !CompatibilityManager.IsPluginCompatible(type); if (isIncompatible) { Log.Warn( "Plugin Manager: Plugin {0} is incompatible with the current MediaPortal version! (File: {1})", type.FullName, pluginFile.Substring(pluginFile.LastIndexOf(@"\") + 1)); } // Try to locate the interface we're interested in if (isPlugin || isGuiWindow) { // Create instance of the current type object pluginObject; try { pluginObject = Activator.CreateInstance(type); } catch (TargetInvocationException) { MessageBox.Show( string.Format( "An error occured while loading the plugin {0}.\n\nIt's incompatible with the current MediaPortal version and won't be loaded.", type.FullName ), "Plugin Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.Warn( "Plugin Manager: Plugin {0} is incompatible with the current MediaPortal version! (File: {1})", type.FullName, pluginFile.Substring(pluginFile.LastIndexOf(@"\") + 1)); continue; } if (isPlugin) { ISetupForm pluginForm = pluginObject as ISetupForm; IExternalPlayer extPlayer = pluginObject as IExternalPlayer; IShowPlugin showPlugin = pluginObject as IShowPlugin; if (pluginForm != null) { ItemTag tag = new ItemTag(); tag.SetupForm = pluginForm; tag.DllName = pluginFile.Substring(pluginFile.LastIndexOf(@"\") + 1); tag.WindowId = pluginForm.GetWindowId(); if (isGuiWindow) { GUIWindow win = (GUIWindow)pluginObject; if (tag.WindowId == win.GetID) { tag.Type = win.GetType().ToString(); tag.IsProcess = false; tag.IsWindow = true; } } else if (extPlayer != null) { tag.IsExternalPlayer = true; } else { tag.IsProcess = true; } if (showPlugin != null) { tag.ShowDefaultHome = showPlugin.ShowDefaultHome(); } tag.IsIncompatible = isIncompatible; LoadPluginImages(type, tag); loadedPlugins.Add(tag); } } else { NonSetupWindows.Add(pluginObject); } } } // Filter plugins from e.g. dialogs or other windows. foreach (GUIWindow win in NonSetupWindows) { foreach (ItemTag tag in loadedPlugins) { if (tag.WindowId == win.GetID) { tag.Type = win.GetType().ToString(); tag.IsProcess = false; tag.IsWindow = true; Log.Debug( "PluginsNew: {0}, window plugin, does not implement \"ISetupForm\" and \"GUIWindow\" in the same class", tag.Type); break; } } } } catch (Exception ex) { MessageBox.Show( string.Format( "An error occured while loading the plugin file {0}.\n\nIt's broken or incompatible with the current MediaPortal version and won't be loaded.", pluginFile.Substring(pluginFile.LastIndexOf(@"\") + 1)), "Plugin Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.Warn( "PluginManager: Plugin file {0} is broken or incompatible with the current MediaPortal version and won't be loaded!", pluginFile.Substring(pluginFile.LastIndexOf(@"\") + 1)); Log.Error("PluginManager: Exception: {0}", ex); } } } }
protected override void LoadButtonNames() { if (menuMain == null) { return; } menuMain.ButtonInfos.Clear(); ArrayList plugins = PluginManager.SetupForms; int myPluginsCount = 0; using (Profile.Settings xmlreader = new Profile.MPSettings()) { foreach (ISetupForm setup in plugins) { string plugInText; string focusTexture; string nonFocusTexture; string hover; string nonFocusHover; if (setup.GetHome(out plugInText, out focusTexture, out nonFocusTexture, out hover)) { if (setup.PluginName().Equals("Home")) { continue; } IShowPlugin showPlugin = setup as IShowPlugin; if (_useMyPlugins) { string showInHome = xmlreader.GetValue("home", setup.PluginName()); if ((showInHome == null) || (showInHome.Length < 1)) { if (showPlugin == null) { continue; } if (showPlugin.ShowDefaultHome() == false) { myPluginsCount++; continue; } } else { if (showInHome.ToLowerInvariant().Equals("no")) { myPluginsCount++; continue; } } } int index = xmlreader.GetValueAsInt("pluginSorting", setup.PluginName(), Int32.MaxValue); if ((focusTexture == null) || (focusTexture.Length < 1)) { focusTexture = setup.PluginName(); } if ((nonFocusTexture == null) || (nonFocusTexture.Length < 1)) { nonFocusTexture = setup.PluginName(); } if ((hover == null) || (hover.Length < 1)) { hover = setup.PluginName(); } focusTexture = GetFocusTextureFileName(focusTexture); nonFocusTexture = GetNonFocusTextureFileName(nonFocusTexture); nonFocusHover = GetNonFocusHoverFileName(hover); hover = GetHoverFileName(hover); menuMain.ButtonInfos.Add(new MenuButtonInfo(plugInText, setup.GetWindowId(), focusTexture, nonFocusTexture, hover, nonFocusHover, index)); } } if ((_useMyPlugins) && (myPluginsCount > 0)) { string focusTexture = GetFocusTextureFileName("my plugins"); string nonFocusTexture = GetNonFocusTextureFileName("my plugins"); string hover = GetHoverFileName("my plugins"); string nonFocusHover = GetNonFocusHoverFileName("my plugins"); int index = xmlreader.GetValueAsInt("pluginSorting", "my Plugins", Int32.MaxValue); menuMain.ButtonInfos.Add(new MenuButtonInfo(GUILocalizeStrings.Get(913), (int)Window.WINDOW_MYPLUGINS, focusTexture, nonFocusTexture, hover, nonFocusHover, index)); } } }
protected override void LoadButtonNames() { if (menuMain == null) { return; } menuMain.ButtonInfos.Clear(); ArrayList plugins = PluginManager.SetupForms; using (Profile.Settings xmlreader = new Profile.MPSettings()) { foreach (ISetupForm setup in plugins) { string plugInText; string focusTexture; string nonFocusTexture; string hover; string nonFocusHover; if (setup.GetHome(out plugInText, out focusTexture, out nonFocusTexture, out hover)) { if (setup.PluginName().Equals("Home")) { continue; } IShowPlugin showPlugin = setup as IShowPlugin; string showInPlugIns = xmlreader.GetValue("myplugins", setup.PluginName()); if ((showInPlugIns == null) || (showInPlugIns.Length < 1)) { if ((showPlugin != null) && (showPlugin.ShowDefaultHome() == true)) { continue; } } else { if (showInPlugIns.ToLower().Equals("no")) { continue; } } if ((focusTexture == null) || (focusTexture.Length < 1)) { focusTexture = setup.PluginName(); } if ((nonFocusTexture == null) || (nonFocusTexture.Length < 1)) { nonFocusTexture = setup.PluginName(); } if ((hover == null) || (hover.Length < 1)) { hover = setup.PluginName(); } focusTexture = GetFocusTextureFileName(focusTexture); nonFocusTexture = GetNonFocusTextureFileName(nonFocusTexture); nonFocusHover = GetNonFocusHoverFileName(hover); hover = GetHoverFileName(hover); int index = xmlreader.GetValueAsInt("pluginSorting", "my Plugins", Int32.MaxValue); menuMain.ButtonInfos.Add(new MenuButtonInfo(plugInText, setup.GetWindowId(), focusTexture, nonFocusTexture, hover, nonFocusHover, index)); } } } }