diff --git a/Netch/Controllers/Interface/Controller.cs b/Netch/Controllers/Interface/Controller.cs index 53302a7f..31468936 100644 --- a/Netch/Controllers/Interface/Controller.cs +++ b/Netch/Controllers/Interface/Controller.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text; +using System.Threading.Tasks; using Netch.Models; using Netch.Utils; @@ -137,40 +139,24 @@ namespace Netch.Controllers /// 数据 protected void OnOutputDataReceived(object sender, DataReceivedEventArgs e) { - var str = Encoding.UTF8.GetString(Encoding.GetEncoding("gbk").GetBytes(e.Data??string.Empty)); + // 程序结束接收到 null + if (e.Data == null) + { + State = State.Stopped; + return; + } + var str = Encoding.UTF8.GetString(Encoding.GetEncoding("gbk").GetBytes(e.Data ?? string.Empty)); // 写入日志 - if (!Write(str)) return; + Task.Run(() => Write(str)); // 检查启动 if (State == State.Starting) { - if (Instance.HasExited) - { + if (_startedKeywords.Any(s => str.Contains(s))) + State = State.Started; + else if (_stoppedKeywords.Any(s => str.Contains(s))) State = State.Stopped; - - return; - } - - foreach (var s in _startedKeywords) - { - if (str.Contains(s)) - { - State = State.Started; - - return; - } - } - - foreach (var s in _stoppedKeywords) - { - if (str.Contains(s)) - { - State = State.Stopped; - - return; - } - } } } } diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 49b42151..22252295 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -86,6 +86,7 @@ namespace Netch.Controllers } Global.MainForm.StatusText(i18N.Translate("Starting ", pEncryptedProxyController.Name)); + pEncryptedProxyController.ClearLog(); result = pEncryptedProxyController.Start(server, mode); } @@ -112,6 +113,7 @@ namespace Netch.Controllers if (pModeController != null) { Global.MainForm.StatusText(i18N.Translate("Starting ", pModeController.Name)); + pModeController.ClearLog(); result = pModeController.Start(server, mode); }