diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 0854bebe..e95831c6 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; +using System.Threading; using System.Threading.Tasks; namespace Netch.Controllers diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs index 4cd94fb2..ead673e1 100644 --- a/Netch/Controllers/NFController.cs +++ b/Netch/Controllers/NFController.cs @@ -32,6 +32,9 @@ namespace Netch.Controllers /// public Models.State State = Models.State.Waiting; + // 生成驱动文件路径 + public string driverPath = string.Format("{0}\\drivers\\netfilter2.sys", Environment.SystemDirectory); + /// /// 启动 /// @@ -41,85 +44,56 @@ namespace Netch.Controllers public bool Start(Models.Server server, Models.Mode mode) { MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Redirector")}"); - if (!File.Exists("bin\\Redirector.exe")) + + // 检查驱动是否存在 + if (File.Exists(driverPath)) { - return false; - } - - // 生成驱动文件路径 - var driver = string.Format("{0}\\drivers\\netfilter2.sys", Environment.SystemDirectory); - - if (File.Exists(driver)) - { - //为了防止小白一直问如何卸载老驱动核心,每次启动时卸载删除一次驱动,保证系统使用最新驱动核心(简单粗暴 但有效:D。增加启动成功率,驱动在被其他加速器占用的情况下可能会导致启动失败 - try + //检查驱动版本号 + FileVersionInfo fileVerInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(driverPath); + if (new Version(fileVerInfo.FileVersion) < new Version(UpdateChecker.NFDriverVersion)) { - var service = new ServiceController("netfilter2"); - if (service.Status == ServiceControllerStatus.Running) + //需要更新驱动 + try { - service.Stop(); - service.WaitForStatus(ServiceControllerStatus.Stopped); - } - nfapinet.NFAPI.nf_unRegisterDriver("netfilter2"); + var service = new ServiceController("netfilter2"); + if (service.Status == ServiceControllerStatus.Running) + { + service.Stop(); + service.WaitForStatus(ServiceControllerStatus.Stopped); + } + nfapinet.NFAPI.nf_unRegisterDriver("netfilter2"); - File.Delete(driver); - } - catch (Exception) - { - // 跳过 - } - - // 生成系统版本 - var version = $"{Environment.OSVersion.Version.Major.ToString()}.{Environment.OSVersion.Version.Minor.ToString()}"; - - // 检查系统版本并复制对应驱动 - try - { - switch (version) - { - case "10.0": - File.Copy("bin\\Win-10.sys", driver); - Utils.Logging.Info("已复制 Win10 驱动"); - break; - case "6.3": - case "6.2": - File.Copy("bin\\Win-8.sys", driver); - Utils.Logging.Info("已复制 Win8 驱动"); - break; - case "6.1": - case "6.0": - File.Copy("bin\\Win-7.sys", driver); - Utils.Logging.Info("已复制 Win7 驱动"); - break; - default: - Utils.Logging.Info($"不支持的系统版本:{version}"); + //删除老驱动 + File.Delete(driverPath); + if (!InstallDriver()) return false; } - } - catch (Exception e) - { - Utils.Logging.Info("复制驱动文件失败"); - Utils.Logging.Info(e.ToString()); - return false; + catch (Exception) + { + Utils.Logging.Info($"更新驱动出错"); + } + } - // 注册驱动文件 - var result = nfapinet.NFAPI.nf_registerDriver("netfilter2"); - if (result != nfapinet.NF_STATUS.NF_STATUS_SUCCESS) - { - Utils.Logging.Info($"注册驱动失败,返回值:{result}"); - return false; - } } - // 检查驱动是否存在 - /*if (!File.Exists(driver)) + else { - }*/ + if (!InstallDriver()) + return false; + } try { + //启动驱动服务 var service = new ServiceController("netfilter2"); - if (service.Status == ServiceControllerStatus.Stopped) + if (service.Status == ServiceControllerStatus.Running) + { + //防止其他程序占用 + service.Stop(); + MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting netfilter2 Service")}"); + service.Start(); + } + else if (service.Status == ServiceControllerStatus.Stopped) { MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting netfilter2 Service")}"); service.Start(); @@ -147,28 +121,69 @@ namespace Netch.Controllers processes = processes.Substring(0, processes.Length - 1); Instance = MainController.GetProcess(); - Instance.StartInfo.FileName = "bin\\Redirector.exe"; - var fallback = ""; - if (server.Type != "Socks5") + if (Global.Settings.UseRedirector2) { - fallback = $"-r 127.0.0.1:{Global.Settings.Socks5LocalPort} -p \"{processes}\""; + if (!File.Exists("bin\\Redirector2.exe")) + { + return false; + } + Instance.StartInfo.FileName = "bin\\Redirector2.exe"; + + + if (server.Type != "Socks5") + { + fallback += $" 127.0.0.1:{Global.Settings.Socks5LocalPort}"; + fallback += $" \"{processes}\""; + } + else + { + var result = Utils.DNS.Lookup(server.Hostname); + if (result == null) + { + Utils.Logging.Info("无法解析服务器 IP 地址"); + return false; + } + + fallback += $" {result}:{server.Port}"; + fallback += $" \"{processes}\""; + + if (!string.IsNullOrWhiteSpace(server.Username) && !string.IsNullOrWhiteSpace(server.Password)) + { + fallback += $" \"{server.Username}\""; + fallback += $" \"{server.Password}\""; + } + } } else { - var result = Utils.DNS.Lookup(server.Hostname); - if (result == null) + if (!File.Exists("bin\\Redirector.exe")) { - Utils.Logging.Info("无法解析服务器 IP 地址"); return false; } + Instance.StartInfo.FileName = "bin\\Redirector.exe"; - fallback = $"-r {result}:{server.Port} -p \"{processes}\""; - if (!string.IsNullOrWhiteSpace(server.Username) && !string.IsNullOrWhiteSpace(server.Password)) + if (server.Type != "Socks5") { - fallback += $" -username \"{server.Username}\" -password \"{server.Password}\""; + fallback = $"-r 127.0.0.1:{Global.Settings.Socks5LocalPort} -p \"{processes}\""; + } + else + { + var result = Utils.DNS.Lookup(server.Hostname); + if (result == null) + { + Utils.Logging.Info("无法解析服务器 IP 地址"); + return false; + } + + fallback = $"-r {result}:{server.Port} -p \"{processes}\""; + + if (!string.IsNullOrWhiteSpace(server.Username) && !string.IsNullOrWhiteSpace(server.Password)) + { + fallback += $" -username \"{server.Username}\" -password \"{server.Password}\""; + } } } @@ -213,6 +228,52 @@ namespace Netch.Controllers Utils.Logging.Info(e.ToString()); } } + public bool InstallDriver() + { + + // 生成系统版本 + var version = $"{Environment.OSVersion.Version.Major.ToString()}.{Environment.OSVersion.Version.Minor.ToString()}"; + + // 检查系统版本并复制对应驱动 + try + { + switch (version) + { + case "10.0": + File.Copy("bin\\Win-10.sys", driverPath); + Utils.Logging.Info("已复制 Win10 驱动"); + break; + case "6.3": + case "6.2": + File.Copy("bin\\Win-8.sys", driverPath); + Utils.Logging.Info("已复制 Win8 驱动"); + break; + case "6.1": + case "6.0": + File.Copy("bin\\Win-7.sys", driverPath); + Utils.Logging.Info("已复制 Win7 驱动"); + break; + default: + Utils.Logging.Info($"不支持的系统版本:{version}"); + return false; + } + } + catch (Exception e) + { + Utils.Logging.Info("复制驱动文件失败"); + Utils.Logging.Info(e.ToString()); + return false; + } + MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Register driver")}"); + // 注册驱动文件 + var result = nfapinet.NFAPI.nf_registerDriver("netfilter2"); + if (result != nfapinet.NF_STATUS.NF_STATUS_SUCCESS) + { + Utils.Logging.Info($"注册驱动失败,返回值:{result}"); + return false; + } + return true; + } public void OnOutputDataReceived(object sender, DataReceivedEventArgs e) { @@ -226,7 +287,7 @@ namespace Netch.Controllers { State = Models.State.Stopped; } - else if (e.Data.Contains("Started") || e.Data.Contains("Redirect to")) + else if (e.Data.Contains("Start") || e.Data.Contains("Redirect to")) { State = Models.State.Started; } diff --git a/Netch/Controllers/NTTController.cs b/Netch/Controllers/NTTController.cs index 090d0cfa..82843cab 100644 --- a/Netch/Controllers/NTTController.cs +++ b/Netch/Controllers/NTTController.cs @@ -24,6 +24,7 @@ namespace Netch.Controllers /// public (bool, string, string, string) Start() { + Thread.Sleep(1000); MainForm.Instance.NatTypeStatusText($"{Utils.i18N.Translate("Starting NatTester")}"); try { diff --git a/Netch/Controllers/UpdateChecker.cs b/Netch/Controllers/UpdateChecker.cs index 43d6cc9e..fea6242a 100644 --- a/Netch/Controllers/UpdateChecker.cs +++ b/Netch/Controllers/UpdateChecker.cs @@ -27,6 +27,7 @@ namespace Netch.Controllers public const string Name = @"Netch"; public const string Copyright = @"Copyright © 2019 - 2020"; public const string Version = @"1.4.0"; + public const string NFDriverVersion = @"1.5.9.0"; public async void Check(bool notifyNoFound, bool isPreRelease) { diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 9a85e998..8339a931 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -49,6 +49,8 @@ this.ControlButton = new System.Windows.Forms.Button(); this.GlobalBypassIPsButton = new System.Windows.Forms.Button(); this.BehaviorGroupBox = new System.Windows.Forms.GroupBox(); + this.Redirector2checkBox = new System.Windows.Forms.CheckBox(); + this.label3 = new System.Windows.Forms.Label(); this.STUN_ServerPortTextBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); @@ -73,11 +75,9 @@ this.PortGroupBox.Controls.Add(this.HTTPPortTextBox); this.PortGroupBox.Controls.Add(this.Socks5PortLabel); this.PortGroupBox.Controls.Add(this.Socks5PortTextBox); - this.PortGroupBox.Location = new System.Drawing.Point(18, 18); - this.PortGroupBox.Margin = new System.Windows.Forms.Padding(4); + this.PortGroupBox.Location = new System.Drawing.Point(12, 12); this.PortGroupBox.Name = "PortGroupBox"; - this.PortGroupBox.Padding = new System.Windows.Forms.Padding(4); - this.PortGroupBox.Size = new System.Drawing.Size(630, 210); + this.PortGroupBox.Size = new System.Drawing.Size(420, 140); this.PortGroupBox.TabIndex = 0; this.PortGroupBox.TabStop = false; this.PortGroupBox.Text = "Local Port"; @@ -85,10 +85,9 @@ // AllowDevicesCheckBox // this.AllowDevicesCheckBox.AutoSize = true; - this.AllowDevicesCheckBox.Location = new System.Drawing.Point(180, 120); - this.AllowDevicesCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.AllowDevicesCheckBox.Location = new System.Drawing.Point(120, 80); this.AllowDevicesCheckBox.Name = "AllowDevicesCheckBox"; - this.AllowDevicesCheckBox.Size = new System.Drawing.Size(301, 28); + this.AllowDevicesCheckBox.Size = new System.Drawing.Size(206, 21); this.AllowDevicesCheckBox.TabIndex = 5; this.AllowDevicesCheckBox.Text = "Allow other Devices to connect"; this.AllowDevicesCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -97,38 +96,34 @@ // HTTPPortLabel // this.HTTPPortLabel.AutoSize = true; - this.HTTPPortLabel.Location = new System.Drawing.Point(14, 81); - this.HTTPPortLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.HTTPPortLabel.Location = new System.Drawing.Point(9, 54); this.HTTPPortLabel.Name = "HTTPPortLabel"; - this.HTTPPortLabel.Size = new System.Drawing.Size(55, 24); + this.HTTPPortLabel.Size = new System.Drawing.Size(38, 17); this.HTTPPortLabel.TabIndex = 3; this.HTTPPortLabel.Text = "HTTP"; // // HTTPPortTextBox // - this.HTTPPortTextBox.Location = new System.Drawing.Point(180, 76); - this.HTTPPortTextBox.Margin = new System.Windows.Forms.Padding(4); + this.HTTPPortTextBox.Location = new System.Drawing.Point(120, 51); this.HTTPPortTextBox.Name = "HTTPPortTextBox"; - this.HTTPPortTextBox.Size = new System.Drawing.Size(439, 31); + this.HTTPPortTextBox.Size = new System.Drawing.Size(294, 23); this.HTTPPortTextBox.TabIndex = 4; this.HTTPPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // Socks5PortLabel // this.Socks5PortLabel.AutoSize = true; - this.Socks5PortLabel.Location = new System.Drawing.Point(14, 38); - this.Socks5PortLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.Socks5PortLabel.Location = new System.Drawing.Point(9, 25); this.Socks5PortLabel.Name = "Socks5PortLabel"; - this.Socks5PortLabel.Size = new System.Drawing.Size(69, 24); + this.Socks5PortLabel.Size = new System.Drawing.Size(49, 17); this.Socks5PortLabel.TabIndex = 0; this.Socks5PortLabel.Text = "Socks5"; // // Socks5PortTextBox // - this.Socks5PortTextBox.Location = new System.Drawing.Point(180, 33); - this.Socks5PortTextBox.Margin = new System.Windows.Forms.Padding(4); + this.Socks5PortTextBox.Location = new System.Drawing.Point(120, 22); this.Socks5PortTextBox.Name = "Socks5PortTextBox"; - this.Socks5PortTextBox.Size = new System.Drawing.Size(439, 31); + this.Socks5PortTextBox.Size = new System.Drawing.Size(294, 23); this.Socks5PortTextBox.TabIndex = 1; this.Socks5PortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // @@ -144,11 +139,9 @@ this.TUNTAPGroupBox.Controls.Add(this.TUNTAPNetmaskTextBox); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPAddressLabel); this.TUNTAPGroupBox.Controls.Add(this.TUNTAPAddressTextBox); - this.TUNTAPGroupBox.Location = new System.Drawing.Point(18, 237); - this.TUNTAPGroupBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPGroupBox.Location = new System.Drawing.Point(12, 158); this.TUNTAPGroupBox.Name = "TUNTAPGroupBox"; - this.TUNTAPGroupBox.Padding = new System.Windows.Forms.Padding(4); - this.TUNTAPGroupBox.Size = new System.Drawing.Size(630, 281); + this.TUNTAPGroupBox.Size = new System.Drawing.Size(420, 187); this.TUNTAPGroupBox.TabIndex = 3; this.TUNTAPGroupBox.TabStop = false; this.TUNTAPGroupBox.Text = "TUN/TAP"; @@ -156,10 +149,9 @@ // TUNTAPProxyDNSCheckBox // this.TUNTAPProxyDNSCheckBox.AutoSize = true; - this.TUNTAPProxyDNSCheckBox.Location = new System.Drawing.Point(180, 243); - this.TUNTAPProxyDNSCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPProxyDNSCheckBox.Location = new System.Drawing.Point(120, 162); this.TUNTAPProxyDNSCheckBox.Name = "TUNTAPProxyDNSCheckBox"; - this.TUNTAPProxyDNSCheckBox.Size = new System.Drawing.Size(221, 28); + this.TUNTAPProxyDNSCheckBox.Size = new System.Drawing.Size(153, 21); this.TUNTAPProxyDNSCheckBox.TabIndex = 10; this.TUNTAPProxyDNSCheckBox.Text = "Proxy DNS in Mode 2"; this.TUNTAPProxyDNSCheckBox.UseVisualStyleBackColor = true; @@ -167,10 +159,9 @@ // TUNTAPUseCustomDNSCheckBox // this.TUNTAPUseCustomDNSCheckBox.AutoSize = true; - this.TUNTAPUseCustomDNSCheckBox.Location = new System.Drawing.Point(180, 207); - this.TUNTAPUseCustomDNSCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPUseCustomDNSCheckBox.Location = new System.Drawing.Point(120, 138); this.TUNTAPUseCustomDNSCheckBox.Name = "TUNTAPUseCustomDNSCheckBox"; - this.TUNTAPUseCustomDNSCheckBox.Size = new System.Drawing.Size(182, 28); + this.TUNTAPUseCustomDNSCheckBox.Size = new System.Drawing.Size(127, 21); this.TUNTAPUseCustomDNSCheckBox.TabIndex = 9; this.TUNTAPUseCustomDNSCheckBox.Text = "Use Custom DNS"; this.TUNTAPUseCustomDNSCheckBox.UseVisualStyleBackColor = true; @@ -179,86 +170,77 @@ // TUNTAPDNSLabel // this.TUNTAPDNSLabel.AutoSize = true; - this.TUNTAPDNSLabel.Location = new System.Drawing.Point(14, 168); - this.TUNTAPDNSLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.TUNTAPDNSLabel.Location = new System.Drawing.Point(9, 112); this.TUNTAPDNSLabel.Name = "TUNTAPDNSLabel"; - this.TUNTAPDNSLabel.Size = new System.Drawing.Size(49, 24); + this.TUNTAPDNSLabel.Size = new System.Drawing.Size(34, 17); this.TUNTAPDNSLabel.TabIndex = 7; this.TUNTAPDNSLabel.Text = "DNS"; // // TUNTAPDNSTextBox // - this.TUNTAPDNSTextBox.Location = new System.Drawing.Point(180, 165); - this.TUNTAPDNSTextBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPDNSTextBox.Location = new System.Drawing.Point(120, 110); this.TUNTAPDNSTextBox.Name = "TUNTAPDNSTextBox"; - this.TUNTAPDNSTextBox.Size = new System.Drawing.Size(439, 31); + this.TUNTAPDNSTextBox.Size = new System.Drawing.Size(294, 23); this.TUNTAPDNSTextBox.TabIndex = 8; this.TUNTAPDNSTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPGatewayLabel // this.TUNTAPGatewayLabel.AutoSize = true; - this.TUNTAPGatewayLabel.Location = new System.Drawing.Point(14, 124); - this.TUNTAPGatewayLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.TUNTAPGatewayLabel.Location = new System.Drawing.Point(9, 83); this.TUNTAPGatewayLabel.Name = "TUNTAPGatewayLabel"; - this.TUNTAPGatewayLabel.Size = new System.Drawing.Size(84, 24); + this.TUNTAPGatewayLabel.Size = new System.Drawing.Size(57, 17); this.TUNTAPGatewayLabel.TabIndex = 5; this.TUNTAPGatewayLabel.Text = "Gateway"; // // TUNTAPGatewayTextBox // - this.TUNTAPGatewayTextBox.Location = new System.Drawing.Point(180, 120); - this.TUNTAPGatewayTextBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPGatewayTextBox.Location = new System.Drawing.Point(120, 80); this.TUNTAPGatewayTextBox.Name = "TUNTAPGatewayTextBox"; - this.TUNTAPGatewayTextBox.Size = new System.Drawing.Size(439, 31); + this.TUNTAPGatewayTextBox.Size = new System.Drawing.Size(294, 23); this.TUNTAPGatewayTextBox.TabIndex = 6; this.TUNTAPGatewayTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPNetmaskLabel // this.TUNTAPNetmaskLabel.AutoSize = true; - this.TUNTAPNetmaskLabel.Location = new System.Drawing.Point(14, 81); - this.TUNTAPNetmaskLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.TUNTAPNetmaskLabel.Location = new System.Drawing.Point(9, 54); this.TUNTAPNetmaskLabel.Name = "TUNTAPNetmaskLabel"; - this.TUNTAPNetmaskLabel.Size = new System.Drawing.Size(87, 24); + this.TUNTAPNetmaskLabel.Size = new System.Drawing.Size(60, 17); this.TUNTAPNetmaskLabel.TabIndex = 3; this.TUNTAPNetmaskLabel.Text = "Netmask"; // // TUNTAPNetmaskTextBox // - this.TUNTAPNetmaskTextBox.Location = new System.Drawing.Point(180, 76); - this.TUNTAPNetmaskTextBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPNetmaskTextBox.Location = new System.Drawing.Point(120, 51); this.TUNTAPNetmaskTextBox.Name = "TUNTAPNetmaskTextBox"; - this.TUNTAPNetmaskTextBox.Size = new System.Drawing.Size(439, 31); + this.TUNTAPNetmaskTextBox.Size = new System.Drawing.Size(294, 23); this.TUNTAPNetmaskTextBox.TabIndex = 4; this.TUNTAPNetmaskTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // TUNTAPAddressLabel // this.TUNTAPAddressLabel.AutoSize = true; - this.TUNTAPAddressLabel.Location = new System.Drawing.Point(14, 38); - this.TUNTAPAddressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.TUNTAPAddressLabel.Location = new System.Drawing.Point(9, 25); this.TUNTAPAddressLabel.Name = "TUNTAPAddressLabel"; - this.TUNTAPAddressLabel.Size = new System.Drawing.Size(80, 24); + this.TUNTAPAddressLabel.Size = new System.Drawing.Size(56, 17); this.TUNTAPAddressLabel.TabIndex = 1; this.TUNTAPAddressLabel.Text = "Address"; // // TUNTAPAddressTextBox // - this.TUNTAPAddressTextBox.Location = new System.Drawing.Point(180, 33); - this.TUNTAPAddressTextBox.Margin = new System.Windows.Forms.Padding(4); + this.TUNTAPAddressTextBox.Location = new System.Drawing.Point(120, 22); this.TUNTAPAddressTextBox.Name = "TUNTAPAddressTextBox"; - this.TUNTAPAddressTextBox.Size = new System.Drawing.Size(439, 31); + this.TUNTAPAddressTextBox.Size = new System.Drawing.Size(294, 23); this.TUNTAPAddressTextBox.TabIndex = 2; this.TUNTAPAddressTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // ControlButton // this.ControlButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.ControlButton.Location = new System.Drawing.Point(536, 1018); - this.ControlButton.Margin = new System.Windows.Forms.Padding(4); + this.ControlButton.Location = new System.Drawing.Point(357, 679); this.ControlButton.Name = "ControlButton"; - this.ControlButton.Size = new System.Drawing.Size(112, 34); + this.ControlButton.Size = new System.Drawing.Size(75, 23); this.ControlButton.TabIndex = 11; this.ControlButton.Text = "Save"; this.ControlButton.UseVisualStyleBackColor = true; @@ -267,10 +249,9 @@ // GlobalBypassIPsButton // this.GlobalBypassIPsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.GlobalBypassIPsButton.Location = new System.Drawing.Point(18, 1018); - this.GlobalBypassIPsButton.Margin = new System.Windows.Forms.Padding(4); + this.GlobalBypassIPsButton.Location = new System.Drawing.Point(12, 679); this.GlobalBypassIPsButton.Name = "GlobalBypassIPsButton"; - this.GlobalBypassIPsButton.Size = new System.Drawing.Size(192, 34); + this.GlobalBypassIPsButton.Size = new System.Drawing.Size(128, 23); this.GlobalBypassIPsButton.TabIndex = 10; this.GlobalBypassIPsButton.Text = "Global Bypass IPs"; this.GlobalBypassIPsButton.UseVisualStyleBackColor = true; @@ -278,6 +259,8 @@ // // BehaviorGroupBox // + this.BehaviorGroupBox.Controls.Add(this.Redirector2checkBox); + this.BehaviorGroupBox.Controls.Add(this.label3); this.BehaviorGroupBox.Controls.Add(this.STUN_ServerPortTextBox); this.BehaviorGroupBox.Controls.Add(this.label2); this.BehaviorGroupBox.Controls.Add(this.label1); @@ -290,71 +273,82 @@ this.BehaviorGroupBox.Controls.Add(this.StartWhenOpenedCheckBox); this.BehaviorGroupBox.Controls.Add(this.StopWhenExitedCheckBox); this.BehaviorGroupBox.Controls.Add(this.ExitWhenClosedCheckBox); - this.BehaviorGroupBox.Location = new System.Drawing.Point(18, 526); - this.BehaviorGroupBox.Margin = new System.Windows.Forms.Padding(4); + this.BehaviorGroupBox.Location = new System.Drawing.Point(12, 351); this.BehaviorGroupBox.Name = "BehaviorGroupBox"; - this.BehaviorGroupBox.Padding = new System.Windows.Forms.Padding(4); - this.BehaviorGroupBox.Size = new System.Drawing.Size(630, 468); + this.BehaviorGroupBox.Size = new System.Drawing.Size(420, 312); this.BehaviorGroupBox.TabIndex = 8; this.BehaviorGroupBox.TabStop = false; this.BehaviorGroupBox.Text = "Behavior"; // + // Redirector2checkBox + // + this.Redirector2checkBox.AutoSize = true; + this.Redirector2checkBox.Location = new System.Drawing.Point(120, 266); + this.Redirector2checkBox.Name = "Redirector2checkBox"; + this.Redirector2checkBox.Size = new System.Drawing.Size(118, 21); + this.Redirector2checkBox.TabIndex = 11; + this.Redirector2checkBox.Text = "是否启用2号核心"; + this.Redirector2checkBox.UseVisualStyleBackColor = true; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 267); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(68, 17); + this.label3.TabIndex = 13; + this.label3.Text = "实验性功能"; + // // STUN_ServerPortTextBox // - this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(180, 356); - this.STUN_ServerPortTextBox.Margin = new System.Windows.Forms.Padding(4); + this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(120, 237); this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox"; - this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(439, 31); + this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(294, 23); this.STUN_ServerPortTextBox.TabIndex = 8; this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(14, 364); - this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Location = new System.Drawing.Point(9, 243); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(157, 24); + this.label2.Size = new System.Drawing.Size(110, 17); this.label2.TabIndex = 12; this.label2.Text = "STUN Server Port"; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(14, 321); - this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Location = new System.Drawing.Point(9, 214); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(116, 24); + this.label1.Size = new System.Drawing.Size(82, 17); this.label1.TabIndex = 10; this.label1.Text = "STUN Server"; // // RunAtStartup // this.RunAtStartup.AutoSize = true; - this.RunAtStartup.Location = new System.Drawing.Point(180, 195); - this.RunAtStartup.Margin = new System.Windows.Forms.Padding(4); + this.RunAtStartup.Location = new System.Drawing.Point(120, 130); this.RunAtStartup.Name = "RunAtStartup"; - this.RunAtStartup.Size = new System.Drawing.Size(159, 28); + this.RunAtStartup.Size = new System.Drawing.Size(109, 21); this.RunAtStartup.TabIndex = 11; this.RunAtStartup.Text = "Run at startup"; this.RunAtStartup.UseVisualStyleBackColor = true; // // STUN_ServerTextBox // - this.STUN_ServerTextBox.Location = new System.Drawing.Point(180, 316); - this.STUN_ServerTextBox.Margin = new System.Windows.Forms.Padding(4); + this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 211); this.STUN_ServerTextBox.Name = "STUN_ServerTextBox"; - this.STUN_ServerTextBox.Size = new System.Drawing.Size(439, 31); + this.STUN_ServerTextBox.Size = new System.Drawing.Size(294, 23); this.STUN_ServerTextBox.TabIndex = 11; this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // MinimizeWhenStartedCheckBox // this.MinimizeWhenStartedCheckBox.AutoSize = true; - this.MinimizeWhenStartedCheckBox.Location = new System.Drawing.Point(180, 154); - this.MinimizeWhenStartedCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.MinimizeWhenStartedCheckBox.Location = new System.Drawing.Point(120, 103); this.MinimizeWhenStartedCheckBox.Name = "MinimizeWhenStartedCheckBox"; - this.MinimizeWhenStartedCheckBox.Size = new System.Drawing.Size(233, 28); + this.MinimizeWhenStartedCheckBox.Size = new System.Drawing.Size(158, 21); this.MinimizeWhenStartedCheckBox.TabIndex = 10; this.MinimizeWhenStartedCheckBox.Text = "Minimize when started"; this.MinimizeWhenStartedCheckBox.UseVisualStyleBackColor = true; @@ -362,29 +356,26 @@ // ProfileCount_Label // this.ProfileCount_Label.AutoSize = true; - this.ProfileCount_Label.Location = new System.Drawing.Point(14, 278); - this.ProfileCount_Label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.ProfileCount_Label.Location = new System.Drawing.Point(9, 185); this.ProfileCount_Label.Name = "ProfileCount_Label"; - this.ProfileCount_Label.Size = new System.Drawing.Size(117, 24); + this.ProfileCount_Label.Size = new System.Drawing.Size(79, 17); this.ProfileCount_Label.TabIndex = 8; this.ProfileCount_Label.Text = "ProfileCount"; // // ProfileCount_TextBox // - this.ProfileCount_TextBox.Location = new System.Drawing.Point(333, 273); - this.ProfileCount_TextBox.Margin = new System.Windows.Forms.Padding(4); + this.ProfileCount_TextBox.Location = new System.Drawing.Point(222, 182); this.ProfileCount_TextBox.Name = "ProfileCount_TextBox"; - this.ProfileCount_TextBox.Size = new System.Drawing.Size(286, 31); + this.ProfileCount_TextBox.Size = new System.Drawing.Size(192, 23); this.ProfileCount_TextBox.TabIndex = 9; this.ProfileCount_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // CheckUpdateWhenOpenedCheckBox // this.CheckUpdateWhenOpenedCheckBox.AutoSize = true; - this.CheckUpdateWhenOpenedCheckBox.Location = new System.Drawing.Point(180, 236); - this.CheckUpdateWhenOpenedCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.CheckUpdateWhenOpenedCheckBox.Location = new System.Drawing.Point(120, 157); this.CheckUpdateWhenOpenedCheckBox.Name = "CheckUpdateWhenOpenedCheckBox"; - this.CheckUpdateWhenOpenedCheckBox.Size = new System.Drawing.Size(277, 28); + this.CheckUpdateWhenOpenedCheckBox.Size = new System.Drawing.Size(190, 21); this.CheckUpdateWhenOpenedCheckBox.TabIndex = 8; this.CheckUpdateWhenOpenedCheckBox.Text = "Check update when opened"; this.CheckUpdateWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -393,10 +384,9 @@ // StartWhenOpenedCheckBox // this.StartWhenOpenedCheckBox.AutoSize = true; - this.StartWhenOpenedCheckBox.Location = new System.Drawing.Point(180, 114); - this.StartWhenOpenedCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.StartWhenOpenedCheckBox.Location = new System.Drawing.Point(120, 76); this.StartWhenOpenedCheckBox.Name = "StartWhenOpenedCheckBox"; - this.StartWhenOpenedCheckBox.Size = new System.Drawing.Size(199, 28); + this.StartWhenOpenedCheckBox.Size = new System.Drawing.Size(137, 21); this.StartWhenOpenedCheckBox.TabIndex = 7; this.StartWhenOpenedCheckBox.Text = "Start when opened"; this.StartWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -405,10 +395,9 @@ // StopWhenExitedCheckBox // this.StopWhenExitedCheckBox.AutoSize = true; - this.StopWhenExitedCheckBox.Location = new System.Drawing.Point(180, 74); - this.StopWhenExitedCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.StopWhenExitedCheckBox.Location = new System.Drawing.Point(120, 49); this.StopWhenExitedCheckBox.Name = "StopWhenExitedCheckBox"; - this.StopWhenExitedCheckBox.Size = new System.Drawing.Size(185, 28); + this.StopWhenExitedCheckBox.Size = new System.Drawing.Size(127, 21); this.StopWhenExitedCheckBox.TabIndex = 6; this.StopWhenExitedCheckBox.Text = "Stop when exited"; this.StopWhenExitedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -417,10 +406,9 @@ // ExitWhenClosedCheckBox // this.ExitWhenClosedCheckBox.AutoSize = true; - this.ExitWhenClosedCheckBox.Location = new System.Drawing.Point(180, 33); - this.ExitWhenClosedCheckBox.Margin = new System.Windows.Forms.Padding(4); + this.ExitWhenClosedCheckBox.Location = new System.Drawing.Point(120, 22); this.ExitWhenClosedCheckBox.Name = "ExitWhenClosedCheckBox"; - this.ExitWhenClosedCheckBox.Size = new System.Drawing.Size(178, 28); + this.ExitWhenClosedCheckBox.Size = new System.Drawing.Size(123, 21); this.ExitWhenClosedCheckBox.TabIndex = 5; this.ExitWhenClosedCheckBox.Text = "Exit when closed"; this.ExitWhenClosedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -428,9 +416,9 @@ // // SettingForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(666, 1069); + this.ClientSize = new System.Drawing.Size(444, 713); this.Controls.Add(this.BehaviorGroupBox); this.Controls.Add(this.PortGroupBox); this.Controls.Add(this.GlobalBypassIPsButton); @@ -439,7 +427,7 @@ this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.MaximizeBox = false; this.Name = "SettingForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; @@ -490,5 +478,7 @@ private System.Windows.Forms.TextBox STUN_ServerTextBox; private System.Windows.Forms.TextBox STUN_ServerPortTextBox; private System.Windows.Forms.CheckBox TUNTAPProxyDNSCheckBox; + private System.Windows.Forms.CheckBox Redirector2checkBox; + private System.Windows.Forms.Label label3; } } \ No newline at end of file diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index bb643378..1723d4bc 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -62,6 +62,7 @@ namespace Netch.Forms CheckUpdateWhenOpenedCheckBox.Checked = Global.Settings.CheckUpdateWhenOpened; MinimizeWhenStartedCheckBox.Checked = Global.Settings.MinimizeWhenStarted; RunAtStartup.Checked = Global.Settings.RunAtStartup; + Redirector2checkBox.Checked = Global.Settings.UseRedirector2; Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString(); HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString(); @@ -144,6 +145,7 @@ namespace Netch.Forms Global.Settings.CheckUpdateWhenOpened = CheckUpdateWhenOpenedCheckBox.Checked; Global.Settings.MinimizeWhenStarted = MinimizeWhenStartedCheckBox.Checked; Global.Settings.RunAtStartup = RunAtStartup.Checked; + Global.Settings.UseRedirector2 = Redirector2checkBox.Checked; // 开机自启判断 TaskSchedulerClass scheduler = new TaskSchedulerClass(); diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index b66d25e6..bf26406e 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -153,5 +153,10 @@ namespace Netch.Models /// STUN测试服务器 /// public int STUN_Server_Port = 3478; + + /// + /// 是否切换为2号核心 + /// + public bool UseRedirector2 = false; } } diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index f9a1749b..eff04253 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -29,6 +29,7 @@ "Test failed": "测试失败", "Starting update subscription": "正在更新订阅", "Subscription updated": "订阅更新完毕", + "Register driver": "正在注册驱动", "Server": "服务器", "Import Servers From Clipboard": "从剪贴板导入服务器", diff --git a/binaries b/binaries index f0686ab1..a1394429 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit f0686ab18491e3b5128749805f6a7059a8b1c524 +Subproject commit a1394429b002a76b397eee58cfadfd6e48f888f0