Exemple #1
0
        public static Plugins.PluginContext LoadPluginLibrary(string path)
        {
            Plugins.PluginContext plugin = null;

            try
            {
                var ldll  = Assembly.LoadFile(path);
                var types = ldll.GetExportedTypes();
                if (types.Any())
                {
                    foreach (var type in types)
                    {
                        if (typeof(Plugins.PluginContext) != type)
                        {
                            if (typeof(Plugins.PluginContext).IsAssignableFrom(type))
                            {
                                plugin = Activator.CreateInstance(type) as Plugins.PluginContext;
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(plugin);
        }
Exemple #2
0
 private void PluginUnloadButton_Click(object sender, EventArgs e)
 {
     if (LoadedPlugin != null)
     {
         LoadedPlugin               = null;
         PluginLabel.Text           = "There is no entry creator plugin selected.";
         PluginUnloadButton.Enabled = false;
     }
 }
Exemple #3
0
        private void PluginButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Title       = "Load uViewer entry creator plugin",
                Filter      = "Dynamic library (*.dll)|*.dll",
                Multiselect = false
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var plugin = PluginHandler.LoadPluginLibrary(ofd.FileName);
                LoadedPlugin = plugin;
                if (LoadedPlugin != null)
                {
                    PluginLabel.Text           = "Selected plugin: " + LoadedPlugin.GetPluginName();
                    PluginUnloadButton.Enabled = true;
                }
                else
                {
                    PluginLabel.Text = "There is no entry creator plugin selected.";
                }
            }
        }
Exemple #4
0
        public EntryForm(Plugins.PluginContext plugin)
        {
            InitializeComponent();
            Plugin = plugin;

            if (Plugin != null)
            {
                Text += " (" + Plugin.GetPluginName() + ")";

                void SetField(string value, Control control)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        control.Text = value;
                    }
                }

                void SetControl(Control custom, string parent_control, string actual_name)
                {
                    if (custom != null)
                    {
                        Control control;
                        if (!string.IsNullOrEmpty(parent_control))
                        {
                            var parent = Controls.Find(parent_control, false).First();
                            control = parent.Controls.Find(actual_name, false).First();
                        }
                        else
                        {
                            control = Controls.Find(actual_name, false).First();
                        }

                        custom.Margin   = control.Margin;
                        custom.Location = control.Location;
                        custom.Name     = actual_name;

                        if (!string.IsNullOrEmpty(parent_control))
                        {
                            var parent = Controls.Find(parent_control, true).First();
                            parent.Controls.RemoveByKey(actual_name);
                            parent.Controls.Add(custom);
                        }

                        else
                        {
                            Controls.RemoveByKey(actual_name);
                            Controls.Add(custom);
                        }
                    }
                }

                SetField(Plugin.GetEntryMenuInformationLabel(), InformationLabel);
                SetField(Plugin.GetEntryMenuNameFieldLabel(), NameLabel);
                SetControl(Plugin.GetEntryMenuNameControl(), "MainGroup", "NameText");
                SetField(Plugin.GetEntryMenuAuthorFieldLabel(), AuthorLabel);
                SetControl(Plugin.GetEntryMenuAuthorControl(), "MainGroup", "AuthorText");
                SetField(Plugin.GetEntryMenuVersionFieldLabel(), VersionLabel);
                SetControl(Plugin.GetEntryMenuVersionControl(), "MainGroup", "VersionText");
                SetField(Plugin.GetEntryMenuNroFieldLabel(), NroLabel);
                SetControl(Plugin.GetEntryMenuNroControl(), "MainGroup", "NroText");
                SetField(Plugin.GetEntryMenuArgvFieldLabel(), ArgvLabel);
                SetControl(Plugin.GetEntryMenuArgvControl(), "MainGroup", "ArgvText");
            }
        }