Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<IEffectPlugin> plugs;
- private void LoadPlugins(string from)
- {
- if (!Directory.Exists(from))
- {
- AddEmptyItem(effectToolStripMenuItem);
- return;
- }
- var dlls = Directory.GetFiles(from, "*.dll").ToList().Where(s => Path.GetFileNameWithoutExtension(s) != "PlugAPI");
- plugs = new List<IEffectPlugin>();
- foreach (var s in dlls) LoadDll(s);
- if (effectToolStripMenuItem.DropDownItems.Count == 0) AddEmptyItem(effectToolStripMenuItem);
- }
- private void LoadDll(string dll)
- {
- Assembly a = Assembly.LoadFrom(dll);
- foreach (var t in a.GetTypes())
- if (t.IsClass && !t.IsAbstract && t.GetConstructors().ToList().Exists(c => c.GetParameters().Length == 0))
- {
- try
- {
- object obj = Activator.CreateInstance(t);
- if (obj is IEffectPlugin)
- {
- IEffectPlugin iplug = (IEffectPlugin)obj;
- plugs.Add(iplug);
- ToolStripMenuItem strip = new ToolStripMenuItem();
- strip.Name = "effect_" + iplug.Name.Replace(" ", "");
- strip.Text = iplug.Name;
- strip.Click += effectClicked;
- strip.DropDownItems.Add(new ToolStripMenuItem
- {
- Text = "Author: " + iplug.Author +
- "\nName: " + iplug.Name +
- "\nDescription: " + iplug.Description +
- "\nVersion: " + iplug.Version.ToString(),
- Enabled = false
- });
- bool finded = false;
- foreach (ToolStripItem ts in effectToolStripMenuItem.DropDownItems)
- if (ts.Text.Equals(iplug.SubMenuName))
- {
- (ts as ToolStripMenuItem).DropDownItems.Add(strip);
- finded = true;
- break;
- }
- if (!finded)
- {
- var ts = (ToolStripMenuItem)effectToolStripMenuItem.DropDownItems.Add(iplug.SubMenuName);
- ts.DropDownItems.Add(strip);
- }
- }
- }
- catch { continue; }
- }
- }
- private void AddEmptyItem(ToolStripMenuItem toolit)
- {
- ToolStripMenuItem strip = new ToolStripMenuItem();
- strip.Name = "effect_empty";
- strip.Text = "Empty";
- strip.Enabled = false;
- toolit.DropDownItems.Add(strip);
- }
- private void effectClicked(object sender, EventArgs e)
- {
- string effName = (sender as ToolStripMenuItem).Text;
- var pl = plugs.Find(ip => ip.Name.Equals(effName));
- if (pl != null && pictureBox1.Image != null)
- {
- Image img = (Image)pictureBox1.Image.Clone(), img0 = null;
- this.Enabled = false;
- var setsForm = AutoGui.Gui.Create(pl.GetType());
- if (setsForm.ShowDialog() == DialogResult.OK)
- {
- this.Text += " [Working...]";
- img0 = (setsForm.Result as IEffectPlugin).ApplyEffect(img);
- this.Text = this.Text.Replace(" [Working...]", "");
- pictureBox1.Image = (Image)img0.Clone();
- (listBox1.SelectedItem as FSFNameIC).Image = img0;
- }
- this.Enabled = true;
- /*using (var progressForm = new ShowProgress())
- {
- th.Start();
- progressForm.Left = this.Left + (this.Width - progressForm.Width) / 2;
- progressForm.Top = this.Top + (this.Height - progressForm.Height) / 2;
- progressForm.Show();
- while (!pl.Completed) progressForm.ProgressValue = pl.ProgressValue;
- progressForm.Hide();
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement