Global.Settings.ProcessProxyProtocol

This commit is contained in:
ChsBuffer
2021-03-03 23:05:04 +08:00
parent 0ce8bbf712
commit 1fc211acde
6 changed files with 38 additions and 73 deletions

View File

@@ -5,7 +5,6 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Threading.Tasks;
using Netch.Forms;
using Netch.Models;
using Netch.Servers.Shadowsocks;
using Netch.Servers.Socks5;
@@ -58,32 +57,9 @@ namespace Netch.Controllers
aio_dial((int) NameList.TYPE_FILTERLOOPBACK, "false");
aio_dial((int) NameList.TYPE_TCPLISN, Global.Settings.RedirectorTCPPort.ToString());
if (Global.Settings.ProcessNoProxyForUdp && Global.Settings.ProcessNoProxyForTcp)
MessageBoxX.Show("");
//UDP
if (Global.Settings.ProcessNoProxyForUdp)
{
aio_dial((int) NameList.TYPE_FILTERUDP, "false");
SetServer(PortType.TCP);
}
else
{
aio_dial((int) NameList.TYPE_FILTERUDP, "true");
SetServer(PortType.Both);
}
//TCP
if (Global.Settings.ProcessNoProxyForTcp)
{
aio_dial((int) NameList.TYPE_FILTERTCP, "false");
SetServer(PortType.UDP);
}
else
{
aio_dial((int) NameList.TYPE_FILTERTCP, "true");
SetServer(PortType.Both);
}
aio_dial((int) NameList.TYPE_FILTERUDP, (Global.Settings.ProcessProxyProtocol != PortType.TCP).ToString().ToLower());
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");

View File

@@ -59,9 +59,9 @@ namespace Netch.Forms
this.LanguageLabel = new System.Windows.Forms.Label();
this.LanguageComboBox = new System.Windows.Forms.ComboBox();
this.NFTabPage = new System.Windows.Forms.TabPage();
this.NoProxyForTcpCheckBox = new System.Windows.Forms.CheckBox();
this.NoProxyForUdpCheckBox = new System.Windows.Forms.CheckBox();
this.ProcessProxyProtocolComboBox = new System.Windows.Forms.ComboBox();
this.ModifySystemDNSCheckBox = new System.Windows.Forms.CheckBox();
this.ProcessProxyProtocolLabel = new System.Windows.Forms.Label();
this.ModifiedDNSLabel = new System.Windows.Forms.Label();
this.ModifiedDNSTextBox = new System.Windows.Forms.TextBox();
this.RedirectorSSCheckBox = new System.Windows.Forms.CheckBox();
@@ -406,12 +406,12 @@ namespace Netch.Forms
// NFTabPage
//
this.NFTabPage.BackColor = System.Drawing.SystemColors.ButtonFace;
this.NFTabPage.Controls.Add(this.NoProxyForTcpCheckBox);
this.NFTabPage.Controls.Add(this.NoProxyForUdpCheckBox);
this.NFTabPage.Controls.Add(this.ModifySystemDNSCheckBox);
this.NFTabPage.Controls.Add(this.ModifiedDNSLabel);
this.NFTabPage.Controls.Add(this.ModifiedDNSTextBox);
this.NFTabPage.Controls.Add(this.RedirectorSSCheckBox);
this.NFTabPage.Controls.Add(this.ProcessProxyProtocolLabel);
this.NFTabPage.Controls.Add(this.ProcessProxyProtocolComboBox);
this.NFTabPage.Location = new System.Drawing.Point(4, 25);
this.NFTabPage.Name = "NFTabPage";
this.NFTabPage.Padding = new System.Windows.Forms.Padding(3);
@@ -419,27 +419,14 @@ namespace Netch.Forms
this.NFTabPage.TabIndex = 1;
this.NFTabPage.Text = "Process Mode";
//
// NoProxyForTcpCheckBox
// ProcessProxyProtocolComboBox
//
this.NoProxyForTcpCheckBox.AutoSize = true;
this.NoProxyForTcpCheckBox.Location = new System.Drawing.Point(8, 82);
this.NoProxyForTcpCheckBox.Name = "NoProxyForTcpCheckBox";
this.NoProxyForTcpCheckBox.Size = new System.Drawing.Size(120, 16);
this.NoProxyForTcpCheckBox.TabIndex = 4;
this.NoProxyForTcpCheckBox.Text = "No Proxy for Tcp";
this.NoProxyForTcpCheckBox.UseVisualStyleBackColor = true;
this.NoProxyForTcpCheckBox.CheckedChanged += new System.EventHandler(this.NoProxyForTcpCheckBox_CheckedChanged);
//
// NoProxyForUdpCheckBox
//
this.NoProxyForUdpCheckBox.AutoSize = true;
this.NoProxyForUdpCheckBox.Location = new System.Drawing.Point(8, 60);
this.NoProxyForUdpCheckBox.Name = "NoProxyForUdpCheckBox";
this.NoProxyForUdpCheckBox.Size = new System.Drawing.Size(120, 16);
this.NoProxyForUdpCheckBox.TabIndex = 3;
this.NoProxyForUdpCheckBox.Text = "No Proxy for Udp";
this.NoProxyForUdpCheckBox.UseVisualStyleBackColor = true;
this.NoProxyForUdpCheckBox.CheckedChanged += new System.EventHandler(this.NoProxyForUdpCheckBox_CheckedChanged);
this.ProcessProxyProtocolComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ProcessProxyProtocolComboBox.FormattingEnabled = true;
this.ProcessProxyProtocolComboBox.Location = new System.Drawing.Point(167, 58);
this.ProcessProxyProtocolComboBox.Name = "ProcessProxyProtocolComboBox";
this.ProcessProxyProtocolComboBox.Size = new System.Drawing.Size(121, 20);
this.ProcessProxyProtocolComboBox.TabIndex = 3;
//
// ModifySystemDNSCheckBox
//
@@ -451,6 +438,15 @@ namespace Netch.Forms
this.ModifySystemDNSCheckBox.Text = "Modify System DNS";
this.ModifySystemDNSCheckBox.UseVisualStyleBackColor = true;
//
// ProcessProxyProtocolLabel
//
this.ProcessProxyProtocolLabel.AutoSize = true;
this.ProcessProxyProtocolLabel.Location = new System.Drawing.Point(24, 61);
this.ProcessProxyProtocolLabel.Name = "ProcessProxyProtocolLabel";
this.ProcessProxyProtocolLabel.Size = new System.Drawing.Size(89, 12);
this.ProcessProxyProtocolLabel.TabIndex = 2;
this.ProcessProxyProtocolLabel.Text = "Proxy Protocol";
//
// ModifiedDNSLabel
//
this.ModifiedDNSLabel.AutoSize = true;
@@ -1034,7 +1030,6 @@ namespace Netch.Forms
}
private System.Windows.Forms.CheckBox XrayConeCheckBox;
private System.Windows.Forms.TextBox StartedPingIntervalTextBox;
private System.Windows.Forms.CheckBox NoProxyForTcpCheckBox;
#endregion
@@ -1115,9 +1110,10 @@ namespace Netch.Forms
private System.Windows.Forms.TextBox ModifiedDNSTextBox;
private System.Windows.Forms.Label ModifiedDNSLabel;
private System.Windows.Forms.CheckBox RedirectorSSCheckBox;
private System.Windows.Forms.CheckBox NoProxyForUdpCheckBox;
private System.Windows.Forms.Label ServerPingTypeLabel;
private System.Windows.Forms.RadioButton TCPingRadioBtn;
private System.Windows.Forms.RadioButton ICMPingRadioBtn;
private System.Windows.Forms.ComboBox ProcessProxyProtocolComboBox;
private System.Windows.Forms.Label ProcessProxyProtocolLabel;
}
}

