Fix problem with registry value sorting

* Removed implemented sorting on ListView
* Added sorting of values before populating ListView
* Small changes to improve code structure
This commit is contained in:
LjungErik 2016-04-24 11:23:21 +02:00
parent ea2584380a
commit 560aa1e9d2
6 changed files with 89 additions and 159 deletions

View File

@ -9,23 +9,6 @@ using xServer.Core.Registry;
namespace xServer.Controls
{
//Comparer for comparing registry values (listview)
//Used to sort the elements in the listview according to the RegName property
public class RegistryValueListItemComparer : IComparer
{
public RegistryValueListItemComparer() { }
public int Compare(object x, object y)
{
if (x.GetType() == typeof(RegistryValueLstItem) && y.GetType() == typeof(RegistryValueLstItem))
{
//Compare if the names are the same
return String.Compare(((RegistryValueLstItem)x).RegName, ((RegistryValueLstItem)y).RegName);
}
return -1;
}
}
public class RegistryValueLstItem : ListViewItem
{
private string _type { get; set; }

View File

@ -31,8 +31,6 @@ namespace xServer.Forms
this.valueDataTxtBox.Text = String.Join("\r\n",((string[])value.Data));
}
#region Ok and Cancel button
private void okButton_Click(object sender, EventArgs e)
{
string[] valueData = valueDataTxtBox.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
@ -40,6 +38,5 @@ namespace xServer.Forms
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
#endregion
}
}

View File

