コード例 #1
0
ファイル: CommandManager.cs プロジェクト: YandalfFX/Redox
 public static CommandManager GetInstance(RedoxPlugin plugin)
 {
     if (instance == null)
     {
         instance = new CommandManager(plugin);
     }
     Commands.Add(instance);
     return(instance);
 }
コード例 #2
0
ファイル: PluginLoader.cs プロジェクト: YandalfFX/Redox
        public static void LoadPlugin(string dir)
        {
            FileInfo info = null;

            try
            {
                foreach (var file in Directory.GetFiles(dir, Expression))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    info = new FileInfo(file);
                    string   name = info.Name.Replace(".dll", string.Empty);
                    Assembly assembly;

                    if (!Plugins.TryGetValue(name, out assembly))
                    {
                        assembly = Assembly.Load(File.ReadAllBytes(file));
                        Plugins.Add(name, assembly);
                    }
                    foreach (Type type in assembly.GetExportedTypes())
                    {
                        if (type.IsSubclassOf(typeof(RedoxPlugin)) && type.IsPublic && !type.IsAbstract)
                        {
                            object          instance  = Activator.CreateInstance(type);
                            RedoxPlugin     plugin    = (RedoxPlugin)instance;
                            PluginContainer container = new PluginContainer(plugin, instance);
                            PluginCollector.GetCollector().AddPlugin(container);

                            container.Plugin.Path = Path.GetDirectoryName(info.Directory.FullName);

                            logger.LogInfo(string.Format("[Redox] Succesfully loaded plugin {0}, {1}, Author {2} ({3}", plugin.Title, plugin.Version, plugin.Author, plugin.Description));
                        }
                    }
                    sw.Stop();
                    int time = sw.Elapsed.Milliseconds;

                    if (time > 500)
                    {
                        logger.LogSpeed(string.Format("[Redox] Plugin {0} took {1} milliseconds to load", name, time));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(string.Format("An exception has thrown while trying to load plugin {0}, Error: {1}", info.FullName, ex));
            }
        }
コード例 #3
0
        public static void LoadPlugin(string dir)
        {
            foreach (var file in Directory.GetFiles(dir, Expression))
            {
                FileInfo info = new FileInfo(file);
                string   name = info.Name.Replace(".dll", string.Empty);
                Assembly assembly;

                if (!Plugins.TryGetValue(name, out assembly))
                {
                    assembly = Assembly.Load(File.ReadAllBytes(file));
                    Plugins.Add(name, assembly);
                }

                if (ValidPlugin(assembly))
                {
                    foreach (Type type in assembly.GetExportedTypes())
                    {
                        if (type.IsSubclassOf(typeof(RedoxPlugin)) && type.IsPublic && !type.IsAbstract)
                        {
                            RedoxPlugin     plugin    = (RedoxPlugin)Activator.CreateInstance(type);
                            PluginContainer container = new PluginContainer(plugin);

                            PluginCollector.GetCollector().AddPlugin(container);

                            foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                            {
                                container.Methods.Add(method.Name, method);
                            }

                            Debug.Log(string.Format("[Redox] Succesfully loaded plugin {0}, {1}, {2} ({3})", plugin.Title, plugin.Author, plugin.Version, plugin.Description));
                        }
                    }
                }
                else
                {
                    Debug.LogWarning(string.Format("[Redox] Denied plugin {0} because of forbidden references", assembly.FullName));
                }
            }
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: YandalfFX/Redox
 public Config(string name, RedoxPlugin plugin)
 {
     this.name   = name + ".json";
     Settings    = new Dictionary <string, object>();
     this.plugin = plugin;
 }
コード例 #5
0
 public PluginContainer(RedoxPlugin plugin, object instance)
 {
     this.Running  = true;
     this.Plugin   = plugin;
     this.instance = instance;
 }
コード例 #6
0
 public Datafile(string name, RedoxPlugin plugin)
 {
     this.name   = name + ".data";
     Settings    = new Dictionary <string, object>();
     this.plugin = plugin;
 }
コード例 #7
0
ファイル: CommandManager.cs プロジェクト: YandalfFX/Redox
 public CommandManager(RedoxPlugin plugin)
 {
     _commands   = new List <Command>();
     this.plugin = plugin;
 }