X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FFunctions%2FCommon.cs;h=c911b836e1b96fd18c71c41faf68c84e5d01fb8e;hb=e9f8c16ea4a74b484ca6d542419244ba3354a48d;hp=e298beac208006df5fe542346fb93ed887017c69;hpb=43235379d9a114d2825d1208acbd4b97c35c3661;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/Functions/Common.cs b/win/C#/Functions/Common.cs index e298beac..c911b836 100644 --- a/win/C#/Functions/Common.cs +++ b/win/C#/Functions/Common.cs @@ -1,3 +1,9 @@ +/* Common.cs $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + using System; using System.Collections.Generic; using System.Text; @@ -13,7 +19,7 @@ namespace Handbrake.Functions /* * Checks for updates and returns "true" boolean if one exists. */ - public Boolean updateCheck() + public Boolean updateCheck(Boolean debug) { try { @@ -21,7 +27,7 @@ namespace Handbrake.Functions string build = rssRead.build(); int latest = int.Parse(build); - int current = Properties.Settings.Default.build; + int current = Properties.Settings.Default.hb_build; int skip = Properties.Settings.Default.skipversion; if (latest == skip) @@ -36,11 +42,12 @@ namespace Handbrake.Functions } catch (Exception exc) { - MessageBox.Show(exc.ToString()); + if (debug == true) + MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } - + /* * Function which generates the filename and path automatically based on the Source Name, DVD title and DVD Chapters */ @@ -76,7 +83,10 @@ namespace Handbrake.Functions { string filePath = ""; if (Properties.Settings.Default.autoNamePath.Trim() != "") - filePath = Properties.Settings.Default.autoNamePath + "\\"; + { + if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location") + filePath = Properties.Settings.Default.autoNamePath + "\\"; + } mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4"; } else @@ -117,6 +127,10 @@ namespace Handbrake.Functions // Source tab #region source + // Reset some vaules to stock first to prevent errors. + mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked; + + // Now load all the new settings onto the main window if (presetQuery.Source != "") mainWindow.text_source.Text = presetQuery.Source; @@ -129,7 +143,7 @@ namespace Handbrake.Functions if (presetQuery.DVDChapterFinish != 0) mainWindow.drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString(); - if (presetQuery.Format != "") + if (presetQuery.Format != null) { string destination = mainWindow.text_destination.Text; destination = destination.Replace(".mp4", "." + presetQuery.Format); @@ -149,13 +163,22 @@ namespace Handbrake.Functions mainWindow.text_destination.Text = presetQuery.Destination; mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder; - mainWindow.drp_audioCodec.Text = presetQuery.AudioEncoder; + + if (presetQuery.IpodAtom == true) + mainWindow.check_iPodAtom.CheckState = CheckState.Checked; + else + mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked; + + if (presetQuery.OptimizeMP4 == true) + mainWindow.check_optimiseMP4.CheckState = CheckState.Checked; + else + mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked; #endregion // Picture Settings Tab #region Picture - mainWindow.drp_crop.Text = "Manual"; + mainWindow.drp_crop.SelectedIndex = 1; mainWindow.text_top.Text = presetQuery.CropTop; mainWindow.text_bottom.Text = presetQuery.CropBottom; mainWindow.text_left.Text = presetQuery.CropLeft; @@ -175,27 +198,26 @@ namespace Handbrake.Functions else mainWindow.check_deblock.CheckState = CheckState.Unchecked; - if (presetQuery.ChapterMarkers == true) - mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked; - else - mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked; if (presetQuery.Anamorphic == true) - mainWindow.CheckPixelRatio.CheckState = CheckState.Checked; + mainWindow.drp_anamorphic.SelectedIndex = 1; else - mainWindow.CheckPixelRatio.CheckState = CheckState.Unchecked; + mainWindow.drp_anamorphic.SelectedIndex = 0; if (presetQuery.LooseAnamorphic == true) - mainWindow.check_lAnamorphic.CheckState = CheckState.Checked; + mainWindow.drp_anamorphic.SelectedIndex = 2; else - mainWindow.check_lAnamorphic.CheckState = CheckState.Unchecked; + { + if (presetQuery.Anamorphic != true) + mainWindow.drp_anamorphic.SelectedIndex = 0; + } + if (presetQuery.Width != 0) mainWindow.text_width.Text = presetQuery.Width.ToString(); else { mainWindow.text_width.Text = ""; - mainWindow.text_width.BackColor = Color.White; } if (presetQuery.Height != 0) @@ -203,7 +225,6 @@ namespace Handbrake.Functions else { mainWindow.text_height.Text = ""; - mainWindow.text_height.BackColor = Color.White; } if (presetQuery.VFR == true) @@ -243,27 +264,76 @@ namespace Handbrake.Functions if (presetQuery.LargeMP4 == true) mainWindow.check_largeFile.CheckState = CheckState.Checked; else + { mainWindow.check_largeFile.CheckState = CheckState.Unchecked; + mainWindow.check_largeFile.BackColor = Color.Transparent; + } - if (presetQuery.IpodAtom == true) - mainWindow.check_iPodAtom.CheckState = CheckState.Checked; - else - mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked; - if (presetQuery.OptimizeMP4 == true) - mainWindow.check_optimiseMP4.CheckState = CheckState.Checked; + + #endregion + + // Chapter Markers Tab + #region Chapter Markers + + if (presetQuery.ChapterMarkers == true) + { + mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked; + mainWindow.text_destination.Text = mainWindow.text_destination.Text.Replace(".mp4", ".m4v"); + } else - mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked; + mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked; #endregion // Audio Settings Tab #region Audio - mainWindow.drp_audioBitrate.Text = presetQuery.AudioBitrate; - mainWindow.drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate; - mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1; - mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2; - mainWindow.drp_audioMixDown.Text = presetQuery.AudioTrackMix; + + if (presetQuery.AudioTrack1 == "") + mainWindow.drp_track1Audio.Text = "Automatic"; + else + mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1; + + if (presetQuery.AudioTrack2 == "None") + { + if (presetQuery.AudioEncoder2 != null) + { + mainWindow.drp_track2Audio.SelectedIndex = 1; + mainWindow.drp_audsr_2.Enabled = true; + mainWindow.drp_audmix_2.Enabled = true; + mainWindow.drp_audenc_2.Enabled = true; + mainWindow.drp_audbit_2.Enabled = true; + } + else + { + mainWindow.drp_track2Audio.SelectedIndex = 0; + mainWindow.drp_audsr_2.Enabled = false; + mainWindow.drp_audmix_2.Enabled = false; + mainWindow.drp_audenc_2.Enabled = false; + mainWindow.drp_audbit_2.Enabled = false; + } + + } + else + mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2; + + if (presetQuery.AudioEncoder1 != null) + mainWindow.drp_audenc_1.Text = presetQuery.AudioEncoder1; + mainWindow.drp_audenc_2.Text = presetQuery.AudioEncoder2; + + if (presetQuery.AudioBitrate1 != null) + mainWindow.drp_audbit_1.Text = presetQuery.AudioBitrate1; + mainWindow.drp_audbit_2.Text = presetQuery.AudioBitrate2; + + if (presetQuery.AudioSamplerate1 != null) + mainWindow.drp_audsr_1.Text = presetQuery.AudioSamplerate1; + mainWindow.drp_audsr_2.Text = presetQuery.AudioSamplerate2; + + mainWindow.drp_audmix_1.Text = presetQuery.AudioTrackMix1; + mainWindow.drp_audmix_2.Text = presetQuery.AudioTrackMix2; + + + mainWindow.drp_subtitle.Text = presetQuery.Subtitles; if (presetQuery.ForcedSubtitles == true) @@ -288,7 +358,7 @@ namespace Handbrake.Functions // H264 Tab & Preset Name #region other - mainWindow.rtf_h264advanced.Text = presetQuery.H264Query; + mainWindow.rtf_x264Query.Text = presetQuery.H264Query; // Set the preset name mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")"; @@ -310,8 +380,10 @@ namespace Handbrake.Functions int totalChapters = mainWindow.drop_chapterFinish.Items.Count - 1; string dvdChapter = ""; - if ((source != "") || (source != "Click 'Browse' to continue")) + if ((source != "") && (source.Trim() != "Click 'Browse' to continue")) source = " -i " + '"' + source + '"'; + else + source = ""; if (dvdTitle == "Automatic") dvdTitle = ""; @@ -336,7 +408,6 @@ namespace Handbrake.Functions string destination = mainWindow.text_destination.Text; string videoEncoder = mainWindow.drp_videoEncoder.Text; - string audioEncoder = mainWindow.drp_audioCodec.Text; string width = mainWindow.text_width.Text; string height = mainWindow.text_height.Text; @@ -363,25 +434,6 @@ namespace Handbrake.Functions break; } - switch (audioEncoder) - { - case "AAC": - audioEncoder = " -E faac"; - break; - case "MP3": - audioEncoder = " -E lame"; - break; - case "Vorbis": - audioEncoder = " -E vorbis"; - break; - case "AC3": - audioEncoder = " -E ac3"; - break; - default: - audioEncoder = " -E faac"; - break; - } - if (width != "") width = " -w " + width; @@ -396,7 +448,7 @@ namespace Handbrake.Functions } - string queryDestination = destination + videoEncoder + audioEncoder + width + height; + string queryDestination = destination + videoEncoder + width + height; #endregion // Picture Settings Tab @@ -462,8 +514,13 @@ namespace Handbrake.Functions if (mainWindow.check_grayscale.Checked) grayscale = " -g "; - if (mainWindow.CheckPixelRatio.Checked) + if (mainWindow.drp_anamorphic.SelectedIndex == 1) pixelRatio = " -p "; + else if (mainWindow.drp_anamorphic.SelectedIndex == 2) + pixelRatio = " -P "; + else + pixelRatio = " "; + if (mainWindow.check_deblock.Checked) deblock = " --deblock"; @@ -474,8 +531,7 @@ namespace Handbrake.Functions if (mainWindow.check_vfr.Checked) vfr = " -V "; - if (mainWindow.check_lAnamorphic.Checked) - lanamorphic = " -P "; + string queryPictureSettings = cropOut + deinterlace + deblock + detelecine + vfr + grayscale + pixelRatio + lanamorphic; #endregion @@ -489,6 +545,7 @@ namespace Handbrake.Functions string vidQSetting = ""; string twoPassEncoding = ""; string videoFramerate = mainWindow.drp_videoFramerate.Text; + string vid_frame_rate = ""; string turboH264 = ""; string largeFile = ""; string denoise = ""; @@ -518,10 +575,13 @@ namespace Handbrake.Functions if (mainWindow.check_2PassEncode.Checked) twoPassEncoding = " -2 "; - if (videoFramerate == "Automatic") - videoFramerate = ""; + if (videoFramerate == "Same as source") + vid_frame_rate = ""; else - videoFramerate = " -r " + videoFramerate; + { + if (!mainWindow.check_vfr.Checked) + vid_frame_rate = " -r " + videoFramerate; + } if (mainWindow.check_turbo.Checked) turboH264 = " -T "; @@ -556,31 +616,37 @@ namespace Handbrake.Functions optimizeMP4 = " -O "; - string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + ipodAtom + optimizeMP4 + largeFile + denoise; + string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + vid_frame_rate + turboH264 + ipodAtom + optimizeMP4 + largeFile + denoise; #endregion // Audio Settings Tab #region Audio Settings Tab - string audioBitrate = mainWindow.drp_audioBitrate.Text; - string audioSampleRate = mainWindow.drp_audioSampleRate.Text; - string track1 = mainWindow.drp_track1Audio.Text; - string track2 = mainWindow.drp_track2Audio.Text; + // Used Varibles + string audioBitrate = ""; string audioChannels = ""; - string Mixdown = mainWindow.drp_audioMixDown.Text; string SixChannelAudio = ""; - string subtitles = mainWindow.drp_subtitle.Text; string subScan = ""; string forced = ""; string drc = ""; + string audioSampleRate = ""; + string audioEncoder = ""; - if (audioBitrate != "") - audioBitrate = " -B " + audioBitrate; + // Track 1 + string track1 = mainWindow.drp_track1Audio.Text; + string vencoder1 = mainWindow.drp_audenc_1.Text; + string audioBitrate1 = mainWindow.drp_audbit_1.Text; + string audioSampleRate1 = mainWindow.drp_audsr_1.Text; + string Mixdown1 = mainWindow.drp_audmix_1.Text; - if (audioSampleRate != "") - audioSampleRate = " -R " + audioSampleRate; + // Track 2 + string track2 = mainWindow.drp_track2Audio.Text; + string vencoder2 = mainWindow.drp_audenc_2.Text; + string audioBitrate2 = mainWindow.drp_audbit_2.Text; + string audioSampleRate2 = mainWindow.drp_audsr_2.Text; + string Mixdown2 = mainWindow.drp_audmix_2.Text; - // Audio Track 1 + // Audio Track Selections if (track1 == "Automatic") audioChannels = ""; else if (track1 == "") @@ -594,7 +660,6 @@ namespace Handbrake.Functions audioChannels = " -a " + tempSub[0]; } - // Audio Track 2 if (audioChannels != "") { if ((track2 != "") && (track2 != "None")) @@ -614,38 +679,169 @@ namespace Handbrake.Functions } } + // Audio Mixdown Selections + switch (Mixdown1) + { + case "Automatic": + Mixdown1 = ""; + break; + case "Mono": + Mixdown1 = "mono"; + break; + case "Stereo": + Mixdown1 = "stereo"; + break; + case "Dolby Surround": + Mixdown1 = "dpl1"; + break; + case "Dolby Pro Logic II": + Mixdown1 = "dpl2"; + break; + case "6 Channel Discrete": + Mixdown1 = "6ch"; + break; + default: + Mixdown1 = ""; + break; + } + if (Mixdown1 != "") + SixChannelAudio = " -6 " + Mixdown1; + else + { + if (mainWindow.drp_track2Audio.Text == "None") + SixChannelAudio = ""; + else + { + if (mainWindow.drp_audmix_2.Text == "Automatic") + SixChannelAudio = ""; + else + SixChannelAudio = " -6 dpl2"; + } + } - switch (Mixdown) + switch (Mixdown2) { case "Automatic": - Mixdown = ""; + Mixdown2 = ""; break; case "Mono": - Mixdown = "mono"; + Mixdown2 = "mono"; break; case "Stereo": - Mixdown = "stereo"; + Mixdown2 = "stereo"; break; case "Dolby Surround": - Mixdown = "dpl1"; + Mixdown2 = "dpl1"; break; case "Dolby Pro Logic II": - Mixdown = "dpl2"; + Mixdown2 = "dpl2"; break; case "6 Channel Discrete": - Mixdown = "6ch"; + Mixdown2 = "6ch"; break; default: - Mixdown = ""; + Mixdown2 = ""; break; } - if (Mixdown != "") - SixChannelAudio = " -6 " + Mixdown; - else - SixChannelAudio = ""; + if (Mixdown2 != "") + { + if (SixChannelAudio != "") + SixChannelAudio = SixChannelAudio + "," + Mixdown2; + else + SixChannelAudio = " -6 " + Mixdown2; + } + + // Audio Encoder Selections + switch (mainWindow.drp_audenc_1.Text) + { + case "AAC": + audioEncoder = " -E faac"; + break; + case "MP3": + audioEncoder = " -E lame"; + break; + case "Vorbis": + audioEncoder = " -E vorbis"; + break; + case "AC3": + audioEncoder = " -E ac3"; + break; + case "AAC + AC3": + audioEncoder = " -E aac+ac3"; + break; + default: + break; + } + + switch (mainWindow.drp_audenc_2.Text) + { + case "AAC": + if (audioEncoder == "") + audioEncoder = " -E faac"; + else + audioEncoder = audioEncoder + ",faac"; + break; + case "MP3": + if (audioEncoder == "") + audioEncoder = " -E lame"; + else + audioEncoder = audioEncoder + ",lame"; + break; + case "Vorbis": + if (audioEncoder == "") + audioEncoder = " -E vorbis"; + else + audioEncoder = audioEncoder + ",vorbis"; + break; + case "AC3": + if (audioEncoder == "") + audioEncoder = " -E ac3"; + else + audioEncoder = audioEncoder + ",ac3"; + break; + case "AAC + AC3": + if (audioEncoder == "") + audioEncoder = " -E aac+ac3"; + else + audioEncoder = audioEncoder + ",aac+ac3"; + break; + default: + break; + } + + // Audio BitRate Selections + if (audioBitrate1 != "") + audioBitrate = " -B " + audioBitrate1; + + if (audioBitrate2 != "") + { + if (audioBitrate == "") + audioBitrate = " -B " + audioBitrate2; + else + audioBitrate = audioBitrate + "," + audioBitrate2; + } + + // Audio SampleRate Selections + if (audioSampleRate1 != "") + audioSampleRate = " -R " + audioSampleRate1; + + if (audioSampleRate2 != "") + { + if (audioSampleRate == "") + audioSampleRate = " -R " + audioSampleRate2; + else + audioSampleRate = audioSampleRate + "," + audioSampleRate2; + } + //Dynamic Range Compression (expects a float but a double is used for ease) + double value = mainWindow.slider_drc.Value / 10.0; + value++; + drc = " -D " + value; + + // Subtitles + string subtitles = mainWindow.drp_subtitle.Text; if (subtitles == "None") subtitles = ""; else if (subtitles == "") @@ -665,12 +861,8 @@ namespace Handbrake.Functions if (mainWindow.check_forced.Checked) forced = " -F "; - //Dynamic Range Compression (expects a float but a double is used for ease) - double value = mainWindow.slider_drc.Value / 10.0; - value++; - drc = " -D " + value; - string queryAudioSettings = audioBitrate + audioSampleRate + drc + audioChannels + SixChannelAudio + subScan + subtitles + forced; + string queryAudioSettings = audioChannels + SixChannelAudio + audioEncoder + audioBitrate + audioSampleRate + drc + subScan + subtitles + forced; #endregion // Chapter Markers Tab @@ -678,20 +870,53 @@ namespace Handbrake.Functions string ChapterMarkers = ""; + // Attach Source name and dvd title to the start of the chapters.csv filename. + // This is for the queue. It allows different chapter name files for each title. + string source_name = mainWindow.text_source.Text; + string[] sourceName = source.Split('\\'); + source_name = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", ""); + source_name = source_name.Replace("\"", ""); + + string source_title = mainWindow.drp_dvdtitle.Text; + string[] titlesplit = source_title.Split(' '); + source_title = titlesplit[0]; + if (mainWindow.Check_ChapterMarkers.Checked) { - Boolean saveCSV = chapterCSVSave(mainWindow); - if (saveCSV == false) + + if ((source_name.Trim().Replace("-i ", "") != "Click 'Browse' to continue") && (source_name.Trim().Replace("-i ", "") != "")) { - MessageBox.Show("Unable to save Chapter Makrers file! \n Chapter marker names will NOT be saved in your encode \n\n", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - ChapterMarkers = " -m "; + if (source_title != "Automatic") + { + string filename = source_name + "-" + source_title + "-chapters.csv"; + string path = Path.Combine(Path.GetTempPath(), filename); + + Boolean saveCSV = chapterCSVSave(mainWindow, path); + if (saveCSV == false) + ChapterMarkers = " -m "; + else + { + ChapterMarkers = " --markers=" + "\"" + path + "\""; + } + } + else + { + string filename = source_name + "-chapters.csv"; + string path = Path.Combine(Path.GetTempPath(), filename); + + Boolean saveCSV = chapterCSVSave(mainWindow, path); + if (saveCSV == false) + ChapterMarkers = " -m "; + else + { + ChapterMarkers = " --markers=" + "\"" + path + "\""; + } + } } else { - string path = Application.StartupPath.ToString(); - path = "\"" + path + "\\chapters.csv\" "; - - ChapterMarkers = " --markers=" + path; + string path = Path.Combine(Path.GetTempPath(), "chapters.csv"); + ChapterMarkers = " --markers=" + "\"" + path + "\""; } } @@ -701,7 +926,7 @@ namespace Handbrake.Functions // H264 Tab #region H264 Tab - string h264Advanced = mainWindow.rtf_h264advanced.Text; + string h264Advanced = mainWindow.rtf_x264Query.Text; if ((h264Advanced == "")) h264Advanced = ""; @@ -726,9 +951,7 @@ namespace Handbrake.Functions string queryAdvancedSettings = processors; - string verbose = ""; - if (Properties.Settings.Default.verbose == "Checked") - verbose = " -v "; + string verbose = " -v "; #endregion return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + ChapterMarkers + queryAdvancedSettings + verbose; @@ -774,15 +997,10 @@ namespace Handbrake.Functions * This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv in this applications * running directory. */ - private Boolean chapterCSVSave(frmMain mainWindow) + private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name) { try { - string appPath = Application.StartupPath.ToString(); - appPath = appPath + "\\"; - - string path = appPath + "chapters.csv"; - StringBuilder csv = new StringBuilder(); foreach (DataGridViewRow row in mainWindow.data_chpt.Rows) @@ -792,7 +1010,7 @@ namespace Handbrake.Functions csv.Append(row.Cells[1].Value.ToString()); csv.Append(Environment.NewLine); } - StreamWriter file = new StreamWriter(path); + StreamWriter file = new StreamWriter(file_path_name); file.Write(csv.ToString()); file.Close(); file.Dispose(); @@ -801,7 +1019,7 @@ namespace Handbrake.Functions } catch (Exception exc) { - MessageBox.Show(exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + MessageBox.Show("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } }