mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Cleanup program initialization
Initial string[] args actually can't be null according to MSDN
This commit is contained in:
@@ -178,8 +178,11 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse environment variables
|
||||
ParseEnvironmentVariables();
|
||||
|
||||
// Parse args
|
||||
if (args != null) {
|
||||
if (args?.Count > 0) {
|
||||
ParseArgs(args);
|
||||
}
|
||||
|
||||
@@ -431,9 +434,13 @@ namespace ArchiSteamFarm {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<int> Main(string[]? args) {
|
||||
private static async Task<int> Main(string[] args) {
|
||||
if (args == null) {
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
// Initialize
|
||||
await Init(args).ConfigureAwait(false);
|
||||
await Init(args.Length > 0 ? args : null).ConfigureAwait(false);
|
||||
|
||||
// Wait for shutdown event
|
||||
return await ShutdownResetEvent.Task.ConfigureAwait(false);
|
||||
@@ -471,32 +478,10 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
private static void ParseArgs(IReadOnlyCollection<string> args) {
|
||||
if (args == null) {
|
||||
if ((args == null) || (args.Count == 0)) {
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
try {
|
||||
string? envCryptKey = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariableCryptKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(envCryptKey)) {
|
||||
HandleCryptKeyArgument(envCryptKey);
|
||||
}
|
||||
|
||||
string? envNetworkGroup = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariableNetworkGroup);
|
||||
|
||||
if (!string.IsNullOrEmpty(envNetworkGroup)) {
|
||||
HandleNetworkGroupArgument(envNetworkGroup);
|
||||
}
|
||||
|
||||
string? envPath = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariablePath);
|
||||
|
||||
if (!string.IsNullOrEmpty(envPath)) {
|
||||
HandlePathArgument(envPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
}
|
||||
|
||||
bool cryptKeyNext = false;
|
||||
bool networkGroupNext = false;
|
||||
bool pathNext = false;
|
||||
@@ -575,6 +560,31 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseEnvironmentVariables() {
|
||||
// We're using a single try-catch block here, as a failure for getting one variable will result in the same failure for all other ones
|
||||
try {
|
||||
string? envCryptKey = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariableCryptKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(envCryptKey)) {
|
||||
HandleCryptKeyArgument(envCryptKey);
|
||||
}
|
||||
|
||||
string? envNetworkGroup = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariableNetworkGroup);
|
||||
|
||||
if (!string.IsNullOrEmpty(envNetworkGroup)) {
|
||||
HandleNetworkGroupArgument(envNetworkGroup);
|
||||
}
|
||||
|
||||
string? envPath = Environment.GetEnvironmentVariable(SharedInfo.EnvironmentVariablePath);
|
||||
|
||||
if (!string.IsNullOrEmpty(envPath)) {
|
||||
HandlePathArgument(envPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task Shutdown(byte exitCode = 0) {
|
||||
if (!await InitShutdownSequence().ConfigureAwait(false)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user