diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 1f39075e..ab161cd7 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -16,6 +16,10 @@ namespace Netch.Forms { public partial class MainForm : Form { + private readonly Dictionary _mainFormText = new(); + + private bool _comboBoxInitialized; + private bool _textRecorded; public MainForm() { InitializeComponent(); @@ -71,15 +75,12 @@ namespace Netch.Forms // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) - { ControlButton.PerformClick(); - } // 自动检测延迟 Task.Run(() => { while (true) - { if (State == State.Waiting || State == State.Stopped) { TestServer(); @@ -90,26 +91,21 @@ namespace Netch.Forms { Thread.Sleep(200); } - } }); Task.Run(() => { // 检查更新 if (Global.Settings.CheckUpdateWhenOpened) - { CheckUpdate(); - } }); Task.Run(async () => { // 检查订阅更新 - if (Global.Settings.UpdateSubscribeatWhenOpened) - { + if (Global.Settings.UpdateServersWhenOpened) await UpdateServersFromSubscribe(Global.Settings.UseProxyToUpdateSubscription); - } }); } @@ -184,9 +180,6 @@ namespace Netch.Forms Show(); } - private readonly Dictionary _mainFormText = new Dictionary(); - private bool _textRecorded; - private void InitText() { #region Record English @@ -249,8 +242,7 @@ namespace Netch.Forms if (value is object[] values) return i18N.TranslateFormat(values.First() as string, values.Skip(1).ToArray()); - else - return i18N.Translate(value); + return i18N.Translate(value); } } @@ -277,27 +269,48 @@ namespace Netch.Forms Hide(); NotifyIcon.Visible = false; if (!IsWaiting) - { ControlFun(); - } Configuration.Save(); foreach (var file in new[] {"data\\last.json", "data\\privoxy.conf"}) - { if (File.Exists(file)) File.Delete(file); - } State = State.Terminating; } + private void ModeComboBox_SelectedIndexChanged(object sender, EventArgs o) + { + if (!_comboBoxInitialized) return; + try + { + Global.Settings.ModeComboBoxSelectedIndex = Global.Modes.IndexOf((Models.Mode) ModeComboBox.SelectedItem); + } + catch + { + Global.Settings.ModeComboBoxSelectedIndex = 0; + } + } + + private void ServerComboBox_SelectedIndexChanged(object sender, EventArgs o) + { + if (!_comboBoxInitialized) return; + Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex; + } + + private void NatTypeStatusLabel_Click(object sender, EventArgs e) + { + if (_state == State.Started && MainController.NttTested) + MainController.NatTest(); + } + #region MISC private bool _resumeFlag; /// - /// 监听电源事件,自动重启Netch服务 + /// 监听电源事件,自动重启Netch服务 /// /// /// @@ -415,13 +428,9 @@ namespace Netch.Forms var server = (Server) ServerComboBox.SelectedItem; string text; if (ModifierKeys == Keys.Control) - { text = ShareLink.GetNetchLink(server); - } else - { text = ShareLink.GetShareLink(server); - } Clipboard.SetText(text); } @@ -445,9 +454,7 @@ namespace Netch.Forms InitServer(); Configuration.Save(); if (ServerComboBox.Items.Count > 0) - { ServerComboBox.SelectedIndex = index != 0 ? index - 1 : index; - } } #region NotifyIcon @@ -496,34 +503,5 @@ namespace Netch.Forms #endregion #endregion - - private bool _comboBoxInitialized; - - private void ModeComboBox_SelectedIndexChanged(object sender, EventArgs o) - { - if (!_comboBoxInitialized) return; - try - { - Global.Settings.ModeComboBoxSelectedIndex = Global.Modes.IndexOf((Models.Mode) ModeComboBox.SelectedItem); - } - catch - { - Global.Settings.ModeComboBoxSelectedIndex = 0; - } - } - - private void ServerComboBox_SelectedIndexChanged(object sender, EventArgs o) - { - if (!_comboBoxInitialized) return; - Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex; - } - - private void NatTypeStatusLabel_Click(object sender, EventArgs e) - { - if (_state == State.Started && MainController.NttTested) - { - MainController.NatTest(); - } - } } } \ No newline at end of file diff --git a/Netch/Forms/SettingForm.Designer.cs b/Netch/Forms/SettingForm.Designer.cs index 11202a6e..9ce726dc 100644 --- a/Netch/Forms/SettingForm.Designer.cs +++ b/Netch/Forms/SettingForm.Designer.cs @@ -105,7 +105,7 @@ namespace Netch.Forms this.RunAtStartupCheckBox = new System.Windows.Forms.CheckBox(); this.CheckUpdateWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); this.CheckBetaUpdateCheckBox = new System.Windows.Forms.CheckBox(); - this.UpdateSubscribeatWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); + this.UpdateServersWhenOpenedCheckBox = new System.Windows.Forms.CheckBox(); this.AioDNSTabPage = new System.Windows.Forms.TabPage(); this.AioDNSRuleRuleLabel = new System.Windows.Forms.Label(); this.AioDNSRulePathTextBox = new System.Windows.Forms.TextBox(); @@ -807,7 +807,7 @@ namespace Netch.Forms this.OtherTabPage.Controls.Add(this.RunAtStartupCheckBox); this.OtherTabPage.Controls.Add(this.CheckUpdateWhenOpenedCheckBox); this.OtherTabPage.Controls.Add(this.CheckBetaUpdateCheckBox); - this.OtherTabPage.Controls.Add(this.UpdateSubscribeatWhenOpenedCheckBox); + this.OtherTabPage.Controls.Add(this.UpdateServersWhenOpenedCheckBox); this.OtherTabPage.Location = new System.Drawing.Point(4, 25); this.OtherTabPage.Name = "OtherTabPage"; this.OtherTabPage.Padding = new System.Windows.Forms.Padding(3); @@ -890,16 +890,16 @@ namespace Netch.Forms this.CheckBetaUpdateCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.CheckBetaUpdateCheckBox.UseVisualStyleBackColor = true; // - // UpdateSubscribeatWhenOpenedCheckBox + // UpdateServersWhenOpenedCheckBox // - this.UpdateSubscribeatWhenOpenedCheckBox.AutoSize = true; - this.UpdateSubscribeatWhenOpenedCheckBox.Location = new System.Drawing.Point(200, 94); - this.UpdateSubscribeatWhenOpenedCheckBox.Name = "UpdateSubscribeatWhenOpenedCheckBox"; - this.UpdateSubscribeatWhenOpenedCheckBox.Size = new System.Drawing.Size(204, 16); - this.UpdateSubscribeatWhenOpenedCheckBox.TabIndex = 7; - this.UpdateSubscribeatWhenOpenedCheckBox.Text = "Update subscribeat when opened"; - this.UpdateSubscribeatWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.UpdateSubscribeatWhenOpenedCheckBox.UseVisualStyleBackColor = true; + this.UpdateServersWhenOpenedCheckBox.AutoSize = true; + this.UpdateServersWhenOpenedCheckBox.Location = new System.Drawing.Point(200, 94); + this.UpdateServersWhenOpenedCheckBox.Name = "UpdateServersWhenOpenedCheckBox"; + this.UpdateServersWhenOpenedCheckBox.Size = new System.Drawing.Size(204, 16); + this.UpdateServersWhenOpenedCheckBox.TabIndex = 7; + this.UpdateServersWhenOpenedCheckBox.Text = "Update Servers when opened"; + this.UpdateServersWhenOpenedCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.UpdateServersWhenOpenedCheckBox.UseVisualStyleBackColor = true; // // AioDNSTabPage // @@ -1067,7 +1067,7 @@ namespace Netch.Forms private System.Windows.Forms.Button ControlButton; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.Windows.Forms.TabPage OtherTabPage; - private System.Windows.Forms.CheckBox UpdateSubscribeatWhenOpenedCheckBox; + private System.Windows.Forms.CheckBox UpdateServersWhenOpenedCheckBox; private System.Windows.Forms.CheckBox RunAtStartupCheckBox; private System.Windows.Forms.CheckBox MinimizeWhenStartedCheckBox; private System.Windows.Forms.CheckBox CheckBetaUpdateCheckBox; diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs index 28c6e9e3..27236b16 100644 --- a/Netch/Forms/SettingForm.cs +++ b/Netch/Forms/SettingForm.cs @@ -1,4 +1,3 @@ -using Netch.Utils; using System; using System.Collections.Generic; using System.Drawing; @@ -7,11 +6,15 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using System.Windows.Forms; +using Netch.Utils; namespace Netch.Forms { public partial class SettingForm : Form { + private readonly Dictionary> _checkActions = new(); + + private readonly Dictionary> _saveActions = new(); public SettingForm() { InitializeComponent(); @@ -238,9 +241,9 @@ namespace Netch.Forms b => Global.Settings.CheckBetaUpdate = b, Global.Settings.CheckBetaUpdate); - BindCheckBox(UpdateSubscribeatWhenOpenedCheckBox, - b => Global.Settings.UpdateSubscribeatWhenOpened = b, - Global.Settings.UpdateSubscribeatWhenOpened); + BindCheckBox(UpdateServersWhenOpenedCheckBox, + b => Global.Settings.UpdateServersWhenOpened = b, + Global.Settings.UpdateServersWhenOpened); #endregion @@ -269,15 +272,11 @@ namespace Netch.Forms TUNTAPDNSTextBox.Enabled = UseCustomDNSCheckBox.Checked; if (UseCustomDNSCheckBox.Checked) - { TUNTAPDNSTextBox.Text = Global.Settings.TUNTAP.DNS.Any() ? DNS.Join(Global.Settings.TUNTAP.DNS) : "1.1.1.1"; - } else - { TUNTAPDNSTextBox.Text = "AioDNS"; - } } @@ -317,9 +316,7 @@ namespace Netch.Forms } if (!flag) - { return; - } #endregion @@ -336,9 +333,7 @@ namespace Netch.Forms stunServer = stun[0]; if (stun.Length > 1) if (!ushort.TryParse(stun[1], out stunServerPort)) - { errFlag = true; - } } else { @@ -356,9 +351,7 @@ namespace Netch.Forms #region Save foreach (var pair in _saveActions) - { pair.Value.Invoke(pair.Key); - } Global.Settings.STUN_Server = stunServer; Global.Settings.STUN_Server_Port = stunServerPort; @@ -428,19 +421,15 @@ namespace Netch.Forms { control.Checked = value; _checkActions.Add(control, s => true); - _saveActions.Add(control, c => save.Invoke(((CheckBox)c).Checked)); + _saveActions.Add(control, c => save.Invoke(((CheckBox) c).Checked)); } private void BindRadioBox(RadioButton control, Action save, bool value) { control.Checked = value; _checkActions.Add(control, s => true); - _saveActions.Add(control, c => save.Invoke(((RadioButton)c).Checked)); + _saveActions.Add(control, c => save.Invoke(((RadioButton) c).Checked)); } - private readonly Dictionary> _checkActions = new Dictionary>(); - - private readonly Dictionary> _saveActions = new Dictionary>(); - private void ModifySystemDNSCheckBox_CheckedChanged(object sender, EventArgs e) { ModifiedDNSTextBox.Enabled = ModifySystemDNSCheckBox.Checked; diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index f2578317..43f6e4ca 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -3,60 +3,59 @@ namespace Netch.Models { /// - /// TUN/TAP 适配器配置类 + /// TUN/TAP 适配器配置类 /// public class TUNTAPConfig { /// - /// 地址 + /// 地址 /// public string Address = "10.0.236.10"; /// - /// 掩码 + /// DNS /// - public string Netmask = "255.255.255.0"; + public List DNS = new(); /// - /// 网关 + /// 网关 /// public string Gateway = "10.0.236.1"; /// - /// DNS + /// 掩码 /// - public List DNS = new List(); + public string Netmask = "255.255.255.0"; /// - /// 使用自定义 DNS 设置 - /// - public bool UseCustomDNS = false; - - /// - /// 模式 2 下是否代理 DNS + /// 模式 2 下是否代理 DNS /// public bool ProxyDNS = false; /// - /// 使用Fake DNS + /// 使用自定义 DNS 设置 + /// + public bool UseCustomDNS = false; + + /// + /// 使用Fake DNS /// public bool UseFakeDNS = false; } public class KcpConfig { + public bool congestion = false; + + public int downlinkCapacity = 100; public int mtu = 1350; + public int readBufferSize = 2; + public int tti = 50; public int uplinkCapacity = 12; - public int downlinkCapacity = 100; - - public bool congestion = false; - - public int readBufferSize = 2; - public int writeBufferSize = 2; } @@ -64,20 +63,19 @@ namespace Netch.Models { public bool AllowInsecure = true; - public KcpConfig KcpConfig = new KcpConfig(); + public KcpConfig KcpConfig = new(); public bool UseMux = false; } public class AioDNSConfig { - public string RulePath = "bin\\china_site_list"; - public string ChinaDNS = "223.5.5.5"; public string OtherDNS = "1.1.1.1"; public string Protocol = "tcp"; + public string RulePath = "bin\\china_site_list"; } /// @@ -85,35 +83,57 @@ namespace Netch.Models /// public class Setting { - - public V2rayConfig V2RayConfig = new V2rayConfig(); - - public AioDNSConfig AioDNS = new AioDNSConfig(); - /// - /// 服务器选择位置 + /// 服务器列表 /// - public int ServerComboBoxSelectedIndex = 0; + public readonly List Server = new(); /// - /// 模式选择位置 + /// ACL规则 /// - public int ModeComboBoxSelectedIndex = 0; + public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl"; + + public AioDNSConfig AioDNS = new(); /// - /// 是否关闭窗口时退出 + /// 是否使用DLL启动Shadowsocks + /// + public bool BootShadowsocksFromDLL = true; + + /// + /// 全局绕过 IP 列表 + /// + public List BypassIPs = new(); + + /// + /// 是否检查 Beta 更新 + /// + public bool CheckBetaUpdate = false; + + /// + /// 是否打开软件时检查更新 + /// + public bool CheckUpdateWhenOpened = true; + + /// + /// 是否关闭窗口时退出 /// public bool ExitWhenClosed = false; /// - /// 是否退出时停止 + /// HTTP 本地端口 /// - public bool StopWhenExited = false; + public ushort HTTPLocalPort = 2802; /// - /// 是否打开软件时启动加速 + /// 语言设置 /// - public bool StartWhenOpened = false; + public string Language = "System"; + + /// + /// HTTP 和 Socks5 本地代理地址 + /// + public string LocalAddress = "127.0.0.1"; /// /// 是否启动后自动最小化 @@ -121,29 +141,9 @@ namespace Netch.Models public bool MinimizeWhenStarted = false; /// - /// 是否开机启动软件 + /// 模式选择位置 /// - public bool RunAtStartup = false; - - /// - /// 是否打开软件时检查更新 - /// - public bool CheckUpdateWhenOpened = true; - - /// - /// 是否检查 Beta 更新 - /// - public bool CheckBetaUpdate = false; - - /// - /// 是否打开软件时更新订阅 - /// - public bool UpdateSubscribeatWhenOpened = false; - - /// - /// 修改系统 DNS - /// - public bool ModifySystemDNS = false; + public int ModeComboBoxSelectedIndex = 0; /// /// 要修改为的系统 DNS @@ -151,19 +151,14 @@ namespace Netch.Models public string ModifiedDNS = "1.1.1.1,8.8.8.8"; /// - /// 解析服务器主机名 + /// 修改系统 DNS /// - public bool ResolveServerHostname = false; + public bool ModifySystemDNS = false; /// - /// 网页请求超时 毫秒 + /// GFWList /// - public int RequestTimeout = 10000; - - /// - /// PAC URL - /// - public string Pac_Url = ""; + public string PAC = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/ss_white.pac"; /// /// PAC端口 @@ -171,74 +166,69 @@ namespace Netch.Models public int Pac_Port = 2803; /// - /// HTTP 本地端口 + /// PAC URL /// - public ushort HTTPLocalPort = 2802; + public string Pac_Url = ""; /// - /// Socks5 本地端口 + /// 不代理TCP /// - public ushort Socks5LocalPort = 2801; + public bool ProcessNoProxyForTcp = false; /// - /// Redirector TCP 占用端口 + /// 不代理UDP /// - public ushort RedirectorTCPPort = 3901; + public bool ProcessNoProxyForUdp = false; /// - /// UDP Socket 占用端口 - /// - public ushort UDPSocketPort = 18291; - - /// - /// HTTP 和 Socks5 本地代理地址 - /// - public string LocalAddress = "127.0.0.1"; - - /// - /// TUNTAP 适配器配置 - /// - public TUNTAPConfig TUNTAP = new TUNTAPConfig(); - - /// - /// 使用代理更新订阅 - /// - public bool UseProxyToUpdateSubscription = false; - - /// - /// 订阅链接列表 - /// - public List SubscribeLink = new List(); - - /// - /// 服务器列表 - /// - public readonly List Server = new List(); - - /// - /// 全局绕过 IP 列表 - /// - public List BypassIPs = new List(); - - /// - /// 已保存的快捷配置 - /// - public List Profiles = new List(); - - /// - /// 快捷配置数量 + /// 快捷配置数量 /// public int ProfileCount = 4; /// - /// STUN测试服务器 + /// 已保存的快捷配置 /// - public string STUN_Server = "stun.syncthing.net"; + public List Profiles = new(); /// - /// STUN测试服务器 + /// 是否使用RDR内置SS /// - public int STUN_Server_Port = 3478; + public bool RedirectorSS = false; + + /// + /// Redirector TCP 占用端口 + /// + public ushort RedirectorTCPPort = 3901; + + /// + /// 网页请求超时 毫秒 + /// + public int RequestTimeout = 10000; + + /// + /// 解析服务器主机名 + /// + public bool ResolveServerHostname = false; + + /// + /// 是否开机启动软件 + /// + public bool RunAtStartup = false; + + /// + /// 服务器选择位置 + /// + public int ServerComboBoxSelectedIndex = 0; + + /// + /// 服务器测试方式 false.ICMPing true.TCPing + /// + public bool ServerTCPing = true; + + /// + /// Socks5 本地端口 + /// + public ushort Socks5LocalPort = 2801; /// /// 是否启用启动后延迟测试 @@ -251,43 +241,50 @@ namespace Netch.Models public int StartedTcping_Interval = 3; /// - /// ACL规则 + /// 是否打开软件时启动加速 /// - public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl"; + public bool StartWhenOpened = false; /// - /// GFWList + /// 是否退出时停止 /// - public string PAC = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/ss_white.pac"; + public bool StopWhenExited = false; /// - /// 是否使用DLL启动Shadowsocks + /// STUN测试服务器 /// - public bool BootShadowsocksFromDLL = true; + public string STUN_Server = "stun.syncthing.net"; /// - /// 语言设置 + /// STUN测试服务器 /// - public string Language = "System"; + public int STUN_Server_Port = 3478; /// - /// 服务器测试方式 false.ICMPing true.TCPing + /// 订阅链接列表 /// - public bool ServerTCPing = true; + public List SubscribeLink = new(); /// - /// 是否使用RDR内置SS + /// TUNTAP 适配器配置 /// - public bool RedirectorSS = false; + public TUNTAPConfig TUNTAP = new(); /// - /// 不代理UDP + /// UDP Socket 占用端口 /// - public bool ProcessNoProxyForUdp = false; + public ushort UDPSocketPort = 18291; /// - /// 不代理TCP + /// 是否打开软件时更新订阅 /// - public bool ProcessNoProxyForTcp = false; + public bool UpdateServersWhenOpened = false; + + /// + /// 使用代理更新订阅 + /// + public bool UseProxyToUpdateSubscription = false; + + public V2rayConfig V2RayConfig = new(); } } \ No newline at end of file diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 45c1a905..707c7bf3 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -167,7 +167,7 @@ "Port value illegal. Try again.": "端口值非法。请重试。", "Check update when opened": "打开软件时检查更新", "Check Beta update": "检查 Beta 更新", - "Update subscribeat when opened": "自动更新订阅", + "Update Servers when opened": "打开软件时更新服务器", "SS DLL": "SS DLL", "Modify System DNS": "修改系统 DNS", "No Proxy for Udp": "不代理Udp流量",