增加修改系统DNS开关

补充"卸载服务"为"卸载NF服务"
This commit is contained in:
ChsBuffer
2020-07-23 14:16:31 +08:00
parent 27d68163a9
commit 3da7451b9f
8 changed files with 203 additions and 186 deletions

View File

@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.ServiceProcess; using System.ServiceProcess;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Netch.Models; using Netch.Models;
using Netch.Utils; using Netch.Utils;
using nfapinet; using nfapinet;
@@ -105,11 +106,13 @@ namespace Netch.Controllers
if (State == State.Started) if (State == State.Started)
{ {
if (Global.Settings.ModifySystemDNS)
//备份并替换系统DNS {
_sysDns = DNS.getSystemDns(); //备份并替换系统DNS
string[] dns = {"1.1.1.1", "8.8.8.8"}; _sysDns = DNS.getSystemDns();
DNS.SetDNS(dns); string[] dns = {"1.1.1.1", "8.8.8.8"};
DNS.SetDNS(dns);
}
return true; return true;
} }
@@ -171,7 +174,7 @@ namespace Netch.Controllers
/// <returns>是否成功卸载</returns> /// <returns>是否成功卸载</returns>
public static bool UninstallDriver() public static bool UninstallDriver()
{ {
Global.MainForm.StatusText("Uninstall netfilter2"); Global.MainForm.StatusText(i18N.Translate("Uninstalling NF Service"));
Logging.Info("卸载NF驱动"); Logging.Info("卸载NF驱动");
try try
{ {
@@ -266,9 +269,13 @@ namespace Netch.Controllers
public override void Stop() public override void Stop()
{ {
Task.Run(() =>
{
if (Global.Settings.ModifySystemDNS)
//恢复系统DNS
DNS.SetDNS(_sysDns);
});
StopInstance(); StopInstance();
//恢复系统DNS
DNS.SetDNS(_sysDns);
} }
/// <summary> /// <summary>

View File

@@ -274,7 +274,7 @@ namespace Netch.Forms
// //
this.UninstallServiceToolStripMenuItem.Name = "UninstallServiceToolStripMenuItem"; this.UninstallServiceToolStripMenuItem.Name = "UninstallServiceToolStripMenuItem";
this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(219, 22); this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(219, 22);
this.UninstallServiceToolStripMenuItem.Text = "Uninstall Service"; this.UninstallServiceToolStripMenuItem.Text = "Uninstall NF Service";
this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click); this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click);
// //
// reinstallTapDriverToolStripMenuItem // reinstallTapDriverToolStripMenuItem

View File

@@ -233,7 +233,7 @@ namespace Netch.Forms
private void UninstallServiceToolStripMenuItem_Click(object sender, EventArgs e) private void UninstallServiceToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Enabled = false; Enabled = false;
StatusText(i18N.Translate("Uninstalling Service")); StatusText(i18N.Translate("Uninstalling NF Service"));
Task.Run(() => Task.Run(() =>
{ {
@@ -241,7 +241,7 @@ namespace Netch.Forms
{ {
if (NFController.UninstallDriver()) if (NFController.UninstallDriver())
{ {
MessageBoxX.Show(i18N.Translate("Service has been uninstalled"), owner: this); StatusText(i18N.Translate("Service has been uninstalled"));
} }
} }
catch (Exception e) catch (Exception e)
@@ -250,8 +250,6 @@ namespace Netch.Forms
Console.WriteLine(e); Console.WriteLine(e);
throw; throw;
} }
StatusText(i18N.Translate(StateExtension.GetStatusString(State.Waiting)));
Enabled = true; Enabled = true;
}); });
} }

View File

@@ -186,7 +186,7 @@ namespace Netch.Forms
UpdateServersFromSubscribeLinksToolStripMenuItem.Text = i18N.Translate("Update Servers From Subscribe Links"); UpdateServersFromSubscribeLinksToolStripMenuItem.Text = i18N.Translate("Update Servers From Subscribe Links");
OptionsToolStripMenuItem.Text = i18N.Translate("Options"); OptionsToolStripMenuItem.Text = i18N.Translate("Options");
ReloadModesToolStripMenuItem.Text = i18N.Translate("Reload Modes"); ReloadModesToolStripMenuItem.Text = i18N.Translate("Reload Modes");
UninstallServiceToolStripMenuItem.Text = i18N.Translate("Uninstall Service"); UninstallServiceToolStripMenuItem.Text = i18N.Translate("Uninstall NF Service");
CleanDNSCacheToolStripMenuItem.Text = i18N.Translate("Clean DNS Cache"); CleanDNSCacheToolStripMenuItem.Text = i18N.Translate("Clean DNS Cache");
UpdateACLToolStripMenuItem.Text = i18N.Translate("Update ACL"); UpdateACLToolStripMenuItem.Text = i18N.Translate("Update ACL");
updateACLWithProxyToolStripMenuItem.Text = i18N.Translate("Update ACL with proxy"); updateACLWithProxyToolStripMenuItem.Text = i18N.Translate("Update ACL with proxy");

View File

