Code improvements and restructuring of 'FrmRegistryEditor'

* Restructured the code for FrmRegistryEditor
* Made parts of code more compact and readable
* Improved naming of functions
* Improved code for handling ContextMenu and ToolStrip
* Changed client to return RegValueData-array instead of null
This commit is contained in:
LjungErik 2016-04-22 08:43:16 +02:00
parent f5f244c727
commit df06fd2b84
7 changed files with 291 additions and 428 deletions

View File

@ -64,7 +64,7 @@ namespace xClient.Core.Commands
}
responsePacket.ErrorMsg = errorMsg;
responsePacket.Match = new RegSeekerMatch(newKeyName, null, 0);
responsePacket.Match = new RegSeekerMatch(newKeyName, new RegValueData[] { }, 0);
responsePacket.ParentPath = packet.ParentPath;
responsePacket.Execute(client);

View File

@ -127,7 +127,7 @@ namespace xClient.Core.Registry
}
else
{
AddMatch(keyName, null, 0);
AddMatch(keyName, new RegValueData[]{}, 0);
}
}

View File

@ -24,7 +24,7 @@ namespace xServer.Controls
}
}
internal class RegistryValueLstItem : ListViewItem
public class RegistryValueLstItem : ListViewItem
{
private string _regName { get; set; }
private string _type { get; set; }

View File

@ -22,7 +22,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.AddKeysToTree(packet.RootKey, packet.Matches);
client.Value.FrmRe.AddKeys(packet.RootKey, packet.Matches);
}
else
{
@ -48,7 +48,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.AddKeyToTree(packet.ParentPath, packet.Match);
client.Value.FrmRe.CreateNewKey(packet.ParentPath, packet.Match);
}
else
{
@ -68,7 +68,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.RemoveKeyFromTree(packet.ParentPath, packet.KeyName);
client.Value.FrmRe.RemoveKey(packet.ParentPath, packet.KeyName);
}
else
{
@ -88,7 +88,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.RenameKeyFromTree(packet.ParentPath, packet.OldKeyName, packet.NewKeyName);
client.Value.FrmRe.RenameKey(packet.ParentPath, packet.OldKeyName, packet.NewKeyName);
}
else
{
@ -112,7 +112,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.AddValueToList(packet.KeyPath, packet.Value);
client.Value.FrmRe.CreateValue(packet.KeyPath, packet.Value);
}
else
{
@ -132,7 +132,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.DeleteValueFromList(packet.KeyPath, packet.ValueName);
client.Value.FrmRe.DeleteValue(packet.KeyPath, packet.ValueName);
}
else
{
@ -152,7 +152,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.RenameValueFromList(packet.KeyPath, packet.OldValueName, packet.NewValueName);
client.Value.FrmRe.RenameValue(packet.KeyPath, packet.OldValueName, packet.NewValueName);
}
else
{
@ -172,7 +172,7 @@ namespace xServer.Core.Commands
{
if (!packet.IsError)
{
client.Value.FrmRe.ChangeValueFromList(packet.KeyPath, packet.Value);
client.Value.FrmRe.ChangeValue(packet.KeyPath, packet.Value);
}
else
{

View File

@ -32,7 +32,12 @@
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();
@ -71,7 +76,7 @@
this.selectedItem_ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.modifyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.modifyBinaryDataToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.modifyToolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.deleteToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.renameToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.lst_ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
@ -84,11 +89,6 @@
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.lstRegistryKeys = 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();
@ -131,17 +131,70 @@
//
// splitContainer.Panel2
//
this.splitContainer.Panel2.Controls.Add(this.lstRegistryKeys);
this.splitContainer.Panel2.Controls.Add(this.lstRegistryValues);
this.splitContainer.Size = new System.Drawing.Size(778, 508);
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")));
@ -204,6 +257,7 @@
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
this.editToolStripMenuItem.Text = "Edit";
this.editToolStripMenuItem.DropDownOpening += new System.EventHandler(this.editToolStripMenuItem_DropDownOpening);
//
// modifyToolStripMenuItem1
//
@ -426,7 +480,7 @@
this.selectedItem_ContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.modifyToolStripMenuItem,
this.modifyBinaryDataToolStripMenuItem,
this.toolStripSeparator3,
this.modifyToolStripSeparator1,
this.deleteToolStripMenuItem1,
this.renameToolStripMenuItem1});
this.selectedItem_ContextMenuStrip.Name = "selectedItem_ContextMenuStrip";
@ -449,10 +503,10 @@
this.modifyBinaryDataToolStripMenuItem.Text = "Modify Binary Data...";
this.modifyBinaryDataToolStripMenuItem.Click += new System.EventHandler(this.modifyBinaryDataRegistryValue_Click);
//
// toolStripSeparator3
// modifyToolStripSeparator1
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(181, 6);
this.modifyToolStripSeparator1.Name = "modifyToolStripSeparator1";
this.modifyToolStripSeparator1.Size = new System.Drawing.Size(181, 6);
//
// deleteToolStripMenuItem1
//
@ -473,7 +527,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(99, 26);
this.lst_ContextMenuStrip.Size = new System.Drawing.Size(153, 48);
//
// newToolStripMenuItem1
//
@ -487,7 +541,7 @@
this.multiStringValueToolStripMenuItem1,
this.expandableStringValueToolStripMenuItem1});
this.newToolStripMenuItem1.Name = "newToolStripMenuItem1";
this.newToolStripMenuItem1.Size = new System.Drawing.Size(98, 22);
this.newToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
this.newToolStripMenuItem1.Text = "New";
//
// keyToolStripMenuItem1
@ -544,62 +598,6 @@
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);
//
// lstRegistryKeys
//
this.lstRegistryKeys.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.hName,
this.hType,
this.hValue});
this.lstRegistryKeys.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstRegistryKeys.FullRowSelect = true;
this.lstRegistryKeys.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lstRegistryKeys.HideSelection = false;
this.lstRegistryKeys.Location = new System.Drawing.Point(0, 0);
this.lstRegistryKeys.Name = "lstRegistryKeys";
this.lstRegistryKeys.Size = new System.Drawing.Size(515, 508);
this.lstRegistryKeys.SmallImageList = this.imageRegistryKeyTypeList;
this.lstRegistryKeys.TabIndex = 0;
this.lstRegistryKeys.UseCompatibleStateImageBehavior = false;
this.lstRegistryKeys.View = System.Windows.Forms.View.Details;
this.lstRegistryKeys.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lstRegistryKeys_AfterLabelEdit);
this.lstRegistryKeys.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.lstRegistryKeys_ItemSelectionChanged);
this.lstRegistryKeys.Enter += new System.EventHandler(this.lstRegistryKeys_Enter);
this.lstRegistryKeys.KeyUp += new System.Windows.Forms.KeyEventHandler(this.lstRegistryKeys_KeyUp);
this.lstRegistryKeys.Leave += new System.EventHandler(this.lstRegistryKeys_Leave);
this.lstRegistryKeys.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);
@ -637,7 +635,7 @@
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
private System.Windows.Forms.SplitContainer splitContainer;
private Controls.RegistryTreeView tvRegistryDirectory;
private Controls.AeroListView lstRegistryKeys;
private Controls.AeroListView lstRegistryValues;
private System.Windows.Forms.StatusStrip statusStrip;
private System.Windows.Forms.ToolStripStatusLabel selectedStripStatusLabel;
private System.Windows.Forms.ImageList imageRegistryDirectoryList;
@ -661,7 +659,6 @@
private System.Windows.Forms.ContextMenuStrip selectedItem_ContextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem modifyToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem modifyBinaryDataToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem renameToolStripMenuItem1;
private System.Windows.Forms.ContextMenuStrip lst_ContextMenuStrip;
@ -693,5 +690,6 @@
private System.Windows.Forms.ToolStripMenuItem qWORD64bitValueToolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem multiStringValueToolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem expandableStringValueToolStripMenuItem2;
private System.Windows.Forms.ToolStripSeparator modifyToolStripSeparator1;
}
}

