public VpnRoute() { Tunnel = new NetIntf(TapDeviceFunc.GetTapDevice(Program.UserConfig.TapIntfaceName)); var intf = Diagnostic.GetBestInterface(Program.UserConfig.CurrentProfile.ServerIp); _origin = intf == null ? new NetIntf(IPNetHelper.GetBestIntf(Program.UserConfig.CurrentProfile.ServerIp.ToUInt32())) : new NetIntf(intf); _chnRouteOn = false; _originGateway = GetGateway(); }
public bool SelfCheck() { if (string.IsNullOrEmpty(TapIntfaceName)) { return(false); } if (Profiles == null) { Profiles = new Dictionary <string, Profile>(); CurrentProfileName = ""; } else if (Profiles.Count == 0) { if (!string.IsNullOrEmpty(CurrentProfileName)) { return(false); } } else { if (!Profiles.ContainsKey(CurrentProfileName)) { return(false); } } if (TapDeviceFunc.GetTapDevice(TapIntfaceName) == null) { Logger.Error("vpnConfig.intf not found in system."); var adapter = TapDeviceFunc.GetTapDevice(); if (adapter != null) { if (Regex.IsMatch(adapter.Name, @"^[a-zA-Z0-9]+$")) { Logger.Info($"Changing vpnConfig.intf to {adapter.Name}"); TapIntfaceName = adapter.Name; } } else { return(false); } } return(Profiles.Values.All(profile => profile.SelfCheck())); }
private async void fTapChecker_Load(object sender, EventArgs e) { bool overall = true; try { lbMsg.Text = @"检查Tap-Windows是否安装……"; if (TapDeviceFunc.CheckTapWindowsIntall()) { lbMsg.Text += "OK\n"; } else { lbMsg.Text += "Fail\n"; overall = false; lbMsg.Text += @"正在安装Tap设备……"; Task t = new Task(TapDeviceFunc.InstallTapDriver); t.Start(); await t; lbMsg.Text += "OK\n"; overall = true; } lbMsg.Text += @"获取Tap设备……"; var adapter = TapDeviceFunc.GetTapDevice(); if (adapter != null) { lbMsg.Text += "OK\n"; lbMsg.Text += @"检查Tap设备名……"; if (Regex.IsMatch(adapter.Name, @"^[a-zA-Z0-9]+$")) { lbMsg.Text += "OK\n"; } else { lbMsg.Text += $"Fail({adapter.Name})\n"; overall = false; lbMsg.Text += @"更改Tap设备名……"; Task t = new Task(() => { TapDeviceFunc.RenameTapDevice(TapDeviceFunc.DefaultTapDeviceName, adapter); }); t.Start(); await t; lbMsg.Text += "OK\n"; overall = true; } } else { lbMsg.Text += "Fail\n"; overall = false; lbMsg.Text += @"添加Tap设备……"; Task t = new Task(TapDeviceFunc.AddTapDevice); t.Start(); await t; adapter = TapDeviceFunc.GetTapDevice(); if (adapter == null) { lbMsg.Text += "Fail\n"; lbMsg.Text += @"正在安装Tap设备……"; t = new Task(TapDeviceFunc.InstallTapDriver); t.Start(); await t; lbMsg.Text += "OK\n"; } lbMsg.Text += @"获取Tap设备……"; adapter = TapDeviceFunc.GetTapDevice(); if (adapter == null) { lbMsg.Text += "Fail\n"; overall = false; Logger.Error("Can not get TapDevice anyway"); TapDeviceFunc.TraceNetworkInterface(); } else { TapDeviceFunc.RenameTapDevice(TapDeviceFunc.DefaultTapDeviceName, adapter); lbMsg.Text += "OK\n"; overall = true; } } } catch (Exception ex) { Logger.Error(ex.Message); Logger.Debug(ex.StackTrace); } finally { TapDeviceFunc.GetSetupLog(); if (overall) { lbMsg.Text += @"硬件检测成功,一切就绪,点击此处退出程序。"; } else { lbMsg.Text += "\n"; lbMsg.Text += @"硬件检测出错误,修复失败,正在生成诊断报告……"; new DiagnosticProgress().ShowDialog(this); lbMsg.Text += @"生成完毕,点击此处退出程序。"; } lbMsg.Click += (_sender, _e) => { Application.Exit(); }; } }