X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmMain.cs;h=bf00e2223aa165a459939747b5b88509a98736d7;hb=d49d3923cd466f1010f0097c9819f2d836aec01c;hp=78c4a9a2e9c80ec9b918dfdde68c2a8c9d35f244;hpb=169ed1a7e02fc8c3486d587abf1e54840bb3ca77;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 78c4a9a2..bf00e222 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Drawing; @@ -8,68 +9,188 @@ using System.Windows.Forms; using System.Net; using System.IO; using System.Diagnostics; +using System.Threading; +using System.Runtime.InteropServices; +using System.Globalization; +using System.Text.RegularExpressions; + namespace Handbrake { public partial class frmMain : Form { + // -------------------------------------------------------------- + // Applicaiton Startup Stuff + // -------------------------------------------------------------- + + #region Application Startup + + // Some stuff that needs to be Initialized. + private Process hbProc; + private Parsing.DVD thisDVD; + private frmQueue queueWindow = new frmQueue(); + + // The main window beings here... public frmMain() { + // Load the splash screen in this thread + Form splash = new frmSplashScreen(); + splash.Show(); + + //Create a label that can be updated from the parent thread. + Label lblStatus = new Label(); + + //Size the label + lblStatus.Size = new Size(250, 20); + + //Position the label + lblStatus.Location = new Point(10, 280); + + //Put the label on the splash form + splash.Controls.Add(lblStatus); + + //Fire a thread to wait for 2 seconds. The splash screen will exit when the time expires + Thread timer = new Thread(splashTimer); + timer.Start(); + InitializeComponent(); - } - // -------------------------------------------------------------- - // onLoad - setup the program ready for use. - // -------------------------------------------------------------- - private void frmMain_Load(object sender, EventArgs e) - { + // show the form, but leave disabled until preloading is complete + this.Enabled = false; + + // Show the main form + this.Show(); + + // Forces frmMain to draw + Application.DoEvents(); + // Set the Version number lable to the corect version. - Version.Text = "Version " + Properties.Settings.Default.GuiVersion; + Version.Text = "Version " + Properties.Settings.Default.CliVersion; + // update the status + lblStatus.Text = "Checking for updates ..."; + // redraw the splash screen + Application.DoEvents(); // Run the update checker. updateCheck(); - - // Now load the users default if required. + Thread.Sleep(200); + + // Update the presets + lblStatus.Text = "Updaing Presets ..."; + Application.DoEvents(); + updatePresets(); + Thread.Sleep(200); + + // Now load the users default if required. (Will overide the above setting) + lblStatus.Text = "Loading User Default Settings..."; + Application.DoEvents(); + loadNormalPreset(); loadUserDefaults(); - + Thread.Sleep(100); + + // Enable or disable tooltips + lblStatus.Text = "Loading Tooltips ..."; + Application.DoEvents(); + tooltip(); + Thread.Sleep(100); + + // Hide the preset bar if required. + hidePresetBar(); + + //Finished Loading + lblStatus.Text = "Loading Complete!"; + Application.DoEvents(); + Thread.Sleep(200); + + // Wait until splash screen is done + while (timer.IsAlive) + { Thread.Sleep(100); } + + //Close the splash screen + splash.Close(); + splash.Dispose(); + + // Turn the interface back to the user + this.Enabled = true; + } + + private void splashTimer(object sender) + { + Thread.Sleep(2000); //sit for 2 seconds then exit + } + + private void showSplash(object sender) + { + // Display splash screen for 1.5 Seconds + Form splash = new frmSplashScreen(); + splash.Show(); + Thread.Sleep(1500); + splash.Close(); // Then close. + } + + private void loadNormalPreset() + { + ListViewItem item = listview_presets.FindItemWithText("Normal"); + + if (item != null) + { + listview_presets.SelectedItems.Clear(); + item.Selected = true; + } } - public void loadUserDefaults() - { + private void loadUserDefaults() + { try { + // Load the users default settings or if the user has not got this option enabled, load the normal preset. if (Properties.Settings.Default.defaultSettings == "Checked") { - //Source + // Source text_source.Text = Properties.Settings.Default.DVDSource; drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle; drop_chapterStart.Text = Properties.Settings.Default.ChapterStart; drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish; - //Destination + + // Destination text_destination.Text = Properties.Settings.Default.VideoDest; drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder; drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder; text_width.Text = Properties.Settings.Default.Width; text_height.Text = Properties.Settings.Default.Height; - //Picture Settings Tab + + // Picture Settings Tab drp_crop.Text = Properties.Settings.Default.CroppingOption; text_top.Text = Properties.Settings.Default.CropTop; text_bottom.Text = Properties.Settings.Default.CropBottom; text_left.Text = Properties.Settings.Default.CropLeft; text_right.Text = Properties.Settings.Default.CropRight; drp_subtitle.Text = Properties.Settings.Default.Subtitles; - //Video Settings Tab + + // Video Settings Tab text_bitrate.Text = Properties.Settings.Default.VideoBitrate; text_filesize.Text = Properties.Settings.Default.VideoFilesize; slider_videoQuality.Value = Properties.Settings.Default.VideoQuality; + if (Properties.Settings.Default.TwoPass == "Checked") { check_2PassEncode.CheckState = CheckState.Checked; } - if (Properties.Settings.Default.DeInterlace == "Checked") + + drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace; + drp_deNoise.Text = Properties.Settings.Default.denoise; + + if (Properties.Settings.Default.detelecine == "Checked") + { + check_detelecine.CheckState = CheckState.Checked; + } + + if (Properties.Settings.Default.detelecine == "Checked") { - check_DeInterlace.CheckState = CheckState.Checked; + check_deblock.CheckState = CheckState.Checked; } + + if (Properties.Settings.Default.Grayscale == "Checked") { check_grayscale.CheckState = CheckState.Checked; @@ -89,16 +210,25 @@ namespace Handbrake { check_largeFile.CheckState = CheckState.Checked; } - //Audio Settings Tab + + if (Properties.Settings.Default.chapterMarker == "Checked") + { + Check_ChapterMarkers.CheckState = CheckState.Checked; + } + + // Audio Settings Tab drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate; drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate; drp_audioChannels.Text = Properties.Settings.Default.AudioChannels; - //H264 Tab + + // H264 Tab if (Properties.Settings.Default.CRF == "Checked") { CheckCRF.CheckState = CheckState.Checked; } rtf_h264advanced.Text = Properties.Settings.Default.H264; + + groupBox_output.Text = "Output Settings (Preset: " + Properties.Settings.Default.selectedPreset + ")"; } } catch (Exception) @@ -107,143 +237,104 @@ namespace Handbrake } } - public void updateCheck() + private Boolean updateCheck() { - if (Properties.Settings.Default.updateStatus == "Checked") + try { - - try + if (Properties.Settings.Default.updateStatus == "Checked") { String updateFile = Properties.Settings.Default.updateFile; WebClient client = new WebClient(); String data = client.DownloadString(updateFile); String[] versionData = data.Split('\n'); - if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion)) - { - lbl_update.Visible = true; - } + int verdata = int.Parse(versionData[0].Replace(".", "")); + int vergui = int.Parse(Properties.Settings.Default.GuiVersion.Replace(".", "")); + int verd1 = int.Parse(versionData[1].Replace(".", "")); + int cliversion = int.Parse(Properties.Settings.Default.CliVersion.Replace(".", "")); + + Boolean update = ((verdata > vergui) || (verd1 > cliversion)); + + lbl_update.Visible = update; + + return update; } - //else fail displaying an error message. - catch (Exception) + else { - //Silently ignore the error + return false; } } + catch (Exception) + { + // Silently ignore the error + return false; + } } + private void tooltip() + { + if (Properties.Settings.Default.tooltipEnable == "Checked") + { + ToolTip.Active = true; + } + } + private void hidePresetBar() + { + if (Properties.Settings.Default.hidePresets == "Checked") + { + btn_presets.Visible = true; + this.Width = 591; + } - // -------------------------------------------------------------- - // The Menu Bar - // -------------------------------------------------------------- + } + + #endregion + + // -------------------------------------------------------------- + // The main Menu bar. + // -------------------------------------------------------------- - // FILE MENU -------------------------------------------------------------- + #region File Menu private void mnu_open_Click(object sender, EventArgs e) { string filename; File_Open.ShowDialog(); filename = File_Open.FileName; + if (filename != "") { try { - // Create StreamReader & open file - StreamReader line = new StreamReader(filename); - string temporyLine; // Used for reading the line into a varible before processing on the checkState items below. - - // Read in the data and set the correct GUI component with the setting. - text_source.Text = line.ReadLine(); - drp_dvdtitle.Text = line.ReadLine(); - drop_chapterStart.Text = line.ReadLine(); - drop_chapterFinish.Text = line.ReadLine(); - text_destination.Text = line.ReadLine(); - drp_videoEncoder.Text = line.ReadLine(); - drp_audioCodec.Text = line.ReadLine(); - text_width.Text = line.ReadLine(); - text_height.Text = line.ReadLine(); - text_top.Text = line.ReadLine(); - text_bottom.Text = line.ReadLine(); - text_left.Text = line.ReadLine(); - text_right.Text = line.ReadLine(); - drp_subtitle.Text = line.ReadLine(); - text_bitrate.Text = line.ReadLine(); - text_filesize.Text = line.ReadLine(); - slider_videoQuality.Value = int.Parse(line.ReadLine()); - - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - check_2PassEncode.CheckState = CheckState.Checked; - } - - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - check_DeInterlace.CheckState = CheckState.Checked; - } - - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - check_grayscale.CheckState = CheckState.Checked; - } + // Some things that need to be done to reset some gui components: + CheckPixelRatio.CheckState = CheckState.Unchecked; - drp_videoFramerate.Text = line.ReadLine(); - - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - Check_ChapterMarkers.CheckState = CheckState.Checked; - } + //--------------------------- + // Get the Preset + // --------------------------- - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - CheckPixelRatio.CheckState = CheckState.Checked; - } + // Create StreamReader & open file + StreamReader line = new StreamReader(filename); - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - check_turbo.CheckState = CheckState.Checked; - } + // Send the query from the file to the Query Parser class + Functions.QueryParser presetQuery = Functions.QueryParser.Parse(line.ReadLine()); - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - check_largeFile.CheckState = CheckState.Checked; - } - - drp_audioBitrate.Text = line.ReadLine(); - drp_audioSampleRate.Text = line.ReadLine(); - drp_audioChannels.Text = line.ReadLine(); - drp_audioMixDown.Text = line.ReadLine(); - - // Advanced H264 Options - temporyLine = line.ReadLine(); - if (temporyLine == "Checked") - { - CheckCRF.CheckState = CheckState.Checked; - } - rtf_h264advanced.Text = line.ReadLine(); + // Now load the preset + presetLoader(presetQuery, filename); // Close the stream line.Close(); - - - // Fix for SliderValue not appearing when Opening saved file - SliderValue.Text = slider_videoQuality.Value + "%"; - - } catch (Exception){ + } + catch (Exception exc) + { MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); + MessageBox.Show(exc.ToString()); } } } private void mnu_save_Click(object sender, EventArgs e) { - string filename; File_Save.ShowDialog(); filename = File_Save.FileName; @@ -254,77 +345,40 @@ namespace Handbrake // Create a StreamWriter and open the file StreamWriter line = new StreamWriter(filename); - //Source - line.WriteLine(text_source.Text); - line.WriteLine(drp_dvdtitle.Text); - line.WriteLine(drop_chapterStart.Text); - line.WriteLine(drop_chapterFinish.Text); - //Destination - line.WriteLine(text_destination.Text); - line.WriteLine(drp_videoEncoder.Text); - line.WriteLine(drp_audioCodec.Text); - line.WriteLine(text_width.Text); - line.WriteLine(text_height.Text); - //Picture Settings Tab - line.WriteLine(text_top.Text); - line.WriteLine(text_bottom.Text); - line.WriteLine(text_left.Text); - line.WriteLine(text_right.Text); - line.WriteLine(drp_subtitle.Text); - //Video Settings Tab - line.WriteLine(text_bitrate.Text); - line.WriteLine(text_filesize.Text); - line.WriteLine(slider_videoQuality.Value.ToString()); - line.WriteLine(check_2PassEncode.CheckState.ToString()); - line.WriteLine(check_DeInterlace.CheckState.ToString()); - line.WriteLine(check_grayscale.CheckState.ToString()); - line.WriteLine(drp_videoFramerate.Text); - line.WriteLine(Check_ChapterMarkers.CheckState.ToString()); - line.WriteLine(CheckPixelRatio.CheckState.ToString()); - line.WriteLine(check_turbo.CheckState.ToString()); - line.WriteLine(check_largeFile.CheckState.ToString()); - //Audio Settings Tab - line.WriteLine(drp_audioBitrate.Text); - line.WriteLine(drp_audioSampleRate.Text); - line.WriteLine(drp_audioChannels.Text); - line.WriteLine(drp_audioMixDown.Text); - //H264 Tab - line.WriteLine(CheckCRF.CheckState.ToString()); - line.WriteLine(rtf_h264advanced.Text); + // Generate and write the query string to the file + String query = GenerateTheQuery(); + line.WriteLine(query); + // close the stream line.Close(); MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } - catch(Exception) + catch (Exception) { MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } - - } - } - private void mnu_update_Click(object sender, EventArgs e) - { - Form Update = new frmUpdate(); - Update.ShowDialog(); + } } private void mnu_exit_Click(object sender, EventArgs e) { - this.Close(); + Application.Exit(); } - // TOOLS MENU -------------------------------------------------------------- + #endregion + + #region Tools Menu + private void mnu_encode_Click(object sender, EventArgs e) { - Form Queue = new frmQueue(); - Queue.ShowDialog(); + showQueue(); } private void mnu_viewDVDdata_Click(object sender, EventArgs e) { - Form DVDData = new frmDVDData(); - DVDData.Show(); + frmDvdInfo dvdInfoWindow = new frmDvdInfo(); + dvdInfoWindow.Show(); } private void mnu_options_Click(object sender, EventArgs e) @@ -333,146 +387,64 @@ namespace Handbrake Options.ShowDialog(); } - // PRESETS MENU -------------------------------------------------------------- - private void mnu_preset_ipod133_Click(object sender, EventArgs e) - { - CheckPixelRatio.CheckState = CheckState.Unchecked; - text_width.Text = "640"; - text_height.Text = "480"; - drp_videoEncoder.Text = "H.264 (iPod)"; - text_bitrate.Text = "1000"; - text_filesize.Text = ""; - slider_videoQuality.Value = 0; - SliderValue.Text = "0%"; - drp_audioBitrate.Text = "160"; - rtf_h264advanced.Text = ""; - drp_crop.Text = "No Crop"; - } + #endregion - private void mnu_preset_ipod178_Click(object sender, EventArgs e) - { - CheckPixelRatio.CheckState = CheckState.Unchecked; - text_width.Text = "640"; - text_height.Text = "352"; - drp_videoEncoder.Text = "H.264 (iPod)"; - text_bitrate.Text = "1000"; - text_filesize.Text = ""; - slider_videoQuality.Value = 0; - SliderValue.Text = "0%"; - drp_audioBitrate.Text = "160"; - rtf_h264advanced.Text = ""; - drp_crop.Text = "No Crop"; - } + #region Presets Menu - private void mnu_preset_ipod235_Click(object sender, EventArgs e) + private void mnu_presetReset_Click(object sender, EventArgs e) { - CheckPixelRatio.CheckState = CheckState.Unchecked; - text_width.Text = "640"; - text_height.Text = "272"; - drp_videoEncoder.Text = "H.264 (iPod)"; - text_bitrate.Text = "1000"; - text_filesize.Text = ""; - slider_videoQuality.Value = 0; - SliderValue.Text = "0%"; - drp_audioBitrate.Text = "160"; - rtf_h264advanced.Text = ""; - drp_crop.Text = "No Crop"; + listview_presets.Items.Clear(); + updatePresets(); + MessageBox.Show("Presets have been updated", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); } - private void mnu_appleTv_Click(object sender, EventArgs e) + private void mnu_SelectDefault_Click(object sender, EventArgs e) { - text_width.Text = ""; - text_height.Text = ""; - drp_videoEncoder.Text = "H.264"; - text_bitrate.Text = "3000"; - text_filesize.Text = ""; - slider_videoQuality.Value = 0; - SliderValue.Text = "0%"; - drp_audioBitrate.Text = "160"; - CheckPixelRatio.CheckState = CheckState.Checked; - drp_audioSampleRate.Text = "48"; - rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2"; - drp_crop.Text = "No Crop"; - - } + ListViewItem item = listview_presets.FindItemWithText("Normal"); - private void mnu_presetPS3_Click(object sender, EventArgs e) - { - CheckPixelRatio.CheckState = CheckState.Unchecked; - text_width.Text = ""; - text_height.Text = ""; - drp_videoEncoder.Text = "H.264"; - text_bitrate.Text = "3000"; - text_filesize.Text = ""; - slider_videoQuality.Value = 0; - SliderValue.Text = "0%"; - drp_audioBitrate.Text = "160"; - CheckPixelRatio.CheckState = CheckState.Checked; - drp_audioSampleRate.Text = "48"; - rtf_h264advanced.Text = "level=41"; - drp_crop.Text = "No Crop"; + if (item != null) + { + listview_presets.SelectedItems.Clear(); + item.Selected = true; + } + + if (presetStatus == false) + { + this.Width = 881; + presetStatus = true; + btn_presets.Text = "Hide Presets"; + } } - private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e) + #endregion + + #region Help Menu + + + private void mnu_quickStart_Click(object sender, EventArgs e) { - //Source - Properties.Settings.Default.DVDSource = text_source.Text; - Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text; - Properties.Settings.Default.ChapterStart = drop_chapterStart.Text; - Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text; - //Destination - Properties.Settings.Default.VideoDest = text_destination.Text; - Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text; - Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text; - Properties.Settings.Default.Width = text_width.Text; - Properties.Settings.Default.Height = text_height.Text; - //Picture Settings Tab - Properties.Settings.Default.CroppingOption = drp_crop.Text; - Properties.Settings.Default.CropTop = text_top.Text; - Properties.Settings.Default.CropBottom = text_bottom.Text; - Properties.Settings.Default.CropLeft = text_left.Text; - Properties.Settings.Default.CropRight = text_right.Text; - Properties.Settings.Default.Subtitles = drp_subtitle.Text; - //Video Settings Tab - Properties.Settings.Default.VideoBitrate = text_bitrate.Text; - Properties.Settings.Default.VideoFilesize = text_filesize.Text; - Properties.Settings.Default.VideoQuality = slider_videoQuality.Value; - Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString(); - Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString(); - Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString(); - Properties.Settings.Default.Framerate = drp_videoFramerate.Text; - Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString(); - Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString(); - Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString(); - //Audio Settings Tab - Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text; - Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text; - Properties.Settings.Default.AudioChannels = drp_audioChannels.Text; - //H264 Tab - Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString(); - Properties.Settings.Default.H264 = rtf_h264advanced.Text; - Properties.Settings.Default.Save(); + Form QuickStart = new frmQuickStart(); + QuickStart.ShowDialog(); } - // Help Menu -------------------------------------------------------------- private void mnu_wiki_Click(object sender, EventArgs e) { - Process.Start("http://handbrake.m0k.org/trac"); + Process.Start("http://handbrake.m0k.org/trac"); } - private void mnu_onlineDocs_Click(object sender, EventArgs e) + private void mnu_faq_Click(object sender, EventArgs e) { - Process.Start("http://handbrake.m0k.org/?page_id=11"); + Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq"); } - private void mnu_faq_Click(object sender, EventArgs e) + private void mnu_onlineDocs_Click(object sender, EventArgs e) { - Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq"); + Process.Start("http://handbrake.m0k.org/?page_id=11"); } private void mnu_homepage_Click(object sender, EventArgs e) { - Process.Start("http://handbrake.m0k.org"); + Process.Start("http://handbrake.m0k.org"); } private void mnu_forum_Click(object sender, EventArgs e) @@ -480,21 +452,38 @@ namespace Handbrake Process.Start("http://handbrake.m0k.org/forum"); } + private void mnu_UpdateCheck_Click(object sender, EventArgs e) + { + Boolean update = updateCheck(); + if (update == true) + { + MessageBox.Show("There is a new update available. Please visit http://handbrake.m0k.org for details!", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void mnu_about_Click(object sender, EventArgs e) { - Form About = new frmAbout(); + Form About = new frmAbout(); About.ShowDialog(); } - + #endregion // -------------------------------------------------------------- // Buttons on the main Window // -------------------------------------------------------------- + + #region Buttons + private void btn_Browse_Click(object sender, EventArgs e) { - String filename =""; + String filename = ""; text_source.Text = ""; + frmDvdInfo dvdInfoWindow = new frmDvdInfo(); if (RadioDVD.Checked) { @@ -502,11 +491,10 @@ namespace Handbrake filename = DVD_Open.SelectedPath; if (filename != "") { + Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); text_source.Text = filename; - Form frmReadDVD = new frmReadDVD(filename, this); - frmReadDVD.ShowDialog(); + frmRD.ShowDialog(); } - } else { @@ -514,23 +502,37 @@ namespace Handbrake filename = ISO_Open.FileName; if (filename != "") { + Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); text_source.Text = filename; - Form frmReadDVD = new frmReadDVD(filename, this); - frmReadDVD.ShowDialog(); + frmRD.ShowDialog(); } + } + // Check if there was titles in the dvd title dropdown + if (filename == "") + { + 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) + { + MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); + } } private void btn_destBrowse_Click(object sender, EventArgs e) { - // TODO: Need to write some code to check if there is a reasonable amount of disk space left. + // This removes the file extension from the filename box on the save file dialog. + // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected. + // Should be a nicer way to do this. + DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", "").Replace(".m4v", "").Replace(".mkv", "").Replace(".ogm", "").Replace(".avi", ""); + // Show the dialog and set the main form file path DVD_Save.ShowDialog(); text_destination.Text = DVD_Save.FileName; + // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing) if (Check_ChapterMarkers.Checked) { string destination = text_destination.Text; @@ -557,43 +559,365 @@ namespace Handbrake private void btn_queue_Click(object sender, EventArgs e) { - Form Queue = new frmQueue(); - Queue.Show(); + + 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 + + // 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); + } + + 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(); + + } + + // Varibles + private Boolean presetStatus = false; + + // Buttons + private void btn_presets_Click(object sender, EventArgs e) + { + if (presetStatus == false) + { + this.Width = 881; + presetStatus = true; + btn_presets.Text = "Hide Presets"; + } + else + { + this.Width = 590; + presetStatus = false; + btn_presets.Text = "Show Presets"; + } + + } + + private void btn_setDefault_Click(object sender, EventArgs e) + { + //Source + Properties.Settings.Default.DVDSource = text_source.Text; + Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text; + Properties.Settings.Default.ChapterStart = drop_chapterStart.Text; + Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text; + //Destination + Properties.Settings.Default.VideoDest = text_destination.Text; + Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text; + Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text; + Properties.Settings.Default.Width = text_width.Text; + Properties.Settings.Default.Height = text_height.Text; + //Picture Settings Tab + Properties.Settings.Default.CroppingOption = drp_crop.Text; + Properties.Settings.Default.CropTop = text_top.Text; + Properties.Settings.Default.CropBottom = text_bottom.Text; + Properties.Settings.Default.CropLeft = text_left.Text; + Properties.Settings.Default.CropRight = text_right.Text; + Properties.Settings.Default.Subtitles = drp_subtitle.Text; + //Video Settings Tab + Properties.Settings.Default.VideoBitrate = text_bitrate.Text; + Properties.Settings.Default.VideoFilesize = text_filesize.Text; + Properties.Settings.Default.VideoQuality = slider_videoQuality.Value; + Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString(); + Properties.Settings.Default.DeInterlace = drp_deInterlace_option.Text; + Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString(); + Properties.Settings.Default.Framerate = drp_videoFramerate.Text; + Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString(); + Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString(); + Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString(); + Properties.Settings.Default.detelecine = check_detelecine.CheckState.ToString(); + Properties.Settings.Default.denoise = drp_deNoise.Text; + Properties.Settings.Default.deblock = check_deblock.CheckState.ToString(); + Properties.Settings.Default.chapterMarker = Check_ChapterMarkers.CheckState.ToString(); + //Audio Settings Tab + Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text; + Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text; + Properties.Settings.Default.AudioChannels = drp_audioChannels.Text; + //H264 Tab + Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString(); + Properties.Settings.Default.H264 = rtf_h264advanced.Text; + //Preset + Properties.Settings.Default.selectedPreset = groupBox_output.Text.Replace("Output Settings (Preset: ", "").Replace("\"", "").Replace(")", ""); + // 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 == "iPhone / iPod Touch") + { + selectedPreset = "iPhone"; + } + + 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) + { + MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + + } + #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) { - String query = ""; - - if (QueryEditorText.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 + { + btn_eCancel.Enabled = true; + String query = ""; + if (QueryEditorText.Text == "") + { + query = GenerateTheQuery(); + } + else + { + 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) { - query = GenerateTheQuery(); + MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { - query = QueryEditorText.Text; + 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; + } } + } - System.Diagnostics.Process hbProc = new System.Diagnostics.Process(); - hbProc.StartInfo.FileName = "hbcli.exe"; - hbProc.StartInfo.Arguments = query; - hbProc.StartInfo.UseShellExecute = false; - hbProc.Start(); - + private delegate void UpdateUIHandler(); - MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - - // TODO: Need to write a bit of code here to do process monitoring. - // Note: hbProc.waitForExit will freeze the app, meaning one cannot add additional items to the queue during an encode. + private void setEncodeLabel() + { + if (this.InvokeRequired) + { + this.BeginInvoke(new UpdateUIHandler(setEncodeLabel)); + return; + } + lbl_encode.Text = "Encoding Finished"; } - // -------------------------------------------------------------- - // Items that require actions on frmMain - // -------------------------------------------------------------- + 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")) { @@ -604,20 +928,21 @@ namespace Handbrake if (chapterFinish < chapterStart) { - MessageBox.Show("Invalid Chapter Range! - Final chapter can not be smaller than the starting chapter.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + drop_chapterStart.BackColor = Color.LightCoral; } } catch (Exception) { - MessageBox.Show("Invalid Character Entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); + 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")) { @@ -626,14 +951,14 @@ namespace Handbrake int chapterFinish = int.Parse(drop_chapterFinish.Text); int chapterStart = int.Parse(drop_chapterStart.Text); - if (chapterFinish > chapterStart) + if (chapterFinish < chapterStart) { - MessageBox.Show("Invalid Chapter Range! - Start chapter can not be larger than the Final chapter.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + drop_chapterFinish.BackColor = Color.LightCoral; } } catch (Exception) { - MessageBox.Show("Invalid Character Entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); + drop_chapterFinish.BackColor = Color.LightCoral; } } } @@ -644,6 +969,7 @@ namespace Handbrake slider_videoQuality.Value = 0; SliderValue.Text = "0%"; CheckCRF.CheckState = CheckState.Unchecked; + CheckCRF.Enabled = false; } private void text_filesize_TextChanged(object sender, EventArgs e) @@ -652,6 +978,7 @@ namespace Handbrake slider_videoQuality.Value = 0; SliderValue.Text = "0%"; CheckCRF.CheckState = CheckState.Unchecked; + CheckCRF.Enabled = false; } private void slider_videoQuality_Scroll(object sender, EventArgs e) @@ -659,6 +986,7 @@ namespace Handbrake SliderValue.Text = slider_videoQuality.Value.ToString() + "%"; text_bitrate.Text = ""; text_filesize.Text = ""; + CheckCRF.Enabled = true; } private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -670,26 +998,49 @@ namespace Handbrake { try { - if (CheckPixelRatio.Checked) { + if (CheckPixelRatio.Checked) + { text_width.Text = ""; - } else { - if ((int.Parse(text_width.Text) % 16) != 0){ + text_width.BackColor = Color.LightCoral; + CheckPixelRatio.BackColor = Color.LightCoral; + } + else + { + if ((int.Parse(text_width.Text) % 16) != 0) + { text_width.BackColor = Color.LightCoral; - }else { + } + else + { text_width.BackColor = Color.LightGreen; } } - if (!lbl_Aspect.Text.Equals("Select a Title")){ - int height = int.Parse(text_width.Text) / int.Parse(lbl_Aspect.Text); - int mod16 = height % 16; + if (lbl_Aspect.Text != "Select a Title") + { + double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text); + double mod16 = height % 16; height = height - mod16; - text_height.Text = height.ToString(); + + if (text_width.Text == "") + { + text_height.Text = ""; + text_width.BackColor = Color.White; + } + else + { + text_height.Text = height.ToString(); + text_width.BackColor = Color.LightGreen; + } } - - } catch(Exception){ - } + catch (Exception) + { + // No need to throw an error here. + // Note on non english systems, this will throw an error because of double.Parse(lbl_Aspect.Text); not working. + } + + } private void text_height_TextChanged(object sender, EventArgs e) @@ -699,6 +1050,8 @@ namespace Handbrake if (CheckPixelRatio.Checked) { text_height.Text = ""; + text_height.BackColor = Color.LightCoral; + CheckPixelRatio.BackColor = Color.LightCoral; } else { @@ -711,7 +1064,10 @@ namespace Handbrake text_height.BackColor = Color.LightGreen; } } - } catch(Exception){ + + } + catch (Exception) + { // No need to alert the user. } } @@ -720,10 +1076,10 @@ namespace Handbrake { if ((string)drp_crop.SelectedItem == "Manual") { - text_left.Enabled = true; - text_right.Enabled = true; - text_top.Enabled = true; - text_bottom.Enabled = true; + text_left.Enabled = true; + text_right.Enabled = true; + text_top.Enabled = true; + text_bottom.Enabled = true; } if ((string)drp_crop.SelectedItem == "Auto Crop") @@ -761,18 +1117,50 @@ namespace Handbrake } } - + private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e) { text_width.Text = ""; text_height.Text = ""; text_width.BackColor = Color.White; text_height.BackColor = Color.White; + CheckPixelRatio.BackColor = TabPage1.BackColor; + } + + private void check_2PassEncode_CheckedChanged(object sender, EventArgs e) + { + if (check_2PassEncode.CheckState.ToString() == "Checked") + { + if (drp_videoEncoder.Text.Contains("H.264")) + { + check_turbo.Enabled = true; + } + } + else + { + check_turbo.Enabled = false; + check_turbo.CheckState = CheckState.Unchecked; + } + } + + private void check_largeFile_CheckedChanged(object sender, EventArgs e) + { + if (!text_destination.Text.Contains(".mp4")) + { + lbl_largeMp4Warning.Text = "Warning: Only mp4 files are supported"; + lbl_largeMp4Warning.ForeColor = Color.Red; + check_largeFile.CheckState = CheckState.Unchecked; + } + else + { + lbl_largeMp4Warning.Text = "Warning: Breaks iPod, @TV, PS3 compatibility."; + lbl_largeMp4Warning.ForeColor = Color.Black; + } } private void drp_dvdtitle_Click(object sender, EventArgs e) { - if (drp_dvdtitle.Items.Count == 1) + if (drp_dvdtitle.Items.Count == 0) { MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } @@ -793,7 +1181,7 @@ namespace Handbrake drp_audioMixDown.Items.Add("Dolby Surround"); drp_audioMixDown.Items.Add("Dolby Pro Logic II"); drp_audioMixDown.Items.Add("6 Channel Discrete"); - + drp_audioBitrate.Items.Clear(); drp_audioBitrate.Items.Add("32"); drp_audioBitrate.Items.Add("40"); @@ -829,7 +1217,6 @@ namespace Handbrake drp_audioBitrate.Items.Add("224"); drp_audioBitrate.Items.Add("256"); drp_audioBitrate.Items.Add("320"); - drp_audioBitrate.Items.Add("384"); } } @@ -868,23 +1255,11 @@ namespace Handbrake destination = destination.Replace(".mp4", ".m4v"); text_destination.Text = destination; } - } - - private void check_largeFile_CheckedChanged(object sender, EventArgs e) - { - if (!text_destination.Text.Contains(".mp4")) - { - MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - check_largeFile.CheckState = CheckState.Unchecked; - } - } - - private void check_turbo_CheckedChanged(object sender, EventArgs e) - { - if (!drp_videoEncoder.Text.Contains("H.264")) + else { - MessageBox.Show("This option is only compatible with the H.264 encoder's", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - check_turbo.CheckState = CheckState.Unchecked; + string destination = text_destination.Text; + destination = destination.Replace(".m4v", ".mp4"); + text_destination.Text = destination; } } @@ -895,19 +1270,23 @@ namespace Handbrake { check_turbo.CheckState = CheckState.Unchecked; CheckCRF.CheckState = CheckState.Unchecked; + CheckCRF.Enabled = false; + check_turbo.Enabled = false; + h264Tab.Enabled = false; + rtf_h264advanced.Text = ""; } - } - - private void CheckCRF_CheckedChanged(object sender, EventArgs e) - { - if (slider_videoQuality.Value == 0) + else { - MessageBox.Show("This option is can only be used with the 'Video Quality' slider.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - CheckCRF.CheckState = CheckState.Unchecked; + CheckCRF.Enabled = true; + if (check_2PassEncode.CheckState.ToString() == "Checked") + { + check_turbo.Enabled = true; + } + h264Tab.Enabled = true; } + } - Parsing.DVD thisDVD; public void setStreamReader(Parsing.DVD dvd) { this.thisDVD = dvd; @@ -918,47 +1297,68 @@ namespace Handbrake // 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") { - string[] temp; - string title; - temp = drp_dvdtitle.Text.Split(' '); - title = temp[0].Trim(); - - int count = thisDVD.Titles.Count - 1; - int counter = 0; + Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title; + + // Set the Aspect Ratio + lbl_Aspect.Text = selectedTitle.AspectRatio.ToString(); - while (count >= counter) + // 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]); + + // 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(); + } - if (thisDVD.Titles[counter].TitleNumber.ToString() == title) - { - lbl_Aspect.Text = thisDVD.Titles[counter].AspectRatio.ToString(); - lbl_RecomendedCrop.Text = thisDVD.Titles[counter].AutoCropDimensions[0] + "/" + thisDVD.Titles[counter].AutoCropDimensions[1] + "/" + thisDVD.Titles[counter].AutoCropDimensions[2] + "/" + thisDVD.Titles[counter].AutoCropDimensions[3]; - // Still need to set these up. - MessageBox.Show(thisDVD.Titles[counter].AudioTracks[0].ToString()); - MessageBox.Show(thisDVD.Titles[counter].Chapters.ToString()); - MessageBox.Show(thisDVD.Titles[counter].Subtitles.ToString()); - } - counter++; + // 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) + { + drp_audioChannels.Text = drp_audioChannels.Items[0].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) + { + drp_subtitle.Text = drp_subtitle.Items[0].ToString(); + } } - - } + } - // - // The Query Generation Function - // + #endregion + //--------------------------------------------------- + // Some Functions + // - Query Generation + //--------------------------------------------------- - // This function was imported from old vb.net version of this application. - // It could probably do with being cleaned up a good deal at some point + #region Program Functions + + // Generate a CLI Query String public string GenerateTheQuery() { string source = text_source.Text; @@ -968,19 +1368,14 @@ namespace Handbrake int totalChapters = drop_chapterFinish.Items.Count - 1; string dvdChapter = ""; - if (source == "") - MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else - { - source = " -i " + '"' + source+ '"'; //'"'+ - } + source = " -i " + '"' + source + '"'; - if (dvdTitle == "Automatic") + if (dvdTitle == "Automatic") dvdTitle = ""; else { string[] titleInfo = dvdTitle.Split(' '); - dvdTitle = " -t "+ titleInfo[0]; + dvdTitle = " -t " + titleInfo[0]; } if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto")) @@ -990,7 +1385,7 @@ namespace Handbrake else dvdChapter = " -c " + chapterStart + "-" + chapterFinish; - string querySource = source+ dvdTitle+ dvdChapter; + string querySource = source + dvdTitle + dvdChapter; // ---------------------------------------------------------------------- // Destination @@ -1001,7 +1396,7 @@ namespace Handbrake string width = text_width.Text; string height = text_height.Text; - if (destination == "") + if (destination == "") MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); else destination = " -o " + '"' + destination + '"'; //'"'+ @@ -1025,10 +1420,10 @@ namespace Handbrake videoEncoder = " -e x264b30"; break; default: - Mixdown = " -e x264"; + videoEncoder = " -e x264"; break; } - + switch (audioEncoder) { case "AAC": @@ -1044,19 +1439,25 @@ namespace Handbrake audioEncoder = " -E ac3"; break; default: - Mixdown = " -E faac"; + audioEncoder = " -E faac"; break; } - if (width != "") - width = " -w "+ width; - + if (width != "") + width = " -w " + width; + + + if (height == "Auto") + { + height = ""; + } + else if (height != "") + { + height = " -l " + height; + } - if (height != "") - height = " -l "+ height; - - string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height; + string queryDestination = destination + videoEncoder + audioEncoder + width + height; // ---------------------------------------------------------------------- // Picture Settings Tab @@ -1068,6 +1469,11 @@ namespace Handbrake string cropRight = text_right.Text; string subtitles = drp_subtitle.Text; string cropOut = ""; + string deInterlace_Option = drp_deInterlace_option.Text; + string deinterlace = ""; + string grayscale = ""; + string pixelRatio = ""; + string ChapterMarkers = ""; // Returns Crop Query if (cropSetting == "Auto Crop") @@ -1075,77 +1481,111 @@ namespace Handbrake else if (cropSetting == "No Crop") cropOut = " --crop 0:0:0:0 "; else + { + if (text_top.Text == "") + cropTop = "0"; + if (text_bottom.Text == "") + cropBottom = "0"; + if (text_left.Text == "") + cropLeft = "0"; + if (text_right.Text == "") + cropRight = "0"; + cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight; + } - if (subtitles == "None") + if (subtitles == "None") subtitles = ""; - else if (subtitles == "") + else if (subtitles == "") subtitles = ""; else { string[] tempSub; tempSub = subtitles.Split(' '); - subtitles = " -s "+ tempSub[0]; + subtitles = " -s " + tempSub[0]; + } + + switch (deInterlace_Option) + { + case "None": + deinterlace = ""; + break; + case "Original (Fast)": + deinterlace = " --deinterlace=fast"; + break; + case "yadif (Slow)": + deinterlace = " --deinterlace=slow"; + break; + case "yadif + mcdeint (Slower)": + deinterlace = " --deinterlace=slower"; + break; + case "yadif + mcdeint (Slowest)": + deinterlace = " --deinterlace=slowest"; + break; + default: + deinterlace = ""; + break; } - string queryPictureSettings = cropOut+ subtitles; + if (check_grayscale.Checked) + grayscale = " -g "; + + if (CheckPixelRatio.Checked) + pixelRatio = " -p "; + + if (Check_ChapterMarkers.Checked) + ChapterMarkers = " -m "; + + string queryPictureSettings = cropOut + subtitles + deinterlace + grayscale + pixelRatio + ChapterMarkers; // ---------------------------------------------------------------------- // Video Settings Tab string videoBitrate = text_bitrate.Text; string videoFilesize = text_filesize.Text; - int videoQuality = slider_videoQuality.Value; + double videoQuality = slider_videoQuality.Value; string vidQSetting = ""; string twoPassEncoding = ""; - string deinterlace = ""; - string grayscale = ""; string videoFramerate = drp_videoFramerate.Text; - string pixelRatio = ""; - string ChapterMarkers = ""; string turboH264 = ""; string largeFile = ""; + string deblock = ""; + string detelecine = ""; + string denoise = ""; + string CRF = CheckCRF.CheckState.ToString(); + + if (CRF == "Checked") + CRF = " -Q "; + else + CRF = ""; - if (videoBitrate != "") - videoBitrate = " -b "+ videoBitrate; + if (videoBitrate != "") + videoBitrate = " -b " + videoBitrate; - if (videoFilesize != "") - videoFilesize = " -S "+ videoFilesize; + if (videoFilesize != "") + videoFilesize = " -S " + videoFilesize; // Video Quality Setting - if ((videoQuality == 0)) + if ((videoQuality == 0)) vidQSetting = ""; else { - videoQuality = videoQuality/ 100; - if (videoQuality == 1) + videoQuality = videoQuality / 100; + if (videoQuality == 1) { vidQSetting = "1.0"; } - - vidQSetting = " -q " + videoQuality.ToString(); + vidQSetting = " -q " + videoQuality.ToString(new CultureInfo("en-US")); } if (check_2PassEncode.Checked) twoPassEncoding = " -2 "; - if (check_DeInterlace.Checked) - deinterlace = " -d "; - - if (check_grayscale.Checked) - grayscale = " -g "; - - if (videoFramerate == "Automatic") + if (videoFramerate == "Automatic") videoFramerate = ""; else - videoFramerate = " -r "+ videoFramerate; - - if (CheckPixelRatio.Checked) - pixelRatio = " -p "; - - if (Check_ChapterMarkers.Checked) - ChapterMarkers = " -m "; + videoFramerate = " -r " + videoFramerate; if (check_turbo.Checked) turboH264 = " -T "; @@ -1153,7 +1593,32 @@ namespace Handbrake if (check_largeFile.Checked) largeFile = " -4 "; - string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile; + if (check_deblock.Checked) + deblock = " --deblock"; + + if (check_detelecine.Checked) + detelecine = " --detelecine"; + + switch (drp_deNoise.Text) + { + case "None": + denoise = ""; + break; + case "Weak": + denoise = " --denoise=weak"; + break; + case "Medium": + denoise = " --denoise=medium"; + break; + case "Strong": + denoise = " --denoise=strong"; + break; + default: + denoise = ""; + break; + } + + string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + CRF + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise; // ---------------------------------------------------------------------- // Audio Settings Tab @@ -1164,21 +1629,21 @@ namespace Handbrake string Mixdown = drp_audioMixDown.Text; string SixChannelAudio = ""; - if (audioBitrate != "") - audioBitrate = " -B "+ audioBitrate; + if (audioBitrate != "") + audioBitrate = " -B " + audioBitrate; - if (audioSampleRate != "") - audioSampleRate = " -R "+ audioSampleRate; + if (audioSampleRate != "") + audioSampleRate = " -R " + audioSampleRate; - if (audioChannels == "Automatic") + if (audioChannels == "Automatic") audioChannels = ""; - else if (audioChannels == "") + else if (audioChannels == "") audioChannels = ""; else { string[] tempSub; tempSub = audioChannels.Split(' '); - audioChannels = " -a "+ tempSub[0]; + audioChannels = " -a " + tempSub[0]; } switch (Mixdown) @@ -1202,34 +1667,30 @@ namespace Handbrake Mixdown = "6ch"; break; default: - Mixdown = "stero"; + Mixdown = ""; break; } - if (Mixdown != "") - SixChannelAudio = " -6 "+ Mixdown; + if (Mixdown != "") + SixChannelAudio = " -6 " + Mixdown; else SixChannelAudio = ""; - string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio; + string queryAudioSettings = audioBitrate + audioSampleRate + audioChannels + SixChannelAudio; // ---------------------------------------------------------------------- // H.264 Tab - string CRF = CheckCRF.CheckState.ToString(); + string h264Advanced = rtf_h264advanced.Text; - if ((CRF == "1")) - CRF = " -Q "; - else - CRF = ""; - if ((h264Advanced == "")) + if ((h264Advanced == "")) h264Advanced = ""; else - h264Advanced = " -x "+ h264Advanced; - + h264Advanced = " -x " + h264Advanced; + - string h264Settings = CRF+ h264Advanced; + string h264Settings = h264Advanced; // ---------------------------------------------------------------------- // Processors (Program Settings) @@ -1237,10 +1698,10 @@ namespace Handbrake string processors = Properties.Settings.Default.Processors; // Number of Processors Handler - if (processors == "Automatic") + if (processors == "Automatic") processors = ""; else - processors = " -C "+ processors+ " "; + processors = " -C " + processors + " "; string queryAdvancedSettings = processors; @@ -1249,14 +1710,206 @@ namespace Handbrake // Verbose option (Program Settings) string verbose = ""; - if (Properties.Settings.Default.verbose == "1") + if (Properties.Settings.Default.verbose == "Checked") verbose = " -v "; // ---------------------------------------------------------------------- - return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose; + return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + queryAdvancedSettings + verbose; + } + + // Load a Preset + private void presetLoader(Functions.QueryParser presetQuery, string name) + { + // --------------------------- + // Setup the GUI + // --------------------------- + + // Source tab + #region source + if (presetQuery.Source != "") + text_source.Text = presetQuery.Source; + + if (presetQuery.DVDTitle != 0) + drp_dvdtitle.Text = presetQuery.DVDTitle.ToString(); + + if (presetQuery.DVDChapterStart != 0) + drop_chapterStart.Text = presetQuery.DVDChapterStart.ToString(); + + if (presetQuery.DVDChapterFinish != 0) + drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString(); + + if (presetQuery.Format != "") + { + string destination = text_destination.Text; + destination = destination.Replace(".mp4", "." + presetQuery.Format); + destination = destination.Replace(".m4v", "." + presetQuery.Format); + destination = destination.Replace(".avi", "." + presetQuery.Format); + destination = destination.Replace(".mkv", "." + presetQuery.Format); + destination = destination.Replace(".ogm", "." + presetQuery.Format); + text_destination.Text = destination; + } + + #endregion + + // Destination tab + #region destination + + if (presetQuery.Destination != "") + text_destination.Text = presetQuery.Destination; + + drp_videoEncoder.Text = presetQuery.VideoEncoder; + drp_audioCodec.Text = presetQuery.AudioEncoder; + if (presetQuery.Width != 0) + { + text_width.Text = presetQuery.Width.ToString(); + + } + else + { + text_width.Text = ""; + text_width.BackColor = Color.White; + } + + if (presetQuery.Height != 0) + { + text_height.Text = presetQuery.Height.ToString(); + } + else + { + text_height.Text = ""; + text_height.BackColor = Color.White; + } + #endregion + + // Picture Settings Tab + #region Picture + drp_crop.Text = "Manual"; + text_top.Text = presetQuery.CropTop; + text_bottom.Text = presetQuery.CropBottom; + text_left.Text = presetQuery.CropLeft; + text_right.Text = presetQuery.CropRight; + + drp_deInterlace_option.Text = presetQuery.DeInterlace; + drp_deNoise.Text = presetQuery.DeNoise; + + if (presetQuery.DeTelecine == true) + { + check_detelecine.CheckState = CheckState.Checked; + } + else + { + check_detelecine.CheckState = CheckState.Unchecked; + } + + + if (presetQuery.DeBlock == true) + { + check_deblock.CheckState = CheckState.Checked; + } + else + { + check_deblock.CheckState = CheckState.Unchecked; + } + + if (presetQuery.ChapterMarkers == true) + { + Check_ChapterMarkers.CheckState = CheckState.Checked; + } + else + { + Check_ChapterMarkers.CheckState = CheckState.Unchecked; + } + + if (presetQuery.Anamorphic == true) + { + CheckPixelRatio.CheckState = CheckState.Checked; + } + else + { + CheckPixelRatio.CheckState = CheckState.Unchecked; + } + #endregion + + // Video Settings Tab + #region video + text_bitrate.Text = presetQuery.AverageVideoBitrate; + text_filesize.Text = presetQuery.VideoTargetSize; + slider_videoQuality.Value = presetQuery.VideoQuality; + if (slider_videoQuality.Value != 0) + { + CheckCRF.Enabled = true; + int ql = presetQuery.VideoQuality; + SliderValue.Text = ql.ToString() + "%"; + } + + if (presetQuery.TwoPass == true) + { + check_2PassEncode.CheckState = CheckState.Checked; + } + else + { + check_2PassEncode.CheckState = CheckState.Unchecked; + } + + if (presetQuery.Grayscale == true) + { + check_grayscale.CheckState = CheckState.Checked; + } + else + { + check_grayscale.CheckState = CheckState.Unchecked; + } + + drp_videoFramerate.Text = presetQuery.VideoFramerate; + + if (presetQuery.TurboFirstPass == true) + { + check_turbo.CheckState = CheckState.Checked; + } + else + { + check_turbo.CheckState = CheckState.Unchecked; + } + + if (presetQuery.LargeMP4 == true) + { + check_largeFile.CheckState = CheckState.Checked; + } + else + { + check_largeFile.CheckState = CheckState.Unchecked; + } + if (presetQuery.CRF == true) + { + CheckCRF.CheckState = CheckState.Checked; + } + else + { + CheckCRF.CheckState = CheckState.Unchecked; + } + #endregion + + // Audio Settings Tab + #region audio + drp_audioBitrate.Text = presetQuery.AudioBitrate; + drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate; + drp_audioChannels.Text = presetQuery.AudioTrack1; + drp_audioMixDown.Text = presetQuery.AudioTrackMix; + drp_subtitle.Text = presetQuery.Subtitles; + #endregion + + // H264 Tab & Preset Name + #region other + rtf_h264advanced.Text = presetQuery.H264Query; + + // Set the preset name + groupBox_output.Text = "Output Settings (Preset: " + name + ")"; + #endregion } + #endregion + // This is the END of the road ------------------------------------------------------------------------------ } } \ No newline at end of file