@@ -55,24 +55,24 @@
this.LanguageLabel = new System.Windows.Forms.Label(); this.LanguageLabel = new System.Windows.Forms.Label();
this.LanguageComboBox = new System.Windows.Forms.ComboBox(); this.LanguageComboBox = new System.Windows.Forms.ComboBox();
this.BootShadowsocksFromDLLCheckBox = new System.Windows.Forms.CheckBox(); this.BootShadowsocksFromDLLCheckBox = new System.Windows.Forms.CheckBox();
this.AclAddr = new System.Windows.Forms.TextBox(); this.AclAddrTextBox = new System.Windows.Forms.TextBox();
this.AclLabel = new System.Windows.Forms.Label(); this.AclLabel = new System.Windows.Forms.Label();
this.DetectionInterval_Label = new System.Windows.Forms.Label(); this.DetectionIntervalLabel = new System.Windows.Forms.Label();
this.DetectionInterval_TextBox = new System.Windows.Forms.TextBox(); this.DetectionIntervalTextBox = new System.Windows.Forms.TextBox();
this.EnableStartedTcping_CheckBox = new System.Windows.Forms.CheckBox(); this.TcpingAtStartedCheckBox = new System.Windows.Forms.CheckBox();
this.DelayTestAfterStartup_Label = new System.Windows.Forms.Label();
this.STUN_ServerPortTextBox = new System.Windows.Forms.TextBox(); this.STUN_ServerPortTextBox = new System.Windows.Forms.TextBox();
this.STUNServerPortLabel = new System.Windows.Forms.Label(); this.StunTextBoxSplitLabel = new System.Windows.Forms.Label();
this.STUNServerLabel = new System.Windows.Forms.Label(); this.STUNServerLabel = new System.Windows.Forms.Label();
this.RunAtStartup = new System.Windows.Forms.CheckBox(); this.RunAtStartupCheckBox = new System.Windows.Forms.CheckBox();
this.STUN_ServerTextBox = new System.Windows.Forms.TextBox(); this.STUN_ServerTextBox = new System.Windows.Forms.TextBox();
this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox(); this.MinimizeWhenStartedCheckBox = new System.Windows.Forms.CheckBox();
this.ProfileCount_Label = new System.Windows.Forms.Label(); this.ProfileCountLabel = new System.Windows.Forms.Label();
this.ProfileCount_TextBox = new System.Windows.Forms.TextBox(); this.ProfileCountTextBox = new System.Windows.Forms.TextBox();
this.CheckUpdateWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); this.CheckUpdateWhenOpenedCheckBox = new System.Windows.Forms.CheckBox();
this.StartWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); this.StartWhenOpenedCheckBox = new System.Windows.Forms.CheckBox();
this.StopWhenExitedCheckBox = new System.Windows.Forms.CheckBox(); this.StopWhenExitedCheckBox = new System.Windows.Forms.CheckBox();
this.ExitWhenClosedCheckBox = new System.Windows.Forms.CheckBox(); this.ExitWhenClosedCheckBox = new System.Windows.Forms.CheckBox();
this.ModifySystemDNSCheckBox = new System.Windows.Forms.CheckBox();
this.PortGroupBox.SuspendLayout(); this.PortGroupBox.SuspendLayout();
this.TUNTAPGroupBox.SuspendLayout(); this.TUNTAPGroupBox.SuspendLayout();
this.BehaviorGroupBox.SuspendLayout(); this.BehaviorGroupBox.SuspendLayout();
@@ -301,21 +301,21 @@
// //
this.BehaviorGroupBox.Controls.Add(this.LanguageLabel); this.BehaviorGroupBox.Controls.Add(this.LanguageLabel);
this.BehaviorGroupBox.Controls.Add(this.LanguageComboBox); this.BehaviorGroupBox.Controls.Add(this.LanguageComboBox);
this.BehaviorGroupBox.Controls.Add(this.ModifySystemDNSCheckBox);
this.BehaviorGroupBox.Controls.Add(this.BootShadowsocksFromDLLCheckBox); this.BehaviorGroupBox.Controls.Add(this.BootShadowsocksFromDLLCheckBox);
this.BehaviorGroupBox.Controls.Add(this.AclAddr); this.BehaviorGroupBox.Controls.Add(this.AclAddrTextBox);
this.BehaviorGroupBox.Controls.Add(this.AclLabel); this.BehaviorGroupBox.Controls.Add(this.AclLabel);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_Label); this.BehaviorGroupBox.Controls.Add(this.DetectionIntervalLabel);
this.BehaviorGroupBox.Controls.Add(this.DetectionInterval_TextBox); this.BehaviorGroupBox.Controls.Add(this.DetectionIntervalTextBox);
this.BehaviorGroupBox.Controls.Add(this.EnableStartedTcping_CheckBox); this.BehaviorGroupBox.Controls.Add(this.TcpingAtStartedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.DelayTestAfterStartup_Label);
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerPortTextBox); this.BehaviorGroupBox.Controls.Add(this.STUN_ServerPortTextBox);
this.BehaviorGroupBox.Controls.Add(this.STUNServerPortLabel); this.BehaviorGroupBox.Controls.Add(this.StunTextBoxSplitLabel);
this.BehaviorGroupBox.Controls.Add(this.STUNServerLabel); this.BehaviorGroupBox.Controls.Add(this.STUNServerLabel);
this.BehaviorGroupBox.Controls.Add(this.RunAtStartup); this.BehaviorGroupBox.Controls.Add(this.RunAtStartupCheckBox);
this.BehaviorGroupBox.Controls.Add(this.STUN_ServerTextBox); this.BehaviorGroupBox.Controls.Add(this.STUN_ServerTextBox);
this.BehaviorGroupBox.Controls.Add(this.MinimizeWhenStartedCheckBox); this.BehaviorGroupBox.Controls.Add(this.MinimizeWhenStartedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_Label); this.BehaviorGroupBox.Controls.Add(this.ProfileCountLabel);
this.BehaviorGroupBox.Controls.Add(this.ProfileCount_TextBox); this.BehaviorGroupBox.Controls.Add(this.ProfileCountTextBox);
this.BehaviorGroupBox.Controls.Add(this.CheckUpdateWhenOpenedCheckBox); this.BehaviorGroupBox.Controls.Add(this.CheckUpdateWhenOpenedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.StartWhenOpenedCheckBox); this.BehaviorGroupBox.Controls.Add(this.StartWhenOpenedCheckBox);
this.BehaviorGroupBox.Controls.Add(this.StopWhenExitedCheckBox); this.BehaviorGroupBox.Controls.Add(this.StopWhenExitedCheckBox);
@@ -357,11 +357,11 @@
// //
// AclAddr // AclAddr
// //
this.AclAddr.Location = new System.Drawing.Point(120, 273); this.AclAddrTextBox.Location = new System.Drawing.Point(120, 273);
this.AclAddr.Name = "AclAddr"; this.AclAddrTextBox.Name = "AclAddrTextBox";
this.AclAddr.Size = new System.Drawing.Size(315, 23); this.AclAddrTextBox.Size = new System.Drawing.Size(315, 23);
this.AclAddr.TabIndex = 19; this.AclAddrTextBox.TabIndex = 19;
this.AclAddr.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.AclAddrTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
// //
// AclLabel // AclLabel
// //
@@ -374,61 +374,53 @@
// //
// DetectionInterval_Label // DetectionInterval_Label
// //
this.DetectionInterval_Label.AutoSize = true; this.DetectionIntervalLabel.AutoSize = true;
this.DetectionInterval_Label.Location = new System.Drawing.Point(229, 192); this.DetectionIntervalLabel.Location = new System.Drawing.Point(228, 215);
this.DetectionInterval_Label.Name = "DetectionInterval_Label"; this.DetectionIntervalLabel.Name = "DetectionIntervalLabel";
this.DetectionInterval_Label.Size = new System.Drawing.Size(136, 17); this.DetectionIntervalLabel.Size = new System.Drawing.Size(136, 17);
this.DetectionInterval_Label.TabIndex = 18; this.DetectionIntervalLabel.TabIndex = 18;
this.DetectionInterval_Label.Text = "Detection interval(sec)"; this.DetectionIntervalLabel.Text = "Detection interval(sec)";
// //
// DetectionInterval_TextBox // DetectionInterval_TextBox
// //
this.DetectionInterval_TextBox.Location = new System.Drawing.Point(367, 189); this.DetectionIntervalTextBox.Location = new System.Drawing.Point(366, 212);
this.DetectionInterval_TextBox.Name = "DetectionInterval_TextBox"; this.DetectionIntervalTextBox.Name = "DetectionIntervalTextBox";
this.DetectionInterval_TextBox.Size = new System.Drawing.Size(68, 23); this.DetectionIntervalTextBox.Size = new System.Drawing.Size(68, 23);
this.DetectionInterval_TextBox.TabIndex = 17; this.DetectionIntervalTextBox.TabIndex = 17;
this.DetectionInterval_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.DetectionIntervalTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
// //
// EnableStartedTcping_CheckBox // EnableStartedTcping_CheckBox
// //
this.EnableStartedTcping_CheckBox.AutoSize = true; this.TcpingAtStartedCheckBox.AutoSize = true;
this.EnableStartedTcping_CheckBox.Location = new System.Drawing.Point(144, 191); this.TcpingAtStartedCheckBox.Location = new System.Drawing.Point(15, 214);
this.EnableStartedTcping_CheckBox.Name = "EnableStartedTcping_CheckBox"; this.TcpingAtStartedCheckBox.Name = "TcpingAtStartedCheckBox";
this.EnableStartedTcping_CheckBox.Size = new System.Drawing.Size(66, 21); this.TcpingAtStartedCheckBox.Size = new System.Drawing.Size(145, 21);
this.EnableStartedTcping_CheckBox.TabIndex = 15; this.TcpingAtStartedCheckBox.TabIndex = 15;
this.EnableStartedTcping_CheckBox.Text = "Enable"; this.TcpingAtStartedCheckBox.TabStop = false;
this.EnableStartedTcping_CheckBox.UseVisualStyleBackColor = true; this.TcpingAtStartedCheckBox.Text = "Delay test after start";
// this.TcpingAtStartedCheckBox.UseVisualStyleBackColor = true;
// DelayTestAfterStartup_Label
//
this.DelayTestAfterStartup_Label.AutoSize = true;
this.DelayTestAfterStartup_Label.Location = new System.Drawing.Point(12, 192);
this.DelayTestAfterStartup_Label.Name = "DelayTestAfterStartup_Label";
this.DelayTestAfterStartup_Label.Size = new System.Drawing.Size(126, 17);
this.DelayTestAfterStartup_Label.TabIndex = 16;
this.DelayTestAfterStartup_Label.Text = "Delay test after start";
// //
// STUN_ServerPortTextBox // STUN_ServerPortTextBox
// //
this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(120, 244); this.STUN_ServerPortTextBox.Location = new System.Drawing.Point(366, 241);
this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox"; this.STUN_ServerPortTextBox.Name = "STUN_ServerPortTextBox";
this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(315, 23); this.STUN_ServerPortTextBox.Size = new System.Drawing.Size(68, 23);
this.STUN_ServerPortTextBox.TabIndex = 8; this.STUN_ServerPortTextBox.TabIndex = 8;
this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.STUN_ServerPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
// //
// STUNServerPortLabel // StunTextBoxSplitLabel
// //
this.STUNServerPortLabel.AutoSize = true; this.StunTextBoxSplitLabel.AutoSize = true;
this.STUNServerPortLabel.Location = new System.Drawing.Point(12, 247); this.StunTextBoxSplitLabel.Location = new System.Drawing.Point(353, 244);
this.STUNServerPortLabel.Name = "STUNServerPortLabel"; this.StunTextBoxSplitLabel.Name = "StunTextBoxSplitLabel";
this.STUNServerPortLabel.Size = new System.Drawing.Size(110, 17); this.StunTextBoxSplitLabel.Size = new System.Drawing.Size(11, 17);
this.STUNServerPortLabel.TabIndex = 12; this.StunTextBoxSplitLabel.TabIndex = 12;
this.STUNServerPortLabel.Text = "STUN Server Port"; this.StunTextBoxSplitLabel.Text = ":";
// //
// STUNServerLabel // STUNServerLabel
// //
this.STUNServerLabel.AutoSize = true; this.STUNServerLabel.AutoSize = true;
this.STUNServerLabel.Location = new System.Drawing.Point(12, 221); this.STUNServerLabel.Location = new System.Drawing.Point(12, 244);
this.STUNServerLabel.Name = "STUNServerLabel"; this.STUNServerLabel.Name = "STUNServerLabel";
this.STUNServerLabel.Size = new System.Drawing.Size(82, 17); this.STUNServerLabel.Size = new System.Drawing.Size(82, 17);
this.STUNServerLabel.TabIndex = 10; this.STUNServerLabel.TabIndex = 10;
@@ -436,19 +428,19 @@
// //
// RunAtStartup // RunAtStartup
// //
this.RunAtStartup.AutoSize = true; this.RunAtStartupCheckBox.AutoSize = true;
this.RunAtStartup.Location = new System.Drawing.Point(12, 75); this.RunAtStartupCheckBox.Location = new System.Drawing.Point(12, 75);
this.RunAtStartup.Name = "RunAtStartup"; this.RunAtStartupCheckBox.Name = "RunAtStartupCheckBox";
this.RunAtStartup.Size = new System.Drawing.Size(109, 21); this.RunAtStartupCheckBox.Size = new System.Drawing.Size(109, 21);
this.RunAtStartup.TabIndex = 11; this.RunAtStartupCheckBox.TabIndex = 11;
this.RunAtStartup.Text = "Run at startup"; this.RunAtStartupCheckBox.Text = "Run at startup";
this.RunAtStartup.UseVisualStyleBackColor = true; this.RunAtStartupCheckBox.UseVisualStyleBackColor = true;
// //
// STUN_ServerTextBox // STUN_ServerTextBox
// //
this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 215); this.STUN_ServerTextBox.Location = new System.Drawing.Point(120, 241);
this.STUN_ServerTextBox.Name = "STUN_ServerTextBox"; this.STUN_ServerTextBox.Name = "STUN_ServerTextBox";
this.STUN_ServerTextBox.Size = new System.Drawing.Size(315, 23); this.STUN_ServerTextBox.Size = new System.Drawing.Size(233, 23);
this.STUN_ServerTextBox.TabIndex = 11; this.STUN_ServerTextBox.TabIndex = 11;
this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.STUN_ServerTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
// //
@@ -464,20 +456,20 @@
// //
// ProfileCount_Label // ProfileCount_Label
// //
this.ProfileCount_Label.AutoSize = true; this.ProfileCountLabel.AutoSize = true;
this.ProfileCount_Label.Location = new System.Drawing.Point(12, 167); this.ProfileCountLabel.Location = new System.Drawing.Point(12, 188);
this.ProfileCount_Label.Name = "ProfileCount_Label"; this.ProfileCountLabel.Name = "ProfileCountLabel";
this.ProfileCount_Label.Size = new System.Drawing.Size(79, 17); this.ProfileCountLabel.Size = new System.Drawing.Size(79, 17);
this.ProfileCount_Label.TabIndex = 8; this.ProfileCountLabel.TabIndex = 8;
this.ProfileCount_Label.Text = "ProfileCount"; this.ProfileCountLabel.Text = "ProfileCount";
// //
// ProfileCount_TextBox // ProfileCount_TextBox
// //
this.ProfileCount_TextBox.Location = new System.Drawing.Point(120, 164); this.ProfileCountTextBox.Location = new System.Drawing.Point(120, 185);
this.ProfileCount_TextBox.Name = "ProfileCount_TextBox"; this.ProfileCountTextBox.Name = "ProfileCountTextBox";
this.ProfileCount_TextBox.Size = new System.Drawing.Size(90, 23); this.ProfileCountTextBox.Size = new System.Drawing.Size(90, 23);
this.ProfileCount_TextBox.TabIndex = 9; this.ProfileCountTextBox.TabIndex = 9;
this.ProfileCount_TextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.ProfileCountTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
// //
// CheckUpdateWhenOpenedCheckBox // CheckUpdateWhenOpenedCheckBox
// //
@@ -523,6 +515,16 @@
this.ExitWhenClosedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.ExitWhenClosedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.ExitWhenClosedCheckBox.UseVisualStyleBackColor = true; this.ExitWhenClosedCheckBox.UseVisualStyleBackColor = true;
// //
// ModifySystemDNSCheckBox
//
this.ModifySystemDNSCheckBox.AutoSize = true;
this.ModifySystemDNSCheckBox.Location = new System.Drawing.Point(12, 129);
this.ModifySystemDNSCheckBox.Name = "ModifySystemDNSCheckBox";
this.ModifySystemDNSCheckBox.Size = new System.Drawing.Size(143, 21);
this.ModifySystemDNSCheckBox.TabIndex = 21;
this.ModifySystemDNSCheckBox.Text = "Modify System DNS";
this.ModifySystemDNSCheckBox.UseVisualStyleBackColor = true;
//
// SettingForm // SettingForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -578,26 +580,26 @@
private System.Windows.Forms.CheckBox StopWhenExitedCheckBox; private System.Windows.Forms.CheckBox StopWhenExitedCheckBox;
private System.Windows.Forms.CheckBox StartWhenOpenedCheckBox; private System.Windows.Forms.CheckBox StartWhenOpenedCheckBox;
private System.Windows.Forms.CheckBox CheckUpdateWhenOpenedCheckBox; private System.Windows.Forms.CheckBox CheckUpdateWhenOpenedCheckBox;
private System.Windows.Forms.Label ProfileCount_Label; private System.Windows.Forms.Label ProfileCountLabel;
private System.Windows.Forms.TextBox ProfileCount_TextBox; private System.Windows.Forms.TextBox ProfileCountTextBox;
private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox; private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox;
private System.Windows.Forms.CheckBox RunAtStartup; private System.Windows.Forms.CheckBox RunAtStartupCheckBox;
private System.Windows.Forms.Label STUNServerPortLabel; private System.Windows.Forms.Label StunTextBoxSplitLabel;
private System.Windows.Forms.Label STUNServerLabel; private System.Windows.Forms.Label STUNServerLabel;
private System.Windows.Forms.TextBox STUN_ServerTextBox; private System.Windows.Forms.TextBox STUN_ServerTextBox;
private System.Windows.Forms.TextBox STUN_ServerPortTextBox; private System.Windows.Forms.TextBox STUN_ServerPortTextBox;
private System.Windows.Forms.CheckBox ProxyDNSCheckBox; private System.Windows.Forms.CheckBox ProxyDNSCheckBox;
private System.Windows.Forms.TextBox DetectionInterval_TextBox; private System.Windows.Forms.TextBox DetectionIntervalTextBox;
private System.Windows.Forms.CheckBox EnableStartedTcping_CheckBox; private System.Windows.Forms.CheckBox TcpingAtStartedCheckBox;
private System.Windows.Forms.Label DelayTestAfterStartup_Label; private System.Windows.Forms.Label DetectionIntervalLabel;
private System.Windows.Forms.Label DetectionInterval_Label;
private System.Windows.Forms.Label RedirectorLabel; private System.Windows.Forms.Label RedirectorLabel;
private System.Windows.Forms.TextBox RedirectorTextBox; private System.Windows.Forms.TextBox RedirectorTextBox;
private System.Windows.Forms.TextBox AclAddr; private System.Windows.Forms.TextBox AclAddrTextBox;
private System.Windows.Forms.Label AclLabel; private System.Windows.Forms.Label AclLabel;
private System.Windows.Forms.CheckBox UseFakeDNSCheckBox; private System.Windows.Forms.CheckBox UseFakeDNSCheckBox;
private System.Windows.Forms.CheckBox BootShadowsocksFromDLLCheckBox; private System.Windows.Forms.CheckBox BootShadowsocksFromDLLCheckBox;
private System.Windows.Forms.Label LanguageLabel; private System.Windows.Forms.Label LanguageLabel;
private System.Windows.Forms.ComboBox LanguageComboBox; private System.Windows.Forms.ComboBox LanguageComboBox;
private System.Windows.Forms.CheckBox ModifySystemDNSCheckBox;
} }
} }

