From e9a2f0eadfefe9f21b1d677c8c53e3a0c2495874 Mon Sep 17 00:00:00 2001 From: sr55 Date: Tue, 27 Nov 2007 21:27:19 +0000 Subject: WinGui: - Removed some duplicate code and fixed a few small bugs. - Changed the layout of the code slightly. - Changed the DVD parser to use verbose CLI which can be displayed on the DVD information log page. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1081 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/frmDvdInfo.Designer.cs | 4 +- win/C#/frmMain.Designer.cs | 3 +- win/C#/frmMain.cs | 929 ++++++++++++++++++++---------------------- win/C#/frmReadDVD.cs | 2 +- 4 files changed, 455 insertions(+), 483 deletions(-) diff --git a/win/C#/frmDvdInfo.Designer.cs b/win/C#/frmDvdInfo.Designer.cs index c80add346..88f5cf81b 100644 --- a/win/C#/frmDvdInfo.Designer.cs +++ b/win/C#/frmDvdInfo.Designer.cs @@ -93,9 +93,9 @@ namespace Handbrake this.label1.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.Location = new System.Drawing.Point(59, 25); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(127, 13); + this.label1.Size = new System.Drawing.Size(154, 13); this.label1.TabIndex = 40; - this.label1.Text = "Media Information"; + this.label1.Text = "Media Information Log"; // // ToolTip // diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index c67ef7137..9ff14a323 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -357,8 +357,7 @@ namespace Handbrake "Mpeg 4", "Xvid", "H.264", - "H.264 (iPod)", - "H.264 Baseline 1.3"}); + "H.264 (iPod)"}); this.drp_videoEncoder.Location = new System.Drawing.Point(99, 20); this.drp_videoEncoder.Name = "drp_videoEncoder"; this.drp_videoEncoder.Size = new System.Drawing.Size(156, 21); diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 094587357..6c6e3489a 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -83,19 +83,25 @@ namespace Handbrake { lblStatus.Text = "Updaing Presets ..."; Application.DoEvents(); - updatePresets(); + grabCLIPresets(); Thread.Sleep(200); } + // Load the presets for the preset box + updatePresets(); + // Now load the users default if required. (Will overide the above setting) if (Properties.Settings.Default.defaultSettings == "Checked") { lblStatus.Text = "Loading User Default Settings..."; Application.DoEvents(); - loadNormalPreset(); loadUserDefaults(); Thread.Sleep(100); } + else + { + loadNormalPreset(); + } // Enable or disable tooltips if (Properties.Settings.Default.tooltipEnable == "Checked") @@ -107,7 +113,11 @@ namespace Handbrake } // Hide the preset bar if required. - hidePresetBar(); + if (Properties.Settings.Default.hidePresets == "Checked") + { + mnu_showPresets.Visible = true; + this.Width = 591; + } //Finished Loading lblStatus.Text = "Loading Complete!"; @@ -140,17 +150,6 @@ namespace Handbrake splash.Close(); // Then close. } - private void loadNormalPreset() - { - ListViewItem item = listview_presets.FindItemWithText("Normal"); - - if (item != null) - { - //listview_presets.SelectedItems.Clear(); - item.Selected = true; - } - } - private void loadUserDefaults() { string userDefaults = Properties.Settings.Default.defaultUserSettings; @@ -167,19 +166,8 @@ namespace Handbrake } catch (Exception exc) { - MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); - MessageBox.Show(exc.ToString()); - } - } - - private void hidePresetBar() - { - if (Properties.Settings.Default.hidePresets == "Checked") - { - mnu_showPresets.Visible = true; - this.Width = 591; + MessageBox.Show("Unable to load user Default Settings. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } - } #endregion @@ -304,19 +292,14 @@ namespace Handbrake private void mnu_presetReset_Click(object sender, EventArgs e) { listview_presets.Items.Clear(); + grabCLIPresets(); updatePresets(); MessageBox.Show("Presets have been updated", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void mnu_SelectDefault_Click(object sender, EventArgs e) { - ListViewItem item = listview_presets.FindItemWithText("Normal"); - - if (item != null) - { - listview_presets.SelectedItems.Clear(); - item.Selected = true; - } + loadNormalPreset(); } #endregion @@ -378,7 +361,7 @@ namespace Handbrake #endregion // -------------------------------------------------------------- - // Buttons on the main Window + // Buttons on the main Window and items that require actions // -------------------------------------------------------------- #region Buttons @@ -393,30 +376,21 @@ namespace Handbrake { DVD_Open.ShowDialog(); filename = DVD_Open.SelectedPath; - if (filename != "") - { - Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); - text_source.Text = filename; - frmRD.ShowDialog(); - } } else { ISO_Open.ShowDialog(); filename = ISO_Open.FileName; - if (filename != "") - { - Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); - text_source.Text = filename; - frmRD.ShowDialog(); - } } - // Check if there was titles in the dvd title dropdown - if (filename == "") + if (filename != "") { - text_source.Text = "Click 'Browse' to continue"; + Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); + text_source.Text = filename; + frmRD.ShowDialog(); } + else + text_source.Text = "Click 'Browse' to continue"; // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user. if (drp_dvdtitle.Items.Count == 0) @@ -461,344 +435,117 @@ namespace Handbrake QueryEditorText.Text = ""; } - private void btn_queue_Click(object sender, EventArgs e) - { - - if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "") - MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else - { - string query; - if (QueryEditorText.Text == "") - { - query = GenerateTheQuery(); - } - else - { - query = QueryEditorText.Text; - } - queueWindow.list_queue.Items.Add(query); - queueWindow.Show(); - } - } - private void btn_copy_Click(object sender, EventArgs e) { if (QueryEditorText.Text != "") Clipboard.SetText(QueryEditorText.Text, TextDataFormat.Text); } - private void showQueue() - { - queueWindow.Show(); - } - #endregion - // -------------------------------------------------------------- - // Main Window Preset System - // -------------------------------------------------------------- - - #region Preset System + #region frmMain Actions - // Import Current Presets - private void updatePresets() + private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e) { - string[] presets = new string[17]; - presets[0] = "Animation"; - presets[1] = "AppleTV"; - presets[2] = "Bedlam"; - presets[3] = "Blind"; - presets[4] = "Broke"; - presets[5] = "Classic"; - presets[6] = "Constant Quality Rate"; - presets[7] = "Deux Six Quatre"; - presets[8] = "Film"; - presets[9] = "iPhone / iPod Touch"; - presets[10] = "iPod High-Rez"; - presets[11] = "iPod Low-Rez"; - presets[12] = "Normal"; - presets[13] = "PS3"; - presets[14] = "PSP"; - presets[15] = "QuickTime"; - presets[16] = "Television"; - - ListViewItem preset_listview = new ListViewItem(); - string[] presetList = new string[1]; + // Reset some values on the form + lbl_Aspect.Text = "Select a Title"; + lbl_RecomendedCrop.Text = "Select a Title"; + drop_chapterStart.Items.Clear(); + drop_chapterFinish.Items.Clear(); + QueryEditorText.Text = ""; - foreach (string preset in presets) + // If the dropdown is set to automatic nothing else needs to be done. + // Otheriwse if its not, title data has to be loased from parsing. + if (drp_dvdtitle.Text != "Automatic") { - presetList[0] = preset; - preset_listview = new ListViewItem(presetList); - - // Now Fill Out List View with Items - listview_presets.Items.Add(preset_listview); - } + Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title; - string appPath = Application.StartupPath.ToString() + "\\"; - string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " --preset-list >" + '"' + appPath + "presets.dat" + '"' + " 2>&1" + '"'; - Process hbproc = Process.Start("CMD.exe", strCmdLine); - hbproc.WaitForExit(); - hbproc.Dispose(); - hbproc.Close(); + // Set the Aspect Ratio + lbl_Aspect.Text = selectedTitle.AspectRatio.ToString(); - } + // Set the Recommended Cropping values + lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]); - // Buttons - private void btn_setDefault_Click(object sender, EventArgs e) - { - String query = GenerateTheQuery(); - Properties.Settings.Default.defaultUserSettings = query; - // Save the new default Settings - Properties.Settings.Default.Save(); - MessageBox.Show("New default settings saved.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - } + // Populate the Start chapter Dropdown + drop_chapterStart.Items.Clear(); + drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray()); + if (drop_chapterStart.Items.Count > 0) + { + drop_chapterStart.Text = drop_chapterStart.Items[0].ToString(); + } - // Preset Selection - private void listview_presets_SelectedIndexChanged(object sender, EventArgs e) - { + // Populate the Final Chapter Dropdown + drop_chapterFinish.Items.Clear(); + drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray()); + if (drop_chapterFinish.Items.Count > 0) + { + drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(); + } - string selectedPreset = null; - ListView.SelectedListViewItemCollection name = null; - name = listview_presets.SelectedItems; + // Populate the Audio Channels Dropdown + drp_audioChannels.Items.Clear(); + drp_audioChannels.Items.Add("Automatic"); + drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray()); + if (drp_audioChannels.Items.Count > 0) + { + drp_audioChannels.Text = drp_audioChannels.Items[0].ToString(); + } - if (listview_presets.SelectedItems.Count != 0) - selectedPreset = name[0].SubItems[0].Text; + // Populate the Subtitles dropdown + drp_subtitle.Items.Clear(); + drp_subtitle.Items.Add("None"); + drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray()); + if (drp_subtitle.Items.Count > 0) + { + drp_subtitle.Text = drp_subtitle.Items[0].ToString(); + } + } + } - try + private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e) + { + drop_chapterStart.BackColor = Color.White; + QueryEditorText.Text = ""; + if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto")) { - string appPath = Application.StartupPath.ToString() + "\\"; - StreamReader presetInput = new StreamReader(appPath + "presets.dat"); - - while (!presetInput.EndOfStream) + try { - if ((char)presetInput.Peek() == '+') - { - string preset = presetInput.ReadLine().Replace("+ ", ""); - Regex r = new Regex("(: )"); // Split on hyphens. - string[] presetName = r.Split(preset); - - if (selectedPreset == presetName[0]) - { - // Need to disable anamorphic now, otherwise it may overide the width / height values later. - CheckPixelRatio.CheckState = CheckState.Unchecked; - - // Send the query from the file to the Query Parser class - Functions.QueryParser presetQuery = Functions.QueryParser.Parse(preset); - - // Now load the preset - presetLoader(presetQuery, selectedPreset); - } + int chapterFinish = int.Parse(drop_chapterFinish.Text); + int chapterStart = int.Parse(drop_chapterStart.Text); - } - else + if (chapterFinish < chapterStart) { - presetInput.ReadLine(); + drop_chapterStart.BackColor = Color.LightCoral; } } - } - catch (Exception exc) - { - MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + catch (Exception) + { + drop_chapterStart.BackColor = Color.LightCoral; + } } } - #endregion - - //--------------------------------------------------- - // Encode / Cancel Buttons - // Encode Progress Text Handler - //--------------------------------------------------- - - #region Encode/CLI - - Functions.CLI process = new Functions.CLI(); - - private void btn_encode_Click(object sender, EventArgs e) + private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e) { - if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "") - MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else + drop_chapterFinish.BackColor = Color.White; + QueryEditorText.Text = ""; + if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto")) { - btn_eCancel.Enabled = true; - String query = ""; - if (QueryEditorText.Text == "") + try { - query = GenerateTheQuery(); + int chapterFinish = int.Parse(drop_chapterFinish.Text); + int chapterStart = int.Parse(drop_chapterStart.Text); + + if (chapterFinish < chapterStart) + { + drop_chapterFinish.BackColor = Color.LightCoral; + } } - else + catch (Exception) { - query = QueryEditorText.Text; - } - - ThreadPool.QueueUserWorkItem(procMonitor, query); - lbl_encode.Visible = true; - lbl_encode.Text = "Encoding in Progress"; - } - } - - private void btn_eCancel_Click(object sender, EventArgs e) - { - process.killCLI(); - process.setNull(); - lbl_encode.Text = "Encoding Canceled"; - } - - [DllImport("user32.dll")] - public static extern void LockWorkStation(); - [DllImport("user32.dll")] - public static extern int ExitWindowsEx(int uFlags, int dwReason); - - private void procMonitor(object state) - { - // Make sure we are not already encoding and if we are then display an error. - if (hbProc != null) - { - MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - else - { - hbProc = process.runCli(this, (string)state, false, false, false, false); - hbProc.WaitForExit(); - - try - { - /* - //***************************************************************************************** - // BUG! - // When the below code is used and standard error is set to true, hbcli is outputing a - // video stream which has mild corruption issues every few seconds. - // Maybe an issue with the Parser cauing the CLI to hickup/pause? - //***************************************************************************************** - - - Parsing.Parser encode = new Parsing.Parser(hbProc.StandardOutput.BaseStream); - encode.OnEncodeProgress += encode_OnEncodeProgress; - while (!encode.EndOfStream) - { - encode.ReadLine(); - } - - hbProc.WaitForExit(); - process.closeCLI(); - */ - - } - catch (Exception exc) - { - // Do nothing - MessageBox.Show(exc.ToString()); - } - - - setEncodeLabel(); - hbProc = null; - - // Do something whent he encode ends. - switch (Properties.Settings.Default.CompletionOption) - { - case "Shutdown": - System.Diagnostics.Process.Start("Shutdown", "-s -t 60"); - break; - case "Log Off": - ExitWindowsEx(0, 0); - break; - case "Suspend": - Application.SetSuspendState(PowerState.Suspend, true, true); - break; - case "Hibernate": - Application.SetSuspendState(PowerState.Hibernate, true, true); - break; - case "Lock System": - LockWorkStation(); - break; - case "Quit HandBrake": - Application.Exit(); - break; - default: - break; - } - } - } - - private delegate void UpdateUIHandler(); - - private void setEncodeLabel() - { - if (this.InvokeRequired) - { - this.BeginInvoke(new UpdateUIHandler(setEncodeLabel)); - return; - } - lbl_encode.Text = "Encoding Finished"; - } - - private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining) - { - - if (this.InvokeRequired) - { - this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress), - new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining }); - return; - } - lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining); - } - - #endregion - - //--------------------------------------------------- - // Items that require actions on frmMain - //--------------------------------------------------- - - #region frmMain Actions - - private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e) - { - drop_chapterStart.BackColor = Color.White; - QueryEditorText.Text = ""; - if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto")) - { - try - { - int chapterFinish = int.Parse(drop_chapterFinish.Text); - int chapterStart = int.Parse(drop_chapterStart.Text); - - if (chapterFinish < chapterStart) - { - drop_chapterStart.BackColor = Color.LightCoral; - } - } - catch (Exception) - { - drop_chapterStart.BackColor = Color.LightCoral; - } - } - - - } - - private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e) - { - drop_chapterFinish.BackColor = Color.White; - QueryEditorText.Text = ""; - if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto")) - { - try - { - int chapterFinish = int.Parse(drop_chapterFinish.Text); - int chapterStart = int.Parse(drop_chapterStart.Text); - - if (chapterFinish < chapterStart) - { - drop_chapterFinish.BackColor = Color.LightCoral; - } - } - catch (Exception) - { - drop_chapterFinish.BackColor = Color.LightCoral; + drop_chapterFinish.BackColor = Color.LightCoral; } } } @@ -928,10 +675,7 @@ namespace Handbrake text_right.Enabled = false; text_top.Enabled = false; text_bottom.Enabled = false; - text_left.Text = ""; - text_right.Text = ""; - text_top.Text = ""; - text_bottom.Text = ""; + if (lbl_RecomendedCrop.Text != "Select a Title") { @@ -942,6 +686,13 @@ namespace Handbrake text_top.Text = temp[0]; text_bottom.Text = temp[1]; } + else + { + text_left.Text = ""; + text_right.Text = ""; + text_top.Text = ""; + text_bottom.Text = ""; + } } if ((string)drp_crop.SelectedItem == "No Crop") @@ -1008,11 +759,6 @@ namespace Handbrake private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e) { - - //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch - - drp_audioMixDown.Items.Clear(); - if (drp_audioCodec.Text == "AAC") { drp_audioMixDown.Items.Clear(); @@ -1035,162 +781,387 @@ namespace Handbrake drp_audioBitrate.Items.Add("160"); } - else + else + { + drp_audioMixDown.Items.Clear(); + drp_audioMixDown.Items.Add("Stereo"); + drp_audioMixDown.Items.Add("Dolby Surround"); + drp_audioMixDown.Items.Add("Dolby Pro Logic II"); + + drp_audioBitrate.Items.Clear(); + drp_audioBitrate.Items.Add("32"); + drp_audioBitrate.Items.Add("40"); + drp_audioBitrate.Items.Add("48"); + drp_audioBitrate.Items.Add("56"); + drp_audioBitrate.Items.Add("64"); + drp_audioBitrate.Items.Add("80"); + drp_audioBitrate.Items.Add("86"); + drp_audioBitrate.Items.Add("112"); + drp_audioBitrate.Items.Add("128"); + drp_audioBitrate.Items.Add("160"); + drp_audioBitrate.Items.Add("192"); + drp_audioBitrate.Items.Add("224"); + drp_audioBitrate.Items.Add("256"); + drp_audioBitrate.Items.Add("320"); + } + } + + private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e) + { + if ((drp_audioCodec.Text == "AAC") && (drp_audioMixDown.Text == "6 Channel Discrete")) + { + drp_audioBitrate.Items.Clear(); + drp_audioBitrate.Items.Add("32"); + drp_audioBitrate.Items.Add("40"); + drp_audioBitrate.Items.Add("48"); + drp_audioBitrate.Items.Add("56"); + drp_audioBitrate.Items.Add("64"); + drp_audioBitrate.Items.Add("80"); + drp_audioBitrate.Items.Add("86"); + drp_audioBitrate.Items.Add("112"); + drp_audioBitrate.Items.Add("128"); + drp_audioBitrate.Items.Add("160"); + drp_audioBitrate.Items.Add("192"); + drp_audioBitrate.Items.Add("224"); + drp_audioBitrate.Items.Add("256"); + drp_audioBitrate.Items.Add("320"); + drp_audioBitrate.Items.Add("384"); + } + } + + private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e) + { + if (Check_ChapterMarkers.Checked) + { + string destination = text_destination.Text; + destination = destination.Replace(".mp4", ".m4v"); + text_destination.Text = destination; + } + else + { + string destination = text_destination.Text; + destination = destination.Replace(".m4v", ".mp4"); + text_destination.Text = destination; + } + } + + private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e) + { + //Turn off some options which are H.264 only when the user selects a non h.264 encoder + if (!drp_videoEncoder.Text.Contains("H.264")) + { + check_turbo.CheckState = CheckState.Unchecked; + CheckCRF.CheckState = CheckState.Unchecked; + CheckCRF.Enabled = false; + check_turbo.Enabled = false; + h264Tab.Enabled = false; + rtf_h264advanced.Text = ""; + } + else + { + CheckCRF.Enabled = true; + if (check_2PassEncode.CheckState == CheckState.Checked) + { + check_turbo.Enabled = true; + } + h264Tab.Enabled = true; + } + + } + + #endregion + + // -------------------------------------------------------------- + // Main Window Preset System + // -------------------------------------------------------------- + + #region Preset System + + // Import Current Presets + private void updatePresets() + { + string[] presets = new string[17]; + presets[0] = "Animation"; + presets[1] = "AppleTV"; + presets[2] = "Bedlam"; + presets[3] = "Blind"; + presets[4] = "Broke"; + presets[5] = "Classic"; + presets[6] = "Constant Quality Rate"; + presets[7] = "Deux Six Quatre"; + presets[8] = "Film"; + presets[9] = "iPhone / iPod Touch"; + presets[10] = "iPod High-Rez"; + presets[11] = "iPod Low-Rez"; + presets[12] = "Normal"; + presets[13] = "PS3"; + presets[14] = "PSP"; + presets[15] = "QuickTime"; + presets[16] = "Television"; + + ListViewItem preset_listview = new ListViewItem(); + string[] presetList = new string[1]; + + foreach (string preset in presets) + { + presetList[0] = preset; + preset_listview = new ListViewItem(presetList); + + // Now Fill Out List View with Items + listview_presets.Items.Add(preset_listview); + } + } + + private void grabCLIPresets() + { + string appPath = Application.StartupPath.ToString() + "\\"; + string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " --preset-list >" + '"' + appPath + "presets.dat" + '"' + " 2>&1" + '"'; + Process hbproc = Process.Start("CMD.exe", strCmdLine); + hbproc.WaitForExit(); + hbproc.Dispose(); + hbproc.Close(); + } + + // Function to select the default preset. + private void loadNormalPreset() + { + ListViewItem item = listview_presets.FindItemWithText("Normal"); + + if (item != null) + { + item.Selected = true; + } + } + + // Buttons + private void btn_setDefault_Click(object sender, EventArgs e) + { + String query = GenerateTheQuery(); + Properties.Settings.Default.defaultUserSettings = query; + // Save the new default Settings + Properties.Settings.Default.Save(); + MessageBox.Show("New default settings saved.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + } + + // Preset Selection + private void listview_presets_SelectedIndexChanged(object sender, EventArgs e) + { + + string selectedPreset = null; + ListView.SelectedListViewItemCollection name = null; + name = listview_presets.SelectedItems; + + if (listview_presets.SelectedItems.Count != 0) + selectedPreset = name[0].SubItems[0].Text; + + try + { + string appPath = Application.StartupPath.ToString() + "\\"; + StreamReader presetInput = new StreamReader(appPath + "presets.dat"); + + while (!presetInput.EndOfStream) + { + if ((char)presetInput.Peek() == '+') + { + string preset = presetInput.ReadLine().Replace("+ ", ""); + Regex r = new Regex("(: )"); // Split on hyphens. + string[] presetName = r.Split(preset); + + if (selectedPreset == presetName[0]) + { + // Need to disable anamorphic now, otherwise it may overide the width / height values later. + CheckPixelRatio.CheckState = CheckState.Unchecked; + + // Send the query from the file to the Query Parser class + Functions.QueryParser presetQuery = Functions.QueryParser.Parse(preset); + + // Now load the preset + presetLoader(presetQuery, selectedPreset); + } + + } + else + { + presetInput.ReadLine(); + } + } + } + catch (Exception exc) { - drp_audioMixDown.Items.Clear(); - drp_audioMixDown.Items.Add("Stereo"); - drp_audioMixDown.Items.Add("Dolby Surround"); - drp_audioMixDown.Items.Add("Dolby Pro Logic II"); - - drp_audioBitrate.Items.Clear(); - drp_audioBitrate.Items.Add("32"); - drp_audioBitrate.Items.Add("40"); - drp_audioBitrate.Items.Add("48"); - drp_audioBitrate.Items.Add("56"); - drp_audioBitrate.Items.Add("64"); - drp_audioBitrate.Items.Add("80"); - drp_audioBitrate.Items.Add("86"); - drp_audioBitrate.Items.Add("112"); - drp_audioBitrate.Items.Add("128"); - drp_audioBitrate.Items.Add("160"); - drp_audioBitrate.Items.Add("192"); - drp_audioBitrate.Items.Add("224"); - drp_audioBitrate.Items.Add("256"); - drp_audioBitrate.Items.Add("320"); + MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e) + #endregion + + //--------------------------------------------------- + // Encode / Cancel Buttons + // Encode Progress Text Handler + //--------------------------------------------------- + + #region Encodeing and Queue + + Functions.CLI process = new Functions.CLI(); + private delegate void UpdateUIHandler(); + + [DllImport("user32.dll")] + public static extern void LockWorkStation(); + [DllImport("user32.dll")] + public static extern int ExitWindowsEx(int uFlags, int dwReason); + + private void btn_queue_Click(object sender, EventArgs e) { - if (drp_audioCodec.Text == "AAC") + + if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "") + MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + else { - if (drp_audioMixDown.Text == "6 Channel Discrete") + string query; + if (QueryEditorText.Text == "") { - - drp_audioBitrate.Items.Clear(); - drp_audioBitrate.Items.Add("32"); - drp_audioBitrate.Items.Add("40"); - drp_audioBitrate.Items.Add("48"); - drp_audioBitrate.Items.Add("56"); - drp_audioBitrate.Items.Add("64"); - drp_audioBitrate.Items.Add("80"); - drp_audioBitrate.Items.Add("86"); - drp_audioBitrate.Items.Add("112"); - drp_audioBitrate.Items.Add("128"); - drp_audioBitrate.Items.Add("160"); - drp_audioBitrate.Items.Add("192"); - drp_audioBitrate.Items.Add("224"); - drp_audioBitrate.Items.Add("256"); - drp_audioBitrate.Items.Add("320"); - drp_audioBitrate.Items.Add("384"); + query = GenerateTheQuery(); } + else + { + query = QueryEditorText.Text; + } + queueWindow.list_queue.Items.Add(query); + queueWindow.Show(); } } - private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e) + private void showQueue() { - if (Check_ChapterMarkers.Checked) - { - string destination = text_destination.Text; - destination = destination.Replace(".mp4", ".m4v"); - text_destination.Text = destination; - } - else - { - string destination = text_destination.Text; - destination = destination.Replace(".m4v", ".mp4"); - text_destination.Text = destination; - } + queueWindow.Show(); } - private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e) + private void btn_encode_Click(object sender, EventArgs e) { - //Turn off some options which are H.264 only when the user selects a non h.264 encoder - if (!drp_videoEncoder.Text.Contains("H.264")) - { - check_turbo.CheckState = CheckState.Unchecked; - CheckCRF.CheckState = CheckState.Unchecked; - CheckCRF.Enabled = false; - check_turbo.Enabled = false; - h264Tab.Enabled = false; - rtf_h264advanced.Text = ""; - } + if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "") + MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); else { - CheckCRF.Enabled = true; - if (check_2PassEncode.CheckState.ToString() == "Checked") + btn_eCancel.Enabled = true; + String query = ""; + if (QueryEditorText.Text == "") { - check_turbo.Enabled = true; + query = GenerateTheQuery(); + } + else + { + query = QueryEditorText.Text; } - h264Tab.Enabled = true; - } + ThreadPool.QueueUserWorkItem(procMonitor, query); + lbl_encode.Visible = true; + lbl_encode.Text = "Encoding in Progress"; + } } - public void setStreamReader(Parsing.DVD dvd) + private void btn_eCancel_Click(object sender, EventArgs e) { - this.thisDVD = dvd; + process.killCLI(); + process.setNull(); + lbl_encode.Text = "Encoding Canceled"; } - private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e) + private void procMonitor(object state) { - // Reset some values on the form - lbl_Aspect.Text = "Select a Title"; - lbl_RecomendedCrop.Text = "Select a Title"; - drop_chapterStart.Items.Clear(); - drop_chapterFinish.Items.Clear(); - QueryEditorText.Text = ""; - - // If the dropdown is set to automatic nothing else needs to be done. - // Otheriwse if its not, title data has to be loased from parsing. - if (drp_dvdtitle.Text != "Automatic") + // Make sure we are not already encoding and if we are then display an error. + if (hbProc != null) { - Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title; + MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + else + { + hbProc = process.runCli(this, (string)state, false, false, false, false); + hbProc.WaitForExit(); - // Set the Aspect Ratio - lbl_Aspect.Text = selectedTitle.AspectRatio.ToString(); + try + { + /* + //***************************************************************************************** + // BUG! + // When the below code is used and standard error is set to true, hbcli is outputing a + // video stream which has mild corruption issues every few seconds. + // Maybe an issue with the Parser cauing the CLI to hickup/pause? + //***************************************************************************************** - // Set the Recommended Cropping values - lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]); + + Parsing.Parser encode = new Parsing.Parser(hbProc.StandardOutput.BaseStream); + encode.OnEncodeProgress += encode_OnEncodeProgress; + while (!encode.EndOfStream) + { + encode.ReadLine(); + } - // Populate the Start chapter Dropdown - drop_chapterStart.Items.Clear(); - drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray()); - if (drop_chapterStart.Items.Count > 0) - { - drop_chapterStart.Text = drop_chapterStart.Items[0].ToString(); - } + hbProc.WaitForExit(); + process.closeCLI(); + */ - // Populate the Final Chapter Dropdown - drop_chapterFinish.Items.Clear(); - drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray()); - if (drop_chapterFinish.Items.Count > 0) - { - drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(); } - - // Populate the Audio Channels Dropdown - drp_audioChannels.Items.Clear(); - drp_audioChannels.Items.Add("Automatic"); - drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray()); - if (drp_audioChannels.Items.Count > 0) + catch (Exception exc) { - drp_audioChannels.Text = drp_audioChannels.Items[0].ToString(); + // Do nothing + MessageBox.Show(exc.ToString()); } - // Populate the Subtitles dropdown - drp_subtitle.Items.Clear(); - drp_subtitle.Items.Add("None"); - drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray()); - if (drp_subtitle.Items.Count > 0) + + setEncodeLabel(); + hbProc = null; + + // Do something whent he encode ends. + switch (Properties.Settings.Default.CompletionOption) { - drp_subtitle.Text = drp_subtitle.Items[0].ToString(); + case "Shutdown": + System.Diagnostics.Process.Start("Shutdown", "-s -t 60"); + break; + case "Log Off": + ExitWindowsEx(0, 0); + break; + case "Suspend": + Application.SetSuspendState(PowerState.Suspend, true, true); + break; + case "Hibernate": + Application.SetSuspendState(PowerState.Hibernate, true, true); + break; + case "Lock System": + LockWorkStation(); + break; + case "Quit HandBrake": + Application.Exit(); + break; + default: + break; } } + } + + private void setEncodeLabel() + { + if (this.InvokeRequired) + { + this.BeginInvoke(new UpdateUIHandler(setEncodeLabel)); + return; + } + lbl_encode.Text = "Encoding Finished"; + } + + private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining) + { + + if (this.InvokeRequired) + { + this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress), + new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining }); + return; + } + lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining); } #endregion + //--------------------------------------------------- // Some Functions // - Query Generation @@ -1255,9 +1226,6 @@ namespace Handbrake case "H.264": videoEncoder = " -e x264"; break; - case "H.264 Baseline 1.3": - videoEncoder = " -e x264b13"; - break; case "H.264 (iPod)": videoEncoder = " -e x264b30"; break; @@ -1779,6 +1747,11 @@ namespace Handbrake } } + public void setStreamReader(Parsing.DVD dvd) + { + this.thisDVD = dvd; + } + #endregion diff --git a/win/C#/frmReadDVD.cs b/win/C#/frmReadDVD.cs index 516f746bb..49197eaea 100644 --- a/win/C#/frmReadDVD.cs +++ b/win/C#/frmReadDVD.cs @@ -90,7 +90,7 @@ namespace Handbrake try { string appPath = Application.StartupPath.ToString()+ "\\"; - string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " -i " + '"' + inputFile + '"' + " -t0 >" + '"' + appPath + "dvdinfo.dat" + '"' + " 2>&1" + '"'; + string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " -i " + '"' + inputFile + '"' + " -t0 -v >" + '"' + appPath + "dvdinfo.dat" + '"' + " 2>&1" + '"'; Process hbproc = Process.Start("CMD.exe", strCmdLine); hbproc.WaitForExit(); hbproc.Dispose(); -- cgit v1.2.3