some improvements

pull/2148/head
2dust 2022-03-23 18:48:57 +08:00
parent dee5613f2f
commit b7a6004830
5 changed files with 28 additions and 17 deletions

View File

@ -21,7 +21,7 @@ namespace v2rayN.Handler
_config = config; _config = config;
} }
public SpeedtestHandler(ref Config config, ref V2rayHandler v2rayHandler, List<VmessItem> selecteds, string actionType, Action<string, string> update) public SpeedtestHandler(ref Config config, V2rayHandler v2rayHandler, List<VmessItem> selecteds, ESpeedActionType actionType, Action<string, string> update)
{ {
_config = config; _config = config;
_v2rayHandler = v2rayHandler; _v2rayHandler = v2rayHandler;
@ -40,19 +40,19 @@ namespace v2rayN.Handler
}); });
} }
if (actionType == "ping") if (actionType == ESpeedActionType.Ping)
{ {
Task.Run(() => RunPing()); Task.Run(() => RunPing());
} }
if (actionType == "tcping") else if (actionType == ESpeedActionType.Tcping)
{ {
Task.Run(() => RunTcping()); Task.Run(() => RunTcping());
} }
else if (actionType == "realping") else if (actionType == ESpeedActionType.Realping)
{ {
Task.Run(() => RunRealPing()); Task.Run(() => RunRealPing());
} }
else if (actionType == "speedtest") else if (actionType == ESpeedActionType.Speedtest)
{ {
Task.Run(() => RunSpeedTest()); Task.Run(() => RunSpeedTest());
} }

View File

@ -182,7 +182,7 @@ namespace v2rayN.Handler
string url = config.subItem[k - 1].url.TrimEx(); string url = config.subItem[k - 1].url.TrimEx();
string userAgent = config.subItem[k - 1].userAgent.TrimEx(); string userAgent = config.subItem[k - 1].userAgent.TrimEx();
string groupId = config.subItem[k - 1].groupId.TrimEx(); string groupId = config.subItem[k - 1].groupId.TrimEx();
string hashCode = $"{k}->"; string hashCode = $"{k}){config.subItem[k - 1].remarks}->";
if (config.subItem[k - 1].enabled == false) if (config.subItem[k - 1].enabled == false)
{ {
continue; continue;

View File

@ -21,7 +21,7 @@ namespace v2rayN.Handler
class V2rayHandler class V2rayHandler
{ {
private static string v2rayConfigRes = Global.v2rayConfigFileName; private static string v2rayConfigRes = Global.v2rayConfigFileName;
private List<string> lstV2ray; private List<string> lstCore;
private string coreUrl; private string coreUrl;
private string coreArguments; private string coreArguments;
public event ProcessDelegate ProcessEvent; public event ProcessDelegate ProcessEvent;
@ -106,7 +106,7 @@ namespace v2rayN.Handler
} }
else else
{ {
foreach (string vName in lstV2ray) foreach (string vName in lstCore)
{ {
Process[] existing = Process.GetProcessesByName(vName); Process[] existing = Process.GetProcessesByName(vName);
foreach (Process p in existing) foreach (Process p in existing)
@ -163,12 +163,10 @@ namespace v2rayN.Handler
} }
} }
private string V2rayFindexe() private string V2rayFindexe(List<string> lstCoreTemp)
{ {
//查找v2ray文件是否存在
string fileName = string.Empty; string fileName = string.Empty;
//lstV2ray.Reverse(); foreach (string name in lstCoreTemp)
foreach (string name in lstV2ray)
{ {
string vName = string.Format("{0}.exe", name); string vName = string.Format("{0}.exe", name);
vName = Utils.GetPath(vName); vName = Utils.GetPath(vName);
@ -195,7 +193,7 @@ namespace v2rayN.Handler
try try
{ {
string fileName = V2rayFindexe(); string fileName = V2rayFindexe(lstCore);
if (fileName == "") return; if (fileName == "") return;
Process p = new Process Process p = new Process
@ -249,7 +247,8 @@ namespace v2rayN.Handler
try try
{ {
string fileName = V2rayFindexe(); coreUrl = Global.xrayCoreUrl;
string fileName = V2rayFindexe(new List<string> { "xray" });
if (fileName == "") return -1; if (fileName == "") return -1;
Process p = new Process Process p = new Process
@ -336,7 +335,7 @@ namespace v2rayN.Handler
if (coreType == ECoreType.v2fly) if (coreType == ECoreType.v2fly)
{ {
lstV2ray = new List<string> lstCore = new List<string>
{ {
"wv2ray", "wv2ray",
"v2ray" "v2ray"
@ -346,7 +345,7 @@ namespace v2rayN.Handler
} }
else if (coreType == ECoreType.Xray) else if (coreType == ECoreType.Xray)
{ {
lstV2ray = new List<string> lstCore = new List<string>
{ {
"xray" "xray"
}; };
@ -355,7 +354,7 @@ namespace v2rayN.Handler
} }
else if (coreType == ECoreType.clash) else if (coreType == ECoreType.clash)
{ {
lstV2ray = new List<string> lstCore = new List<string>
{ {
"clash-windows-amd64", "clash-windows-amd64",
"clash-windows-386", "clash-windows-386",

View File

@ -0,0 +1,11 @@

namespace v2rayN.Mode
{
public enum ESpeedActionType
{
Ping,
Tcping,
Realping,
Speedtest
}
}

View File

@ -199,6 +199,7 @@
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Handler\SysProxyHandle.cs" /> <Compile Include="Handler\SysProxyHandle.cs" />
<Compile Include="Mode\ESpeedActionType.cs" />
<Compile Include="Mode\EGlobalHotkey.cs" /> <Compile Include="Mode\EGlobalHotkey.cs" />
<Compile Include="Mode\ECoreType.cs" /> <Compile Include="Mode\ECoreType.cs" />
<Compile Include="Mode\ESysProxyType.cs" /> <Compile Include="Mode\ESysProxyType.cs" />