private void MainForm_Load(object sender, EventArgs e) { if (sender == null || e == null) { return; } ASFTab = new ConfigPage(GlobalConfig.Load(Path.Combine(Program.ConfigDirectory, Program.GlobalConfigFile))); MainTab.TabPages.Add(ASFTab); foreach (var configFile in Directory.EnumerateFiles(Program.ConfigDirectory, "*.json")) { string botName = Path.GetFileNameWithoutExtension(configFile); switch (botName) { case Program.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); }
private void MainForm_Load(object sender, EventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } ASFTab = new ConfigPage(GlobalConfig.Load(Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName))); 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); }
private void MainTab_Selected(object sender, TabControlEventArgs e) { if (sender == null || e == null) { return; } if (e.TabPage == RemoveTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericError("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 (e.TabPage == RenameTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericError("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.LogGenericError("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 (e.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.LogGenericError("Your bot name is empty!"); return; } // Get rid of any potential whitespaces in bot name input = Regex.Replace(input, @"\s+", ""); foreach (ASFConfig config in ASFConfig.ASFConfigs) { if (Path.GetFileNameWithoutExtension(config.FilePath).Equals(input)) { Logging.LogGenericError("Bot with such name exists already!"); return; } } input = Path.Combine(Program.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 (e.TabPage == ASFTab) { Tutorial.OnAction(Tutorial.EPhase.GlobalConfigOpened); } }
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); } }
private void MainTab_Selected(object sender, TabControlEventArgs e) { if (sender == null || e == null) { return; } if (e.TabPage == RemoveTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericError("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 (e.TabPage == RenameTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericError("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.LogGenericError("Your bot name is empty!"); return; } configPage.ASFConfig.Rename(input); configPage.RefreshText(); } else if (e.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.LogGenericError("Your bot name is empty!"); return; } foreach (ASFConfig config in ASFConfig.ASFConfigs) { if (Path.GetFileNameWithoutExtension(config.FilePath).Equals(input)) { Logging.LogGenericError("Bot with such name exists already!"); return; } } input = Path.Combine(Program.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 (e.TabPage == ASFTab) { Tutorial.OnAction(Tutorial.EPhase.GlobalConfigOpened); } }
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 (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(Program.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); } }