X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmAddPreset.cs;h=ca726c09b1fd5c2b5b3c41d0873168f39c4810c2;hb=d646c74eab71ce803181537759b19c9b2726fc0a;hp=f6a51fc6a8ea3f3c9af55db304488767fe96b032;hpb=89f1a81858a35ecf5bccf71bc44b066bb3c3bbc3;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs index f6a51fc6..ca726c09 100644 --- a/win/C#/frmAddPreset.cs +++ b/win/C#/frmAddPreset.cs @@ -5,74 +5,45 @@ It may be used under the terms of the GNU General Public License. */ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Text; -using System.Windows.Forms; -using System.IO; using System.Windows.Forms; namespace Handbrake { public partial class frmAddPreset : Form { - private frmMain frmMainWindow; - public frmAddPreset(frmMain fmw) + private readonly frmMain frmMainWindow; + readonly Presets.PresetsHandler presetCode; + private readonly string query = ""; + + public frmAddPreset(frmMain fmw, string query_string, Presets.PresetsHandler presetHandler) { InitializeComponent(); frmMainWindow = fmw; + presetCode = presetHandler; + this.query = query_string; } private void btn_add_Click(object sender, EventArgs e) { - if (txt_preset_name.Text.Trim() == "") - MessageBox.Show("You have not entered a name for the preset.","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else if (txt_preset_name.Text.Trim().Contains("--")) - MessageBox.Show("The preset name can not contain two dashes '--'","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else - { - Functions.Common hb_common_func = new Functions.Common(); + Boolean pictureSettings = false; + if (check_pictureSettings.Checked) + pictureSettings = true; - Boolean already_exists = false; - foreach (TreeNode treenode in frmMainWindow.treeView_presets.Nodes) - { - if (treenode.ToString().Equals("TreeNode: --" + txt_preset_name.Text)) - already_exists = true; - } - - if (already_exists == true) - MessageBox.Show("Sorry, a preset with this name already exists", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else - { - 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); + if (presetCode.addPreset(txt_preset_name.Text.Trim(), query, pictureSettings)) + { + TreeNode preset_treeview = new TreeNode(txt_preset_name.Text.Trim()) { ForeColor = Color.Black }; + frmMainWindow.treeView_presets.Nodes.Add(preset_treeview); - // 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(); } } - } -} - + private void btn_cancel_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} \ No newline at end of file