void EditEvent(Event a_ev) { AddForm form = new AddForm(); form.AllowFileEdit = a_ev.lineNum > -1; form.sound = a_ev.SoundName; form.icon = a_ev.ImageName; form.mods = a_ev.modifier; form.keys = new List <Keys>(new Keys[1] { a_ev.key }); form.Volume = a_ev.Volume; form.UseEcho = a_ev.UseEcho; form.EchoAmount = a_ev.EchoAmount; form.Playmode = a_ev.PlayMode; var result = form.ShowDialog(); if (result == DialogResult.OK) { try { var info = new FileInfo(form.sound); } catch { return; } Keys key = Keys.None; foreach (var item in form.keys) { key = key | item; } foreach (var v in events) { if (v == a_ev) { continue; } if (v.modifier == form.mods && v.key == key) { return; } } a_ev.key = key; a_ev.modifier = form.mods; a_ev.Volume = form.Volume; a_ev.PlayMode = form.Playmode; if (form.AllowFileEdit) { a_ev.SoundName = form.sound; a_ev.ImageName = form.icon; string line = a_ev.modifier.ToString() + "|" + a_ev.key.ToString() + "|" + a_ev.SoundName + "|" + a_ev.ImageName + "|" + a_ev.Volume.ToString() + "|" + a_ev.PlayMode.ToString(); string[] lines = File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Sounds.txt"); lines[a_ev.lineNum] = line; File.WriteAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Sounds.txt", lines); } else { string[] lines = File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Settings.txt"); if (lines.Length < 2) { var temp = new List <string>(lines); temp.Add(a_ev.Volume.ToString()); lines = temp.ToArray(); } else { lines[1] = a_ev.Volume.ToString(); } File.WriteAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Settings.txt", lines); } if (!(a_ev.modifier == Sound_events.ModifierKeys.None && a_ev.key == Keys.None)) { ReRegister(); } a_ev.button.Parent = panel; try { a_ev.button.BackgroundImage = Image.FromFile(a_ev.ImageName); a_ev.button.BackgroundImageLayout = ImageLayout.Stretch; a_ev.button.BackColor = Color.Transparent; } catch { } a_ev.button.FlatStyle = FlatStyle.Popup; a_ev.EchoAmount = form.EchoAmount; a_ev.UseEcho = form.UseEcho; } else if (result == DialogResult.Ignore) { if (!form.AllowFileEdit) { return; } List <string> lines = new List <string>(File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Sounds.txt")); lines.RemoveAt(a_ev.lineNum); File.WriteAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Sounds.txt", lines.ToArray()); a_ev.button.Dispose(); events.Remove(a_ev); a_ev = null; ReRegister(); } }
private void addButton_Click(object sender, EventArgs e) { AddForm form = new AddForm(); var result = form.ShowDialog(); if (result == DialogResult.OK) { try { var info = new FileInfo(form.sound); } catch { return; } Keys key = Keys.None; foreach (var item in form.keys) { key = key | item; } foreach (var v in events) { if (v.modifier == form.mods && v.key == key) { return; } } int linenum = File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Sounds.txt").Length; Button btn = new Button(); Event ev = new Event(form.mods, key, form.sound, form.icon, linenum, btn, form.Volume, Event.PlayModes.multi); events.Add(ev); if (!(ev.modifier == Sound_events.ModifierKeys.None && ev.key == Keys.None)) { hook.RegisterHotKey(ev.modifier, ev.key); } string line = ev.modifier.ToString() + "|" + ev.key.ToString() + "|" + ev.SoundName + "|" + ev.ImageName + "|" + ev.Volume.ToString() + "|" + ev.PlayMode.ToString(); File.AppendAllLines(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/SoundEvents/Sounds.txt", new string[1] { line }); btn.Parent = panel; btn.Size = new Size(100, 100); try { btn.BackgroundImage = Image.FromFile(ev.ImageName); btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackColor = Color.Transparent; } catch { } btn.FlatStyle = FlatStyle.Popup; btn.MouseUp += new MouseEventHandler(delegate(Object o, MouseEventArgs args) { if (args.Button == MouseButtons.Left) { hook_KeyPressed(btn, new KeyPressedEventArgs(ev.modifier, ev.key)); } else if (args.Button == MouseButtons.Right) { EditEvent(ev); } }); int index = panel.Controls.GetChildIndex(btn, false); panel.Controls.SetChildIndex(btn, index - 1); ev.EchoAmount = form.EchoAmount; ev.UseEcho = form.UseEcho; } }