OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmAddPreset.cs
1 /*  frmAddPreset.cs $\r
2         \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
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.ComponentModel;\r
10 using System.Data;\r
11 using System.Drawing;\r
12 using System.Text;\r
13 using System.Windows.Forms;\r
14 using System.IO;\r
15 using System.Windows.Forms;\r
16 \r
17 namespace Handbrake\r
18 {\r
19     public partial class frmAddPreset : Form\r
20     {\r
21         private frmMain frmMainWindow;\r
22         public frmAddPreset(frmMain fmw)\r
23         {\r
24             InitializeComponent();\r
25             frmMainWindow = fmw;\r
26         }\r
27 \r
28         private void btn_add_Click(object sender, EventArgs e)\r
29         {\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
34             else\r
35             {\r
36                 Functions.Common hb_common_func = new Functions.Common();\r
37 \r
38                 Boolean already_exists = false;\r
39                 foreach (TreeNode treenode in frmMainWindow.treeView_presets.Nodes)\r
40                 {\r
41                     if (treenode.ToString().Equals("TreeNode: --" + txt_preset_name.Text))\r
42                         already_exists = true;  \r
43                 }\r
44 \r
45                 if (already_exists == true)\r
46                     MessageBox.Show("Sorry, a preset with this name already exists", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
47                 else\r
48                 {\r
49                     string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";\r
50                     try\r
51                     {\r
52                         // Create a StreamWriter and open the file\r
53                         StreamWriter line = File.AppendText(userPresets);\r
54 \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
59 \r
60                         // close the stream\r
61                         line.Close();\r
62                         line.Dispose();\r
63                         MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
64                     }\r
65                     catch (Exception exc)\r
66                     {\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
68                     }\r
69                     frmMainWindow.loadPresetPanel();\r
70                     this.Close();\r
71                 }\r
72             }\r
73         }\r
74     }\r
75 }\r
76 \r
77 \r
78 \r