Add support for specifying --path=

This commit is contained in:
JustArchi
2016-07-24 00:36:15 +02:00
parent b19a5c533f
commit 0714c4e575

View File

@@ -400,7 +400,29 @@ namespace ArchiSteamFarm {
WebBrowser = new WebBrowser(ASF); WebBrowser = new WebBrowser(ASF);
} }
private static void ParseArgs(IEnumerable<string> args) { private static void ParsePreInitArgs(IEnumerable<string> args) {
if (args == null) {
Logging.LogNullError(nameof(args));
return;
}
foreach (string arg in args) {
switch (arg) {
case "":
break;
default:
if (arg.StartsWith("--", StringComparison.Ordinal)) {
if (arg.StartsWith("--path=", StringComparison.Ordinal) && (arg.Length > 7)) {
Directory.SetCurrentDirectory(arg.Substring(7));
}
}
break;
}
}
}
private static void ParsePostInitArgs(IEnumerable<string> args) {
if (args == null) { if (args == null) {
Logging.LogNullError(nameof(args)); Logging.LogNullError(nameof(args));
return; return;
@@ -421,8 +443,6 @@ namespace ArchiSteamFarm {
if (arg.StartsWith("--", StringComparison.Ordinal)) { if (arg.StartsWith("--", StringComparison.Ordinal)) {
if (arg.StartsWith("--cryptkey=", StringComparison.Ordinal) && (arg.Length > 11)) { if (arg.StartsWith("--cryptkey=", StringComparison.Ordinal) && (arg.Length > 11)) {
CryptoHelper.SetEncryptionKey(arg.Substring(11)); CryptoHelper.SetEncryptionKey(arg.Substring(11));
} else {
Logging.LogGenericWarning("Unrecognized parameter: " + arg);
} }
break; break;
@@ -434,14 +454,7 @@ namespace ArchiSteamFarm {
} }
Logging.LogGenericInfo("Command sent: " + arg); Logging.LogGenericInfo("Command sent: " + arg);
// We intentionally execute this async block synchronously
Logging.LogGenericInfo("Response received: " + WCF.SendCommand(arg)); Logging.LogGenericInfo("Response received: " + WCF.SendCommand(arg));
/*
Task.Run(async () => {
Logging.LogGenericNotice("WCF", "Response received: " + await WCF.SendCommand(arg).ConfigureAwait(false));
}).Wait();
*/
break; break;
} }
} }
@@ -465,7 +478,7 @@ namespace ArchiSteamFarm {
Logging.LogFatalException(args.Exception); Logging.LogFatalException(args.Exception);
} }
private static void Init(IEnumerable<string> args) { private static void Init(string[] args) {
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler; TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
@@ -491,6 +504,11 @@ namespace ArchiSteamFarm {
} }
} }
// Parse pre-init args
if (args != null) {
ParsePreInitArgs(args);
}
InitServices(); InitServices();
// If debugging is on, we prepare debug directory prior to running // If debugging is on, we prepare debug directory prior to running
@@ -505,9 +523,9 @@ namespace ArchiSteamFarm {
SteamKit2.DebugLog.Enabled = true; SteamKit2.DebugLog.Enabled = true;
} }
// Parse args // Parse post-init args
if (args != null) { if (args != null) {
ParseArgs(args); ParsePostInitArgs(args);
} }
// If we ran ASF as a client, we're done by now // If we ran ASF as a client, we're done by now