修复 端口被占用文本错误,

修复 停止并退出的逻辑错误
This commit is contained in:
ChsBuffer
2020-07-19 18:18:57 +08:00
parent e10c994e38
commit 7a15fa7375
2 changed files with 48 additions and 47 deletions

View File

@@ -68,19 +68,19 @@ namespace Netch.Controllers
// 检查端口是否被占用
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;
}

View File

@@ -216,6 +216,51 @@ namespace Netch.Forms
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
/// <summary>
@@ -385,50 +430,6 @@ namespace Netch.Forms
}
}
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)