diff --git a/Netch/Controllers/Guard.cs b/Netch/Controllers/Guard.cs index a9079c34..066b1bc4 100644 --- a/Netch/Controllers/Guard.cs +++ b/Netch/Controllers/Guard.cs @@ -157,7 +157,7 @@ namespace Netch.Controllers } catch (Win32Exception e) { - Log.Error(e, "停止 {Name} 异常", Instance.ProcessName); + Log.Error(e, "Stop {Name} failed", Instance.ProcessName); } catch { diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 1690926d..dfbb3fa3 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -10,7 +10,6 @@ using Netch.Models; using Netch.Servers; using Netch.Utils; using Serilog; -using Serilog.Events; namespace Netch.Controllers { @@ -48,14 +47,6 @@ namespace Netch.Controllers await Task.WhenAll(Task.Run(NativeMethods.RefreshDNSCache), Task.Run(Firewall.AddNetchFwRules)); - if (Log.IsEnabled(LogEventLevel.Debug)) - Task.Run(() => - { - // TODO log level setting - Log.Debug("Running Processes: \n{Processes}", string.Join("\n", SystemInfo.Processes(false))); - }) - .Forget(); - try { (ModeController, ModeFeatures) = ModeHelper.GetModeControllerByType(mode.Type, out var modePort, out var portName); diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs index 333fcdc9..d1f924ed 100644 --- a/Netch/Controllers/NFController.cs +++ b/Netch/Controllers/NFController.cs @@ -149,8 +149,7 @@ namespace Netch.Controllers if (invalidList.Any()) throw new MessageException(GenerateInvalidRulesMessage(invalidList)); - Dial(NameList.TYPE_ADDNAME, @"NTT\.exe"); - Dial(NameList.TYPE_BYPNAME, "^" + Global.NetchDir.ToRegexString() + @"((?!NTT\.exe).)*$"); + Dial(NameList.TYPE_BYPNAME, "^" + Global.NetchDir.ToRegexString()); } private void CheckCore() @@ -166,8 +165,8 @@ namespace Netch.Controllers var binFileVersion = Utils.Utils.GetFileVersion(Constants.NFDriver); var systemFileVersion = Utils.Utils.GetFileVersion(SystemDriver); - Log.Information("内置驱动版本: {Name}", binFileVersion); - Log.Information("系统驱动版本: {Name}", systemFileVersion); + Log.Information("Built-in netfilter2 driver version: {Name}", binFileVersion); + Log.Information("Installed netfilter2 driver version: {Name}", systemFileVersion); if (!File.Exists(SystemDriver)) { @@ -197,7 +196,7 @@ namespace Netch.Controllers if (!reinstall) return; - Log.Information("更新驱动"); + Log.Information("Update netfilter2 driver"); UninstallDriver(); InstallDriver(); } @@ -208,7 +207,8 @@ namespace Netch.Controllers /// 驱动是否安装成功 private static void InstallDriver() { - Log.Information("安装 NF 驱动"); + Log.Information("Install netfilter2 driver"); + Global.MainForm.StatusText(i18N.Translate("Installing netfilter2 driver")); if (!File.Exists(Constants.NFDriver)) throw new MessageException(i18N.Translate("builtin driver files missing, can't install NF driver")); @@ -219,21 +219,20 @@ namespace Netch.Controllers } catch (Exception e) { - Log.Error(e, "驱动复制失败\n"); - throw new MessageException($"Copy NF driver file failed\n{e.Message}"); + Log.Error(e, "Copy netfilter2.sys failed\n"); + throw new MessageException($"Copy netfilter2.sys failed\n{e.Message}"); } - Global.MainForm.StatusText(i18N.Translate("Register driver")); // 注册驱动文件 var result = NFAPI.nf_registerDriver("netfilter2"); if (result == NF_STATUS.NF_STATUS_SUCCESS) { - Log.Information("驱动安装成功"); + Log.Information("Install netfilter2 driver finished"); } else { - Log.Error("注册驱动失败: {Result}", result); - throw new MessageException($"Register NF driver failed\n{result}"); + Log.Error("Register netfilter2 failed: {Result}", result); + throw new MessageException($"Register netfilter2 failed\n{result}"); } } @@ -243,7 +242,7 @@ namespace Netch.Controllers /// 是否成功卸载 public static bool UninstallDriver() { - Log.Information("卸载 NF 驱动"); + Log.Information("Uninstall netfilter2"); try { if (NFService.Status == ServiceControllerStatus.Running) diff --git a/Netch/Controllers/TUNController.cs b/Netch/Controllers/TUNController.cs index 1112e02b..48832c71 100644 --- a/Netch/Controllers/TUNController.cs +++ b/Netch/Controllers/TUNController.cs @@ -125,8 +125,8 @@ namespace Netch.Controllers var binHash = Utils.Utils.SHA256CheckSum(binDriver); var sysHash = Utils.Utils.SHA256CheckSum(sysDriver); - Log.Information("自带 wintun.dll Hash: {Hash}", binHash); - Log.Information("系统 wintun.dll Hash: {Hash}", sysHash); + Log.Information("Built-in wintun.dll Hash: {Hash}", binHash); + Log.Information("Installed wintun.dll Hash: {Hash}", sysHash); if (binHash == sysHash) return; @@ -137,7 +137,7 @@ namespace Netch.Controllers } catch (Exception e) { - Log.Error(e, "复制 wintun.dll 异常"); + Log.Error(e, "Copy wintun.dll failed"); throw new MessageException($"Failed to copy wintun.dll to system directory: {e.Message}"); } } diff --git a/Netch/Controllers/UpdateChecker.cs b/Netch/Controllers/UpdateChecker.cs index 2a7909ac..1f55c4f6 100644 --- a/Netch/Controllers/UpdateChecker.cs +++ b/Netch/Controllers/UpdateChecker.cs @@ -48,24 +48,24 @@ namespace Netch.Controllers var releases = JsonSerializer.Deserialize>(json)!; LatestRelease = GetLatestRelease(releases, isPreRelease); - Log.Information("Github 最新发布版本: {Version}", LatestRelease.tag_name); + Log.Information("Github latest release: {Version}", LatestRelease.tag_name); if (VersionUtil.CompareVersion(LatestRelease.tag_name, Version) > 0) { - Log.Information("发现新版本"); + Log.Information("Found newer version"); NewVersionFound?.Invoke(null, EventArgs.Empty); } else { - Log.Information("目前是最新版本"); + Log.Information("Already the latest version"); NewVersionNotFound?.Invoke(null, EventArgs.Empty); } } catch (Exception e) { if (e is WebException) - Log.Warning(e, "获取新版本失败"); + Log.Warning(e, "Get releases failed"); else - Log.Error(e, "获取新版本异常"); + Log.Error(e, "Get releases error"); NewVersionFoundFailed?.Invoke(null, EventArgs.Empty); } diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index cafd6c55..0002a833 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -35,19 +35,19 @@ this.ModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CreateProcessModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CreateRouteTableRuleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.SubscribeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ManageSubscribeLinksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.UpdateServersFromSubscribeLinksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SubscriptionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ManageSubscriptionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.UpdateServersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OptionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OpenDirectoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ShowHideConsoleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CleanDNSCacheToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.UninstallServiceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.removeNetchFirewallRulesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.RemoveNetchFirewallRulesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.HelpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.CheckForUpdatesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.fAQToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.CheckForUpdateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.FAQToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ForceExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AboutToolStripButton = new System.Windows.Forms.ToolStripButton(); this.NewVersionLabel = new System.Windows.Forms.ToolStripLabel(); this.VersionLabel = new System.Windows.Forms.ToolStripLabel(); @@ -111,10 +111,10 @@ this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ServerToolStripMenuItem, this.ModeToolStripMenuItem, - this.SubscribeToolStripMenuItem, + this.SubscriptionToolStripMenuItem, this.OptionsToolStripMenuItem, this.HelpToolStripMenuItem, - this.exitToolStripMenuItem, + this.ForceExitToolStripMenuItem, this.AboutToolStripButton, this.NewVersionLabel, this.VersionLabel}); @@ -164,29 +164,29 @@ this.CreateRouteTableRuleToolStripMenuItem.Text = "Create Route Table Rule"; this.CreateRouteTableRuleToolStripMenuItem.Click += new System.EventHandler(this.createRouteTableModeToolStripMenuItem_Click); // - // SubscribeToolStripMenuItem + // SubscriptionToolStripMenuItem // - this.SubscribeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.ManageSubscribeLinksToolStripMenuItem, - this.UpdateServersFromSubscribeLinksToolStripMenuItem}); - this.SubscribeToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1); - this.SubscribeToolStripMenuItem.Name = "SubscribeToolStripMenuItem"; - this.SubscribeToolStripMenuItem.Size = new System.Drawing.Size(77, 21); - this.SubscribeToolStripMenuItem.Text = "Subscribe"; + this.SubscriptionToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ManageSubscriptionsToolStripMenuItem, + this.UpdateServersToolStripMenuItem}); + this.SubscriptionToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1); + this.SubscriptionToolStripMenuItem.Name = "SubscriptionToolStripMenuItem"; + this.SubscriptionToolStripMenuItem.Size = new System.Drawing.Size(92, 21); + this.SubscriptionToolStripMenuItem.Text = "Subscription"; // - // ManageSubscribeLinksToolStripMenuItem + // ManageSubscriptionsToolStripMenuItem // - this.ManageSubscribeLinksToolStripMenuItem.Name = "ManageSubscribeLinksToolStripMenuItem"; - this.ManageSubscribeLinksToolStripMenuItem.Size = new System.Drawing.Size(294, 22); - this.ManageSubscribeLinksToolStripMenuItem.Text = "Manage Subscribe Links"; - this.ManageSubscribeLinksToolStripMenuItem.Click += new System.EventHandler(this.ManageSubscribeLinksToolStripMenuItem_Click); + this.ManageSubscriptionsToolStripMenuItem.Name = "ManageSubscriptionsToolStripMenuItem"; + this.ManageSubscriptionsToolStripMenuItem.Size = new System.Drawing.Size(206, 22); + this.ManageSubscriptionsToolStripMenuItem.Text = "Manage Subscriptions"; + this.ManageSubscriptionsToolStripMenuItem.Click += new System.EventHandler(this.ManageSubscriptionLinksToolStripMenuItem_Click); // - // UpdateServersFromSubscribeLinksToolStripMenuItem + // UpdateServersToolStripMenuItem // - this.UpdateServersFromSubscribeLinksToolStripMenuItem.Name = "UpdateServersFromSubscribeLinksToolStripMenuItem"; - this.UpdateServersFromSubscribeLinksToolStripMenuItem.Size = new System.Drawing.Size(294, 22); - this.UpdateServersFromSubscribeLinksToolStripMenuItem.Text = "Update Servers From Subscribe Links"; - this.UpdateServersFromSubscribeLinksToolStripMenuItem.Click += new System.EventHandler(this.UpdateServersFromSubscribeLinksToolStripMenuItem_Click); + this.UpdateServersToolStripMenuItem.Name = "UpdateServersToolStripMenuItem"; + this.UpdateServersToolStripMenuItem.Size = new System.Drawing.Size(206, 22); + this.UpdateServersToolStripMenuItem.Text = "Update Servers"; + this.UpdateServersToolStripMenuItem.Click += new System.EventHandler(this.UpdateServersFromSubscriptionLinksToolStripMenuItem_Click); // // OptionsToolStripMenuItem // @@ -195,7 +195,7 @@ this.ShowHideConsoleToolStripMenuItem, this.CleanDNSCacheToolStripMenuItem, this.UninstallServiceToolStripMenuItem, - this.removeNetchFirewallRulesToolStripMenuItem}); + this.RemoveNetchFirewallRulesToolStripMenuItem}); this.OptionsToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1); this.OptionsToolStripMenuItem.Name = "OptionsToolStripMenuItem"; this.OptionsToolStripMenuItem.Size = new System.Drawing.Size(66, 21); @@ -229,43 +229,43 @@ this.UninstallServiceToolStripMenuItem.Text = "Uninstall NF Service"; this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click); // - // removeNetchFirewallRulesToolStripMenuItem + // RemoveNetchFirewallRulesToolStripMenuItem // - this.removeNetchFirewallRulesToolStripMenuItem.Name = "removeNetchFirewallRulesToolStripMenuItem"; - this.removeNetchFirewallRulesToolStripMenuItem.Size = new System.Drawing.Size(243, 22); - this.removeNetchFirewallRulesToolStripMenuItem.Text = "Remove Netch Firewall Rules"; - this.removeNetchFirewallRulesToolStripMenuItem.Click += new System.EventHandler(this.RemoveNetchFirewallRulesToolStripMenuItem_Click); + this.RemoveNetchFirewallRulesToolStripMenuItem.Name = "RemoveNetchFirewallRulesToolStripMenuItem"; + this.RemoveNetchFirewallRulesToolStripMenuItem.Size = new System.Drawing.Size(243, 22); + this.RemoveNetchFirewallRulesToolStripMenuItem.Text = "Remove Netch Firewall Rules"; + this.RemoveNetchFirewallRulesToolStripMenuItem.Click += new System.EventHandler(this.RemoveNetchFirewallRulesToolStripMenuItem_Click); // // HelpToolStripMenuItem // this.HelpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.CheckForUpdatesToolStripMenuItem, - this.fAQToolStripMenuItem}); + this.CheckForUpdateToolStripMenuItem, + this.FAQToolStripMenuItem}); this.HelpToolStripMenuItem.Margin = new System.Windows.Forms.Padding(0, 0, 0, 1); this.HelpToolStripMenuItem.Name = "HelpToolStripMenuItem"; this.HelpToolStripMenuItem.Size = new System.Drawing.Size(47, 21); this.HelpToolStripMenuItem.Text = "Help"; // - // CheckForUpdatesToolStripMenuItem + // CheckForUpdateToolStripMenuItem // - this.CheckForUpdatesToolStripMenuItem.Name = "CheckForUpdatesToolStripMenuItem"; - this.CheckForUpdatesToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.CheckForUpdatesToolStripMenuItem.Text = "Check for updates"; - this.CheckForUpdatesToolStripMenuItem.Click += new System.EventHandler(this.CheckForUpdatesToolStripMenuItem_Click); + this.CheckForUpdateToolStripMenuItem.Name = "CheckForUpdateToolStripMenuItem"; + this.CheckForUpdateToolStripMenuItem.Size = new System.Drawing.Size(177, 22); + this.CheckForUpdateToolStripMenuItem.Text = "Check for update"; + this.CheckForUpdateToolStripMenuItem.Click += new System.EventHandler(this.CheckForUpdatesToolStripMenuItem_Click); // - // fAQToolStripMenuItem + // FAQToolStripMenuItem // - this.fAQToolStripMenuItem.Name = "fAQToolStripMenuItem"; - this.fAQToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.fAQToolStripMenuItem.Text = "FAQ"; - this.fAQToolStripMenuItem.Click += new System.EventHandler(this.fAQToolStripMenuItem_Click); + this.FAQToolStripMenuItem.Name = "FAQToolStripMenuItem"; + this.FAQToolStripMenuItem.Size = new System.Drawing.Size(177, 22); + this.FAQToolStripMenuItem.Text = "FAQ"; + this.FAQToolStripMenuItem.Click += new System.EventHandler(this.fAQToolStripMenuItem_Click); // - // exitToolStripMenuItem + // ForceExitToolStripMenuItem // - this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(40, 22); - this.exitToolStripMenuItem.Text = "Exit"; - this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + this.ForceExitToolStripMenuItem.Name = "ForceExitToolStripMenuItem"; + this.ForceExitToolStripMenuItem.Size = new System.Drawing.Size(40, 22); + this.ForceExitToolStripMenuItem.Text = "Exit"; + this.ForceExitToolStripMenuItem.Click += new System.EventHandler(this.ForceExitToolStripMenuItem_Click); // // AboutToolStripButton // @@ -562,7 +562,7 @@ // blankToolStripStatusLabel // this.blankToolStripStatusLabel.Name = "blankToolStripStatusLabel"; - this.blankToolStripStatusLabel.Size = new System.Drawing.Size(240, 17); + this.blankToolStripStatusLabel.Size = new System.Drawing.Size(494, 17); this.blankToolStripStatusLabel.Spring = true; // // HttpStatusLabel @@ -620,19 +620,19 @@ this.ExitToolStripButton}); this.NotifyMenu.Name = "NotifyMenu"; this.NotifyMenu.ShowItemToolTips = false; - this.NotifyMenu.Size = new System.Drawing.Size(108, 48); + this.NotifyMenu.Size = new System.Drawing.Size(181, 70); // // ShowMainFormToolStripButton // this.ShowMainFormToolStripButton.Name = "ShowMainFormToolStripButton"; - this.ShowMainFormToolStripButton.Size = new System.Drawing.Size(107, 22); + this.ShowMainFormToolStripButton.Size = new System.Drawing.Size(180, 22); this.ShowMainFormToolStripButton.Text = "Show"; this.ShowMainFormToolStripButton.Click += new System.EventHandler(this.ShowMainFormToolStripButton_Click); // // ExitToolStripButton // this.ExitToolStripButton.Name = "ExitToolStripButton"; - this.ExitToolStripButton.Size = new System.Drawing.Size(107, 22); + this.ExitToolStripButton.Size = new System.Drawing.Size(180, 22); this.ExitToolStripButton.Text = "Exit"; this.ExitToolStripButton.Click += new System.EventHandler(this.ExitToolStripButton_Click); // @@ -744,7 +744,7 @@ private System.Windows.Forms.ToolStripMenuItem CreateRouteTableRuleToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem removeNetchFirewallRulesToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem RemoveNetchFirewallRulesToolStripMenuItem; private System.Windows.Forms.ToolStripButton AboutToolStripButton; private System.Windows.Forms.ToolStripMenuItem CleanDNSCacheToolStripMenuItem; @@ -759,9 +759,9 @@ private System.Windows.Forms.PictureBox EditModePictureBox; private System.Windows.Forms.PictureBox EditServerPictureBox; private System.Windows.Forms.ToolStripMenuItem ExitToolStripButton; - private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ForceExitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ImportServersFromClipboardToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem ManageSubscribeLinksToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ManageSubscriptionsToolStripMenuItem; private System.Windows.Forms.MenuStrip MenuStrip; public System.Windows.Forms.ComboBox ModeComboBox; private System.Windows.Forms.Label ModeLabel; @@ -776,7 +776,7 @@ private System.Windows.Forms.Label ProfileLabel; private System.Windows.Forms.TextBox ProfileNameText; private System.Windows.Forms.TableLayoutPanel ProfileTable; - private System.Windows.Forms.ToolStripMenuItem CheckForUpdatesToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem CheckForUpdateToolStripMenuItem; private System.Windows.Forms.ComboBox ServerComboBox; private System.Windows.Forms.Label ServerLabel; private System.Windows.Forms.ToolStripMenuItem ServerToolStripMenuItem; @@ -785,18 +785,18 @@ private System.Windows.Forms.PictureBox SpeedPictureBox; private System.Windows.Forms.ToolStripStatusLabel StatusLabel; private System.Windows.Forms.StatusStrip StatusStrip; - private System.Windows.Forms.ToolStripMenuItem SubscribeToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SubscriptionToolStripMenuItem; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; private System.Windows.Forms.ToolStripMenuItem UninstallServiceToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem UpdateServersFromSubscribeLinksToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem UpdateServersToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel UploadSpeedLabel; private System.Windows.Forms.ToolStripStatusLabel UsedBandwidthLabel; private System.Windows.Forms.ToolStripLabel NewVersionLabel; private System.Windows.Forms.ToolStripLabel VersionLabel; private System.Windows.Forms.ToolStripStatusLabel NatTypeStatusLightLabel; private System.Windows.Forms.ToolStripStatusLabel blankToolStripStatusLabel; - private System.Windows.Forms.ToolStripMenuItem fAQToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem FAQToolStripMenuItem; #endregion diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 8f5a0f55..716315b9 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -103,7 +103,7 @@ namespace Netch.Forms // 检查订阅更新 if (Global.Settings.UpdateServersWhenOpened) - UpdateServersFromSubscribeAsync().Forget(); + UpdateServersFromSubscriptionAsync().Forget(); // 打开软件时启动加速,产生开始按钮点击事件 if (Global.Settings.StartWhenOpened) @@ -263,47 +263,47 @@ namespace Netch.Forms #region Subscription - private void ManageSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e) + private void ManageSubscriptionLinksToolStripMenuItem_Click(object sender, EventArgs e) { Hide(); - new SubscribeForm().ShowDialog(); + new SubscriptionForm().ShowDialog(); LoadServers(); Show(); } - private async void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e) + private async void UpdateServersFromSubscriptionLinksToolStripMenuItem_Click(object sender, EventArgs e) { - await UpdateServersFromSubscribeAsync(); + await UpdateServersFromSubscriptionAsync(); } - private async Task UpdateServersFromSubscribeAsync() + private async Task UpdateServersFromSubscriptionAsync() { void DisableItems(bool v) { MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ProfileGroupBox.Enabled = ControlButton.Enabled = v; } - if (Global.Settings.SubscribeLink.Count <= 0) + if (Global.Settings.Subscription.Count <= 0) { MessageBoxX.Show(i18N.Translate("No subscription link")); return; } - StatusText(i18N.Translate("Starting update subscription")); + StatusText(i18N.Translate("Updating servers")); DisableItems(false); try { - await Subscription.UpdateServersAsync(); + await SubscriptionUtil.UpdateServersAsync(); LoadServers(); await Configuration.SaveAsync(); - StatusText(i18N.Translate("Subscription updated")); + StatusText(i18N.Translate("Servers updated")); } catch (Exception e) { - NotifyTip(i18N.Translate("update servers failed") + "\n" + e.Message, info: false); - Log.Error("更新服务器 失败!" + e); + NotifyTip(i18N.Translate("Unhandled update servers error") + "\n" + e.Message, info: false); + Log.Error(e, "Unhandled Update servers error"); } finally { @@ -324,7 +324,7 @@ namespace Netch.Forms void OnNewVersionFoundFailed(object? o, EventArgs? args) { - NotifyTip(i18N.Translate("New version found failed"), info: false); + NotifyTip(i18N.Translate("Check for update failed"), info: false); } try @@ -402,7 +402,7 @@ namespace Netch.Forms /// /// 菜单栏强制退出 /// - private void exitToolStripMenuItem_Click(object sender, EventArgs e) + private void ForceExitToolStripMenuItem_Click(object sender, EventArgs e) { Exit(true); } @@ -482,7 +482,7 @@ namespace Netch.Forms } catch (Exception exception) { - Log.Error(exception, "更新未处理异常"); + Log.Error(exception, "Unhandled Update error"); NotifyTip(exception.Message, info: false); } finally @@ -582,7 +582,7 @@ namespace Netch.Forms private void SettingsButton_Click(object sender, EventArgs e) { - var oldSettings = Global.Settings.Clone(); + var oldSettings = Global.Settings.ShallowCopy(); Hide(); new SettingForm().ShowDialog(); @@ -995,7 +995,7 @@ namespace Netch.Forms // 启动需要禁用的控件 ServerToolStripMenuItem.Enabled = ModeToolStripMenuItem.Enabled = - SubscribeToolStripMenuItem.Enabled = UninstallServiceToolStripMenuItem.Enabled = enabled; + SubscriptionToolStripMenuItem.Enabled = UninstallServiceToolStripMenuItem.Enabled = enabled; } _state = value; @@ -1172,7 +1172,7 @@ namespace Netch.Forms private async Task DiscoveryNatTypeAsync() { NatTypeStatusLabel.Enabled = false; - UpdateNatTypeStatusLabelText("Testing NAT Type"); + UpdateNatTypeStatusLabelText(i18N.Translate("Testing NAT Type")); _discoveryNatCts = new CancellationTokenSource(); @@ -1253,7 +1253,7 @@ namespace Netch.Forms if (!IsWaiting()) { _resumeFlag = true; - Log.Information("操作系统即将挂起,自动停止"); + Log.Information("OS Suspend, Stop"); ControlButton_Click(null, null); } @@ -1262,7 +1262,7 @@ namespace Netch.Forms if (_resumeFlag) { _resumeFlag = false; - Log.Information("操作系统即将从挂起状态继续,自动重启"); + Log.Information("OS Resume, Restart"); ControlButton_Click(null, null); } diff --git a/Netch/Forms/SubscribeForm.Designer.cs b/Netch/Forms/SubscriptionForm.Designer.cs similarity index 79% rename from Netch/Forms/SubscribeForm.Designer.cs rename to Netch/Forms/SubscriptionForm.Designer.cs index 350de5fb..a18e91ab 100644 --- a/Netch/Forms/SubscribeForm.Designer.cs +++ b/Netch/Forms/SubscriptionForm.Designer.cs @@ -1,6 +1,6 @@ namespace Netch.Forms { - partial class SubscribeForm + partial class SubscriptionForm { /// /// Required designer variable. @@ -29,24 +29,23 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SubscribeForm)); this.AddSubscriptionBox = new System.Windows.Forms.GroupBox(); + this.RemarkLabel = new System.Windows.Forms.Label(); + this.RemarkTextBox = new System.Windows.Forms.TextBox(); + this.LinkLabel = new System.Windows.Forms.Label(); + this.LinkTextBox = new System.Windows.Forms.TextBox(); + this.UserAgentLabel = new System.Windows.Forms.Label(); this.UserAgentTextBox = new System.Windows.Forms.TextBox(); this.UnselectButton = new System.Windows.Forms.Button(); this.AddButton = new System.Windows.Forms.Button(); - this.UserAgentLabel = new System.Windows.Forms.Label(); - this.LinkTextBox = new System.Windows.Forms.TextBox(); - this.LinkLabel = new System.Windows.Forms.Label(); - this.RemarkTextBox = new System.Windows.Forms.TextBox(); - this.RemarkLabel = new System.Windows.Forms.Label(); - this.SubscribeLinkListView = new System.Windows.Forms.ListView(); + this.SubscriptionLinkListView = new System.Windows.Forms.ListView(); this.EnableColumnHeader = new System.Windows.Forms.ColumnHeader(); this.RemarkColumnHeader = new System.Windows.Forms.ColumnHeader(); this.LinkColumnHeader = new System.Windows.Forms.ColumnHeader(); this.UserAgentHeader = new System.Windows.Forms.ColumnHeader(); this.pContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.DeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.deleteServerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DeleteServersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CopyLinkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MainTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.AddSubscriptionBox.SuspendLayout(); @@ -56,14 +55,14 @@ // // AddSubscriptionBox // + this.AddSubscriptionBox.Controls.Add(this.RemarkLabel); + this.AddSubscriptionBox.Controls.Add(this.RemarkTextBox); + this.AddSubscriptionBox.Controls.Add(this.LinkLabel); + this.AddSubscriptionBox.Controls.Add(this.LinkTextBox); + this.AddSubscriptionBox.Controls.Add(this.UserAgentLabel); this.AddSubscriptionBox.Controls.Add(this.UserAgentTextBox); this.AddSubscriptionBox.Controls.Add(this.UnselectButton); this.AddSubscriptionBox.Controls.Add(this.AddButton); - this.AddSubscriptionBox.Controls.Add(this.UserAgentLabel); - this.AddSubscriptionBox.Controls.Add(this.LinkTextBox); - this.AddSubscriptionBox.Controls.Add(this.LinkLabel); - this.AddSubscriptionBox.Controls.Add(this.RemarkTextBox); - this.AddSubscriptionBox.Controls.Add(this.RemarkLabel); this.AddSubscriptionBox.Dock = System.Windows.Forms.DockStyle.Fill; this.AddSubscriptionBox.Location = new System.Drawing.Point(8, 248); this.AddSubscriptionBox.Name = "AddSubscriptionBox"; @@ -71,6 +70,47 @@ this.AddSubscriptionBox.TabIndex = 1; this.AddSubscriptionBox.TabStop = false; // + // RemarkLabel + // + this.RemarkLabel.AutoSize = true; + this.RemarkLabel.Location = new System.Drawing.Point(11, 19); + this.RemarkLabel.Name = "RemarkLabel"; + this.RemarkLabel.Size = new System.Drawing.Size(53, 17); + this.RemarkLabel.TabIndex = 1; + this.RemarkLabel.Text = "Remark"; + // + // RemarkTextBox + // + this.RemarkTextBox.Location = new System.Drawing.Point(109, 16); + this.RemarkTextBox.Name = "RemarkTextBox"; + this.RemarkTextBox.Size = new System.Drawing.Size(545, 23); + this.RemarkTextBox.TabIndex = 2; + // + // LinkLabel + // + this.LinkLabel.AutoSize = true; + this.LinkLabel.Location = new System.Drawing.Point(11, 48); + this.LinkLabel.Name = "LinkLabel"; + this.LinkLabel.Size = new System.Drawing.Size(31, 17); + this.LinkLabel.TabIndex = 3; + this.LinkLabel.Text = "Link"; + // + // LinkTextBox + // + this.LinkTextBox.Location = new System.Drawing.Point(109, 45); + this.LinkTextBox.Name = "LinkTextBox"; + this.LinkTextBox.Size = new System.Drawing.Size(545, 23); + this.LinkTextBox.TabIndex = 4; + // + // UserAgentLabel + // + this.UserAgentLabel.AutoSize = true; + this.UserAgentLabel.Location = new System.Drawing.Point(11, 77); + this.UserAgentLabel.Name = "UserAgentLabel"; + this.UserAgentLabel.Size = new System.Drawing.Size(74, 17); + this.UserAgentLabel.TabIndex = 5; + this.UserAgentLabel.Text = "User-Agent"; + // // UserAgentTextBox // this.UserAgentTextBox.Location = new System.Drawing.Point(109, 74); @@ -98,68 +138,28 @@ this.AddButton.UseVisualStyleBackColor = true; this.AddButton.Click += new System.EventHandler(this.AddButton_Click); // - // UserAgentLabel + // SubscriptionLinkListView // - this.UserAgentLabel.AutoSize = true; - this.UserAgentLabel.Location = new System.Drawing.Point(11, 77); - this.UserAgentLabel.Name = "UserAgentLabel"; - this.UserAgentLabel.Size = new System.Drawing.Size(74, 17); - this.UserAgentLabel.TabIndex = 5; - this.UserAgentLabel.Text = "User-Agent"; - // - // LinkTextBox - // - this.LinkTextBox.Location = new System.Drawing.Point(109, 45); - this.LinkTextBox.Name = "LinkTextBox"; - this.LinkTextBox.Size = new System.Drawing.Size(545, 23); - this.LinkTextBox.TabIndex = 4; - // - // LinkLabel - // - this.LinkLabel.AutoSize = true; - this.LinkLabel.Location = new System.Drawing.Point(11, 48); - this.LinkLabel.Name = "LinkLabel"; - this.LinkLabel.Size = new System.Drawing.Size(31, 17); - this.LinkLabel.TabIndex = 3; - this.LinkLabel.Text = "Link"; - // - // RemarkTextBox - // - this.RemarkTextBox.Location = new System.Drawing.Point(109, 16); - this.RemarkTextBox.Name = "RemarkTextBox"; - this.RemarkTextBox.Size = new System.Drawing.Size(545, 23); - this.RemarkTextBox.TabIndex = 2; - // - // RemarkLabel - // - this.RemarkLabel.AutoSize = true; - this.RemarkLabel.Location = new System.Drawing.Point(11, 19); - this.RemarkLabel.Name = "RemarkLabel"; - this.RemarkLabel.Size = new System.Drawing.Size(53, 17); - this.RemarkLabel.TabIndex = 1; - this.RemarkLabel.Text = "Remark"; - // - // SubscribeLinkListView - // - this.SubscribeLinkListView.AllowColumnReorder = true; - this.SubscribeLinkListView.CheckBoxes = true; - this.SubscribeLinkListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] - { - this.EnableColumnHeader, this.RemarkColumnHeader, this.LinkColumnHeader, this.UserAgentHeader - }); - this.SubscribeLinkListView.Dock = System.Windows.Forms.DockStyle.Fill; - this.SubscribeLinkListView.FullRowSelect = true; - this.SubscribeLinkListView.HideSelection = false; - this.SubscribeLinkListView.Location = new System.Drawing.Point(8, 8); - this.SubscribeLinkListView.MultiSelect = false; - this.SubscribeLinkListView.Name = "SubscribeLinkListView"; - this.SubscribeLinkListView.Size = new System.Drawing.Size(668, 234); - this.SubscribeLinkListView.TabIndex = 0; - this.SubscribeLinkListView.UseCompatibleStateImageBehavior = false; - this.SubscribeLinkListView.View = System.Windows.Forms.View.Details; - this.SubscribeLinkListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.SubscribeLinkListView_ItemChecked); - this.SubscribeLinkListView.SelectedIndexChanged += new System.EventHandler(this.SubscribeLinkListView_SelectedIndexChanged); - this.SubscribeLinkListView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SubscribeLinkListView_MouseUp); + this.SubscriptionLinkListView.AllowColumnReorder = true; + this.SubscriptionLinkListView.CheckBoxes = true; + this.SubscriptionLinkListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.EnableColumnHeader, + this.RemarkColumnHeader, + this.LinkColumnHeader, + this.UserAgentHeader}); + this.SubscriptionLinkListView.Dock = System.Windows.Forms.DockStyle.Fill; + this.SubscriptionLinkListView.FullRowSelect = true; + this.SubscriptionLinkListView.HideSelection = false; + this.SubscriptionLinkListView.Location = new System.Drawing.Point(8, 8); + this.SubscriptionLinkListView.MultiSelect = false; + this.SubscriptionLinkListView.Name = "SubscriptionLinkListView"; + this.SubscriptionLinkListView.Size = new System.Drawing.Size(668, 234); + this.SubscriptionLinkListView.TabIndex = 0; + this.SubscriptionLinkListView.UseCompatibleStateImageBehavior = false; + this.SubscriptionLinkListView.View = System.Windows.Forms.View.Details; + this.SubscriptionLinkListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.SubscriptionLinkListView_ItemChecked); + this.SubscriptionLinkListView.SelectedIndexChanged += new System.EventHandler(this.SubscriptionLinkListView_SelectedIndexChanged); + this.SubscriptionLinkListView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SubscriptionLinkListView_MouseUp); // // EnableColumnHeader // @@ -182,39 +182,39 @@ // // pContextMenuStrip // - this.pContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] - { - this.DeleteToolStripMenuItem, this.deleteServerToolStripMenuItem, this.CopyLinkToolStripMenuItem - }); + this.pContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.DeleteToolStripMenuItem, + this.DeleteServersToolStripMenuItem, + this.CopyLinkToolStripMenuItem}); this.pContextMenuStrip.Name = "pContextMenuStrip"; - this.pContextMenuStrip.Size = new System.Drawing.Size(151, 70); + this.pContextMenuStrip.Size = new System.Drawing.Size(161, 70); // // DeleteToolStripMenuItem // this.DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem"; - this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(150, 22); + this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(160, 22); this.DeleteToolStripMenuItem.Text = "Delete"; this.DeleteToolStripMenuItem.Click += new System.EventHandler(this.DeleteToolStripMenuItem_Click); // - // deleteServerToolStripMenuItem + // DeleteServersToolStripMenuItem // - this.deleteServerToolStripMenuItem.Name = "deleteServerToolStripMenuItem"; - this.deleteServerToolStripMenuItem.Size = new System.Drawing.Size(150, 22); - this.deleteServerToolStripMenuItem.Text = "DeleteServer"; - this.deleteServerToolStripMenuItem.Click += new System.EventHandler(this.deleteServerToolStripMenuItem_Click); + this.DeleteServersToolStripMenuItem.Name = "DeleteServersToolStripMenuItem"; + this.DeleteServersToolStripMenuItem.Size = new System.Drawing.Size(160, 22); + this.DeleteServersToolStripMenuItem.Text = "Delete Servers"; + this.DeleteServersToolStripMenuItem.Click += new System.EventHandler(this.DeleteServersToolStripMenuItem_Click); // // CopyLinkToolStripMenuItem // this.CopyLinkToolStripMenuItem.Name = "CopyLinkToolStripMenuItem"; - this.CopyLinkToolStripMenuItem.Size = new System.Drawing.Size(150, 22); - this.CopyLinkToolStripMenuItem.Text = "CopyLink"; + this.CopyLinkToolStripMenuItem.Size = new System.Drawing.Size(160, 22); + this.CopyLinkToolStripMenuItem.Text = "Copy link"; this.CopyLinkToolStripMenuItem.Click += new System.EventHandler(this.CopyLinkToolStripMenuItem_Click); // // MainTableLayoutPanel // this.MainTableLayoutPanel.ColumnCount = 1; this.MainTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.MainTableLayoutPanel.Controls.Add(this.SubscribeLinkListView, 0, 0); + this.MainTableLayoutPanel.Controls.Add(this.SubscriptionLinkListView, 0, 0); this.MainTableLayoutPanel.Controls.Add(this.AddSubscriptionBox, 0, 1); this.MainTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.MainTableLayoutPanel.Location = new System.Drawing.Point(0, 0); @@ -227,25 +227,26 @@ this.MainTableLayoutPanel.Size = new System.Drawing.Size(684, 391); this.MainTableLayoutPanel.TabIndex = 11; // - // SubscribeForm + // SubscriptionForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(684, 391); this.Controls.Add(this.MainTableLayoutPanel); - this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (134))); + this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.MaximizeBox = false; - this.Name = "SubscribeForm"; + this.Name = "SubscriptionForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Subscribe"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SubscribeForm_FormClosing); + this.Text = "Subscription"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SubscriptionForm_FormClosing); this.AddSubscriptionBox.ResumeLayout(false); this.AddSubscriptionBox.PerformLayout(); this.pContextMenuStrip.ResumeLayout(false); this.MainTableLayoutPanel.ResumeLayout(false); this.ResumeLayout(false); + } private System.Windows.Forms.ColumnHeader EnableColumnHeader; @@ -257,7 +258,7 @@ private System.Windows.Forms.Label LinkLabel; private System.Windows.Forms.TextBox RemarkTextBox; private System.Windows.Forms.Button AddButton; - private System.Windows.Forms.ListView SubscribeLinkListView; + private System.Windows.Forms.ListView SubscriptionLinkListView; private System.Windows.Forms.ColumnHeader RemarkColumnHeader; private System.Windows.Forms.ColumnHeader LinkColumnHeader; private System.Windows.Forms.ContextMenuStrip pContextMenuStrip; @@ -269,6 +270,6 @@ #endregion - private System.Windows.Forms.ToolStripMenuItem deleteServerToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem DeleteServersToolStripMenuItem; } } \ No newline at end of file diff --git a/Netch/Forms/SubscribeForm.cs b/Netch/Forms/SubscriptionForm.cs similarity index 70% rename from Netch/Forms/SubscribeForm.cs rename to Netch/Forms/SubscriptionForm.cs index 2109dedb..fcfcc7d3 100644 --- a/Netch/Forms/SubscribeForm.cs +++ b/Netch/Forms/SubscriptionForm.cs @@ -1,15 +1,15 @@ -using Netch.Models; -using Netch.Properties; -using Netch.Utils; -using System; +using System; using System.Linq; using System.Windows.Forms; +using Netch.Models; +using Netch.Properties; +using Netch.Utils; namespace Netch.Forms { - public partial class SubscribeForm : Form + public partial class SubscriptionForm : Form { - public SubscribeForm() + public SubscriptionForm() { InitializeComponent(); Icon = Resources.icon; @@ -17,33 +17,33 @@ namespace Netch.Forms i18N.TranslateForm(this); i18N.TranslateForm(pContextMenuStrip); - InitSubscribeLink(); + LoadSubscriptionLinks(); } private int SelectedIndex { get { - if (SubscribeLinkListView.MultiSelect) + if (SubscriptionLinkListView.MultiSelect) throw new Exception(); - return SubscribeLinkListView.SelectedIndices.Count == 0 ? -1 : SubscribeLinkListView.SelectedIndices[0]; + return SubscriptionLinkListView.SelectedIndices.Count == 0 ? -1 : SubscriptionLinkListView.SelectedIndices[0]; } } #region EventHandler - private void SubscribeLinkListView_MouseUp(object sender, MouseEventArgs e) + private void SubscriptionLinkListView_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) if (SelectedIndex != -1) - pContextMenuStrip.Show(SubscribeLinkListView, e.Location); + pContextMenuStrip.Show(SubscriptionLinkListView, e.Location); } /// /// 选中/取消选中 /// - private void SubscribeLinkListView_SelectedIndexChanged(object sender, EventArgs e) + private void SubscriptionLinkListView_SelectedIndexChanged(object sender, EventArgs e) { SetEditingGroup(SelectedIndex); } @@ -51,13 +51,13 @@ namespace Netch.Forms /// /// 订阅启/禁用 /// - private void SubscribeLinkListView_ItemChecked(object sender, ItemCheckedEventArgs e) + private void SubscriptionLinkListView_ItemChecked(object sender, ItemCheckedEventArgs e) { var index = e.Item.Index; - Global.Settings.SubscribeLink[index].Enable = SubscribeLinkListView.Items[index].Checked; + Global.Settings.Subscription[index].Enable = SubscriptionLinkListView.Items[index].Checked; } - private async void SubscribeForm_FormClosing(object sender, FormClosingEventArgs e) + private async void SubscriptionForm_FormClosing(object sender, FormClosingEventArgs e) { await Configuration.SaveAsync(); } @@ -94,13 +94,13 @@ namespace Netch.Forms if (SelectedIndex == -1) { - if (Global.Settings.SubscribeLink.Any(link => link.Remark.Equals(RemarkTextBox.Text))) + if (Global.Settings.Subscription.Any(link => link.Remark.Equals(RemarkTextBox.Text))) { - MessageBoxX.Show("Remark Name Duplicate!"); + MessageBoxX.Show(i18N.Translate("Subscription with the specified remark already exists")); return; } - Global.Settings.SubscribeLink.Add(new SubscribeLink + Global.Settings.Subscription.Add(new Subscription { Enable = true, Remark = RemarkTextBox.Text, @@ -110,7 +110,7 @@ namespace Netch.Forms } else { - var subscribeLink = Global.Settings.SubscribeLink[SelectedIndex]; + var subscribeLink = Global.Settings.Subscription[SelectedIndex]; RenameServers(subscribeLink.Remark, RemarkTextBox.Text); subscribeLink.Link = LinkTextBox.Text; @@ -118,7 +118,7 @@ namespace Netch.Forms subscribeLink.UserAgent = UserAgentTextBox.Text; } - InitSubscribeLink(); + LoadSubscriptionLinks(); } #endregion @@ -131,24 +131,24 @@ namespace Netch.Forms confirm: true) != DialogResult.OK) return; - var subscribeLink = Global.Settings.SubscribeLink[SelectedIndex]; + var subscribeLink = Global.Settings.Subscription[SelectedIndex]; DeleteServers(subscribeLink.Remark); - Global.Settings.SubscribeLink.Remove(subscribeLink); + Global.Settings.Subscription.Remove(subscribeLink); - InitSubscribeLink(); + LoadSubscriptionLinks(); } - private void deleteServerToolStripMenuItem_Click(object sender, EventArgs e) + private void DeleteServersToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBoxX.Show(i18N.Translate("Confirm deletion?"), confirm: true) != DialogResult.OK) return; - DeleteServers(Global.Settings.SubscribeLink[SelectedIndex].Remark); + DeleteServers(Global.Settings.Subscription[SelectedIndex].Remark); } private void CopyLinkToolStripMenuItem_Click(object sender, EventArgs e) { - Clipboard.SetText(Global.Settings.SubscribeLink[SelectedIndex].Link); + Clipboard.SetText(Global.Settings.Subscription[SelectedIndex].Link); } #endregion @@ -166,12 +166,12 @@ namespace Netch.Forms server.Group = newGroup; } - private void InitSubscribeLink() + private void LoadSubscriptionLinks() { - SubscribeLinkListView.Items.Clear(); + SubscriptionLinkListView.Items.Clear(); - foreach (var item in Global.Settings.SubscribeLink) - SubscribeLinkListView.Items.Add(new ListViewItem(new[] + foreach (var item in Global.Settings.Subscription) + SubscriptionLinkListView.Items.Add(new ListViewItem(new[] { "", item.Remark, @@ -202,7 +202,7 @@ namespace Netch.Forms return; } - var item = Global.Settings.SubscribeLink[index]; + var item = Global.Settings.Subscription[index]; AddSubscriptionBox.Text = item.Remark; RemarkTextBox.Text = item.Remark; LinkTextBox.Text = item.Link; diff --git a/Netch/Forms/SubscriptionForm.resx b/Netch/Forms/SubscriptionForm.resx new file mode 100644 index 00000000..3002be98 --- /dev/null +++ b/Netch/Forms/SubscriptionForm.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Netch/Global.cs b/Netch/Global.cs index 08b5412d..a3b1b1b1 100644 --- a/Netch/Global.cs +++ b/Netch/Global.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text.Encodings.Web; using System.Text.Json; +using System.Text.Json.Serialization; using System.Windows.Forms; using Netch.Forms; using Netch.Models; @@ -42,7 +43,7 @@ namespace Netch public static JsonSerializerOptions NewCustomJsonSerializerOptions() => new() { WriteIndented = true, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; } diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 23557c94..3e20370f 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; using System.Text.Json.Serialization; using Netch.Utils; @@ -240,7 +243,7 @@ namespace Netch.Models /// /// 订阅链接列表 /// - public List SubscribeLink { get; set; } = new(); + public List Subscription { get; set; } = new(); /// /// TUNTAP 适配器配置 @@ -256,7 +259,21 @@ namespace Netch.Models public bool NoSupportDialog { get; set; } = false; - public Setting Clone() + #region Migration + + [Obsolete] + public JsonElement SubscribeLink + { + set + { + if (Subscription == null! || !Subscription.Any()) + Subscription = value.Deserialize>()!; + } + } + + #endregion + + public Setting ShallowCopy() { return (Setting)MemberwiseClone(); } diff --git a/Netch/Models/SubscribeLink.cs b/Netch/Models/Subscription.cs similarity index 94% rename from Netch/Models/SubscribeLink.cs rename to Netch/Models/Subscription.cs index f74c88ce..d4711123 100644 --- a/Netch/Models/SubscribeLink.cs +++ b/Netch/Models/Subscription.cs @@ -1,6 +1,6 @@ namespace Netch.Models { - public class SubscribeLink + public class Subscription { /// /// 启用状态 diff --git a/Netch/Netch.cs b/Netch/Netch.cs index 2dadba8c..20c874b0 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -113,8 +113,13 @@ namespace Netch Log.Information("OS: {OSVersion}", Environment.OSVersion); Log.Information("SHA256: {Hash}", $"{Utils.Utils.SHA256CheckSum(Global.NetchExecutable)}"); Log.Information("System Language: {Language}", CultureInfo.CurrentCulture.Name); + if (Log.IsEnabled(LogEventLevel.Debug)) - Log.Debug("Third-party Drivers:\n{Drivers}", string.Join("\n", SystemInfo.SystemDrivers(false))); + { + // TODO log level setting + Task.Run(() => Log.Debug("Third-party Drivers:\n{Drivers}", string.Join(Constants.EOF, SystemInfo.SystemDrivers(false)))).Forget(); + Task.Run(() => Log.Debug("Running Processes: \n{Processes}", string.Join(Constants.EOF, SystemInfo.Processes(false)))).Forget(); + } } private static void CheckClr() @@ -162,13 +167,13 @@ namespace Netch Log.Logger = new LoggerConfiguration() #if DEBUG .MinimumLevel.Verbose() - .WriteTo.Async(c => c.Debug(outputTemplate: Constants.OutputTemplate)) #else .MinimumLevel.Debug() #endif .WriteTo.Async(c => c.File(Path.Combine(Global.NetchDir, Constants.LogFile), outputTemplate: Constants.OutputTemplate, rollOnFileSizeLimit: false)) + .WriteTo.Console(outputTemplate: Constants.OutputTemplate) .MinimumLevel.Override(@"Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .CreateLogger(); @@ -176,7 +181,7 @@ namespace Netch private static void Application_OnException(object sender, ThreadExceptionEventArgs e) { - Log.Error(e.Exception, "未处理异常"); + Log.Error(e.Exception, "Unhandled error"); } private static void Application_OnExit(object? sender, EventArgs eventArgs) diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj index 0ca39071..677b1a7b 100644 --- a/Netch/Netch.csproj +++ b/Netch/Netch.csproj @@ -32,7 +32,7 @@ - + all @@ -45,11 +45,12 @@ - + + diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 14c9b407..8c098ced 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -18,9 +18,9 @@ "Testing NAT Type": "正在测试 NAT 类型", "Setup Route Table Rule": "配置路由规则", "Test failed": "测试失败", - "Starting update subscription": "正在更新订阅", - "Subscription updated": "订阅更新完毕", - "Register driver": "正在注册驱动", + "Updating servers": "正在更新服务器", + "Servers updated": "服务器更新完毕", + "Installing netfilter2 driver": "正在安装 netfilter2 驱动", "Server": "服务器", "Import Servers From Clipboard": "从剪贴板导入服务器", @@ -28,10 +28,10 @@ "Netch is now minimized to the notification bar, double click this icon to restore.": "Netch 已最小化至通知栏,双击此图标恢复窗口", "New version available": "发现新版本", "Already latest version": "已经是最新版本", - "New version found failed": "寻找新版本失败", + "Check for update failed": "检查更新失败", "Mode": "模式", "Help": "帮助", - "Check for updates": "检查更新", + "Check for update": "检查更新", "Download and install now?": "立即下载并安装?", "Start downloading new version": "开始下载新版本", "Download update failed": "下载更新错误", @@ -64,16 +64,16 @@ "Plugin": "插件", "Plugin Options": "插件参数", - "Subscribe": "订阅", - "Manage Subscribe Links": "管理订阅链接", - "Update Servers From Subscribe Links": "从订阅链接更新服务器", + "Subscription": "订阅", + "Manage Subscriptions": "管理订阅", + "Update Servers": "更新服务器", "No subscription link": "没有任何一条订阅链接", "Updating {0}": "正在更新 {0}", - "Update {1} server(s) from {0}": "从 {0} 更新 {1} 个服务器", - "Update servers error from {0}": "从 {0} 更新服务器失败", + "Update {1} server(s) from {0}": "从 {0} 更新了 {1} 个服务器", + "Update servers failed from {0}": "从 {0} 更新服务器失败", "Confirm deletion?": "确认删除?", - "DeleteServer": "删除订阅节点", - "CopyLink": "复制链接", + "Delete Servers": "删除订阅节点", + "Copy link": "复制链接", "Status": "状态", "Link": "链接", "Unselect": "取消选择", @@ -133,6 +133,7 @@ "Delete or not ? Will clean up the corresponding group of items in the server list": "是否删除?将会清理服务器列表中对应组的项目", "Remark can not be empty": "备注不可为空", "Link can not be empty": "链接不可为空", + "Subscription with the specified remark already exists": "带有指定备注的订阅已存在", "Link must start with http:// or https://": "链接必须以 http:// 或 https:// 开头", "Settings": "设置", diff --git a/Netch/Servers/Shadowsocks/ShadowsocksUtil.cs b/Netch/Servers/Shadowsocks/ShadowsocksUtil.cs index 3bb21506..1a464e8c 100644 --- a/Netch/Servers/Shadowsocks/ShadowsocksUtil.cs +++ b/Netch/Servers/Shadowsocks/ShadowsocksUtil.cs @@ -64,7 +64,7 @@ namespace Netch.Servers var server = (ShadowsocksServer)s; if (!SSGlobal.EncryptMethods.Contains(server.EncryptMethod)) { - Log.Warning("不支持的 SS 加密方式:{Method}", server.EncryptMethod); + Log.Warning("Unsupported SS Encrypt Method: {Method}", server.EncryptMethod); return false; } diff --git a/Netch/Servers/ShadowsocksR/ShadowsocksRUtil.cs b/Netch/Servers/ShadowsocksR/ShadowsocksRUtil.cs index 346c7b60..8318536a 100644 --- a/Netch/Servers/ShadowsocksR/ShadowsocksRUtil.cs +++ b/Netch/Servers/ShadowsocksR/ShadowsocksRUtil.cs @@ -145,19 +145,19 @@ namespace Netch.Servers var server = (ShadowsocksRServer)s; if (!SSRGlobal.EncryptMethods.Contains(server.EncryptMethod)) { - Log.Error("不支持的 SSR 加密方式:{Method}", server.EncryptMethod); + Log.Error("Unsupported ShadowsocksR Encrypt method: {Method}", server.EncryptMethod); return false; } if (!SSRGlobal.Protocols.Contains(server.Protocol)) { - Log.Error("不支持的 SSR 协议:{Protocol}", server.Protocol); + Log.Error("Unsupported ShadowsocksR Protocol: {Protocol}", server.Protocol); return false; } if (!SSRGlobal.OBFSs.Contains(server.OBFS)) { - Log.Error("不支持的 SSR 混淆:{Obfs}", server.OBFS); + Log.Error("Unsupported ShadowsocksR Obfs: {Obfs}", server.OBFS); return false; } diff --git a/Netch/Utils/Bandwidth.cs b/Netch/Utils/Bandwidth.cs index 9598340b..d61c3806 100644 --- a/Netch/Utils/Bandwidth.cs +++ b/Netch/Utils/Bandwidth.cs @@ -78,7 +78,7 @@ namespace Netch.Utils var pidHastSet = processes.Select(instance => instance.Id).ToHashSet(); - Log.Information("流量统计进程: {Processes}", string.Join(',', processes.Select(v => $"({v.Id}){v.ProcessName}"))); + Log.Information("Net traffic processes: {Processes}", string.Join(',', processes.Select(v => $"({v.Id}){v.ProcessName}"))); received = 0; diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index 2d266422..85bafbe8 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -50,12 +50,12 @@ namespace Netch.Utils if (await LoadCoreAsync(FileFullName)) return; - Log.Information("尝试加载备份配置文件 {FileName}", BackupFileFullName); + Log.Information("Load backup configuration \"{FileName}\"", BackupFileFullName); await LoadCoreAsync(BackupFileFullName); } catch (Exception e) { - Log.Error(e, "加载配置异常"); + Log.Error(e, "Load configuration failed"); Environment.Exit(-1); } } @@ -77,7 +77,7 @@ namespace Netch.Utils } catch (Exception e) { - Log.Error(e, @"从 {FileName} 加载配置异常", filename); + Log.Error(e, "Load configuration file \"{FileName}\" error ", filename); return false; } } @@ -122,7 +122,7 @@ namespace Netch.Utils } catch (Exception e) { - Log.Error(e, "保存配置异常"); + Log.Error(e, "Save Configuration error"); } } diff --git a/Netch/Utils/Firewall.cs b/Netch/Utils/Firewall.cs index 53a3012a..c3b3e7fe 100644 --- a/Netch/Utils/Firewall.cs +++ b/Netch/Utils/Firewall.cs @@ -1,9 +1,9 @@ using System; using System.IO; using System.Linq; +using Serilog; using WindowsFirewallHelper; using WindowsFirewallHelper.FirewallRules; -using Serilog; namespace Netch.Utils { @@ -18,7 +18,7 @@ namespace Netch.Utils { if (!FirewallWAS.IsLocallySupported) { - Log.Warning("不支持防火墙"); + Log.Warning("Windows Firewall Locally Unsupported"); return; } @@ -38,7 +38,7 @@ namespace Netch.Utils } catch (Exception e) { - Log.Warning(e, "添加防火墙规则错误"); + Log.Warning(e, "Create Netch Firewall rules error"); } } @@ -58,7 +58,7 @@ namespace Netch.Utils } catch (Exception e) { - Log.Warning(e, "清除防火墙规则错误"); + Log.Warning(e, "Remove Netch Firewall rules error"); } } diff --git a/Netch/Utils/ModeHelper.cs b/Netch/Utils/ModeHelper.cs index a38ad612..7328cefc 100644 --- a/Netch/Utils/ModeHelper.cs +++ b/Netch/Utils/ModeHelper.cs @@ -139,8 +139,8 @@ namespace Netch.Utils case ModeType.Pcap2Socks: return (new PcapController(), 0); default: - Log.Error("未知模式类型"); - throw new MessageException("未知模式类型"); + Log.Error("Unknown Mode Type \"{Type}\"", (int)type); + throw new MessageException("Unknown Mode Type"); } } } diff --git a/Netch/Utils/PortHelper.cs b/Netch/Utils/PortHelper.cs index f47704d3..f0bf5757 100644 --- a/Netch/Utils/PortHelper.cs +++ b/Netch/Utils/PortHelper.cs @@ -28,7 +28,7 @@ namespace Netch.Utils } catch (Exception e) { - Log.Error(e, "获取保留端口错误"); + Log.Error(e, "Get reserved ports failed"); } } diff --git a/Netch/Utils/ServerConverterWithTypeDiscriminator.cs b/Netch/Utils/ServerConverterWithTypeDiscriminator.cs index 08e0bf76..752739dd 100644 --- a/Netch/Utils/ServerConverterWithTypeDiscriminator.cs +++ b/Netch/Utils/ServerConverterWithTypeDiscriminator.cs @@ -1,7 +1,7 @@ -using Netch.Models; -using System; +using System; using System.Text.Json; using System.Text.Json.Serialization; +using Netch.Models; namespace Netch.Utils { @@ -13,7 +13,7 @@ namespace Netch.Utils { var jsonElement = JsonSerializer.Deserialize(ref reader); var type = ServerHelper.GetTypeByTypeName(jsonElement.GetProperty("Type").GetString()!); - return (Server)JsonSerializer.Deserialize(jsonElement.GetRawText(), type)!; + return (Server)jsonElement.Deserialize(type)!; } public override void Write(Utf8JsonWriter writer, Server value, JsonSerializerOptions options) diff --git a/Netch/Utils/ShareLink.cs b/Netch/Utils/ShareLink.cs index bb43aaaf..69746f3f 100644 --- a/Netch/Utils/ShareLink.cs +++ b/Netch/Utils/ShareLink.cs @@ -53,13 +53,13 @@ namespace Netch.Utils } catch (Exception e) { - Log.Error(e, "从分享链接导入服务器异常"); + Log.Error(e, "Parse servers from share link error"); } } } catch (Exception e) { - Log.Error(e, "从分享链接导入服务器异常"); + Log.Error(e, "Parse servers from share link error"); } return list; @@ -84,7 +84,7 @@ namespace Netch.Utils if (util != null) list.AddRange(util.ParseUri(text)); else - Log.Warning("无法处理 {Scheme} 协议订阅链接", scheme); + Log.Warning("\"{Scheme}\" scheme share link not supported", scheme); } foreach (var node in list.Where(node => !node.Remark.IsNullOrWhiteSpace())) diff --git a/Netch/Utils/Subscription.cs b/Netch/Utils/SubscriptionUtil.cs similarity index 81% rename from Netch/Utils/Subscription.cs rename to Netch/Utils/SubscriptionUtil.cs index 253e1e83..44d6deb3 100644 --- a/Netch/Utils/Subscription.cs +++ b/Netch/Utils/SubscriptionUtil.cs @@ -8,16 +8,16 @@ using Serilog; namespace Netch.Utils { - public static class Subscription + public static class SubscriptionUtil { private static readonly object ServerLock = new(); public static async Task UpdateServersAsync(string? proxyServer = default) { - await Task.WhenAll(Global.Settings.SubscribeLink.Select(item => UpdateServerCoreAsync(item, proxyServer))); + await Task.WhenAll(Global.Settings.Subscription.Select(item => UpdateServerCoreAsync(item, proxyServer))); } - private static async Task UpdateServerCoreAsync(SubscribeLink item, string? proxyServer) + private static async Task UpdateServerCoreAsync(Subscription item, string? proxyServer) { try { @@ -53,8 +53,8 @@ namespace Netch.Utils } catch (Exception e) { - Global.MainForm.NotifyTip($"{i18N.TranslateFormat("Update servers error from {0}", item.Remark)}\n{e.Message}", info: false); - Log.Warning(e, "更新服务器失败"); + Global.MainForm.NotifyTip($"{i18N.TranslateFormat("Update servers failed from {0}", item.Remark)}\n{e.Message}", info: false); + Log.Warning(e, "Update servers failed"); } } } diff --git a/Netch/Utils/SystemInfo.cs b/Netch/Utils/SystemInfo.cs index ed23ffaa..7fc8b899 100644 --- a/Netch/Utils/SystemInfo.cs +++ b/Netch/Utils/SystemInfo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Management; @@ -31,25 +32,28 @@ namespace Netch.Utils public static IEnumerable Processes(bool mask) { - var hashset = new HashSet(); + var sortedSet = new SortedSet(); var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows); + var windowsAppsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps"); + var userProfileFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); foreach (var process in Process.GetProcesses()) { try { - if (process.Id is 0 or 4) + var path = process.MainModule?.FileName; + if (path == null) continue; - // ! NT Kernel & System - if (process.MainModule!.FileName!.StartsWith(windowsFolder, StringComparison.OrdinalIgnoreCase)) + if (path.StartsWith(windowsFolder, StringComparison.OrdinalIgnoreCase)) continue; - var path = process.MainModule.FileName; + if (path.StartsWith(windowsAppsFolder, StringComparison.OrdinalIgnoreCase)) + continue; if (mask) - path = path.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "%USERPROFILE%"); - - hashset.Add(path); + sortedSet.Add(path.Replace(userProfileFolder, "%USERPROFILE%")); + else + sortedSet.Add(path); } catch (Exception) { @@ -57,7 +61,7 @@ namespace Netch.Utils } } - return hashset; + return sortedSet; } } } \ No newline at end of file diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index 33c35ed9..1546f12e 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -33,7 +33,7 @@ namespace Netch.Utils } catch (Exception e) { - Log.Warning(e, "打开 {Uri} 失败", path); + Log.Warning(e, "Open \"{Uri}\" failed", path); } } diff --git a/Netch/Utils/i18N.cs b/Netch/Utils/i18N.cs index 6435f72f..72c57793 100644 --- a/Netch/Utils/i18N.cs +++ b/Netch/Utils/i18N.cs @@ -1,5 +1,4 @@ -using Netch.Properties; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -7,6 +6,7 @@ using System.Linq; using System.Text; using System.Text.Json; using System.Windows.Forms; +using Netch.Properties; using Serilog; namespace Netch.Utils @@ -42,7 +42,7 @@ namespace Netch.Utils { var oldLangCode = LangCode; LangCode = languages.FirstOrDefault(s => GetLanguage(s).Equals(GetLanguage(LangCode))) ?? "en-US"; - Log.Information("找不到语言 {OldLangCode}, 使用 {LangCode}",oldLangCode,LangCode); + Log.Information("Not found language {OldLangCode}, use {LangCode} instead", oldLangCode, LangCode); } switch (LangCode) @@ -62,7 +62,7 @@ namespace Netch.Utils if (!dictionary.Any()) { - Log.Error("{LangCode} 语言文件错误", LangCode); + Log.Error("Invalid language file \"{LangCode}\"", LangCode); return; }