@ -52,17 +52,6 @@ namespace xServer.Forms
}
}
#region Helpfunctions
private DialogResult ShowWarning(string msg, string caption)
{
return MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
#endregion
#region RadioButton Actions
private void radioHex_CheckboxChanged(object sender, EventArgs e)
{
if (valueDataTxtBox.IsHexNumber == radioHexa.Checked)
@ -74,10 +63,6 @@ namespace xServer.Forms
radioDecimal.Checked = true;
}
#endregion
#region OK and Cancel Buttons
private void okButton_Click(object sender, EventArgs e)
{
if(valueDataTxtBox.IsConversionValid() || IsOverridePossible())
@ -97,7 +82,10 @@ namespace xServer.Forms
}
}
#endregion
private DialogResult ShowWarning(string msg, string caption)
{
return MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
private bool IsOverridePossible()
{

View File

@ -32,12 +32,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmRegistryEditor));
this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.splitContainer = new System.Windows.Forms.SplitContainer();
this.tvRegistryDirectory = new xServer.Controls.RegistryTreeView();
this.imageRegistryDirectoryList = new System.Windows.Forms.ImageList(this.components);
this.lstRegistryValues = new xServer.Controls.AeroListView();
this.hName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.hType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.hValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.imageRegistryKeyTypeList = new System.Windows.Forms.ImageList(this.components);
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.selectedStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
@ -89,6 +84,11 @@
this.qWORD64bitValueToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.multiStringValueToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.expandableStringValueToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.tvRegistryDirectory = new xServer.Controls.RegistryTreeView();
this.lstRegistryValues = new xServer.Controls.AeroListView();
this.hName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.hType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.hValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout();
@ -136,65 +136,12 @@
this.splitContainer.SplitterDistance = 259;
this.splitContainer.TabIndex = 0;
//
// tvRegistryDirectory
//
this.tvRegistryDirectory.Dock = System.Windows.Forms.DockStyle.Fill;
this.tvRegistryDirectory.HideSelection = false;
this.tvRegistryDirectory.ImageIndex = 0;
this.tvRegistryDirectory.ImageList = this.imageRegistryDirectoryList;
this.tvRegistryDirectory.Location = new System.Drawing.Point(0, 0);
this.tvRegistryDirectory.Name = "tvRegistryDirectory";
this.tvRegistryDirectory.SelectedImageIndex = 0;
this.tvRegistryDirectory.Size = new System.Drawing.Size(259, 508);
this.tvRegistryDirectory.TabIndex = 0;
this.tvRegistryDirectory.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.tvRegistryDirectory_AfterLabelEdit);
this.tvRegistryDirectory.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvRegistryDirectory_BeforeExpand);
this.tvRegistryDirectory.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvRegistryDirectory_BeforeSelect);
this.tvRegistryDirectory.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvRegistryDirectory_NodeMouseClick);
this.tvRegistryDirectory.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tvRegistryDirectory_KeyUp);
//
// imageRegistryDirectoryList
//
this.imageRegistryDirectoryList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageRegistryDirectoryList.ImageStream")));
this.imageRegistryDirectoryList.TransparentColor = System.Drawing.Color.Transparent;
this.imageRegistryDirectoryList.Images.SetKeyName(0, "folder.png");
//
// lstRegistryValues
//
this.lstRegistryValues.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.hName,
this.hType,
this.hValue});
this.lstRegistryValues.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstRegistryValues.FullRowSelect = true;
this.lstRegistryValues.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lstRegistryValues.HideSelection = false;
this.lstRegistryValues.Location = new System.Drawing.Point(0, 0);
this.lstRegistryValues.Name = "lstRegistryValues";
this.lstRegistryValues.Size = new System.Drawing.Size(515, 508);
this.lstRegistryValues.SmallImageList = this.imageRegistryKeyTypeList;
this.lstRegistryValues.TabIndex = 0;
this.lstRegistryValues.UseCompatibleStateImageBehavior = false;
this.lstRegistryValues.View = System.Windows.Forms.View.Details;
this.lstRegistryValues.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lstRegistryKeys_AfterLabelEdit);
this.lstRegistryValues.KeyUp += new System.Windows.Forms.KeyEventHandler(this.lstRegistryKeys_KeyUp);
this.lstRegistryValues.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lstRegistryKeys_MouseClick);
//
// hName
//
this.hName.Text = "Name";
this.hName.Width = 173;
//
// hType
//
this.hType.Text = "Type";
this.hType.Width = 104;
//
// hValue
//
this.hValue.Text = "Value";
this.hValue.Width = 214;
//
// imageRegistryKeyTypeList
//
this.imageRegistryKeyTypeList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageRegistryKeyTypeList.ImageStream")));
@ -527,7 +474,7 @@
this.lst_ContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.newToolStripMenuItem1});
this.lst_ContextMenuStrip.Name = "lst_ContextMenuStrip";
this.lst_ContextMenuStrip.Size = new System.Drawing.Size(153, 48);
this.lst_ContextMenuStrip.Size = new System.Drawing.Size(99, 26);
//
// newToolStripMenuItem1
//
@ -541,7 +488,7 @@
this.multiStringValueToolStripMenuItem1,
this.expandableStringValueToolStripMenuItem1});
this.newToolStripMenuItem1.Name = "newToolStripMenuItem1";
this.newToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.newToolStripMenuItem1.Size = new System.Drawing.Size(98, 22);
this.newToolStripMenuItem1.Text = "New";
//
// keyToolStripMenuItem1
@ -598,6 +545,59 @@
this.expandableStringValueToolStripMenuItem1.Text = "Expandable String Value";
this.expandableStringValueToolStripMenuItem1.Click += new System.EventHandler(this.createExpandStringRegistryValue_Click);
//
// tvRegistryDirectory
//
this.tvRegistryDirectory.Dock = System.Windows.Forms.DockStyle.Fill;
this.tvRegistryDirectory.HideSelection = false;
this.tvRegistryDirectory.ImageIndex = 0;
this.tvRegistryDirectory.ImageList = this.imageRegistryDirectoryList;
this.tvRegistryDirectory.Location = new System.Drawing.Point(0, 0);
this.tvRegistryDirectory.Name = "tvRegistryDirectory";
this.tvRegistryDirectory.SelectedImageIndex = 0;
this.tvRegistryDirectory.Size = new System.Drawing.Size(259, 508);
this.tvRegistryDirectory.TabIndex = 0;
this.tvRegistryDirectory.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.tvRegistryDirectory_AfterLabelEdit);
this.tvRegistryDirectory.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvRegistryDirectory_BeforeExpand);
this.tvRegistryDirectory.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvRegistryDirectory_BeforeSelect);
this.tvRegistryDirectory.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvRegistryDirectory_NodeMouseClick);
this.tvRegistryDirectory.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tvRegistryDirectory_KeyUp);
//
// lstRegistryValues
//
this.lstRegistryValues.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.hName,
this.hType,
this.hValue});
this.lstRegistryValues.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstRegistryValues.FullRowSelect = true;
this.lstRegistryValues.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lstRegistryValues.HideSelection = false;
this.lstRegistryValues.Location = new System.Drawing.Point(0, 0);
this.lstRegistryValues.Name = "lstRegistryValues";
this.lstRegistryValues.Size = new System.Drawing.Size(515, 508);
this.lstRegistryValues.SmallImageList = this.imageRegistryKeyTypeList;
this.lstRegistryValues.TabIndex = 0;
this.lstRegistryValues.UseCompatibleStateImageBehavior = false;
this.lstRegistryValues.View = System.Windows.Forms.View.Details;
this.lstRegistryValues.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lstRegistryKeys_AfterLabelEdit);
this.lstRegistryValues.KeyUp += new System.Windows.Forms.KeyEventHandler(this.lstRegistryKeys_KeyUp);
this.lstRegistryValues.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lstRegistryKeys_MouseClick);
//
// hName
//
this.hName.Text = "Name";
this.hName.Width = 173;
//
// hType
//
this.hType.Text = "Type";
this.hType.Width = 104;
//
// hValue
//
this.hValue.Text = "Value";
this.hValue.Width = 214;
//
// FrmRegistryEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -40,20 +40,13 @@ namespace xServer.Forms
private void FrmRegistryEditor_Load(object sender, EventArgs e)
{
if (_connectClient.Value.AccountType != "Admin")
{
//Prompt user of not being admin
string msg = PRIVILEGE_WARNING;
string caption = "Alert!";
MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
MessageBox.Show(PRIVILEGE_WARNING, "Alert!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
if (_connectClient != null)
this.Text = WindowHelper.GetWindowTitle("Registry Editor", _connectClient);
// Signal client to retrive the root nodes (indicated by null)
new xServer.Core.Packets.ServerPackets.DoLoadRegistryKey(null).Execute(_connectClient);
this.lstRegistryValues.ListViewItemSorter = new RegistryValueListItemComparer();
if (_connectClient != null)
this.Text = WindowHelper.GetWindowTitle("Registry Editor", _connectClient);
}
private void FrmRegistryEditor_FormClosing(object sender, FormClosingEventArgs e)
@ -121,9 +114,7 @@ namespace xServer.Forms
tvRegistryDirectory.BeginUpdate();
foreach (var match in matches)
{
AddRootKey(match);
}
tvRegistryDirectory.SelectedNode = tvRegistryDirectory.Nodes[0];
@ -141,10 +132,8 @@ namespace xServer.Forms
{
tvRegistryDirectory.BeginUpdate();
foreach (RegSeekerMatch match in matches)
{
foreach (var match in matches)
AddKeyToTree(parent, match);
}
parent.Expand();
tvRegistryDirectory.EndUpdate();
@ -193,10 +182,6 @@ namespace xServer.Forms
parent.Nodes[oldName].Text = newName;
parent.Nodes[oldName].Name = newName;
//Make sure to reselect the node
if (tvRegistryDirectory.SelectedNode == parent.Nodes[newName])
tvRegistryDirectory.SelectedNode = null;
tvRegistryDirectory.SelectedNode = parent.Nodes[newName];
});
}
@ -240,9 +225,6 @@ namespace xServer.Forms
ValuesFromNode.Add(value);
key.Tag = ValuesFromNode.ToArray();
//Deactivate sorting (prevent sorting of new value)
lstRegistryValues.Sorting = SortOrder.None;
if (tvRegistryDirectory.SelectedNode == key)
{
RegistryValueLstItem item = new RegistryValueLstItem(value);
@ -253,10 +235,8 @@ namespace xServer.Forms
lstRegistryValues.LabelEdit = true;
item.BeginEdit();
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
@ -275,9 +255,7 @@ namespace xServer.Forms
key.Tag = ((RegValueData[])key.Tag).Where(value => value.Name != valueName).ToArray();
if (tvRegistryDirectory.SelectedNode == key)
{
lstRegistryValues.Items.RemoveByKey(valueName);
}
}
else //Handle delete of default value
{
@ -289,9 +267,7 @@ namespace xServer.Forms
var valueItem = lstRegistryValues.Items.Cast<RegistryValueLstItem>()
.SingleOrDefault(item => item.Name == valueName);
if (valueItem != null)
{
valueItem.Data = regValue.Kind.RegistryTypeToString(null);
}
}
}
@ -317,14 +293,10 @@ namespace xServer.Forms
var valueItem = lstRegistryValues.Items.Cast<RegistryValueLstItem>()
.SingleOrDefault(item => item.Name == oldName);
if (valueItem != null)
{
valueItem.RegName = newName;
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
@ -345,14 +317,10 @@ namespace xServer.Forms
var valueItem = lstRegistryValues.Items.Cast<RegistryValueLstItem>()
.SingleOrDefault(item => item.Name == value.Name);
if (valueItem != null)
{
valueItem.Data = value.Kind.RegistryTypeToString(value.Data);
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
@ -371,15 +339,19 @@ namespace xServer.Forms
lstRegistryValues.BeginUpdate();
lstRegistryValues.Items.Clear();
// Make sure that the passed values are usable
if (values != null && values.Length > 0)
//Sort values
values = (
from value in values
orderby value.Name ascending
select value
).ToArray();
foreach (var value in values)
{
foreach (var value in values)
{
RegistryValueLstItem item = new RegistryValueLstItem(value);
lstRegistryValues.Items.Add(item);
}
RegistryValueLstItem item = new RegistryValueLstItem(value);
lstRegistryValues.Items.Add(item);
}
lstRegistryValues.EndUpdate();
}
@ -453,21 +425,13 @@ namespace xServer.Forms
private void tvRegistryDirectory_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
if (e.Node != null)
{
//Activate sorting (Make sure to sort values correctly)
lstRegistryValues.Sorting = SortOrder.Ascending;
UpdateLstRegistryValues(e.Node);
}
UpdateLstRegistryValues(e.Node);
}
private void tvRegistryDirectory_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete && GetDeleteState())
{
deleteRegistryKey_Click(this, e);
}
}
#endregion
@ -602,9 +566,7 @@ namespace xServer.Forms
private void lstRegistryKeys_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete && GetDeleteState())
{
deleteRegistryValue_Click(this, e);
}
}
#endregion

View File

@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADm
BwAAAk1TRnQBSQFMAwEBAAEwAQUBMAEFARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
BwAAAk1TRnQBSQFMAwEBAAFIAQUBSAEFARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
AUADAAEQAwABAQEAAQgGAAEEGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEA
AfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEA
AYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFm
@ -169,7 +169,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABk
CQAAAk1TRnQBSQFMAgEBAgEAAVABBAFQAQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CQAAAk1TRnQBSQFMAgEBAgEAAWgBBAFoAQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA