private static void Init(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
string homeDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
if (!string.IsNullOrEmpty(homeDirectory))
{
Directory.SetCurrentDirectory(homeDirectory);
// Allow loading configs from source tree if it's a debug build
if (Debugging.IsDebugBuild)
{
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
for (byte i = 0; i < 4; i++)
{
Directory.SetCurrentDirectory("..");
if (Directory.Exists(SharedInfo.ConfigDirectory))
{
break;
}
}
// If config directory doesn't exist after our adjustment, abort all of that
if (!Directory.Exists(SharedInfo.ConfigDirectory))
{
Directory.SetCurrentDirectory(homeDirectory);
}
}
}
// Parse pre-init args
if (args != null)
{
ParsePreInitArgs(args);
}
Logging.InitLoggers();
Logging.LogGenericInfo("ASF V" + SharedInfo.Version);
if (!Runtime.IsRuntimeSupported)
{
Logging.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!");
Thread.Sleep(10000);
}
InitServices();
// If debugging is on, we prepare debug directory prior to running
if (GlobalConfig.Debug)
{
if (Directory.Exists(SharedInfo.DebugDirectory))
{
Directory.Delete(SharedInfo.DebugDirectory, true);
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
}
Directory.CreateDirectory(SharedInfo.DebugDirectory);
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener());
SteamKit2.DebugLog.Enabled = true;
}
// Parse post-init args
if (args != null)
{
ParsePostInitArgs(args);
}
// If we ran ASF as a client, we're done by now
if (Mode == EMode.Client)
{
Exit();
}
// From now on it's server mode
if (!Directory.Exists(SharedInfo.ConfigDirectory))
{
Logging.LogGenericError("Config directory doesn't exist!");
Thread.Sleep(5000);
Exit(1);
}
ASF.CheckForUpdate().Wait();
// Before attempting to connect, initialize our list of CMs
Bot.InitializeCMs(GlobalDatabase.CellID, GlobalDatabase.ServerListProvider);
bool isRunning = false;
foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension))
{
switch (botName)
{
case SharedInfo.ASF:
case "example":
case "minimal":
continue;
}
Bot bot = new Bot(botName);
if ((bot.BotConfig == null) || !bot.BotConfig.Enabled)
{
continue;
}
if (bot.BotConfig.StartOnLaunch)
{
isRunning = true;
}
}
// Check if we got any bots running
if (!isRunning)
{
Events.OnBotShutdown();
}
}