Esempio n. 1
0
        internal bool ScanVersionInfo(string asm)
        {
            Assembly plugin = null;

            try
            {
                plugin = Assembly.LoadFrom(asm);
            }
            catch {}

            if (plugin == null)
            {
                return(false);
            }

            CompatibleVersionAttribute[] versions = (CompatibleVersionAttribute[])CompatibilityManager.GetRequestedVersions(plugin);
            foreach (CompatibleVersionAttribute attr in versions)
            {
                CompatibleVersionItem compatibleVersionItem = new CompatibleVersionItem();
                compatibleVersionItem.MinRequiredVersion = attr.MinRequiredVersion.ToString();
                compatibleVersionItem.DesignedForVersion = attr.DesignedForVersion.ToString();
                CompatibleVersion.Add(compatibleVersionItem);
            }

            IEnumerable <UsesSubsystemAttribute> subSystems = (IEnumerable <UsesSubsystemAttribute>)CompatibilityManager.GetSubSystemsUsed(plugin);

            foreach (UsesSubsystemAttribute attr in subSystems)
            {
                SubSystemItem subsystemItem = new SubSystemItem();
                subsystemItem.Name = attr.Subsystem;
                //subsystemItem.Version = attr.Version.ToString();
                SubSystemsUsed.Add(subsystemItem);
            }
            return(true);
        }
        private void LoadExternalPlayers()
        {
            Log.Info("Loading external players plugins");
            string[] fileList = Util.Utils.GetFiles(Config.GetSubFolder(Config.Dir.Plugins, "ExternalPlayers"), "dll");
            foreach (string fileName in fileList)
            {
                try
                {
                    Assembly assem = Assembly.LoadFrom(fileName);
                    if (assem != null)
                    {
                        Type[] types = assem.GetExportedTypes();
                        foreach (Type t in types)
                        {
                            try
                            {
                                if (t.IsClass)
                                {
                                    if (t.IsSubclassOf(typeof(IExternalPlayer)))
                                    {
                                        if (!CompatibilityManager.IsPluginCompatible(t))
                                        {
                                            Log.Error(
                                                "  external player: {0} is tagged as incompatible with the current MediaPortal version and won't be loaded!",
                                                t.FullName);
                                            continue;
                                        }

                                        object newObj = (object)Activator.CreateInstance(t);
                                        Log.Info("  found plugin:{0} in {1}", t.ToString(), fileName);

                                        IExternalPlayer player = (IExternalPlayer)newObj;
                                        Log.Info("  player:{0}.  author: {1}", player.PlayerName, player.AuthorName);
                                        _externalPlayerList.Add(player);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Info("Error loading external player: {0}", t.ToString());
                                Log.Info("Error: {0}", e.StackTrace);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Info("Error loading external player: {0}", e);
                }
            }
            _externalPlayersLoaded = true;
        }
        private static void AppendActorCreationMessage(INetworkMessageOut message, INetworkedActor localActor)
        {
            var actorLocation = localActor.GetLocation();

            message.Write(localActor.Id);
            message.Write(actorLocation.X);
            message.Write(actorLocation.Y);
            message.Write(CompatibilityManager.GetHashCode(localActor.GetType().Name));

            if (localActor.ReplicateProperties)
            {
                localActor.Serialize(message);
            }
        }
Esempio n. 4
0
        public static void OnStartup()
        {
            try
            {
                Persistent.Load();
                Access.Initialize();
                Textures.Initialize();

                IntegrationManager.Initialize();
                CompatibilityManager.Initialize();
            }
            catch (System.Exception exception)
            {
                var info = new ExceptionInfo(exception);
                Error("RimHUD was unable to initialize properly due to the following exception:\n" + info.Text);
                State.Activated = false;
                Harmony.UnpatchAll();
            }
        }
Esempio n. 5
0
        private static void CheckPluginCompatibility(string strFile, Type pluginInterface)
        {
            try
            {
                Assembly assem = Assembly.LoadFrom(strFile);
                if (assem != null)
                {
                    Type[] types = assem.GetExportedTypes();

                    if (types.Any(t => t.IsClass && !t.IsAbstract && pluginInterface.IsAssignableFrom(t)) &&
                        !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
                    {
                        foreach (Type t in types)
                        {
                            try
                            {
                                if (t.IsClass && !t.IsAbstract && pluginInterface.IsAssignableFrom(t) && !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);
                                }
                            }
                            catch (NullReferenceException) {}
                        }
                    }
                }
            }
            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);
            }
        }
        private void LoadRemoteMethods(Assembly actorsAssembly)
        {
            var networkedActorType          = typeof(INetworkedActor);
            var clientCallableAttributeType = typeof(RemoteCallableAttribute);

            foreach (var actorType in actorsAssembly.GetTypes().Where(t => t.GetInterfaces().Contains(networkedActorType)))
            {
                foreach (var methodInfo in actorType.GetMethods().Where(m => m.GetCustomAttribute(clientCallableAttributeType) != null))
                {
                    var methodName = methodInfo.Name;
                    var methodKey  = CompatibilityManager.GetHashCode(methodName);

                    if (!_remoteMethods.ContainsKey(methodKey))
                    {
                        _remoteMethods.Add(methodKey, methodName);
                    }
                }
            }
        }
        public void AddActorRemoteMethodCall(int actorRemoteId, string methodName, bool reliable, object[] parameters)
        {
            var hashedMethodName = CompatibilityManager.GetHashCode(methodName);

            var methodCall = new CallMethod(actorRemoteId, hashedMethodName, reliable, parameters);

            if (!_methodCalls.ContainsKey(actorRemoteId))
            {
                _methodCalls.Add(actorRemoteId, new Dictionary <int, CallMethod>(1));
            }

            if (_methodCalls[actorRemoteId].ContainsKey(hashedMethodName))
            {
                _methodCalls[actorRemoteId][hashedMethodName] = methodCall;
            }
            else
            {
                _methodCalls[actorRemoteId].Add(hashedMethodName, methodCall);
            }
        }
Esempio n. 8
0
        public override void OnLoad(XmlElement xmlStorage)
        {
            base.OnLoad(xmlStorage);

            CompatibilityManager.FixProviderStorage(Storage);

            Manifest = Storage.DocumentElement.SelectSingleNode("manifest");

            if (Manifest == null)
            {
                XmlNode nodeDefinitionDefaultManifest = Definition.SelectSingleNode("manifest");
                if (nodeDefinitionDefaultManifest == null)
                {
                    throw new Exception(Messages.ProvidersInvalid);
                }

                Manifest = Storage.ImportNode(nodeDefinitionDefaultManifest, true);
                Storage.DocumentElement.AppendChild(Manifest);
            }

            User = Storage.DocumentElement.SelectSingleNode("user");
        }
Esempio n. 9
0
 public NetworkPeerGameClient() : base(1, typeof(NetworkPeerGameClient).Assembly)
 {
     _hashedNames.Add(CompatibilityManager.GetHashCode(nameof(Bar)), typeof(Bar));
     _hashedNames.Add(CompatibilityManager.GetHashCode(nameof(Ball)), typeof(Ball));
     _hashedNames.Add(CompatibilityManager.GetHashCode(nameof(GameState)), typeof(GameState));
 }
        /// <summary>
        /// Loads the plugin.
        /// </summary>
        /// <param name="strFile">The STR file.</param>
        private void LoadPlugin(string strFile)
        {
            Type[] foundInterfaces;

            try
            {
                Assembly assem = Assembly.LoadFrom(strFile);
                if (assem != null)
                {
                    Type[] types = assem.GetExportedTypes();

                    foreach (Type t in types)
                    {
                        try
                        {
                            if (t.IsClass)
                            {
                                if (t.IsAbstract)
                                {
                                    continue;
                                }

                                ITvServerPlugin plugin;
                                TypeFilter      myFilter2 = MyInterfaceFilter;
                                try
                                {
                                    foundInterfaces = t.FindInterfaces(myFilter2, "TvEngine.ITvServerPlugin");
                                    if (foundInterfaces.Length > 0)
                                    {
                                        if (!CompatibilityManager.IsPluginCompatible(t))
                                        {
                                            Log.WriteFile(
                                                "PluginManager: {0} is incompatible with the current tvserver version and won't be loaded!",
                                                t.FullName);
                                            continue;
                                        }
                                        Object newObj = Activator.CreateInstance(t);
                                        plugin = (ITvServerPlugin)newObj;
                                        _plugins.Add(plugin);
                                        Log.WriteFile("PluginManager: Loaded {0} version:{1} author:{2}", plugin.Name, plugin.Version,
                                                      plugin.Author);
                                    }
                                }
                                catch (TargetInvocationException)
                                {
                                    Log.WriteFile(
                                        "PluginManager: {0} is incompatible with the current tvserver version and won't be loaded!",
                                        t.FullName);
                                    continue;
                                }
                                catch (Exception ex)
                                {
                                    Log.WriteFile("Exception while loading ITvServerPlugin instances: {0}", t.FullName);
                                    Log.WriteFile(ex.ToString());
                                    Log.WriteFile(ex.Message);
                                    Log.WriteFile(ex.StackTrace);
                                }
                            }
                        }
                        catch (NullReferenceException) {}
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteFile(
                    "PluginManager: Plugin file {0} is broken or incompatible with the current tvserver version and won't be loaded!",
                    strFile.Substring(strFile.LastIndexOf(@"\") + 1));
                Log.WriteFile("PluginManager: Exception: {0}", ex);
            }
        }
Esempio n. 11
0
        public static void LoadWindowPlugin(string strFile)
        {
            if (!IsPlugInEnabled(strFile))
            {
                return;
            }

            try
            {
                Assembly assem = Assembly.LoadFrom(strFile);
                if (assem != null)
                {
                    Log.Info("PluginManager: '{0}' file version: {1}", strFile, 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);

                        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 = Activator.CreateInstance(t);
                                            var 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);
                                            }
                                        }
                                        catch (Exception guiWindowsException)
                                        {
                                            Log.Error("Exception while loading GUIWindows instances: {0}", t.FullName);
                                            Log.Error(guiWindowsException.Message);
                                            Log.Error(guiWindowsException.StackTrace);
                                        }
                                    }

                                    TypeFilter myFilter2 = MyInterfaceFilter;
                                    Type[]     foundInterfaces;
                                    try
                                    {
                                        foundInterfaces = t.FindInterfaces(myFilter2, "MediaPortal.GUI.Library.ISetupForm");
                                        if (foundInterfaces.Length > 0)
                                        {
                                            if (newObj == null)
                                            {
                                                newObj = Activator.CreateInstance(t);
                                            }
                                            var 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 = Activator.CreateInstance(t);
                                            }
                                            var 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(@"\", StringComparison.Ordinal) + 1));
                Log.Info("PluginManager: Exception: {0}", ex);
            }
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strFile"></param>
        private static void LoadPlugin(string strFile)
        {
            if (!IsPlugInEnabled(strFile))
            {
                return;
            }

            try
            {
                Assembly assem = Assembly.LoadFrom(strFile);
                if (assem != null)
                {
                    Log.Info("PluginManager: Plugin: '{0}' / Version: {1}", strFile, FileVersionInfo.GetVersionInfo(strFile).ProductVersion);

                    Type[]     types     = assem.GetExportedTypes();
                    TypeFilter myFilter2 = MyInterfaceFilter;

                    if (types.Any(t => t.IsClass && !t.IsAbstract && typeof(IPlugin).IsAssignableFrom(t)) && !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
                    {
                        foreach (Type t in types)
                        {
                            try
                            {
                                if (t.IsClass)
                                {
                                    if (t.IsAbstract)
                                    {
                                        continue;
                                    }

                                    Object  newObj = null;
                                    IPlugin plugin = null;
                                    Type[]  foundInterfaces;
                                    try
                                    {
                                        foundInterfaces = t.FindInterfaces(myFilter2, "MediaPortal.GUI.Library.IPlugin");
                                        if (foundInterfaces.Length > 0)
                                        {
                                            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 = Activator.CreateInstance(t);
                                            plugin = (IPlugin)newObj;
                                        }
                                    }
                                    catch (TargetInvocationException ex)
                                    {
                                        Log.Error(ex);
                                        Log.Error("PluginManager: {0} is incompatible with the current MediaPortal version and won't be loaded!", t.FullName);
                                        continue;
                                    }
                                    catch (Exception iPluginException)
                                    {
                                        Log.Error("Exception while loading IPlugin instances: {0}", t.FullName);
                                        Log.Error(iPluginException.ToString());
                                        Log.Error(iPluginException.Message);
                                        Log.Error(iPluginException.StackTrace);
                                    }
                                    if (plugin == null)
                                    {
                                        continue;
                                    }

                                    try
                                    {
                                        foundInterfaces = t.FindInterfaces(myFilter2, "MediaPortal.GUI.Library.ISetupForm");
                                        if (foundInterfaces.Length > 0)
                                        {
                                            if (newObj == null)
                                            {
                                                newObj = Activator.CreateInstance(t);
                                            }
                                            var setup = (ISetupForm)newObj;
                                            // don't activate plugins that have NO entry at all in MediaPortal.xml
                                            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);
                                                MPSettings.Instance.SetValueAsBool("home", setup.PluginName(), false);
                                                MPSettings.Instance.SetValueAsBool("myplugins", setup.PluginName(), true);
                                                MPSettings.Instance.SetValueAsBool("pluginswindows", t.ToString(), true);
                                            }

                                            // Load PowerScheduler if PS++ is enabled and remove PS++ entry
                                            if (setup.PluginName() == "PowerScheduler")
                                            {
                                                if (MPSettings.Instance.GetValueAsBool("plugins", "PowerScheduler++", false))
                                                {
                                                    MPSettings.Instance.SetValueAsBool("plugins", "PowerScheduler", true);
                                                }
                                                MPSettings.Instance.RemoveEntry("plugins", "PowerScheduler++");
                                            }

                                            if (IsPluginNameEnabled(setup.PluginName()))
                                            {
                                                _setupForms.Add(setup);
                                                _nonGuiPlugins.Add(plugin);
                                            }
                                        }
                                        else
                                        {
                                            //IPlugin without ISetupForm, adding anyway
                                            if (!PluginEntryExists(t.Name))
                                            {
                                                AddPluginEntry(t.Name, t.Assembly.ManifestModule.Name);
                                            }
                                            _nonGuiPlugins.Add(plugin);
                                        }
                                    }
                                    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 = Activator.CreateInstance(t);
                                            }
                                            var 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 (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(@"\", StringComparison.Ordinal) + 1));
                Log.Info("PluginManager: Exception: {0}", ex);
            }
        }
Esempio n. 13
0
        private static void LoadPlugin(string strFile)
        {
            if (!IsPlugInEnabled(strFile))
            {
                return;
            }

            Type[] foundInterfaces = null;

            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();
                    TypeFilter myFilter2 = new TypeFilter(MyInterfaceFilter);

                    if (types.Any(t => t.IsClass && !t.IsAbstract && typeof(IPlugin).IsAssignableFrom(t)) &&
                        !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
                    {
                        foreach (Type t in types)
                        {
                            try
                            {
                                if (t.IsClass)
                                {
                                    if (t.IsAbstract)
                                    {
                                        continue;
                                    }

                                    Object  newObj = null;
                                    IPlugin plugin = null;
                                    try
                                    {
                                        foundInterfaces = t.FindInterfaces(myFilter2, "MediaPortal.GUI.Library.IPlugin");
                                        if (foundInterfaces.Length > 0)
                                        {
                                            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);
                                            plugin = (IPlugin)newObj;
                                        }
                                    }
                                    catch (TargetInvocationException ex)
                                    {
                                        Log.Error(ex);
                                        Log.Error(
                                            "PluginManager: {0} is incompatible with the current MediaPortal version and won't be loaded!",
                                            t.FullName);
                                        continue;
                                    }
                                    catch (Exception iPluginException)
                                    {
                                        Log.Error("Exception while loading IPlugin instances: {0}", t.FullName);
                                        Log.Error(iPluginException.ToString());
                                        Log.Error(iPluginException.Message);
                                        Log.Error(iPluginException.StackTrace);
                                    }
                                    if (plugin == null)
                                    {
                                        continue;
                                    }

                                    // If we get to this point, the plugin has loaded successfully
                                    // Mark it as compatible.
                                    //MarkPluginAsCompatible(t);

                                    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;
                                            // don't activate plugins that have NO entry at all in
                                            // MediaPortal.xml
                                            if (PluginEntryExists(setup.PluginName()) && IsPluginNameEnabled(setup.PluginName()))
                                            {
                                                _setupForms.Add(setup);
                                                _nonGuiPlugins.Add(plugin);
                                            }
                                        }
                                    }
                                    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 (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);
            }
        }
Esempio n. 14
0
        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);
                    }
                }
            }
        }
Esempio n. 15
0
 public static void OnStartup() => CompatibilityManager.OnStartup();