LogGenericErrorWithoutStacktrace() static private method

static private LogGenericErrorWithoutStacktrace ( string message ) : void
message string
return void
Example #1
0
        private static void Init()
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            TaskScheduler.UnobservedTaskException      += UnobservedTaskExceptionHandler;

            Directory.SetCurrentDirectory(ExecutableDirectory);

            // 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(ASFDirectory))
                    {
                        continue;
                    }

                    Directory.SetCurrentDirectory(ASFDirectory);
                    break;
                }

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

            if (!Directory.Exists(ConfigDirectory))
            {
                Logging.LogGenericErrorWithoutStacktrace("Config directory could not be found!");
                Environment.Exit(1);
            }

            if (!File.Exists(ASFExecutableFile))
            {
                return;
            }

            FileVersionInfo asfVersionInfo = FileVersionInfo.GetVersionInfo(ASFExecutableFile);

            Version asfVersion = new Version(asfVersionInfo.ProductVersion);

            if (Version == asfVersion)
            {
                return;
            }

            Logging.LogGenericErrorWithoutStacktrace(
                "Version of ASF and ConfigGenerator doesn't match!" + Environment.NewLine +
                "ASF version: " + asfVersion + " | ConfigGenerator version: " + Version + Environment.NewLine +
                Environment.NewLine +
                "Please use ConfigGenerator from the same ASF release, I'll redirect you to appropriate ASF release..."
                );

            Process.Start("https://github.com/" + SharedInfo.GithubRepo + "/releases/tag/" + asfVersion);
            Environment.Exit(1);
        }
Example #2
0
        private static void Init()
        {
            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.ASFDirectory))
                        {
                            continue;
                        }

                        Directory.SetCurrentDirectory(SharedInfo.ASFDirectory);
                        break;
                    }

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

            if (!Directory.Exists(SharedInfo.ConfigDirectory))
            {
                Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorConfigDirectoryNotFound);
                Environment.Exit(1);
            }

            if (!File.Exists(ASFExecutableFile))
            {
                return;
            }

            FileVersionInfo asfVersionInfo = FileVersionInfo.GetVersionInfo(ASFExecutableFile);
            Version         asfVersion     = new Version(asfVersionInfo.ProductVersion);

            Version cgVersion = Assembly.GetEntryAssembly().GetName().Version;

            if (asfVersion == cgVersion)
            {
                return;
            }

            Logging.LogGenericErrorWithoutStacktrace(string.Format(CGStrings.ErrorVersionMismatch, asfVersion, cgVersion));
            Process.Start("https://github.com/" + SharedInfo.GithubRepo + "/releases/tag/" + asfVersion);
            Environment.Exit(1);
        }
Example #3
0
        private void MainForm_Load(object sender, EventArgs args)
        {
            if ((sender == null) || (args == null))
            {
                Logging.LogNullError(nameof(sender) + " || " + nameof(args));
                return;
            }

            GlobalConfig globalConfig = GlobalConfig.Load(Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName));

            if (!string.IsNullOrEmpty(globalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(globalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorInvalidCurrentCulture);
                }
            }

            ASFTab = new ConfigPage(globalConfig);
            MainTab.TabPages.Add(ASFTab);

            foreach (string configFile in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json"))
            {
                string botName = Path.GetFileNameWithoutExtension(configFile);
                switch (botName)
                {
                case SharedInfo.ASF:
                case "example":
                case "minimal":
                    continue;
                }

                MainTab.TabPages.Add(new ConfigPage(BotConfig.Load(configFile)));
                Tutorial.Enabled = false;
            }

            MainTab.TabPages.AddRange(new[] { RemoveTab, RenameTab, NewTab });
            Tutorial.OnAction(Tutorial.EPhase.Start);
        }
