{\r
class Common\r
{\r
- /// <summary>\r
- /// Checks for updates and returns true if an update is available.\r
- /// </summary>\r
- /// <param name="debug">Turns on debug mode. Don't use on program startup</param>\r
- /// <returns>Boolean True = Update available</returns>\r
- public Boolean updateCheck(Boolean debug)\r
- {\r
- try\r
- {\r
- Functions.AppcastReader rssRead = new Functions.AppcastReader();\r
- string build = rssRead.build();\r
-\r
- int latest = int.Parse(build);\r
- int current = Properties.Settings.Default.hb_build;\r
- int skip = Properties.Settings.Default.skipversion;\r
-\r
- if (latest == skip)\r
- return false;\r
- else\r
- {\r
- Boolean update = (latest > current);\r
- return update;\r
- }\r
- }\r
- catch (Exception exc)\r
- {\r
- if (debug == true)\r
- MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- return false;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Get's HandBrakes version data from the CLI.\r
- /// </summary>\r
- /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
- public ArrayList getCliVersionData()\r
- {\r
- ArrayList cliVersionData = new ArrayList();\r
- // 0 = SVN Build / Version\r
- // 1 = Build Date\r
-\r
- Process cliProcess = new Process();\r
- ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");\r
- handBrakeCLI.UseShellExecute = false;\r
- handBrakeCLI.RedirectStandardError = true;\r
- handBrakeCLI.RedirectStandardOutput = true;\r
- handBrakeCLI.CreateNoWindow = true;\r
- cliProcess.StartInfo = handBrakeCLI;\r
- cliProcess.Start();\r
-\r
- // Retrieve standard output and report back to parent thread until the process is complete\r
- String line;\r
- TextReader stdOutput = cliProcess.StandardError;\r
-\r
- while (!cliProcess.HasExited)\r
- {\r
- line = stdOutput.ReadLine();\r
- Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");\r
- if (m.Success != false)\r
- {\r
- string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
- string[] arr = data.Split(' ');\r
- cliVersionData.Add(arr[0]);\r
- cliVersionData.Add(arr[1]);\r
- return cliVersionData;\r
- }\r
- }\r
- return null;\r
- }\r
+ #region Presets\r
\r
/// <summary>\r
/// Update the presets.dat file with the latest version of HandBrak's presets from the CLI\r
hbproc.Dispose();\r
hbproc.Close();\r
}\r
-\r
- /// <summary>\r
- /// Function which generates the filename and path automatically based on \r
- /// the Source Name, DVD title and DVD Chapters\r
- /// </summary>\r
- /// <param name="mainWindow"></param>\r
- public void autoName(frmMain mainWindow)\r
- {\r
- if (Properties.Settings.Default.autoNaming == "Checked")\r
- {\r
- if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
- {\r
- string source = mainWindow.text_source.Text;\r
- string[] sourceName = source.Split('\\');\r
- source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
-\r
- string title = mainWindow.drp_dvdtitle.Text;\r
- string[] titlesplit = title.Split(' ');\r
- title = titlesplit[0];\r
-\r
- string cs = mainWindow.drop_chapterStart.Text;\r
- string cf = mainWindow.drop_chapterFinish.Text;\r
-\r
- if (title == "Automatic")\r
- title = "";\r
- if (cs == "Auto")\r
- cs = "";\r
- if (cf == "Auto")\r
- cf = "";\r
-\r
- string dash = "";\r
- if (cf != "Auto")\r
- dash = "-";\r
-\r
- if (!mainWindow.text_destination.Text.Contains("\\"))\r
- {\r
- string filePath = "";\r
- if (Properties.Settings.Default.autoNamePath.Trim() != "")\r
- {\r
- if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")\r
- filePath = Properties.Settings.Default.autoNamePath + "\\";\r
- }\r
- mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";\r
- }\r
- else\r
- {\r
- string dest = mainWindow.text_destination.Text;\r
-\r
- string[] destName = dest.Split('\\');\r
-\r
-\r
- string[] extension = dest.Split('.');\r
- string ext = extension[extension.Length - 1];\r
-\r
- destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;\r
-\r
- string fullDest = "";\r
- foreach (string part in destName)\r
- {\r
- if (fullDest != "")\r
- fullDest = fullDest + "\\" + part;\r
- else\r
- fullDest = fullDest + part;\r
- }\r
-\r
- mainWindow.text_destination.Text = fullDest;\r
- }\r
- }\r
- }\r
- }\r
-\r
/// <summary>\r
/// This function takes in a Query which has been parsed by QueryParser and\r
/// set's all the GUI widgets correctly.\r
#endregion\r
}\r
\r
+ #endregion\r
+\r
+ #region Query Generator & Chapter CSV Creation\r
+\r
/// <summary>\r
/// Generates a CLI query based on the GUI widgets.\r
/// </summary>\r
query += generateTabbedComponentsQuery(mainWindow, mainWindow.text_source.Text);\r
return query;\r
}\r
-\r
/// <summary>\r
/// Generates a CLI query for the preview function.\r
/// This basically forces a shortened version of the encdode.\r
return query;\r
}\r
\r
- /// <summary>\r
- /// Set's up the DataGridView on the Chapters tab (frmMain)\r
- /// </summary>\r
- /// <param name="mainWindow"></param>\r
- public void chapterNaming(frmMain mainWindow)\r
- {\r
- try\r
- {\r
- mainWindow.data_chpt.Rows.Clear();\r
- int i = 0;\r
- int rowCount = 0;\r
- int start = 0;\r
- int finish = 0;\r
- if (mainWindow.drop_chapterFinish.Text != "Auto")\r
- finish = int.Parse(mainWindow.drop_chapterFinish.Text);\r
-\r
- if (mainWindow.drop_chapterStart.Text != "Auto")\r
- start = int.Parse(mainWindow.drop_chapterStart.Text);\r
-\r
- rowCount = finish - (start - 1);\r
-\r
- while (i < rowCount)\r
- {\r
- DataGridViewRow row = new DataGridViewRow();\r
-\r
- mainWindow.data_chpt.Rows.Insert(i, row);\r
- mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);\r
- mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);\r
- i++;\r
- }\r
- }\r
- catch (Exception exc)\r
- {\r
- MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Select the longest title in the DVD title dropdown menu on frmMain\r
- /// </summary>\r
- public void selectLongestTitle(frmMain mainWindow)\r
- {\r
- int current_largest = 0;\r
- Handbrake.Parsing.Title title2Select;\r
-\r
- // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"\r
- if (mainWindow.drp_dvdtitle.Items[0].ToString() != "Automatic")\r
- title2Select = (Handbrake.Parsing.Title)mainWindow.drp_dvdtitle.Items[0];\r
- else\r
- title2Select = null;\r
-\r
- // So, If there are titles in the DVD Title dropdown menu, lets select the longest.\r
- if (title2Select != null)\r
- {\r
- foreach (Handbrake.Parsing.Title x in mainWindow.drp_dvdtitle.Items)\r
- {\r
- string title = x.ToString();\r
- if (title != "Automatic")\r
- {\r
- string[] y = title.Split(' ');\r
- string time = y[1].Replace("(", "").Replace(")", "");\r
- string[] z = time.Split(':');\r
-\r
- int hours = int.Parse(z[0]) * 60 * 60;\r
- int minutes = int.Parse(z[1]) * 60;\r
- int seconds = int.Parse(z[2]);\r
- int total_sec = hours + minutes + seconds;\r
-\r
- if (current_largest == 0)\r
- {\r
- current_largest = hours + minutes + seconds;\r
- title2Select = x;\r
- }\r
- else\r
- {\r
- if (total_sec > current_largest)\r
- {\r
- current_largest = total_sec;\r
- title2Select = x;\r
- }\r
- }\r
- }\r
- }\r
-\r
- // Now set the longest title in the gui.\r
- mainWindow.drp_dvdtitle.SelectedItem = title2Select;\r
- }\r
- }\r
-\r
// Generates part of the CLI query, for the tabbed components only.\r
private string generateTabbedComponentsQuery(frmMain mainWindow, string source)\r
{\r
query += " --crop 0:0:0:0 ";\r
else if (mainWindow.drp_crop.Text == "Custom")\r
{\r
- if (mainWindow.text_top.Text == "")\r
- cropTop = "0";\r
- if (mainWindow.text_bottom.Text == "")\r
- cropBottom = "0";\r
- if (mainWindow.text_left.Text == "")\r
- cropLeft = "0";\r
- if (mainWindow.text_right.Text == "")\r
- cropRight = "0";\r
-\r
- query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
+ if (mainWindow.text_top.Text == "")\r
+ cropTop = "0";\r
+ if (mainWindow.text_bottom.Text == "")\r
+ cropBottom = "0";\r
+ if (mainWindow.text_left.Text == "")\r
+ cropLeft = "0";\r
+ if (mainWindow.text_right.Text == "")\r
+ cropRight = "0";\r
+\r
+ query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
}\r
\r
switch (mainWindow.drp_deInterlace_option.Text)\r
query += " -6 dpl2";\r
\r
if (Mixdown2 != "" && track2 != "None")\r
- query += "," + getMixDown(Mixdown2);\r
+ query += "," + getMixDown(Mixdown2);\r
\r
if (Mixdown3 != "" && track3 != "None" && track2 != "None")\r
- query += "," + getMixDown(Mixdown3);\r
+ query += "," + getMixDown(Mixdown3);\r
\r
if (Mixdown4 != "" && track4 != "None" && track3 != "None")\r
- query += "," + getMixDown(Mixdown4);\r
+ query += "," + getMixDown(Mixdown4);\r
\r
\r
//\r
\r
return query;\r
}\r
-\r
- // This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv\r
- // in a directory specified by file_path_name\r
- private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name)\r
+ // Get the CLI equive of the audio mixdown from the widget name.\r
+ private string getMixDown(string selectedAudio)\r
{\r
- try\r
- {\r
- StringBuilder csv = new StringBuilder();\r
-\r
- foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)\r
- {\r
- csv.Append(row.Cells[0].Value.ToString());\r
- csv.Append(",");\r
- csv.Append(row.Cells[1].Value.ToString());\r
- csv.Append(Environment.NewLine);\r
- }\r
- StreamWriter file = new StreamWriter(file_path_name);\r
- file.Write(csv.ToString());\r
- file.Close();\r
- file.Dispose();\r
- return true;\r
-\r
- }\r
- catch (Exception exc)\r
- {\r
- 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);\r
- return false;\r
- }\r
- }\r
-\r
- // Get the CLI equive of the audio mixdown from the widget name.\r
- private string getMixDown(string selectedAudio)\r
- {\r
- switch (selectedAudio)\r
+ switch (selectedAudio)\r
{\r
case "Automatic":\r
return "dpl2";\r
return "dpl2";\r
}\r
}\r
-\r
// Get the CLI equiv of the audio encoder from the widget name.\r
private string getAudioEncoder(string selectedEncoder)\r
{\r
return "";\r
}\r
}\r
+ // This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv\r
+ // in a directory specified by file_path_name\r
+ private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name)\r
+ {\r
+ try\r
+ {\r
+ StringBuilder csv = new StringBuilder();\r
+\r
+ foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)\r
+ {\r
+ csv.Append(row.Cells[0].Value.ToString());\r
+ csv.Append(",");\r
+ csv.Append(row.Cells[1].Value.ToString());\r
+ csv.Append(Environment.NewLine);\r
+ }\r
+ StreamWriter file = new StreamWriter(file_path_name);\r
+ file.Write(csv.ToString());\r
+ file.Close();\r
+ file.Dispose();\r
+ return true;\r
+\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ 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);\r
+ return false;\r
+ }\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region frmMain Actions\r
+\r
+ /// <summary>\r
+ /// Select the longest title in the DVD title dropdown menu on frmMain\r
+ /// </summary>\r
+ public void selectLongestTitle(frmMain mainWindow)\r
+ {\r
+ int current_largest = 0;\r
+ Handbrake.Parsing.Title title2Select;\r
+\r
+ // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"\r
+ if (mainWindow.drp_dvdtitle.Items[0].ToString() != "Automatic")\r
+ title2Select = (Handbrake.Parsing.Title)mainWindow.drp_dvdtitle.Items[0];\r
+ else\r
+ title2Select = null;\r
+\r
+ // So, If there are titles in the DVD Title dropdown menu, lets select the longest.\r
+ if (title2Select != null)\r
+ {\r
+ foreach (Handbrake.Parsing.Title x in mainWindow.drp_dvdtitle.Items)\r
+ {\r
+ string title = x.ToString();\r
+ if (title != "Automatic")\r
+ {\r
+ string[] y = title.Split(' ');\r
+ string time = y[1].Replace("(", "").Replace(")", "");\r
+ string[] z = time.Split(':');\r
+\r
+ int hours = int.Parse(z[0]) * 60 * 60;\r
+ int minutes = int.Parse(z[1]) * 60;\r
+ int seconds = int.Parse(z[2]);\r
+ int total_sec = hours + minutes + seconds;\r
+\r
+ if (current_largest == 0)\r
+ {\r
+ current_largest = hours + minutes + seconds;\r
+ title2Select = x;\r
+ }\r
+ else\r
+ {\r
+ if (total_sec > current_largest)\r
+ {\r
+ current_largest = total_sec;\r
+ title2Select = x;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ // Now set the longest title in the gui.\r
+ mainWindow.drp_dvdtitle.SelectedItem = title2Select;\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Set's up the DataGridView on the Chapters tab (frmMain)\r
+ /// </summary>\r
+ /// <param name="mainWindow"></param>\r
+ public void chapterNaming(frmMain mainWindow)\r
+ {\r
+ try\r
+ {\r
+ mainWindow.data_chpt.Rows.Clear();\r
+ int i = 0;\r
+ int rowCount = 0;\r
+ int start = 0;\r
+ int finish = 0;\r
+ if (mainWindow.drop_chapterFinish.Text != "Auto")\r
+ finish = int.Parse(mainWindow.drop_chapterFinish.Text);\r
+\r
+ if (mainWindow.drop_chapterStart.Text != "Auto")\r
+ start = int.Parse(mainWindow.drop_chapterStart.Text);\r
+\r
+ rowCount = finish - (start - 1);\r
+\r
+ while (i < rowCount)\r
+ {\r
+ DataGridViewRow row = new DataGridViewRow();\r
+\r
+ mainWindow.data_chpt.Rows.Insert(i, row);\r
+ mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);\r
+ mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);\r
+ i++;\r
+ }\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Function which generates the filename and path automatically based on \r
+ /// the Source Name, DVD title and DVD Chapters\r
+ /// </summary>\r
+ /// <param name="mainWindow"></param>\r
+ public void autoName(frmMain mainWindow)\r
+ {\r
+ if (Properties.Settings.Default.autoNaming == "Checked")\r
+ {\r
+ if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
+ {\r
+ string source = mainWindow.text_source.Text;\r
+ string[] sourceName = source.Split('\\');\r
+ source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");\r
+\r
+ string title = mainWindow.drp_dvdtitle.Text;\r
+ string[] titlesplit = title.Split(' ');\r
+ title = titlesplit[0];\r
+\r
+ string cs = mainWindow.drop_chapterStart.Text;\r
+ string cf = mainWindow.drop_chapterFinish.Text;\r
+\r
+ if (title == "Automatic")\r
+ title = "";\r
+ if (cs == "Auto")\r
+ cs = "";\r
+ if (cf == "Auto")\r
+ cf = "";\r
+\r
+ string dash = "";\r
+ if (cf != "Auto")\r
+ dash = "-";\r
+\r
+ if (!mainWindow.text_destination.Text.Contains("\\"))\r
+ {\r
+ string filePath = "";\r
+ if (Properties.Settings.Default.autoNamePath.Trim() != "")\r
+ {\r
+ if (Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")\r
+ filePath = Properties.Settings.Default.autoNamePath + "\\";\r
+ }\r
+ mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";\r
+ }\r
+ else\r
+ {\r
+ string dest = mainWindow.text_destination.Text;\r
+\r
+ string[] destName = dest.Split('\\');\r
+\r
+\r
+ string[] extension = dest.Split('.');\r
+ string ext = extension[extension.Length - 1];\r
+\r
+ destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;\r
+\r
+ string fullDest = "";\r
+ foreach (string part in destName)\r
+ {\r
+ if (fullDest != "")\r
+ fullDest = fullDest + "\\" + part;\r
+ else\r
+ fullDest = fullDest + part;\r
+ }\r
+\r
+ mainWindow.text_destination.Text = fullDest;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Version and Update Checking\r
+\r
+ /// <summary>\r
+ /// Checks for updates and returns true if an update is available.\r
+ /// </summary>\r
+ /// <param name="debug">Turns on debug mode. Don't use on program startup</param>\r
+ /// <returns>Boolean True = Update available</returns>\r
+ public Boolean updateCheck(Boolean debug)\r
+ {\r
+ try\r
+ {\r
+ Functions.AppcastReader rssRead = new Functions.AppcastReader();\r
+ string build = rssRead.build();\r
+\r
+ int latest = int.Parse(build);\r
+ int current = Properties.Settings.Default.hb_build;\r
+ int skip = Properties.Settings.Default.skipversion;\r
+\r
+ if (latest == skip)\r
+ return false;\r
+ else\r
+ {\r
+ Boolean update = (latest > current);\r
+ return update;\r
+ }\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ if (debug == true)\r
+ MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ return false;\r
+ }\r
+ }\r
+ /// <summary>\r
+ /// Get's HandBrakes version data from the CLI.\r
+ /// </summary>\r
+ /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
+ public ArrayList getCliVersionData()\r
+ {\r
+ ArrayList cliVersionData = new ArrayList();\r
+ // 0 = SVN Build / Version\r
+ // 1 = Build Date\r
+\r
+ Process cliProcess = new Process();\r
+ ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u");\r
+ handBrakeCLI.UseShellExecute = false;\r
+ handBrakeCLI.RedirectStandardError = true;\r
+ handBrakeCLI.RedirectStandardOutput = true;\r
+ handBrakeCLI.CreateNoWindow = true;\r
+ cliProcess.StartInfo = handBrakeCLI;\r
+ cliProcess.Start();\r
+\r
+ // Retrieve standard output and report back to parent thread until the process is complete\r
+ String line;\r
+ TextReader stdOutput = cliProcess.StandardError;\r
+\r
+ while (!cliProcess.HasExited)\r
+ {\r
+ line = stdOutput.ReadLine();\r
+ Match m = Regex.Match(line, @"HandBrake [0-9\.]*svn[0-9]*[M]* \([0-9]*\)");\r
+ if (m.Success != false)\r
+ {\r
+ string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
+ string[] arr = data.Split(' ');\r
+ cliVersionData.Add(arr[0]);\r
+ cliVersionData.Add(arr[1]);\r
+ return cliVersionData;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
\r
+ #endregion\r
}\r
}
\ No newline at end of file