View File

@@ -46,74 +46,33 @@ namespace Netch.Forms
} }
} }
private void InitText() private void InitValue()
{ {
Text = i18N.Translate(Text); // Local Port
PortGroupBox.Text = i18N.Translate(PortGroupBox.Text);
AllowDevicesCheckBox.Text = i18N.Translate(AllowDevicesCheckBox.Text);
TUNTAPAddressLabel.Text = i18N.Translate(TUNTAPAddressLabel.Text);
TUNTAPNetmaskLabel.Text = i18N.Translate(TUNTAPNetmaskLabel.Text);
TUNTAPGatewayLabel.Text = i18N.Translate(TUNTAPGatewayLabel.Text);
UseCustomDNSCheckBox.Text = i18N.Translate(UseCustomDNSCheckBox.Text);
ProxyDNSCheckBox.Text = i18N.Translate(ProxyDNSCheckBox.Text);
UseFakeDNSCheckBox.Text = i18N.Translate(UseFakeDNSCheckBox.Text);
GlobalBypassIPsButton.Text = i18N.Translate(GlobalBypassIPsButton.Text);
ControlButton.Text = i18N.Translate(ControlButton.Text);
BootShadowsocksFromDLLCheckBox.Text = i18N.Translate(BootShadowsocksFromDLLCheckBox.Text);
ExitWhenClosedCheckBox.Checked = Global.Settings.ExitWhenClosed;
StopWhenExitedCheckBox.Checked = Global.Settings.StopWhenExited;
StartWhenOpenedCheckBox.Checked = Global.Settings.StartWhenOpened;
CheckUpdateWhenOpenedCheckBox.Checked = Global.Settings.CheckUpdateWhenOpened;
MinimizeWhenStartedCheckBox.Checked = Global.Settings.MinimizeWhenStarted;
RunAtStartup.Checked = Global.Settings.RunAtStartup;
EnableStartedTcping_CheckBox.Checked = Global.Settings.StartedTcping;
DetectionInterval_TextBox.Text = Global.Settings.StartedTcping_Interval.ToString();
BootShadowsocksFromDLLCheckBox.Checked = Global.Settings.BootShadowsocksFromDLL;
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString(); Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString(); HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString(); RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
switch (Global.Settings.LocalAddress)
{
case "127.0.0.1":
AllowDevicesCheckBox.Checked = false;
break;
case "0.0.0.0":
AllowDevicesCheckBox.Checked = true;
break;
default:
Global.Settings.LocalAddress = "127.0.0.1";
AllowDevicesCheckBox.Checked = false;
break;
}
// TUN/TAP
TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address; TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address;
TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask; TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask;
TUNTAPGatewayTextBox.Text = Global.Settings.TUNTAP.Gateway; TUNTAPGatewayTextBox.Text = Global.Settings.TUNTAP.Gateway;
UseCustomDNSCheckBox.Checked = Global.Settings.TUNTAP.UseCustomDNS; UseCustomDNSCheckBox.Checked = Global.Settings.TUNTAP.UseCustomDNS;
ProxyDNSCheckBox.Checked = Global.Settings.TUNTAP.ProxyDNS; ProxyDNSCheckBox.Checked = Global.Settings.TUNTAP.ProxyDNS;
UseFakeDNSCheckBox.Checked = Global.Settings.TUNTAP.UseFakeDNS; UseFakeDNSCheckBox.Checked = Global.Settings.TUNTAP.UseFakeDNS;
BehaviorGroupBox.Text = i18N.Translate(BehaviorGroupBox.Text);
ExitWhenClosedCheckBox.Text = i18N.Translate(ExitWhenClosedCheckBox.Text);
StopWhenExitedCheckBox.Text = i18N.Translate(StopWhenExitedCheckBox.Text);
StartWhenOpenedCheckBox.Text = i18N.Translate(StartWhenOpenedCheckBox.Text);
MinimizeWhenStartedCheckBox.Text = i18N.Translate(MinimizeWhenStartedCheckBox.Text);
RunAtStartup.Text = i18N.Translate(RunAtStartup.Text);
CheckUpdateWhenOpenedCheckBox.Text = i18N.Translate(CheckUpdateWhenOpenedCheckBox.Text);
ProfileCount_Label.Text = i18N.Translate(ProfileCount_Label.Text);
DelayTestAfterStartup_Label.Text = i18N.Translate(DelayTestAfterStartup_Label.Text);
EnableStartedTcping_CheckBox.Text = i18N.Translate(EnableStartedTcping_CheckBox.Text);
DetectionInterval_Label.Text = i18N.Translate(DetectionInterval_Label.Text);
DelayTestAfterStartup_Label.Text = i18N.Translate(DelayTestAfterStartup_Label.Text);
STUNServerLabel.Text = i18N.Translate(STUNServerLabel.Text);
STUNServerPortLabel.Text = i18N.Translate(STUNServerPortLabel.Text);
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
STUN_ServerTextBox.Text = Global.Settings.STUN_Server;
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
AclLabel.Text = i18N.Translate(AclLabel.Text);
AclAddr.Text = Global.Settings.ACL;
LanguageLabel.Text = i18N.Translate(LanguageLabel.Text);
LanguageComboBox.Items.AddRange(i18N.GetTranslateList().ToArray());
LanguageComboBox.SelectedItem = Global.Settings.Language;
}
private void SettingForm_Load(object sender, EventArgs e)
{
InitText();
if (Global.Settings.TUNTAP.DNS.Count > 0) if (Global.Settings.TUNTAP.DNS.Count > 0)
{ {
var dns = ""; var dns = "";
@@ -126,9 +85,9 @@ namespace Netch.Forms
dns = dns.Trim(); dns = dns.Trim();
TUNTAPDNSTextBox.Text = dns.Substring(0, dns.Length - 1); TUNTAPDNSTextBox.Text = dns.Substring(0, dns.Length - 1);
} }
// 如果 DNS 为空,设置为默认 DNS 1.1.1.1
else else
{ {
// 如果 DNS 为空,设置为默认 DNS 1.1.1.1
Global.Settings.TUNTAP.DNS.Add("1.1.1.1"); Global.Settings.TUNTAP.DNS.Add("1.1.1.1");
TUNTAPDNSTextBox.Text = "1.1.1.1"; TUNTAPDNSTextBox.Text = "1.1.1.1";
} }
@@ -138,20 +97,63 @@ namespace Netch.Forms
TUNTAPDNSTextBox.Enabled = false; TUNTAPDNSTextBox.Enabled = false;
} }
// 设置本地代理是否允许其他设备连接 // Behavior
if (Global.Settings.LocalAddress == "127.0.0.1") ExitWhenClosedCheckBox.Checked = Global.Settings.ExitWhenClosed;
{ StopWhenExitedCheckBox.Checked = Global.Settings.StopWhenExited;
AllowDevicesCheckBox.Checked = false; StartWhenOpenedCheckBox.Checked = Global.Settings.StartWhenOpened;
} MinimizeWhenStartedCheckBox.Checked = Global.Settings.MinimizeWhenStarted;
else if (Global.Settings.LocalAddress == "0.0.0.0") RunAtStartupCheckBox.Checked = Global.Settings.RunAtStartup;
{ CheckUpdateWhenOpenedCheckBox.Checked = Global.Settings.CheckUpdateWhenOpened;
AllowDevicesCheckBox.Checked = true; BootShadowsocksFromDLLCheckBox.Checked = Global.Settings.BootShadowsocksFromDLL;
} ModifySystemDNSCheckBox.Checked = Global.Settings.ModifySystemDNS;
else
{ ProfileCountTextBox.Text = Global.Settings.ProfileCount.ToString();
Global.Settings.LocalAddress = "127.0.0.1"; TcpingAtStartedCheckBox.Checked = Global.Settings.StartedTcping;
AllowDevicesCheckBox.Checked = false; DetectionIntervalTextBox.Text = Global.Settings.StartedTcping_Interval.ToString();
} STUN_ServerTextBox.Text = Global.Settings.STUN_Server;
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
AclAddrTextBox.Text = Global.Settings.ACL;
LanguageComboBox.Items.AddRange(i18N.GetTranslateList().ToArray());
LanguageComboBox.SelectedItem = Global.Settings.Language;
}
private void InitText()
{
Text = i18N.Translate(Text);
PortGroupBox.Text = i18N.Translate(PortGroupBox.Text);
AllowDevicesCheckBox.Text = i18N.Translate(AllowDevicesCheckBox.Text);
TUNTAPAddressLabel.Text = i18N.Translate(TUNTAPAddressLabel.Text);
TUNTAPNetmaskLabel.Text = i18N.Translate(TUNTAPNetmaskLabel.Text);
TUNTAPGatewayLabel.Text = i18N.Translate(TUNTAPGatewayLabel.Text);
UseCustomDNSCheckBox.Text = i18N.Translate(UseCustomDNSCheckBox.Text);
ProxyDNSCheckBox.Text = i18N.Translate(ProxyDNSCheckBox.Text);
UseFakeDNSCheckBox.Text = i18N.Translate(UseFakeDNSCheckBox.Text);
GlobalBypassIPsButton.Text = i18N.Translate(GlobalBypassIPsButton.Text);
ControlButton.Text = i18N.Translate(ControlButton.Text);
BootShadowsocksFromDLLCheckBox.Text = i18N.Translate(BootShadowsocksFromDLLCheckBox.Text);
ModifySystemDNSCheckBox.Text = i18N.Translate(ModifySystemDNSCheckBox.Text);
BehaviorGroupBox.Text = i18N.Translate(BehaviorGroupBox.Text);
ExitWhenClosedCheckBox.Text = i18N.Translate(ExitWhenClosedCheckBox.Text);
StopWhenExitedCheckBox.Text = i18N.Translate(StopWhenExitedCheckBox.Text);
StartWhenOpenedCheckBox.Text = i18N.Translate(StartWhenOpenedCheckBox.Text);
MinimizeWhenStartedCheckBox.Text = i18N.Translate(MinimizeWhenStartedCheckBox.Text);
RunAtStartupCheckBox.Text = i18N.Translate(RunAtStartupCheckBox.Text);
CheckUpdateWhenOpenedCheckBox.Text = i18N.Translate(CheckUpdateWhenOpenedCheckBox.Text);
ProfileCountLabel.Text = i18N.Translate(ProfileCountLabel.Text);
TcpingAtStartedCheckBox.Text = i18N.Translate(TcpingAtStartedCheckBox.Text);
DetectionIntervalLabel.Text = i18N.Translate(DetectionIntervalLabel.Text);
STUNServerLabel.Text = i18N.Translate(STUNServerLabel.Text);
StunTextBoxSplitLabel.Text = i18N.Translate(StunTextBoxSplitLabel.Text);
AclLabel.Text = i18N.Translate(AclLabel.Text);
LanguageLabel.Text = i18N.Translate(LanguageLabel.Text);
}
private void SettingForm_Load(object sender, EventArgs e)
{
InitText();
InitValue();
} }
private void SettingForm_FormClosing(object sender, FormClosingEventArgs e) private void SettingForm_FormClosing(object sender, FormClosingEventArgs e)
@@ -172,7 +174,7 @@ namespace Netch.Forms
Global.Settings.StartWhenOpened = StartWhenOpenedCheckBox.Checked; Global.Settings.StartWhenOpened = StartWhenOpenedCheckBox.Checked;
Global.Settings.CheckUpdateWhenOpened = CheckUpdateWhenOpenedCheckBox.Checked; Global.Settings.CheckUpdateWhenOpened = CheckUpdateWhenOpenedCheckBox.Checked;
Global.Settings.MinimizeWhenStarted = MinimizeWhenStartedCheckBox.Checked; Global.Settings.MinimizeWhenStarted = MinimizeWhenStartedCheckBox.Checked;
Global.Settings.RunAtStartup = RunAtStartup.Checked; Global.Settings.RunAtStartup = RunAtStartupCheckBox.Checked;
Global.Settings.BootShadowsocksFromDLL = BootShadowsocksFromDLLCheckBox.Checked; Global.Settings.BootShadowsocksFromDLL = BootShadowsocksFromDLLCheckBox.Checked;
Global.Settings.Language = LanguageComboBox.SelectedItem.ToString(); Global.Settings.Language = LanguageComboBox.SelectedItem.ToString();
@@ -191,7 +193,7 @@ namespace Netch.Forms
// ignored // ignored
} }
if (RunAtStartup.Checked) if (RunAtStartupCheckBox.Checked)
{ {
if (taskIsExists) if (taskIsExists)
folder.DeleteTask("Netch Startup", 0); folder.DeleteTask("Netch Startup", 0);
@@ -264,7 +266,7 @@ namespace Netch.Forms
try try
{ {
var ProfileCount = int.Parse(ProfileCount_TextBox.Text); var ProfileCount = int.Parse(ProfileCountTextBox.Text);
if (ProfileCount > -1) if (ProfileCount > -1)
{ {
@@ -277,7 +279,7 @@ namespace Netch.Forms
} }
catch (FormatException) catch (FormatException)
{ {
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString(); ProfileCountTextBox.Text = Global.Settings.ProfileCount.ToString();
MessageBoxX.Show(i18N.Translate("ProfileCount value illegal. Try again.")); MessageBoxX.Show(i18N.Translate("ProfileCount value illegal. Try again."));
return; return;
@@ -301,7 +303,7 @@ namespace Netch.Forms
} }
catch (FormatException) catch (FormatException)
{ {
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString(); ProfileCountTextBox.Text = Global.Settings.ProfileCount.ToString();
MessageBoxX.Show(i18N.Translate("STUN_ServerPort value illegal. Try again.")); MessageBoxX.Show(i18N.Translate("STUN_ServerPort value illegal. Try again."));
return; return;
@@ -309,9 +311,9 @@ namespace Netch.Forms
try try
{ {
Global.Settings.StartedTcping = EnableStartedTcping_CheckBox.Checked; Global.Settings.StartedTcping = TcpingAtStartedCheckBox.Checked;
var DetectionInterval = int.Parse(DetectionInterval_TextBox.Text); var DetectionInterval = int.Parse(DetectionIntervalTextBox.Text);
if (DetectionInterval > 0) if (DetectionInterval > 0)
{ {
@@ -324,13 +326,13 @@ namespace Netch.Forms
} }
catch (FormatException) catch (FormatException)
{ {
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString(); ProfileCountTextBox.Text = Global.Settings.ProfileCount.ToString();
MessageBoxX.Show(i18N.Translate("Detection interval value illegal. Try again.")); MessageBoxX.Show(i18N.Translate("Detection interval value illegal. Try again."));
return; return;
} }
Global.Settings.ACL = AclAddr.Text; Global.Settings.ACL = AclAddrTextBox.Text;
Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text; Global.Settings.TUNTAP.Address = TUNTAPAddressTextBox.Text;
Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text; Global.Settings.TUNTAP.Netmask = TUNTAPNetmaskTextBox.Text;
@@ -346,6 +348,8 @@ namespace Netch.Forms
Global.Settings.TUNTAP.ProxyDNS = ProxyDNSCheckBox.Checked; Global.Settings.TUNTAP.ProxyDNS = ProxyDNSCheckBox.Checked;
Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked; Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked;
Global.Settings.ModifySystemDNS = ModifySystemDNSCheckBox.Checked;
Configuration.Save(); Configuration.Save();
MessageBoxX.Show(i18N.Translate("Saved")); MessageBoxX.Show(i18N.Translate("Saved"));
Close(); Close();

View File

@@ -88,6 +88,11 @@ namespace Netch.Models
/// </summary> /// </summary>
public bool CheckUpdateWhenOpened = true; public bool CheckUpdateWhenOpened = true;
/// <summary>
/// 修改系统 DNS
/// </summary>
public bool ModifySystemDNS = false;
/// <summary> /// <summary>
/// 使用何种模式文件名 /// 使用何种模式文件名
/// 0 为自定义文件名1 为使用和备注一致的文件名2 为使用时间数据作为文件名 /// 0 为自定义文件名1 为使用和备注一致的文件名2 为使用时间数据作为文件名

View File

@@ -74,8 +74,8 @@
"Update servers error from {0}": "从 {0} 更新服务器失败", "Update servers error from {0}": "从 {0} 更新服务器失败",
"Options": "选项", "Options": "选项",
"Uninstall Service": "卸载服务", "Uninstall NF Service": "卸载 NF 服务",
"Uninstalling Service": "正在卸载服务中", "Uninstalling NF Service": "正在 NF 卸载服务中",
"Service has been uninstalled": "服务已卸载", "Service has been uninstalled": "服务已卸载",
"Reload Modes": "重载模式", "Reload Modes": "重载模式",
"Modes have been reload": "模式已重载", "Modes have been reload": "模式已重载",
@@ -157,6 +157,7 @@
"Port value illegal. Try again.": "端口值非法。请重试。", "Port value illegal. Try again.": "端口值非法。请重试。",
"Check update when opened": "打开软件时检查更新", "Check update when opened": "打开软件时检查更新",
"Start Shadowsocks from DLL (No support for ACL)": "SS DLL推荐使用不支持 ACL", "Start Shadowsocks from DLL (No support for ACL)": "SS DLL推荐使用不支持 ACL",
"Modify System DNS": "修改系统 DNS",
"ProfileCount": "快捷配置数量", "ProfileCount": "快捷配置数量",
"ProfileCount value illegal. Try again.": "快捷配置数值非法。请重试。", "ProfileCount value illegal. Try again.": "快捷配置数值非法。请重试。",
"STUN_ServerPort value illegal. Try again.": "STUN 端口数值非法。请重试。", "STUN_ServerPort value illegal. Try again.": "STUN 端口数值非法。请重试。",