예제 #1
0
        /// <summary>
        /// Unloads the plugin by the given name
        /// </summary>
        /// <param name="name"></param>
        public bool UnloadPlugin(string name)
        {
            // Get the plugin
            var plugin = RootPluginManager.GetPlugin(name);

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

            // Let the plugin loader know that this plugin is being unloaded
            var loader = extensionManager.GetPluginLoaders().SingleOrDefault(l => l.LoadedPlugins.ContainsKey(name));

            loader?.Unloading(plugin);

            // Unload it
            RootPluginManager.RemovePlugin(plugin);

            // Let other plugins know that this plugin has been unloaded
            if (plugin.IsLoaded)
            {
                CallHook("OnPluginUnloaded", plugin);
            }
            plugin.IsLoaded = false;

            LogInfo("Unloaded plugin {0} v{1} by {2}", plugin.Title, plugin.Version, plugin.Author);
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Loads a plugin by the given name
        /// </summary>
        /// <param name="name"></param>
        public bool LoadPlugin(string name)
        {
            // Check if the plugin is already loaded
            if (RootPluginManager.GetPlugin(name) != null)
            {
                return(false);
            }

            // Find all plugin loaders that lay claim to the name
            HashSet <PluginLoader> loaders = new HashSet <PluginLoader>(extensionManager.GetPluginLoaders().Where(l => l.ScanDirectory(PluginDirectory).Contains(name)));

            if (loaders.Count == 0)
            {
                // TODO: Fix symlinked plugins unloaded still triggering this
                LogError("Could not load plugin '{0}' (no plugin found with that file name)", name);
                return(false);
            }

            if (loaders.Count > 1)
            {
                LogError("Could not load plugin '{0}' (multiple plugin with that name)", name);
                return(false);
            }

            // Load it and watch for errors
            PluginLoader loader = loaders.First();

            try
            {
                Plugin plugin = loader.Load(PluginDirectory, name);
                if (plugin == null)
                {
                    return(true); // Async load
                }

                plugin.Loader = loader;
                PluginLoaded(plugin);
                return(true);
            }
            catch (Exception ex)
            {
                LogException($"Could not load plugin {name}", ex);
                return(false);
            }
        }
예제 #3
0
파일: OxideMod.cs 프로젝트: VoxR4710/Oxide
        /// <summary>
        /// Loads a plugin by the given name
        /// </summary>
        /// <param name="name"></param>
        public bool LoadPlugin(string name)
        {
            // Check if the plugin is already loaded
            if (RootPluginManager.GetPlugin(name) != null)
            {
                return(false);
            }

            // Find all plugin loaders that lay claim to the name
            var loaders = new HashSet <PluginLoader>(extensionManager.GetPluginLoaders().Where(l => l.ScanDirectory(PluginDirectory).Contains(name)));

            if (loaders.Count == 0)
            {
                LogError("Failed to load plugin '{0}' (no source found)", name);
                return(false);
            }

            if (loaders.Count > 1)
            {
                LogError("Failed to load plugin '{0}' (multiple sources found)", name);
                return(false);
            }

            // Load it and watch for errors
            var loader = loaders.First();

            try
            {
                var plugin = loader.Load(PluginDirectory, name);
                if (plugin == null)
                {
                    return(true);                // Async load
                }
                plugin.Loader = loader;
                PluginLoaded(plugin);
                return(true);
            }
            catch (Exception ex)
            {
                LogException($"Failed to load plugin {name}", ex);
                return(false);
            }
        }