Add backup/restore CLI options (not useful for most people)

This commit is contained in:
Timothy Baldridge 2020-11-08 17:41:17 -07:00
parent 565bc78161
commit fd74b1b4dc
2 changed files with 100 additions and 1 deletions

View File

@ -32,7 +32,9 @@ namespace Wabbajack.CLI
typeof(NoPatch),
typeof(NexusPermissions),
typeof(ExportServerGameFiles),
typeof(HashGamefiles)
typeof(HashGamefiles),
typeof(Backup),
typeof(Restore)
};
}
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CommandLine;
using Wabbajack.Common;
using Wabbajack.Common.IO;
namespace Wabbajack.CLI.Verbs
{
[Verb("backup", HelpText = @"Copy all encrypted and personal info into a location for transferring to a new machine", Hidden = true)]
public class Backup : AVerb
{
public static Dictionary<string, bool> Keys = new Dictionary<string, bool>()
{
{"bunnycdn", true},
{"nexusapikey", true},
{"nexus-cookies", true},
{"x-metrics-key", true},
{"author-api-key.txt", false}
};
[Option('o', "output", Required = true, HelpText = @"Output folder for the decrypted data")]
public string Output { get; set; } = "";
public AbsolutePath OutputPath => (AbsolutePath)Output;
protected override async Task<ExitCode> Run()
{
foreach(var (name, encrypted) in Keys)
{
byte[] data;
var src = name.RelativeTo(Consts.LocalAppDataPath);
if (!src.Exists)
{
Console.WriteLine($"{name} doesn't exist, skipping");
continue;
}
if (encrypted)
{
data = await Utils.FromEncryptedData(name);
}
else
{
data = await src.ReadAllBytesAsync();
}
await name.RelativeTo(OutputPath).WriteAllBytesAsync(data);
}
return ExitCode.Ok;
}
}
[Verb("restore", HelpText = @"Copy all encrypted and personal info into a location for transferring to a new machine", Hidden = true)]
public class Restore : AVerb
{
public static Dictionary<string, bool> Keys = new Dictionary<string, bool>()
{
{"bunnycdn", true},
{"nexusapikey", true},
{"nexus-cookies", true},
{"x-metrics-key", true},
{"author-api-key.txt", false}
};
[Option('i', "input", Required = true, HelpText = @"Input folder for the decrypted data")]
public string Input { get; set; } = "";
public AbsolutePath InputPath => (AbsolutePath)Input;
protected override async Task<ExitCode> Run()
{
foreach(var (name, encrypted) in Keys)
{
var src = name.RelativeTo(InputPath);
if (!src.Exists)
{
Console.WriteLine($"{name} doesn't exist, skipping");
continue;
}
var data = await src.ReadAllBytesAsync();
if (encrypted)
{
await data.ToEcryptedData(name);
}
else
{
await name.RelativeTo(Consts.LocalAppDataPath).WriteAllBytesAsync(data);
}
}
return ExitCode.Ok;
}
}
}