improved argument system for optimization and ease of use
This commit is contained in:
parent
e57ad4e2ce
commit
0eef63eca0
1 changed files with 68 additions and 48 deletions
80
Program.cs
80
Program.cs
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -23,55 +24,71 @@ public static class Program
|
|||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string action = "generate-code";
|
||||
|
||||
string action = "";
|
||||
string user = "";
|
||||
|
||||
// Parse cli arguments
|
||||
if (args.Contains("--help") || args.Contains("-h"))
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i].StartsWith("-"))
|
||||
{
|
||||
if (args[i] == "-v" || args[i] == "--verbose")
|
||||
{
|
||||
Verbose = true;
|
||||
}
|
||||
else if (args[i] == "-m" || args[i] == "--mafiles-path")
|
||||
{
|
||||
i++;
|
||||
if (i < args.Length)
|
||||
SteamGuardPath = args[i];
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Expected path after {args[i-1]}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (args[i] == "--help" || args[i] == "-h")
|
||||
{
|
||||
ShowHelp();
|
||||
return;
|
||||
}
|
||||
Verbose = args.Contains("-v") || args.Contains("--verbose");
|
||||
// Actions
|
||||
if (args.Contains("--generate-code"))
|
||||
{
|
||||
action = "generate-code";
|
||||
}
|
||||
else if (args.Contains("--encrypt"))
|
||||
else // Parse as action or username
|
||||
{
|
||||
action = "encrypt";
|
||||
}
|
||||
else if (args.Contains("--decrypt"))
|
||||
if (string.IsNullOrEmpty(action))
|
||||
{
|
||||
action = "decrypt";
|
||||
}
|
||||
else if (args.Contains("--setup"))
|
||||
if (args[i] == "add")
|
||||
{
|
||||
action = "setup";
|
||||
}
|
||||
// Misc
|
||||
if (args.Contains("--user") || args.Contains("-u"))
|
||||
else if (args[i] == "encrypt")
|
||||
{
|
||||
int u = Array.IndexOf(args, "--user");
|
||||
if (u == -1)
|
||||
{
|
||||
u = Array.IndexOf(args, "-u");
|
||||
action = "encrypt";
|
||||
}
|
||||
try
|
||||
else if (args[i] == "decrypt")
|
||||
{
|
||||
user = args[u + 1];
|
||||
action = "decrypt";
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
else if (args[i] == "remove")
|
||||
{
|
||||
Console.WriteLine("error: Account name must be supplied after --user or -u.");
|
||||
return;
|
||||
action = "remove";
|
||||
}
|
||||
else if (args[i] == "2fa" || args[i] == "code" || args[i] == "generate-code")
|
||||
{
|
||||
action = "generate-code";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// its a username
|
||||
if (string.IsNullOrEmpty(user))
|
||||
user = args[i];
|
||||
}
|
||||
if (Verbose) Console.WriteLine("Generating Steam Gaurd code for account \"{0}\"", user);
|
||||
}
|
||||
|
||||
// Do some configure
|
||||
if (string.IsNullOrEmpty(action))
|
||||
action = "generate-code";
|
||||
|
||||
// Do some configuring
|
||||
SteamGuardPath = SteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME"));
|
||||
if (!Directory.Exists(SteamGuardPath))
|
||||
{
|
||||
|
@ -86,9 +103,12 @@ public static class Program
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (Verbose) Console.WriteLine("maFiles path: {0}", SteamGuardPath);
|
||||
|
||||
if (Verbose) Console.WriteLine("Action: {0}", action);
|
||||
if (Verbose) Console.WriteLine($"Action: {action}");
|
||||
if (Verbose) Console.WriteLine($"User: {user}");
|
||||
if (Verbose) Console.WriteLine($"maFiles path: {SteamGuardPath}");
|
||||
return;
|
||||
|
||||
// Perform desired action
|
||||
switch (action)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue