2022-02-12 00:47:02 +00:00
|
|
|
using System;
|
|
|
|
using System.CommandLine;
|
|
|
|
using System.CommandLine.Invocation;
|
2022-09-29 05:10:49 +00:00
|
|
|
using System.CommandLine.NamingConventionBinder;
|
2022-02-12 00:47:02 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-14 22:08:21 +00:00
|
|
|
using Wabbajack.CLI.Builder;
|
2022-02-12 00:47:02 +00:00
|
|
|
using Wabbajack.Common;
|
|
|
|
using Wabbajack.Downloaders;
|
|
|
|
using Wabbajack.DTOs;
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
using Wabbajack.Paths.IO;
|
|
|
|
|
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
2022-10-14 22:08:21 +00:00
|
|
|
public class Extract
|
2022-02-12 00:47:02 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
private readonly ILogger<DownloadUrl> _logger;
|
|
|
|
private readonly FileExtractor.FileExtractor _extractor;
|
|
|
|
|
|
|
|
public Extract(ILogger<DownloadUrl> logger, FileExtractor.FileExtractor extractor)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_extractor = extractor;
|
|
|
|
}
|
|
|
|
|
2022-10-01 01:35:36 +00:00
|
|
|
public static VerbDefinition Definition = new("extract",
|
|
|
|
"Extracts the contents of an archive into a folder", new[]
|
|
|
|
{
|
|
|
|
new OptionDefinition(typeof(AbsolutePath), "i", "input", "Input Archive"),
|
|
|
|
new OptionDefinition(typeof(AbsolutePath), "o", "output", "Output Folder")
|
|
|
|
});
|
2022-02-12 00:47:02 +00:00
|
|
|
|
2022-10-01 01:35:36 +00:00
|
|
|
internal async Task<int> Run(AbsolutePath input, AbsolutePath output, CancellationToken token)
|
2022-02-12 00:47:02 +00:00
|
|
|
{
|
|
|
|
if (!output.DirectoryExists())
|
|
|
|
output.Parent.CreateDirectory();
|
|
|
|
|
|
|
|
await _extractor.ExtractAll(input, output, token, f =>
|
|
|
|
{
|
|
|
|
Console.WriteLine($" - {f}");
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|