Merge pull request #449 from LjungErik/master

Updated Registry Editor
This commit is contained in:
MaxXor 2016-04-24 20:21:33 +02:00
commit 9cd5f6abfa
24 changed files with 903 additions and 988 deletions

View File

@ -7,6 +7,7 @@ using xClient.Core.Registry;
using xClient.Core.Extensions;
using Microsoft.Win32;
using System.Threading;
using xClient.Core.Helper;
namespace xClient.Core.Commands
{
@ -64,7 +65,7 @@ namespace xClient.Core.Commands
}
responsePacket.ErrorMsg = errorMsg;
responsePacket.Match = new RegSeekerMatch(newKeyName, null, 0);
responsePacket.Match = new RegSeekerMatch(newKeyName, RegistryKeyHelper.GetDefaultValues(), 0);
responsePacket.ParentPath = packet.ParentPath;
responsePacket.Execute(client);

View File

@ -1,11 +1,16 @@
using System;
using System.Linq;
using Microsoft.Win32;
using xClient.Core.Extensions;
using xClient.Core.Registry;
using System.Collections.Generic;
namespace xClient.Core.Helper
{
public static class RegistryKeyHelper
{
private static string DEFAULT_VALUE = String.Empty;
/// <summary>
/// Adds a value to the registry key.
/// </summary>
@ -77,5 +82,44 @@ namespace xClient.Core.Helper
return false;
}
}
/// <summary>
/// Checks if the provided value is the default value
/// </summary>
/// <param name="valueName">The name of the value</param>
/// <returns>True if default value, else False</returns>
public static bool IsDefaultValue(string valueName)
{
return String.IsNullOrEmpty(valueName);
}
/// <summary>
/// Adds the default value to the list of values and returns them as an array.
/// If default value already exists this function will only return the list as an array.
/// </summary>
/// <param name="values">The list with the values for which the default value should be added to</param>
/// <returns>Array with all of the values including the default value</returns>
public static RegValueData[] AddDefaultValue(List<RegValueData> values)
{
if(!values.Any(value => IsDefaultValue(value.Name)))
{
values.Add(GetDefaultValue());
}
return values.ToArray();
}
/// <summary>
/// Gets the default registry values
/// </summary>
/// <returns>A array with the default registry values</returns>
public static RegValueData[] GetDefaultValues()
{
return new RegValueData[] { GetDefaultValue() };
}
private static RegValueData GetDefaultValue()
{
return new RegValueData(DEFAULT_VALUE, RegistryValueKind.String, null);
}
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using xClient.Core.Extensions;
using xClient.Core.Helper;
namespace xClient.Core.Registry
{
@ -308,7 +309,6 @@ namespace xClient.Core.Registry
{
try
{
RegistryKey key = GetWritableRegistryKey(keyPath);
//Invalid can not open key
@ -369,8 +369,8 @@ namespace xClient.Core.Registry
return false;
}
//Value does not exist
if (!key.ContainsValue(value.Name))
//Is not default value and does not exist
if (!RegistryKeyHelper.IsDefaultValue(value.Name) && !key.ContainsValue(value.Name))
{
errorMsg = "The value: " + value.Name + " does not exist in: " + keyPath;
return false;

View File

@ -5,6 +5,7 @@ using System.Security;
using Microsoft.Win32;
using System.Threading;
using xClient.Core.Extensions;
using xClient.Core.Helper;
namespace xClient.Core.Registry
{
@ -123,11 +124,11 @@ namespace xClient.Core.Registry
values.Add(new RegValueData(valueName, valueType, valueData));
}
AddMatch(keyName, values.ToArray(), key.SubKeyCount);
AddMatch(keyName, RegistryKeyHelper.AddDefaultValue(values), key.SubKeyCount);
}
else
{
AddMatch(keyName, null, 0);
AddMatch(keyName, RegistryKeyHelper.GetDefaultValues(), 0);
}
}
@ -139,9 +140,9 @@ namespace xClient.Core.Registry
matches.Add(match);
}
public static RegistryKey GetRootKey(string subkey_fullpath)
public static RegistryKey GetRootKey(string subkeyFullPath)
{
string[] path = subkey_fullpath.Split('\\');
string[] path = subkeyFullPath.Split('\\');
try
{
switch (path[0]) // <== root;

View File

@ -4,41 +4,22 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using xServer.Core.Extensions;
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 class RegistryValueLstItem : ListViewItem
{
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;
}
}
internal class RegistryValueLstItem : ListViewItem
{
private string _regName { get; set; }
private string _type { get; set; }
private string _data { get; set; }
public string RegName {
get { return _regName; }
set
{
_regName = value;
//Handle if the given value is for a null registry value (default value)
//Display (Default) not empty string
this.Name = String.IsNullOrEmpty(value) ? "(Default)" : value;
this.Text = String.IsNullOrEmpty(value) ? "(Default)" : value;
get { return this.Name; }
set
{
this.Name = value;
this.Text = RegValueHelper.GetName(value);
}
}
public string Type {
@ -46,7 +27,13 @@ namespace xServer.Controls
set
{
_type = value;
this.ImageIndex = GetRegistryValueImgIndex(value);
if (this.SubItems.Count < 2)
this.SubItems.Add(_type);
else
this.SubItems[1].Text = _type;
this.ImageIndex = GetRegistryValueImgIndex(_type);
}
}
@ -54,23 +41,21 @@ namespace xServer.Controls
get { return _data; }
set
{
//Hardcoded that the data is the second column
if (this.SubItems.Count == 3)
{
this.SubItems[2].Text = value;
_data = value;
}
_data = value;
if (this.SubItems.Count < 3)
this.SubItems.Add(_data);
else
this.SubItems[2].Text = _data;
}
}
public RegistryValueLstItem(string name, string type, string data) :
public RegistryValueLstItem(RegValueData value) :
base()
{
RegName = name;
this.SubItems.Add(type);
Type = type;
this.SubItems.Add(data);
Data = data;
RegName = value.Name;
Type = value.Kind.RegistryTypeToString();
Data = value.Kind.RegistryTypeToString(value.Data);
}
private int GetRegistryValueImgIndex(string type)

36
Server/Controls/WordTextBox.Designer.cs generated Normal file
View File

@ -0,0 +1,36 @@
namespace xServer.Controls
{
partial class WordTextBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using xServer.Enums;
namespace xServer.Controls
{
public partial class WordTextBox : TextBox
{
private bool isHexNumber;
private WordType type;
public override int MaxLength
{
get
{
return base.MaxLength;
}
set { }
}
public bool IsHexNumber
{
get { return isHexNumber; }
set
{
if (isHexNumber == value)
return;
if(value)
{
if (Type == WordType.DWORD)
Text = UIntValue.ToString("x");
else
Text = ULongValue.ToString("x");
}
else
{
if (Type == WordType.DWORD)
Text = UIntValue.ToString();
else
Text = ULongValue.ToString();
}
isHexNumber = value;
UpdateMaxLength();
}
}
public WordType Type
{
get { return type; }
set
{
if (type == value)
return;
type = value;
UpdateMaxLength();
}
}
public uint UIntValue
{
get
{
try
{
if (String.IsNullOrEmpty(Text))
return 0;
else if (IsHexNumber)
return UInt32.Parse(Text, NumberStyles.HexNumber);
else
return UInt32.Parse(Text);
}
catch (Exception)
{
return UInt32.MaxValue;
}
}
}
public ulong ULongValue
{
get
{
try
{
if (String.IsNullOrEmpty(Text))
return 0;
else if (IsHexNumber)
return UInt64.Parse(Text, NumberStyles.HexNumber);
else
return UInt64.Parse(Text);
}
catch (Exception)
{
return UInt64.MaxValue;
}
}
}
public bool IsConversionValid()
{
if (String.IsNullOrEmpty(Text))
return true;
if (!IsHexNumber)
{
return ConvertToHex();
}
return true;
}
public WordTextBox()
{
InitializeComponent();
base.MaxLength = 8;
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
e.Handled = !IsValidChar(e.KeyChar);
}
private bool IsValidChar(char ch)
{
return (Char.IsControl(ch) ||
Char.IsDigit(ch) ||
(IsHexNumber && Char.IsLetter(ch) && Char.ToLower(ch) <= 'f'));
}
private void UpdateMaxLength()
{
if(Type == WordType.DWORD)
{
if (IsHexNumber)
base.MaxLength = 8;
else
base.MaxLength = 10;
}
else
{
if (IsHexNumber)
base.MaxLength = 16;
else
base.MaxLength = 20;
}
}
private bool ConvertToHex()
{
try
{
if (Type == WordType.DWORD)
UInt32.Parse(Text);
else
UInt64.Parse(Text);
return true;
}
catch (Exception)
{
return false;
}
}
}
}

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

@ -10,6 +10,9 @@ namespace xServer.Core.Extensions
{
public static string RegistryTypeToString(this RegistryValueKind valueKind, object valueData)
{
if (valueData == null)
return "(value not set)";
switch (valueKind)
{
case RegistryValueKind.Binary:

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace xServer.Core.Registry
{
public class RegValueHelper
{
private static string DEFAULT_REG_VALUE = "(Default)";
public static bool IsDefaultValue(string valueName)
{
return String.IsNullOrEmpty(valueName);
}
public static string GetName(string valueName)
{
return IsDefaultValue(valueName) ? DEFAULT_REG_VALUE : valueName;
}
}
}

View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace xServer.Core.Utilities
{
public class ByteConverter
{
private static byte NULL_BYTE = byte.MinValue;
public static byte[] GetBytes(int value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(long value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(uint value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(ulong value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(string value)
{
return StringToBytes(value);
}
public static byte[] GetBytes(string[] value)
{
return StringArrayToBytes(value);
}
public static int ToInt32(byte[] bytes)
{
return BitConverter.ToInt32(bytes, 0);
}
public static long ToInt64(byte[] bytes)
{
return BitConverter.ToInt64(bytes, 0);
}
public static uint ToUInt32(byte[] bytes)
{
return BitConverter.ToUInt32(bytes, 0);
}
public static ulong ToUInt64(byte[] bytes)
{
return BitConverter.ToUInt64(bytes, 0);
}
public static string ToString(byte[] bytes)
{
return BytesToString(bytes);
}
public static string[] ToStringArray(byte[] bytes)
{
return BytesToStringArray(bytes);
}
private static byte[] GetNullBytes()
{
//Null bytes: 00 00
return new byte[] { NULL_BYTE, NULL_BYTE };
}
private static byte[] StringToBytes(string value)
{
byte[] bytes = new byte[value.Length * sizeof(char)];
Buffer.BlockCopy(value.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
private static byte[] StringArrayToBytes(string[] strings)
{
List<byte> bytes = new List<byte>();
foreach(string str in strings)
{
bytes.AddRange(StringToBytes(str));
bytes.AddRange(GetNullBytes());
}
return bytes.ToArray();
}
private static string BytesToString(byte[] bytes)
{
int nrChars = (int)Math.Ceiling((float)bytes.Length / (float)sizeof(char));
char[] chars = new char[nrChars];
Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
return new string(chars);
}
private static string[] BytesToStringArray(byte[] bytes)
{
List<string> strings = new List<string>();
int i = 0;
StringBuilder strBuilder = new StringBuilder(bytes.Length);
while (i < bytes.Length)
{
//Holds the number of nulls (3 nulls indicated end of a string)
int nullcount = 0;
while (i < bytes.Length && nullcount < 3)
{
if (bytes[i] == NULL_BYTE)
{
nullcount++;
}
else
{
strBuilder.Append(Convert.ToChar(bytes[i]));
nullcount = 0;
}
i++;
}
strings.Add(strBuilder.ToString());
strBuilder.Clear();
}
return strings.ToArray();
}
}
}

13
Server/Enums/WordType.cs Normal file
View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace xServer.Enums
{
public enum WordType
{
DWORD,
QWORD
}
}

View File

@ -31,11 +31,9 @@
this.valueNameTxtBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.hexEditor = new xServer.Controls.HexEditor.HexEditor();
this.flowLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// valueNameTxtBox
@ -45,7 +43,7 @@
this.valueNameTxtBox.Name = "valueNameTxtBox";
this.valueNameTxtBox.ReadOnly = true;
this.valueNameTxtBox.Size = new System.Drawing.Size(341, 20);
this.valueNameTxtBox.TabIndex = 5;
this.valueNameTxtBox.TabIndex = 3;
//
// label1
//
@ -56,7 +54,6 @@
this.label1.Location = new System.Drawing.Point(9, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Value name:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@ -69,42 +66,27 @@
this.label2.Location = new System.Drawing.Point(9, 54);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.TabIndex = 6;
this.label2.Text = "Value data:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flowLayoutPanel1.Controls.Add(this.cancelButton);
this.flowLayoutPanel1.Controls.Add(this.okButton);
this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 270);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.flowLayoutPanel1.Size = new System.Drawing.Size(341, 29);
this.flowLayoutPanel1.TabIndex = 8;
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(263, 3);
this.cancelButton.Location = new System.Drawing.Point(278, 273);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 4;
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// okButton
//
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.okButton.Location = new System.Drawing.Point(182, 3);
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(197, 273);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 5;
this.okButton.TabIndex = 1;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
@ -120,7 +102,7 @@
this.hexEditor.Margin = new System.Windows.Forms.Padding(0, 2, 3, 3);
this.hexEditor.Name = "hexEditor";
this.hexEditor.Size = new System.Drawing.Size(341, 196);
this.hexEditor.TabIndex = 6;
this.hexEditor.TabIndex = 0;
this.hexEditor.VScrollBarVisisble = true;
//
// FrmRegValueEditBinary
@ -130,8 +112,9 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(365, 304);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.hexEditor);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.label2);
this.Controls.Add(this.valueNameTxtBox);
this.Controls.Add(this.label1);
@ -141,8 +124,6 @@
this.Name = "FrmRegValueEditBinary";
this.ShowIcon = false;
this.Text = "Edit Binary";
this.Load += new System.EventHandler(this.FrmRegValueEditBinary_Load);
this.flowLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -153,7 +134,6 @@
private System.Windows.Forms.TextBox valueNameTxtBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private Controls.HexEditor.HexEditor hexEditor;

View File

@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using xServer.Core.Networking;
using xServer.Core.Registry;
using xServer.Core.Utilities;
namespace xServer.Forms
{
@ -34,175 +35,77 @@ namespace xServer.Forms
InitializeComponent();
this.valueNameTxtBox.Text = value.Name;
this.valueNameTxtBox.Text = RegValueHelper.GetName(value.Name);
if (value.Kind == Microsoft.Win32.RegistryValueKind.Binary)
if(value.Data == null)
{
hexEditor.HexTable = (byte[])value.Data;
hexEditor.HexTable = new byte[] { };
}
else if (value.Kind == Microsoft.Win32.RegistryValueKind.DWord)
{
hexEditor.HexTable = BitConverter.GetBytes((uint)(int)value.Data);
}
else if (value.Kind == Microsoft.Win32.RegistryValueKind.QWord)
{
hexEditor.HexTable = BitConverter.GetBytes((ulong)(long)value.Data);
}
else if (value.Kind == Microsoft.Win32.RegistryValueKind.String || value.Kind == Microsoft.Win32.RegistryValueKind.ExpandString)
{
//Convert string to bytes
byte[] bytes = new byte[value.Data.ToString().Length * sizeof(char)];
Buffer.BlockCopy(value.Data.ToString().ToCharArray(), 0, bytes, 0, bytes.Length);
hexEditor.HexTable = bytes;
}
else if (value.Kind == Microsoft.Win32.RegistryValueKind.MultiString)
{
byte[] bytes = MultiStringToBytes((string[])value.Data);
hexEditor.HexTable = bytes;
else {
switch(value.Kind)
{
case RegistryValueKind.Binary:
hexEditor.HexTable = (byte[])value.Data;
break;
case RegistryValueKind.DWord:
hexEditor.HexTable = ByteConverter.GetBytes((uint)(int)value.Data);
break;
case RegistryValueKind.QWord:
hexEditor.HexTable = ByteConverter.GetBytes((ulong)(long)value.Data);
break;
case RegistryValueKind.MultiString:
hexEditor.HexTable = ByteConverter.GetBytes((string[])value.Data);
break;
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
hexEditor.HexTable = ByteConverter.GetBytes(value.Data.ToString());
break;
}
}
}
private void FrmRegValueEditBinary_Load(object sender, EventArgs e)
{
hexEditor.Select();
hexEditor.Focus();
}
#region Help function
private object GetData()
{
byte[] bytes = hexEditor.HexTable;
if (bytes != null && bytes.Length > 0)
if (bytes != null)
{
try
{
if (_value.Kind == Microsoft.Win32.RegistryValueKind.Binary)
switch(_value.Kind)
{
return bytes;
}
else if (_value.Kind == Microsoft.Win32.RegistryValueKind.DWord)
{
uint unsignedValue = BitConverter.ToUInt32(hexEditor.HexTable, 0);
return (int)unsignedValue;
}
else if (_value.Kind == Microsoft.Win32.RegistryValueKind.QWord)
{
ulong unsignedValue = BitConverter.ToUInt64(hexEditor.HexTable, 0);
return (long)unsignedValue;
}
else if (_value.Kind == Microsoft.Win32.RegistryValueKind.String || _value.Kind == Microsoft.Win32.RegistryValueKind.ExpandString)
{
//Use ceiling function to make sure that the bytes fit in the char
int nrChars = (int)Math.Ceiling((float)bytes.Length / (float)sizeof(char));
char[] chars = new char[nrChars];
Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
return new string(chars);
}
else if (_value.Kind == Microsoft.Win32.RegistryValueKind.MultiString)
{
string[] strings = BytesToMultiString(hexEditor.HexTable);
return strings;
case RegistryValueKind.Binary:
return bytes;
case RegistryValueKind.DWord:
return (int)ByteConverter.ToUInt32(bytes);
case RegistryValueKind.QWord:
return (long)ByteConverter.ToUInt64(bytes);
case RegistryValueKind.MultiString:
return ByteConverter.ToStringArray(bytes);
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return ByteConverter.ToString(bytes);
}
}
catch
{
string msg = INVALID_BINARY_ERROR;
ShowWarning(msg, "Warning");
return null;
ShowWarning(INVALID_BINARY_ERROR, "Warning");
}
}
return null;
}
#endregion
#region Ok and Cancel button
private void okButton_Click(object sender, EventArgs e)
{
object valueData = GetData();
if (valueData != null)
{
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
this.Close();
}
else
DialogResult = DialogResult.None;
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region Misc
private void ShowWarning(string msg, string caption)
{
MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
/// <summary>
/// Converts the given string array to
/// a byte array.
/// </summary>
/// <param name="strings"> string array</param>
/// <returns></returns>
private byte[] MultiStringToBytes(string[] strings)
{
List<byte> ret = new List<byte>();
foreach (string str in strings)
{
byte[] bytes = new byte[str.Length * sizeof(char)];
Buffer.BlockCopy(str.ToString().ToCharArray(), 0, bytes, 0, bytes.Length);
ret.AddRange(bytes);
//Add nullbytes
ret.Add(byte.MinValue);
ret.Add(byte.MinValue);
}
return ret.ToArray();
}
/// <summary>
/// Converts a array of bytes to
/// a string array
/// </summary>
/// <param name="bytes"> array of bytes</param>
/// <returns></returns>
private string[] BytesToMultiString(byte[] bytes)
{
List<string> ret = new List<string>();
int i = 0;
while (i < bytes.Length)
{
//Holds the number of nulls (3 nulls indicated end of a string)
int nullcount = 0;
string str = "";
while (i < bytes.Length && nullcount < 3)
{
//Null byte
if (bytes[i] == byte.MinValue)
{
nullcount++;
}
else
{
str += Convert.ToChar(bytes[i]);
nullcount = 0;
}
i++;
}
ret.Add(str);
}
return ret.ToArray();
}
#endregion
}
}

View File

@ -31,11 +31,9 @@
this.valueNameTxtBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.valueDataTxtBox = new System.Windows.Forms.TextBox();
this.flowLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// valueNameTxtBox
@ -47,7 +45,7 @@
this.valueNameTxtBox.Name = "valueNameTxtBox";
this.valueNameTxtBox.ReadOnly = true;
this.valueNameTxtBox.Size = new System.Drawing.Size(346, 20);
this.valueNameTxtBox.TabIndex = 5;
this.valueNameTxtBox.TabIndex = 3;
//
// label1
//
@ -58,7 +56,6 @@
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Value name:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@ -71,41 +68,27 @@
this.label2.Location = new System.Drawing.Point(12, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.TabIndex = 6;
this.label2.Text = "Value data:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flowLayoutPanel1.Controls.Add(this.cancelButton);
this.flowLayoutPanel1.Controls.Add(this.okButton);
this.flowLayoutPanel1.Location = new System.Drawing.Point(24, 327);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.flowLayoutPanel1.Size = new System.Drawing.Size(337, 29);
this.flowLayoutPanel1.TabIndex = 8;
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(259, 3);
this.cancelButton.Location = new System.Drawing.Point(286, 330);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 4;
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(178, 3);
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(205, 330);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 5;
this.okButton.TabIndex = 1;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
@ -113,12 +96,12 @@
// valueDataTxtBox
//
this.valueDataTxtBox.AcceptsReturn = true;
this.valueDataTxtBox.Location = new System.Drawing.Point(15, 69);
this.valueDataTxtBox.Location = new System.Drawing.Point(15, 72);
this.valueDataTxtBox.Multiline = true;
this.valueDataTxtBox.Name = "valueDataTxtBox";
this.valueDataTxtBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.valueDataTxtBox.Size = new System.Drawing.Size(346, 252);
this.valueDataTxtBox.TabIndex = 9;
this.valueDataTxtBox.TabIndex = 0;
this.valueDataTxtBox.WordWrap = false;
//
// FrmRegValueEditMultiString
@ -128,8 +111,9 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(373, 365);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.valueDataTxtBox);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.okButton);
this.Controls.Add(this.label2);
this.Controls.Add(this.valueNameTxtBox);
this.Controls.Add(this.label1);
@ -139,8 +123,6 @@
this.Name = "FrmRegValueEditMultiString";
this.ShowIcon = false;
this.Text = "Edit Multi-String";
this.Load += new System.EventHandler(this.FrmRegValueEditMultiString_Load);
this.flowLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -151,7 +133,6 @@
private System.Windows.Forms.TextBox valueNameTxtBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.TextBox valueDataTxtBox;

View File

@ -19,12 +19,6 @@ namespace xServer.Forms
private readonly string _keyPath;
#region Constants
private const string WARNING_MSG = "Data of type REG_MULTI_SZ cannot contain empty strings. Registry Editor will remove the empty strings found.";
#endregion
public FrmRegValueEditMultiString(string keyPath, RegValueData value, Client c)
{
_connectClient = c;
@ -34,55 +28,15 @@ namespace xServer.Forms
InitializeComponent();
this.valueNameTxtBox.Text = value.Name;
this.valueDataTxtBox.Lines = (string[])value.Data;
this.valueDataTxtBox.Text = String.Join("\r\n",((string[])value.Data));
}
private void FrmRegValueEditMultiString_Load(object sender, EventArgs e)
{
this.valueDataTxtBox.Select();
this.valueDataTxtBox.Focus();
}
#region Ok and Cancel button
private void okButton_Click(object sender, EventArgs e)
{
string[] lines = valueDataTxtBox.Lines;
if (lines.Length > 0)
{
string[] valueData = GetSanitizedStrings(lines);
if (valueData.Length != lines.Length)
{
ShowWarning();
}
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
this.Close();
string[] valueData = valueDataTxtBox.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
private string[] GetSanitizedStrings(string[] strs)
{
List<string> sanitized = new List<string>();
foreach (string str in strs)
{
if (!String.IsNullOrWhiteSpace(str) && !String.IsNullOrEmpty(str))
{
sanitized.Add(str);
}
}
return sanitized.ToArray();
}
private void ShowWarning()
{
MessageBox.Show(WARNING_MSG, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

View File

@ -35,8 +35,6 @@
this.valueDataTxtBox = new System.Windows.Forms.TextBox();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// label1
@ -48,7 +46,6 @@
this.label1.Location = new System.Drawing.Point(9, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Value name:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@ -61,7 +58,7 @@
this.valueNameTxtBox.Name = "valueNameTxtBox";
this.valueNameTxtBox.ReadOnly = true;
this.valueNameTxtBox.Size = new System.Drawing.Size(343, 20);
this.valueNameTxtBox.TabIndex = 1;
this.valueNameTxtBox.TabIndex = 3;
//
// label2
//
@ -72,7 +69,6 @@
this.label2.Location = new System.Drawing.Point(9, 60);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Value data:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@ -84,43 +80,30 @@
this.valueDataTxtBox.Location = new System.Drawing.Point(12, 76);
this.valueDataTxtBox.Name = "valueDataTxtBox";
this.valueDataTxtBox.Size = new System.Drawing.Size(343, 20);
this.valueDataTxtBox.TabIndex = 3;
this.valueDataTxtBox.TabIndex = 0;
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(265, 3);
this.cancelButton.Location = new System.Drawing.Point(280, 111);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 4;
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(184, 3);
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(199, 111);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 5;
this.okButton.TabIndex = 1;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flowLayoutPanel1.Controls.Add(this.cancelButton);
this.flowLayoutPanel1.Controls.Add(this.okButton);
this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 108);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.flowLayoutPanel1.Size = new System.Drawing.Size(343, 33);
this.flowLayoutPanel1.TabIndex = 6;
//
// FrmRegValueEditString
//
this.AcceptButton = this.okButton;
@ -128,20 +111,21 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(364, 146);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.valueDataTxtBox);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.Controls.Add(this.label2);
this.Controls.Add(this.valueNameTxtBox);
this.Controls.Add(this.valueDataTxtBox);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FrmRegValueEditString";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.Text = "Edit String";
this.Load += new System.EventHandler(this.FrmRegValueEditString_Load);
this.flowLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -155,6 +139,5 @@
private System.Windows.Forms.TextBox valueDataTxtBox;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
}
}

View File

@ -28,29 +28,17 @@ namespace xServer.Forms
InitializeComponent();
this.valueNameTxtBox.Text = value.Name;
this.valueDataTxtBox.Text = value.Data.ToString();
}
private void FrmRegValueEditString_Load(object sender, EventArgs e)
{
this.valueDataTxtBox.Select();
this.valueDataTxtBox.Focus();
this.valueNameTxtBox.Text = RegValueHelper.GetName(value.Name);
this.valueDataTxtBox.Text = value.Data == null ? "" : value.Data.ToString();
}
private void okButton_Click(object sender, EventArgs e)
{
if (valueDataTxtBox.Text != _value.Data.ToString())
if (_value.Data == null || valueDataTxtBox.Text != _value.Data.ToString())
{
object valueData = valueDataTxtBox.Text;
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
this.Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

View File

@ -32,14 +32,12 @@
this.valueNameTxtBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.valueDataTxtBox = new System.Windows.Forms.TextBox();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.baseBox = new System.Windows.Forms.GroupBox();
this.radioDecimal = new System.Windows.Forms.RadioButton();
this.radioHexa = new System.Windows.Forms.RadioButton();
this.flowLayoutPanel1.SuspendLayout();
this.valueDataTxtBox = new xServer.Controls.WordTextBox();
this.baseBox.SuspendLayout();
this.SuspendLayout();
//
@ -51,8 +49,8 @@
this.valueNameTxtBox.Location = new System.Drawing.Point(12, 27);
this.valueNameTxtBox.Name = "valueNameTxtBox";
this.valueNameTxtBox.ReadOnly = true;
this.valueNameTxtBox.Size = new System.Drawing.Size(337, 20);
this.valueNameTxtBox.TabIndex = 3;
this.valueNameTxtBox.Size = new System.Drawing.Size(334, 20);
this.valueNameTxtBox.TabIndex = 5;
//
// label1
//
@ -63,7 +61,7 @@
this.label1.Location = new System.Drawing.Point(9, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 13);
this.label1.TabIndex = 2;
this.label1.TabIndex = 10;
this.label1.Text = "Value name:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
@ -76,51 +74,28 @@
this.label2.Location = new System.Drawing.Point(9, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.TabIndex = 4;
this.label2.TabIndex = 9;
this.label2.Text = "Value data:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// valueDataTxtBox
//
this.valueDataTxtBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Lower;
this.valueDataTxtBox.Location = new System.Drawing.Point(12, 70);
this.valueDataTxtBox.Name = "valueDataTxtBox";
this.valueDataTxtBox.Size = new System.Drawing.Size(161, 20);
this.valueDataTxtBox.TabIndex = 5;
this.valueDataTxtBox.WordWrap = false;
this.valueDataTxtBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.valueDataTxtBox_KeyPress);
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flowLayoutPanel1.Controls.Add(this.cancelButton);
this.flowLayoutPanel1.Controls.Add(this.okButton);
this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 122);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.flowLayoutPanel1.Size = new System.Drawing.Size(337, 29);
this.flowLayoutPanel1.TabIndex = 7;
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(259, 3);
this.cancelButton.Location = new System.Drawing.Point(271, 128);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 4;
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(178, 3);
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(190, 128);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 5;
this.okButton.TabIndex = 1;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
@ -132,7 +107,7 @@
this.baseBox.Location = new System.Drawing.Point(190, 53);
this.baseBox.Name = "baseBox";
this.baseBox.Size = new System.Drawing.Size(156, 63);
this.baseBox.TabIndex = 8;
this.baseBox.TabIndex = 6;
this.baseBox.TabStop = false;
this.baseBox.Text = "Base";
//
@ -142,10 +117,9 @@
this.radioDecimal.Location = new System.Drawing.Point(14, 40);
this.radioDecimal.Name = "radioDecimal";
this.radioDecimal.Size = new System.Drawing.Size(63, 17);
this.radioDecimal.TabIndex = 1;
this.radioDecimal.TabIndex = 4;
this.radioDecimal.Text = "Decimal";
this.radioDecimal.UseVisualStyleBackColor = true;
this.radioDecimal.Click += new System.EventHandler(this.radioDecimal_Click);
//
// radioHexa
//
@ -154,11 +128,22 @@
this.radioHexa.Location = new System.Drawing.Point(14, 17);
this.radioHexa.Name = "radioHexa";
this.radioHexa.Size = new System.Drawing.Size(86, 17);
this.radioHexa.TabIndex = 0;
this.radioHexa.TabIndex = 3;
this.radioHexa.TabStop = true;
this.radioHexa.Text = "Hexadecimal";
this.radioHexa.UseVisualStyleBackColor = true;
this.radioHexa.Click += new System.EventHandler(this.radioHexa_Click);
this.radioHexa.CheckedChanged += new System.EventHandler(this.radioHex_CheckboxChanged);
//
// valueDataTxtBox
//
this.valueDataTxtBox.IsHexNumber = true;
this.valueDataTxtBox.Location = new System.Drawing.Point(12, 70);
this.valueDataTxtBox.MaxLength = 8;
this.valueDataTxtBox.Name = "valueDataTxtBox";
this.valueDataTxtBox.Size = new System.Drawing.Size(161, 20);
this.valueDataTxtBox.TabIndex = 0;
this.valueDataTxtBox.Text = "0";
this.valueDataTxtBox.Type = xServer.Enums.WordType.DWORD;
//
// FrmRegValueEditWord
//
@ -167,21 +152,21 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(358, 163);
this.Controls.Add(this.baseBox);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.valueDataTxtBox);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.baseBox);
this.Controls.Add(this.okButton);
this.Controls.Add(this.label2);
this.Controls.Add(this.valueNameTxtBox);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FrmRegValueEditWord";
this.ShowIcon = false;
this.Text = "Edit";
this.Load += new System.EventHandler(this.FrmRegValueEditWord_Load);
this.flowLayoutPanel1.ResumeLayout(false);
this.baseBox.ResumeLayout(false);
this.baseBox.PerformLayout();
this.ResumeLayout(false);
@ -194,12 +179,11 @@
private System.Windows.Forms.TextBox valueNameTxtBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox valueDataTxtBox;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.GroupBox baseBox;
private System.Windows.Forms.RadioButton radioDecimal;
private System.Windows.Forms.RadioButton radioHexa;
private Controls.WordTextBox valueDataTxtBox;
}
}

View File

@ -9,6 +9,7 @@ using System.Text;
using System.Windows.Forms;
using xServer.Core.Networking;
using xServer.Core.Registry;
using xServer.Enums;
namespace xServer.Forms
{
@ -20,19 +21,11 @@ namespace xServer.Forms
private readonly string _keyPath;
private int valueBase;
#region CONSTANT
private const int HEXA_32BIT_MAX_LENGTH = 8;
private const int HEXA_64BIT_MAX_LENGTH = 16;
private const int DEC_32BIT_MAX_LENGTH = 10;
private const int DEC_64BIT_MAX_LENGTH = 20;
private const int HEXA_BASE = 16;
private const int DEC_BASE = 10;
private const string DWORD_WARNING = "The decimal value entered is greater than the maximum value of a DWORD (32-bit number). Should the value be truncated in order to continue?";
private const string QWORD_WARNING = "The decimal value entered is greater than the maximum value of a QWORD (64-bit number). Should the value be truncated in order to continue?";
private const string QWORD_WARNING = "The decimal value entered is greater than the maximum value of a QWORD (64-bit number). Should the value be truncated in order to continue?";
#endregion
public FrmRegValueEditWord(string keyPath, RegValueData value, Client c)
@ -45,174 +38,60 @@ namespace xServer.Forms
this.valueNameTxtBox.Text = value.Name;
if (value.Kind == RegistryValueKind.DWord) {
this.Text = "Edit DWORD (32-bit) Value";
this.valueDataTxtBox.Text = ((uint)(int)value.Data).ToString("X");
this.valueDataTxtBox.MaxLength = HEXA_32BIT_MAX_LENGTH;
}
else if (value.Kind == RegistryValueKind.QWord) {
this.Text = "Edit QWORD (64-bit) Value";
this.valueDataTxtBox.Text = ((ulong)(long)value.Data).ToString("X");
this.valueDataTxtBox.MaxLength = HEXA_64BIT_MAX_LENGTH;
}
valueBase = HEXA_BASE;
}
private void FrmRegValueEditWord_Load(object sender, EventArgs e)
{
this.valueDataTxtBox.Select();
this.valueDataTxtBox.Focus();
}
#region Helpfunctions
private string GetDataAsString(int type)
{
if (!String.IsNullOrEmpty(valueDataTxtBox.Text))
if (value.Kind == RegistryValueKind.DWord)
{
string text = valueDataTxtBox.Text;
string returnType = (type == HEXA_BASE ? "X" : "D");
try
{
if (_value.Kind == RegistryValueKind.DWord)
return Convert.ToUInt32(text, valueBase).ToString(returnType);
else
return Convert.ToUInt64(text, valueBase).ToString(returnType);
}
catch
{
string message = _value.Kind == RegistryValueKind.DWord ? DWORD_WARNING : QWORD_WARNING;
if (ShowWarning(message, "Overflow") == DialogResult.Yes) //Yes from popup
{
if (_value.Kind == RegistryValueKind.DWord)
return UInt32.MaxValue.ToString(returnType);
else
return UInt64.MaxValue.ToString(returnType);
}
}
this.Text = "Edit DWORD (32-bit) Value";
this.valueDataTxtBox.Type = WordType.DWORD;
this.valueDataTxtBox.Text = ((uint)(int)value.Data).ToString("x");
}
else
{
this.Text = "Edit QWORD (64-bit) Value";
this.valueDataTxtBox.Type = WordType.QWORD;
this.valueDataTxtBox.Text = ((ulong)(long)value.Data).ToString("x");
}
}
private void radioHex_CheckboxChanged(object sender, EventArgs e)
{
if (valueDataTxtBox.IsHexNumber == radioHexa.Checked)
return;
if(valueDataTxtBox.IsConversionValid() || IsOverridePossible())
valueDataTxtBox.IsHexNumber = radioHexa.Checked;
else
radioDecimal.Checked = true;
}
private void okButton_Click(object sender, EventArgs e)
{
if(valueDataTxtBox.IsConversionValid() || IsOverridePossible())
{
object valueData = null;
if(_value.Kind == RegistryValueKind.DWord)
valueData = (int)valueDataTxtBox.UIntValue;
else
valueData = (long)valueDataTxtBox.ULongValue;
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
else
{
return "";
//Prevent exit
DialogResult = DialogResult.None;
}
//No convertion made
return null;
}
private DialogResult ShowWarning(string msg, string caption)
{
return MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
#endregion
#region RadioButton Actions
private void radioHexa_Click(object sender, EventArgs e)
private bool IsOverridePossible()
{
if (radioHexa.Checked)
{
string text = GetDataAsString(HEXA_BASE);
if (text != null)
{
this.valueDataTxtBox.MaxLength = HEXA_64BIT_MAX_LENGTH;
string message = _value.Kind == RegistryValueKind.DWord ? DWORD_WARNING : QWORD_WARNING;
if (_value.Kind == RegistryValueKind.DWord)
this.valueDataTxtBox.MaxLength = HEXA_32BIT_MAX_LENGTH;
valueDataTxtBox.Text = text;
valueBase = HEXA_BASE;
}
else if(valueBase == DEC_BASE)
{
//Re-check
radioDecimal.Checked = true;
}
}
}
private void radioDecimal_Click(object sender, EventArgs e)
{
if (radioDecimal.Checked)
{
string text = GetDataAsString(DEC_BASE);
if (text != null)
{
this.valueDataTxtBox.MaxLength = DEC_64BIT_MAX_LENGTH;
if (_value.Kind == RegistryValueKind.DWord)
this.valueDataTxtBox.MaxLength = DEC_32BIT_MAX_LENGTH;
valueDataTxtBox.Text = text;
valueBase = DEC_BASE;
}
else if(valueBase == HEXA_BASE)
{
//Re-check
radioHexa.Checked = true;
}
}
}
#endregion
#region OK and Cancel Buttons
private void okButton_Click(object sender, EventArgs e)
{
//Try to convert string
string text = GetDataAsString(DEC_BASE);
if (text != null)
{
if (_value.Kind == RegistryValueKind.DWord)
{
if (text != ((uint)(int)_value.Data).ToString())
{
uint unsignedValue = Convert.ToUInt32(text);
object valueData = (int)(unsignedValue);
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
}
else if (_value.Kind == RegistryValueKind.QWord)
{
if (text != ((ulong)(long)_value.Data).ToString())
{
ulong unsignedValue = Convert.ToUInt64(text);
object valueData = (long)(unsignedValue);
new xServer.Core.Packets.ServerPackets.DoChangeRegistryValue(_keyPath, new RegValueData(_value.Name, _value.Kind, valueData)).Execute(_connectClient);
}
}
this.Close();
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void valueDataTxtBox_KeyPress(object sender, KeyPressEventArgs e)
{
//Control keys are ok
if(!Char.IsControl(e.KeyChar)) {
if (radioHexa.Checked)
{
e.Handled = !(IsHexa(e.KeyChar));
}
else
{
e.Handled = !(Char.IsDigit(e.KeyChar));
}
}
}
#endregion
private static bool IsHexa(char c)
{
return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || Char.IsDigit(c);
return ShowWarning(message, "Overflow") == DialogResult.Yes;
}
}
}

View File

@ -71,7 +71,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);
@ -85,7 +85,7 @@
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.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()));
@ -131,7 +131,7 @@
//
// 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;
@ -204,6 +204,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 +427,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 +450,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
//
@ -561,29 +562,26 @@
this.tvRegistryDirectory.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvRegistryDirectory_NodeMouseClick);
this.tvRegistryDirectory.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tvRegistryDirectory_KeyUp);
//
// lstRegistryKeys
// lstRegistryValues
//
this.lstRegistryKeys.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.lstRegistryValues.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);
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
//
@ -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,9 +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 DEFAULT_REG_VALUE = "(Default)";
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!";
#endregion
@ -41,23 +39,14 @@ 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
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);
// Set the ListSorter for the listView
this.lstRegistryKeys.ListViewItemSorter = new RegistryValueListItemComparer();
if (_connectClient != null)
this.Text = WindowHelper.GetWindowTitle("Registry Editor", _connectClient);
}
private void FrmRegistryEditor_FormClosing(object sender, FormClosingEventArgs e)
@ -76,7 +65,6 @@ namespace xServer.Forms
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
public void PerformClose()
@ -98,6 +86,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 +105,7 @@ namespace xServer.Forms
};
}
public void AddKeysToTree(string rootName, RegSeekerMatch[] matches)
public void AddKeys(string rootName, RegSeekerMatch[] matches)
{
if (string.IsNullOrEmpty(rootName))
{
@ -117,9 +114,7 @@ namespace xServer.Forms
tvRegistryDirectory.BeginUpdate();
foreach (var match in matches)
{
AddRootKey(match);
}
tvRegistryDirectory.SelectedNode = tvRegistryDirectory.Nodes[0];
@ -129,7 +124,6 @@ namespace xServer.Forms
}
else
{
TreeNode parent = GetTreeNode(rootName);
if (parent != null)
@ -139,14 +133,7 @@ namespace xServer.Forms
tvRegistryDirectory.BeginUpdate();
foreach (var 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();
tvRegistryDirectory.EndUpdate();
@ -155,39 +142,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 +171,18 @@ 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])
tvRegistryDirectory.SelectedNode = null;
tvRegistryDirectory.SelectedNode = parent.Nodes[index];
tvRegistryDirectory.SelectedNode = parent.Nodes[newName];
});
}
}
@ -227,232 +194,165 @@ 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();
}
//Deactivate sorting
lstRegistryKeys.Sorting = SortOrder.None;
List<RegValueData> ValuesFromNode = ((RegValueData[])key.Tag).ToList();
ValuesFromNode.Add(value);
key.Tag = ValuesFromNode.ToArray();
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);
RegistryValueLstItem item = new RegistryValueLstItem(value);
lstRegistryValues.Items.Add(item);
//Unselect all
lstRegistryValues.SelectedIndices.Clear();
item.Selected = true;
lstRegistryKeys.LabelEdit = true;
lstRegistryValues.LabelEdit = true;
item.BeginEdit();
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
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[]))
if (!RegValueHelper.IsDefaultValue(valueName))
{
ValuesFromNode = ((RegValueData[])key.Tag).ToList();
ValuesFromNode.RemoveAll(value => value.Name == valueName);
key.Tag = ValuesFromNode.ToArray();
//Remove the values that have the specified name
key.Tag = ((RegValueData[])key.Tag).Where(value => value.Name != valueName).ToArray();
if (tvRegistryDirectory.SelectedNode == key)
lstRegistryValues.Items.RemoveByKey(valueName);
}
else
else //Handle delete of default value
{
//Tag has incorrect element or is missing data
key.Tag = new RegValueData[] {};
var regValue = ((RegValueData[])key.Tag).First(item => item.Name == valueName);
regValue.Data = null;
if(tvRegistryDirectory.SelectedNode == key)
{
var valueItem = lstRegistryValues.Items.Cast<RegistryValueLstItem>()
.SingleOrDefault(item => item.Name == valueName);
if (valueItem != null)
valueItem.Data = regValue.Kind.RegistryTypeToString(null);
}
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
public void RenameValue(string keyPath, string oldName, string newName)
{
TreeNode key = GetTreeNode(keyPath);
if (key != null)
{
lstRegistryValues.Invoke((MethodInvoker)delegate
{
var value = ((RegValueData[])key.Tag).First(item => item.Name == oldName);
value.Name = newName;
if (tvRegistryDirectory.SelectedNode == key)
{
valueName = String.IsNullOrEmpty(valueName) ? DEFAULT_REG_VALUE : valueName;
lstRegistryKeys.Items.RemoveByKey(valueName);
}
else
{
tvRegistryDirectory.SelectedNode = key;
var valueItem = lstRegistryValues.Items.Cast<RegistryValueLstItem>()
.SingleOrDefault(item => item.Name == oldName);
if (valueItem != null)
valueItem.RegName = newName;
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
public void RenameValueFromList(string keyPath, string oldName, string newName)
public void ChangeValue(string keyPath, RegValueData value)
{
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 regValue = ((RegValueData[])key.Tag).First(item => item.Name == value.Name);
regValue.Data = value.Data;
if (tvRegistryDirectory.SelectedNode == key)
{
var index = lstRegistryKeys.Items.IndexOfKey(oldName);
if (index != -1)
{
RegistryValueLstItem valueItem = (RegistryValueLstItem)lstRegistryKeys.Items[index];
valueItem.RegName = newName;
}
}
else
{
tvRegistryDirectory.SelectedNode = key;
}
if (tvRegistryDirectory.SelectedNode == key)
{
var valueItem = lstRegistryValues.Items.Cast<RegistryValueLstItem>()
.SingleOrDefault(item => item.Name == value.Name);
if (valueItem != null)
valueItem.Data = value.Kind.RegistryTypeToString(value.Data);
}
tvRegistryDirectory.SelectedNode = key;
});
}
}
public void ChangeValueFromList(string keyPath, RegValueData value)
{
TreeNode key = GetTreeNode(keyPath);
if (key != null)
{
lstRegistryKeys.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;
if (tvRegistryDirectory.SelectedNode == key)
{
//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;
}
}
});
}
}
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.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)
{
string kind = value.Kind.RegistryTypeToString();
string data = value.Kind.RegistryTypeToString(value.Data);
RegistryValueLstItem item = new RegistryValueLstItem(value.Name, kind, data);
lstRegistryKeys.Items.Add(item);
}
RegistryValueLstItem item = new RegistryValueLstItem(value);
lstRegistryValues.Items.Add(item);
}
lstRegistryValues.EndUpdate();
}
#endregion
@ -461,31 +361,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 +393,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,78 +401,94 @@ 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);
}
}
private void tvRegistryDirectory_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
if (e.Node != null)
{
UpdateLstRegistryKeys(e.Node);
}
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);
}
}
#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 && !RegValueHelper.IsDefaultValue(lstRegistryValues.SelectedItems[0].Name);
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 +499,7 @@ namespace xServer.Forms
{
renameRegistryKey_Click(this, e);
}
else if (lstRegistryKeys.Focused)
else if (lstRegistryValues.Focused)
{
renameRegistryValue_Click(this, e);
}
@ -605,16 +514,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,78 +534,39 @@ 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
@ -703,47 +575,37 @@ namespace xServer.Forms
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 +670,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 +690,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 +714,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 && !RegValueHelper.IsDefaultValue(lstRegistryValues.SelectedItems[0].Name);
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 +761,21 @@ namespace xServer.Forms
}
}
private void CreateModifyForm(bool isBinary)
{
string keyPath = tvRegistryDirectory.SelectedNode.FullPath;
string name = 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
BwAAAk1TRnQBSQFMAwEBAAFIAQUBSAEFARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
AUADAAEQAwABAQEAAQgGAAEEGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEA
AfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEA
AYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFm
@ -169,7 +169,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABk
CQAAAk1TRnQBSQFMAgEBAgEAAXABAwFwAQMBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CQAAAk1TRnQBSQFMAgEBAgEAAWgBBAFoAQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -88,6 +88,12 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\RegistryValueLstItem.cs" />
<Compile Include="Controls\WordTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\WordTextBox.Designer.cs">
<DependentUpon>WordTextBox.cs</DependentUpon>
</Compile>
<Compile Include="Core\Build\IconInjector.cs" />
<Compile Include="Core\Commands\RegistryHandler.cs" />
<Compile Include="Core\Commands\TCPConnectionsHandler.cs" />
@ -179,6 +185,8 @@
<Compile Include="Core\Packets\ServerPackets\SetAuthenticationSuccess.cs" />
<Compile Include="Core\Registry\RegSeekerMatch.cs" />
<Compile Include="Core\Registry\RegValueData.cs" />
<Compile Include="Core\Registry\RegValueHelper.cs" />
<Compile Include="Core\Utilities\ByteConverter.cs" />
<Compile Include="Core\Utilities\FrameCounter.cs" />
<Compile Include="Core\Helper\NativeMethodsHelper.cs" />
<Compile Include="Core\Helper\PlatformHelper.cs" />
@ -267,6 +275,7 @@
<Compile Include="Enums\PathType.cs" />
<Compile Include="Enums\ShutdownAction.cs" />
<Compile Include="Enums\UserStatus.cs" />
<Compile Include="Enums\WordType.cs" />
<Compile Include="Forms\FrmAbout.cs">
<SubType>Form</SubType>
</Compile>