Example #4
0
        private static void Init()
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            TaskScheduler.UnobservedTaskException      += UnobservedTaskExceptionHandler;

            Directory.SetCurrentDirectory(ExecutableDirectory);

            // 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(ASFDirectory))
                    {
                        continue;
                    }

                    Directory.SetCurrentDirectory(ASFDirectory);
                    break;
                }

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

            if (Directory.Exists(ConfigDirectory))
            {
                return;
            }

            Logging.LogGenericErrorWithoutStacktrace("Config directory could not be found!");
            Environment.Exit(1);
        }
Example #5
0
        private void MainTab_Selected(object sender, TabControlEventArgs args)
        {
            if ((sender == null) || (args == null))
            {
                Logging.LogNullError(nameof(sender) + " || " + nameof(args));
                return;
            }

            if (args.TabPage == RemoveTab)
            {
                ConfigPage configPage = OldTab as ConfigPage;
                if (configPage == null)
                {
                    MainTab.SelectedIndex = -1;
                    return;
                }

                if (configPage == ASFTab)
                {
                    MainTab.SelectedTab = ASFTab;
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorCantRemoveGlobalConfig);
                    return;
                }

                MainTab.SelectedTab = configPage;

                if (DialogBox.YesNoBox(CGStrings.Removal, CGStrings.ConfirmRemoval) != DialogResult.Yes)
                {
                    return;
                }

                MainTab.SelectedIndex = 0;
                configPage.ASFConfig.Remove();
                MainTab.TabPages.Remove(configPage);
            }
            else if (args.TabPage == RenameTab)
            {
                ConfigPage configPage = OldTab as ConfigPage;
                if (configPage == null)
                {
                    MainTab.SelectedIndex = -1;
                    return;
                }

                if (configPage == ASFTab)
                {
                    MainTab.SelectedTab = ASFTab;
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorCantRenameGlobalConfig);
                    return;
                }

                MainTab.SelectedTab = configPage;

                string input;
                if (DialogBox.InputBox(CGStrings.Rename, CGStrings.UserInputBotName, out input) != DialogResult.OK)
                {
                    return;
                }

                if (string.IsNullOrEmpty(input))
                {
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorBotNameEmpty);
                    return;
                }

                // Get rid of any potential whitespaces in bot name
                input = Regex.Replace(input, @"\s+", "");

                configPage.ASFConfig.Rename(input);
                configPage.RefreshText();
            }
            else if (args.TabPage == NewTab)
            {
                ConfigPage configPage = OldTab as ConfigPage;
                if (configPage == null)
                {
                    MainTab.SelectedIndex = -1;
                    return;
                }

                MainTab.SelectedTab = configPage;

                Tutorial.OnAction(Tutorial.EPhase.BotNickname);

                string input;
                if (DialogBox.InputBox(CGStrings.New, CGStrings.UserInputBotName, out input) != DialogResult.OK)
                {
                    return;
                }

                if (string.IsNullOrEmpty(input))
                {
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorBotNameEmpty);
                    return;
                }

                // Get rid of any potential whitespaces in bot name
                input = Regex.Replace(input, @"\s+", "");

                if (string.IsNullOrEmpty(input))
                {
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorBotNameEmpty);
                    return;
                }

                switch (input)
                {
                case SharedInfo.ASF:
                case "example":
                case "minimal":
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorNameReserved);
                    return;
                }

                if (ASFConfig.ASFConfigs.Select(config => Path.GetFileNameWithoutExtension(config.FilePath)).Any(fileNameWithoutExtension => (fileNameWithoutExtension == null) || fileNameWithoutExtension.Equals(input)))
                {
                    Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorNameAlreadyUsed);
                    return;
                }

                input = Path.Combine(SharedInfo.ConfigDirectory, input + ".json");

                ConfigPage newConfigPage = new ConfigPage(BotConfig.Load(input));
                MainTab.TabPages.Insert(MainTab.TabPages.Count - ReservedTabs, newConfigPage);
                MainTab.SelectedTab = newConfigPage;
                Tutorial.OnAction(Tutorial.EPhase.BotNicknameFinished);
            }
        }
