From c31338ee1f69c8c46e29cae3379633f67782cbd9 Mon Sep 17 00:00:00 2001 From: Amazing_DM Date: Tue, 21 Apr 2020 16:58:06 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=E6=B7=BB=E5=8A=A0=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E6=9B=B4=E6=96=B0ACL=E5=8A=9F=E8=83=BD=20:ar?= =?UTF-8?q?t:=E5=90=AF=E5=8A=A8=E5=90=8E=E5=85=81=E8=AE=B8=E6=89=93?= =?UTF-8?q?=E5=BC=80Netch=E8=AE=BE=E7=BD=AE=E5=8F=8A=E5=A4=A7=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=83=A8=E5=88=86=E5=B7=A5=E5=85=B7=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Forms/MainForm.Designer.cs | 22 +++++-- Netch/Forms/MainForm.cs | 90 +++++++++++++++++++++++++-- Netch/Forms/SubscribeForm.Designer.cs | 12 ++-- Netch/Forms/SubscribeForm.cs | 10 +++ 4 files changed, 116 insertions(+), 18 deletions(-) diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index 29fd8492..01caeed2 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -84,6 +84,7 @@ 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.MenuStrip.SuspendLayout(); this.ConfigurationGroupBox.SuspendLayout(); this.configLayoutPanel.SuspendLayout(); @@ -221,7 +222,8 @@ namespace Netch.Forms this.RestartServiceToolStripMenuItem, this.UninstallServiceToolStripMenuItem, this.CleanDNSCacheToolStripMenuItem, - this.UpdateACLToolStripMenuItem}); + this.UpdateACLToolStripMenuItem, + this.updateACLWithProxyToolStripMenuItem}); 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); @@ -230,35 +232,35 @@ namespace Netch.Forms // ReloadModesToolStripMenuItem // this.ReloadModesToolStripMenuItem.Name = "ReloadModesToolStripMenuItem"; - this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ReloadModesToolStripMenuItem.Size = new System.Drawing.Size(209, 22); this.ReloadModesToolStripMenuItem.Text = "Reload Modes"; this.ReloadModesToolStripMenuItem.Click += new System.EventHandler(this.ReloadModesToolStripMenuItem_Click); // // RestartServiceToolStripMenuItem // this.RestartServiceToolStripMenuItem.Name = "RestartServiceToolStripMenuItem"; - this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.RestartServiceToolStripMenuItem.Size = new System.Drawing.Size(209, 22); this.RestartServiceToolStripMenuItem.Text = "Restart Service"; this.RestartServiceToolStripMenuItem.Click += new System.EventHandler(this.RestartServiceToolStripMenuItem_Click); // // UninstallServiceToolStripMenuItem // this.UninstallServiceToolStripMenuItem.Name = "UninstallServiceToolStripMenuItem"; - this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.UninstallServiceToolStripMenuItem.Size = new System.Drawing.Size(209, 22); this.UninstallServiceToolStripMenuItem.Text = "Uninstall Service"; this.UninstallServiceToolStripMenuItem.Click += new System.EventHandler(this.UninstallServiceToolStripMenuItem_Click); // // CleanDNSCacheToolStripMenuItem // this.CleanDNSCacheToolStripMenuItem.Name = "CleanDNSCacheToolStripMenuItem"; - this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.CleanDNSCacheToolStripMenuItem.Size = new System.Drawing.Size(209, 22); this.CleanDNSCacheToolStripMenuItem.Text = "Clean DNS Cache"; this.CleanDNSCacheToolStripMenuItem.Click += new System.EventHandler(this.CleanDNSCacheToolStripMenuItem_Click); // // UpdateACLToolStripMenuItem // this.UpdateACLToolStripMenuItem.Name = "UpdateACLToolStripMenuItem"; - this.UpdateACLToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.UpdateACLToolStripMenuItem.Size = new System.Drawing.Size(209, 22); this.UpdateACLToolStripMenuItem.Text = "Update ACL"; this.UpdateACLToolStripMenuItem.Click += new System.EventHandler(this.updateACLToolStripMenuItem_Click); // @@ -620,6 +622,13 @@ namespace Netch.Forms this.ProfileTable.Size = new System.Drawing.Size(599, 43); this.ProfileTable.TabIndex = 0; // + // 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); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -718,5 +727,6 @@ namespace Netch.Forms private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; private System.Windows.Forms.ToolStripMenuItem UpdateACLToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem updateACLWithProxyToolStripMenuItem; } } \ No newline at end of file diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index 5fadd513..cb6b9b87 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -794,7 +794,14 @@ namespace Netch.Forms return; } - MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false; + //MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false; + + //关闭启动按钮 + ControlButton.Enabled = false; + //关闭使用代理更新ACL + updateACLWithProxyToolStripMenuItem.Enabled = false; + UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false; + ControlButton.Text = "..."; StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting")}"; State = Models.State.Starting; @@ -1295,14 +1302,29 @@ namespace Netch.Forms client.DownloadFileTaskAsync(Global.Settings.ACL, "bin\\default.acl"); client.DownloadFileCompleted += ((sender, args) => { - if (args.Error == null) + try { - MessageBox.Show(Utils.i18N.Translate("ACL updated successfully")); + + 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")); + } } - else + finally { - Utils.Logging.Info("ACL更新失败!" + args.Error); - MessageBox.Show(Utils.i18N.Translate("ACL update failed")); + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"); } }); } @@ -1337,5 +1359,61 @@ namespace Netch.Forms Dispose(); Environment.Exit(Environment.ExitCode); } + + private void updateACLWithProxyToolStripMenuItem_Click(object sender, EventArgs e) + { + updateACLWithProxyToolStripMenuItem.Enabled = false; + if (Global.Settings.UseProxyToUpdateSubscription) + { + // 当前 ServerComboBox 中至少有一项 + if (ServerComboBox.SelectedIndex == -1) + { + MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false; + ControlButton.Text = "..."; + } + + Task.Run(() => + { + var mode = new Models.Mode + { + Remark = "ProxyUpdate", + Type = 5 + }; + MainController = new MainController(); + MainController.Start(ServerComboBox.SelectedItem as Models.Server, mode); + + using var client = new Override.WebClient(); + + client.Proxy = new System.Net.WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}"); + + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Updating in the background")}"); + try + { + client.DownloadFile(Global.Settings.ACL, "bin\\default.acl"); + NotifyIcon.ShowBalloonTip(5, + UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"), + ToolTipIcon.Info); + } + catch (Exception e) + { + + Utils.Logging.Info("ACL更新失败!" + e.Message); + NotifyIcon.ShowBalloonTip(5, + UpdateChecker.Name, + Utils.i18N.Translate("ACL update failed"), + ToolTipIcon.Error); + } + finally + { + updateACLWithProxyToolStripMenuItem.Enabled = true; + + StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}"); + MainController.Stop(); + } + }); + } } } diff --git a/Netch/Forms/SubscribeForm.Designer.cs b/Netch/Forms/SubscribeForm.Designer.cs index 7f4dfabf..d6ea8a1d 100644 --- a/Netch/Forms/SubscribeForm.Designer.cs +++ b/Netch/Forms/SubscribeForm.Designer.cs @@ -88,7 +88,7 @@ this.UserAgentLabel.AutoSize = true; this.UserAgentLabel.Location = new System.Drawing.Point(11, 77); this.UserAgentLabel.Name = "UserAgentLabel"; - this.UserAgentLabel.Size = new System.Drawing.Size(73, 17); + this.UserAgentLabel.Size = new System.Drawing.Size(74, 17); this.UserAgentLabel.TabIndex = 5; this.UserAgentLabel.Text = "User-Agent"; // @@ -150,6 +150,7 @@ this.SubscribeLinkListView.TabIndex = 0; this.SubscribeLinkListView.UseCompatibleStateImageBehavior = false; this.SubscribeLinkListView.View = System.Windows.Forms.View.Details; + this.SubscribeLinkListView.SelectedIndexChanged += new System.EventHandler(this.SubscribeLinkListView_SelectedIndexChanged); // // RemarkColumnHeader // @@ -169,23 +170,22 @@ // pContextMenuStrip // this.pContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.DeleteToolStripMenuItem}); - this.pContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.DeleteToolStripMenuItem, this.CopyLinkToolStripMenuItem}); this.pContextMenuStrip.Name = "pContextMenuStrip"; - this.pContextMenuStrip.Size = new System.Drawing.Size(114, 26); + this.pContextMenuStrip.Size = new System.Drawing.Size(130, 48); // // DeleteToolStripMenuItem // this.DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem"; - this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(113, 22); + this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(129, 22); this.DeleteToolStripMenuItem.Text = "Delete"; this.DeleteToolStripMenuItem.Click += new System.EventHandler(this.DeleteToolStripMenuItem_Click); // // CopyLinkToolStripMenuItem // this.CopyLinkToolStripMenuItem.Name = "CopyLinkToolStripMenuItem"; - this.CopyLinkToolStripMenuItem.Size = new System.Drawing.Size(113, 22); + this.CopyLinkToolStripMenuItem.Size = new System.Drawing.Size(129, 22); this.CopyLinkToolStripMenuItem.Text = "CopyLink"; this.CopyLinkToolStripMenuItem.Click += new System.EventHandler(this.CopyLinkToolStripMenuItem_Click); // diff --git a/Netch/Forms/SubscribeForm.cs b/Netch/Forms/SubscribeForm.cs index a40633ab..b6f8013b 100644 --- a/Netch/Forms/SubscribeForm.cs +++ b/Netch/Forms/SubscribeForm.cs @@ -144,5 +144,15 @@ namespace Netch.Forms MessageBox.Show(Utils.i18N.Translate("Successfully saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } + /// + /// 订阅列表选中节点 + /// TODO 选中节点编辑 + /// + /// + /// + private void SubscribeLinkListView_SelectedIndexChanged(object sender, EventArgs e) + { + //MessageBox.Show(SubscribeLinkListView.SelectedItems + "", Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); + } } }