Skip to content

Commit

Permalink
添加测速方式(TCPing&ICMPing)切换设置选项
Browse files Browse the repository at this point in the history
  • Loading branch information
AmazingDM committed Jan 4, 2021
1 parent ce15e94 commit 35b9f16
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 18 deletions.
51 changes: 48 additions & 3 deletions Netch/Forms/SettingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 35 additions & 12 deletions Netch/Forms/SettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(ProfileCountTextBox,
i => i > -1,
i => Global.Settings.ProfileCount = i,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -432,7 +429,13 @@ private void BindCheckBox(CheckBox control, Action<bool> 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<bool> save, bool value)
{
control.Checked = value;
_checkActions.Add(control, s => true);
_saveActions.Add(control, c => save.Invoke(((RadioButton)c).Checked));
}

private readonly Dictionary<Control, Func<string, bool>> _checkActions = new Dictionary<Control, Func<string, bool>>();
Expand All @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions Netch/Models/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Netch.Models
{
public class Server:ICloneable
public class Server : ICloneable
{
/// <summary>
/// 备注
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions Netch/Models/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ public class Setting
/// </summary>
public string Language = "System";

/// <summary>
/// 服务器测试方式 false.ICMPing true.TCPing
/// </summary>
public bool ServerTCPing = true;

/// <summary>
/// 是否使用RDR内置SS
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Netch/Resources/zh-CN
Original file line number Diff line number Diff line change
Expand Up @@ -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 服务器端口",
Expand Down
2 changes: 1 addition & 1 deletion Netch/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static async Task<int> TCPingAsync(IPAddress ip, int port, int timeout =
return timeout;
}

public static int ICMPing(IPAddress ip, int timeout = 1000)
public static async Task<int> ICMPing(IPAddress ip, int timeout = 1000)
{
var reply = new Ping().Send(ip, timeout);

Expand Down

0 comments on commit 35b9f16

Please sign in to comment.