View File

@@ -90,9 +90,10 @@ namespace Netch.Forms
BindCheckBox(RedirectorSSCheckBox, s => Global.Settings.RedirectorSS = s, Global.Settings.RedirectorSS);
BindCheckBox(NoProxyForUdpCheckBox, s => Global.Settings.ProcessNoProxyForUdp = s, Global.Settings.ProcessNoProxyForUdp);
BindCheckBox(NoProxyForTcpCheckBox, s => Global.Settings.ProcessNoProxyForTcp = s, Global.Settings.ProcessNoProxyForTcp);
BindComboBox(ProcessProxyProtocolComboBox,
s => Global.Settings.ProcessProxyProtocol = (PortType) Enum.Parse(typeof(PortType), s.ToString(), false),
Enum.GetNames(typeof(PortType)).Cast<object>().ToArray(),
Global.Settings.ProcessProxyProtocol.ToString());
#endregion
@@ -331,16 +332,11 @@ namespace Netch.Forms
_saveActions.Add(control, c => save.Invoke(((RadioButton) c).Checked));
}
private void NoProxyForUdpCheckBox_CheckedChanged(object sender, EventArgs e)
private void BindComboBox(ComboBox control, Action<object> save, object[] values, object value)
{
if (NoProxyForUdpCheckBox.Checked)
NoProxyForTcpCheckBox.Checked = false;
}
private void NoProxyForTcpCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (NoProxyForTcpCheckBox.Checked)
NoProxyForUdpCheckBox.Checked = false;
control.Items.AddRange(values);
_saveActions.Add(control, c => save.Invoke(((ComboBox) c).SelectedItem));
Load += (_, _) => { control.SelectedItem = value; };
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Netch.Utils;
namespace Netch.Models
{
@@ -179,12 +180,7 @@ namespace Netch.Models
/// <summary>
/// 不代理TCP
/// </summary>
public bool ProcessNoProxyForTcp { get; set; } = false;
/// <summary>
/// 不代理UDP
/// </summary>
public bool ProcessNoProxyForUdp { get; set; } = false;
public PortType ProcessProxyProtocol { get; set; } = PortType.Both;
/// <summary>
/// 快捷配置数量

View File

@@ -164,8 +164,7 @@
"Update Servers when opened": "打开软件时更新服务器",
"SS DLL": "SS DLL",
"Modify System DNS": "修改系统 DNS",
"No Proxy for Udp": "代理 UDP 流量",
"No Proxy for Tcp": "不代理 TCP 流量",
"Proxy Protocol": "代理协议",
"ProfileCount": "快捷配置数量",
"Delay test after start": "启动后延迟测试",
"ServerPingType": "测速方式",

View File

@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Netch.Models;
namespace Netch.Utils
@@ -22,6 +23,7 @@ namespace Netch.Utils
static Configuration()
{
JsonSerializerOptions.Converters.Add(new ServerConverterWithTypeDiscriminator());
JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
}
/// <summary>