更新 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;
using System.Diagnostics;
using Netch.Utils;
namespace Netch.Controllers
@@ -8,10 +7,8 @@ namespace Netch.Controllers
{
public DNSController()
{
Name = "dns Service";
MainFile = "unbound";
ExtFiles = new[] {"unbound-service.conf", "forward-zone.conf"};
InitCheck();
Name = "DNS Service";
MainFile = "unbound.exe";
}
/// <summary>
@@ -20,9 +17,7 @@ namespace Netch.Controllers
/// <returns></returns>
public bool Start()
{
if (!Ready) return false;
Instance = GetProcess("bin\\unbound.exe");
Instance = GetProcess();
Instance.StartInfo.Arguments = "-c unbound-service.conf -v";
Instance.OutputDataReceived += OnOutputDataReceived;
@@ -42,11 +37,6 @@ namespace Netch.Controllers
}
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
Write(e.Data);
}
public override void Stop()
{
StopInstance();

View File

@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Text;
using System.Text;
using System.Threading;
using Netch.Models;
using Netch.Utils;
@@ -10,8 +9,10 @@ namespace Netch.Controllers
{
public SSController()
{
MainFile = "Shadowsocks";
InitCheck();
Name = "Shadowsocks";
MainFile = "Shadowsocks.exe";
StartedKeywords("listening at");
StoppedKeywords("Invalid config path","usage","plugin service exit unexpectedly");
}
public override bool Start(Server server, Mode mode)
@@ -45,8 +46,7 @@ namespace Netch.Controllers
return true;
}
if (!Ready) return false;
Instance = GetProcess("bin\\Shadowsocks.exe");
Instance = GetProcess();
Instance.StartInfo.Arguments = $"-s {server.Hostname} -p {server.Port} -b {Global.Settings.LocalAddress} -l {Global.Settings.Socks5LocalPort} -m {server.EncryptMethod} -k \"{server.Password}\" -u";
if (!string.IsNullOrWhiteSpace(server.Plugin) && !string.IsNullOrWhiteSpace(server.PluginOption))
@@ -89,18 +89,5 @@ namespace Netch.Controllers
else
StopInstance();
}
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("listening at"))
State = State.Started;
else if (e.Data.Contains("Invalid config path") || e.Data.Contains("usage") || e.Data.Contains("plugin service exit unexpectedly")) State = State.Stopped;
}
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Threading;
using System.Threading;
using Netch.Models;
using Netch.Utils;
@@ -9,15 +8,15 @@ namespace Netch.Controllers
{
public SSRController()
{
MainFile = "ShadowsocksR";
InitCheck();
Name = "ShadowsocksR";
MainFile = "ShadowsocksR.exe";
StartedKeywords("listening at");
StoppedKeywords("Invalid config path","usage");
}
public override bool Start(Server server, Mode mode)
{
if (!Ready) return false;
Instance = GetProcess("bin\\ShadowsocksR.exe");
Instance = GetProcess();
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
@@ -66,19 +65,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("listening at"))
State = State.Started;
else if (e.Data.Contains("Invalid config path") || e.Data.Contains("usage")) State = State.Stopped;
}
}
public override void Stop()
{
StopInstance();

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();

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Netch.Models;
@@ -13,13 +12,14 @@ namespace Netch.Controllers
{
public VMessController()
{
MainFile = "v2ray";
InitCheck();
Name = "v2ray";
MainFile = "v2ray.exe";
StartedKeywords("started");
StoppedKeywords("config file not readable", "failed to");
}
public override bool Start(Server server, Mode mode)
{
if (!Ready) return false;
File.WriteAllText("data\\last.json", JsonConvert.SerializeObject(new VMess.Config
{
inbounds = new List<VMess.Inbounds>
@@ -58,14 +58,14 @@ namespace Netch.Controllers
streamSettings = new VMess.StreamSettings
{
network = server.TransferProtocol,
security = server.TLSSecure ? "tls" : "",
security = server.TLSSecure ? "tls" : string.Empty,
wsSettings = server.TransferProtocol == "ws"
? new VMess.WebSocketSettings
{
path = server.Path == "" ? "/" : server.Path,
path = server.Path == string.Empty ? "/" : server.Path,
headers = new VMess.WSHeaders
{
Host = server.Host == "" ? server.Hostname : server.Host
Host = server.Host == string.Empty ? server.Hostname : server.Host
}
}
: null,
@@ -77,10 +77,10 @@ namespace Netch.Controllers
type = server.FakeType,
request = new VMess.TCPRequest
{
path = server.Path == "" ? "/" : server.Path,
path = server.Path == string.Empty ? "/" : server.Path,
headers = new VMess.TCPRequestHeaders
{
Host = server.Host == "" ? server.Hostname : server.Host
Host = server.Host == string.Empty ? server.Hostname : server.Host
}
}
}
@@ -168,7 +168,7 @@ namespace Netch.Controllers
}
}));
Instance = GetProcess("bin\\v2ray.exe");
Instance = GetProcess();
Instance.StartInfo.Arguments = "-config ..\\data\\last.json";
Instance.OutputDataReceived += OnOutputDataReceived;
@@ -203,19 +203,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("config file not readable") || e.Data.Contains("failed to")) State = State.Stopped;
}
}
public override void Stop()
{
StopInstance();

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Netch.Models;
@@ -10,16 +11,9 @@ namespace Netch.Controllers
{
/// <summary>
/// 控制器名
/// <param />
/// 未赋值会在 <see cref="InitCheck" /> 赋值为 <see cref="MainFile" />
/// </summary>
public string Name;
/// <summary>
/// 其他需要文件
/// </summary>
protected string[] ExtFiles;
/// <summary>
/// 进程实例
/// </summary>
@@ -30,10 +24,29 @@ namespace Netch.Controllers
/// </summary>
public string MainFile;
/// <summary>
/// 运行检查, 由 <see cref="InitCheck()" /> 赋值
/// </summary>
public bool Ready;
private List<string> _startedKeywords = new List<string>();
private List<string> _stoppedKeywords = new List<string>();
protected bool RedirectStd = true;
protected void StartedKeywords(params string[] texts)
{
foreach (var text in texts)
{
_startedKeywords.Add(text);
}
}
protected void StoppedKeywords(params string[] texts)
{
foreach (var text in texts)
{
_stoppedKeywords.Add(text);
}
}
/// <summary>
/// 当前状态
@@ -55,23 +68,13 @@ namespace Netch.Controllers
}
catch (Exception e)
{
Logging.Error($"停止 {MainFile}.exe 错误:\n" + e);
Logging.Error($"停止 {MainFile} 错误:\n" + e);
}
}
/// <summary>
/// 杀残留进程,清除日志,检查文件
/// </summary>
/// <returns></returns>
protected void InitCheck()
public void ClearLog()
{
if (string.IsNullOrEmpty(Name)) Name = MainFile;
var result = false;
// 杀残留
MainController.KillProcessByName(MainFile);
// 清日志
try
{
if (File.Exists($"logging\\{Name}.log")) File.Delete($"logging\\{Name}.log");
@@ -80,30 +83,6 @@ namespace Netch.Controllers
{
// ignored
}
// 检查文件
var mainResult = true;
var extResult = true;
if (!string.IsNullOrEmpty(MainFile) && !File.Exists($"bin\\{MainFile}.exe"))
{
mainResult = false;
Logging.Error($"主程序 bin\\{MainFile}.exe 不存在");
}
if (ExtFiles != null)
{
foreach (var file in ExtFiles)
if (!File.Exists($"bin\\{file}"))
{
extResult = false;
Logging.Error($"附加文件 bin\\{file} 不存在");
}
}
result = extResult && mainResult;
if (!result)
Logging.Error(Name + " 未就绪");
Ready = result;
}
/// <summary>
@@ -126,24 +105,65 @@ namespace Netch.Controllers
return true;
}
public static Process GetProcess(string path = null, bool redirectStd = true)
public Process GetProcess()
{
var p = new Process
{
StartInfo =
{
Arguments = "",
FileName = Path.GetFullPath($"bin\\{MainFile}"),
WorkingDirectory = $"{Global.NetchDir}\\bin",
CreateNoWindow = true,
RedirectStandardError = redirectStd,
RedirectStandardInput = redirectStd,
RedirectStandardOutput = redirectStd,
RedirectStandardError = RedirectStd,
RedirectStandardInput = RedirectStd,
RedirectStandardOutput = RedirectStd,
UseShellExecute = false
},
EnableRaisingEvents = true
};
if (path != null) p.StartInfo.FileName = Path.GetFullPath(path);
return p;
}
/// <summary>
/// 接收输出数据
/// </summary>
/// <param name="sender">发送者</param>
/// <param name="e">数据</param>
protected void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
// 写入日志
if (!Write(e.Data)) return;
// 检查启动
if (State == State.Starting)
{
if (Instance.HasExited)
{
State = State.Stopped;
return;
}
foreach (var s in _startedKeywords)
{
if (e.Data.Contains(s))
{
State = State.Started;
return;
}
}
foreach (var s in _stoppedKeywords)
{
if (e.Data.Contains(s))
{
State = State.Stopped;
return;
}
}
}
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Diagnostics;
using Netch.Models;
using Netch.Models;
namespace Netch.Controllers
{
@@ -12,7 +11,5 @@ namespace Netch.Controllers
/// <param name="mode">模式</param>
/// <returns>是否启动成功</returns>
public abstract bool Start(Server server, Mode mode);
public abstract void OnOutputDataReceived(object sender, DataReceivedEventArgs e);
}
}

