diff --git a/Wabbajack.CLI/Verbs/ValidateLists.cs b/Wabbajack.CLI/Verbs/ValidateLists.cs index 321a8aa0..fc05d40b 100644 --- a/Wabbajack.CLI/Verbs/ValidateLists.cs +++ b/Wabbajack.CLI/Verbs/ValidateLists.cs @@ -11,6 +11,8 @@ using System.Threading; using System.Threading.Tasks; using FluentFTP; using Microsoft.Extensions.Logging; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Processing; using Wabbajack.CLI.Services; using Wabbajack.Common; using Wabbajack.Compression.Zip; @@ -90,6 +92,10 @@ public class ValidateLists : IVerb public async Task Run(AbsolutePath reports, AbsolutePath otherArchives) { + _logger.LogInformation("Cleaning {Reports}", reports); + if (reports.DirectoryExists()) + reports.DeleteDirectory(); + reports.CreateDirectory(); var token = CancellationToken.None; @@ -210,6 +216,10 @@ public class ValidateLists : IVerb validatedList.Status = archives.Any(a => a.Status == ArchiveStatus.InValid) ? ListStatus.Failed : ListStatus.Available; + + var image = await ProcessModlistImage(reports, modList, token); + validatedList.Image = new Uri($"https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/reports/{image.ToString().Replace("\\", "/")}"); + return validatedList; }).ToArray(); @@ -239,6 +249,28 @@ public class ValidateLists : IVerb return 0; } + private async Task ProcessModlistImage(AbsolutePath reports, ModlistMetadata validatedList, + CancellationToken token) + { + _logger.LogInformation("Processing Modlist Image"); + var baseFolder = reports.Combine(validatedList.NamespacedName); + baseFolder.CreateDirectory(); + + var standardWidth = 466; + await using var imageStream = await _httpClient.GetStreamAsync(validatedList.Links.ImageUri, token); + var ms = new MemoryStream(); + var hash = await imageStream.HashingCopy(ms, token); + ms.Position = 0; + using var image = await Image.LoadAsync(ms, token); + var height = standardWidth * image.Height / image.Width; + image.Mutate(x => x + .Resize(standardWidth, height)); + var path = validatedList.RepositoryName.ToRelativePath().Combine(hash.ToHex()).WithExtension(Ext.Webp); + await image.SaveAsync(path.RelativeTo(reports).ToString(), cancellationToken: token); + + return path; + } + private async Task SendDefinitionToLoadOrderLibrary(ModlistMetadata metadata, ModList modListData, CancellationToken token) { var lolGame = modListData.GameType switch @@ -513,7 +545,7 @@ public class ValidateLists : IVerb } - + private async Task SendDefinitionToLoadOrderLibrary(ValidatedModList validatedModList, CancellationToken token) { var modlistMetadata = (await _wjClient.LoadLists()) diff --git a/Wabbajack.CLI/Wabbajack.CLI.csproj b/Wabbajack.CLI/Wabbajack.CLI.csproj index 19bc0a15..5fbb8b0c 100644 --- a/Wabbajack.CLI/Wabbajack.CLI.csproj +++ b/Wabbajack.CLI/Wabbajack.CLI.csproj @@ -18,6 +18,7 @@ + diff --git a/Wabbajack.Common/Ext.cs b/Wabbajack.Common/Ext.cs index 10c5304f..29e02477 100644 --- a/Wabbajack.Common/Ext.cs +++ b/Wabbajack.Common/Ext.cs @@ -25,4 +25,5 @@ public static class Ext public static Extension Temp = new(".temp"); public static Extension ModlistMetadataExtension = new(".modlist_metadata"); public static Extension Txt = new(".txt"); + public static Extension Webp = new(".webp"); } \ No newline at end of file diff --git a/Wabbajack.DTOs/ModListValidation/ValidatedModList.cs b/Wabbajack.DTOs/ModListValidation/ValidatedModList.cs index e8e7277e..3d72df02 100644 --- a/Wabbajack.DTOs/ModListValidation/ValidatedModList.cs +++ b/Wabbajack.DTOs/ModListValidation/ValidatedModList.cs @@ -16,4 +16,5 @@ public class ValidatedModList public ListStatus Status { get; set; } public long Failures => Archives.Count(a => a.Status == ArchiveStatus.InValid); + public Uri Image { get; set; } } \ No newline at end of file