using System;\r
using System.Collections.Generic;\r
using System.Diagnostics;\r
+ using System.Globalization;\r
using System.IO;\r
using System.Net;\r
+ using System.Text;\r
using System.Text.RegularExpressions;\r
using System.Threading;\r
using System.Windows.Forms;\r
using System.Xml.Serialization;\r
- using EncodeQueue;\r
using Model;\r
using Parsing;\r
\r
/// <summary>\r
/// The XML Serializer\r
/// </summary>\r
- private static readonly XmlSerializer Ser = new XmlSerializer(typeof (List<Job>));\r
+ private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Job>));\r
\r
/// <summary>\r
/// Calculate the duration of the selected title and chapters\r
}\r
\r
/// <summary>\r
- /// Select the longest title in the DVD title dropdown menu on frmMain\r
- /// </summary>\r
- /// <param name="source">\r
- /// The Source.\r
- /// </param>\r
- /// <returns>\r
- /// The longest title.\r
- /// </returns>\r
- public static Title SelectLongestTitle(DVD source)\r
- {\r
- TimeSpan longestDurationFound = TimeSpan.FromSeconds(0.0);\r
- Title returnTitle = null;\r
-\r
- foreach (Title item in source.Titles)\r
- {\r
- if (item.Duration > longestDurationFound)\r
- {\r
- returnTitle = item;\r
- longestDurationFound = item.Duration;\r
- }\r
- }\r
- return returnTitle;\r
- }\r
-\r
- /// <summary>\r
/// Set's up the DataGridView on the Chapters tab (frmMain)\r
/// </summary>\r
/// <param name="dataChpt">\r
int n = dataChpt.Rows.Add();\r
dataChpt.Rows[n].Cells[0].Value = i + 1;\r
dataChpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);\r
- dataChpt.Rows[n].Cells[0].ValueType = typeof (int);\r
- dataChpt.Rows[n].Cells[1].ValueType = typeof (string);\r
+ dataChpt.Rows[n].Cells[0].ValueType = typeof(int);\r
+ dataChpt.Rows[n].Cells[1].ValueType = typeof(string);\r
i++;\r
}\r
\r
foreach (DataGridViewRow item in dataChpt.Rows)\r
{\r
string name;\r
- chapterMap.TryGetValue((int) item.Cells[0].Value, out name);\r
+ chapterMap.TryGetValue((int)item.Cells[0].Value, out name);\r
item.Cells[1].Value = name ?? "Chapter " + item.Cells[0].Value;\r
}\r
\r
}\r
\r
/// <summary>\r
+ /// Create a CSV file with the data from the Main Window Chapters tab\r
+ /// </summary>\r
+ /// <param name="mainWindow">Main Window</param>\r
+ /// <param name="filePathName">Path to save the csv file</param>\r
+ /// <returns>True if successful </returns>\r
+ public static bool SaveChapterMarkersToCsv(frmMain mainWindow, string filePathName)\r
+ {\r
+ try\r
+ {\r
+ string csv = string.Empty;\r
+\r
+ foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)\r
+ {\r
+ csv += row.Cells[0].Value.ToString();\r
+ csv += ",";\r
+ csv += row.Cells[1].Value.ToString().Replace(",", "\\,");\r
+ csv += Environment.NewLine;\r
+ }\r
+ StreamWriter file = new StreamWriter(filePathName);\r
+ file.Write(csv);\r
+ file.Close();\r
+ file.Dispose();\r
+ return true;\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ frmExceptionWindow exceptionWindow = new frmExceptionWindow();\r
+ exceptionWindow.Setup("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode", exc.ToString());\r
+ exceptionWindow.ShowDialog();\r
+ return false;\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
// Get the Source Name \r
string sourceName = mainWindow.SourceName;\r
\r
+ // Remove any illeagal characters from the source name\r
+ foreach (char character in Path.GetInvalidFileNameChars())\r
+ {\r
+ if (autoNamePath != null)\r
+ {\r
+ sourceName = sourceName.Replace(character.ToString(), string.Empty);\r
+ }\r
+ }\r
+\r
+ if (Properties.Settings.Default.AutoNameRemoveUnderscore)\r
+ sourceName = sourceName.Replace("_", " ");\r
+\r
+ if (Properties.Settings.Default.AutoNameTitleCase)\r
+ sourceName = TitleCase(sourceName);\r
+\r
// Get the Selected Title Number\r
string[] titlesplit = mainWindow.drp_dvdtitle.Text.Split(' ');\r
string dvdTitle = titlesplit[0].Replace("Automatic", string.Empty);\r
else // Otherwise, use the path that is already there.\r
{\r
// Use the path and change the file extension to match the previous destination\r
- autoNamePath = Path.Combine(Path.GetDirectoryName(mainWindow.text_destination.Text), \r
+ autoNamePath = Path.Combine(Path.GetDirectoryName(mainWindow.text_destination.Text),\r
destinationFilename);\r
\r
if (Path.HasExtension(mainWindow.text_destination.Text))\r
- autoNamePath = Path.ChangeExtension(autoNamePath, \r
+ autoNamePath = Path.ChangeExtension(autoNamePath,\r
Path.GetExtension(mainWindow.text_destination.Text));\r
}\r
}\r
Process cliProcess = new Process();\r
ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0")\r
{\r
- UseShellExecute = false, \r
- RedirectStandardError = true, \r
- RedirectStandardOutput = true, \r
+ UseShellExecute = false,\r
+ RedirectStandardError = true,\r
+ RedirectStandardOutput = true,\r
CreateNoWindow = true\r
};\r
cliProcess.StartInfo = handBrakeCli;\r
\r
if (m.Success)\r
{\r
- string data = line.Replace("(", string.Empty).Replace(")", string.Empty).Replace("HandBrake ", \r
- string.Empty);\r
+ string data = line.Replace("(", string.Empty).Replace(")", string.Empty).Replace("HandBrake ", string.Empty);\r
string[] arr = data.Split(' ');\r
\r
Properties.Settings.Default.hb_build = int.Parse(arr[1]);\r
}\r
catch (Exception e)\r
{\r
- MessageBox.Show("Unable to retrieve version information from the CLI. \nError:\n" + e);\r
+ frmExceptionWindow exceptionWindow = new frmExceptionWindow();\r
+ exceptionWindow.Setup("Unable to retrieve version information from the CLI.", e.ToString());\r
+ exceptionWindow.ShowDialog();\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Check to make sure that the user has an up to date version of the CLI installed.\r
+ /// </summary>\r
+ public static void CheckForValidCliVersion()\r
+ {\r
+ // Make sure we have a recent version for svn builds\r
+ string version = Properties.Settings.Default.hb_version;\r
+ if (version.Contains("svn"))\r
+ {\r
+ version = version.Replace("svn", string.Empty).Trim();\r
+ int build;\r
+ int.TryParse(version, out build);\r
+ if (build < Properties.Settings.Default.hb_min_cli)\r
+ {\r
+ MessageBox.Show(\r
+ "It appears you are trying to use a CLI executable that is too old for this version of the HandBrake GUI.\n" +\r
+ "Please update the HandBrakeCLI.exe to a newer build.\n\n" +\r
+ "HandBrake build Detected: " + Properties.Settings.Default.hb_version,\r
+ "Error",\r
+ MessageBoxButtons.OK,\r
+ MessageBoxIcon.Error);\r
+ return;\r
+ }\r
}\r
}\r
\r
{\r
try\r
{\r
- string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), \r
- @"HandBrake\hb_queue_recovery.xml");\r
+ string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\hb_queue_recovery.xml");\r
if (File.Exists(tempPath))\r
{\r
using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))\r
UpdateCheckInformation info =\r
new UpdateCheckInformation\r
{\r
- NewVersionAvailable = false, \r
+ NewVersionAvailable = false,\r
BuildInformation = null\r
};\r
callback(new UpdateCheckResult(debug, info));\r
UpdateCheckInformation info2 =\r
new UpdateCheckInformation\r
{\r
- NewVersionAvailable = latest > current, \r
+ NewVersionAvailable = latest > current,\r
BuildInformation = reader\r
};\r
callback(new UpdateCheckResult(debug, info2));\r
}\r
catch (Exception exc)\r
{\r
- callback(new UpdateCheckResult(debug, \r
- new UpdateCheckInformation\r
- {\r
- Error = exc\r
- }));\r
+ callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));\r
}\r
}));\r
}\r
/// </returns>\r
public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)\r
{\r
- UpdateCheckResult checkResult = (UpdateCheckResult) result;\r
+ UpdateCheckResult checkResult = (UpdateCheckResult)result;\r
return checkResult.Result;\r
}\r
\r
{\r
List<DriveInformation> drives = new List<DriveInformation>();\r
DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
+ int id = 0;\r
foreach (DriveInfo curDrive in theCollectionOfDrives)\r
{\r
if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady &&\r
{\r
drives.Add(new DriveInformation\r
{\r
- VolumeLabel = curDrive.VolumeLabel, \r
+ Id = id,\r
+ VolumeLabel = curDrive.VolumeLabel,\r
RootDirectory = curDrive.RootDirectory + "VIDEO_TS"\r
});\r
+ id++;\r
}\r
}\r
return drives;\r
}\r
+\r
+ /// <summary>\r
+ /// Change a string to Title Case/\r
+ /// </summary>\r
+ /// <param name="input">\r
+ /// The input.\r
+ /// </param>\r
+ /// <returns>\r
+ /// A string in title case.\r
+ /// </returns>\r
+ public static string TitleCase(string input)\r
+ {\r
+ string[] tokens = input.Split(' ');\r
+ StringBuilder sb = new StringBuilder(input.Length);\r
+ foreach (string s in tokens)\r
+ {\r
+ sb.Append(s[0].ToString().ToUpper());\r
+ sb.Append(s.Substring(1).ToLower());\r
+ sb.Append(" ");\r
+ }\r
+\r
+ return sb.ToString().Trim();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Show the Exception Window\r
+ /// </summary>\r
+ /// <param name="shortError">\r
+ /// The short error.\r
+ /// </param>\r
+ /// <param name="longError">\r
+ /// The long error.\r
+ /// </param>\r
+ public static void ShowExceptiowWindow(string shortError, string longError)\r
+ {\r
+ frmExceptionWindow exceptionWindow = new frmExceptionWindow();\r
+ exceptionWindow.Setup(shortError, longError);\r
+ exceptionWindow.Show();\r
+ }\r
}\r
}
\ No newline at end of file