From 7a15fa73751cdb7878786e2ebfebc886a74d9bca Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Sun, 19 Jul 2020 18:18:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E8=A2=AB=E5=8D=A0=E7=94=A8=E6=96=87=E6=9C=AC=E9=94=99=E8=AF=AF?= =?UTF-8?q?,=20=E4=BF=AE=E5=A4=8D=20=E5=81=9C=E6=AD=A2=E5=B9=B6=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Controllers/MainController.cs | 6 +- Netch/Forms/MainForm.cs | 89 +++++++++++++++-------------- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 0671901ae7..d4c58a54b7 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -68,19 +68,19 @@ public bool Start(Server server, Mode mode) // 检查端口是否被占用 if (PortHelper.PortInUse(Global.Settings.Socks5LocalPort)) { - MessageBoxX.Show(i18N.Translate("The {0} port is in use.", "Socks5")); + MessageBoxX.Show(i18N.TranslateFormat("The {0} port is in use.", "Socks5")); return false; } if (PortHelper.PortInUse(Global.Settings.HTTPLocalPort)) { - MessageBoxX.Show(i18N.Translate("The {0} port is in use.", "HTTP")); + MessageBoxX.Show(i18N.TranslateFormat("The {0} port is in use.", "HTTP")); return false; } if (PortHelper.PortInUse(Global.Settings.RedirectorTCPPort, PortType.TCP)) { - MessageBoxX.Show(i18N.Translate("The {0} port is in use.", "Redirector TCP")); + MessageBoxX.Show(i18N.TranslateFormat("The {0} port is in use.", "Redirector TCP")); return false; } diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index abd0a3a3b0..9cf2d08454 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -216,6 +216,51 @@ private void InitText() VersionLabel.Text = UpdateChecker.Version; } + private void Exit(bool forceExit = false) + { + if (IsDisposed) return; + + // 已启动 + if (State != State.Waiting && State != State.Stopped) + { + if (Global.Settings.StopWhenExited || forceExit) + { + UpdateStatus(State.Stopping); + ControlFun(); + } + else + { + // 未开启自动停止 + MessageBoxX.Show(i18N.Translate("Please press Stop button first")); + + Visible = true; + ShowInTaskbar = true; // 显示在系统任务栏 + WindowState = FormWindowState.Normal; // 还原窗体 + NotifyIcon.Visible = true; // 托盘图标隐藏 + + return; + } + } + + NotifyIcon.Visible = false; + Hide(); + + Task.Run(() => + { + for (var i = 0; i < 16; i++) + { + if (State == State.Waiting || State == State.Stopped) + break; + Thread.Sleep(250); + } + + SaveConfigs(); + UpdateStatus(State.Terminating); + Dispose(); + Environment.Exit(Environment.ExitCode); + }); + } + #region MISC /// @@ -385,50 +430,6 @@ private void DeleteServerPictureBox_Click(object sender, EventArgs e) } } - private void Exit(bool forceExit = false) - { - if(IsDisposed) return; - // 已启动 - if (State != State.Waiting && State != State.Stopped) - { - if (forceExit) - ControlFun(); - else - { - if (!Global.Settings.StopWhenExited) - { - // 未开启自动停止 - MessageBoxX.Show(i18N.Translate("Please press Stop button first")); - - Visible = true; - ShowInTaskbar = true; // 显示在系统任务栏 - WindowState = FormWindowState.Normal; // 还原窗体 - NotifyIcon.Visible = true; // 托盘图标隐藏 - - return; - } - } - } - - NotifyIcon.Visible = false; - Hide(); - - Task.Run(() => - { - for (var i = 0; i < 16; i++) - { - if (State == State.Waiting || State == State.Stopped) - break; - Thread.Sleep(250); - } - - SaveConfigs(); - UpdateStatus(State.Terminating); - Dispose(); - Environment.Exit(Environment.ExitCode); - }); - } - #region NotifyIcon private void ShowMainFormToolStripButton_Click(object sender, EventArgs e)