mirror of
https://github.com/netchx/netch.git
synced 2026-03-16 17:53:17 +08:00
修复 端口被占用文本错误,
修复 停止并退出的逻辑错误
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user