public static void LoadWindowPlugin(string strFile) { if (!IsPlugInEnabled(strFile)) { return; } Log.Info(" Load plugins from : {0}", strFile); try { Assembly assem = Assembly.LoadFrom(strFile); if (assem != null) { Log.Info(" File Version : {0}", FileVersionInfo.GetVersionInfo(strFile).ProductVersion); Type[] types = assem.GetExportedTypes(); if (types.Any(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(GUIWindow))) && !CompatibilityManager.IsPluginCompatible(assem)) { Log.Error( "PluginManager: {0} is tagged as incompatible with the current MediaPortal version and won't be loaded!", assem.FullName); _incompatibilities.Add(assem); } else { //MarkPluginAsCompatible(assem); Type[] foundInterfaces = null; foreach (Type t in types) { try { if (t.IsClass) { if (t.IsAbstract) { continue; } Object newObj = null; if (t.IsSubclassOf(typeof(GUIWindow))) { try { if (!CompatibilityManager.IsPluginCompatible(t)) { Log.Error( "PluginManager: {0} is tagged as incompatible with the current MediaPortal version and won't be loaded!", t.FullName); _incompatibilities.Add(t); continue; } newObj = (object)Activator.CreateInstance(t); GUIWindow win = (GUIWindow)newObj; if (win.GetID >= 0 && IsWindowPlugInEnabled(win.GetType().ToString())) { try { win.Init(); _guiPlugins.Add(win); } catch (Exception ex) { Log.Error("Error initializing window:{0} {1} {2} {3}", win.ToString(), ex.Message, ex.Source, ex.StackTrace); } GUIWindowManager.Add(ref win); } //else Log.Info(" plugin:{0} not enabled",win.GetType().ToString()); } catch (Exception guiWindowsException) { Log.Error("Exception while loading GUIWindows instances: {0}", t.FullName); Log.Error(guiWindowsException.Message); Log.Error(guiWindowsException.StackTrace); } } // If we get to this point, the plugin has loaded successfully // Mark it as compatible. //MarkPluginAsCompatible(t); TypeFilter myFilter2 = new TypeFilter(MyInterfaceFilter); try { foundInterfaces = t.FindInterfaces(myFilter2, "MediaPortal.GUI.Library.ISetupForm"); if (foundInterfaces.Length > 0) { if (newObj == null) { newObj = (object)Activator.CreateInstance(t); } ISetupForm setup = (ISetupForm)newObj; if (!PluginEntryExists(setup.PluginName())) { Log.Info("PluginManager: {0} {1} not found in Mediaportal.xml so adding it now", setup.PluginName(), t.Assembly.ManifestModule.Name); AddPluginEntry(setup.PluginName(), t.Assembly.ManifestModule.Name); } if (IsPluginNameEnabled(setup.PluginName())) { _setupForms.Add(setup); } } } catch (Exception iSetupFormException) { Log.Error("Exception while loading ISetupForm instances: {0}", t.FullName); Log.Error(iSetupFormException.Message); Log.Error(iSetupFormException.StackTrace); } try { foundInterfaces = t.FindInterfaces(myFilter2, "MediaPortal.GUI.Library.IWakeable"); if (foundInterfaces.Length > 0) { if (newObj == null) { newObj = (object)Activator.CreateInstance(t); } IWakeable setup = (IWakeable)newObj; if (PluginEntryExists(setup.PluginName()) && IsPluginNameEnabled(setup.PluginName())) { _wakeables.Add(setup); } } } catch (Exception iWakeableException) { Log.Error("Exception while loading IWakeable instances: {0}", t.FullName); Log.Error(iWakeableException.Message); Log.Error(iWakeableException.StackTrace); } } } catch (NullReferenceException) {} } } } } catch (BadImageFormatException) { } catch (Exception ex) { Log.Info( "PluginManager: Plugin file {0} is broken or incompatible with the current MediaPortal version and won't be loaded!", strFile.Substring(strFile.LastIndexOf(@"\") + 1)); Log.Info("PluginManager: Exception: {0}", ex); } }
/// <summary> /// Load available window plugins in a list /// /// Copied and modified from MediaPortal config: PluginsNew.cs /// </summary> private void LoadPlugins() { try { foreach (string pluginFile in availablePlugins) { Assembly pluginAssembly = null; try { pluginAssembly = Assembly.LoadFrom(pluginFile); } catch (BadImageFormatException) { Log.Warn("[WifiRemote Setup] {0} has a bad image format", pluginFile); } if (pluginAssembly != null) { try { Type[] exportedTypes = pluginAssembly.GetExportedTypes(); 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; } // 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) { // Plugin is incompatible with current MediaPortal Log.Error("[WifiRemote Setup] Plugin " + pluginFile + " incompatible"); continue; } if (isPlugin) { ISetupForm pluginForm = pluginObject as ISetupForm; 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(); } } LoadPluginImages(type, tag); plugins.Add(tag); } } } } } catch (Exception ex) { // plugin broken or incompatible Log.Error("[WifiRemote Setup] Exception: {0}", ex); } } } } catch (Exception excep) { Log.Error("[WifiRemote Setup] Error loading plugins: " + excep.Message); } }
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); } } } }
/// <summary> /// Handle the facade message /// </summary> /// <param name="message">Message sent from client</param> /// <param name="server">Instance of the socket server</param> /// <param name="client">Socket that sent the message (for return messages)</param> internal static void HandleFacadeMessage(Newtonsoft.Json.Linq.JObject message, SocketServer server, AsyncSocket client) { String action = (string)message["FacadeAction"]; GUIWindow currentPlugin = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow); if (action.Equals("get")) { MessageFacade returnMessage = new MessageFacade(); if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome)) { GUIMenuControl menu = (GUIMenuControl)currentPlugin.GetControl(50); List <FacadeItem> items = MpFacadeHelper.GetHomeItems(menu); returnMessage.FacadeItems = items; returnMessage.ViewType = "Home"; } else { GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50); if (facade != null) { List <FacadeItem> items = MpFacadeHelper.GetFacadeItems(currentPlugin.GetID, 50); returnMessage.ViewType = facade.CurrentLayout.ToString(); returnMessage.FacadeItems = items; } } returnMessage.WindowId = currentPlugin.GetID; server.SendMessageToClient(returnMessage, client); } else if (action.Equals("setselected")) { if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome)) { } else { GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50); int selected = (int)message["SelectedIndex"]; facade.SelectedListItemIndex = selected; } } else if (action.Equals("getselected")) { if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome)) { //TODO: find a way to retrieve the currently selected home button } else { GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50); int selected = facade.SelectedListItemIndex; } } else if (action.Equals("getcount")) { if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome)) { GUIMenuControl menu = (GUIMenuControl)currentPlugin.GetControl(50); int count = menu.ButtonInfos.Count; } else { GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50); int count = facade.Count; } } else if (action.Equals("select")) { int selected = (int)message["SelectedIndex"]; if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome)) { GUIMenuControl menu = (GUIMenuControl)currentPlugin.GetControl(50); MenuButtonInfo info = menu.ButtonInfos[selected]; GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, info.PluginID, 0, null); GUIWindowManager.SendThreadMessage(msg); } else { GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50); //TODO: is there a better way to select a list item facade.SelectedListItemIndex = selected; new Communication().SendCommand("ok"); } } else if (action.Equals("context")) { int selected = (int)message["SelectedIndex"]; if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome)) { GUIMenuControl menu = (GUIMenuControl)currentPlugin.GetControl(50); MenuButtonInfo info = menu.ButtonInfos[selected]; GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, info.PluginID, 0, null); GUIWindowManager.SendThreadMessage(msg); } else { GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50); //TODO: is there a better way to select a list item facade.SelectedListItemIndex = selected; new Communication().SendCommand("info"); } } }