Esempio n. 1
0
 public Plugin(IChainChompCorruptor newInstance)
 {
     corruptor              = newInstance;
     settings.pluginName    = newInstance.Name;
     settings.pluginAuthor  = newInstance.Author;
     settings.pluginVersion = newInstance.Version;
 }
Esempio n. 2
0
 public Plugin(string path)
 {
     LoadSettings(path);
     corruptor = PluginManager.Current.CreateMatchingCorruptor(settings);
     if (settings != null)
     {
         settings.Restore(corruptor);
     }
     else
     {
         MessageBox.Show("Attempted to load a Corruptor that is not installed.", "Error", MessageBoxButtons.OK);
     }
 }
Esempio n. 3
0
        public void Restore(IChainChompCorruptor corruptor)
        {
            Type t = corruptor.GetType();

            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (Attribute.IsDefined(prop, typeof(SaveableSetting)))
                {
                    object value = data[prop.Name];

                    prop.SetValue(corruptor, Convert.ChangeType(value, prop.PropertyType));
                }
            }
        }
Esempio n. 4
0
        public void Store(IChainChompCorruptor corruptor)
        {
            Type t = corruptor.GetType();

            data = new Dictionary <string, dynamic>();

            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (Attribute.IsDefined(prop, typeof(SaveableSetting)))
                {
                    dynamic value = prop.GetValue(corruptor);
                    string  name  = prop.Name;

                    data.Add(name, value);
                }
            }
        }
Esempio n. 5
0
        //plugin loader
        private ICollection <IChainChompCorruptor> LoadPlugins(string path)
        {
            //aggregate files
            string[] dllFileNames = new string[0];
            if (Directory.Exists(path))
            {
                dllFileNames = Directory.GetFiles(path, "*.dll");
            }

            //load assemblies
            ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length);

            foreach (string dll in dllFileNames)
            {
                AssemblyName assN;
                try
                {
                    assN = AssemblyName.GetAssemblyName(dll);
                }
                catch (FileLoadException e)
                {
                    MessageBox.Show(e.Message);
                    continue;
                }

                Console.WriteLine(assN.FullName);
                Assembly ass;
                try
                {
                    ass = Assembly.Load(assN);
                }
                catch (FileLoadException e)
                {
                    MessageBox.Show(e.Message);
                    continue;
                }
                assemblies.Add(ass);
            }

            //search assemblies for corruptors
            Type corruptorType             = typeof(IChainChompCorruptor);
            ICollection <Type> pluginTypes = new List <Type>();

            foreach (Assembly assembly in assemblies)
            {
                if (assembly != null)
                {
                    Type[] types = assembly.GetTypes();
                    foreach (Type type in types)
                    {
                        if (type.IsInterface || type.IsAbstract)
                        {
                            continue;
                        }
                        else
                        {
                            if (type.GetInterface(corruptorType.FullName) != null)
                            {
                                pluginTypes.Add(type);
                            }
                        }
                    }
                }
            }

            //create instances
            ICollection <IChainChompCorruptor> plugins = new List <IChainChompCorruptor>(pluginTypes.Count);

            foreach (Type type in pluginTypes)
            {
                IChainChompCorruptor corruptor = (IChainChompCorruptor)Activator.CreateInstance(type);
                plugins.Add(corruptor);
            }

            return(plugins);
        }
Esempio n. 6
0
        public IChainChompCorruptor CreateMatchingCorruptor(PluginSettings settings)
        {
            IChainChompCorruptor x = FindMatchingPlugin(settings);

            return(x != null?CreateCorruptor(_plugins.IndexOf(x)) : null);
        }
Esempio n. 7
0
        // Chain Expansion
        private void pluginDropDown_SelectedIndexChanged(object sender, EventArgs e)
        {
            IChainChompCorruptor c = PluginManager.Current.GetCorruptor((ComboBoxItem)pluginDropDown.SelectedItem);

            editorToolTip.SetToolTip(pluginDropDown, string.Format("{0} (Version {1} by {2})", c.Name, c.Version, c.Author));
        }
Esempio n. 8
0
 public Plugin(IChainChompCorruptor newInstance, string path) : this(newInstance)
 {
     LoadSettings(path, true);
 }