From 16222f64e3f0f6dc7c256111bc191d3ff69419f6 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 8 Jul 2007 23:56:26 +0000 Subject: [PATCH] WinGui: - C# Handbrake CLI output parsing code converted from vb.net project. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@660 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/HandBrakeCS.csproj | 1 + win/C#/HandBrakeCS.suo | Bin 32256 -> 32256 bytes win/C#/frmAbout.Designer.cs | 15 +-- win/C#/frmReadDVD.Designer.cs | 41 ++------ win/C#/frmReadDVD.cs | 177 +++++++++++++++++++++++++++++++--- 5 files changed, 178 insertions(+), 56 deletions(-) diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index 30c0c8f79..aed93e217 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -61,6 +61,7 @@ frmOptions.cs + diff --git a/win/C#/HandBrakeCS.suo b/win/C#/HandBrakeCS.suo index 7c13520b02a9ea68d3db2110c35b8948ed95363e..7833f2b678669531e1bb5154f243fec562a20d2d 100644 GIT binary patch delta 2016 zcmbuAYitx%6vywK&MrG`X}8^FS?FsKQ?^jbZg;CZwCuJ8wo5}P?Lui6=(Yvh2&E~j zyd(|@5yu7SW% zr4znnRctYsxv85XKN4b}(W@BjPPwRH12exxzf~&zJ>0O~sZ(ou9z(i5Iw6 z#>8M!UxLPmX{5&Uiow)t+q(TiPX*IbFty zbooXi?x&Y)Jc<1AgnUiIRC4xUt0jojsvCnAi(=*IpICvAwPoA}7GbTd4d<=(#f(|l zJ%eEkWtlAS*vS5;lq;~qmi+Q)+Oe$W?`ds(JM*(bHpj?JOs+YFsy;#F5|<8n(|;Md zJ1mLs2d#jyNsnCP+(PAX=jcshCtmxwmc@kF5)2NG0Q{N=@<|7rr9fx-g| z6{RVPz8X6Y)>zONNXCp+6L2J?p}#5zhqOGL2$bP)z)bV;FlQ8FuOktiWp=KP>}LOb zD{7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#ws0{gFXiMUNo|N4p{S$G zt0@z?#Tz+!D<`!APZK&jteBFl$KyxwOOG9s#wro&R5|>zjI|LDd{L9s)Hk;ADleK( zHMFT}CuKTCigr*M4em?BzsUwu)Q9Dp9-uqgheunCSg(}fhb;!)g-WNBj$sK_^&H_t zuv9-U#y5|1^hRt@6h}7kYOD;$HWiL`tEi0Blgohd?hy8rRUo$YG{$>E=!@4Q7+a6k zbp{-E=`lHQe_k)^XGs=jU2HRMKiils>5F>s*|rcu#QyCr43-+DKoB)Hn_VHe|8aLq zae9|q*UDO17>5>muxin2E0vA0ovfFoSc3JjJ*4%E*SE_2ss3k0C{DwgP&}x3**4Y} z<_goENDXoJLZ^3(U`fi3^+~(MMox`142e8op(d_zxt3g7yhy)to#Rn_C8}z@qp@=M zcboBeMOMA(H0#zhuWO?{2C7Hf?YNXIMOn~?`!(*_P$SBH^a=x6v&>VT4PTKBr&5!R zW|(Uo{JFg2p2Ldw+e_z0o$NGYilV&vsFR)6xe+Os8DG~mXIrKW_%z_aw9lOfG+wjh z-`teTDjw|aG2p9%cHPfoCw?uYpKPg6573tB(d9-obW8itkUlgb4K(1gu>o%mAI9Bb bg1b|1TFnO8YjhSV*1+a711e?LnPL7920`o= diff --git a/win/C#/frmAbout.Designer.cs b/win/C#/frmAbout.Designer.cs index 5a8da77b6..f4e65592b 100644 --- a/win/C#/frmAbout.Designer.cs +++ b/win/C#/frmAbout.Designer.cs @@ -55,7 +55,7 @@ namespace Handbrake this.btn_close.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btn_close.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_close.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); - this.btn_close.Location = new System.Drawing.Point(410, 208); + this.btn_close.Location = new System.Drawing.Point(415, 229); this.btn_close.Name = "btn_close"; this.btn_close.Size = new System.Drawing.Size(99, 22); this.btn_close.TabIndex = 27; @@ -109,16 +109,17 @@ namespace Handbrake this.Label1.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label1.Location = new System.Drawing.Point(144, 161); this.Label1.Name = "Label1"; - this.Label1.Size = new System.Drawing.Size(296, 39); + this.Label1.Size = new System.Drawing.Size(305, 52); this.Label1.TabIndex = 22; - this.Label1.Text = "\"Titer\" - The original developer of handbrake.\r\nEveryone on the current developme" + - "nt team listed:\r\nhttp://handbrake.m0k.org/?page_id=9"; + this.Label1.Text = "- \"Titer\" - The original developer of handbrake.\r\n- Everyone on the current devel" + + "opment team listed:\r\n http://handbrake.m0k.org/?page_id=9\r\n- Ported to C#.net w" + + "ith help from \"brianmario\""; // - // About + // frmAbout // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(526, 239); + this.ClientSize = new System.Drawing.Size(526, 259); this.Controls.Add(this.Label4); this.Controls.Add(this.btn_close); this.Controls.Add(this.Version); @@ -127,7 +128,7 @@ namespace Handbrake this.Controls.Add(this.PictureBox1); this.Controls.Add(this.Label1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Name = "About"; + this.Name = "frmAbout"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "About Handbrake"; this.Load += new System.EventHandler(this.About_Load); diff --git a/win/C#/frmReadDVD.Designer.cs b/win/C#/frmReadDVD.Designer.cs index 6e853ab44..5cf290e1f 100644 --- a/win/C#/frmReadDVD.Designer.cs +++ b/win/C#/frmReadDVD.Designer.cs @@ -33,19 +33,17 @@ namespace Handbrake this.btn_ok = new System.Windows.Forms.Button(); this.Label3 = new System.Windows.Forms.Label(); this.Label2 = new System.Windows.Forms.Label(); - this.Label1 = new System.Windows.Forms.Label(); - this.rtf_dvdInfo = new System.Windows.Forms.RichTextBox(); this.SuspendLayout(); // // Label4 // this.Label4.AutoSize = true; this.Label4.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Label4.Location = new System.Drawing.Point(66, 31); + this.Label4.Location = new System.Drawing.Point(66, 51); this.Label4.Name = "Label4"; - this.Label4.Size = new System.Drawing.Size(130, 13); + this.Label4.Size = new System.Drawing.Size(178, 13); this.Label4.TabIndex = 29; - this.Label4.Text = "Press OK to continue."; + this.Label4.Text = "Press OK to start the process."; // // btn_ok // @@ -54,7 +52,7 @@ namespace Handbrake this.btn_ok.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btn_ok.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_ok.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); - this.btn_ok.Location = new System.Drawing.Point(405, 9); + this.btn_ok.Location = new System.Drawing.Point(405, 51); this.btn_ok.Name = "btn_ok"; this.btn_ok.Size = new System.Drawing.Size(56, 22); this.btn_ok.TabIndex = 28; @@ -69,9 +67,9 @@ namespace Handbrake this.Label3.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label3.Location = new System.Drawing.Point(66, 9); this.Label3.Name = "Label3"; - this.Label3.Size = new System.Drawing.Size(231, 13); + this.Label3.Size = new System.Drawing.Size(222, 26); this.Label3.TabIndex = 27; - this.Label3.Text = "The CLI is currently reading the DVD..."; + this.Label3.Text = "The CLI is about to read the DVD...\r\nThis process can take up to 1 minute."; // // Label2 // @@ -83,42 +81,19 @@ namespace Handbrake this.Label2.TabIndex = 26; this.Label2.Text = "Status:"; // - // Label1 - // - this.Label1.AutoSize = true; - this.Label1.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Label1.Location = new System.Drawing.Point(67, 49); - this.Label1.Name = "Label1"; - this.Label1.Size = new System.Drawing.Size(269, 24); - this.Label1.TabIndex = 25; - this.Label1.Text = "Note: After pressing OK the window will remain open \r\nuntil the CLI has completed" + - " the scan."; - // - // rtf_dvdInfo - // - this.rtf_dvdInfo.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.rtf_dvdInfo.Location = new System.Drawing.Point(11, 86); - this.rtf_dvdInfo.Name = "rtf_dvdInfo"; - this.rtf_dvdInfo.Size = new System.Drawing.Size(450, 70); - this.rtf_dvdInfo.TabIndex = 30; - this.rtf_dvdInfo.Text = ""; - // // frmReadDVD // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(473, 168); - this.Controls.Add(this.rtf_dvdInfo); + this.ClientSize = new System.Drawing.Size(473, 86); this.Controls.Add(this.Label4); this.Controls.Add(this.btn_ok); this.Controls.Add(this.Label3); this.Controls.Add(this.Label2); - this.Controls.Add(this.Label1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "frmReadDVD"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Reading DVD..."; - this.Load += new System.EventHandler(this.frmReadDVD_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -130,7 +105,5 @@ namespace Handbrake internal System.Windows.Forms.Button btn_ok; internal System.Windows.Forms.Label Label3; internal System.Windows.Forms.Label Label2; - internal System.Windows.Forms.Label Label1; - internal System.Windows.Forms.RichTextBox rtf_dvdInfo; } } \ No newline at end of file diff --git a/win/C#/frmReadDVD.cs b/win/C#/frmReadDVD.cs index ca70a6ba1..2ecff6fd5 100644 --- a/win/C#/frmReadDVD.cs +++ b/win/C#/frmReadDVD.cs @@ -19,34 +19,181 @@ namespace Handbrake this.inputFile = inputFile; } - private void frmReadDVD_Load(object sender, EventArgs e) + public void scan(string filename) { - //start(inputFile); - } - - public void start(string filename) - { - MessageBox.Show(filename); string query = "-i " + '"' + filename + '"' + " -t0"; System.Diagnostics.Process hbProc = new System.Diagnostics.Process(); hbProc.StartInfo.FileName = "hbcli.exe"; hbProc.StartInfo.RedirectStandardOutput = true; hbProc.StartInfo.RedirectStandardError = true; - //hbProc.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; - //hbProc.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; hbProc.StartInfo.Arguments = query; hbProc.StartInfo.UseShellExecute = false; hbProc.Start(); + System.IO.StreamReader errorReader = new System.IO.StreamReader(new System.IO.BufferedStream(hbProc.StandardError.BaseStream)); + //rtf_dvdInfo.AppendText(errorReader.ReadToEnd()); + hbProc.WaitForExit(); + hbProc.Close(); + + String DvdData = errorReader.ReadToEnd(); + DvdData = DvdData + "-- end --"; + + String[] DvdDataArr = DvdData.Split('\n'); + int DvdDataSize = DvdDataArr.Length -1; + String line = ""; + int counter = 0; + + // + // 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) + { + line = DvdDataArr[counter]; + 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); + 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); + 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 titleData) + { + string[] titleInfo = new string[10]; + string[] str = new string[1]; + + string title; + string t =""; + string d =""; - rtf_dvdInfo.Text = "-- Start --"; - while (hbProc.StandardOutput.BaseStream.CanRead && !hbProc.HasExited) + titleInfo = titleData.Split('~'); + try { - rtf_dvdInfo.Text = rtf_dvdInfo.Text + "\n" + hbProc.StandardOutput.ReadLine(); - rtf_dvdInfo.Text = rtf_dvdInfo.Text + "\n" + hbProc.StandardError.ReadLine(); - MessageBox.Show("Test"); + t = titleInfo[0].Trim().Substring(8).Replace(":", ""); // Title + d = titleInfo[1].Trim().Substring(12); //Duration + } catch(Exception){ + MessageBox.Show("Incomplete DVD data found. Please copy the data on the View DVD Information tab and report this error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } - rtf_dvdInfo.Text = rtf_dvdInfo.Text + "\n" + "-- End --"; + //Now lets add the info to the main form dropdowns + frmMain form = (frmMain)frmMain.ActiveForm; + title = t + " " + " " + d + " "; + form.drp_dvdtitle.Items.Add(title); } private void btn_ok_Click(object sender, EventArgs e) -- 2.40.0