reafactor: ICS Check State

This commit is contained in:
ChsBuffer
2020-10-08 20:30:42 +08:00
parent 3efbad5e5e
commit 75bf753a65
2 changed files with 14 additions and 10 deletions

View File

@@ -39,10 +39,11 @@ namespace Netch.Forms
ProxyDNSCheckBox.Checked = Global.Settings.TUNTAP.ProxyDNS;
UseFakeDNSCheckBox.Checked = Global.Settings.TUNTAP.UseFakeDNS;
if (TUNTAPController.SearchTapAdapter())
var icsHelperEnabled = ICSHelper.Enabled;
if (icsHelperEnabled != null)
{
ICSCheckBox.Enabled = true;
ICSCheckBox.Checked = ICSHelper.Enabled;
ICSCheckBox.Checked = (bool) icsHelperEnabled;
}
// Behavior
@@ -392,7 +393,7 @@ namespace Netch.Forms
{
if (ICSCheckBox.Checked)
{
if (!ICSHelper.Enabled)
if (!(ICSHelper.Enabled ?? true))
ICSCheckBox.Checked = ICSHelper.Enable();
}
else

View File

@@ -9,16 +9,19 @@ namespace Netch.Utils
{
public static class ICSHelper
{
public static bool Enabled
public static bool? Enabled
{
get
{
TUNTAPController.SearchTapAdapter();
return (
from NetworkConnection connection in new NetworkConnectionCollection()
where connection.DeviceName == Global.TUNTAP.Adapter.Description
select connection.SharingEnabled
).FirstOrDefault();
if (Global.TUNTAP.Adapter == null)
TUNTAPController.SearchTapAdapter();
foreach (var connection in new NetworkConnectionCollection().Cast<NetworkConnection>().Where(connection => connection.DeviceName == Global.TUNTAP.Adapter?.Description))
{
return connection.SharingEnabled;
}
return null;
}
}