public IReleaseJson CheckForUpdate(string aCurrentVersion, EReleaseQuality aCurrentQuality, string aCurrentPlatform, string aCurrentPlatformVersion, EReleaseQuality aDesiredQuality) { // select all releases that // - are for this platform // - have a min platform version that is less than or equal to this platform version // - have a quality that matches the desired quality var releases = Json.Releases.Where(r => r.Platform == aCurrentPlatform) .Where(r => VersionSupport.ComparePartialVersions(aCurrentPlatformVersion, r.PlatformMinVersion) >= 0) .Where(r => (r.Quality() & aDesiredQuality) == r.Quality()); // select the release with the highest version for each release quality // - group by quality // - order releases in each group by ascending version // - select the last release in each group releases = releases.GroupBy(r => r.Quality()) .Select(g => g.OrderBy(r => r.Version, new VersionComparer()).Last()); // pick the release with the highest version number and the highest quality (priority to version number) var release = releases.OrderBy(r => r.Version, new VersionComparer()) .ThenBy(r => r.Quality()) .LastOrDefault(); if (release == null) { return(null); } // this version is a valid update if // - its version is greater than the current app version // - its version is the same as the current app version but its quality is greater than the current app quality // - its version is less than the current app version and the current app quality is not in the desired quality if (VersionSupport.ComparePartialVersions(release.Version, aCurrentVersion) > 0 || (VersionSupport.ComparePartialVersions(release.Version, aCurrentVersion) == 0 && release.Quality() > aCurrentQuality) || (VersionSupport.ComparePartialVersions(release.Version, aCurrentVersion) < 0 && (aCurrentQuality & aDesiredQuality) != aCurrentQuality)) { return(release); } return(null); }
public int Compare(string aVersionA, string aVersionB) { return VersionSupport.ComparePartialVersions(aVersionA, aVersionB); }