Merge pull request #308 from chsbuffer/master

移除NTT日志文件
This commit is contained in:
AmazingDM
2020-07-13 17:28:29 +08:00
committed by GitHub
3 changed files with 25 additions and 26 deletions

View File

@@ -94,7 +94,13 @@ namespace Netch.Controllers
case 1:
case 2:
if (result)
Task.Run(() => pNTTController.Start());
Task.Run(() =>
{
MainForm.Instance.NatTypeStatusText(i18N.Translate("Starting NatTester"));
// Thread.Sleep(1000);
var (nttResult, natType, _, _) = pNTTController.Start();
if (nttResult) MainForm.Instance.NatTypeStatusText(natType);
});
break;
}
}

View File

@@ -1,8 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Netch.Forms;
using Netch.Models;
using Netch.Utils;
@@ -10,6 +7,8 @@ namespace Netch.Controllers
{
public class NTTController : Controller
{
private string _lastResult;
public NTTController()
{
MainFile = "NTT";
@@ -23,8 +22,6 @@ namespace Netch.Controllers
public (bool, string, string, string) Start()
{
if (!Ready) return (false, null, null, null);
Thread.Sleep(1000);
MainForm.Instance.NatTypeStatusText(i18N.Translate("Starting NatTester"));
try
{
Instance = GetProcess("bin\\NTT.exe");
@@ -40,11 +37,10 @@ namespace Netch.Controllers
Instance.BeginErrorReadLine();
Instance.WaitForExit();
var result = File.ReadAllText($"logging\\{MainFile}.log").Split('#');
var result = _lastResult.Split('#');
var natType = result[0];
var localEnd = result[1];
var publicEnd = result[2];
MainForm.Instance.NatTypeStatusText(natType);
return (true, natType, localEnd, publicEnd);
}
@@ -58,7 +54,8 @@ namespace Netch.Controllers
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
WriteLog(e);
if (!string.IsNullOrEmpty(e.Data))
_lastResult = e.Data;
}
/// <summary>

View File

@@ -1,8 +1,7 @@
using System;
using System.Windows.Media;
using System.Drawing;
using Netch.Models;
using Netch.Utils;
using Color = System.Drawing.Color;
namespace Netch.Forms
{
@@ -22,28 +21,24 @@ namespace Netch.Forms
if (State != State.Started)
{
NatTypeStatusLabel.Text = "";
NatTypeStatusLabel.Visible = false;
NatTypeStatusLightLabel.Visible = false;
NatTypeStatusLabel.Visible = NatTypeStatusLightLabel.Visible = false;
return;
}
if (!string.IsNullOrEmpty(text))
{
NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + text.Trim();
if (Enum.TryParse(text, false, out STUN_Client.NatType natType))
{
NatTypeStatusLightLabel.Visible = true;
UpdateNatTypeLight(natType);
}
}
else
{
NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + i18N.Translate("Test failed");
}
if (Enum.TryParse(text,false,out STUN_Client.NatType natType))
{
UpdateNatTypeLight(natType);
NatTypeStatusLightLabel.Visible = true;
}
else
{
NatTypeStatusLightLabel.Visible = false;
}
NatTypeStatusLabel.Visible = true;
}
@@ -66,12 +61,13 @@ namespace Netch.Forms
c = Color.LimeGreen;
break;
default:
c=Color.Red;
c = Color.Red;
break;
}
NatTypeStatusLightLabel.ForeColor=c;
NatTypeStatusLightLabel.ForeColor = c;
}
public void StatusText(string text)
{
@@ -79,7 +75,7 @@ namespace Netch.Forms
}
/// <summary>
/// Update UI, Status, Status Label
/// Update UI, Status, Status Label
/// </summary>
/// <param name="state"></param>
public void UpdateStatus(State state)