mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
reafactor: ICS Check State
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user