diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index d76208c8..5e0a5276 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -57,13 +57,32 @@ namespace Netch.Controllers KillProcessByName(pEncryptedProxyController.MainFile); + // 检查端口是否被占用 + if (PortHelper.PortInUse(Global.Settings.Socks5LocalPort)) + { + MessageBoxX.Show("Socks5" + i18N.Translate("port is in use.")); + return false; + } + + if (PortHelper.PortInUse(Global.Settings.HTTPLocalPort)) + { + MessageBoxX.Show("HTTP" + i18N.Translate("port is in use.")); + return false; + } + + if (PortHelper.PortInUse(Global.Settings.RedirectorTCPPort, PortType.TCP)) + { + MessageBoxX.Show("RedirectorTCP"+i18N.Translate("port is in use.")); + return false; + } + Global.MainForm.StatusText(i18N.Translate("Starting ", pEncryptedProxyController.Name)); result = pEncryptedProxyController.Start(server, mode); } if (result) { - // 加密代理已启动 + Logging.Info("加密代理已启动"); switch (mode.Type) { case 0: // 进程代理模式 diff --git a/Netch/Forms/MainForm.Control.cs b/Netch/Forms/MainForm.Control.cs index a069bcba..62344bd6 100644 --- a/Netch/Forms/MainForm.Control.cs +++ b/Netch/Forms/MainForm.Control.cs @@ -24,7 +24,7 @@ namespace Netch.Forms if (State == State.Waiting || State == State.Stopped) { - #region 服务器、模式 需选择 + // 服务器、模式 需选择 if (ServerComboBox.SelectedIndex == -1) { MessageBoxX.Show(i18N.Translate("Please select a server first")); @@ -36,30 +36,6 @@ namespace Netch.Forms MessageBoxX.Show(i18N.Translate("Please select an mode first")); return; } - #endregion - - #region 检查端口是否被占用 - if (PortHelper.PortInUse(Global.Settings.Socks5LocalPort)) - { - MessageBoxX.Show(i18N.Translate("The Socks5 port is in use. Click OK to modify it.")); - SettingsButton.PerformClick(); - return; - } - - if (PortHelper.PortInUse(Global.Settings.HTTPLocalPort)) - { - MessageBoxX.Show(i18N.Translate("The HTTP port is in use. Click OK to modify it.")); - SettingsButton.PerformClick(); - return; - } - - if (PortHelper.PortInUse(Global.Settings.RedirectorTCPPort, PortType.TCP)) - { - MessageBoxX.Show(i18N.Translate("The RedirectorTCP port is in use. Click OK to modify it.")); - SettingsButton.PerformClick(); - return; - } - #endregion UpdateStatus(State.Starting); diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 6c85d3b7..8f9c07db 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -188,12 +188,7 @@ "Exit": "退出", "Unable to start? Click me to download": "无法启动?点我下载依赖", - "The Socks5 port is in use. Click OK to modify it.": "Socks5端口已被占用,点击确定前往修改", - "The Socks5 port is in use. Please reset.": "Socks5端口已被占用,请重新设置", - "The HTTP port is in use. Click OK to modify it.": "HTTP端口已被占用,点击确定前往修改", - "The HTTP port is in use. Please reset.": "HTTP端口已被占用,请重新设置", - "The RedirectorTCP port is in use. Click OK to modify it.": "RedirectorTCP端口已被占用,点击确定前往修改", - "The RedirectorTCP port is in use. Please reset.": "RedirectorTCP端口已被占用,请重新设置", + "port is in use.": "端口已被占用", "Bypass LAN": "[网页代理] 绕过局域网", "Bypass LAN (Non System Proxy)": "[网页代理] 绕过局域网(不设置系统代理)", diff --git a/Netch/Utils/PortHelper.cs b/Netch/Utils/PortHelper.cs index 8c57d370..b5750e0e 100644 --- a/Netch/Utils/PortHelper.cs +++ b/Netch/Utils/PortHelper.cs @@ -6,7 +6,7 @@ namespace Netch.Utils class PortHelper { /// - /// 端口是否被使用 + /// 端口是否被使用 /// /// /// @@ -16,7 +16,7 @@ namespace Netch.Utils } /// - /// 指定类型的端口是否已经被使用了 + /// 指定类型的端口是否已经被使用了 /// /// 端口号 /// 端口类型