Skip to content

Commit

Permalink
Fix missing mods not returned as needing update
Browse files Browse the repository at this point in the history
  • Loading branch information
3Mydlo3 committed Nov 15, 2023
1 parent f1766fa commit 73f95e7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -88,14 +89,25 @@ public async Task PrepareModset_SomeModsOutdated_UpdatedOutdatedMods()

var outdatedMods = modset.Mods
.Take(5)
.Select(x => {
x.LastUpdatedAt = DateTime.Now.AddDays(-10);
return x;
})
.ToList();
var upToDateMods = modset.Mods
.Except(outdatedMods)
.Select(x => {
x.LastUpdatedAt = DateTime.Now.AddDays(10);
return x;
})
.ToList();

modset.Mods = outdatedMods.Concat(upToDateMods).ToHashSet();

AddModsToModsCache(modset.Mods.ToList());
SetModsAsUpToDate(upToDateMods);
SetupPublishedFileDetails(modset.Mods);
SetupContentDownloader(outdatedMods);
AddModsToModsCache(modset.Mods.ToList());

await _modsManager.PrepareModset(modset, cancellationToken);

Expand Down Expand Up @@ -164,6 +176,24 @@ private void SetModsAsUpToDate(IReadOnlyCollection<Mod> mods)
.Returns(Task.FromResult(Result.Success(contentItem)));
}
}

private void SetupPublishedFileDetails(ISet<Mod> mods)
{
var modsIds = mods.Select(x => (ulong)x.WorkshopId!);

var details = mods
.Select(x => new PublishedFileDetails
{
Title = x.Name,
PublishedFileId = x.WorkshopId!.Value,
LastUpdatedAt = DateTime.Now
})
.ToArray();

_steamRemoteStorageMock
.Setup(x => x.GetPublishedFileDetails(modsIds, It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(Result.Success(details)));
}

private void AddModsToModsCache(IReadOnlyCollection<Mod> mods)
{
Expand All @@ -173,6 +203,11 @@ private void AddModsToModsCache(IReadOnlyCollection<Mod> mods)
.Setup(x => x.ModExists(mod))
.Returns(Task.FromResult(true));
}

var modsInCache = _modsCacheMock.Object.Mods;
_modsCacheMock
.Setup(x => x.Mods)
.Returns(modsInCache.Concat(mods).ToList());
}

private Mock<IModsCache> CreateModsCacheMock()
Expand All @@ -182,6 +217,10 @@ private Mock<IModsCache> CreateModsCacheMock()
mock
.Setup(x => x.ModExists(It.IsAny<Mod>()))
.Returns(Task.FromResult(false));

mock
.Setup(x => x.Mods)
.Returns(new List<Mod>());

return mock;
}
Expand Down Expand Up @@ -214,7 +253,7 @@ private Mock<ISteamRemoteStorage> CreateSteamRemoteStorageMock()

mock
.Setup(x => x.GetPublishedFileDetails(It.IsAny<IReadOnlyCollection<ulong>>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(new Result<PublishedFileDetails[]>()));
.Returns(Task.FromResult(Result.Success(Array.Empty<PublishedFileDetails>())));

return mock;
}
Expand Down
12 changes: 9 additions & 3 deletions ArmaForces.ArmaServerManager/Features/Mods/ModsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ public async Task<Result<List<Mod>>> CheckModsUpdated(IReadOnlyCollection<Mod> m
{
return Result.Success(new List<Mod>());
}

var workshopModIds = modsList
var workshopMods = modsList
.Where(x => x.Source == ModSource.SteamWorkshop)
.ToList();

var workshopModIds = workshopMods
.Select(x => x.WorkshopId)
.Where(x => x.HasValue)
.Select(x => (ulong)x!.Value)
Expand All @@ -93,8 +96,11 @@ public async Task<Result<List<Mod>>> CheckModsUpdated(IReadOnlyCollection<Mod> m
.Where(x => x.mod.LastUpdatedAt < x.details.LastUpdatedAt)
.Select(x => x.mod)
.ToList();

var modsNotInCache = workshopMods
.Where(x => _modsCache.Mods.NotContains(x));

return Result.Success(modsToUpdate);
return Result.Success(modsNotInCache.Concat(modsToUpdate).ToList());
}

/// <inheritdoc />
Expand Down

0 comments on commit 73f95e7

Please sign in to comment.