From 5c10b5c92dd512d22b806af1447cd84a6f3339a4 Mon Sep 17 00:00:00 2001 From: Amazing_DM Date: Sat, 25 Apr 2020 17:36:16 +0800 Subject: [PATCH] :art:fix some bug :loud_sound: add some debug logs --- Netch/Controllers/DNSController.cs | 2 + Netch/Controllers/TUNTAPController.cs | 11 ++ Netch/Forms/MainForm.Designer.cs | 184 +++++++++++++------------- Netch/Forms/MainForm.cs | 132 ++++++++++-------- Netch/Netch.cs | 14 +- Netch/Resources/zh-CN | 2 + Netch/Utils/Configuration.cs | 3 + 7 files changed, 192 insertions(+), 156 deletions(-) diff --git a/Netch/Controllers/DNSController.cs b/Netch/Controllers/DNSController.cs index ae8fb993..add9d5c2 100644 --- a/Netch/Controllers/DNSController.cs +++ b/Netch/Controllers/DNSController.cs @@ -1,4 +1,5 @@ using Netch.Forms; +using Netch.Utils; using System; using System.Diagnostics; using System.IO; @@ -37,6 +38,7 @@ namespace Netch.Controllers Instance.Start(); Instance.BeginOutputReadLine(); Instance.BeginErrorReadLine(); + Logging.Info("dns-unbound 启动完毕"); return true; } catch (Exception) diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs index b60d9625..4ab7695c 100644 --- a/Netch/Controllers/TUNTAPController.cs +++ b/Netch/Controllers/TUNTAPController.cs @@ -68,6 +68,7 @@ namespace Netch.Controllers public bool SetupBypass() { MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("SetupBypass")}"); + Logging.Info("设置绕行规则->设置让服务器 IP 走直连"); // 让服务器 IP 走直连 foreach (var address in ServerAddresses) { @@ -80,6 +81,7 @@ namespace Netch.Controllers // 处理模式的绕过中国 if (SavedMode.BypassChina) { + Logging.Info("设置绕行规则->处理模式的绕过中国"); using (var sr = new StringReader(Encoding.UTF8.GetString(Properties.Resources.CNIP))) { string text; @@ -93,6 +95,7 @@ namespace Netch.Controllers } } + Logging.Info("设置绕行规则->处理全局绕过 IP"); // 处理全局绕过 IP foreach (var ip in Global.Settings.BypassIPs) { @@ -105,6 +108,8 @@ namespace Netch.Controllers } } + Logging.Info("设置绕行规则->处理绕过局域网 IP"); + // 处理绕过局域网 IP foreach (var ip in BypassLanIPs) { var info = ip.Split('/'); @@ -118,6 +123,7 @@ namespace Netch.Controllers if (SavedMode.Type == 2) // 处理仅规则内走直连 { + Logging.Info("设置绕行规则->处理仅规则内走直连"); // 将 TUN/TAP 网卡权重放到最高 var instance = new Process { @@ -132,6 +138,7 @@ namespace Netch.Controllers }; instance.Start(); + Logging.Info("设置绕行规则->创建默认路由"); // 创建默认路由 if (!NativeMethods.CreateRoute("0.0.0.0", 0, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index, 10)) { @@ -145,6 +152,8 @@ namespace Netch.Controllers return false; } + Logging.Info("设置绕行规则->创建规则路由"); + // 创建规则路由 foreach (var ip in SavedMode.Rule) { var info = ip.Split('/'); @@ -160,6 +169,7 @@ namespace Netch.Controllers } else if (SavedMode.Type == 1) // 处理仅规则内走代理 { + Logging.Info("设置绕行规则->处理仅规则内走代理"); foreach (var ip in SavedMode.Rule) { var info = ip.Split('/'); @@ -196,6 +206,7 @@ namespace Netch.Controllers //处理DNS代理 if (Global.Settings.TUNTAP.ProxyDNS) { + Logging.Info("设置绕行规则->处理自定义DNS代理"); if (Global.Settings.TUNTAP.UseCustomDNS) { string dns = ""; diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index b2d7864e..4f165c5f 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -52,6 +52,7 @@ namespace Netch.Forms this.CleanDNSCacheToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.UpdateACLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.updateACLWithProxyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.reinstallTapDriverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AboutToolStripButton = new System.Windows.Forms.ToolStripButton(); this.VersionLabel = new System.Windows.Forms.ToolStripLabel(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -64,7 +65,13 @@ namespace Netch.Forms this.ModeComboBox = new System.Windows.Forms.SearchComboBox(); this.ServerComboBox = new System.Windows.Forms.ComboBox(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.EditPictureBox = new System.Windows.Forms.PictureBox(); + this.CopyLinkPictureBox = new System.Windows.Forms.PictureBox(); + this.DeletePictureBox = new System.Windows.Forms.PictureBox(); + this.SpeedPictureBox = new System.Windows.Forms.PictureBox(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.EditModePictureBox = new System.Windows.Forms.PictureBox(); + this.DeleteModePictureBox = new System.Windows.Forms.PictureBox(); this.StatusStrip = new System.Windows.Forms.StatusStrip(); this.StatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.UsedBandwidthLabel = new System.Windows.Forms.ToolStripStatusLabel(); @@ -79,27 +86,20 @@ namespace Netch.Forms this.SettingsButton = new System.Windows.Forms.Button(); this.ProfileGroupBox = new System.Windows.Forms.GroupBox(); this.ProfileTable = new System.Windows.Forms.TableLayoutPanel(); - this.reinstallTapDriverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.EditPictureBox = new System.Windows.Forms.PictureBox(); - this.CopyLinkPictureBox = new System.Windows.Forms.PictureBox(); - this.DeletePictureBox = new System.Windows.Forms.PictureBox(); - this.SpeedPictureBox = new System.Windows.Forms.PictureBox(); - this.EditModePictureBox = new System.Windows.Forms.PictureBox(); - this.DeleteModePictureBox = new System.Windows.Forms.PictureBox(); this.MenuStrip.SuspendLayout(); this.ConfigurationGroupBox.SuspendLayout(); this.configLayoutPanel.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout(); - this.tableLayoutPanel3.SuspendLayout(); - this.StatusStrip.SuspendLayout(); - this.NotifyMenu.SuspendLayout(); - this.ProfileGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.EditPictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.CopyLinkPictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.DeletePictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SpeedPictureBox)).BeginInit(); + this.tableLayoutPanel3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.EditModePictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.DeleteModePictureBox)).BeginInit(); + this.StatusStrip.SuspendLayout(); + this.NotifyMenu.SuspendLayout(); + this.ProfileGroupBox.SuspendLayout(); this.SuspendLayout(); // // MenuStrip @@ -273,6 +273,13 @@ namespace Netch.Forms this.updateACLWithProxyToolStripMenuItem.Text = "Update ACL with proxy"; this.updateACLWithProxyToolStripMenuItem.Click += new System.EventHandler(this.updateACLWithProxyToolStripMenuItem_Click); // + // reinstallTapDriverToolStripMenuItem + // + this.reinstallTapDriverToolStripMenuItem.Name = "reinstallTapDriverToolStripMenuItem"; + this.reinstallTapDriverToolStripMenuItem.Size = new System.Drawing.Size(209, 22); + this.reinstallTapDriverToolStripMenuItem.Text = "Reinstall Tap driver"; + this.reinstallTapDriverToolStripMenuItem.Click += new System.EventHandler(this.reinstallTapDriverToolStripMenuItem_Click); + // // AboutToolStripButton // this.AboutToolStripButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; @@ -419,6 +426,50 @@ namespace Netch.Forms this.tableLayoutPanel2.Size = new System.Drawing.Size(94, 24); this.tableLayoutPanel2.TabIndex = 12; // + // EditPictureBox + // + this.EditPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.EditPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("EditPictureBox.Image"))); + this.EditPictureBox.Location = new System.Drawing.Point(3, 3); + this.EditPictureBox.Name = "EditPictureBox"; + this.EditPictureBox.Size = new System.Drawing.Size(16, 16); + this.EditPictureBox.TabIndex = 7; + this.EditPictureBox.TabStop = false; + this.EditPictureBox.Click += new System.EventHandler(this.EditPictureBox_Click); + // + // CopyLinkPictureBox + // + this.CopyLinkPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.CopyLinkPictureBox.Image = global::Netch.Properties.Resources.CopyLink; + this.CopyLinkPictureBox.Location = new System.Drawing.Point(72, 3); + this.CopyLinkPictureBox.Name = "CopyLinkPictureBox"; + this.CopyLinkPictureBox.Size = new System.Drawing.Size(18, 18); + this.CopyLinkPictureBox.TabIndex = 14; + this.CopyLinkPictureBox.TabStop = false; + this.CopyLinkPictureBox.Click += new System.EventHandler(this.CopyLinkPictureBox_Click); + // + // DeletePictureBox + // + this.DeletePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.DeletePictureBox.Image = ((System.Drawing.Image)(resources.GetObject("DeletePictureBox.Image"))); + this.DeletePictureBox.Location = new System.Drawing.Point(26, 3); + this.DeletePictureBox.Name = "DeletePictureBox"; + this.DeletePictureBox.Size = new System.Drawing.Size(16, 16); + this.DeletePictureBox.TabIndex = 8; + this.DeletePictureBox.TabStop = false; + this.DeletePictureBox.Click += new System.EventHandler(this.DeletePictureBox_Click); + // + // SpeedPictureBox + // + this.SpeedPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.SpeedPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("SpeedPictureBox.Image"))); + this.SpeedPictureBox.Location = new System.Drawing.Point(49, 3); + this.SpeedPictureBox.Name = "SpeedPictureBox"; + this.SpeedPictureBox.Size = new System.Drawing.Size(16, 16); + this.SpeedPictureBox.TabIndex = 9; + this.SpeedPictureBox.TabStop = false; + this.SpeedPictureBox.Click += new System.EventHandler(this.SpeedPictureBox_Click); + // // tableLayoutPanel3 // this.tableLayoutPanel3.ColumnCount = 4; @@ -435,6 +486,30 @@ namespace Netch.Forms this.tableLayoutPanel3.Size = new System.Drawing.Size(94, 24); this.tableLayoutPanel3.TabIndex = 13; // + // EditModePictureBox + // + this.EditModePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.EditModePictureBox.ErrorImage = global::Netch.Properties.Resources.edit; + this.EditModePictureBox.Image = global::Netch.Properties.Resources.edit; + this.EditModePictureBox.InitialImage = global::Netch.Properties.Resources.edit; + this.EditModePictureBox.Location = new System.Drawing.Point(3, 3); + this.EditModePictureBox.Name = "EditModePictureBox"; + this.EditModePictureBox.Size = new System.Drawing.Size(16, 16); + this.EditModePictureBox.TabIndex = 12; + this.EditModePictureBox.TabStop = false; + this.EditModePictureBox.Click += new System.EventHandler(this.EditModePictureBox_Click); + // + // DeleteModePictureBox + // + this.DeleteModePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.DeleteModePictureBox.Image = global::Netch.Properties.Resources.delete; + this.DeleteModePictureBox.Location = new System.Drawing.Point(26, 3); + this.DeleteModePictureBox.Name = "DeleteModePictureBox"; + this.DeleteModePictureBox.Size = new System.Drawing.Size(16, 16); + this.DeleteModePictureBox.TabIndex = 13; + this.DeleteModePictureBox.TabStop = false; + this.DeleteModePictureBox.Click += new System.EventHandler(this.DeleteModePictureBox_Click); + // // StatusStrip // this.StatusStrip.ImageScalingSize = new System.Drawing.Size(20, 20); @@ -563,81 +638,6 @@ namespace Netch.Forms this.ProfileTable.Size = new System.Drawing.Size(599, 43); this.ProfileTable.TabIndex = 0; // - // reinstallTapDriverToolStripMenuItem - // - this.reinstallTapDriverToolStripMenuItem.Name = "reinstallTapDriverToolStripMenuItem"; - this.reinstallTapDriverToolStripMenuItem.Size = new System.Drawing.Size(209, 22); - this.reinstallTapDriverToolStripMenuItem.Text = "Reinstall Tap driver"; - this.reinstallTapDriverToolStripMenuItem.Click += new System.EventHandler(this.reinstallTapDriverToolStripMenuItem_Click); - // - // EditPictureBox - // - this.EditPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.EditPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("EditPictureBox.Image"))); - this.EditPictureBox.Location = new System.Drawing.Point(3, 3); - this.EditPictureBox.Name = "EditPictureBox"; - this.EditPictureBox.Size = new System.Drawing.Size(16, 16); - this.EditPictureBox.TabIndex = 7; - this.EditPictureBox.TabStop = false; - this.EditPictureBox.Click += new System.EventHandler(this.EditPictureBox_Click); - // - // CopyLinkPictureBox - // - this.CopyLinkPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.CopyLinkPictureBox.Image = global::Netch.Properties.Resources.CopyLink; - this.CopyLinkPictureBox.Location = new System.Drawing.Point(72, 3); - this.CopyLinkPictureBox.Name = "CopyLinkPictureBox"; - this.CopyLinkPictureBox.Size = new System.Drawing.Size(18, 18); - this.CopyLinkPictureBox.TabIndex = 14; - this.CopyLinkPictureBox.TabStop = false; - this.CopyLinkPictureBox.Click += new System.EventHandler(this.CopyLinkPictureBox_Click); - // - // DeletePictureBox - // - this.DeletePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.DeletePictureBox.Image = ((System.Drawing.Image)(resources.GetObject("DeletePictureBox.Image"))); - this.DeletePictureBox.Location = new System.Drawing.Point(26, 3); - this.DeletePictureBox.Name = "DeletePictureBox"; - this.DeletePictureBox.Size = new System.Drawing.Size(16, 16); - this.DeletePictureBox.TabIndex = 8; - this.DeletePictureBox.TabStop = false; - this.DeletePictureBox.Click += new System.EventHandler(this.DeletePictureBox_Click); - // - // SpeedPictureBox - // - this.SpeedPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.SpeedPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("SpeedPictureBox.Image"))); - this.SpeedPictureBox.Location = new System.Drawing.Point(49, 3); - this.SpeedPictureBox.Name = "SpeedPictureBox"; - this.SpeedPictureBox.Size = new System.Drawing.Size(16, 16); - this.SpeedPictureBox.TabIndex = 9; - this.SpeedPictureBox.TabStop = false; - this.SpeedPictureBox.Click += new System.EventHandler(this.SpeedPictureBox_Click); - // - // EditModePictureBox - // - this.EditModePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.EditModePictureBox.ErrorImage = global::Netch.Properties.Resources.edit; - this.EditModePictureBox.Image = global::Netch.Properties.Resources.edit; - this.EditModePictureBox.InitialImage = global::Netch.Properties.Resources.edit; - this.EditModePictureBox.Location = new System.Drawing.Point(3, 3); - this.EditModePictureBox.Name = "EditModePictureBox"; - this.EditModePictureBox.Size = new System.Drawing.Size(16, 16); - this.EditModePictureBox.TabIndex = 12; - this.EditModePictureBox.TabStop = false; - this.EditModePictureBox.Click += new System.EventHandler(this.EditModePictureBox_Click); - // - // DeleteModePictureBox - // - this.DeleteModePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.DeleteModePictureBox.Image = global::Netch.Properties.Resources.delete; - this.DeleteModePictureBox.Location = new System.Drawing.Point(26, 3); - this.DeleteModePictureBox.Name = "DeleteModePictureBox"; - this.DeleteModePictureBox.Size = new System.Drawing.Size(16, 16); - this.DeleteModePictureBox.TabIndex = 13; - this.DeleteModePictureBox.TabStop = false; - this.DeleteModePictureBox.Click += new System.EventHandler(this.DeleteModePictureBox_Click); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -665,18 +665,18 @@ namespace Netch.Forms this.configLayoutPanel.ResumeLayout(false); this.configLayoutPanel.PerformLayout(); this.tableLayoutPanel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.EditPictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.CopyLinkPictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.DeletePictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.SpeedPictureBox)).EndInit(); this.tableLayoutPanel3.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.EditModePictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.DeleteModePictureBox)).EndInit(); this.StatusStrip.ResumeLayout(false); this.StatusStrip.PerformLayout(); this.NotifyMenu.ResumeLayout(false); this.ProfileGroupBox.ResumeLayout(false); this.ProfileGroupBox.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.EditPictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.CopyLinkPictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.DeletePictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.SpeedPictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.EditModePictureBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.DeleteModePictureBox)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index c9a60312..0d33fe2e 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -800,7 +800,10 @@ namespace Netch.Forms //关闭启动按钮 ControlButton.Enabled = false; - //关闭使用代理更新ACL + + //关闭部分选项功能 + RestartServiceToolStripMenuItem.Enabled = false; + UninstallServiceToolStripMenuItem.Enabled = false; updateACLWithProxyToolStripMenuItem.Enabled = false; UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false; reinstallTapDriverToolStripMenuItem.Enabled = false; @@ -914,6 +917,13 @@ namespace Netch.Forms else { MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true; + + RestartServiceToolStripMenuItem.Enabled = true; + UninstallServiceToolStripMenuItem.Enabled = true; + updateACLWithProxyToolStripMenuItem.Enabled = true; + UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = true; + reinstallTapDriverToolStripMenuItem.Enabled = true; + ControlButton.Text = Utils.i18N.Translate("Start"); StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Start failed")}"; State = Models.State.Stopped; @@ -950,6 +960,8 @@ namespace Netch.Forms ControlButton.Enabled = true; ProfileGroupBox.Enabled = true; + RestartServiceToolStripMenuItem.Enabled = true; + UninstallServiceToolStripMenuItem.Enabled = true; updateACLWithProxyToolStripMenuItem.Enabled = true; UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = true; reinstallTapDriverToolStripMenuItem.Enabled = true; @@ -1303,40 +1315,6 @@ namespace Netch.Forms } } - private void updateACLToolStripMenuItem_Click(object sender, EventArgs e) - { - using var client = new Override.WebClient(); - - client.DownloadFileTaskAsync(Global.Settings.ACL, "bin\\default.acl"); - client.DownloadFileCompleted += ((sender, args) => - { - try - { - - if (args.Error == null) - { - NotifyIcon.ShowBalloonTip(5, - UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"), - ToolTipIcon.Info); - //MessageBox.Show(Utils.i18N.Translate("ACL updated successfully")); - } - else - { - Utils.Logging.Info("ACL更新失败!" + args.Error); - NotifyIcon.ShowBalloonTip(5, - UpdateChecker.Name, - Utils.i18N.Translate("ACL update failed"), - ToolTipIcon.Error); - //MessageBox.Show(Utils.i18N.Translate("ACL update failed")); - } - } - finally - { - StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"); - } - }); - } - private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // 当前状态如果不是已停止状态 @@ -1368,6 +1346,41 @@ namespace Netch.Forms Environment.Exit(Environment.ExitCode); } + private void updateACLToolStripMenuItem_Click(object sender, EventArgs e) + { + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting update ACL")}"); + using var client = new Override.WebClient(); + + client.DownloadFileTaskAsync(Global.Settings.ACL, "bin\\default.acl"); + client.DownloadFileCompleted += ((sender, args) => + { + try + { + + if (args.Error == null) + { + NotifyIcon.ShowBalloonTip(5, + UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"), + ToolTipIcon.Info); + //MessageBox.Show(Utils.i18N.Translate("ACL updated successfully")); + } + else + { + Utils.Logging.Info("ACL更新失败!" + args.Error); + /*NotifyIcon.ShowBalloonTip(5, + UpdateChecker.Name, + Utils.i18N.Translate("ACL update failed") + args.Error, + ToolTipIcon.Error);*/ + MessageBox.Show(Utils.i18N.Translate("ACL update failed") + "\n" + args.Error); + } + } + finally + { + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"); + } + }); + } + private void updateACLWithProxyToolStripMenuItem_Click(object sender, EventArgs e) { updateACLWithProxyToolStripMenuItem.Enabled = false; @@ -1407,17 +1420,19 @@ namespace Netch.Forms } catch (Exception e) { - - Utils.Logging.Info("ACL更新失败!" + e.Message); - NotifyIcon.ShowBalloonTip(5, + Utils.Logging.Info("使用代理更新ACL失败!" + e.Message); + /*NotifyIcon.ShowBalloonTip(5, UpdateChecker.Name, - Utils.i18N.Translate("ACL update failed"), - ToolTipIcon.Error); + Utils.i18N.Translate("ACL update failed") + args.Error, + ToolTipIcon.Error);*/ + MessageBox.Show(Utils.i18N.Translate("ACL update failed") + "\n" + e.Message); } finally { updateACLWithProxyToolStripMenuItem.Enabled = true; + MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true; + ControlButton.Text = Utils.i18N.Translate("Start"); StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"); MainController.Stop(); } @@ -1426,20 +1441,31 @@ namespace Netch.Forms private void reinstallTapDriverToolStripMenuItem_Click(object sender, EventArgs e) { - try + Task.Run(() => { - Configuration.deltapall(); - Configuration.addtap(); - NotifyIcon.ShowBalloonTip(5, - UpdateChecker.Name, Utils.i18N.Translate("Reinstall Tap driver successfully"), - ToolTipIcon.Info); - } - catch - { - NotifyIcon.ShowBalloonTip(5, - UpdateChecker.Name, Utils.i18N.Translate("Reinstall Tap driver failed"), - ToolTipIcon.Error); - } + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Reinstalling Tap driver")}"); + Enabled = false; + try + { + Configuration.deltapall(); + Configuration.addtap(); + NotifyIcon.ShowBalloonTip(5, + UpdateChecker.Name, Utils.i18N.Translate("Reinstall Tap driver successfully"), + ToolTipIcon.Info); + } + catch + { + NotifyIcon.ShowBalloonTip(5, + UpdateChecker.Name, Utils.i18N.Translate("Reinstall Tap driver failed"), + ToolTipIcon.Error); + } + finally + { + ControlButton.Text = Utils.i18N.Translate("Start"); + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"); + Enabled = true; + } + }); } } } diff --git a/Netch/Netch.cs b/Netch/Netch.cs index afcc5c82..57c56820 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -73,24 +73,16 @@ namespace Netch { // 加载语言 Utils.i18N.Load(Encoding.UTF8.GetString(Properties.Resources.zh_CN)); - - // 记录当前程序语言 - Utils.Logging.Info($"当前程序语言:{culture}"); } + // 记录当前程序语言 + Utils.Logging.Info($"当前程序语言:{culture}"); + // 从外置文件中加载语言 if (File.Exists($"i18n\\{culture}")) { // 加载语言 Utils.i18N.Load(File.ReadAllText($"i18n\\{culture}")); - - // 记录当前程序语言 - Utils.Logging.Info($"当前程序语言:{culture}"); - } - else - { - // 记录日志 - Utils.Logging.Info("当前程序语言:en_US"); } // 检查是否已经运行 diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 4f6ddfff..39d5a2a6 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -29,6 +29,7 @@ "SetupBypass": "设置绕行规则", "Test failed": "测试失败", "Starting update subscription": "正在更新订阅", + "Starting update ACL": "正在更新ACL", "Subscription updated": "订阅更新完毕", "Register driver": "正在注册驱动", @@ -95,6 +96,7 @@ "Reinstall Tap driver": "重新安装Tap驱动", "Reinstall Tap driver successfully": "重装Tap驱动成功", "Reinstall Tap driver failed": "重装Tap驱动失败", + "Reinstalling Tap driver": "正在重装Tap驱动", "About": "关于", "Telegram Channel": "Telegram 频道", diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index b0b29e40..ee9e3378 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -161,6 +161,7 @@ namespace Netch.Utils Global.TUNTAP.ComponentID = TUNTAP.GetComponentID(); if (string.IsNullOrEmpty(Global.TUNTAP.ComponentID)) { + Logging.Info("未找到可用 TUN/TAP 适配器"); if (MessageBox.Show(i18N.Translate("TUN/TAP driver is not detected. Is it installed now?"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { addtap(); @@ -197,6 +198,7 @@ namespace Netch.Utils /// public static void addtap() { + Logging.Info("正在安装 TUN/TAP 适配器"); //安装Tap Driver Process installProcess = new Process(); installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; @@ -210,6 +212,7 @@ namespace Netch.Utils /// public static void deltapall() { + Logging.Info("正在卸载 TUN/TAP 适配器"); Process installProcess = new Process(); installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; installProcess.StartInfo.FileName = Path.Combine("bin/tap-driver", "deltapall.bat");