From 9a8b4593e1e668106a36f27ca08231121d16f90a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 30 Jul 2022 20:12:14 +0800 Subject: [PATCH] Fix some issues with update core --- v2rayN/v2rayN/Forms/AddServerForm.cs | 2 +- v2rayN/v2rayN/Handler/ConfigHandler.cs | 2 +- v2rayN/v2rayN/Handler/LazyConfig.cs | 28 +++++++++++++-------- v2rayN/v2rayN/Handler/UpdateHandle.cs | 18 ++++++++++--- v2rayN/v2rayN/Handler/V2rayConfigHandler.cs | 2 +- v2rayN/v2rayN/Mode/CoreInfo.cs | 2 ++ 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/v2rayN/v2rayN/Forms/AddServerForm.cs b/v2rayN/v2rayN/Forms/AddServerForm.cs index 80458e83..c0f4459f 100644 --- a/v2rayN/v2rayN/Forms/AddServerForm.cs +++ b/v2rayN/v2rayN/Forms/AddServerForm.cs @@ -35,7 +35,7 @@ namespace v2rayN.Forms //panTran.Visible = false; //this.Height = this.Height - panTran.Height; - cmbSecurity3.Items.AddRange(LazyConfig.Instance.GetShadowsocksSecuritys().ToArray()); + cmbSecurity3.Items.AddRange(LazyConfig.Instance.GetShadowsocksSecuritys(vmessItem).ToArray()); break; case EConfigType.Socks: panSocks.Dock = DockStyle.Fill; diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 99585d3f..9b0f1d55 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -529,7 +529,7 @@ namespace v2rayN.Handler vmessItem.id = vmessItem.id.TrimEx(); vmessItem.security = vmessItem.security.TrimEx(); - if (!LazyConfig.Instance.GetShadowsocksSecuritys().Contains(vmessItem.security)) + if (!LazyConfig.Instance.GetShadowsocksSecuritys(vmessItem).Contains(vmessItem.security)) { return -1; } diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs index d907ec3b..890123cd 100644 --- a/v2rayN/v2rayN/Handler/LazyConfig.cs +++ b/v2rayN/v2rayN/Handler/LazyConfig.cs @@ -22,18 +22,18 @@ namespace v2rayN.Handler return _config; } - public List GetShadowsocksSecuritys() + public List GetShadowsocksSecuritys(VmessItem vmessItem) { - if (GetCoreType(null, EConfigType.Shadowsocks) == ECoreType.v2fly) + if (GetCoreType(vmessItem, EConfigType.Shadowsocks) == ECoreType.v2fly) { return Global.ssSecuritys; } - if (GetCoreType(null, EConfigType.Shadowsocks) == ECoreType.SagerNet) + if (GetCoreType(vmessItem, EConfigType.Shadowsocks) == ECoreType.Xray) { - return Global.ssSecuritysInSagerNet; - } + return Global.ssSecuritysInXray; + } - return Global.ssSecuritysInXray; + return Global.ssSecuritysInSagerNet; } public ECoreType GetCoreType(VmessItem vmessItem, EConfigType eConfigType) @@ -86,7 +86,8 @@ namespace v2rayN.Handler coreLatestUrl = Global.v2flyCoreUrl + "/latest", coreDownloadUrl32 = Global.v2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip", coreDownloadUrl64 = Global.v2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip", - match = "V2Ray" + match = "V2Ray", + versionArg = "-version" }); coreInfos.Add(new CoreInfo @@ -98,7 +99,8 @@ namespace v2rayN.Handler coreLatestUrl = Global.SagerNetCoreUrl + "/latest", coreDownloadUrl32 = Global.SagerNetCoreUrl + "/download/{0}/v2ray-windows-{1}.zip", coreDownloadUrl64 = Global.SagerNetCoreUrl + "/download/{0}/v2ray-windows-{1}.zip", - match = "V2Ray" + match = "V2Ray", + versionArg = "version" }); coreInfos.Add(new CoreInfo @@ -110,7 +112,8 @@ namespace v2rayN.Handler coreLatestUrl = Global.xrayCoreUrl + "/latest", coreDownloadUrl32 = Global.xrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip", coreDownloadUrl64 = Global.xrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip", - match = "Xray" + match = "Xray", + versionArg = "-version" }); coreInfos.Add(new CoreInfo @@ -122,18 +125,21 @@ namespace v2rayN.Handler coreLatestUrl = Global.clashCoreUrl + "/latest", coreDownloadUrl32 = Global.clashCoreUrl + "/download/{0}/clash-windows-386-{0}.zip", coreDownloadUrl64 = Global.clashCoreUrl + "/download/{0}/clash-windows-amd64-{0}.zip", - match = "v" + match = "v", + versionArg = "-v" }); coreInfos.Add(new CoreInfo { coreType = ECoreType.clash_meta, - coreExes = new List { "Clash.Meta-windows-amd64v1", "Clash.Meta-windows-amd64", "Clash.Meta-windows-amd64-compatible", "Clash.Meta-windows-386", "Clash.Meta", "clash" }, + coreExes = new List { "Clash.Meta-windows-amd64-compatible", "Clash.Meta-windows-amd64", "Clash.Meta-windows-386", "Clash.Meta", "clash" }, arguments = "-f config.json", coreUrl = Global.clashMetaCoreUrl, coreLatestUrl = Global.clashMetaCoreUrl + "/latest", coreDownloadUrl32 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-386-{0}.zip", coreDownloadUrl64 = Global.clashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-amd64-compatible-{0}.zip", + match = "v", + versionArg = "-v" }); coreInfos.Add(new CoreInfo diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs index 8a86892e..cf430a01 100644 --- a/v2rayN/v2rayN/Handler/UpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs @@ -360,7 +360,7 @@ namespace v2rayN.Handler Process p = new Process(); p.StartInfo.FileName = filePath; - p.StartInfo.Arguments = "-version"; + p.StartInfo.Arguments = coreInfo.versionArg; p.StartInfo.WorkingDirectory = Utils.StartupPath(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; @@ -369,7 +369,19 @@ namespace v2rayN.Handler p.Start(); p.WaitForExit(5000); string echo = p.StandardOutput.ReadToEnd(); - string version = Regex.Match(echo, $"{coreInfo.match} ([0-9.]+) \\(").Groups[1].Value; + string version = string.Empty; + switch (type) + { + case ECoreType.v2fly: + case ECoreType.SagerNet: + case ECoreType.Xray: + version = Regex.Match(echo, $"{coreInfo.match} ([0-9.]+) \\(").Groups[1].Value; + break; + case ECoreType.clash: + case ECoreType.clash_meta: + version = Regex.Match(echo, $"v[0-9.]+").Groups[0].Value; + break; + } return version; } catch (Exception ex) @@ -404,7 +416,7 @@ namespace v2rayN.Handler case ECoreType.clash: case ECoreType.clash_meta: { - curVersion = "";//getCoreVersion(type); + curVersion = getCoreVersion(type); message = string.Format(ResUI.IsLatestCore, curVersion); if (Environment.Is64BitProcess) { diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 8596b9a2..bd89f191 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -411,7 +411,7 @@ namespace v2rayN.Handler serversItem.address = node.address; serversItem.port = node.port; serversItem.password = node.id; - serversItem.method = LazyConfig.Instance.GetShadowsocksSecuritys().Contains(node.security) ? node.security : "none"; + serversItem.method = LazyConfig.Instance.GetShadowsocksSecuritys(node).Contains(node.security) ? node.security : "none"; serversItem.ota = false; diff --git a/v2rayN/v2rayN/Mode/CoreInfo.cs b/v2rayN/v2rayN/Mode/CoreInfo.cs index 4afc1c22..c47bc709 100644 --- a/v2rayN/v2rayN/Mode/CoreInfo.cs +++ b/v2rayN/v2rayN/Mode/CoreInfo.cs @@ -21,5 +21,7 @@ namespace v2rayN.Mode public string coreDownloadUrl64 { get; set; } public string match { get; set; } + public string versionArg { get; set; } + } }