[Break] Rename UpdateSubscribeatWhenOpened to UpdateServersWhenOpened

This commit is contained in:
ChsBuffer
2021-01-12 19:13:14 +08:00
parent 8cf32e5d37
commit 59cfc071cc
5 changed files with 186 additions and 222 deletions

View File

@@ -16,6 +16,10 @@ namespace Netch.Forms
{
public partial class MainForm : Form
{
private readonly Dictionary<string, object> _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<string, object> _mainFormText = new Dictionary<string, object>();
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;
/// <summary>
/// 监听电源事件自动重启Netch服务
/// 监听电源事件自动重启Netch服务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
@@ -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();
}
}
}
}

View File

@@ -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;

View File

@@ -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<Control, Func<string, bool>> _checkActions = new();
private readonly Dictionary<Control, Action<Control>> _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<bool> 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<Control, Func<string, bool>> _checkActions = new Dictionary<Control, Func<string, bool>>();
private readonly Dictionary<Control, Action<Control>> _saveActions = new Dictionary<Control, Action<Control>>();
private void ModifySystemDNSCheckBox_CheckedChanged(object sender, EventArgs e)
{
ModifiedDNSTextBox.Enabled = ModifySystemDNSCheckBox.Checked;

View File

@@ -3,60 +3,59 @@
namespace Netch.Models
{
/// <summary>
/// TUN/TAP 适配器配置类
/// TUN/TAP 适配器配置类
/// </summary>
public class TUNTAPConfig
{
/// <summary>
/// 地址
/// 地址
/// </summary>
public string Address = "10.0.236.10";
/// <summary>
/// 掩码
/// DNS
/// </summary>
public string Netmask = "255.255.255.0";
public List<string> DNS = new();
/// <summary>
/// 网关
/// 网关
/// </summary>
public string Gateway = "10.0.236.1";
/// <summary>
/// DNS
/// 掩码
/// </summary>
public List<string> DNS = new List<string>();
public string Netmask = "255.255.255.0";
/// <summary>
/// 使用自定义 DNS 设置
/// </summary>
public bool UseCustomDNS = false;
/// <summary>
/// 模式 2 下是否代理 DNS
/// 模式 2 下是否代理 DNS
/// </summary>
public bool ProxyDNS = false;
/// <summary>
/// 使用Fake DNS
/// 使用自定义 DNS 设置
/// </summary>
public bool UseCustomDNS = false;
/// <summary>
/// 使用Fake DNS
/// </summary>
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";
}
/// <summary>
@@ -85,35 +83,57 @@ namespace Netch.Models
/// </summary>
public class Setting
{
public V2rayConfig V2RayConfig = new V2rayConfig();
public AioDNSConfig AioDNS = new AioDNSConfig();
/// <summary>
/// 服务器选择位置
/// 服务器列表
/// </summary>
public int ServerComboBoxSelectedIndex = 0;
public readonly List<Server> Server = new();
/// <summary>
/// 模式选择位置
/// ACL规则
/// </summary>
public int ModeComboBoxSelectedIndex = 0;
public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl";
public AioDNSConfig AioDNS = new();
/// <summary>
/// 是否关闭窗口时退出
/// 是否使用DLL启动Shadowsocks
/// </summary>
public bool BootShadowsocksFromDLL = true;
/// <summary>
/// 全局绕过 IP 列表
/// </summary>
public List<string> BypassIPs = new();
/// <summary>
/// 是否检查 Beta 更新
/// </summary>
public bool CheckBetaUpdate = false;
/// <summary>
/// 是否打开软件时检查更新
/// </summary>
public bool CheckUpdateWhenOpened = true;
/// <summary>
/// 是否关闭窗口时退出
/// </summary>
public bool ExitWhenClosed = false;
/// <summary>
/// 是否退出时停止
/// HTTP 本地端口
/// </summary>
public bool StopWhenExited = false;
public ushort HTTPLocalPort = 2802;
/// <summary>
/// 是否打开软件时启动加速
/// 语言设置
/// </summary>
public bool StartWhenOpened = false;
public string Language = "System";
/// <summary>
/// HTTP 和 Socks5 本地代理地址
/// </summary>
public string LocalAddress = "127.0.0.1";
/// <summary>
/// 是否启动后自动最小化
@@ -121,29 +141,9 @@ namespace Netch.Models
public bool MinimizeWhenStarted = false;
/// <summary>
/// 是否开机启动软件
/// 模式选择位置
/// </summary>
public bool RunAtStartup = false;
/// <summary>
/// 是否打开软件时检查更新
/// </summary>
public bool CheckUpdateWhenOpened = true;
/// <summary>
/// 是否检查 Beta 更新
/// </summary>
public bool CheckBetaUpdate = false;
/// <summary>
/// 是否打开软件时更新订阅
/// </summary>
public bool UpdateSubscribeatWhenOpened = false;
/// <summary>
/// 修改系统 DNS
/// </summary>
public bool ModifySystemDNS = false;
public int ModeComboBoxSelectedIndex = 0;
/// <summary>
/// 要修改为的系统 DNS
@@ -151,19 +151,14 @@ namespace Netch.Models
public string ModifiedDNS = "1.1.1.1,8.8.8.8";
/// <summary>
/// 解析服务器主机名
/// 修改系统 DNS
/// </summary>
public bool ResolveServerHostname = false;
public bool ModifySystemDNS = false;
/// <summary>
/// 网页请求超时 毫秒
/// GFWList
/// </summary>
public int RequestTimeout = 10000;
/// <summary>
/// PAC URL
/// </summary>
public string Pac_Url = "";
public string PAC = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/ss_white.pac";
/// <summary>
/// PAC端口
@@ -171,74 +166,69 @@ namespace Netch.Models
public int Pac_Port = 2803;
/// <summary>
/// HTTP 本地端口
/// PAC URL
/// </summary>
public ushort HTTPLocalPort = 2802;
public string Pac_Url = "";
/// <summary>
/// Socks5 本地端口
/// 不代理TCP
/// </summary>
public ushort Socks5LocalPort = 2801;
public bool ProcessNoProxyForTcp = false;
/// <summary>
/// Redirector TCP 占用端口
/// 不代理UDP
/// </summary>
public ushort RedirectorTCPPort = 3901;
public bool ProcessNoProxyForUdp = false;
/// <summary>
/// UDP Socket 占用端口
/// </summary>
public ushort UDPSocketPort = 18291;
/// <summary>
/// HTTP 和 Socks5 本地代理地址
/// </summary>
public string LocalAddress = "127.0.0.1";
/// <summary>
/// TUNTAP 适配器配置
/// </summary>
public TUNTAPConfig TUNTAP = new TUNTAPConfig();
/// <summary>
/// 使用代理更新订阅
/// </summary>
public bool UseProxyToUpdateSubscription = false;
/// <summary>
/// 订阅链接列表
/// </summary>
public List<SubscribeLink> SubscribeLink = new List<SubscribeLink>();
/// <summary>
/// 服务器列表
/// </summary>
public readonly List<Server> Server = new List<Server>();
/// <summary>
/// 全局绕过 IP 列表
/// </summary>
public List<string> BypassIPs = new List<string>();
/// <summary>
/// 已保存的快捷配置
/// </summary>
public List<Profile> Profiles = new List<Profile>();
/// <summary>
/// 快捷配置数量
/// 快捷配置数量
/// </summary>
public int ProfileCount = 4;
/// <summary>
/// STUN测试服务器
/// 已保存的快捷配置
/// </summary>
public string STUN_Server = "stun.syncthing.net";
public List<Profile> Profiles = new();
/// <summary>
/// STUN测试服务器
/// 是否使用RDR内置SS
/// </summary>
public int STUN_Server_Port = 3478;
public bool RedirectorSS = false;
/// <summary>
/// Redirector TCP 占用端口
/// </summary>
public ushort RedirectorTCPPort = 3901;
/// <summary>
/// 网页请求超时 毫秒
/// </summary>
public int RequestTimeout = 10000;
/// <summary>
/// 解析服务器主机名
/// </summary>
public bool ResolveServerHostname = false;
/// <summary>
/// 是否开机启动软件
/// </summary>
public bool RunAtStartup = false;
/// <summary>
/// 服务器选择位置
/// </summary>
public int ServerComboBoxSelectedIndex = 0;
/// <summary>
/// 服务器测试方式 false.ICMPing true.TCPing
/// </summary>
public bool ServerTCPing = true;
/// <summary>
/// Socks5 本地端口
/// </summary>
public ushort Socks5LocalPort = 2801;
/// <summary>
/// 是否启用启动后延迟测试
@@ -251,43 +241,50 @@ namespace Netch.Models
public int StartedTcping_Interval = 3;
/// <summary>
/// ACL规则
/// 是否打开软件时启动加速
/// </summary>
public string ACL = "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/banAD.acl";
public bool StartWhenOpened = false;
/// <summary>
/// GFWList
/// 是否退出时停止
/// </summary>
public string PAC = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/ss_white.pac";
public bool StopWhenExited = false;
/// <summary>
/// 是否使用DLL启动Shadowsocks
/// STUN测试服务器
/// </summary>
public bool BootShadowsocksFromDLL = true;
public string STUN_Server = "stun.syncthing.net";
/// <summary>
/// 语言设置
/// STUN测试服务器
/// </summary>
public string Language = "System";
public int STUN_Server_Port = 3478;
/// <summary>
/// 服务器测试方式 false.ICMPing true.TCPing
/// 订阅链接列表
/// </summary>
public bool ServerTCPing = true;
public List<SubscribeLink> SubscribeLink = new();
/// <summary>
/// 是否使用RDR内置SS
/// TUNTAP 适配器配置
/// </summary>
public bool RedirectorSS = false;
public TUNTAPConfig TUNTAP = new();
/// <summary>
/// 不代理UDP
/// UDP Socket 占用端口
/// </summary>
public bool ProcessNoProxyForUdp = false;
public ushort UDPSocketPort = 18291;
/// <summary>
/// 不代理TCP
/// 是否打开软件时更新订阅
/// </summary>
public bool ProcessNoProxyForTcp = false;
public bool UpdateServersWhenOpened = false;
/// <summary>
/// 使用代理更新订阅
/// </summary>
public bool UseProxyToUpdateSubscription = false;
public V2rayConfig V2RayConfig = new();
}
}

View File

@@ -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流量",