mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #459 from wabbajack-tools/wabbajac-cli
Wabbajack cli
This commit is contained in:
commit
bd588fd84e
13
Wabbajack.CLI/OptionsDefinition.cs
Normal file
13
Wabbajack.CLI/OptionsDefinition.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using Wabbajack.CLI.Verbs;
|
||||
|
||||
namespace Wabbajack.CLI
|
||||
{
|
||||
public class OptionsDefinition
|
||||
{
|
||||
public static Type[] AllOptions = new[]
|
||||
{
|
||||
typeof(OptionsDefinition), typeof(Encrypt), typeof(Decrypt)
|
||||
};
|
||||
}
|
||||
}
|
18
Wabbajack.CLI/Program.cs
Normal file
18
Wabbajack.CLI/Program.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using CommandLine;
|
||||
using Wabbajack.CLI.Verbs;
|
||||
|
||||
namespace Wabbajack.CLI
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
return CommandLine.Parser.Default.ParseArguments(args, OptionsDefinition.AllOptions)
|
||||
.MapResult(
|
||||
(Encrypt opts) => Encrypt.Run(opts),
|
||||
(Decrypt opts) => Decrypt.Run(opts),
|
||||
errs => 1);
|
||||
}
|
||||
}
|
||||
}
|
23
Wabbajack.CLI/Verbs/Decrypt.cs
Normal file
23
Wabbajack.CLI/Verbs/Decrypt.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using CommandLine;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.CLI.Verbs
|
||||
{
|
||||
[Verb("decrypt", HelpText = @"Decrypt data from AppData\Local\Wabbajack and store it locally", Hidden = true)]
|
||||
public class Decrypt
|
||||
{
|
||||
[Option('n', "name", Required = true, HelpText = @"Credential to encrypt and store in AppData\Local\Wabbajack")]
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
[Option('o', "output", Required = true, HelpText = @"Output file for the decrypted data")]
|
||||
public string Output { get; set; }
|
||||
|
||||
public static int Run(Decrypt opts)
|
||||
{
|
||||
File.WriteAllBytes(opts.Output, Utils.FromEncryptedData(opts.Name));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
22
Wabbajack.CLI/Verbs/Encrypt.cs
Normal file
22
Wabbajack.CLI/Verbs/Encrypt.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using CommandLine;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.CLI.Verbs
|
||||
{
|
||||
[Verb("encrypt", HelpText = @"Encrypt local data and store it in AppData\Local\Wabbajack", Hidden = true)]
|
||||
public class Encrypt
|
||||
{
|
||||
[Option('n', "name", Required = true, HelpText = @"Credential to encrypt and store in AppData\Local\Wabbajack")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Option('i', "input", Required = true, HelpText = @"Source data file name")]
|
||||
public string Input { get; set; }
|
||||
|
||||
public static int Run(Encrypt opts)
|
||||
{
|
||||
File.ReadAllBytes(opts.Input).ToEcryptedData(opts.Name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
19
Wabbajack.CLI/Wabbajack.CLI.csproj
Normal file
19
Wabbajack.CLI/Wabbajack.CLI.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AssemblyName>wabbajack-cli</AssemblyName>
|
||||
<Company>Wabbajack</Company>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.7.82" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wabbajack.Common\Wabbajack.Common.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Lib\Wabbajack.Lib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -19,7 +19,7 @@ namespace Wabbajack.Common
|
||||
public static bool Help { get; set; }
|
||||
}
|
||||
|
||||
public static class CLI
|
||||
public static class CLIOld
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the argument and sets the properties of <see cref="CLIArguments"/>
|
||||
|
@ -1082,6 +1082,18 @@ namespace Wabbajack.Common
|
||||
public static void ToEcryptedJson<T>(this T data, string key)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(data.ToJSON());
|
||||
bytes.ToEcryptedData(key);
|
||||
}
|
||||
|
||||
public static T FromEncryptedJson<T>(string key)
|
||||
{
|
||||
var decoded = FromEncryptedData(key);
|
||||
return Encoding.UTF8.GetString(decoded).FromJSONString<T>();
|
||||
}
|
||||
|
||||
|
||||
public static void ToEcryptedData(this byte[] bytes, string key)
|
||||
{
|
||||
var encoded = ProtectedData.Protect(bytes, Encoding.UTF8.GetBytes(key), DataProtectionScope.LocalMachine);
|
||||
|
||||
if (!Directory.Exists(Consts.LocalAppDataPath))
|
||||
@ -1090,13 +1102,11 @@ namespace Wabbajack.Common
|
||||
var path = Path.Combine(Consts.LocalAppDataPath, key);
|
||||
File.WriteAllBytes(path, encoded);
|
||||
}
|
||||
|
||||
public static T FromEncryptedJson<T>(string key)
|
||||
public static byte[] FromEncryptedData(string key)
|
||||
{
|
||||
var path = Path.Combine(Consts.LocalAppDataPath, key);
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
var decoded = ProtectedData.Unprotect(bytes, Encoding.UTF8.GetBytes(key), DataProtectionScope.LocalMachine);
|
||||
return Encoding.UTF8.GetString(decoded).FromJSONString<T>();
|
||||
return ProtectedData.Unprotect(bytes, Encoding.UTF8.GetBytes(key), DataProtectionScope.LocalMachine);
|
||||
}
|
||||
|
||||
public static bool HaveEncryptedJson(string key)
|
||||
|
@ -36,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.VirtualFileSystem
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.Test", "Wabbajack.Test\Wabbajack.Test.csproj", "{81F87B8B-D5CE-4807-9005-38DE95BD7840}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.CLI", "Wabbajack.CLI\Wabbajack.CLI.csproj", "{685D8BB1-D178-4D2C-85C7-C54A36FB7454}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -132,6 +134,14 @@ Global
|
||||
{81F87B8B-D5CE-4807-9005-38DE95BD7840}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{81F87B8B-D5CE-4807-9005-38DE95BD7840}.Release|x64.ActiveCfg = Release|x64
|
||||
{81F87B8B-D5CE-4807-9005-38DE95BD7840}.Release|x64.Build.0 = Release|x64
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -16,9 +16,9 @@ namespace Wabbajack
|
||||
{
|
||||
public App()
|
||||
{
|
||||
CLI.ParseOptions(Environment.GetCommandLineArgs());
|
||||
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
|
||||
if (CLIArguments.Help)
|
||||
CLI.DisplayHelpText();
|
||||
CLIOld.DisplayHelpText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,10 @@
|
||||
<StartupObject></StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Resources\Icons\wabbajack.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
@ -42,6 +46,7 @@
|
||||
<None Remove="Resources\Wabba_Ded.png" />
|
||||
<None Remove="Resources\Wabba_Mouth.png" />
|
||||
<None Remove="Resources\Wabba_Mouth_No_Text.png" />
|
||||
<None Remove="Resources\Wabba_Mouth_Small.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -68,6 +73,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Compression.BSA\Compression.BSA.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.CLI\Wabbajack.CLI.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Common\Wabbajack.Common.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Lib\Wabbajack.Lib.csproj" />
|
||||
</ItemGroup>
|
||||
@ -80,4 +86,8 @@
|
||||
<Resource Include="Resources\Wabba_Mouth_No_Text.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<SplashScreen Include="Resources\Wabba_Mouth_Small.png" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user