Add TAP Adapter Internet Network Sharing Setting(ICS)

This commit is contained in:
ChsBuffer
2020-09-22 17:57:26 +08:00
parent 48d543ce65
commit 8b7ce23a82
7 changed files with 540 additions and 3 deletions

View File

@@ -2,7 +2,9 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
using Netch.Controllers;
using Netch.Utils;
using TaskScheduler;
@@ -36,6 +38,7 @@ namespace Netch.Forms
TUNTAPUseCustomDNSCheckBox_CheckedChanged(null, null);
ProxyDNSCheckBox.Checked = Global.Settings.TUNTAP.ProxyDNS;
UseFakeDNSCheckBox.Checked = Global.Settings.TUNTAP.UseFakeDNS;
ICSCheckBox.Checked = ICSController.Enabled;
// Behavior
ExitWhenClosedCheckBox.Checked = Global.Settings.ExitWhenClosed;
@@ -64,7 +67,9 @@ namespace Netch.Forms
if (UseCustomDNSCheckBox.Checked)
{
TUNTAPDNSTextBox.Text = Global.Settings.TUNTAP.DNS.Any() ? Global.Settings.TUNTAP.DNS.Aggregate((current, ip) => $"{current},{ip}") : "1.1.1.1";
TUNTAPDNSTextBox.Text = Global.Settings.TUNTAP.DNS.Any()
? Global.Settings.TUNTAP.DNS.Aggregate((current, ip) => $"{current},{ip}")
: "1.1.1.1";
}
else
{
@@ -195,7 +200,8 @@ namespace Netch.Forms
if (UseCustomDNSCheckBox.Checked)
{
dns = TUNTAPDNSTextBox.Text.Split(',').Where(s => !string.IsNullOrEmpty(s)).Select(s => s.Trim()).ToArray();
dns = TUNTAPDNSTextBox.Text.Split(',').Where(s => !string.IsNullOrEmpty(s)).Select(s => s.Trim())
.ToArray();
if (dns.Any())
{
foreach (var ip in dns)
@@ -401,5 +407,22 @@ namespace Netch.Forms
MessageBoxX.Show(i18N.Translate("Saved"));
Close();
}
private async void ICSCheckBox_CheckedChanged(object sender, EventArgs e)
{
ICSCheckBox.Enabled = false;
await Task.Run(() =>
{
if (ICSCheckBox.Checked)
{
ICSCheckBox.Checked = ICSController.Enable();
}
else
{
ICSController.Disable();
}
});
ICSCheckBox.Enabled = true;
}
}
}