From 365d4b5ff58962c83a6751b164190fa6418b32e4 Mon Sep 17 00:00:00 2001 From: Amazing_DM Date: Sat, 25 Apr 2020 11:07:48 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=E6=96=B0=E5=A2=9E=E9=87=8D=E8=A3=85t?= =?UTF-8?q?ap=E9=A9=B1=E5=8A=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Forms/MainForm.Designer.cs | 192 ++++++++++++++++--------------- Netch/Forms/MainForm.cs | 22 ++++ Netch/Netch.csproj | 2 +- Netch/Resources/zh-CN | 3 + Netch/Utils/Configuration.cs | 34 ++++-- binaries | 2 +- 6 files changed, 154 insertions(+), 101 deletions(-) diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index 01caeed2..b2d7864e 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -51,6 +51,7 @@ namespace Netch.Forms this.UninstallServiceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CleanDNSCacheToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.UpdateACLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.updateACLWithProxyToolStripMenuItem = 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(); @@ -63,13 +64,7 @@ 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(); @@ -84,21 +79,27 @@ 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.updateACLWithProxyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + 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 @@ -223,7 +224,8 @@ namespace Netch.Forms this.UninstallServiceToolStripMenuItem, this.CleanDNSCacheToolStripMenuItem, this.UpdateACLToolStripMenuItem, - this.updateACLWithProxyToolStripMenuItem}); + this.updateACLWithProxyToolStripMenuItem, + this.reinstallTapDriverToolStripMenuItem}); 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); @@ -264,6 +266,13 @@ namespace Netch.Forms this.UpdateACLToolStripMenuItem.Text = "Update ACL"; this.UpdateACLToolStripMenuItem.Click += new System.EventHandler(this.updateACLToolStripMenuItem_Click); // + // updateACLWithProxyToolStripMenuItem + // + this.updateACLWithProxyToolStripMenuItem.Name = "updateACLWithProxyToolStripMenuItem"; + this.updateACLWithProxyToolStripMenuItem.Size = new System.Drawing.Size(209, 22); + this.updateACLWithProxyToolStripMenuItem.Text = "Update ACL with proxy"; + this.updateACLWithProxyToolStripMenuItem.Click += new System.EventHandler(this.updateACLWithProxyToolStripMenuItem_Click); + // // AboutToolStripButton // this.AboutToolStripButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; @@ -410,50 +419,6 @@ 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; @@ -470,30 +435,6 @@ 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); @@ -622,12 +563,80 @@ namespace Netch.Forms this.ProfileTable.Size = new System.Drawing.Size(599, 43); this.ProfileTable.TabIndex = 0; // - // updateACLWithProxyToolStripMenuItem + // reinstallTapDriverToolStripMenuItem // - this.updateACLWithProxyToolStripMenuItem.Name = "updateACLWithProxyToolStripMenuItem"; - this.updateACLWithProxyToolStripMenuItem.Size = new System.Drawing.Size(209, 22); - this.updateACLWithProxyToolStripMenuItem.Text = "Update ACL with proxy"; - this.updateACLWithProxyToolStripMenuItem.Click += new System.EventHandler(this.updateACLWithProxyToolStripMenuItem_Click); + 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 // @@ -656,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(); @@ -728,5 +737,6 @@ namespace Netch.Forms private System.Windows.Forms.ToolStripMenuItem UpdateACLToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem updateACLWithProxyToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem reinstallTapDriverToolStripMenuItem; } } \ No newline at end of file diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 7f9893c0..c9a60312 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -1,4 +1,5 @@ using Netch.Controllers; +using Netch.Utils; using System; using System.Collections.Generic; using System.Diagnostics; @@ -332,6 +333,7 @@ namespace Netch.Forms CleanDNSCacheToolStripMenuItem.Text = Utils.i18N.Translate(CleanDNSCacheToolStripMenuItem.Text); UpdateACLToolStripMenuItem.Text = Utils.i18N.Translate(UpdateACLToolStripMenuItem.Text); updateACLWithProxyToolStripMenuItem.Text = Utils.i18N.Translate(updateACLWithProxyToolStripMenuItem.Text); + reinstallTapDriverToolStripMenuItem.Text = Utils.i18N.Translate(reinstallTapDriverToolStripMenuItem.Text); AboutToolStripButton.Text = Utils.i18N.Translate(AboutToolStripButton.Text); ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text); ServerLabel.Text = Utils.i18N.Translate(ServerLabel.Text); @@ -801,6 +803,7 @@ namespace Netch.Forms //关闭使用代理更新ACL updateACLWithProxyToolStripMenuItem.Enabled = false; UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false; + reinstallTapDriverToolStripMenuItem.Enabled = false; ControlButton.Text = "..."; StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting")}"; @@ -949,6 +952,7 @@ namespace Netch.Forms 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("Stopped")}"; @@ -1419,5 +1423,23 @@ namespace Netch.Forms } }); } + + private void reinstallTapDriverToolStripMenuItem_Click(object sender, EventArgs e) + { + 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); + } + } } } diff --git a/Netch/Netch.csproj b/Netch/Netch.csproj index 1e6b4190..720c974b 100644 --- a/Netch/Netch.csproj +++ b/Netch/Netch.csproj @@ -108,7 +108,7 @@ - + diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 278e67da..be5258a6 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -92,6 +92,9 @@ "Update ACL with proxy": "使用代理更新 ACL 规则", "ACL updated successfully": "ACL 更新成功", "ACL update failed": "ACL更新失败", + "Reinstall Tap driver": "重新安装Tap驱动", + "Reinstall Tap driver successfully": "重装Tap驱动成功", + "Reinstall Tap driver failed": "重装Tap驱动失败", "About": "关于", "Telegram Channel": "Telegram 频道", diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs index eb10295d..b0b29e40 100644 --- a/Netch/Utils/Configuration.cs +++ b/Netch/Utils/Configuration.cs @@ -163,16 +163,9 @@ namespace Netch.Utils { if (MessageBox.Show(i18N.Translate("TUN/TAP driver is not detected. Is it installed now?"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { - //安装Tap Driver - Process installProcess = new Process(); - installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - installProcess.StartInfo.FileName = Path.Combine("bin/tap-driver", "install.bat"); - installProcess.Start(); - installProcess.WaitForExit(); - installProcess.Close(); + addtap(); //给点时间,不然立马安装完毕就查找适配器可能会导致找不到适配器ID Thread.Sleep(1000); - Global.TUNTAP.ComponentID = TUNTAP.GetComponentID(); } else @@ -199,5 +192,30 @@ namespace Netch.Utils Logging.Info("无法找到出口"); return false; } + /// + /// 安装tap网卡 + /// + public static void addtap() + { + //安装Tap Driver + Process installProcess = new Process(); + installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + installProcess.StartInfo.FileName = Path.Combine("bin/tap-driver", "addtap.bat"); + installProcess.Start(); + installProcess.WaitForExit(); + installProcess.Close(); + } + /// + /// 卸载tap网卡 + /// + public static void deltapall() + { + Process installProcess = new Process(); + installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + installProcess.StartInfo.FileName = Path.Combine("bin/tap-driver", "deltapall.bat"); + installProcess.Start(); + installProcess.WaitForExit(); + installProcess.Close(); + } } } diff --git a/binaries b/binaries index b01d61e0..2d329685 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit b01d61e06f6e98729a072095314dc285bdc39132 +Subproject commit 2d32968553b895e97cc9257986322905e93c1ccd