public void V2RayVersionComparationTest() { var version1 = new V2RayVersion(1, 0, 0); var version2 = new V2RayVersion(1, 1, 0); var version3 = new V2RayVersion(2, 0, 0); var version4 = new V2RayVersion(1, 0, 0); Assert.IsTrue(version1 >= version4); Assert.IsTrue(version4 <= version1); Assert.IsTrue(version2 > version1); Assert.IsTrue(version2 >= version1); Assert.IsTrue(version3 > version1); Assert.IsTrue(version3 >= version1); Assert.IsTrue(version1 < version2); Assert.IsTrue(version1 <= version2); Assert.IsTrue(version1 < version3); Assert.IsTrue(version1 <= version3); Assert.IsTrue(version3 > version2); Assert.IsTrue(version3 >= version2); Assert.IsTrue(version2 < version3); Assert.IsTrue(version2 <= version3); }
public V2RayVersion GetLatestV2RayVersion(string releaseInfo) { var json = JsonConvert.DeserializeObject <Dictionary <string, object> >(releaseInfo); var versionTag = json["tag_name"].ToString(); var regex = new Regex(@"^v(\d+).(\d+?)(?:.(\d+))?$"); var match = regex.Match(versionTag); try { if (!match.Success) { throw new Exception(); } var version = new V2RayVersion { Major = Convert.ToInt32(match.Groups[1].ToString()), Minor = Convert.ToInt32(match.Groups[2].ToString()), Build = Convert.ToInt32(string.IsNullOrWhiteSpace(match.Groups[3].ToString()) ? "0" : match.Groups[3].ToString()), }; return(version); } catch { Logging.Error("Cannot get latest v2ray version from GitHub, \r\n" + $" CONTENT: {releaseInfo}\r\n" + $" TAG: {versionTag}", "v2ray-updator"); return(null); } }
public V2RayVersion GetV2RayVersion() { var process = new Process(); process.StartInfo.FileName = executablePath; process.StartInfo.Arguments = "-version"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.CreateNoWindow = true; var stdout = string.Empty; process.OutputDataReceived += (s, e) => stdout += e.Data; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(3000); if (!process.HasExited) { process.Kill(); } var regex = new Regex(@"^V2Ray\sv(\d+).(\d+)(?:.(\d+))?\s"); var match = regex.Match(stdout); try { if (!match.Success) { throw new Exception(); } var version = new V2RayVersion { Major = Convert.ToInt32(match.Groups[1].ToString()), Minor = Convert.ToInt32(match.Groups[2].ToString()), Build = Convert.ToInt32(string.IsNullOrWhiteSpace(match.Groups[3].ToString()) ? "0" : match.Groups[3].ToString()), }; return(version); } catch { Logging.Error("Cannot dectect v2ray-core version, \r\n" + $" Command: {executablePath} -version\r\n" + $" Output: {stdout}", "v2ray-updator"); return(null); } }
public V2RayManager(V2RayVersion minimumRequriedVersion) { MinimumRequriedVersion = minimumRequriedVersion; }