Exemple #1
0
        public override Plugin Load(string directory, string name)
        {
            try
            {
                LogDebug($"Load({directory}, {name})");
                if (LoadingPlugins.Contains(name))
                {
                    LogDebug("Return null; (plugin already loading)");
                    return(null);
                }

                var plugin = GetPlugin(name);
                if (plugin == null)
                {
                    LogDebug("Return null; (plugin not found)");
                    return(null);
                }

                LoadingPlugins.Add(plugin.Name);
                Interface.Oxide.NextTick(() => LoadPlugin(plugin));
                LogDebug("Return null; (load on next tick)");
                return(null);
            }
            catch (Exception ex)
            {
                Interface.Oxide.LogException($"Fail to load plugin: {name}", ex);
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads a plugin given the specified name
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public virtual Plugin Load(string directory, string name)
        {
            if (LoadingPlugins.Contains(name))
            {
                Interface.Oxide.LogDebug("Load requested for plugin which is already loading: {0}", name);
                return(null);
            }

            string filename = Path.Combine(directory, name + FileExtension);
            Plugin plugin   = GetPlugin(filename);

            LoadingPlugins.Add(plugin.Name);
            Interface.Oxide.NextTick(() => LoadPlugin(plugin));

            return(null);
        }
Exemple #3
0
        public void Load(CompilablePlugin plugin)
        {
            plugin.Compile(compiled =>
            {
                if (!compiled)
                {
                    PluginLoadingCompleted(plugin);
                    return;
                }

                var loadedLoadingRequirements = plugin.Requires.Where(r => LoadedPlugins.ContainsKey(r) && LoadingPlugins.Contains(r));
                foreach (var loadedPlugin in loadedLoadingRequirements)
                {
                    Interface.Oxide.UnloadPlugin(loadedPlugin);
                }

                var missingRequirements = plugin.Requires.Where(r => !LoadedPlugins.ContainsKey(r));
                if (missingRequirements.Any())
                {
                    var loadingRequirements = plugin.Requires.Where(r => LoadingPlugins.Contains(r));
                    if (loadingRequirements.Any())
                    {
                        Interface.Oxide.LogDebug($"{plugin.Name} plugin is waiting for requirements to be loaded: {loadingRequirements.ToSentence()}");
                    }
                    else
                    {
                        Interface.Oxide.LogError($"{plugin.Name} plugin requires missing dependencies: {missingRequirements.ToSentence()}");
                        PluginErrors[plugin.Name] = $"Missing dependencies: {missingRequirements.ToSentence()}";
                        PluginLoadingCompleted(plugin);
                    }
                }
                else
                {
                    Interface.Oxide.UnloadPlugin(plugin.Name);
                    plugin.LoadPlugin(pl =>
                    {
                        if (pl != null)
                        {
                            LoadedPlugins[pl.Name] = pl;
                        }
                        PluginLoadingCompleted(plugin);
                    });
                }
            });
        }
Exemple #4
0
        /// <summary>
        /// Attempt to asynchronously compile and load plugin
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public override Plugin Load(string directory, string name)
        {
            //if (name == "CSharpCore") return new CSharpCore();

            if (LoadingPlugins.Contains(name))
            {
                Interface.GetMod().LogInfo("Plugin is already being loaded: {0}", name);
                return(null);
            }

            // Let the Oxide core know that this plugin will be loading asynchronously
            LoadingPlugins.Add(name);

            var compilable_plugin = GetCompilablePlugin(extension, directory, name);

            compilable_plugin.Compile(compiled =>
            {
                // Load the plugin assembly if it was successfully compiled
                if (compiled)
                {
                    compilable_plugin.LoadAssembly(plugin =>
                    {
                        LoadingPlugins.Remove(name);
                        if (plugin != null)
                        {
                            LoadedPlugins.Add(plugin);
                        }
                    });
                }
                else
                {
                    LoadingPlugins.Remove(name);
                }
            });

            return(null);
        }