View File

@@ -3,7 +3,6 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Netch.Forms;
using Netch.Models;
using Netch.Utils;
@@ -56,13 +55,14 @@ namespace Netch.Controllers
break;
}
KillProcessByName(pEncryptedProxyController.MainFile);
Global.MainForm.StatusText(i18N.Translate("Starting ", pEncryptedProxyController.Name));
if (pEncryptedProxyController.Ready) result = pEncryptedProxyController.Start(server, mode);
result = pEncryptedProxyController.Start(server, mode);
}
if (result)
{
Logging.Info("加密代理已启动");
// 加密代理已启动
switch (mode.Type)
{
@@ -82,7 +82,7 @@ namespace Netch.Controllers
break;
}
if (pModeController != null && pModeController.Ready)
if (pModeController != null)
{
Global.MainForm.StatusText(i18N.Translate("Starting ", pModeController.Name));
result = pModeController.Start(server, mode);
@@ -90,7 +90,6 @@ namespace Netch.Controllers
if (result)
{
Logging.Info("模式已启动");
switch (mode.Type)
{
case 0:

View File

@@ -20,7 +20,6 @@ namespace Netch.Controllers
public HTTPController()
{
Name = "HTTP";
Ready = true;
}
/// <summary>
@@ -31,8 +30,6 @@ namespace Netch.Controllers
/// <returns>是否启动成功</returns>
public override bool Start(Server server, Mode mode)
{
if (!Ready) return false;
RecordPrevious();
try
{

View File

@@ -3,8 +3,6 @@ using System.Diagnostics;
using System.IO;
using System.ServiceProcess;
using System.Threading;
using System.Threading.Tasks;
using Netch.Forms;
using Netch.Models;
using Netch.Utils;
using nfapinet;
@@ -15,14 +13,9 @@ namespace Netch.Controllers
{
private static readonly ServiceController NFService = new ServiceController("netfilter2");
private static readonly string BinDriver = "";
private static readonly string BinDriver = string.Empty;
private static readonly string SystemDriver = $"{Environment.SystemDirectory}\\drivers\\netfilter2.sys";
public static string DriverVersion(string file)
{
return File.Exists(file) ? FileVersionInfo.GetVersionInfo(file).FileVersion : "";
}
static NFController()
{
switch ($"{Environment.OSVersion.Version.Major}.{Environment.OSVersion.Version.Minor}")
@@ -48,22 +41,24 @@ namespace Netch.Controllers
public NFController()
{
MainFile = "Redirector";
ExtFiles = new[] {Path.GetFileName(BinDriver)};
InitCheck();
if (!File.Exists(SystemDriver))
{
InstallDriver();
}
Name = "Redirector";
MainFile = "Redirector.exe";
StartedKeywords("Started");
StoppedKeywords("Failed", "Unable");
}
public override bool Start(Server server, Mode mode)
{
if (!CheckDriverReady())
Logging.Info("内置驱动版本" + DriverVersion(BinDriver));
Logging.Info("系统驱动版本" + DriverVersion(SystemDriver));
if (DriverVersion(SystemDriver) != DriverVersion(BinDriver))
{
if (File.Exists(SystemDriver))
{
Logging.Info("更新驱动");
UninstallDriver();
}
if (!InstallDriver())
return false;
}
@@ -73,7 +68,7 @@ namespace Netch.Controllers
processList += proc + ",";
processList += "NTT.exe";
Instance = GetProcess("bin\\Redirector.exe");
Instance = GetProcess();
if (server.Type != "Socks5")
{
Instance.StartInfo.Arguments += $"-r 127.0.0.1:{Global.Settings.Socks5LocalPort} -p \"{processList}\"";
@@ -110,7 +105,7 @@ namespace Netch.Controllers
if (State == State.Started) return true;
}
Logging.Error("NF 进程启动超时");
Logging.Error(Name + "启动超时");
Stop();
if (!RestartService()) return false;
}
@@ -155,17 +150,19 @@ namespace Netch.Controllers
return true;
}
private bool CheckDriverReady()
public static string DriverVersion(string file)
{
// 检查驱动是否存在
if (!File.Exists(SystemDriver)) return false;
// 检查驱动版本号
return DriverVersion(SystemDriver) == DriverVersion(BinDriver);
return File.Exists(file) ? FileVersionInfo.GetVersionInfo(file).FileVersion : string.Empty;
}
/// <summary>
/// 卸载 NF 驱动
/// </summary>
/// <returns>是否成功卸载</returns>
public static bool UninstallDriver()
{
Global.MainForm.StatusText("Uninstall netfilter2");
Logging.Info("卸载NF驱动");
try
{
if (NFService.Status == ServiceControllerStatus.Running)
@@ -180,22 +177,28 @@ namespace Netch.Controllers
}
if (!File.Exists(SystemDriver)) return true;
try
{
NFAPI.nf_unRegisterDriver("netfilter2");
File.Delete(SystemDriver);
return true;
}
catch (Exception ex)
catch (Exception e)
{
throw ex;
Logging.Error(e.ToString());
return false;
}
File.Delete(SystemDriver);
return true;
}
/// <summary>
/// 安装 NF 驱动
/// </summary>
/// <returns>驱动是否安装成功</returns>
public static bool InstallDriver()
{
Logging.Info("安装驱动");
Logging.Info("安装NF驱动");
try
{
File.Copy(BinDriver, SystemDriver);
@@ -222,34 +225,34 @@ namespace Netch.Controllers
return true;
}
private 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("Failed") || e.Data.Contains("Unable")) State = State.Stopped;
}
else if (State == State.Started)
{
if (e.Data.StartsWith("[APP][Bandwidth]"))
{
var splited = e.Data.Replace("[APP][Bandwidth]", "").Trim().Split(',');
if (splited.Length == 2)
{
var uploadSplited = splited[0].Split(':');
var downloadSplited = splited[1].Split(':');
if (uploadSplited.Length == 2 && downloadSplited.Length == 2)
if (long.TryParse(uploadSplited[1], out var upload) && long.TryParse(downloadSplited[1], out var download))
Task.Run(() => OnBandwidthUpdated(upload, download));
}
}
}
}
// private new 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("Failed") || e.Data.Contains("Unable")) State = State.Stopped;
// }
// else if (State == State.Started)
// {
// if (e.Data.StartsWith("[APP][Bandwidth]"))
// {
// var splited = e.Data.Replace("[APP][Bandwidth]", "").Trim().Split(',');
// if (splited.Length == 2)
// {
// var uploadSplited = splited[0].Split(':');
// var downloadSplited = splited[1].Split(':');
//
// if (uploadSplited.Length == 2 && downloadSplited.Length == 2)
// if (long.TryParse(uploadSplited[1], out var upload) && long.TryParse(downloadSplited[1], out var download))
// Task.Run(() => OnBandwidthUpdated(upload, download));
// }
// }
// }
// }
public override void Stop()
{

View File

@@ -8,7 +8,6 @@ using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Netch.Forms;
using Netch.Models;
using Netch.Properties;
using Netch.Utils;
@@ -35,14 +34,16 @@ namespace Netch.Controllers
public TUNTAPController()
{
MainFile = "tun2socks";
InitCheck();
Name = "Tap";
MainFile = "tun2socks.exe";
StartedKeywords("Running");
StoppedKeywords("failed","invalid vconfig file");
}
/// <summary>
/// 配置 TUNTAP 适配器
/// </summary>
public bool Configure()
private bool Configure()
{
// 查询服务器 IP 地址
var destination = Dns.GetHostAddressesAsync(_savedServer.Hostname);
@@ -60,7 +61,7 @@ namespace Netch.Controllers
/// <summary>
/// 设置绕行规则
/// </summary>
public bool SetupBypass()
private bool SetupBypass()
{
Global.MainForm.StatusText(i18N.Translate("SetupBypass"));
Logging.Info("设置绕行规则 → 设置让服务器 IP 走直连");
@@ -178,7 +179,7 @@ namespace Netch.Controllers
Logging.Info("设置绕行规则 → 处理自定义 DNS 代理");
if (Global.Settings.TUNTAP.UseCustomDNS)
{
var dns = "";
var dns = string.Empty;
foreach (var value in Global.Settings.TUNTAP.DNS)
{
dns += value;
@@ -252,7 +253,7 @@ namespace Netch.Controllers
{
if (Global.Settings.TUNTAP.UseCustomDNS)
{
var dns = "";
var dns = string.Empty;
foreach (var value in Global.Settings.TUNTAP.DNS)
{
dns += value;
@@ -308,8 +309,6 @@ namespace Netch.Controllers
public override bool Start(Server server, Mode mode)
{
if (!Ready) return false;
Global.MainForm.StatusText(i18N.Translate("Starting Tap"));
_savedMode = mode;
@@ -321,7 +320,7 @@ namespace Netch.Controllers
SetupBypass();
Logging.Info("设置绕行规则完毕");
Instance = GetProcess("bin\\tun2socks.exe");
Instance = GetProcess();
var adapterName = TUNTAP.GetName(Global.TUNTAP.ComponentID);
Logging.Info($"tun2sock使用适配器{adapterName}");
@@ -331,7 +330,7 @@ namespace Netch.Controllers
//if (Global.Settings.TUNTAP.UseCustomDNS || server.Type.Equals("VMess"))
if (Global.Settings.TUNTAP.UseCustomDNS)
{
dns = "";
dns = string.Empty;
foreach (var value in Global.Settings.TUNTAP.DNS)
{
dns += value;
@@ -389,17 +388,6 @@ namespace Netch.Controllers
pDNSController.Stop();
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!Write(e.Data)) return;
if (State == State.Starting)
{
if (e.Data.Contains("Running"))
State = State.Started;
else if (e.Data.Contains("failed") || e.Data.Contains("invalid vconfig file")) State = State.Stopped;
}
}
/// <summary>
/// 搜索出口
/// </summary>
@@ -431,7 +419,7 @@ namespace Netch.Controllers
// 通过索引查找对应适配器的 IPv4 地址
if (p.Index == Global.Adapter.Index)
{
var AdapterIPs = "";
var AdapterIPs = string.Empty;
foreach (var ip in adapterProperties.UnicastAddresses)
{

View File

@@ -11,8 +11,8 @@ namespace Netch.Controllers
public NTTController()
{
MainFile = "NTT";
InitCheck();
Name = "NTT";
MainFile = "NTT.exe";
}
/// <summary>
@@ -21,10 +21,9 @@ namespace Netch.Controllers
/// <returns></returns>
public (bool, string, string, string) Start()
{
if (!Ready) return (false, null, null, null);
try
{
Instance = GetProcess("bin\\NTT.exe");
Instance = GetProcess();
Instance.StartInfo.Arguments = $" {Global.Settings.STUN_Server} {Global.Settings.STUN_Server_Port}";
@@ -52,7 +51,7 @@ namespace Netch.Controllers
}
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
private new void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Data))
_lastResult = e.Data;

View File

@@ -9,15 +9,13 @@ namespace Netch.Controllers
{
public PrivoxyController()
{
MainFile = "Privoxy";
ExtFiles = new[] {"default.conf"};
InitCheck();
Name = "Privoxy";
MainFile = "Privoxy.exe";
RedirectStd = false;
}
public bool Start(Server server, Mode mode)
{
if (!Ready) return false;
var isSocks5 = server.Type == "Socks5";
var socks5Port = isSocks5 ? server.Port : Global.Settings.Socks5LocalPort;
var text = File.ReadAllText("bin\\default.conf")
@@ -28,7 +26,7 @@ namespace Netch.Controllers
text = text.Replace("/ 127.0.0.1", $"/ {server.Hostname}");
File.WriteAllText("data\\privoxy.conf", text);
Instance = GetProcess("bin\\Privoxy.exe", false);
Instance = GetProcess();
Instance.StartInfo.Arguments = "..\\data\\privoxy.conf";
Instance.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Instance.StartInfo.UseShellExecute = true;

View File

@@ -53,7 +53,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.ToString());
if (notifyNoFound) NewVersionFoundFailed?.Invoke(this, new EventArgs());
}
}

View File

@@ -279,7 +279,7 @@ namespace Netch.Forms
}
catch (Exception e)
{
MessageBox.Show(i18N.Translate("Error", e.Message));
MessageBoxX.Show(e.ToString(),info:false);
Console.WriteLine(e);
throw;
}

View File

@@ -200,7 +200,7 @@ namespace Netch.Forms
{
Task.Run(() =>
{
Logging.Info(ee.Message);
Logging.Info(ee.ToString());
ProfileButtons[index].Text = i18N.Translate("Error");
Thread.Sleep(1200);
ProfileButtons[index].Text = i18N.Translate("None");

View File

@@ -2,6 +2,7 @@
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Netch.Controllers;
using Netch.Forms;
using Netch.Utils;
@@ -57,6 +58,8 @@ namespace Netch
// 记录当前系统语言
Logging.Info($"当前语言:{Global.Settings.Language}");
Logging.Info($"版本:{UpdateChecker.Owner}/{UpdateChecker.Repo} {UpdateChecker.Version}");
Logging.Info($"主程序创建日期:{File.GetCreationTime(Global.NetchDir + "\\Netch.exe"):yyyy-M-d HH:mm}");
// 检查是否已经运行
if (!mutex.WaitOne(0, false))