diff options
Diffstat (limited to 'win/C#/frmAddPreset.cs')
-rw-r--r-- | win/C#/frmAddPreset.cs | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs index 2beabc53c..f6a51fc6a 100644 --- a/win/C#/frmAddPreset.cs +++ b/win/C#/frmAddPreset.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Text;
using System.Windows.Forms;
using System.IO;
+using System.Windows.Forms;
namespace Handbrake
{
@@ -34,28 +35,40 @@ namespace Handbrake {
Functions.Common hb_common_func = new Functions.Common();
- string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";
- try
+ Boolean already_exists = false;
+ foreach (TreeNode treenode in frmMainWindow.treeView_presets.Nodes)
{
- // Create a StreamWriter and open the file
- StreamWriter line = File.AppendText(userPresets);
-
- // Generate and write the preset string to the file
- String query = hb_common_func.GenerateTheQuery(frmMainWindow);
- String preset = "+ " + txt_preset_name.Text + ": " + query;
- line.WriteLine(preset);
-
- // close the stream
- line.Close();
- line.Dispose();
- MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+ if (treenode.ToString().Equals("TreeNode: --" + txt_preset_name.Text))
+ already_exists = true;
}
- catch (Exception exc)
+
+ if (already_exists == true)
+ MessageBox.Show("Sorry, a preset with this name already exists", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ else
{
- 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);
+ string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";
+ try
+ {
+ // Create a StreamWriter and open the file
+ StreamWriter line = File.AppendText(userPresets);
+
+ // Generate and write the preset string to the file
+ String query = hb_common_func.GenerateTheQuery(frmMainWindow);
+ String preset = "+ " + txt_preset_name.Text + ": " + query;
+ line.WriteLine(preset);
+
+ // close the stream
+ line.Close();
+ line.Dispose();
+ MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+ }
+ catch (Exception exc)
+ {
+ 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);
+ }
+ frmMainWindow.loadPresetPanel();
+ this.Close();
}
- frmMainWindow.loadPresetPanel();
- this.Close();
}
}
}
|