Skip to content

Commit

Permalink
Added correct beta support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii Mikhailov committed Jun 24, 2023
1 parent 9a222e6 commit 5cf804d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/Bannerlord.ReferenceAssemblies/NuGet/NuGetFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public NuGetFeed(string feedUrl, string? feedUser, string? feedPassword)
public async Task<IReadOnlyDictionary<string, IReadOnlyList<NuGetPackage>>> GetVersionsAsync(CancellationToken ct)
{
var packageLister = await _sourceRepository.GetResourceAsync<PackageSearchResource>(ct);
var foundPackages = await packageLister.SearchAsync("Bannerlord.ReferenceAssemblies", new SearchFilter(true), 0, 50, NullLogger.Instance, ct);
var foundPackages = (await packageLister.SearchAsync("Bannerlord.ReferenceAssemblies", new SearchFilter(true), 0, 50, NullLogger.Instance, ct))
.Where(x => !x.Identity.Id.Contains("EarlyAccess", StringComparison.OrdinalIgnoreCase));

var sourceCacheContext = new SourceCacheContext();
var finderPackageByIdResource = await _sourceRepository.GetResourceAsync<FindPackageByIdResource>(ct);
Expand All @@ -49,8 +50,10 @@ public async Task<IReadOnlyDictionary<string, IReadOnlyList<NuGetPackage>>> GetV

private static async IAsyncEnumerable<NuGetVersion> MaxVersions(Task<IEnumerable<NuGetVersion>> source)
{
var data = (await source).ToList();
var dict = new Dictionary<string, NuGetVersion>();
foreach (var version in await source)
var dictBeta = new Dictionary<string, NuGetVersion>();
foreach (var version in data.Where(x => !x.IsPrerelease))
{
var v = version.Version.ToString(3);
var currentMax = dict.TryGetValue(v, out var c) ? c : null;
Expand All @@ -60,8 +63,20 @@ private static async IAsyncEnumerable<NuGetVersion> MaxVersions(Task<IEnumerable
else if (version.Version.Build < 100000 && currentMax.Version < version.Version) dict[v] = version;
else if (currentMax.Version < version.Version) dict[v] = version;
}
foreach (var version in data.Where(x => x.IsPrerelease))
{
var v = version.Version.ToString(3);
var currentMax = dictBeta.TryGetValue(v, out var c) ? c : null;
if (currentMax is null) dictBeta[v] = version;
// Release reset their build index. For now everything that is higher than 200000 is considered EA
// TODO: better fix?
else if (version.Version.Build < 100000 && currentMax.Version < version.Version) dictBeta[v] = version;
else if (currentMax.Version < version.Version) dictBeta[v] = version;
}
foreach (var value in dict.Values)
yield return value;
foreach (var value in dictBeta.Values)
yield return value;
}

private static async IAsyncEnumerable<IPackageSearchMetadata> GetMetadataAsync(IAsyncEnumerable<NuGetVersion> versions, Func<NuGetVersion, Task<IPackageSearchMetadata>> getMeta, CancellationToken cancellationToken = default)
Expand Down
12 changes: 8 additions & 4 deletions src/Bannerlord.ReferenceAssemblies/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ internal partial class Tool
{
private static readonly Dictionary<string, string> SupportMatrix = new()
{
{"Bannerlord.ReferenceAssemblies.BirthAndDeath.EarlyAccess", "e1.8.0"}
{"BannerlordReferenceAssembliesMultiplayer", "v1.2.0" },
};
private static readonly Dictionary<string, string> ExcludeMatrix = new()
{
{"BannerlordReferenceAssembliesDedicatedCustomServerHelper", "v1.2.0" },
};

private static readonly IFolder ExecutableFolder = new FolderFromPath(AppDomain.CurrentDomain.BaseDirectory);
Expand Down Expand Up @@ -70,9 +74,9 @@ public async Task ExecuteAsync(CancellationToken ct)
var toDownload = new HashSet<SteamAppBranch>();
foreach (var (packageId, buildIds) in packageNameWithBuildIds)
{
toDownload.AddRange(branches.Where(branch =>
(!SupportMatrix.TryGetValue(packageId, out var val) || new AlphanumComparatorFast().Compare(val, branch.Name) <= 0) &&
!buildIds.Contains(branch.BuildId)));
toDownload.AddRange(branches.Where(x => (!SupportMatrix.TryGetValue(packageId, out var val) || new AlphanumComparatorFast().Compare(val, x.Name) <= 0) &&
(!ExcludeMatrix.TryGetValue(packageId, out var val2) || new AlphanumComparatorFast().Compare(val2, x.Name) > 0) &&
!buildIds.Contains(x.BuildId)).ToArray());
}

if (toDownload.Count == 0)
Expand Down

0 comments on commit 5cf804d

Please sign in to comment.