예제 #1
0
        private async Task <bool> RunGithubJob(GithubProvider provider, Mod mod)
        {
            var mcVersion     = string.IsNullOrWhiteSpace(mod.OverrideMinecraftVersion) ? _settings.Minecraft.Version : mod.OverrideMinecraftVersion;
            var latestRelease = await _githubClient.IsLatestRelease(mod.CurrentVersion, mcVersion, provider);

            if (!latestRelease.UpToDate)
            {
                Log.Information("Downloading update for {ModName} {CurrentVersion} -> {LatestVersion}", mod.Name, mod.CurrentVersion, latestRelease.Version);
                var downloadResult = await _githubClient.DownloadLatestRelease(latestRelease.Asset);

                if (downloadResult.Success)
                {
                    mod.Filename       = downloadResult.FileName;
                    mod.CurrentVersion = latestRelease.Version;
                }
            }
            return(!latestRelease.UpToDate);
        }
예제 #2
0
        private (bool UpToDate, string Version, Asset Asset) FindLatestVersionFromAssetNames(string currentVersion, GithubProvider provider, GithubRelease latestRelease, string minecraftVersion)
        {
            if (string.IsNullOrWhiteSpace(currentVersion))
            {
                currentVersion = "0";
            }

            var currentMcSemvar = SemVersion.Parse(minecraftVersion);
            var currentSemvar   = SemVersion.Parse(currentVersion);
            var releases        = new List <SemVersion>();
            var allAssets       = latestRelease.Assets.Where(x => Regex.IsMatch(x.Name, provider.AssetRegex));
            var assetsMatchingMinecraftVersion = ExtractSemVersionFromAssetNames(allAssets, provider.MinecraftVersionRegex).Where(x => x.Value == currentMcSemvar);
            var assets             = ExtractSemVersionFromAssetNames(assetsMatchingMinecraftVersion.Select(x => x.Key), provider.ModVersionRegex);
            var latestReleaseAsset = GetLatestRelease(assets);

            return(currentSemvar >= latestReleaseAsset.Version, latestReleaseAsset.Version?.ToString(), latestReleaseAsset.Asset);
        }
예제 #3
0
        public async Task <(bool UpToDate, string Version, Asset Asset)> IsLatestRelease(string currentVersion, string minecraftVersion, GithubProvider provider)
        {
            // Cache the response to avoid as many requests as possible to keep from hitting Rate limit.
            var latestRelease = await _cache.GetOrAddAsync($"release{provider.Author}{provider.Repository}", () => GetLatestRelease(provider.Author, provider.Repository), DateTimeOffset.Now.AddMinutes(5));

            var latestVersion   = latestRelease.TagName;
            var isLatestVersion = latestRelease.TagName == currentVersion;
            var latestAsset     = latestRelease.Assets.Where(x => Regex.IsMatch(x.Name, provider.AssetRegex)).FirstOrDefault();

            if (!provider.UseReleaseTagAsVersion)
            {
                (isLatestVersion, latestVersion, latestAsset) = FindLatestVersionFromAssetNames(currentVersion, provider, latestRelease, minecraftVersion);
            }

            return(isLatestVersion, latestVersion, latestAsset);
        }