mirror of
https://github.com/netchx/netch.git
synced 2026-04-03 19:35:10 +08:00
优化日志事件接收方法, 修复启动控制器时没有清除上次启动的日志
This commit is contained in:
@@ -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
|
||||
/// <param name="e">数据</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user