View File

@ -23,7 +23,7 @@ namespace xServer.Forms
#region Constants
private const string PRIVILEGE_WARNING = "The client software is not running as administrator and therefore some functionality like Update, Create, Open and Delete my not work properly!";
private const string PRIVILEGE_WARNING = "The client software is not running as administrator and therefore some functionality like Update, Create, Open and Delete may not work properly!";
private const string DEFAULT_REG_VALUE = "(Default)";
@ -41,7 +41,6 @@ namespace xServer.Forms
private void FrmRegistryEditor_Load(object sender, EventArgs e)
{
//Check if user is not currently running as administrator
if (_connectClient.Value.AccountType != "Admin")
{
//Prompt user of not being admin
@ -53,8 +52,7 @@ namespace xServer.Forms
// Signal client to retrive the root nodes (indicated by null)
new xServer.Core.Packets.ServerPackets.DoLoadRegistryKey(null).Execute(_connectClient);
// Set the ListSorter for the listView
this.lstRegistryKeys.ListViewItemSorter = new RegistryValueListItemComparer();
this.lstRegistryValues.ListViewItemSorter = new RegistryValueListItemComparer();
if (_connectClient != null)
this.Text = WindowHelper.GetWindowTitle("Registry Editor", _connectClient);
@ -76,7 +74,6 @@ namespace xServer.Forms
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
public void PerformClose()
@ -98,6 +95,15 @@ namespace xServer.Forms
tvRegistryDirectory.Nodes.Add(node);
}
private TreeNode AddKeyToTree(TreeNode parent, RegSeekerMatch subKey)
{
TreeNode node = CreateNode(subKey.Key, subKey.Key, subKey.Data);
parent.Nodes.Add(node);
if (subKey.HasSubKeys)
node.Nodes.Add(new TreeNode());
return node;
}
private TreeNode CreateNode(string key, string text, object tag)
{
return new TreeNode()
@ -108,7 +114,7 @@ namespace xServer.Forms
};
}
public void AddKeysToTree(string rootName, RegSeekerMatch[] matches)
public void AddKeys(string rootName, RegSeekerMatch[] matches)
{
if (string.IsNullOrEmpty(rootName))
{
@ -129,7 +135,6 @@ namespace xServer.Forms
}
else
{
TreeNode parent = GetTreeNode(rootName);
if (parent != null)
@ -138,14 +143,9 @@ namespace xServer.Forms
{
tvRegistryDirectory.BeginUpdate();
foreach (var match in matches)
foreach (RegSeekerMatch match in matches)
{
//This will execute in the form thread
TreeNode node = CreateNode(match.Key, match.Key, match.Data);
if (match.HasSubKeys)
node.Nodes.Add(new TreeNode());
parent.Nodes.Add(node);
AddKeyToTree(parent, match);
}
parent.Expand();
@ -155,39 +155,27 @@ namespace xServer.Forms
}
}
public void AddKeyToTree(string rootKey, RegSeekerMatch match)
public void CreateNewKey(string rootKey, RegSeekerMatch match)
{
TreeNode parent = GetTreeNode(rootKey);
tvRegistryDirectory.Invoke((MethodInvoker)delegate
{
//This will execute in the form thread
TreeNode node = CreateNode(match.Key, match.Key, match.Data);
if (match.HasSubKeys)
node.Nodes.Add(new TreeNode());
TreeNode node = AddKeyToTree(parent, match);
parent.Nodes.Add(node);
node.EnsureVisible();
if (!parent.IsExpanded)
{
tvRegistryDirectory.SelectedNode = parent;
tvRegistryDirectory.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.specialCreateRegistryKey_AfterExpand);
parent.Expand();
}
else
{
tvRegistryDirectory.SelectedNode = node;
tvRegistryDirectory.LabelEdit = true;
node.BeginEdit();
}
tvRegistryDirectory.SelectedNode = node;
node.Expand();
tvRegistryDirectory.LabelEdit = true;
node.BeginEdit();
});
}
public void RemoveKeyFromTree(string rootKey, string subKey)
public void RemoveKey(string rootKey, string subKey)
{
TreeNode parent = GetTreeNode(rootKey);
//Make sure the key does exist
if (parent.Nodes.ContainsKey(subKey)) {
tvRegistryDirectory.Invoke((MethodInvoker)delegate
{
@ -196,26 +184,22 @@ namespace xServer.Forms
}
}
public void RenameKeyFromTree(string rootKey, string oldName, string newName)
public void RenameKey(string rootKey, string oldName, string newName)
{
TreeNode parent = GetTreeNode(rootKey);
//Make sure the key does exist
if (parent.Nodes.ContainsKey(oldName))
{
int index = parent.Nodes.IndexOfKey(oldName);
tvRegistryDirectory.Invoke((MethodInvoker)delegate
{
parent.Nodes[index].Text = newName;
parent.Nodes[index].Name = newName;
parent.Nodes[oldName].Text = newName;
parent.Nodes[oldName].Name = newName;
//Make sure that the newly renamed node is selected
//To allow update in the listview
if (tvRegistryDirectory.SelectedNode == parent.Nodes[index])
//Make sure to reselect the node
if (tvRegistryDirectory.SelectedNode == parent.Nodes[newName])
tvRegistryDirectory.SelectedNode = null;
tvRegistryDirectory.SelectedNode = parent.Nodes[index];
tvRegistryDirectory.SelectedNode = parent.Nodes[newName];
});
}
}
@ -227,91 +211,50 @@ namespace xServer.Forms
/// <returns>Null if an invalid name is passed or the TreeNode could not be found; The TreeNode represented by the fullpath;</returns>
private TreeNode GetTreeNode(string path)
{
string[] nodePath = null;
if (path.Contains("\\"))
{
nodePath = path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
string[] nodePath = path.Split(new char[] { '\\' });
// Only one valid node. Probably malformed
if (nodePath.Length < 2)
return null;
}
else
{
//Is a root node
nodePath = new string[] { path };
}
// Keep track of the last node to reference for traversal.
TreeNode lastNode = null;
if (tvRegistryDirectory.Nodes.ContainsKey(nodePath[0]))
{
lastNode = tvRegistryDirectory.Nodes[nodePath[0]];
}
else
{
//Node is missing
TreeNode lastNode = tvRegistryDirectory.Nodes[nodePath[0]];
if (lastNode == null)
return null;
}
// Go through the rest of the node path.
for (int i = 1; i < nodePath.Length; i++)
{
if (lastNode.Nodes.ContainsKey(nodePath[i]))
{
lastNode = lastNode.Nodes[nodePath[i]];
}
else
{
//Node is missing
lastNode = lastNode.Nodes[nodePath[i]];
if (lastNode == null)
return null;
}
}
return lastNode;
}
#endregion
#region ListView Helpfunctions
public void AddValueToList(string keyPath, RegValueData value)
public void CreateValue(string keyPath, RegValueData value)
{
TreeNode key = GetTreeNode(keyPath);
if (key != null )
{
lstRegistryKeys.Invoke((MethodInvoker)delegate
lstRegistryValues.Invoke((MethodInvoker)delegate
{
List<RegValueData> ValuesFromNode = null;
if (key.Tag != null && key.Tag.GetType() == typeof(RegValueData[])) {
ValuesFromNode = ((RegValueData[])key.Tag).ToList();
ValuesFromNode.Add(value);
key.Tag = ValuesFromNode.ToArray();
}
else
{
//The tag has a incorrect element or is missing data
ValuesFromNode = new List<RegValueData>();
ValuesFromNode.Add(value);
key.Tag = ValuesFromNode.ToArray();
}
List<RegValueData> ValuesFromNode = ((RegValueData[])key.Tag).ToList();
ValuesFromNode.Add(value);
key.Tag = ValuesFromNode.ToArray();
//Deactivate sorting
lstRegistryKeys.Sorting = SortOrder.None;
//Deactivate sorting (prevent sorting of new value)
lstRegistryValues.Sorting = SortOrder.None;
if (tvRegistryDirectory.SelectedNode == key)
{
string kind = value.Kind.RegistryTypeToString();
string data = value.Kind.RegistryTypeToString(value.Data);
RegistryValueLstItem item = new RegistryValueLstItem(value.Name, kind, data);
//unselect all
lstRegistryKeys.SelectedIndices.Clear();
lstRegistryKeys.Items.Add(item);
lstRegistryValues.Items.Add(item);
//Unselect all
lstRegistryValues.SelectedIndices.Clear();
item.Selected = true;
lstRegistryKeys.LabelEdit = true;
lstRegistryValues.LabelEdit = true;
item.BeginEdit();
}
else
@ -322,31 +265,21 @@ namespace xServer.Forms
}
}
public void DeleteValueFromList(string keyPath, string valueName)
public void DeleteValue(string keyPath, string valueName)
{
TreeNode key = GetTreeNode(keyPath);
if (key != null)
{
lstRegistryKeys.Invoke((MethodInvoker)delegate
lstRegistryValues.Invoke((MethodInvoker)delegate
{
List<RegValueData> ValuesFromNode = null;
if (key.Tag != null && key.Tag.GetType() == typeof(RegValueData[]))
{
ValuesFromNode = ((RegValueData[])key.Tag).ToList();
ValuesFromNode.RemoveAll(value => value.Name == valueName);
key.Tag = ValuesFromNode.ToArray();
}
else
{
//Tag has incorrect element or is missing data
key.Tag = new RegValueData[] {};
}
//Remove the values that have the specified name
key.Tag = ((RegValueData[])key.Tag).Where(value => value.Name != valueName).ToArray();
if (tvRegistryDirectory.SelectedNode == key)
{
valueName = String.IsNullOrEmpty(valueName) ? DEFAULT_REG_VALUE : valueName;
lstRegistryKeys.Items.RemoveByKey(valueName);
lstRegistryValues.Items.RemoveByKey(valueName);
}
else
{
@ -357,90 +290,74 @@ namespace xServer.Forms
}
}
public void RenameValueFromList(string keyPath, string oldName, string newName)
public void RenameValue(string keyPath, string oldName, string newName)
{
TreeNode key = GetTreeNode(keyPath);
if (key != null)
{
lstRegistryKeys.Invoke((MethodInvoker)delegate
lstRegistryValues.Invoke((MethodInvoker)delegate
{
//Can only rename if the value exists in the tag
if (key.Tag != null && key.Tag.GetType() == typeof(RegValueData[]))
{
List<RegValueData> ValuesFromNode = ((RegValueData[])key.Tag).ToList();
var value = ValuesFromNode.Find(item => item.Name == oldName);
value.Name = newName;
var value = ((RegValueData[])key.Tag).First(item => item.Name == oldName);
value.Name = newName;
if (tvRegistryDirectory.SelectedNode == key)
if (tvRegistryDirectory.SelectedNode == key)
{
var valueItem = lstRegistryValues.Items[oldName] as RegistryValueLstItem;
if (valueItem != null)
{
var index = lstRegistryKeys.Items.IndexOfKey(oldName);
if (index != -1)
{
RegistryValueLstItem valueItem = (RegistryValueLstItem)lstRegistryKeys.Items[index];
valueItem.RegName = newName;
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
valueItem.RegName = newName;
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
});
}
}
public void ChangeValueFromList(string keyPath, RegValueData value)
public void ChangeValue(string keyPath, RegValueData value)
{
TreeNode key = GetTreeNode(keyPath);
if (key != null)
{
lstRegistryKeys.Invoke((MethodInvoker)delegate
lstRegistryValues.Invoke((MethodInvoker)delegate
{
//Can only change if the value exists in the tag
if (key.Tag != null && key.Tag.GetType() == typeof(RegValueData[]))
{
List<RegValueData> ValuesFromNode = ((RegValueData[])key.Tag).ToList();
var regValue = ValuesFromNode.Find(item => item.Name == value.Name);
regValue.Data = value.Data;
var regValue = ((RegValueData[])key.Tag).First(item => item.Name == value.Name);
regValue.Data = value.Data;
if (tvRegistryDirectory.SelectedNode == key)
if (tvRegistryDirectory.SelectedNode == key)
{
//Make sure if it is a default value
string name = String.IsNullOrEmpty(value.Name) ? DEFAULT_REG_VALUE : value.Name;
var valueItem = lstRegistryValues.Items[name] as RegistryValueLstItem;
if (valueItem != null)
{
//Make sure if it is a default value
string name = String.IsNullOrEmpty(value.Name) ? DEFAULT_REG_VALUE : value.Name;
var index = lstRegistryKeys.Items.IndexOfKey(name);
if (index != -1)
{
RegistryValueLstItem valueItem = (RegistryValueLstItem)lstRegistryKeys.Items[index];
valueItem.Data = value.Kind.RegistryTypeToString(value.Data);;
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
valueItem.Data = value.Kind.RegistryTypeToString(value.Data);;
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
});
}
}
private void UpdateLstRegistryKeys(TreeNode node)
private void UpdateLstRegistryValues(TreeNode node)
{
selectedStripStatusLabel.Text = node.FullPath;
RegValueData[] ValuesFromNode = null;
if (node.Tag != null && node.Tag.GetType() == typeof(RegValueData[]))
{
ValuesFromNode = (RegValueData[])node.Tag;
}
RegValueData[] ValuesFromNode = (RegValueData[])node.Tag;
PopulateLstRegistryKeys(ValuesFromNode);
PopulateLstRegistryValues(ValuesFromNode);
}
private void PopulateLstRegistryKeys(RegValueData[] values)
private void PopulateLstRegistryValues(RegValueData[] values)
{
lstRegistryKeys.Items.Clear();
lstRegistryValues.Items.Clear();
// Make sure that the passed values are usable
if (values != null && values.Length > 0)
@ -450,7 +367,7 @@ namespace xServer.Forms
string kind = value.Kind.RegistryTypeToString();
string data = value.Kind.RegistryTypeToString(value.Data);
RegistryValueLstItem item = new RegistryValueLstItem(value.Name, kind, data);
lstRegistryKeys.Items.Add(item);
lstRegistryValues.Items.Add(item);
}
}
}
@ -461,31 +378,25 @@ namespace xServer.Forms
private void tvRegistryDirectory_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
//No need to edit if it is null
if (e.Label != null)
{
//Prevent the change of the label
e.CancelEdit = true;
if (e.Label.Length > 0)
{
if (e.Node.Parent.Nodes.ContainsKey(e.Label))
{
//Prompt error
MessageBox.Show("Invalid label. \nA node with that label already exists.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
e.Node.BeginEdit();
}
else
{
//Normal rename action
//Perform Rename action
new xServer.Core.Packets.ServerPackets.DoRenameRegistryKey(e.Node.Parent.FullPath, e.Node.Name, e.Label).Execute(_connectClient);
tvRegistryDirectory.LabelEdit = false;
}
}
else
{
//Prompt error
MessageBox.Show("Invalid label. \nThe label cannot be blank.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
e.Node.BeginEdit();
}
@ -499,7 +410,6 @@ namespace xServer.Forms
private void tvRegistryDirectory_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
// Before expansion of the node, prepare the first node with RegistryKeys.
TreeNode parentNode = e.Node;
// If nothing is there (yet).
@ -508,32 +418,24 @@ namespace xServer.Forms
tvRegistryDirectory.SuspendLayout();
parentNode.Nodes.Clear();
// Send a packet to retrieve the data to use for the nodes.
new xServer.Core.Packets.ServerPackets.DoLoadRegistryKey(parentNode.FullPath).Execute(_connectClient);
tvRegistryDirectory.ResumeLayout();
//Cancel expand
e.Cancel = true;
}
}
private void tvRegistryDirectory_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (tvRegistryDirectory.SelectedNode != e.Node)
{
//Select the clicked node
tvRegistryDirectory.SelectedNode = e.Node;
//Activate sorting
lstRegistryKeys.Sorting = SortOrder.Ascending;
}
/* Enable delete and rename if not root node */
SetDeleteAndRename(tvRegistryDirectory.SelectedNode.Parent != null);
//Check if right click, and if so provide the contrext menu
if (e.Button == MouseButtons.Right)
{
//Bug fix with rightclick not working for selectednode
tvRegistryDirectory.SelectedNode = e.Node;
//Display the context menu
Point pos = new Point(e.X, e.Y);
CreateTreeViewMenuStrip();
tv_ContextMenuStrip.Show(tvRegistryDirectory, pos);
}
}
@ -542,13 +444,16 @@ namespace xServer.Forms
{
if (e.Node != null)
{
UpdateLstRegistryKeys(e.Node);
//Activate sorting (Make sure to sort values correctly)
lstRegistryValues.Sorting = SortOrder.Ascending;
UpdateLstRegistryValues(e.Node);
}
}
private void tvRegistryDirectory_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
if (e.KeyCode == Keys.Delete && GetDeleteState())
{
deleteRegistryKey_Click(this, e);
}
@ -556,30 +461,59 @@ namespace xServer.Forms
#endregion
#region ToolStrip Helpfunctions
#region ToolStrip and Contextmenu Helpfunctions
public void SetDeleteAndRename(bool enable)
private void CreateEditToolStrip()
{
this.deleteToolStripMenuItem.Enabled = enable;
this.renameToolStripMenuItem.Enabled = enable;
this.deleteToolStripMenuItem2.Enabled = enable;
this.renameToolStripMenuItem2.Enabled = enable;
this.modifyToolStripMenuItem1.Visible =
this.modifyBinaryDataToolStripMenuItem1.Visible =
this.modifyNewtoolStripSeparator.Visible = lstRegistryValues.Focused;
this.modifyToolStripMenuItem1.Enabled =
this.modifyBinaryDataToolStripMenuItem1.Enabled = lstRegistryValues.SelectedItems.Count == 1;
this.renameToolStripMenuItem2.Enabled = GetRenameState();
this.deleteToolStripMenuItem2.Enabled = GetDeleteState();
}
private void CreateTreeViewMenuStrip()
{
this.renameToolStripMenuItem.Enabled = tvRegistryDirectory.SelectedNode.Parent != null;
this.deleteToolStripMenuItem.Enabled = tvRegistryDirectory.SelectedNode.Parent != null;
}
private void CreateListViewMenuStrip()
{
this.modifyToolStripMenuItem.Enabled =
this.modifyBinaryDataToolStripMenuItem.Enabled = lstRegistryValues.SelectedItems.Count == 1;
this.renameToolStripMenuItem1.Enabled = lstRegistryValues.SelectedItems.Count == 1 && !lstRegistryValues.SelectedItems.ContainsKey(DEFAULT_REG_VALUE);
this.deleteToolStripMenuItem1.Enabled = tvRegistryDirectory.SelectedNode != null && lstRegistryValues.SelectedItems.Count > 0;
}
#endregion
#region MenuStrip Action
private void editToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
CreateEditToolStrip();
}
private void menuStripExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void menuStripDelete_Click(object sender, EventArgs e) {
if(tvRegistryDirectory.Focused) {
if(tvRegistryDirectory.Focused)
{
deleteRegistryKey_Click(this, e);
}
else if (lstRegistryKeys.Focused) {
else if (lstRegistryValues.Focused)
{
deleteRegistryValue_Click(this, e);
}
}
@ -590,7 +524,7 @@ namespace xServer.Forms
{
renameRegistryKey_Click(this, e);
}
else if (lstRegistryKeys.Focused)
else if (lstRegistryValues.Focused)
{
renameRegistryValue_Click(this, e);
}
@ -605,16 +539,18 @@ namespace xServer.Forms
if (e.Button == MouseButtons.Right)
{
Point pos = new Point(e.X, e.Y);
//Try to check if a item was clicked
if (lstRegistryKeys.GetItemAt(pos.X, pos.Y) == null)
if (lstRegistryValues.GetItemAt(pos.X, pos.Y) == null)
{
//Not on a item
lst_ContextMenuStrip.Show(lstRegistryKeys, pos);
lst_ContextMenuStrip.Show(lstRegistryValues, pos);
}
else
{
//Clicked on a item
selectedItem_ContextMenuStrip.Show(lstRegistryKeys, pos);
CreateListViewMenuStrip();
selectedItem_ContextMenuStrip.Show(lstRegistryValues, pos);
}
}
}
@ -623,127 +559,80 @@ namespace xServer.Forms
{
if (e.Label != null && tvRegistryDirectory.SelectedNode != null)
{
//Prevent the change of the label
e.CancelEdit = true;
int index = e.Item;
if (e.Label.Length > 0)
{
if (lstRegistryKeys.Items.ContainsKey(e.Label))
if (lstRegistryValues.Items.ContainsKey(e.Label))
{
//Prompt error
MessageBox.Show("Invalid label. \nA node with that label already exists.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lstRegistryKeys.Items[index].BeginEdit();
lstRegistryValues.Items[index].BeginEdit();
return;
}
//Normal rename action
//Perform Rename action
new xServer.Core.Packets.ServerPackets.DoRenameRegistryValue(tvRegistryDirectory.SelectedNode.FullPath, lstRegistryKeys.Items[index].Name, e.Label).Execute(_connectClient);
new xServer.Core.Packets.ServerPackets.DoRenameRegistryValue(tvRegistryDirectory.SelectedNode.FullPath, lstRegistryValues.Items[index].Name, e.Label).Execute(_connectClient);
lstRegistryKeys.LabelEdit = false;
lstRegistryValues.LabelEdit = false;
}
else
{
//Prompt error
MessageBox.Show("Invalid label. \nThe label cannot be blank.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lstRegistryKeys.Items[index].BeginEdit();
lstRegistryValues.Items[index].BeginEdit();
}
}
else
{
lstRegistryKeys.LabelEdit = false;
lstRegistryValues.LabelEdit = false;
}
}
private void lstRegistryKeys_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
modifyToolStripMenuItem.Enabled = lstRegistryKeys.SelectedItems.Count == 1;
modifyToolStripMenuItem1.Enabled = lstRegistryKeys.SelectedItems.Count == 1;
modifyBinaryDataToolStripMenuItem.Enabled = lstRegistryKeys.SelectedItems.Count == 1;
modifyBinaryDataToolStripMenuItem1.Enabled = lstRegistryKeys.SelectedItems.Count == 1;
//Make sure that only one item selected and that the item is not a default
renameToolStripMenuItem1.Enabled = lstRegistryKeys.SelectedItems.Count == 1 && e.Item.Name != DEFAULT_REG_VALUE;
renameToolStripMenuItem2.Enabled = lstRegistryKeys.SelectedItems.Count == 1 && e.Item.Name != DEFAULT_REG_VALUE;
deleteToolStripMenuItem2.Enabled = lstRegistryKeys.SelectedItems.Count > 0;
}
private void lstRegistryKeys_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
if (e.KeyCode == Keys.Delete && GetDeleteState())
{
deleteRegistryValue_Click(this, e);
}
}
private void lstRegistryKeys_Enter(object sender, EventArgs e)
{
/* Make the modifers visible */
modifyNewtoolStripSeparator.Visible = true;
modifyToolStripMenuItem1.Visible = true;
modifyBinaryDataToolStripMenuItem1.Visible = true;
}
private void lstRegistryKeys_Leave(object sender, EventArgs e)
{
/* Disable the modify functions (only avaliable for registry values) */
modifyNewtoolStripSeparator.Visible = false;
modifyToolStripMenuItem1.Visible = false;
modifyBinaryDataToolStripMenuItem1.Visible = false;
}
#endregion
#region ContextMenu
private void createNewRegistryKey_Click(object sender, EventArgs e)
{
if (tvRegistryDirectory.SelectedNode != null)
if (!(tvRegistryDirectory.SelectedNode.IsExpanded) && tvRegistryDirectory.SelectedNode.Nodes.Count > 0)
{
if (!(tvRegistryDirectory.SelectedNode.IsExpanded) && tvRegistryDirectory.SelectedNode.Nodes.Count > 0)
{
//Subscribe (wait for node to expand)
tvRegistryDirectory.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.createRegistryKey_AfterExpand);
tvRegistryDirectory.SelectedNode.Expand();
}
else
{
//Try to create a new subkey
new xServer.Core.Packets.ServerPackets.DoCreateRegistryKey(tvRegistryDirectory.SelectedNode.FullPath).Execute(_connectClient);
}
//Subscribe (wait for node to expand)
tvRegistryDirectory.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.createRegistryKey_AfterExpand);
tvRegistryDirectory.SelectedNode.Expand();
}
else
{
new xServer.Core.Packets.ServerPackets.DoCreateRegistryKey(tvRegistryDirectory.SelectedNode.FullPath).Execute(_connectClient);
}
}
private void deleteRegistryKey_Click(object sender, EventArgs e)
{
if (tvRegistryDirectory.SelectedNode != null && tvRegistryDirectory.SelectedNode.Parent != null)
//Prompt user to confirm delete
string msg = "Are you sure you want to permanently delete this key and all of its subkeys?";
string caption = "Confirm Key Delete";
var answer = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (answer == DialogResult.Yes)
{
//Prompt user to confirm delete
string msg = "Are you sure you want to permanently delete this key and all of its subkeys?";
string caption = "Confirm Key Delete";
var answer = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
string parentPath = tvRegistryDirectory.SelectedNode.Parent.FullPath;
if (answer == DialogResult.Yes)
{
string parentPath = tvRegistryDirectory.SelectedNode.Parent.FullPath;
new xServer.Core.Packets.ServerPackets.DoDeleteRegistryKey(parentPath, tvRegistryDirectory.SelectedNode.Name).Execute(_connectClient);
}
new xServer.Core.Packets.ServerPackets.DoDeleteRegistryKey(parentPath, tvRegistryDirectory.SelectedNode.Name).Execute(_connectClient);
}
}
private void renameRegistryKey_Click(object sender, EventArgs e)
{
if (tvRegistryDirectory.SelectedNode != null && tvRegistryDirectory.SelectedNode.Parent != null)
{
tvRegistryDirectory.LabelEdit = true;
tvRegistryDirectory.SelectedNode.BeginEdit();
}
tvRegistryDirectory.LabelEdit = true;
tvRegistryDirectory.SelectedNode.BeginEdit();
}
#region New Registry Value
@ -808,21 +697,19 @@ namespace xServer.Forms
private void deleteRegistryValue_Click(object sender, EventArgs e)
{
if(tvRegistryDirectory.SelectedNode != null && lstRegistryKeys.SelectedItems.Count > 0) {
//Prompt user to confirm delete
string msg = "Deleting certain registry values could cause system instability. Are you sure you want to permanently delete " + (lstRegistryKeys.SelectedItems.Count == 1 ? "this value?": "these values?");
string caption = "Confirm Value Delete";
var answer = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
//Prompt user to confirm delete
string msg = "Deleting certain registry values could cause system instability. Are you sure you want to permanently delete " + (lstRegistryValues.SelectedItems.Count == 1 ? "this value?": "these values?");
string caption = "Confirm Value Delete";
var answer = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (answer == DialogResult.Yes)
if (answer == DialogResult.Yes)
{
foreach (var item in lstRegistryValues.SelectedItems)
{
foreach (var item in lstRegistryKeys.SelectedItems)
if (item.GetType() == typeof(RegistryValueLstItem))
{
if (item.GetType() == typeof(RegistryValueLstItem))
{
RegistryValueLstItem registyValue = (RegistryValueLstItem)item;
new xServer.Core.Packets.ServerPackets.DoDeleteRegistryValue(tvRegistryDirectory.SelectedNode.FullPath, registyValue.RegName).Execute(_connectClient);
}
RegistryValueLstItem registyValue = (RegistryValueLstItem)item;
new xServer.Core.Packets.ServerPackets.DoDeleteRegistryValue(tvRegistryDirectory.SelectedNode.FullPath, registyValue.RegName).Execute(_connectClient);
}
}
}
@ -830,56 +717,18 @@ namespace xServer.Forms
private void renameRegistryValue_Click(object sender, EventArgs e)
{
if (tvRegistryDirectory.SelectedNode != null && lstRegistryKeys.SelectedItems.Count == 1)
{
//Before edit make sure that it is not a default registry value
if (lstRegistryKeys.SelectedItems[0].Name != DEFAULT_REG_VALUE)
{
lstRegistryKeys.LabelEdit = true;
lstRegistryKeys.SelectedItems[0].BeginEdit();
}
}
lstRegistryValues.LabelEdit = true;
lstRegistryValues.SelectedItems[0].BeginEdit();
}
private void modifyRegistryValue_Click(object sender, EventArgs e)
{
if (tvRegistryDirectory.SelectedNode != null && lstRegistryKeys.SelectedItems.Count == 1)
{
if (tvRegistryDirectory.SelectedNode.Tag != null && tvRegistryDirectory.SelectedNode.Tag.GetType() == typeof(RegValueData[]))
{
string keyPath = tvRegistryDirectory.SelectedNode.FullPath;
string name = lstRegistryKeys.SelectedItems[0].Name == DEFAULT_REG_VALUE ? "" : lstRegistryKeys.SelectedItems[0].Name;
RegValueData value = ((RegValueData[])tvRegistryDirectory.SelectedNode.Tag).ToList().Find(item => item.Name == name);
//Initialize the right form to allow editing
using (var frm = GetEditForm(keyPath, value, value.Kind))
{
if(frm != null)
frm.ShowDialog();
}
}
}
CreateModifyForm(false);
}
private void modifyBinaryDataRegistryValue_Click(object sender, EventArgs e)
{
if (tvRegistryDirectory.SelectedNode != null && lstRegistryKeys.SelectedItems.Count == 1)
{
if (tvRegistryDirectory.SelectedNode.Tag != null && tvRegistryDirectory.SelectedNode.Tag.GetType() == typeof(RegValueData[]))
{
string keyPath = tvRegistryDirectory.SelectedNode.FullPath;
string name = lstRegistryKeys.SelectedItems[0].Name == DEFAULT_REG_VALUE ? "" : lstRegistryKeys.SelectedItems[0].Name;
RegValueData value = ((RegValueData[])tvRegistryDirectory.SelectedNode.Tag).ToList().Find(item => item.Name == name);
//Initialize binary editor
using (var frm = GetEditForm(keyPath, value, RegistryValueKind.Binary))
{
if (frm != null)
frm.ShowDialog();
}
}
}
CreateModifyForm(true);
}
#endregion
@ -892,33 +741,34 @@ namespace xServer.Forms
{
if (e.Node == tvRegistryDirectory.SelectedNode)
{
//Trigger a click
createNewRegistryKey_Click(this, e);
//Unsubscribe
tvRegistryDirectory.AfterExpand -= new System.Windows.Forms.TreeViewEventHandler(this.createRegistryKey_AfterExpand);
}
}
//A special case for when the node was empty and add was performed before expand
private void specialCreateRegistryKey_AfterExpand(object sender, TreeViewEventArgs e)
{
if (e.Node == tvRegistryDirectory.SelectedNode)
{
tvRegistryDirectory.SelectedNode = tvRegistryDirectory.SelectedNode.FirstNode;
tvRegistryDirectory.LabelEdit = true;
tvRegistryDirectory.SelectedNode.BeginEdit();
//Unsubscribe
tvRegistryDirectory.AfterExpand -= new System.Windows.Forms.TreeViewEventHandler(this.specialCreateRegistryKey_AfterExpand);
}
}
#endregion
#region Help function
private bool GetDeleteState()
{
if (lstRegistryValues.Focused)
return lstRegistryValues.SelectedItems.Count > 0;
else if (tvRegistryDirectory.Focused && tvRegistryDirectory.SelectedNode != null)
return tvRegistryDirectory.SelectedNode.Parent != null;
return false;
}
private bool GetRenameState()
{
if (lstRegistryValues.Focused)
return lstRegistryValues.SelectedItems.Count == 1 && !lstRegistryValues.SelectedItems.ContainsKey(DEFAULT_REG_VALUE);
else if (tvRegistryDirectory.Focused && tvRegistryDirectory.SelectedNode != null)
return tvRegistryDirectory.SelectedNode.Parent != null;
return false;
}
private Form GetEditForm(string keyPath, RegValueData value, RegistryValueKind valueKind)
{
switch (valueKind)
@ -938,6 +788,21 @@ namespace xServer.Forms
}
}
private void CreateModifyForm(bool isBinary)
{
string keyPath = tvRegistryDirectory.SelectedNode.FullPath;
string name = lstRegistryValues.SelectedItems[0].Name == DEFAULT_REG_VALUE ? "" : lstRegistryValues.SelectedItems[0].Name;
RegValueData value = ((RegValueData[])tvRegistryDirectory.SelectedNode.Tag).ToList().Find(item => item.Name == name);
RegistryValueKind kind = isBinary ? RegistryValueKind.Binary : value.Kind;
using (var frm = GetEditForm(keyPath, value, kind))
{
if (frm != null)
frm.ShowDialog();
}
}
#endregion
}

View File

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