private static bool ReleaseIsNewer(release data, Version curVersion) { if (data == null) { return(false); } var nextVersion = GetReleaseVersion(data); if (nextVersion.Count < 3) { return(false); } if (nextVersion[0] > curVersion.Major) { return(true); } if (nextVersion[0] == curVersion.Major) { if (nextVersion[1] > curVersion.Minor) { return(true); } if (nextVersion[1] == curVersion.Minor) { if (nextVersion[2] > curVersion.Build) { return(true); } } } return(false); }
private static List <int> GetReleaseVersion(release data) { List <int> ret = new List <int>(); if (data == null) { return(ret); } if (data.tag_name == null) { return(ret); } String[] parts = data.tag_name.ToLower().TrimStart('v').Split('.'); foreach (var i in parts) { if (!int.TryParse(i, out int j)) { break; } ret.Add(j); } return(ret); }
private static string GetReleaseDownloadUrl(release data, string assetName) { if (data == null) { return(null); } if (data.assets == null) { return(null); } foreach (var i in data.assets) { if (i.content_type == "application/x-msdownload") { if (i.name.StartsWith(assetName)) { return(i.browser_download_url); } } } return(null); }
/// <summary> /// Get next version download url if available /// </summary> /// <param name="author">Github author</param> /// <param name="repositoryName">Github repository name</param> /// <param name="curVersion">Current assembly version</param> /// <returns>Next release download url is available, else null</returns> public static string GetNextVersionDownloadUrl(string author, string repositoryName, Version curVersion) { string releaseStr = GetReleasesFromApi(author, repositoryName); List <release> list = DeserializeResponse <List <release> >(releaseStr); release max = GetMaxRelease(list); if (ReleaseIsNewer(max, curVersion)) { return(GetReleaseDownloadUrl(max, repositoryName)); } return(null); }
private static release GetMaxRelease(List <release> list) { if (list == null) { return(null); } release ret = null; foreach (var j in list) { if (ret == null) { ret = j; } else { var max = GetReleaseVersion(ret); var cur = GetReleaseVersion(j); for (int i = 0; (i < max.Count) && (i < cur.Count); i++) { if (cur[i] < max[i]) { break; } if (cur[i] > max[i]) { ret = j; break; } } } } return(ret); }