static void BuildDependencyTree(List<string> dependencies, KeyValuePair<string, SixRepoModDto> repoContent, CustomRepo[] customRepos, IReadOnlyCollection<NetworkContent> content) { var name = repoContent.Key.ToLower(); if (dependencies.Contains(name)) return; dependencies.Add(name); if (repoContent.Value.Dependencies == null) return; foreach (var d in repoContent.Value.Dependencies) { var n = d.ToLower(); var repo = customRepos.FirstOrDefault(r => r.HasMod(d)); if (repo == null) { var nc = content.FirstOrDefault(x => x.PackageName.Equals(d, StringComparison.InvariantCultureIgnoreCase)); if (nc != null) { var deps = nc.GetRelatedContent() .Select(x => x.Content) .OfType<IHavePackageName>() .Select(x => x.PackageName) .Where(x => !dependencies.ContainsIgnoreCase(x)) .ToArray(); // TODO: this does not take care of dependencies that actually exist then on the custom repo, and might have different deps setup than the official network counter parts.. // But the use case is very limited.. dependencies.AddRange(deps); } else dependencies.Add(n); } else BuildDependencyTree(dependencies, repo.GetMod(d), customRepos, content); } dependencies.Remove(name); dependencies.Add(name); }
static Content ConvertToRepoContent(CollectionVersionDependencyModel x, Collection col, CustomRepo[] customRepos, IReadOnlyCollection<NetworkContent> content) { var repo = customRepos.FirstOrDefault(r => r.HasMod(x.Dependency)); if (repo == null) return null; var repoContent = repo.GetMod(x.Dependency); var mod = new ModRepoContent(x.Dependency, x.Dependency, col.GameId, repoContent.Value.ModVersion); if (repoContent.Value.Dependencies != null) mod.Dependencies = GetDependencyTree(repoContent, customRepos, content); return mod; }
static List<string> GetDependencyTree(KeyValuePair<string, SixRepoModDto> repoContent, CustomRepo[] customRepos, IReadOnlyCollection<NetworkContent> content) { var dependencies = new List<string>(); var name = repoContent.Key.ToLower(); // TODO: Would be better to build the dependency tree from actual objects instead of strings?? BuildDependencyTree(dependencies, repoContent, customRepos, content); dependencies.Remove(name); // we dont want ourselves to be a dep of ourselves return dependencies; }
static void HandleContent(IReadOnlyCollection<NetworkContent> content, Collection col, CollectionModelWithLatestVersion c, CustomRepo[] customRepos) { col.Contents.Replace( c.LatestVersion .Dependencies .Select( x => new { Content = ConvertToRepoContent(x, col, customRepos, content) ?? ConvertToContentOrLocal(x, col, content), // temporary x.Constraint }) .Where(x => x.Content != null) .Select(x => new ContentSpec(x.Content, x.Constraint)) .ToList()); }