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 \r
16 namespace Handbrake\r
17 {\r
18     public partial class frmAddPreset : Form\r
19     {\r
20         private frmMain frmMainWindow;\r
21         public frmAddPreset(frmMain fmw)\r
22         {\r
23             InitializeComponent();\r
24             frmMainWindow = fmw;\r
25         }\r
26 \r
27         private void btn_add_Click(object sender, EventArgs e)\r
28         {\r
29             if (txt_preset_name.Text.Trim() == "")\r
30                 MessageBox.Show("You have not entered a name for the preset.","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
31             else if (txt_preset_name.Text.Trim().Contains("--"))\r
32                 MessageBox.Show("The preset name can not contain two dashes '--'","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
33             else\r
34             {\r
35                 Functions.Common hb_common_func = new Functions.Common();\r
36 \r
37                 string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";\r
38                 try\r
39                 {\r
40                     // Create a StreamWriter and open the file\r
41                     StreamWriter line = File.AppendText(userPresets);\r
42 \r
43                     // Generate and write the preset string to the file\r
44                     String query = hb_common_func.GenerateTheQuery(frmMainWindow);\r
45                     String preset = "+ " + txt_preset_name.Text + ":  " + query;\r
46                     line.WriteLine(preset);\r
47 \r
48                     // close the stream\r
49                     line.Close();\r
50                     line.Dispose();\r
51                     MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
52                 }\r
53                 catch (Exception exc)\r
54                 {\r
55                     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
56                 }\r
57                 frmMainWindow.loadPresetPanel();\r
58                 this.Close();\r
59             }\r
60         }\r
61     }\r
62 }\r
63 \r
64 \r
65 \r