Added support for editing multi-string registry values.

This commit is contained in:
StingRaptor 2016-01-27 20:57:27 +01:00
parent c497d56a00
commit 9bb81d8a4f
5 changed files with 377 additions and 0 deletions

View File

@ -0,0 +1,159 @@
namespace xServer.Forms
{
partial class FrmRegValueEditMultiString
{
/// <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 Windows Form 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()
{
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
//
this.valueNameTxtBox.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.valueNameTxtBox.Location = new System.Drawing.Point(15, 25);
this.valueNameTxtBox.Name = "valueNameTxtBox";
this.valueNameTxtBox.ReadOnly = true;
this.valueNameTxtBox.Size = new System.Drawing.Size(346, 20);
this.valueNameTxtBox.TabIndex = 5;
//
// label1
//
this.label1.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.label1.AutoSize = true;
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;
//
// label2
//
this.label2.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.label2.AutoSize = true;
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.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 4;
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.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 5;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// valueDataTxtBox
//
this.valueDataTxtBox.AcceptsReturn = true;
this.valueDataTxtBox.Location = new System.Drawing.Point(15, 69);
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.WordWrap = false;
//
// FrmRegValueEditMultiString
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(373, 365);
this.Controls.Add(this.valueDataTxtBox);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.label2);
this.Controls.Add(this.valueNameTxtBox);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
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();
}
#endregion
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

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using xServer.Core.Networking;
using xServer.Core.Registry;
namespace xServer.Forms
{
public partial class FrmRegValueEditMultiString : Form
{
private readonly Client _connectClient;
private readonly RegValueData _value;
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 string found.";
#endregion
public FrmRegValueEditMultiString(string keyPath, RegValueData value, Client c)
{
_connectClient = c;
_keyPath = keyPath;
_value = value;
InitializeComponent();
this.valueNameTxtBox.Text = value.Name;
this.valueDataTxtBox.Lines = (string[])value.Data;
}
private void FrmRegValueEditMultiString_Load(object sender, EventArgs e)
{
this.valueDataTxtBox.Select();
this.valueDataTxtBox.Focus();
}
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();
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
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

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -826,10 +826,15 @@ private Form GetEditForm(string keyPath, RegValueData value)
switch (value.Kind)
{
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return new FrmRegValueEditString(keyPath, value, _connectClient);
case RegistryValueKind.DWord:
case RegistryValueKind.QWord:
return new FrmRegValueEditWord(keyPath, value, _connectClient);
case RegistryValueKind.MultiString:
return new FrmRegValueEditMultiString(keyPath, value, _connectClient);
case RegistryValueKind.Binary:
default:
return null;
}

View File

@ -307,6 +307,12 @@
<Compile Include="Forms\FrmRegistryEditor.Designer.cs">
<DependentUpon>FrmRegistryEditor.cs</DependentUpon>
</Compile>
<Compile Include="Forms\FrmRegValueEditMultiString.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\FrmRegValueEditMultiString.Designer.cs">
<DependentUpon>FrmRegValueEditMultiString.cs</DependentUpon>
</Compile>
<Compile Include="Forms\FrmRegValueEditString.cs">
<SubType>Form</SubType>
</Compile>
@ -428,6 +434,9 @@
<EmbeddedResource Include="Forms\FrmRegistryEditor.resx">
<DependentUpon>FrmRegistryEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\FrmRegValueEditMultiString.resx">
<DependentUpon>FrmRegValueEditMultiString.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\FrmRegValueEditString.resx">
<DependentUpon>FrmRegValueEditString.cs</DependentUpon>
</EmbeddedResource>