mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Updates to list validation to recompress images
This commit is contained in:
parent
1c5f537eea
commit
d8b8475843
@ -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<int> 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<RelativePath> 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())
|
||||
|
@ -18,6 +18,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.2-mauipre.1.22054.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.1" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21561.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -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");
|
||||
}
|
@ -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; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user