更新 Controller类

改善错误输出
This commit is contained in:
ChsBuffer
2020-07-17 19:18:29 +08:00
parent a779295525
commit 281c67aced
17 changed files with 195 additions and 254 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Netch.Models;
@@ -12,13 +11,14 @@ namespace Netch.Controllers
{
public TrojanController()
{
MainFile = "Trojan";
InitCheck();
Name = "Trojan";
MainFile = "Trojan.exe";
StartedKeywords("started");
StoppedKeywords("exiting");
}
public override bool Start(Server server, Mode mode)
{
if (!Ready) return false;
File.WriteAllText("data\\last.json", JsonConvert.SerializeObject(new Trojan
{
@@ -32,7 +32,7 @@ namespace Netch.Controllers
}
}));
Instance = GetProcess("bin\\Trojan.exe");
Instance = GetProcess();
Instance.StartInfo.Arguments = "-c ..\\data\\last.json";
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
@@ -61,19 +61,6 @@ namespace Netch.Controllers
return false;
}
public override void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!Write(e.Data)) return;
if (State == State.Starting)
{
if (Instance.HasExited)
State = State.Stopped;
else if (e.Data.Contains("started"))
State = State.Started;
else if (e.Data.Contains("exiting")) State = State.Stopped;
}
}
public override void Stop()
{
StopInstance();