Example #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (presetBox.SelectedIndex >= 0)
            {
                string selectedPreset     = presetBox.SelectedItem.ToString();
                string selectedPresetName = selectedPreset.Split('|')[0].Trim();

                PresetClass prclass = new PresetClass();
                Preset      preset  = prclass.GetByName(selectedPresetName);
                Preset      p       = Pr.GetByName(selectedPresetName);

                if (!Pr.PresetIsNull(p))
                {
                    // Remove the preset file in case it's an user preset!
                    if (Pr.PresetIsNull(preset))
                    {
                        // It only exists inside the Pr class, which means it's a user element
                        if (MessageBox.Show($"Are you sure you want to remove {selectedPresetName}?", "Remove?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            // Remove it from the list
                            presetBox.Items.RemoveAt(presetBox.SelectedIndex);
                            Pr.Presets.Remove(p);

                            File.Delete(UserPresets);
                            foreach (var pre in Pr.Presets)
                            {
                                if (pre.isUsermade)
                                {
                                    // Print to file
                                    File.AppendAllText(UserPresets, pre.ToSaveableString());
                                }
                            }

                            // Remove from file
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can't remove this built in preset!", "Can't remove!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show($"An error occured when trying to remove a preset! Seems like the preset does not exist! ({selectedPresetName})!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }