using System.Collections;\r
using System.Collections.Generic;\r
using System.Drawing;\r
-using System.Text;\r
using System.Windows.Forms;\r
using System.IO;\r
using System.Diagnostics;\r
using System.Threading;\r
-using System.Runtime.InteropServices;\r
-using System.Globalization;\r
-using System.Text.RegularExpressions;\r
+using Handbrake.Functions;\r
\r
namespace Handbrake\r
{\r
{\r
// Objects which may be used by one or more other objects\r
private delegate void UpdateWindowHandler();\r
- Functions.Main hb_common_func = new Functions.Main();\r
- Functions.Encode encodeHandler = new Functions.Encode();\r
+ Main hb_common_func = new Main();\r
+ Encode encodeHandler = new Encode();\r
Queue.QueueHandler encodeQueue = new Queue.QueueHandler();\r
Presets.PresetsHandler presetHandler = new Presets.PresetsHandler();\r
Parsing.Title selectedTitle;\r
\r
// Globals: Mainly used for tracking.\r
private frmQueue queueWindow;\r
- private frmGenPreview preview;\r
- private string lastAction = null;\r
- public int maxWidth = 0;\r
- public int maxHeight = 0;\r
+ private frmGenPreview vlcpreview;\r
+ private frmPreview qtpreview;\r
+ private string lastAction;\r
+ public int maxWidth;\r
+ public int maxHeight;\r
+ Process hbproc;\r
\r
// Applicaiton Startup ************************************************\r
\r
loadPresetPanel(); // Load the Preset Panel\r
treeView_presets.ExpandAll();\r
lbl_encode.Text = "";\r
- queueWindow = new frmQueue(this); // Prepare the Queue\r
+ queueWindow = new frmQueue(encodeQueue); // Prepare the Queue\r
if (Properties.Settings.Default.QueryEditorTab != "Checked")\r
tabs_panel.TabPages.RemoveAt(5); // Remove the query editor tab if the user does not want it enabled.\r
\r
this.Enabled = true;\r
\r
// Event Handlers\r
- if (Properties.Settings.Default.MainWindowMinimize == "Checked")\r
- this.Resize += new EventHandler(frmMain_Resize);\r
+ events();\r
\r
// Queue Recovery\r
queueRecovery();\r
{\r
try\r
{\r
- if (this.InvokeRequired)\r
+ if (InvokeRequired)\r
{\r
- this.BeginInvoke(new updateStatusChanger(startupUpdateCheck));\r
+ BeginInvoke(new updateStatusChanger(startupUpdateCheck));\r
return;\r
}\r
\r
Boolean update = hb_common_func.updateCheck(false);\r
- if (update == true)\r
+ if (update)\r
{\r
frmUpdater updateWindow = new frmUpdater();\r
updateWindow.Show();\r
}\r
private void queueRecovery()\r
{\r
- if (hb_common_func.check_queue_recovery() == true)\r
+ if (hb_common_func.check_queue_recovery())\r
{\r
DialogResult result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
\r
}\r
#endregion\r
\r
+ #region Events\r
+ // Encoding Events for setting up the GUI\r
+ private void events()\r
+ {\r
+ // Handle Window Resize\r
+ if (Properties.Settings.Default.MainWindowMinimize == "Checked")\r
+ this.Resize += new EventHandler(frmMain_Resize);\r
+\r
+ // Handle Encode Start\r
+ encodeQueue.OnEncodeEnded += new EventHandler(encodeEnded);\r
+ encodeQueue.OnPaused += new EventHandler(encodePaused);\r
+ encodeQueue.OnEncodeStart += new EventHandler(encodeStarted);\r
+ }\r
+ private void encodeStarted(object sender, EventArgs e)\r
+ {\r
+ setLastAction("encode");\r
+ setEncodeStarted();\r
+ }\r
+ private void encodeEnded(object sender, EventArgs e)\r
+ {\r
+ setEncodeFinished();\r
+ }\r
+ private void encodePaused(object sender, EventArgs e)\r
+ {\r
+ setEncodeFinished();\r
+ }\r
+ #endregion\r
+\r
// User Interface Menus / Tool Strips *********************************\r
\r
#region File Menu\r
+ private void mnu_killCLI_Click(object sender, EventArgs e)\r
+ {\r
+ killCLI();\r
+ }\r
private void mnu_exit_Click(object sender, EventArgs e)\r
{\r
Application.Exit();\r
#region Tools Menu\r
private void mnu_encode_Click(object sender, EventArgs e)\r
{\r
- queueWindow.setQueue(encodeQueue);\r
+ queueWindow.setQueue();\r
queueWindow.Show();\r
}\r
private void mnu_encodeLog_Click(object sender, EventArgs e)\r
{\r
- String file = String.Empty;\r
+ String file;\r
if (lastAction == "scan")\r
file = "dvdinfo.dat";\r
else\r
}\r
private void mnu_options_Click(object sender, EventArgs e)\r
{\r
- Form Options = new frmOptions(this);\r
+ Form Options = new frmOptions();\r
Options.ShowDialog();\r
}\r
#endregion\r
private void mnu_delete_preset_Click(object sender, EventArgs e)\r
{\r
// Empty the preset file\r
- string presetsFile = Application.StartupPath.ToString() + "\\presets.xml";\r
+ string presetsFile = Application.StartupPath + "\\presets.xml";\r
if (File.Exists(presetsFile))\r
File.Delete(presetsFile);\r
\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("An error has occured during the preset removal process.\n If you are using Windows Vista, you may need to run under Administrator Mode to complete this task. \n" + exc.ToString());\r
+ MessageBox.Show("An error has occured during the preset removal process.\n If you are using Windows Vista, you may need to run under Administrator Mode to complete this task. \n" + exc);\r
}\r
\r
// Reload the preset panel\r
}\r
#endregion\r
\r
+ #region Debug Menu\r
+ private void mnu_qptest_Click(object sender, EventArgs e)\r
+ {\r
+ QueryParserTester qptest = new QueryParserTester();\r
+ qptest.Show();\r
+ }\r
+ #endregion\r
+\r
#region Preset Bar\r
// Right Click Menu Code\r
private void pmnu_expandAll_Click(object sender, EventArgs e)\r
{\r
treeView_presets.CollapseAll();\r
}\r
+ private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
+ {\r
+ DialogResult result = MessageBox.Show("Do you wish to include picture settings when updating the preset: " + treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);\r
+ if (result == DialogResult.Yes)\r
+ presetHandler.updatePreset(treeView_presets.SelectedNode.Text, queryGen.generateTabbedComponentsQuery(this), true);\r
+ else if (result == DialogResult.No)\r
+ presetHandler.updatePreset(treeView_presets.SelectedNode.Text, queryGen.generateTabbedComponentsQuery(this), false);\r
+ }\r
private void pmnu_delete_click(object sender, EventArgs e)\r
{\r
if (treeView_presets.SelectedNode != null)\r
}\r
treeView_presets.Select();\r
}\r
+ private void presets_menu_Opening(object sender, System.ComponentModel.CancelEventArgs e)\r
+ {\r
+ // Make sure that the save menu is always disabled by default\r
+ pmnu_saveChanges.Enabled = false;\r
+\r
+ // Now enable the save menu if the selected preset is a user preset\r
+ if (treeView_presets.SelectedNode != null)\r
+ {\r
+ if (presetHandler.checkIfUserPresetExists(treeView_presets.SelectedNode.Text))\r
+ {\r
+ pmnu_saveChanges.Enabled = true;\r
+ }\r
+ }\r
+ treeView_presets.Select();\r
+ }\r
\r
// Presets Management\r
private void btn_addPreset_Click(object sender, EventArgs e)\r
if (e.Button == MouseButtons.Right)\r
treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);\r
else if (e.Button == MouseButtons.Left)\r
- selectPreset();\r
+ {\r
+ if (treeView_presets.GetNodeAt(e.Location) != null)\r
+ {\r
+ if (groupBox_output.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))\r
+ selectPreset();\r
+ }\r
+ }\r
\r
treeView_presets.Select();\r
}\r
int i = 0;\r
foreach (TreeNode node in treeView_presets.Nodes)\r
{\r
- if (nodeStatus[i] == true)\r
+ if (nodeStatus[i])\r
node.Expand();\r
\r
i++;\r
int i = 0;\r
foreach (TreeNode node in treeView_presets.Nodes)\r
{\r
- if (nodeStatus[i] == true)\r
+ if (nodeStatus[i])\r
node.Expand();\r
\r
foreach (TreeNode subNode in node.Nodes)\r
{\r
- if (nodeStatus[i] == true)\r
+ if (nodeStatus[i])\r
subNode.Expand();\r
}\r
\r
{\r
foreach (TreeNode node in treenode.Nodes)\r
{\r
- if (node.Text.ToString().Equals("Normal"))\r
+ if (node.Text.Equals("Normal"))\r
treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];\r
}\r
}\r
\r
if (result == DialogResult.Yes)\r
{\r
+ // Pause The Queue\r
+ encodeQueue.pauseEncode();\r
+\r
+ // Kill the current process.\r
Process[] aProc = Process.GetProcessesByName("HandBrakeCLI");\r
Process HandBrakeCLI;\r
if (aProc.Length > 0)\r
HandBrakeCLI = aProc[0];\r
HandBrakeCLI.Kill();\r
}\r
- if (!queueWindow.isEncoding())\r
- setEncodeFinished();\r
+\r
+ // Update the GUI\r
+ setEncodeFinished();\r
}\r
}\r
else\r
// This is used for tracking which file to load in the activity window\r
lastAction = "encode";\r
\r
- String query;\r
- if (rtf_query.Text != "")\r
- query = rtf_query.Text;\r
- else\r
- query = queryGen.GenerateTheQuery(this);\r
+ String query = rtf_query.Text != "" ? rtf_query.Text : queryGen.GenerateTheQuery(this);\r
\r
if (encodeQueue.count() == 0)\r
{\r
encodeQueue.add(query, text_source.Text, text_destination.Text);\r
encodeQueue.write2disk("hb_queue_recovery.xml");\r
}\r
- queueWindow.setQueue(encodeQueue);\r
+ queueWindow.setQueue();\r
if (encodeQueue.count() > 1)\r
queueWindow.Show();\r
\r
- queueWindow.frmMain_encode();\r
-\r
setEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
+ encodeQueue.startEncode(); // Start The Queue Encoding Process\r
+\r
}\r
else if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)\r
MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
encodeQueue.add(query, text_source.Text, text_destination.Text);\r
encodeQueue.write2disk("hb_queue_recovery.xml"); // Writes the queue to the recovery file, just incase the GUI crashes.\r
\r
- queueWindow.setQueue(encodeQueue);\r
+ queueWindow.setQueue();\r
queueWindow.Show();\r
}\r
}\r
private void btn_showQueue_Click(object sender, EventArgs e)\r
{\r
- queueWindow.setQueue(encodeQueue);\r
+ queueWindow.setQueue();\r
queueWindow.Show();\r
}\r
- private void btn_vidPreview_Click(object sender, EventArgs e)\r
+ private void mnu_vlcpreview_Click(object sender, EventArgs e)\r
{\r
if (text_source.Text == "" || text_source.Text == "Click 'Source' to continue" || text_destination.Text == "")\r
MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
else\r
{\r
- if (preview == null)\r
+ if (vlcpreview == null)\r
{\r
- preview = new frmGenPreview(this);\r
- preview.Show();\r
+ vlcpreview = new frmGenPreview(this);\r
+ vlcpreview.Show();\r
}\r
- else if (preview.IsDisposed)\r
+ else if (vlcpreview.IsDisposed)\r
{\r
- preview = new frmGenPreview(this);\r
- preview.Show();\r
+ vlcpreview = new frmGenPreview(this);\r
+ vlcpreview.Show();\r
}\r
else\r
MessageBox.Show("The preview window is already open!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
}\r
- private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
+ private void mnu_qtpreview_Click(object sender, EventArgs e)\r
{\r
- String file = String.Empty;\r
- if (lastAction == "scan")\r
- file = "dvdinfo.dat";\r
+ if (text_source.Text == "" || text_source.Text == "Click 'Source' to continue" || text_destination.Text == "")\r
+ MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
else\r
- file = "hb_encode_log.dat";\r
+ {\r
+ if (qtpreview == null)\r
+ {\r
+ qtpreview = new frmPreview(this);\r
+ qtpreview.Show();\r
+ }\r
+ else if (qtpreview.IsDisposed)\r
+ {\r
+ qtpreview = new frmPreview(this);\r
+ qtpreview.Show();\r
+ }\r
+ else\r
+ MessageBox.Show("The preview window is already open!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ }\r
+ }\r
+ private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
+ {\r
+ String file = lastAction == "scan" ? "dvdinfo.dat" : "hb_encode_log.dat";\r
\r
frmActivityWindow ActivityWindow = new frmActivityWindow(file, encodeHandler);\r
ActivityWindow.Show();\r
if (FormWindowState.Minimized == this.WindowState)\r
{\r
notifyIcon.Visible = true;\r
- if (lbl_encode.Text != "")\r
- notifyIcon.BalloonTipText = lbl_encode.Text;\r
- else\r
- notifyIcon.BalloonTipText = "Not Encoding";\r
+ notifyIcon.BalloonTipText = lbl_encode.Text != "" ? lbl_encode.Text : "Not Encoding";\r
notifyIcon.ShowBalloonTip(500);\r
this.Hide();\r
}\r
// This is used for tracking which file to load in the activity window\r
lastAction = "scan";\r
\r
- String filename = "";\r
+ String filename;\r
text_source.Text = "";\r
\r
DVD_Open.ShowDialog();\r
{\r
if (filename != "")\r
{\r
- Form frmRD = new frmReadDVD(filename, this);\r
- text_source.Text = filename;\r
- lbl_encode.Text = "Scanning ...";\r
- frmRD.ShowDialog();\r
+ setupGUIforScan(filename);\r
+ startScan(filename);\r
}\r
else\r
text_source.Text = "Click 'Source' to continue";\r
-\r
- // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.\r
- if (drp_dvdtitle.Items.Count == 0)\r
- MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
-\r
- lbl_encode.Text = "";\r
}\r
}\r
private void btn_file_source_Click(object sender, EventArgs e)\r
// This is used for tracking which file to load in the activity window\r
lastAction = "scan";\r
\r
- String filename = "";\r
+ String filename;\r
text_source.Text = "";\r
\r
ISO_Open.ShowDialog();\r
{\r
if (filename != "")\r
{\r
- Form frmRD = new frmReadDVD(filename, this);\r
- text_source.Text = filename;\r
- lbl_encode.Text = "Scanning ...";\r
- frmRD.ShowDialog();\r
+ setupGUIforScan(filename);\r
+ startScan(filename);\r
}\r
else\r
text_source.Text = "Click 'Source' to continue";\r
-\r
- // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.\r
- if (drp_dvdtitle.Items.Count == 0)\r
- MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
-\r
- lbl_encode.Text = "";\r
-\r
- // Enable the creation of chapter markers if the file is an image of a dvd.\r
- if (filename.ToLower().Contains(".iso"))\r
- Check_ChapterMarkers.Enabled = true;\r
- else\r
- {\r
- Check_ChapterMarkers.Enabled = false;\r
- Check_ChapterMarkers.Checked = false;\r
- data_chpt.Rows.Clear();\r
- }\r
}\r
}\r
private void mnu_dvd_drive_Click(object sender, EventArgs e)\r
// This is used for tracking which file to load in the activity window\r
lastAction = "scan";\r
\r
- String filename = "";\r
if (mnu_dvd_drive.Text.Contains("VIDEO_TS"))\r
{\r
string[] path = mnu_dvd_drive.Text.Split(' ');\r
- filename = path[0];\r
- lbl_encode.Text = "Scanning ...";\r
- Form frmRD = new frmReadDVD(filename, this);\r
- text_source.Text = filename;\r
- frmRD.ShowDialog();\r
+ String filename = path[0];\r
+ setupGUIforScan(filename);\r
+ startScan(filename);\r
}\r
\r
// If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.\r
\r
lbl_encode.Text = "";\r
}\r
-\r
private void drp_dvdtitle_Click(object sender, EventArgs e)\r
{\r
if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))\r
text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);\r
\r
data_chpt.Rows.Clear();\r
- DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterStart.Text, drop_chapterFinish.Text);\r
+ DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterFinish.Text);\r
if (chapterGridView != null)\r
data_chpt = chapterGridView;\r
+\r
+ // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.\r
+ data_chpt.Columns[0].Width = 166;\r
+ data_chpt.Columns[0].Width = 165;\r
}\r
private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
{\r
- int c_start, c_end = 1;\r
+ int c_start, c_end;\r
\r
if (drop_chapterFinish.Text == "Auto" && drop_chapterFinish.Items.Count != 0)\r
drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;\r
// Run the Autonaming function\r
if (Properties.Settings.Default.autoNaming == "Checked")\r
text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);\r
+\r
}\r
private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
{\r
- int c_start, c_end = 1;\r
+ int c_start, c_end;\r
\r
if (drop_chapterStart.Text == "Auto" && drop_chapterStart.Items.Count >= 1)\r
drop_chapterStart.SelectedIndex = 1;\r
// Run the Autonaming function\r
if (Properties.Settings.Default.autoNaming == "Checked")\r
text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);\r
+\r
+ // Add more rows to the Chapter menu if needed.\r
+ if (Check_ChapterMarkers.Checked)\r
+ {\r
+ int i = data_chpt.Rows.Count, finish = 0;\r
+\r
+ if (drop_chapterFinish.Text != "Auto")\r
+ int.TryParse(drop_chapterFinish.Text, out finish);\r
+\r
+ while (i < finish)\r
+ {\r
+ int n = data_chpt.Rows.Add();\r
+ data_chpt.Rows[n].Cells[0].Value = (i + 1);\r
+ data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);\r
+ data_chpt.Rows[n].Cells[0].ValueType = typeof(int);\r
+ data_chpt.Rows[n].Cells[1].ValueType = typeof(string);\r
+ i++;\r
+ }\r
+ }\r
}\r
\r
//Destination\r
DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", "").Replace(".m4v", "").Replace(".mkv", "").Replace(".ogm", "").Replace(".avi", "");\r
\r
// Show the dialog and set the main form file path\r
- if (text_destination.Text.EndsWith(".mp4"))\r
+ if (drop_format.SelectedIndex.Equals(0))\r
DVD_Save.FilterIndex = 1;\r
- else if (text_destination.Text.EndsWith(".m4v"))\r
+ else if (drop_format.SelectedIndex.Equals(1))\r
DVD_Save.FilterIndex = 2;\r
- else if (text_destination.Text.EndsWith(".avi"))\r
+ else if (drop_format.SelectedIndex.Equals(2))\r
DVD_Save.FilterIndex = 3;\r
- else if (text_destination.Text.EndsWith(".ogm"))\r
+ else if (drop_format.SelectedIndex.Equals(3))\r
DVD_Save.FilterIndex = 4;\r
- else if (text_destination.Text.EndsWith(".mkv"))\r
+ else if (drop_format.SelectedIndex.Equals(4))\r
DVD_Save.FilterIndex = 5;\r
\r
if (DVD_Save.ShowDialog() == DialogResult.OK)\r
}\r
private void text_destination_TextChanged(object sender, EventArgs e)\r
{\r
- setAudioByContainer(text_destination.Text);\r
- setVideoByContainer(text_destination.Text);\r
string path = text_destination.Text;\r
if (path.EndsWith(".mp4"))\r
drop_format.SelectedIndex = 0;\r
setExtension(".avi");\r
else if (drop_format.SelectedIndex == 4)\r
setExtension(".ogm");\r
+\r
+ setAudioByContainer(drop_format.Text);\r
+ setVideoByContainer(drop_format.Text);\r
}\r
private void setExtension(string newExtension)\r
{\r
check_iPodAtom.Enabled = true;\r
else\r
check_iPodAtom.Enabled = false;\r
- if (!drp_anamorphic.Items.Contains("Loose"))\r
- drp_anamorphic.Items.Add("Loose");\r
}\r
else\r
{\r
rtf_x264Query.Text = "";\r
check_iPodAtom.Enabled = false;\r
check_iPodAtom.Checked = false;\r
- if (drp_anamorphic.Items.Count == 3)\r
- drp_anamorphic.Items.RemoveAt(2);\r
}\r
-\r
+ \r
+ // Setup the CQ Slider\r
+ switch (drp_videoEncoder.Text)\r
+ { \r
+ case "MPEG-4 (FFmpeg)":\r
+ slider_videoQuality.Minimum = 1;\r
+ slider_videoQuality.Maximum = 31;\r
+ slider_videoQuality.Value = 1;\r
+ SliderValue.Text = "0% QP: 31.00";\r
+ break;\r
+ case "MPEG-4 (XviD)":\r
+ slider_videoQuality.Minimum = 1;\r
+ slider_videoQuality.Maximum = 31;\r
+ slider_videoQuality.Value = 1;\r
+ SliderValue.Text = "0% QP: 31.00";\r
+ break;\r
+ case "H.264 (x264)":\r
+ slider_videoQuality.Minimum = 0;\r
+ slider_videoQuality.Value = 0;\r
+ slider_videoQuality.TickFrequency = 1;\r
+ SliderValue.Text = "0% RF: 51.00";\r
+ String step = Properties.Settings.Default.x264cqstep;\r
+ switch (step)\r
+ {\r
+ case "0.20":\r
+ slider_videoQuality.Maximum = 255;\r
+ break;\r
+ case "0.25":\r
+ slider_videoQuality.Maximum = 204;\r
+ break;\r
+ case "0.33":\r
+ slider_videoQuality.Maximum = 155;\r
+ break;\r
+ case "0.50":\r
+ slider_videoQuality.Maximum = 102;\r
+ break;\r
+ case "1.0":\r
+ slider_videoQuality.Maximum = 51;\r
+ break;\r
+ default:\r
+ slider_videoQuality.Maximum = 51;\r
+ break; \r
+ } \r
+ break;\r
+ case "VP3 (Theora)":\r
+ slider_videoQuality.Minimum = 0;\r
+ slider_videoQuality.Maximum = 63;\r
+ slider_videoQuality.Value = 0;\r
+ SliderValue.Text = "0% QP: 0.00";\r
+ break;\r
+ }\r
}\r
- private void text_bitrate_TextChanged(object sender, EventArgs e)\r
+ private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
{\r
- text_filesize.Text = "";\r
- slider_videoQuality.Value = 0;\r
- SliderValue.Text = "0%";\r
+ switch (drp_videoEncoder.Text)\r
+ {\r
+ case "MPEG-4 (FFmpeg)":\r
+ double rfValue = 31 - (slider_videoQuality.Value - 1);\r
+ double max = slider_videoQuality.Maximum;\r
+ double min = slider_videoQuality.Minimum;\r
+ double val = ((max - min) - (rfValue - min)) / (max - min);\r
+ SliderValue.Text = Math.Round((val * 100), 2) + "% QP:" + (32 - slider_videoQuality.Value);\r
+ break;\r
+ case "MPEG-4 (XviD)":\r
+ rfValue = 31 - (slider_videoQuality.Value - 1);\r
+ max = slider_videoQuality.Maximum;\r
+ min = slider_videoQuality.Minimum;\r
+ val = ((max - min) - (rfValue - min)) / (max - min);\r
+ SliderValue.Text = Math.Round((val * 100), 2) + "% QP:" + (32 - slider_videoQuality.Value);\r
+ break;\r
+ case "H.264 (x264)":\r
+ double divided;\r
+ double.TryParse(Properties.Settings.Default.x264cqstep, out divided);\r
+ rfValue = 51.0 - slider_videoQuality.Value*divided;\r
+ max = slider_videoQuality.Maximum * divided;\r
+ min = slider_videoQuality.Minimum;\r
+ val = ((max - min) - (rfValue - min)) / (max - min);\r
+ rfValue = Math.Round(rfValue, 2);\r
+ SliderValue.Text = Math.Round((val * 100), 2) + "% RF:" + rfValue; \r
+ break;\r
+ case "VP3 (Theora)":\r
+ rfValue = slider_videoQuality.Value;\r
+ double value = rfValue / 63;\r
+ SliderValue.Text = Math.Round((value * 100), 2) + "% QP:" + slider_videoQuality.Value;\r
+ break;\r
+ }\r
+ }\r
+ private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)\r
+ {\r
+ text_bitrate.Enabled = false;\r
+ text_filesize.Enabled = true;\r
+ slider_videoQuality.Enabled = false;\r
+\r
check_2PassEncode.Enabled = true;\r
}\r
- private void text_filesize_TextChanged(object sender, EventArgs e)\r
+ private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)\r
{\r
- text_bitrate.Text = "";\r
- slider_videoQuality.Value = 0;\r
- SliderValue.Text = "0%";\r
+ text_bitrate.Enabled = true;\r
+ text_filesize.Enabled = false;\r
+ slider_videoQuality.Enabled = false;\r
+\r
check_2PassEncode.Enabled = true;\r
}\r
- private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
+ private void radio_cq_CheckedChanged(object sender, EventArgs e)\r
{\r
- SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
- text_bitrate.Text = "";\r
- text_filesize.Text = "";\r
+ text_bitrate.Enabled = false;\r
+ text_filesize.Enabled = false;\r
+ slider_videoQuality.Enabled = true;\r
+\r
check_2PassEncode.Enabled = false;\r
check_2PassEncode.CheckState = CheckState.Unchecked;\r
}\r
\r
int width;\r
Boolean parsed = int.TryParse(text_width.Text, out width);\r
- if (parsed != false)\r
+ if (parsed)\r
{\r
- if ((width % 16) != 0)\r
- text_width.BackColor = Color.LightCoral;\r
- else\r
- text_width.BackColor = Color.LightGreen;\r
-\r
+ text_width.BackColor = (width % 16) != 0 ? Color.LightCoral : Color.LightGreen;\r
\r
if (lbl_Aspect.Text != "Select a Title" && maxWidth == 0 && maxHeight == 0)\r
{\r
\r
int height;\r
Boolean parsed = int.TryParse(text_height.Text, out height);\r
- if (parsed != false)\r
- {\r
- if ((height % 16) != 0)\r
- text_height.BackColor = Color.LightCoral;\r
- else\r
- text_height.BackColor = Color.LightGreen;\r
- }\r
+ if (parsed)\r
+ text_height.BackColor = (height % 16) != 0 ? Color.LightCoral : Color.LightGreen;\r
}\r
private void check_customCrop_CheckedChanged(object sender, EventArgs e)\r
{\r
text_width.Enabled = true;\r
}\r
}\r
+ \r
+ // Filter Tab\r
+ private void ctl_decomb_changed(object sender, EventArgs e)\r
+ {\r
+ if (ctl_decomb.getDropValue != "Off")\r
+ if (ctl_deinterlace.getDropValue != "None")\r
+ ctl_deinterlace.setOption("None");\r
+ }\r
+ private void ctl_deinterlace_changed(object sender, EventArgs e)\r
+ {\r
+ if (ctl_detelecine.getDropValue != "None")\r
+ if (ctl_decomb.getDropValue != "Off")\r
+ ctl_decomb.setOption("Off");\r
+ }\r
private void slider_deblock_Scroll(object sender, EventArgs e)\r
{\r
- if (slider_deblock.Value == 4)\r
- lbl_deblockVal.Text = "Off";\r
- else\r
- lbl_deblockVal.Text = slider_deblock.Value.ToString();\r
+ lbl_deblockVal.Text = slider_deblock.Value == 4 ? "Off" : slider_deblock.Value.ToString();\r
}\r
\r
//Audio Tab\r
}\r
private void tb_drc_Scroll(object sender, EventArgs e)\r
{\r
- double value = (tb_drc.Value / 10.0) + 1;\r
+ double value;\r
+ if (tb_drc.Value == 0) value = 0;\r
+ else\r
+ value = ((tb_drc.Value-1) / 10.0) + 1;\r
+ \r
lbl_drc.Text = value.ToString();\r
\r
// Update an item in the Audio list if required.\r
drp_audmix_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;\r
drp_audsr_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;\r
drp_audbit_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;\r
- double drcValue = 0; int drcCalculated = 0;\r
+ double drcValue; int drcCalculated;\r
double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text, out drcValue);\r
- drcValue = (drcValue * 10) - 10;\r
+ if (drcValue == 0) drcCalculated = 0;\r
+ else\r
+ drcValue = ((drcValue * 10)+1) -10;\r
int.TryParse(drcValue.ToString(), out drcCalculated);\r
tb_drc.Value = drcCalculated;\r
}\r
text_destination.Text = text_destination.Text.Replace(".m4v", ".mp4");\r
data_chpt.Rows.Clear();\r
data_chpt.Enabled = true;\r
- DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterStart.Text, drop_chapterFinish.Text);\r
+ DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterFinish.Text);\r
if (chapterGridView != null)\r
data_chpt = chapterGridView;\r
}\r
{\r
x264PanelFunctions.on_x264_WidgetChange("weightb", this);\r
}\r
- private void check_bFrameDistortion_CheckedChanged(object sender, EventArgs e)\r
- {\r
- x264PanelFunctions.on_x264_WidgetChange("brdo", this);\r
- }\r
- private void check_BidirectionalRefinement_CheckedChanged(object sender, EventArgs e)\r
- {\r
- x264PanelFunctions.on_x264_WidgetChange("bime", this);\r
- }\r
private void check_pyrmidalBFrames_CheckedChanged(object sender, EventArgs e)\r
{\r
x264PanelFunctions.on_x264_WidgetChange("b-pyramid", this);\r
\r
// MainWindow Components, Actions and Functions ***********************\r
\r
+ #region Source Scan\r
+ private void setupGUIforScan(String filename)\r
+ {\r
+ text_source.Text = filename;\r
+\r
+ foreach (Control ctrl in Controls)\r
+ {\r
+ if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
+ ctrl.Enabled = false;\r
+ }\r
+ lbl_encode.Visible = true;\r
+ lbl_encode.Text = "Scanning ...";\r
+ gb_source.Text = "Source: Scanning ...";\r
+ btn_source.Enabled = false;\r
+ btn_start.Enabled = false;\r
+ btn_showQueue.Enabled = false;\r
+ btn_add2Queue.Enabled = false;\r
+ tb_preview.Enabled = false;\r
+ mnu_killCLI.Visible = true;\r
+ }\r
+ private void startScan(String filename)\r
+ {\r
+ try\r
+ {\r
+ lbl_encode.Visible = true;\r
+ lbl_encode.Text = "Scanning...";\r
+ ThreadPool.QueueUserWorkItem(scanProcess, filename);\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmMain.cs - startScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
+ }\r
+ private void scanProcess(object state)\r
+ {\r
+ try\r
+ {\r
+ string inputFile = (string)state;\r
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
+ string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");\r
+\r
+ // Make we don't pick up a stale hb_encode_log.dat (and that we have rights to the file)\r
+ if (File.Exists(dvdInfoPath))\r
+ File.Delete(dvdInfoPath);\r
+\r
+ string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);\r
+\r
+ ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine);\r
+ hbParseDvd.WindowStyle = ProcessWindowStyle.Hidden;\r
+\r
+ using (hbproc = Process.Start(hbParseDvd))\r
+ {\r
+ hbproc.WaitForExit();\r
+ }\r
+\r
+ if (!File.Exists(dvdInfoPath))\r
+ {\r
+ throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing. \nExpected location of dvdinfo.dat: \n" + dvdInfoPath);\r
+ }\r
+\r
+ using (StreamReader sr = new StreamReader(dvdInfoPath))\r
+ {\r
+ thisDVD = Parsing.DVD.Parse(sr);\r
+ sr.Close();\r
+ sr.Dispose();\r
+ }\r
+\r
+ updateUIafterScan();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmMain.cs - scanProcess() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ enableGUI();\r
+ }\r
+ }\r
+ private void updateUIafterScan()\r
+ {\r
+ try\r
+ {\r
+ if (InvokeRequired)\r
+ {\r
+ BeginInvoke(new UpdateWindowHandler(updateUIafterScan));\r
+ return;\r
+ }\r
+\r
+ // Setup some GUI components\r
+ drp_dvdtitle.Items.Clear();\r
+ if (thisDVD.Titles.Count != 0)\r
+ drp_dvdtitle.Items.AddRange(thisDVD.Titles.ToArray());\r
+ drp_dvdtitle.Text = "Automatic";\r
+ drop_chapterFinish.Text = "Auto";\r
+ drop_chapterStart.Text = "Auto";\r
+\r
+ // Now select the longest title\r
+ if (thisDVD.Titles.Count != 0)\r
+ drp_dvdtitle.SelectedItem = hb_common_func.selectLongestTitle(drp_dvdtitle);\r
+\r
+ // Enable the creation of chapter markers if the file is an image of a dvd.\r
+ if (text_source.Text.ToLower().Contains(".iso") || text_source.Text.ToLower().Contains("VIDEO_TS"))\r
+ Check_ChapterMarkers.Enabled = true;\r
+ else\r
+ {\r
+ Check_ChapterMarkers.Enabled = false;\r
+ Check_ChapterMarkers.Checked = false;\r
+ data_chpt.Rows.Clear();\r
+ }\r
+\r
+ // If no titles were found, Display an error message\r
+ if (drp_dvdtitle.Items.Count == 0)\r
+ MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+\r
+ // Enable the GUI components and enable any disabled components\r
+ enableGUI();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ enableGUI();\r
+ }\r
+ }\r
+\r
+ private void enableGUI()\r
+ {\r
+ try\r
+ {\r
+ if (InvokeRequired)\r
+ {\r
+ BeginInvoke(new UpdateWindowHandler(updateUIafterScan));\r
+ }\r
+ lbl_encode.Text = "Scan Completed";\r
+ gb_source.Text = "Source";\r
+ foreach (Control ctrl in Controls)\r
+ ctrl.Enabled = true;\r
+ btn_start.Enabled = true;\r
+ btn_showQueue.Enabled = true;\r
+ btn_add2Queue.Enabled = true;\r
+ tb_preview.Enabled = true;\r
+ btn_source.Enabled = true;\r
+ mnu_killCLI.Visible = false;\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("frmMain.cs - enableGUI " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
+ }\r
+ private static void killCLI()\r
+ {\r
+ // This may seem like a long way of killing HandBrakeCLI, but for whatever reason,\r
+ // hbproc.kill/close just won't do the trick.\r
+ try\r
+ {\r
+ string AppName = "HandBrakeCLI";\r
+\r
+ AppName = AppName.ToUpper();\r
+\r
+ System.Diagnostics.Process[] prs = Process.GetProcesses();\r
+ foreach (System.Diagnostics.Process proces in prs)\r
+ {\r
+ if (proces.ProcessName.ToUpper() == AppName)\r
+ {\r
+ proces.Refresh();\r
+ if (!proces.HasExited)\r
+ proces.Kill();\r
+ }\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ MessageBox.Show("Unable to kill HandBrakeCLI.exe \nYou may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically within the next few minutes. \n\nError Information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
+ }\r
+ #endregion\r
+\r
#region DVD Drive Detection\r
// Source Button Drive Detection\r
private delegate void ProgressUpdateHandler();\r
{\r
try\r
{\r
- if (this.InvokeRequired)\r
+ if (InvokeRequired)\r
{\r
- this.BeginInvoke(new ProgressUpdateHandler(getDriveInfoThread));\r
+ BeginInvoke(new ProgressUpdateHandler(getDriveInfoThread));\r
return;\r
}\r
\r
{\r
if (curDrive.IsReady)\r
{\r
- if (File.Exists(curDrive.RootDirectory.ToString() + "VIDEO_TS\\VIDEO_TS.IFO"))\r
- mnu_dvd_drive.Text = curDrive.RootDirectory.ToString() + "VIDEO_TS (" + curDrive.VolumeLabel + ")";\r
+ if (File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))\r
+ mnu_dvd_drive.Text = curDrive.RootDirectory + "VIDEO_TS (" + curDrive.VolumeLabel + ")";\r
else\r
mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
\r
#region Audio Panel Code Helpers\r
private void setAudioByContainer(String path)\r
{\r
- string oldval = "";\r
+ string oldval;\r
\r
- if ((path.EndsWith(".mp4")) || (path.EndsWith(".m4v")))\r
+ if ((path.Contains("MP4")) || (path.Contains("M4V")))\r
{\r
oldval = drp_audenc_1.Text;\r
drp_audenc_1.Items.Clear();\r
drp_audenc_1.SelectedIndex = 0;\r
\r
}\r
- else if (path.EndsWith(".avi"))\r
+ else if (path.Contains("AVI"))\r
{\r
oldval = drp_audenc_1.Text;\r
drp_audenc_1.Items.Clear();\r
drp_audenc_1.SelectedIndex = 0;\r
\r
}\r
- else if (path.EndsWith(".ogm"))\r
+ else if (path.Contains("OGM"))\r
{\r
drp_audenc_1.Items.Clear();\r
drp_audenc_1.Items.Add("Vorbis");\r
drp_audenc_1.SelectedIndex = 0;\r
\r
}\r
- else if (path.EndsWith(".mkv"))\r
+ else if (path.Contains("MKV"))\r
{\r
drp_audenc_1.Items.Clear();\r
drp_audenc_1.Items.Add("AAC");\r
if (drp_audenc_1.Text == string.Empty)\r
drp_audenc_1.SelectedIndex = 0;\r
}\r
+\r
+ // Make sure the table is updated with new audio codecs\r
+ foreach (ListViewItem row in lv_audioList.Items)\r
+ {\r
+ if (!drp_audenc_1.Items.Contains(row.SubItems[1].Text))\r
+ row.SubItems[1].Text = drp_audenc_1.Items[0].ToString();\r
+ }\r
}\r
private void setVideoByContainer(String path)\r
{\r
- string oldval = "";\r
+ string oldval;\r
\r
- if ((path.EndsWith(".mp4")) || (path.EndsWith(".m4v")))\r
+ if ((path.Contains("MP3")) || (path.Contains("M4V")))\r
{\r
oldval = drp_videoEncoder.Text;\r
drp_videoEncoder.Items.Clear();\r
drp_videoEncoder.Text = oldval;\r
\r
}\r
- else if (path.EndsWith(".avi"))\r
+ else if (path.Contains("AVI"))\r
{\r
oldval = drp_videoEncoder.Text;\r
drp_videoEncoder.Items.Clear();\r
else\r
drp_videoEncoder.Text = oldval;\r
}\r
- else if (path.EndsWith(".ogm"))\r
+ else if (path.Contains("OGM"))\r
{\r
oldval = drp_videoEncoder.Text;\r
drp_videoEncoder.Items.Clear();\r
else\r
drp_videoEncoder.Text = oldval;\r
}\r
- else if (path.EndsWith(".mkv"))\r
+ else if (path.Contains("MKV"))\r
{\r
oldval = drp_videoEncoder.Text;\r
drp_videoEncoder.Items.Clear();\r
dropdown.Items.Add("Dolby Surround");\r
dropdown.Items.Add("Dolby Pro Logic II");\r
}\r
- private void audioEncoderChange(ComboBox audenc, ComboBox audMix, ComboBox audbit, ComboBox audsr)\r
- {\r
- if (audenc.Text == "AC3")\r
- {\r
- audMix.Enabled = false;\r
- audbit.Enabled = false;\r
- audsr.Enabled = false;\r
-\r
- audMix.Text = "Automatic";\r
- audbit.Text = "160";\r
- audsr.Text = "Auto";\r
- }\r
- else\r
- {\r
- // Just make sure not to re-enable the following boxes if the track above is none\r
- /* if (drp_track2Audio.Text != "None")\r
- {\r
- audMix.Enabled = true;\r
- audbit.Enabled = true;\r
- audsr.Enabled = true;\r
-\r
- audMix.Text = "Automatic";\r
- audbit.Text = "160";\r
- audsr.Text = "Auto";\r
- }*/\r
- }\r
- }\r
#endregion\r
\r
#region Public Methods\r
/// 1 = Encode Running\r
/// 0 = Encode Finished.\r
/// </summary>\r
- /// <param name="i">Int</param>\r
public void setEncodeFinished()\r
{\r
try\r
{\r
- if (this.InvokeRequired)\r
+ if (InvokeRequired)\r
{\r
- this.BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
+ BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
return;\r
}\r
\r
notifyIcon.BalloonTipText = lbl_encode.Text;\r
notifyIcon.ShowBalloonTip(500);\r
}\r
-\r
}\r
catch (Exception exc)\r
{\r
{\r
try\r
{\r
- if (this.InvokeRequired)\r
+ if (InvokeRequired)\r
{\r
- this.BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
+ BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
return;\r
}\r
\r
\r
treeView_presets.Nodes.Clear();\r
\r
- List<Presets.Preset> presetNameList = new List<Presets.Preset>();\r
- List<string> presetNames = new List<string>();\r
- TreeNode preset_treeview = new TreeNode();\r
+ List<Presets.Preset> presetNameList;\r
+ List<string> presetNames;\r
+ TreeNode preset_treeview;\r
\r
TreeNode rootNode = new TreeNode();\r
TreeNode rootNodeTwo = new TreeNode();\r
- TreeNode childNode = new TreeNode();\r
+ TreeNode childNode;\r
int workingLevel = 0;\r
string previousCategory = String.Empty;\r
string currentCategory = String.Empty;\r
\r
#endregion\r
\r
+ \r
+\r
// This is the END of the road ------------------------------------------------------------------------------\r
}\r
}
\ No newline at end of file