wabbajack/Wabbajack.CLI/Verbs/DumpZipInfo.cs

58 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.NamingConventionBinder;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Wabbajack.CLI.Builder;
using Wabbajack.Common;
using Wabbajack.Compression.Zip;
using Wabbajack.Downloaders;
using Wabbajack.DTOs;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.CLI.Verbs;
public class DumpZipInfo
{
private readonly ILogger<DumpZipInfo> _logger;
public DumpZipInfo(ILogger<DumpZipInfo> logger)
{
_logger = logger;
}
2022-10-01 01:35:36 +00:00
public static VerbDefinition Definition = new("dump-zip-info",
"Dumps the contents of a zip file to the console, for use in debugging wabbajack files",
new[]
{
new OptionDefinition(typeof(AbsolutePath), "i", "input", "Zip file to parse"),
new OptionDefinition(typeof(bool), "t", "test", "Test extracting each file")
});
2022-10-01 01:35:36 +00:00
internal async Task<int> Run(AbsolutePath input, bool test)
{
await using var ar = new ZipReader(input.Open(FileMode.Open), false);
foreach (var value in (await ar.GetFiles()))
{
if (test)
{
_logger.LogInformation("Extracting {File}", value.FileName);
await ar.Extract(value, new MemoryStream(), CancellationToken.None);
}
else
{
_logger.LogInformation("Read {File}", value.FileName);
}
}
return 0;
}
}