Beispiel #1
0
        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>());

                _mode.WriteFile();
                Global.MainForm.LoadModes();
                Edited = false;
                MessageBoxX.Show(i18N.Translate("Mode updated successfully"));
            }
            else
            {
                var relativePath = $"Custom\\{FilenameTextBox.Text}.txt";
                var fullName     = ModeHelper.GetFullPath(relativePath);
                if (File.Exists(fullName))
                {
                    MessageBoxX.Show(i18N.Translate("File already exists.\n Please Change the filename"));
                    return;
                }

                var mode = new Models.Mode(fullName)
                {
                    BypassChina = false,
                    Type        = 0,
                    Remark      = RemarkTextBox.Text
                };

                mode.Rule.AddRange(RuleListBox.Items.Cast <string>());

                mode.WriteFile();
                ModeHelper.Add(mode);
                MessageBoxX.Show(i18N.Translate("Mode added successfully"));
            }

            Close();
        }