add --passkey, -p argument, fix #6

This commit is contained in:
Carson McManus 2017-05-22 18:07:12 -04:00
parent 2dccd9c4ef
commit 8d89d63053

View file

@ -28,12 +28,14 @@ namespace SteamGuard
{ {
string action = ""; string action = "";
string user = ""; string user = "";
string passkey = "";
// Parse cli arguments // Parse cli arguments
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
{ {
if (args[i].StartsWith("-")) if (args[i].StartsWith("-"))
{ {
// TODO: there's gotta be some framework or tool or something for this
if (args[i] == "-v" || args[i] == "--verbose") if (args[i] == "-v" || args[i] == "--verbose")
{ {
Verbose = true; Verbose = true;
@ -51,6 +53,19 @@ namespace SteamGuard
return; return;
} }
} }
else if (args[i] == "-p" || args[i] == "--passkey")
{
i++;
if (i < args.Length)
{
passkey = args[i];
}
else
{
Console.WriteLine($"Expected encryption passkey after {args[i-1]}");
return;
}
}
else if (args[i] == "--help" || args[i] == "-h") else if (args[i] == "--help" || args[i] == "-h")
{ {
ShowHelp(); ShowHelp();
@ -122,6 +137,7 @@ namespace SteamGuard
{ {
Console.WriteLine($"Action: {action}"); Console.WriteLine($"Action: {action}");
Console.WriteLine($"User: {user}"); Console.WriteLine($"User: {user}");
Console.WriteLine($"Passkey: {passkey}");
Console.WriteLine($"maFiles path: {SteamGuardPath}"); Console.WriteLine($"maFiles path: {SteamGuardPath}");
} }
@ -129,22 +145,22 @@ namespace SteamGuard
switch (action) switch (action)
{ {
case "generate-code": case "generate-code":
GenerateCode(user); GenerateCode(user, passkey);
break; break;
case "encrypt": // Can also be used to change passkey case "encrypt": // Can also be used to change passkey
Console.WriteLine(Encrypt()); Console.WriteLine(Encrypt(passkey));
break; break;
case "decrypt": case "decrypt":
Console.WriteLine(Decrypt()); Console.WriteLine(Decrypt(passkey));
break; break;
case "setup": case "setup":
Setup(user); Setup(user, passkey);
break; break;
case "trade": case "trade":
Trade(user); Trade(user, passkey);
break; break;
case "accept-all": case "accept-all":
AcceptAllTrades(user); AcceptAllTrades(user, passkey);
break; break;
default: default:
Console.WriteLine("error: Unknown action: {0}", action); Console.WriteLine("error: Unknown action: {0}", action);