Пример #1
0
 protected IEnumerable <CfanJson> yieldCfanJsons(IUser user, ModJson modJson)
 {
     foreach (ModReleaseJson modReleaseJson in modJson.releases)
     {
         foreach (ModReleaseJson.ModReleaseJsonFile modReleaseJsonFile in modReleaseJson.files)
         {
             string url = checkUrl(user, modReleaseJsonFile.mirror, $"mod: {modJson.name}");
             if (string.IsNullOrEmpty(url))
             {
                 url = checkUrl(user, modReleaseJsonFile.url, $"mod: {modJson.name}");
             }
             if (string.IsNullOrEmpty(url))
             {
                 user.RaiseError($"Mod {modJson.name} does not have download url, omitting");
                 continue;
             }
             string expectedFilename = modJson.name + "_" + modReleaseJson.version + ".zip";
             string downloadedFilePath;
             try
             {
                 downloadedFilePath = fmmManager.getCachedOrDownloadFile(user, url, expectedFilename);
             }
             catch (NetfanDownloadKraken e)
             {
                 user.RaiseError($"Couldn't download {modJson.name}: {e.Message}");
                 continue;
             }
             catch (Exception e)
             {
                 user.RaiseError($"Couldn't handle {modJson.name}: {e.Message}");
                 continue;
             }
             yield return(fmmManager.generateCfanFromZipFile(user, downloadedFilePath, new Dictionary <string, string>
             {
                 ["x-source"] = typeof(FactorioModsComAggregator).Name,
                 ["fmm-id"] = modJson.id.ToString()
             }));
         }
     }
 }
Пример #2
0
        public IEnumerable <CfanJson> getAllCfanJsons(IUser user)
        {
            var client = new GitHubClient(new ProductHeaderValue("CFAN", CKAN.Meta.ReleaseNumber()?.ToString()));

            if (!string.IsNullOrEmpty(accessToken))
            {
                client.Credentials = new Credentials(accessToken);
            }
            string[] allRepos = githubRepositoriesDataProvider.GithubRepositories;
            foreach (var repo in allRepos.Select(p => p.Split('/')).Select(p => new { owner = p[0], name = p[1] }))
            {
                IReadOnlyList <Release> releases;
                try
                {
                    releases = client.Repository.Release.GetAll(repo.owner, repo.name).Result;
                }
                catch (Exception e)
                {
                    user.RaiseError($"Couldn't fetch releases for {repo.owner}/{repo.name}: {e.Message}");
                    continue;
                }
                int count = 0;
                foreach (Release release in releases)
                {
                    if (count > 0 && repo.name != "DyTech")
                    {
                        // return only newest one to speed up things
                        // DyTech has different mods in different releases, so exclude it from this shortcut
                        break;
                    }
                    if (!release.Assets.Any())
                    {
                        user.RaiseError($"No assets for {repo.owner}/{repo.name}:{release.TagName}");
                        continue;
                    }
                    if (release.Assets.Count > 1)
                    {
                        user.RaiseError($"Unexpected {release.Assets.Count} assets for {repo.owner}/{repo.name}:{release.TagName}");
                        continue;
                    }
                    ReleaseAsset asset = release.Assets[0];
                    string       downloadedFilePath;
                    try
                    {
                        downloadedFilePath = modDirectoryManager.getCachedOrDownloadFile(user, asset.BrowserDownloadUrl,
                                                                                         $"{repo.name}-{release.TagName}");
                    }
                    catch (NetfanNormalizerKraken e)
                    {
                        user.RaiseError($"Couldn't normalize asset {repo.owner}/{repo.name}:{release.TagName}: {e.Message}");
                        continue;
                    }
                    catch (NetfanDownloadKraken e)
                    {
                        user.RaiseError($"Couldn't download {repo.owner}/{repo.name}:{release.TagName}: {e.Message}");
                        continue;
                    }
                    count++;
                    yield return(modDirectoryManager.generateCfanFromZipFile(user, downloadedFilePath, new Dictionary <string, string>
                    {
                        ["x-source"] = typeof(FactorioModsComAggregator).Name,
                        ["github-repo"] = $"{repo.owner}/{repo.name}"
                    }));
                }
            }
        }