Example #1
0
        private static void Init(IEnumerable <string> args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            TaskScheduler.UnobservedTaskException      += UnobservedTaskExceptionHandler;

            Logging.LogGenericInfo("ASF V" + Version);
            Directory.SetCurrentDirectory(ExecutableDirectory);
            InitServices();

            // 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(ConfigDirectory))
                    {
                        break;
                    }
                }

                // If config directory doesn't exist after our adjustment, abort all of that
                if (!Directory.Exists(ConfigDirectory))
                {
                    Directory.SetCurrentDirectory(ExecutableDirectory);
                }
            }

            // If debugging is on, we prepare debug directory prior to running
            if (GlobalConfig.Debug)
            {
                if (Directory.Exists(DebugDirectory))
                {
                    Directory.Delete(DebugDirectory, true);
                    Thread.Sleep(1000);                     // Dirty workaround giving Windows some time to sync
                }
                Directory.CreateDirectory(DebugDirectory);

                SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(DebugDirectory, "debug.txt")));
                SteamKit2.DebugLog.Enabled = true;
            }

            // Parse args
            if (args != null)
            {
                ParseArgs(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
            Logging.Init();

            if (!Directory.Exists(ConfigDirectory))
            {
                Logging.LogGenericError("Config directory doesn't exist!");
                Thread.Sleep(5000);
                Exit(1);
            }

            CheckForUpdate().Wait();

            // Before attempting to connect, initialize our list of CMs
            Bot.RefreshCMs(GlobalDatabase.CellID).Wait();

            bool isRunning = false;

            foreach (string botName in Directory.EnumerateFiles(ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension))
            {
                switch (botName)
                {
                case 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)
            {
                OnBotShutdown();
            }
        }
Example #2
0
        private static void Init(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            TaskScheduler.UnobservedTaskException      += UnobservedTaskExceptionHandler;

            Logging.LogGenericInfo("Archi's Steam Farm, version " + Version);
            Directory.SetCurrentDirectory(ExecutableDirectory);
            InitServices();

            // 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 (var i = 0; i < 4; i++)
                {
                    Directory.SetCurrentDirectory("..");
                    if (Directory.Exists(ConfigDirectory))
                    {
                        break;
                    }
                }

                // If config directory doesn't exist after our adjustment, abort all of that
                if (!Directory.Exists(ConfigDirectory))
                {
                    Directory.SetCurrentDirectory(ExecutableDirectory);
                }
            }

            // If debugging is on, we prepare debug directory prior to running
            if (GlobalConfig.Debug)
            {
                if (Directory.Exists(DebugDirectory))
                {
                    Directory.Delete(DebugDirectory, true);
                    Thread.Sleep(1000);                     // Dirty workaround giving Windows some time to sync
                }
                Directory.CreateDirectory(DebugDirectory);

                SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(Program.DebugDirectory, "debug.txt")));
                SteamKit2.DebugLog.Enabled = true;
            }

            // Parse args
            ParseArgs(args);

            // If we ran ASF as a client, we're done by now
            if (Mode == EMode.Client)
            {
                return;
            }

            // From now on it's server mode
            Logging.Init();

            if (!Directory.Exists(ConfigDirectory))
            {
                Logging.LogGenericError("Config directory doesn't exist!");
                Thread.Sleep(5000);
                Environment.Exit(1);
            }

            CheckForUpdate().Wait();

            // Before attempting to connect, initialize our list of CMs
            Bot.RefreshCMs(GlobalDatabase.CellID).Wait();

            bool isRunning = false;

            foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.json"))
            {
                string botName = Path.GetFileNameWithoutExtension(configFile);
                if (botName.Equals(ASF))
                {
                    continue;
                }

                Bot bot = new Bot(botName);
                if (bot.BotConfig != null && bot.BotConfig.Enabled)
                {
                    isRunning = true;
                }
                else
                {
                    Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
                }
            }

            // CONVERSION START
            foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.xml"))
            {
                string botName = Path.GetFileNameWithoutExtension(configFile);
                Logging.LogGenericWarning("Found legacy " + botName + ".xml config file, it will now be converted to new ASF V2.0 format!");
                Bot bot = new Bot(botName);
                if (bot.BotConfig != null && bot.BotConfig.Enabled)
                {
                    isRunning = true;
                }
                else
                {
                    Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
                }
            }
            // CONVERSION END

            // Check if we got any bots running
            if (!isRunning)
            {
                OnBotShutdown();
            }
        }
Example #3
0
 private static void InitServices()
 {
     Logging.Init();
     WebBrowser.Init();
 }
Example #4
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            Logging.LogGenericInfo("Archi's Steam Farm, version " + Version);
            Directory.SetCurrentDirectory(ExecutableDirectory);
            InitServices();

            // 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 (var i = 0; i < 4; i++)
                {
                    Directory.SetCurrentDirectory("..");
                    if (Directory.Exists(ConfigDirectory))
                    {
                        break;
                    }
                }

                // If config directory doesn't exist after our adjustment, abort all of that
                if (!Directory.Exists(ConfigDirectory))
                {
                    Directory.SetCurrentDirectory(ExecutableDirectory);
                }
            }

            // Parse args
            ParseArgs(args);

            // If we ran ASF as a client, we're done by now
            if (Mode == EMode.Client)
            {
                return;
            }

            // From now on it's server mode
            Logging.Init();

            if (!Directory.Exists(ConfigDirectory))
            {
                Logging.LogGenericError("Config directory doesn't exist!");
                Thread.Sleep(5000);
                Exit(1);
            }

            CheckForUpdate().Wait();

            // Before attempting to connect, initialize our list of CMs
            Bot.RefreshCMs(GlobalDatabase.CellID).Wait();

            foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.json"))
            {
                string botName = Path.GetFileNameWithoutExtension(configFile);
                if (botName.Equals(ASF))
                {
                    continue;
                }

                Bot bot = new Bot(botName);
                if (bot.BotConfig == null || !bot.BotConfig.Enabled)
                {
                    Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
                }
            }

            // CONVERSION START
            foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.xml"))
            {
                string botName = Path.GetFileNameWithoutExtension(configFile);
                Logging.LogGenericWarning("Found legacy " + botName + ".xml config file, it will now be converted to new ASF V2.0 format!");
                Bot bot = new Bot(botName);
                if (bot.BotConfig == null || !bot.BotConfig.Enabled)
                {
                    Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
                }
            }
            // CONVERSION END

            // Check if we got any bots running
            OnBotShutdown();

            // Wait for signal to shutdown
            ShutdownResetEvent.WaitOne();

            // We got a signal to shutdown, consider giving user some time to read the message
            Thread.Sleep(5000);

            // This is over, cleanup only now
            WCF.StopServer();
        }