diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 04faff4ab4..11202a6e83 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -34,6 +34,9 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm)); this.TabControl = new System.Windows.Forms.TabControl(); this.GeneralTabPage = new System.Windows.Forms.TabPage(); + this.ServerPingTypeLabel = new System.Windows.Forms.Label(); + this.TCPingRadioBtn = new System.Windows.Forms.RadioButton(); + this.ICMPingRadioBtn = new System.Windows.Forms.RadioButton(); this.PortGroupBox = new System.Windows.Forms.GroupBox(); this.Socks5PortLabel = new System.Windows.Forms.Label(); this.Socks5PortTextBox = new System.Windows.Forms.TextBox(); @@ -143,6 +146,9 @@ private void InitializeComponent() // GeneralTabPage // this.GeneralTabPage.BackColor = System.Drawing.SystemColors.ButtonFace; + this.GeneralTabPage.Controls.Add(this.ServerPingTypeLabel); + this.GeneralTabPage.Controls.Add(this.TCPingRadioBtn); + this.GeneralTabPage.Controls.Add(this.ICMPingRadioBtn); this.GeneralTabPage.Controls.Add(this.PortGroupBox); this.GeneralTabPage.Controls.Add(this.BootShadowsocksFromDLLCheckBox); this.GeneralTabPage.Controls.Add(this.ResolveServerHostnameCheckBox); @@ -164,6 +170,39 @@ private void InitializeComponent() this.GeneralTabPage.TabIndex = 0; this.GeneralTabPage.Text = "General"; // + // ServerPingTypeLabel + // + this.ServerPingTypeLabel.AutoSize = true; + this.ServerPingTypeLabel.Location = new System.Drawing.Point(217, 160); + this.ServerPingTypeLabel.Name = "ServerPingTypeLabel"; + this.ServerPingTypeLabel.Size = new System.Drawing.Size(89, 12); + this.ServerPingTypeLabel.TabIndex = 16; + this.ServerPingTypeLabel.Text = "ServerPingType"; + // + // TCPingRadioBtn + // + this.TCPingRadioBtn.AutoSize = true; + this.TCPingRadioBtn.Location = new System.Drawing.Point(376, 158); + this.TCPingRadioBtn.Name = "TCPingRadioBtn"; + this.TCPingRadioBtn.Size = new System.Drawing.Size(59, 16); + this.TCPingRadioBtn.TabIndex = 15; + this.TCPingRadioBtn.TabStop = true; + this.TCPingRadioBtn.Text = "TCPing"; + this.TCPingRadioBtn.UseVisualStyleBackColor = true; + this.TCPingRadioBtn.CheckedChanged += new System.EventHandler(this.TCPingRadioBtn_CheckedChanged); + // + // ICMPingRadioBtn + // + this.ICMPingRadioBtn.AutoSize = true; + this.ICMPingRadioBtn.Location = new System.Drawing.Point(312, 158); + this.ICMPingRadioBtn.Name = "ICMPingRadioBtn"; + this.ICMPingRadioBtn.Size = new System.Drawing.Size(65, 16); + this.ICMPingRadioBtn.TabIndex = 14; + this.ICMPingRadioBtn.TabStop = true; + this.ICMPingRadioBtn.Text = "ICMPing"; + this.ICMPingRadioBtn.UseVisualStyleBackColor = true; + this.ICMPingRadioBtn.CheckedChanged += new System.EventHandler(this.ICMPingRadioBtn_CheckedChanged); + // // PortGroupBox // this.PortGroupBox.Controls.Add(this.Socks5PortLabel); @@ -292,7 +331,7 @@ private void InitializeComponent() // DetectionIntervalLabel // this.DetectionIntervalLabel.AutoSize = true; - this.DetectionIntervalLabel.Location = new System.Drawing.Point(228, 187); + this.DetectionIntervalLabel.Location = new System.Drawing.Point(217, 187); this.DetectionIntervalLabel.Name = "DetectionIntervalLabel"; this.DetectionIntervalLabel.Size = new System.Drawing.Size(143, 12); this.DetectionIntervalLabel.TabIndex = 6; @@ -383,6 +422,7 @@ private void InitializeComponent() 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 // @@ -393,6 +433,7 @@ private void InitializeComponent() this.NoProxyForUdpCheckBox.TabIndex = 3; this.NoProxyForUdpCheckBox.Text = "No Proxy for Udp"; this.NoProxyForUdpCheckBox.UseVisualStyleBackColor = true; + this.NoProxyForUdpCheckBox.CheckedChanged += new System.EventHandler(this.NoProxyForUdpCheckBox_CheckedChanged); // // ModifySystemDNSCheckBox // @@ -929,7 +970,7 @@ private void InitializeComponent() // // ControlButton // - this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.ControlButton.Location = new System.Drawing.Point(397, 363); this.ControlButton.Name = "ControlButton"; this.ControlButton.Size = new System.Drawing.Size(75, 23); @@ -960,7 +1001,7 @@ private void InitializeComponent() this.ClientSize = new System.Drawing.Size(480, 400); this.Controls.Add(this.flowLayoutPanel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon"))); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "SettingForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; @@ -987,6 +1028,7 @@ private void InitializeComponent() this.flowLayoutPanel1.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); + } private System.Windows.Forms.CheckBox NoProxyForTcpCheckBox; @@ -1071,5 +1113,8 @@ private void InitializeComponent() 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; } } \ No newline at end of file diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 3599ccc8bf..12e7c43068 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -59,6 +59,14 @@ private void InitValue() c => Global.Settings.ResolveServerHostname = c, Global.Settings.ResolveServerHostname); + BindRadioBox(ICMPingRadioBtn, + c => Global.Settings.ServerTCPing = c, + !Global.Settings.ServerTCPing); + + BindRadioBox(TCPingRadioBtn, + c => Global.Settings.ServerTCPing = c, + Global.Settings.ServerTCPing); + BindTextBox(ProfileCountTextBox, i => i > -1, i => Global.Settings.ProfileCount = i, @@ -346,17 +354,6 @@ private void ControlButton_Click(object sender, EventArgs e) #endregion - #region CheckProcessMode - - if (NoProxyForUdpCheckBox.Checked && NoProxyForTcpCheckBox.Checked) - { - Utils.Utils.ChangeControlForeColor(STUN_ServerComboBox, Color.Red); - MessageBoxX.Show("TCP&UDP只允许勾选一个"); - return; - } - - #endregion - #region Save foreach (var pair in _saveActions) @@ -432,7 +429,13 @@ private void BindCheckBox(CheckBox control, Action save, bool value) { control.Checked = value; _checkActions.Add(control, s => true); - _saveActions.Add(control, c => save.Invoke(((CheckBox) c).Checked)); + _saveActions.Add(control, c => save.Invoke(((CheckBox)c).Checked)); + } + private void BindRadioBox(RadioButton control, Action save, bool value) + { + control.Checked = value; + _checkActions.Add(control, s => true); + _saveActions.Add(control, c => save.Invoke(((RadioButton)c).Checked)); } private readonly Dictionary> _checkActions = new Dictionary>(); @@ -443,5 +446,25 @@ private void ModifySystemDNSCheckBox_CheckedChanged(object sender, EventArgs e) { ModifiedDNSTextBox.Enabled = ModifySystemDNSCheckBox.Checked; } + + private void NoProxyForUdpCheckBox_CheckedChanged(object sender, EventArgs e) + { + if (NoProxyForUdpCheckBox.Checked) NoProxyForTcpCheckBox.Checked = false; + } + + private void NoProxyForTcpCheckBox_CheckedChanged(object sender, EventArgs e) + { + if (NoProxyForTcpCheckBox.Checked) NoProxyForUdpCheckBox.Checked = false; + } + + private void ICMPingRadioBtn_CheckedChanged(object sender, EventArgs e) + { + if (ICMPingRadioBtn.Checked) TCPingRadioBtn.Checked = false; + } + + private void TCPingRadioBtn_CheckedChanged(object sender, EventArgs e) + { + if (TCPingRadioBtn.Checked) ICMPingRadioBtn.Checked = false; + } } } \ No newline at end of file diff --git a/Netch/Models/Server.cs b/Netch/Models/Server.cs index 0041182d80..2d5fdbb0a0 100644 --- a/Netch/Models/Server.cs +++ b/Netch/Models/Server.cs @@ -4,7 +4,7 @@ namespace Netch.Models { - public class Server:ICloneable + public class Server : ICloneable { /// /// 备注 @@ -81,7 +81,7 @@ public int Test() { try { - return await Utils.Utils.TCPingAsync(destination, Port); + return Global.Settings.ServerTCPing ? await Utils.Utils.TCPingAsync(destination, Port) : await Utils.Utils.ICMPing(destination, Port); } catch (Exception) { diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index dd010eae7d..84fc0815c4 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -272,6 +272,11 @@ public class Setting /// public string Language = "System"; + /// + /// 服务器测试方式 false.ICMPing true.TCPing + /// + public bool ServerTCPing = true; + /// /// 是否使用RDR内置SS /// diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 9a58125870..1a7b2e8ca9 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -171,6 +171,7 @@ "Failed to set the system proxy, it may be caused by the lack of dependent programs. Do you want to jump to Netch's official website to download dependent programs?": "设置系统代理失败,可能是缺少依赖导致,是否跳转 Netch 官网下载依赖程序?", "Delay test after start": "启动后延迟测试", "Enable": "启用", + "ServerPingType": "测速方式", "Detection interval(sec)": "检测间隔(秒)", "STUN Server": "STUN 服务器", "STUN Server Port": "STUN 服务器端口", diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index 60dfff541f..7baeda19ad 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -56,7 +56,7 @@ public static async Task TCPingAsync(IPAddress ip, int port, int timeout = return timeout; } - public static int ICMPing(IPAddress ip, int timeout = 1000) + public static async Task ICMPing(IPAddress ip, int timeout = 1000) { var reply = new Ping().Send(ip, timeout);