mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
Update Edit Process Mode Form
This commit is contained in:
@@ -35,8 +35,9 @@ namespace Netch.Controllers
|
||||
aio_dial((int) NameList.TYPE_FILTERTCP, (Global.Settings.ProcessProxyProtocol != PortType.UDP).ToString().ToLower());
|
||||
SetServer(Global.Settings.ProcessProxyProtocol);
|
||||
|
||||
if (!CheckRule(mode.FullRule, out var list))
|
||||
throw new MessageException($"\"{string.Join("", list.Select(s => s + "\n"))}\" does not conform to C++ regular expression syntax");
|
||||
var result = CheckRuleMessageResult(mode.FullRule);
|
||||
if (result != null)
|
||||
throw new MessageException(result);
|
||||
|
||||
SetName(mode);
|
||||
|
||||
@@ -71,6 +72,14 @@ namespace Netch.Controllers
|
||||
return !incompatibleRule.Any();
|
||||
}
|
||||
|
||||
public static string? CheckRuleMessageResult(IEnumerable<string> rules)
|
||||
{
|
||||
if (CheckRule(rules, out var list))
|
||||
return null;
|
||||
|
||||
return ($"{string.Join("\n", list)}\nAbove rules does not conform to C++ regular expression syntax");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="r"></param>
|
||||
|
||||
134
Netch/Forms/Mode/Process.Designer.cs
generated
134
Netch/Forms/Mode/Process.Designer.cs
generated
@@ -31,26 +31,21 @@ namespace Netch.Forms.Mode
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.ConfigurationGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.RemarkLabel = new System.Windows.Forms.Label();
|
||||
this.RemarkTextBox = new System.Windows.Forms.TextBox();
|
||||
this.FilenameLabel = new System.Windows.Forms.Label();
|
||||
this.FilenameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.containerControl1 = new System.Windows.Forms.ContainerControl();
|
||||
this.RuleListBox = new System.Windows.Forms.ListBox();
|
||||
this.RuleRichTextBox = new System.Windows.Forms.RichTextBox();
|
||||
this.ProcessGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.ProcessNameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.ScanButton = new System.Windows.Forms.Button();
|
||||
this.SelectButton = new System.Windows.Forms.Button();
|
||||
this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.DeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ScanButton = new System.Windows.Forms.Button();
|
||||
this.ValidationButton = new System.Windows.Forms.Button();
|
||||
this.ControlButton = new System.Windows.Forms.Button();
|
||||
this.ConfigurationGroupBox.SuspendLayout();
|
||||
this.containerControl1.SuspendLayout();
|
||||
this.ProcessGroupBox.SuspendLayout();
|
||||
this.contextMenuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ConfigurationGroupBox
|
||||
@@ -61,12 +56,12 @@ namespace Netch.Forms.Mode
|
||||
this.ConfigurationGroupBox.Controls.Add(this.FilenameTextBox);
|
||||
this.ConfigurationGroupBox.Controls.Add(this.containerControl1);
|
||||
this.ConfigurationGroupBox.Controls.Add(this.ProcessGroupBox);
|
||||
this.ConfigurationGroupBox.Controls.Add(this.SelectButton);
|
||||
this.ConfigurationGroupBox.Controls.Add(this.ScanButton);
|
||||
this.ConfigurationGroupBox.Location = new System.Drawing.Point(12, 12);
|
||||
this.ConfigurationGroupBox.Controls.Add(this.ControlButton);
|
||||
this.ConfigurationGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.ConfigurationGroupBox.Location = new System.Drawing.Point(12, 5);
|
||||
this.ConfigurationGroupBox.Name = "ConfigurationGroupBox";
|
||||
this.ConfigurationGroupBox.Size = new System.Drawing.Size(340, 344);
|
||||
this.ConfigurationGroupBox.TabIndex = 1;
|
||||
this.ConfigurationGroupBox.Size = new System.Drawing.Size(431, 378);
|
||||
this.ConfigurationGroupBox.TabIndex = 0;
|
||||
this.ConfigurationGroupBox.TabStop = false;
|
||||
this.ConfigurationGroupBox.Text = "Configuration";
|
||||
//
|
||||
@@ -83,7 +78,7 @@ namespace Netch.Forms.Mode
|
||||
//
|
||||
this.RemarkTextBox.Location = new System.Drawing.Point(84, 22);
|
||||
this.RemarkTextBox.Name = "RemarkTextBox";
|
||||
this.RemarkTextBox.Size = new System.Drawing.Size(250, 23);
|
||||
this.RemarkTextBox.Size = new System.Drawing.Size(341, 23);
|
||||
this.RemarkTextBox.TabIndex = 1;
|
||||
this.RemarkTextBox.TextChanged += new System.EventHandler(this.RemarkTextBox_TextChanged);
|
||||
//
|
||||
@@ -101,96 +96,76 @@ namespace Netch.Forms.Mode
|
||||
this.FilenameTextBox.Location = new System.Drawing.Point(84, 52);
|
||||
this.FilenameTextBox.Name = "FilenameTextBox";
|
||||
this.FilenameTextBox.ReadOnly = true;
|
||||
this.FilenameTextBox.Size = new System.Drawing.Size(250, 23);
|
||||
this.FilenameTextBox.Size = new System.Drawing.Size(341, 23);
|
||||
this.FilenameTextBox.TabIndex = 3;
|
||||
//
|
||||
// containerControl1
|
||||
//
|
||||
this.containerControl1.Controls.Add(this.RuleListBox);
|
||||
this.containerControl1.Controls.Add(this.RuleRichTextBox);
|
||||
this.containerControl1.Location = new System.Drawing.Point(6, 81);
|
||||
this.containerControl1.Name = "containerControl1";
|
||||
this.containerControl1.Size = new System.Drawing.Size(328, 176);
|
||||
this.containerControl1.TabIndex = 5;
|
||||
this.containerControl1.Size = new System.Drawing.Size(419, 221);
|
||||
this.containerControl1.TabIndex = 4;
|
||||
this.containerControl1.Text = "containerControl1";
|
||||
//
|
||||
// RuleListBox
|
||||
// RuleRichTextBox
|
||||
//
|
||||
this.RuleListBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.RuleListBox.FormattingEnabled = true;
|
||||
this.RuleListBox.ItemHeight = 17;
|
||||
this.RuleListBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.RuleListBox.Name = "RuleListBox";
|
||||
this.RuleListBox.Size = new System.Drawing.Size(328, 176);
|
||||
this.RuleListBox.TabIndex = 0;
|
||||
this.RuleListBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.RuleListBox_MouseUp);
|
||||
this.RuleRichTextBox.DetectUrls = false;
|
||||
this.RuleRichTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.RuleRichTextBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.RuleRichTextBox.Name = "RuleRichTextBox";
|
||||
this.RuleRichTextBox.Size = new System.Drawing.Size(419, 221);
|
||||
this.RuleRichTextBox.TabIndex = 0;
|
||||
this.RuleRichTextBox.Text = "";
|
||||
this.RuleRichTextBox.WordWrap = false;
|
||||
//
|
||||
// ProcessGroupBox
|
||||
//
|
||||
this.ProcessGroupBox.Controls.Add(this.ProcessNameTextBox);
|
||||
this.ProcessGroupBox.Controls.Add(this.AddButton);
|
||||
this.ProcessGroupBox.Location = new System.Drawing.Point(6, 263);
|
||||
this.ProcessGroupBox.Controls.Add(this.SelectButton);
|
||||
this.ProcessGroupBox.Controls.Add(this.ScanButton);
|
||||
this.ProcessGroupBox.Controls.Add(this.ValidationButton);
|
||||
this.ProcessGroupBox.Location = new System.Drawing.Point(6, 295);
|
||||
this.ProcessGroupBox.Name = "ProcessGroupBox";
|
||||
this.ProcessGroupBox.Size = new System.Drawing.Size(328, 46);
|
||||
this.ProcessGroupBox.TabIndex = 6;
|
||||
this.ProcessGroupBox.Size = new System.Drawing.Size(419, 44);
|
||||
this.ProcessGroupBox.TabIndex = 5;
|
||||
this.ProcessGroupBox.TabStop = false;
|
||||
//
|
||||
// ProcessNameTextBox
|
||||
//
|
||||
this.ProcessNameTextBox.Location = new System.Drawing.Point(6, 15);
|
||||
this.ProcessNameTextBox.Name = "ProcessNameTextBox";
|
||||
this.ProcessNameTextBox.Size = new System.Drawing.Size(222, 23);
|
||||
this.ProcessNameTextBox.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
this.AddButton.Location = new System.Drawing.Point(247, 15);
|
||||
this.AddButton.Name = "AddButton";
|
||||
this.AddButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.AddButton.TabIndex = 1;
|
||||
this.AddButton.Text = "Add";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// ScanButton
|
||||
//
|
||||
this.ScanButton.Location = new System.Drawing.Point(87, 315);
|
||||
this.ScanButton.Name = "ScanButton";
|
||||
this.ScanButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.ScanButton.TabIndex = 7;
|
||||
this.ScanButton.Text = "Scan";
|
||||
this.ScanButton.UseVisualStyleBackColor = true;
|
||||
this.ScanButton.Click += new System.EventHandler(this.ScanButton_Click);
|
||||
//
|
||||
// SelectButton
|
||||
//
|
||||
this.SelectButton.Location = new System.Drawing.Point(6, 315);
|
||||
this.SelectButton.Location = new System.Drawing.Point(6, 13);
|
||||
this.SelectButton.Name = "SelectButton";
|
||||
this.SelectButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.SelectButton.TabIndex = 7;
|
||||
this.SelectButton.TabIndex = 0;
|
||||
this.SelectButton.Text = "Select";
|
||||
this.SelectButton.UseVisualStyleBackColor = true;
|
||||
this.SelectButton.Click += new System.EventHandler(this.SelectButton_Click);
|
||||
//
|
||||
// contextMenuStrip
|
||||
// ScanButton
|
||||
//
|
||||
this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.DeleteToolStripMenuItem});
|
||||
this.contextMenuStrip.Name = "contextMenuStrip";
|
||||
this.contextMenuStrip.Size = new System.Drawing.Size(114, 26);
|
||||
this.ScanButton.Location = new System.Drawing.Point(87, 13);
|
||||
this.ScanButton.Name = "ScanButton";
|
||||
this.ScanButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.ScanButton.TabIndex = 1;
|
||||
this.ScanButton.Text = "Scan";
|
||||
this.ScanButton.UseVisualStyleBackColor = true;
|
||||
this.ScanButton.Click += new System.EventHandler(this.ScanButton_Click);
|
||||
//
|
||||
// DeleteToolStripMenuItem
|
||||
// ValidationButton
|
||||
//
|
||||
this.DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem";
|
||||
this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(113, 22);
|
||||
this.DeleteToolStripMenuItem.Text = "Delete";
|
||||
this.DeleteToolStripMenuItem.Click += new System.EventHandler(this.deleteRule_Click);
|
||||
this.ValidationButton.Location = new System.Drawing.Point(338, 13);
|
||||
this.ValidationButton.Name = "ValidationButton";
|
||||
this.ValidationButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.ValidationButton.TabIndex = 2;
|
||||
this.ValidationButton.Text = "Validation";
|
||||
this.ValidationButton.UseVisualStyleBackColor = true;
|
||||
this.ValidationButton.Click += new System.EventHandler(this.ValidationButton_Click);
|
||||
//
|
||||
// ControlButton
|
||||
//
|
||||
this.ControlButton.Location = new System.Drawing.Point(277, 362);
|
||||
this.ControlButton.Location = new System.Drawing.Point(344, 345);
|
||||
this.ControlButton.Name = "ControlButton";
|
||||
this.ControlButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.ControlButton.TabIndex = 2;
|
||||
this.ControlButton.TabIndex = 6;
|
||||
this.ControlButton.Text = "Save";
|
||||
this.ControlButton.UseVisualStyleBackColor = true;
|
||||
this.ControlButton.Click += new System.EventHandler(this.ControlButton_Click);
|
||||
@@ -199,14 +174,14 @@ namespace Netch.Forms.Mode
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.ClientSize = new System.Drawing.Size(364, 397);
|
||||
this.ClientSize = new System.Drawing.Size(455, 388);
|
||||
this.Controls.Add(this.ConfigurationGroupBox);
|
||||
this.Controls.Add(this.ControlButton);
|
||||
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "Process";
|
||||
this.Padding = new System.Windows.Forms.Padding(12, 5, 12, 5);
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Create Process Mode";
|
||||
this.Load += new System.EventHandler(this.ModeForm_Load);
|
||||
@@ -214,8 +189,6 @@ namespace Netch.Forms.Mode
|
||||
this.ConfigurationGroupBox.PerformLayout();
|
||||
this.containerControl1.ResumeLayout(false);
|
||||
this.ProcessGroupBox.ResumeLayout(false);
|
||||
this.ProcessGroupBox.PerformLayout();
|
||||
this.contextMenuStrip.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -224,18 +197,15 @@ namespace Netch.Forms.Mode
|
||||
|
||||
private System.Windows.Forms.Button ScanButton;
|
||||
private System.Windows.Forms.ContainerControl containerControl1;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
|
||||
private System.Windows.Forms.ToolStripMenuItem DeleteToolStripMenuItem;
|
||||
public System.Windows.Forms.GroupBox ConfigurationGroupBox;
|
||||
private System.Windows.Forms.Label RemarkLabel;
|
||||
private System.Windows.Forms.GroupBox ProcessGroupBox;
|
||||
private System.Windows.Forms.ListBox RuleListBox;
|
||||
private System.Windows.Forms.TextBox RemarkTextBox;
|
||||
private System.Windows.Forms.TextBox ProcessNameTextBox;
|
||||
private System.Windows.Forms.Button AddButton;
|
||||
private System.Windows.Forms.Button SelectButton;
|
||||
public System.Windows.Forms.Button ControlButton;
|
||||
private System.Windows.Forms.Label FilenameLabel;
|
||||
private System.Windows.Forms.TextBox FilenameTextBox;
|
||||
private RichTextBox RuleRichTextBox;
|
||||
private Button ValidationButton;
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,24 @@ namespace Netch.Forms.Mode
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否被编辑过
|
||||
/// </summary>
|
||||
public bool Edited { get; private set; }
|
||||
#region Model
|
||||
|
||||
public IEnumerable<string> Rules => RuleRichTextBox.Lines;
|
||||
|
||||
private void RuleAdd(string value)
|
||||
{
|
||||
RuleRichTextBox.AppendText($"{value}\n");
|
||||
}
|
||||
|
||||
private void RuleAddRange(IEnumerable<string> value)
|
||||
{
|
||||
foreach (string s in value)
|
||||
{
|
||||
RuleAdd(s);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void ModeForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -49,60 +63,10 @@ namespace Netch.Forms.Mode
|
||||
RemarkTextBox.TextChanged -= RemarkTextBox_TextChanged;
|
||||
RemarkTextBox.Text = _mode.Remark;
|
||||
FilenameTextBox.Text = _mode.RelativePath;
|
||||
RuleListBox.Items.AddRange(_mode.Rule.Cast<object>().ToArray());
|
||||
RuleAddRange(_mode.Rule);
|
||||
}
|
||||
|
||||
i18N.TranslateForm(this);
|
||||
i18N.Translate(contextMenuStrip);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// listBox右键菜单
|
||||
/// </summary>
|
||||
private void RuleListBox_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
RuleListBox.SelectedIndex = RuleListBox.IndexFromPoint(e.X, e.Y);
|
||||
if (RuleListBox.SelectedIndex == -1)
|
||||
return;
|
||||
|
||||
if (e.Button == MouseButtons.Right)
|
||||
contextMenuStrip.Show(RuleListBox, e.Location);
|
||||
}
|
||||
|
||||
private void deleteRule_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (RuleListBox.SelectedIndex == -1)
|
||||
return;
|
||||
|
||||
RuleListBox.Items.RemoveAt(RuleListBox.SelectedIndex);
|
||||
Edited = true;
|
||||
}
|
||||
|
||||
private async void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ProcessNameTextBox.Text))
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("rule can not be empty"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NFController.CheckCppRegex(ProcessNameTextBox.Text))
|
||||
{
|
||||
MessageBoxX.Show("Rule does not conform to C++ regular expression syntax");
|
||||
return;
|
||||
}
|
||||
|
||||
var process = ProcessNameTextBox.Text;
|
||||
|
||||
if (!RuleListBox.Items.Contains(process))
|
||||
RuleListBox.Items.Add(process);
|
||||
|
||||
Edited = true;
|
||||
RuleListBox.SelectedIndex = RuleListBox.Items.IndexOf(process);
|
||||
ProcessNameTextBox.Text = string.Empty;
|
||||
});
|
||||
}
|
||||
|
||||
private void SelectButton_Click(object sender, EventArgs e)
|
||||
@@ -130,14 +94,9 @@ namespace Netch.Forms.Mode
|
||||
}
|
||||
}
|
||||
|
||||
private void RuleAdd(string value)
|
||||
{
|
||||
RuleListBox.Items.Add(value);
|
||||
}
|
||||
|
||||
public void ControlButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (RuleListBox.Items.Count == 0)
|
||||
if (!RuleRichTextBox.Lines.Any())
|
||||
{
|
||||
MessageBoxX.Show(i18N.Translate("Unable to add empty rule"));
|
||||
return;
|
||||
@@ -159,11 +118,10 @@ namespace Netch.Forms.Mode
|
||||
{
|
||||
_mode.Remark = RemarkTextBox.Text;
|
||||
_mode.Rule.Clear();
|
||||
_mode.Rule.AddRange(RuleListBox.Items.Cast<string>());
|
||||
_mode.Rule.AddRange(RuleRichTextBox.Lines);
|
||||
|
||||
_mode.WriteFile();
|
||||
Global.MainForm.LoadModes();
|
||||
Edited = false;
|
||||
MessageBoxX.Show(i18N.Translate("Mode updated successfully"));
|
||||
}
|
||||
else
|
||||
@@ -183,7 +141,7 @@ namespace Netch.Forms.Mode
|
||||
Remark = RemarkTextBox.Text
|
||||
};
|
||||
|
||||
mode.Rule.AddRange(RuleListBox.Items.Cast<string>());
|
||||
mode.Rule.AddRange(RuleRichTextBox.Lines);
|
||||
|
||||
mode.WriteFile();
|
||||
ModeHelper.Add(mode);
|
||||
@@ -230,7 +188,7 @@ namespace Netch.Forms.Mode
|
||||
return;
|
||||
}
|
||||
|
||||
RuleListBox.Items.AddRange(list.Cast<object>().ToArray());
|
||||
RuleAddRange(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,5 +202,14 @@ namespace Netch.Forms.Mode
|
||||
if (maxCount != 0 && list.Count > maxCount)
|
||||
throw new Exception("The number of filter results is greater than maxCount");
|
||||
}
|
||||
|
||||
private void ValidationButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var result = NFController.CheckRuleMessageResult(Rules);
|
||||
if (result != null)
|
||||
MessageBoxX.Show(result, LogLevel.WARNING);
|
||||
else
|
||||
MessageBoxX.Show("Fine");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user