Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add a plugin to the display list if it is active
 /// </summary>
 /// <param name="plugin"></param>
 private void addPluginToList(ItemTag plugin)
 {
     if (plugin.IsEnabled)
     {
         pluginsDataSource.Add(
             new WindowPlugin(plugin.SetupForm.PluginName(),
                              plugin.WindowId,
                              (plugin.ActiveImage != null) ? ImageHelper.imageToByteArray(plugin.ActiveImage, System.Drawing.Imaging.ImageFormat.Png)
                                                           : ImageHelper.imageToByteArray(Properties.Resources.NoPluginImage, System.Drawing.Imaging.ImageFormat.Png),
                              !ignoredPluginsList.Contains(plugin.WindowId)));
     }
 }
Exemplo n.º 3
0
    public static 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>();

            if (!exportedTypes.Any(t => t.IsClass && !t.IsAbstract &&
                (typeof(ISetupForm).IsAssignableFrom(t) || typeof(GUIWindow).IsAssignableFrom(t))))
            {
              continue; // there are no plugins in the assembly, skip it
            }

            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.expType = type;
                    tag.PluginName = pluginForm.PluginName();
                    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);
          }
        }
      }
    }
Exemplo n.º 4
0
 /// <summary>
 /// Checks whether the a plugin has a <see cref="PluginIconsAttribute"/> defined.  If it has, the images that are indicated
 /// in the attribute are loaded
 /// 
 /// Copied from MediaPortal setup, see PluginsNew.cs
 /// </summary>
 /// <param name="type">The <see cref="Type"/> to examine.</param>
 /// <param name="tag">The <see cref="ItemTag"/> to store the images in.</param>
 private static void LoadPluginImages(Type type, ItemTag tag)
 {
     PluginIconsAttribute[] icons =
       (PluginIconsAttribute[])type.GetCustomAttributes(typeof(PluginIconsAttribute), false);
     if (icons == null || icons.Length == 0)
     {
         return;
     }
     string resourceName = icons[0].ActivatedResourceName;
     if (!string.IsNullOrEmpty(resourceName))
     {
         tag.ActiveImage = LoadImageFromResource(type, resourceName);
     }
 }
Exemplo n.º 5
0
        public static 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>();

                        if (!exportedTypes.Any(t => t.IsClass && !t.IsAbstract &&
                                               (typeof(ISetupForm).IsAssignableFrom(t) || typeof(GUIWindow).IsAssignableFrom(t))))
                        {
                            continue; // there are no plugins in the assembly, skip it
                        }

                        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.expType    = type;
                                        tag.PluginName = pluginForm.PluginName();
                                        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);
                    }
                }
            }
        }