2022-02-10 02:37:46 +00:00
|
|
|
|
2021-09-27 12:42:46 +00:00
|
|
|
using System.CommandLine;
|
|
|
|
using System.CommandLine.Invocation;
|
2022-09-29 05:10:49 +00:00
|
|
|
using System.CommandLine.NamingConventionBinder;
|
2021-09-27 12:42:46 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-14 22:08:21 +00:00
|
|
|
using Wabbajack.CLI.Builder;
|
2021-09-27 12:42:46 +00:00
|
|
|
using Wabbajack.Paths;
|
|
|
|
using Wabbajack.Paths.IO;
|
|
|
|
using Wabbajack.Services.OSIntegrated;
|
2020-01-31 22:38:56 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
2022-10-14 22:08:21 +00:00
|
|
|
public class Decrypt
|
2020-01-31 22:38:56 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
private readonly ILogger<Decrypt> _logger;
|
|
|
|
|
|
|
|
public Decrypt(ILogger<Decrypt> logger)
|
2020-01-31 22:38:56 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
2020-01-31 22:38:56 +00:00
|
|
|
|
2022-10-01 01:35:36 +00:00
|
|
|
public static VerbDefinition Definition = new VerbDefinition("decrypt",
|
|
|
|
"Decrypts a file from the wabbajack encrypted storage",
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
new OptionDefinition(typeof(AbsolutePath), "o", "output", "Output file path"),
|
|
|
|
new OptionDefinition(typeof(string), "n", "name", "Name of the key to load data from")
|
|
|
|
});
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public async Task<int> Run(AbsolutePath output, string name)
|
|
|
|
{
|
|
|
|
var data = await name.ToRelativePath()
|
|
|
|
.RelativeTo(KnownFolders.WabbajackAppLocal.Combine("encrypted"))
|
|
|
|
.FromEncryptedDataFile();
|
|
|
|
_logger.LogInformation("Decrypting {bytes} bytes into `{key}`", data.Length, name);
|
|
|
|
await output.WriteAllBytesAsync(data);
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
return 0;
|
2020-01-31 22:38:56 +00:00
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|