Skip to content

Commit

Permalink
修复 端口被占用文本错误,
Browse files Browse the repository at this point in the history
修复 停止并退出的逻辑错误
  • Loading branch information
chsbuffer committed Jul 19, 2020
1 parent e10c994 commit 7a15fa7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
6 changes: 3 additions & 3 deletions Netch/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
89 changes: 45 additions & 44 deletions Netch/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7a15fa7

Please sign in to comment.