예제 #1
0
        /// <summary>
        /// Loads a given plugin
        /// </summary>
        /// <param name="plugin"></param>
        /// <param name="waitingForAccess"></param>
        protected void LoadPlugin(Plugin plugin, bool waitingForAccess = false)
        {
            if (!File.Exists(plugin.Filename))
            {
                LoadingPlugins.Remove(plugin.Name);
                Interface.Oxide.LogWarning("Script no longer exists: {0}", plugin.Name);
                return;
            }

            try
            {
                plugin.Load();
                Interface.Oxide.UnloadPlugin(plugin.Name);
                LoadingPlugins.Remove(plugin.Name);
                Interface.Oxide.PluginLoaded(plugin);
            }
            catch (IOException)
            {
                if (!waitingForAccess)
                {
                    Interface.Oxide.LogWarning("Waiting for another application to stop using script: {0}", plugin.Name);
                }

                Interface.Oxide.GetLibrary <Timer>().Once(.5f, () => LoadPlugin(plugin, true));
            }
            catch (Exception ex)
            {
                LoadingPlugins.Remove(plugin.Name);
                Interface.Oxide.LogException($"Failed to load plugin {plugin.Name}", ex);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
 private void PluginLoadingCompleted(CompilablePlugin plugin)
 {
     LoadingPlugins.Remove(plugin.Name);
     plugin.IsLoading = false;
     foreach (var loadingName in LoadingPlugins.ToArray())
     {
         var loadingPlugin = GetCompilablePlugin(plugin.Directory, loadingName);
         if (loadingPlugin.IsLoading && loadingPlugin.Requires.Contains(plugin.Name))
         {
             Load(loadingPlugin);
         }
     }
 }
예제 #4
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);
        }
예제 #5
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);
                    });
                }
            });
        }
예제 #6
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);
        }
예제 #7
0
 public void PluginLoadingStarted(CompilablePlugin plugin)
 {
     // Let the Oxide core know that this plugin will be loading asynchronously
     LoadingPlugins.Add(plugin.Name);
     plugin.IsLoading = true;
 }