OSDN Git Service

cf9b5135b3428f97891ed3c7d969d064f56348fe
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmAddPreset.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 using System.IO;\r
9 \r
10 namespace Handbrake\r
11 {\r
12     public partial class frmAddPreset : Form\r
13     {\r
14         private frmMain frmMainWindow;\r
15         public frmAddPreset(frmMain fmw)\r
16         {\r
17             InitializeComponent();\r
18             frmMainWindow = fmw;\r
19         }\r
20 \r
21         private void btn_add_Click(object sender, EventArgs e)\r
22         {\r
23             if (txt_preset_name.Text.Trim() == "")\r
24                 MessageBox.Show("You have not entered a name for the preset.","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
25             else if (txt_preset_name.Text.Trim().Contains("--"))\r
26                 MessageBox.Show("The preset name can not contain two dashes '--'","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
27             else\r
28             {\r
29                 Functions.Common hb_common_func = new Functions.Common();\r
30 \r
31                 string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";\r
32                 try\r
33                 {\r
34                     // Create a StreamWriter and open the file\r
35                     StreamWriter line = File.AppendText(userPresets);\r
36 \r
37                     // Generate and write the preset string to the file\r
38                     String query = hb_common_func.GenerateTheQuery(frmMainWindow);\r
39                     String preset = "+ " + txt_preset_name.Text + ":  " + query;\r
40                     line.WriteLine(preset);\r
41 \r
42                     // close the stream\r
43                     line.Close();\r
44                     line.Dispose();\r
45                     MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
46                 }\r
47                 catch (Exception exc)\r
48                 {\r
49                     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
50                 }\r
51                 frmMainWindow.loadPresetPanel();\r
52                 this.Close();\r
53             }\r
54         }\r
55     }\r
56 }\r
57 \r
58 \r
59 \r