Example #6
0
        private void MainTab_Selected(object sender, TabControlEventArgs args)
        {
            if ((sender == null) || (args == null))
            {
                Logging.LogNullError(nameof(sender) + " || " + nameof(args));
                return;
            }

            if (args.TabPage == RemoveTab)
            {
                ConfigPage configPage = OldTab as ConfigPage;
                if (configPage == null)
                {
                    MainTab.SelectedIndex = -1;
                    return;
                }

                if (configPage == ASFTab)
                {
                    MainTab.SelectedTab = ASFTab;
                    Logging.LogGenericErrorWithoutStacktrace("You can't remove global config!");
                    return;
                }

                MainTab.SelectedTab = configPage;

                if (DialogBox.YesNoBox("Removal", "Do you really want to remove this config?") != DialogResult.Yes)
                {
                    return;
                }

                MainTab.SelectedIndex = 0;
                configPage.ASFConfig.Remove();
                MainTab.TabPages.Remove(configPage);
            }
            else if (args.TabPage == RenameTab)
            {
                ConfigPage configPage = OldTab as ConfigPage;
                if (configPage == null)
                {
                    MainTab.SelectedIndex = -1;
                    return;
                }

                if (configPage == ASFTab)
                {
                    MainTab.SelectedTab = ASFTab;
                    Logging.LogGenericErrorWithoutStacktrace("You can't rename global config!");
                    return;
                }

                MainTab.SelectedTab = configPage;

                string input;
                if (DialogBox.InputBox("Rename", "Your new bot name:", out input) != DialogResult.OK)
                {
                    return;
                }

                if (string.IsNullOrEmpty(input))
                {
                    Logging.LogGenericErrorWithoutStacktrace("Your bot name is empty!");
                    return;
                }

                // Get rid of any potential whitespaces in bot name
                input = Regex.Replace(input, @"\s+", "");

                configPage.ASFConfig.Rename(input);
                configPage.RefreshText();
            }
            else if (args.TabPage == NewTab)
            {
                ConfigPage configPage = OldTab as ConfigPage;
                if (configPage == null)
                {
                    MainTab.SelectedIndex = -1;
                    return;
                }

                MainTab.SelectedTab = configPage;

                Tutorial.OnAction(Tutorial.EPhase.BotNickname);

                string input;
                if (DialogBox.InputBox("New", "Your new bot name:", out input) != DialogResult.OK)
                {
                    return;
                }

                if (string.IsNullOrEmpty(input))
                {
                    Logging.LogGenericErrorWithoutStacktrace("Your bot name is empty!");
                    return;
                }

                // Get rid of any potential whitespaces in bot name
                input = Regex.Replace(input, @"\s+", "");

                if (string.IsNullOrEmpty(input))
                {
                    Logging.LogGenericErrorWithoutStacktrace("Your bot name is empty!");
                    return;
                }

                switch (input)
                {
                case SharedInfo.ASF:
                case "example":
                case "minimal":
                    Logging.LogGenericErrorWithoutStacktrace("This name is reserved!");
                    return;
                }

                if (ASFConfig.ASFConfigs.Select(config => Path.GetFileNameWithoutExtension(config.FilePath)).Any(fileNameWithoutExtension => (fileNameWithoutExtension == null) || fileNameWithoutExtension.Equals(input)))
                {
                    Logging.LogGenericErrorWithoutStacktrace("Bot with such name exists already!");
                    return;
                }

                input = Path.Combine(SharedInfo.ConfigDirectory, input + ".json");

                ConfigPage newConfigPage = new ConfigPage(BotConfig.Load(input));
                MainTab.TabPages.Insert(MainTab.TabPages.Count - ReservedTabs, newConfigPage);
                MainTab.SelectedTab = newConfigPage;
                Tutorial.OnAction(Tutorial.EPhase.BotNicknameFinished);
            }
            else if (args.TabPage == ASFTab)
            {
                Tutorial.OnAction(Tutorial.EPhase.GlobalConfigOpened);
            }
        }