diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 5ec3cdc4..2d8b22d3 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -1392,15 +1392,15 @@ namespace v2rayN.Forms private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { - CheckUpdateCore("v2fly"); + CheckUpdateCore(ECoreType.v2fly); } private void tsbCheckUpdateXrayCore_Click(object sender, EventArgs e) { - CheckUpdateCore("xray"); + CheckUpdateCore(ECoreType.Xray); } - private void CheckUpdateCore(string type) + private void CheckUpdateCore(ECoreType type) { void _updateUI(bool success, string msg) { diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs index d1be5442..9303a1af 100644 --- a/v2rayN/v2rayN/Handler/LazyConfig.cs +++ b/v2rayN/v2rayN/Handler/LazyConfig.cs @@ -9,6 +9,7 @@ namespace v2rayN.Handler { private static readonly Lazy<LazyConfig> _instance = new Lazy<LazyConfig>(() => new LazyConfig()); private Config _config; + private List<CoreInfo> coreInfos; public static LazyConfig Instance { @@ -51,5 +52,45 @@ namespace v2rayN.Handler } return item.coreType; } + + public CoreInfo GetCoreInfo(ECoreType coreType) + { + if (coreInfos == null) + { + InitCoreInfo(); + } + return coreInfos.Where(t => t.coreType == coreType).FirstOrDefault(); + } + + private void InitCoreInfo() + { + coreInfos = new List<CoreInfo>(); + + coreInfos.Add(new CoreInfo + { + coreType = ECoreType.v2fly, + coreExes = new List<string> { "wv2ray", "v2ray" }, + arguments = "", + coreUrl = Global.v2flyCoreUrl + + }); + + coreInfos.Add(new CoreInfo + { + coreType = ECoreType.Xray, + coreExes = new List<string> { "xray" }, + arguments = "", + coreUrl = Global.xrayCoreUrl + }); + + coreInfos.Add(new CoreInfo + { + coreType = ECoreType.clash, + coreExes = new List<string> { "clash-windows-amd64", "clash-windows-386", "clash" }, + arguments = "-f config.json", + coreUrl = Global.clashCoreUrl + }); + } + } } diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs index 62c795f4..1ab00e3b 100644 --- a/v2rayN/v2rayN/Handler/UpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs @@ -104,11 +104,11 @@ namespace v2rayN.Handler } }; _updateFunc(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN")); - CheckUpdateAsync("v2rayN"); + CheckUpdateAsync(ECoreType.v2rayN); } - public void CheckUpdateCore(string type, Config config, Action<bool, string> update) + public void CheckUpdateCore(ECoreType type, Config config, Action<bool, string> update) { _config = config; _updateFunc = update; @@ -292,7 +292,7 @@ namespace v2rayN.Handler #region private - private async void CheckUpdateAsync(string type) + private async void CheckUpdateAsync(ECoreType type) { try { @@ -310,15 +310,15 @@ namespace v2rayN.Handler HttpClient httpClient = new HttpClient(webRequestHandler); string url; - if (type == "v2fly") + if (type == ECoreType.v2fly) { url = v2flyCoreLatestUrl; } - else if (type == "xray") + else if (type == ECoreType.Xray) { url = xrayCoreLatestUrl; } - else if (type == "v2rayN") + else if (type == ECoreType.v2rayN) { url = nLatestUrl; } @@ -347,18 +347,18 @@ namespace v2rayN.Handler /// <summary> /// 获取V2RayCore版本 /// </summary> - private string getCoreVersion(string type) + private string getCoreVersion(ECoreType type) { try { var core = string.Empty; var match = string.Empty; - if (type == "v2fly") + if (type == ECoreType.v2fly) { core = "v2ray.exe"; match = "V2Ray"; } - else if (type == "xray") + else if (type == ECoreType.Xray) { core = "xray.exe"; match = "Xray"; @@ -392,7 +392,7 @@ namespace v2rayN.Handler return ""; } } - private void responseHandler(string type, string redirectUrl) + private void responseHandler(ECoreType type, string redirectUrl) { try { @@ -401,21 +401,21 @@ namespace v2rayN.Handler string curVersion; string message; string url; - if (type == "v2fly") + if (type == ECoreType.v2fly) { curVersion = "v" + getCoreVersion(type); message = string.Format(UIRes.I18N("IsLatestCore"), curVersion); string osBit = Environment.Is64BitProcess ? "64" : "32"; url = string.Format(v2flyCoreUrl, version, osBit); } - else if (type == "xray") + else if (type == ECoreType.Xray) { curVersion = "v" + getCoreVersion(type); message = string.Format(UIRes.I18N("IsLatestCore"), curVersion); string osBit = Environment.Is64BitProcess ? "64" : "32"; url = string.Format(xrayCoreUrl, version, osBit); } - else if (type == "v2rayN") + else if (type == ECoreType.v2rayN) { curVersion = FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString(); message = string.Format(UIRes.I18N("IsLatestN"), curVersion); diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 16762304..24887606 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -168,6 +168,7 @@ namespace v2rayN.Handler inbound2.protocol = Global.InboundHttp; inbound2.listen = inbound.listen; inbound2.settings.allowTransparent = false; + inbound2.sniffing.enabled = inbound.sniffing.enabled; } catch { diff --git a/v2rayN/v2rayN/Handler/V2rayHandler.cs b/v2rayN/v2rayN/Handler/V2rayHandler.cs index bb4e4435..e6796d34 100644 --- a/v2rayN/v2rayN/Handler/V2rayHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayHandler.cs @@ -21,9 +21,7 @@ namespace v2rayN.Handler class V2rayHandler { private static string v2rayConfigRes = Global.v2rayConfigFileName; - private List<string> lstCore; - private string coreUrl; - private string coreArguments; + private CoreInfo coreInfo; public event ProcessDelegate ProcessEvent; //private int processId = 0; private Process _process; @@ -46,7 +44,11 @@ namespace v2rayN.Handler return; } - SetCore(config, item); + if (SetCore(config, item) != 0) + { + ShowMsg(false, UIRes.I18N("CheckServerSettings")); + return; + } string fileName = Utils.GetPath(v2rayConfigRes); if (V2rayConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0) { @@ -106,7 +108,7 @@ namespace v2rayN.Handler } else { - foreach (string vName in lstCore) + foreach (string vName in coreInfo.coreExes) { Process[] existing = Process.GetProcessesByName(vName); foreach (Process p in existing) @@ -178,7 +180,7 @@ namespace v2rayN.Handler } if (Utils.IsNullOrEmpty(fileName)) { - string msg = string.Format(UIRes.I18N("NotFoundCore"), coreUrl); + string msg = string.Format(UIRes.I18N("NotFoundCore"), coreInfo.coreUrl); ShowMsg(false, msg); } return fileName; @@ -193,7 +195,7 @@ namespace v2rayN.Handler try { - string fileName = V2rayFindexe(lstCore); + string fileName = V2rayFindexe(coreInfo.coreExes); if (fileName == "") return; Process p = new Process @@ -201,7 +203,7 @@ namespace v2rayN.Handler StartInfo = new ProcessStartInfo { FileName = fileName, - Arguments = coreArguments, + Arguments = coreInfo.arguments, WorkingDirectory = Utils.StartupPath(), UseShellExecute = false, RedirectStandardOutput = true, @@ -247,7 +249,6 @@ namespace v2rayN.Handler try { - coreUrl = Global.xrayCoreUrl; string fileName = V2rayFindexe(new List<string> { "xray" }); if (fileName == "") return -1; @@ -325,44 +326,21 @@ namespace v2rayN.Handler } } - private void SetCore(Config config, VmessItem item) + private int SetCore(Config config, VmessItem item) { if (item == null) { - return; + return -1; } var coreType = LazyConfig.Instance.GetCoreType(item, item.configType); - if (coreType == ECoreType.v2fly) + coreInfo = LazyConfig.Instance.GetCoreInfo(coreType); + + if (coreInfo == null) { - lstCore = new List<string> - { - "wv2ray", - "v2ray" - }; - coreUrl = Global.v2flyCoreUrl; - coreArguments = string.Empty; - } - else if (coreType == ECoreType.Xray) - { - lstCore = new List<string> - { - "xray" - }; - coreUrl = Global.xrayCoreUrl; - coreArguments = string.Empty; - } - else if (coreType == ECoreType.clash) - { - lstCore = new List<string> - { - "clash-windows-amd64", - "clash-windows-386", - "clash" - }; - coreUrl = Global.clashCoreUrl; - coreArguments = "-f config.json"; + return -1; } + return 0; } } } diff --git a/v2rayN/v2rayN/Mode/CoreInfo.cs b/v2rayN/v2rayN/Mode/CoreInfo.cs new file mode 100644 index 00000000..2d66b121 --- /dev/null +++ b/v2rayN/v2rayN/Mode/CoreInfo.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace v2rayN.Mode +{ + [Serializable] + public class CoreInfo + { + public ECoreType coreType { get; set; } + + public List<string> coreExes { get; set; } + + public string arguments { get; set; } + + public string coreUrl { get; set; } + } +} diff --git a/v2rayN/v2rayN/Mode/ECoreType.cs b/v2rayN/v2rayN/Mode/ECoreType.cs index 390f008f..2448c96d 100644 --- a/v2rayN/v2rayN/Mode/ECoreType.cs +++ b/v2rayN/v2rayN/Mode/ECoreType.cs @@ -5,6 +5,7 @@ namespace v2rayN.Mode { v2fly = 1, Xray = 2, - clash = 3 + clash = 3, + v2rayN = 99 } } diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index a6623b5d..5499ccd2 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -208,6 +208,7 @@ <Compile Include="Mode\RoutingItem.cs" /> <Compile Include="Mode\RulesItem.cs" /> <Compile Include="Mode\ServerStatistics.cs" /> + <Compile Include="Mode\CoreInfo.cs" /> <Compile Include="Mode\SysproxyConfig.cs" /> <Compile Include="Mode\EConfigType.cs" /> <Compile Include="Mode\ServerTestItem.cs" />