diff options
Diffstat (limited to 'win/C#/frmReadDVD.cs')
-rw-r--r-- | win/C#/frmReadDVD.cs | 187 |
1 files changed, 23 insertions, 164 deletions
diff --git a/win/C#/frmReadDVD.cs b/win/C#/frmReadDVD.cs index 2c95731df..0d8e109e9 100644 --- a/win/C#/frmReadDVD.cs +++ b/win/C#/frmReadDVD.cs @@ -5,6 +5,8 @@ using System.Data; using System.Drawing;
using System.Text;
using System.Windows.Forms;
+using System.IO;
+
namespace Handbrake
{
@@ -12,197 +14,54 @@ namespace Handbrake {
string inputFile;
+ frmMain mainWindow;
- public frmReadDVD(string inputFile)
+ public frmReadDVD(string inputFile, frmMain window)
{
InitializeComponent();
this.inputFile = inputFile;
+ this.mainWindow = window;
}
- public void scan(string filename)
+ private void btn_ok_Click(object sender, EventArgs e)
{
- string query = "-i " + '"' + filename + '"' + " -t0";
+
+ string query = "-i " + '"' + inputFile + '"' + " -t0";
System.Diagnostics.Process hbProc = new System.Diagnostics.Process();
hbProc.StartInfo.FileName = "hbcli.exe";
hbProc.StartInfo.RedirectStandardOutput = true;
hbProc.StartInfo.RedirectStandardError = true;
hbProc.StartInfo.Arguments = query;
hbProc.StartInfo.UseShellExecute = false;
+ hbProc.StartInfo.CreateNoWindow = true;
+
+
hbProc.Start();
- System.IO.StreamReader errorReader = new System.IO.StreamReader(new System.IO.BufferedStream(hbProc.StandardError.BaseStream));
+ StreamReader readData = new StreamReader(new BufferedStream(hbProc.StandardError.BaseStream));
hbProc.WaitForExit();
hbProc.Close();
- //Parsing.DVD thisDvd = Parsing.DVD.Parse(errorReader);
+ // Setup the parser
+ Parsing.DVD thisDvd = Parsing.DVD.Parse(readData);
- String DvdData = errorReader.ReadToEnd();
- DvdData = DvdData + "-- end --";
+ // Now pass this streamreader to frmMain so that it can be used there.
+ mainWindow.setStreamReader(thisDvd);
- String[] DvdDataArr = DvdData.Split('\n');
- int DvdDataSize = DvdDataArr.Length -1;
- String line = "";
+ // Setup frmMain drp_dvdTitle with the title information in the form: 1 (02:34:11)
+ int count = thisDvd.Titles.Count -1;
int counter = 0;
+ string title;
- //
- // Some varbiles used for parseing HandBrakes output
- //
-
- // DVD info stroage varibles
- string titleData = "";
- string duationData = "";
- string sizeData = "";
- string cropdata = "";
- string chatperData = "";
- string audioData = "";
- string subtitleData = "";
-
- string fullTitleData = "";
-
- // Position Pointers
- bool chapterPointer = false;
- bool audioPointer = false;
- bool subtitlePointer = false;
-
- // Error handling varibles
- bool titleError = false;
- bool readError = false;
-
- while (counter <= DvdDataSize)
+ while (count >= counter)
{
- line = DvdDataArr[counter];
+ title = thisDvd.Titles[counter].TitleNumber.ToString() + " (" + thisDvd.Titles[counter].Duration.ToString() + ")";
+ mainWindow.drp_dvdtitle.Items.Add(title);
counter++;
-
- // Get all the 1 liner data and set chaper potiner to true when done
- if (line.Contains("exited.")){
- subtitlePointer = false;
- fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
- add(fullTitleData, titleData, duationData);
- counter++;
- }else if (line.Contains("+ title")){
- if (titleData != "") {
- subtitlePointer = true;
- fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
- add(fullTitleData, titleData, duationData);
- counter = counter + 1;
- }
- titleData = line;
- }else if (line.Contains("+ duration")) {
- duationData = line;
- }else if (line.Contains("+ size")) {
- sizeData = line;
- }else if (line.Contains("+ autocrop")) {
- cropdata = line;
- }else if (line.Contains("+ chapters")) {
- chatperData = line;
- chapterPointer = true;
- }
-
- // Get all the chapter information in 1 varible
- if (chapterPointer == true)
- {
- if (!line.Contains("+ audio"))
- {
- chapterPointer = false;
- audioPointer = true;
- audioData = line;
- }
- else
- {
- if (!chatperData.Equals(line))
- {
- chatperData = chatperData + " & " + line.Trim();
- }
- }
- }
-
- // Get all the audio channel information in 1 varible
- if (audioPointer == true)
- {
- if (line.Contains("+ subtitle"))
- {
- audioPointer = false;
- subtitlePointer = true;
- subtitleData = line;
- }
- else
- {
- if (!audioData.Equals(line))
- {
- audioData = audioData + " & " + line.Trim();
- }
- }
- }
-
- //Get all the subtitle data into 1 varible
- if (subtitlePointer == true)
- {
- if (line.Contains("+ subtitle"))
- {
- subtitleData = line;
- } else
- {
- if (!subtitleData.Equals(line))
- {
- subtitleData = subtitleData + " & " + line.Trim();
- }
- }
- }
-
- // Handle some of Handbrakes Error outputs if they occur.
- if (line.Contains("No title"))
- {
- titleError = true;
- }
-
- if (line.Contains("***"))
- {
- readError = true;
- }
-
- // Display error messages for errors detected above.
- if (readError == true)
- {
- MessageBox.Show("Some DVD Title information may be missing however you may still be able to select your required title for encoding!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
-
- if (titleError == true)
- {
- MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- }
-
- }
- }
-
- public void add(string fullTitleData, string titleData, string durationData)
- {
-
- try
- {
- string t = titleData.Trim().Substring(8).Replace(":", "");
- string d = durationData.Trim().Substring(12);
-
- // Lets store the captured full title data as a string in the programs settings file.
- // This can then be used by the DVD title dropdown menu to populate other fields.
-
- Properties.Settings.Default.FullDVDInfo = Properties.Settings.Default.FullDVDInfo + " \n " + fullTitleData;
-
- //Now lets add the info to the main form dropdowns
- frmMain form = (frmMain)frmMain.ActiveForm;
- string title = t + " " + " " + d + " ";
- form.drp_dvdtitle.Items.Add(title);
- }
- catch (Exception)
- {
- // Don't really need to do anything about it.
}
+ this.Close();
}
- private void btn_ok_Click(object sender, EventArgs e)
- {
- scan(inputFile);
- }
-
}
}
\ No newline at end of file |