private void btnDown_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex >= plugins.Count) { return; } int i = listBox1.SelectedIndex; cPlugin pl = plugins[i]; plugins.RemoveAt(i); plugins.Insert(i + 1, pl); listBox1.Items.RemoveAt(i); listBox1.Items.Insert(i + 1, pl.Name); listBox1.SelectedIndex = i + 1; }
private void Form1_Load(object sender, EventArgs e) { Microsoft.Win32.RegistryKey pkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Decal\\Plugins"); //Read in plugin data in GUID order foreach (string k in pkey.GetSubKeyNames()) { cPlugin curplg = new cPlugin(); curplg.GUID = k; Microsoft.Win32.RegistryKey mykey = pkey.OpenSubKey(k); curplg.orderkey = ((string)mykey.GetValue("Order", "."))[0]; curplg.Name = (string)mykey.GetValue("", "."); plugins.Add(curplg); if (!usedkeys.Contains(curplg.orderkey)) { usedkeys.Add(curplg.orderkey); } } //Switch to keyed order List <cPlugin> keyedorderplugins = new List <cPlugin>(); string sorder = (string)pkey.GetValue("Order", ""); while (sorder.Length > 0) { //Read plugins with this key bool gotone = false; for (int i = plugins.Count - 1; i >= 0; --i) { if (plugins[i].orderkey == sorder[0]) { keyedorderplugins.Add(plugins[i]); plugins.RemoveAt(i); if (!gotone) { gotone = true; } else { keyedorderplugins[keyedorderplugins.Count - 1].orderkey = GetNewOrderKey(); } } } sorder = sorder.Substring(1); } //Read plugins with no matching key in keystring for (int i = plugins.Count - 1; i >= 0; --i) { keyedorderplugins.Add(plugins[i]); plugins.RemoveAt(i); keyedorderplugins[keyedorderplugins.Count - 1].orderkey = GetNewOrderKey(); } plugins = keyedorderplugins; foreach (cPlugin p in plugins) { listBox1.Items.Add(p.Name); } }