public void ControlButton_Click(object sender, EventArgs e) { if (RuleListBox.Items.Count == 0) { MessageBoxX.Show(i18N.Translate("Unable to add empty rule")); return; } if (string.IsNullOrWhiteSpace(RemarkTextBox.Text)) { MessageBoxX.Show(i18N.Translate("Please enter a mode remark")); return; } if (string.IsNullOrWhiteSpace(FilenameTextBox.Text)) { MessageBoxX.Show(i18N.Translate("Please enter a mode filename")); return; } if (_mode != null) { _mode.Remark = RemarkTextBox.Text; _mode.Rule.Clear(); _mode.Rule.AddRange(RuleListBox.Items.Cast <string>()); ModeHelper.WriteFile(_mode); Global.MainForm.InitMode(); Edited = false; MessageBoxX.Show(i18N.Translate("Mode updated successfully")); } else { var fullName = ModeHelper.GetFullPath(FilenameTextBox.Text + ".txt"); if (File.Exists(fullName)) { MessageBoxX.Show(i18N.Translate("File already exists.\n Please Change the filename")); return; } var mode = new Models.Mode { BypassChina = false, FileName = FilenameTextBox.Text, Type = 0, Remark = RemarkTextBox.Text }; mode.Rule.AddRange(RuleListBox.Items.Cast <string>()); ModeHelper.WriteFile(mode); ModeHelper.Add(mode); MessageBoxX.Show(i18N.Translate("Mode added successfully")); } Close(); }