Skip to content

Commit

Permalink
Merge #4178 Inflation error for multi-hosted mods with mismatched ver…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
HebaruSan committed Sep 8, 2024
2 parents bc7b390 + e1d251f commit 3992aa0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ All notable changes to this project will be documented in this file.
- [CLI] Ability to update repos without a game instance (#4161 by: HebaruSan)
- [Multiple] Nullable references, net8.0, blend registry alert dot, netkan fixes (#4171, #4176 by: HebaruSan)
- [Netkan] SourceForge kref (#4172, #4174 by: HebaruSan)
- [Netkan] Inflation error for multi-hosted mods with mismatched versions (#4178 by: HebaruSan)

## v1.34.4 (Niven)

Expand Down
12 changes: 12 additions & 0 deletions Netkan/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ internal sealed class Metadata
public bool Staged { get; private set; }
public string? StagingReason { get; private set; }

public string[] Hosts
=> (_json.TryGetValue(DownloadPropertyName, out JToken? downloadToken)
? downloadToken.Type == JTokenType.String
&& (string?)downloadToken is string url
? Enumerable.Repeat(url, 1)
: downloadToken.Children()
.Select(ch => (string?)ch)
.OfType<string>()
: Enumerable.Empty<string>())
.Select(u => new Uri(u).Host)
.ToArray();

public Metadata(JObject? json)
{
if (json == null)
Expand Down
24 changes: 17 additions & 7 deletions Netkan/Processors/Inflator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ internal IEnumerable<Metadata> Inflate(string filename, Metadata[] netkans, Tran
}
log.Debug("Input successfully passed pre-validation");

var ckans = netkans
.SelectMany(netkan => transformer.Transform(netkan, opts))
.GroupBy(module => module.Version)
.Select(grp => Metadata.Merge(grp.ToArray()))
.SelectMany(merged => specVersionTransformer.Transform(merged, opts))
.SelectMany(withSpecVersion => sortTransformer.Transform(withSpecVersion, opts))
.ToList();
var ckans = netkans.SelectMany(netkan => transformer.Transform(netkan, opts))
.GroupBy(module => module.Version)
.Select(grp => Metadata.Merge(grp.ToArray()))
.SelectMany(merged => specVersionTransformer.Transform(merged, opts))
.SelectMany(withSpecVersion => sortTransformer.Transform(withSpecVersion, opts))
.ToList();
log.Debug("Finished transformation");

if (ckans.Count > (opts?.Releases ?? 1))
{
throw new Kraken(string.Format("Generated {0} modules but only {1} requested: {2}",
ckans.Count,
opts?.Releases ?? 1,
string.Join("; ", ckans.Select(DescribeHosting))));
}

foreach (Metadata ckan in ckans)
{
ckanValidator.ValidateCkan(ckan, netkans.First());
Expand Down Expand Up @@ -123,6 +130,9 @@ private static void PurgeDownloads(IHttpService http, NetFileCache cache)
}
}

private string DescribeHosting(Metadata metadata)
=> $"{metadata.Version} on {string.Join(", ", metadata.Hosts)}";

private readonly NetFileCache cache;
private readonly IHttpService http;

Expand Down

0 comments on commit 3992aa0

Please sign in to comment.