1 /* frmAddPreset.cs $
\r
3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
9 using System.ComponentModel;
\r
11 using System.Drawing;
\r
13 using System.Windows.Forms;
\r
15 using System.Windows.Forms;
\r
19 public partial class frmAddPreset : Form
\r
21 private frmMain frmMainWindow;
\r
22 public frmAddPreset(frmMain fmw)
\r
24 InitializeComponent();
\r
25 frmMainWindow = fmw;
\r
28 private void btn_add_Click(object sender, EventArgs e)
\r
30 if (txt_preset_name.Text.Trim() == "")
\r
31 MessageBox.Show("You have not entered a name for the preset.","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
32 else if (txt_preset_name.Text.Trim().Contains("--"))
\r
33 MessageBox.Show("The preset name can not contain two dashes '--'","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
36 Functions.Common hb_common_func = new Functions.Common();
\r
38 Boolean already_exists = false;
\r
39 foreach (TreeNode treenode in frmMainWindow.treeView_presets.Nodes)
\r
41 if (treenode.ToString().Equals("TreeNode: --" + txt_preset_name.Text))
\r
42 already_exists = true;
\r
45 if (already_exists == true)
\r
46 MessageBox.Show("Sorry, a preset with this name already exists", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
49 string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";
\r
52 // Create a StreamWriter and open the file
\r
53 StreamWriter line = File.AppendText(userPresets);
\r
55 // Generate and write the preset string to the file
\r
56 String query = hb_common_func.GenerateTheQuery(frmMainWindow);
\r
57 String preset = "+ " + txt_preset_name.Text + ": " + query;
\r
58 line.WriteLine(preset);
\r
63 MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
65 catch (Exception exc)
\r
67 MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
69 frmMainWindow.loadPresetPanel();
\r