diff options
author | sr55 <[email protected]> | 2007-07-25 21:58:43 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2007-07-25 21:58:43 +0000 |
commit | 293f0c3d36474e6114948e8c186a3bcc44bf4ad3 (patch) | |
tree | 8398293d22f48aed9f79136e2e7d65b2dd23cba1 /win/C# | |
parent | bc4964e49d17d09be0bf2d866579becb746fb176 (diff) |
WinGui:
- Added Cancel button to frmMain. Allows one to cancel the encode on the fly.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@736 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#')
-rw-r--r-- | win/C#/Functions/CLI.cs | 67 | ||||
-rw-r--r-- | win/C#/frmMain.Designer.cs | 22 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 69 |
3 files changed, 111 insertions, 47 deletions
diff --git a/win/C#/Functions/CLI.cs b/win/C#/Functions/CLI.cs index f6c774d68..85d1c5569 100644 --- a/win/C#/Functions/CLI.cs +++ b/win/C#/Functions/CLI.cs @@ -13,35 +13,43 @@ namespace Handbrake.Functions public Process runCli(object s, string query, bool stderr, bool stdout, bool useShellExec, bool noWindow)
{
- hbProc.StartInfo.FileName = "hbcli.exe";
- hbProc.StartInfo.Arguments = query;
- hbProc.StartInfo.RedirectStandardOutput = stdout;
- hbProc.StartInfo.RedirectStandardError = stderr;
- hbProc.StartInfo.UseShellExecute = useShellExec;
- hbProc.StartInfo.CreateNoWindow = noWindow;
- hbProc.Start();
+ try
+ {
+ hbProc = new Process();
+ hbProc.StartInfo.FileName = "hbcli.exe";
+ hbProc.StartInfo.Arguments = query;
+ hbProc.StartInfo.RedirectStandardOutput = stdout;
+ hbProc.StartInfo.RedirectStandardError = stderr;
+ hbProc.StartInfo.UseShellExecute = useShellExec;
+ hbProc.StartInfo.CreateNoWindow = noWindow;
+ hbProc.Start();
- // Set the process Priority
- switch (Properties.Settings.Default.processPriority)
+ // Set the process Priority
+ switch (Properties.Settings.Default.processPriority)
+ {
+ case "Realtime":
+ hbProc.PriorityClass = ProcessPriorityClass.RealTime;
+ break;
+ case "High":
+ hbProc.PriorityClass = ProcessPriorityClass.High;
+ break;
+ case "Above Normal":
+ hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;
+ break;
+ case "Normal":
+ hbProc.PriorityClass = ProcessPriorityClass.Normal;
+ break;
+ case "Low":
+ hbProc.PriorityClass = ProcessPriorityClass.Idle;
+ break;
+ default:
+ hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;
+ break;
+ }
+ }
+ catch
{
- case "Realtime":
- hbProc.PriorityClass = ProcessPriorityClass.RealTime;
- break;
- case "High":
- hbProc.PriorityClass = ProcessPriorityClass.High;
- break;
- case "Above Normal":
- hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;
- break;
- case "Normal":
- hbProc.PriorityClass = ProcessPriorityClass.Normal;
- break;
- case "Low":
- hbProc.PriorityClass = ProcessPriorityClass.Idle;
- break;
- default:
- hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;
- break;
+ MessageBox.Show("Internal Software Error. Please Restart the Program");
}
return hbProc;
}
@@ -63,5 +71,10 @@ namespace Handbrake.Functions hbProc.Close();
hbProc.Dispose();
}
+
+ public void setNull()
+ {
+ hbProc = new Process();
+ }
}
}
diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index 418b47910..30b8af7a0 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -167,6 +167,7 @@ namespace Handbrake this.btn_encode = new System.Windows.Forms.Button();
this.Version = new System.Windows.Forms.Label();
this.lbl_encode = new System.Windows.Forms.Label();
+ this.btn_eCancel = new System.Windows.Forms.Button();
Label38 = new System.Windows.Forms.Label();
this.frmMainMenu.SuspendLayout();
this.GroupBox1.SuspendLayout();
@@ -1637,7 +1638,7 @@ namespace Handbrake this.btn_queue.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_queue.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_queue.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
- this.btn_queue.Location = new System.Drawing.Point(406, 589);
+ this.btn_queue.Location = new System.Drawing.Point(335, 589);
this.btn_queue.Name = "btn_queue";
this.btn_queue.Size = new System.Drawing.Size(124, 22);
this.btn_queue.TabIndex = 416;
@@ -1683,11 +1684,29 @@ namespace Handbrake this.lbl_encode.Text = "Encoding started...";
this.lbl_encode.Visible = false;
//
+ // btn_eCancel
+ //
+ this.btn_eCancel.BackColor = System.Drawing.SystemColors.Control;
+ this.btn_eCancel.Enabled = false;
+ this.btn_eCancel.FlatAppearance.BorderColor = System.Drawing.Color.Black;
+ this.btn_eCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+ this.btn_eCancel.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.btn_eCancel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
+ this.btn_eCancel.Location = new System.Drawing.Point(465, 589);
+ this.btn_eCancel.Name = "btn_eCancel";
+ this.btn_eCancel.Size = new System.Drawing.Size(65, 22);
+ this.btn_eCancel.TabIndex = 419;
+ this.btn_eCancel.TabStop = false;
+ this.btn_eCancel.Text = "Cancel";
+ this.btn_eCancel.UseVisualStyleBackColor = false;
+ this.btn_eCancel.Click += new System.EventHandler(this.btn_eCancel_Click);
+ //
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(675, 621);
+ this.Controls.Add(this.btn_eCancel);
this.Controls.Add(this.lbl_encode);
this.Controls.Add(this.lbl_update);
this.Controls.Add(this.btn_queue);
@@ -1863,6 +1882,7 @@ namespace Handbrake private System.Windows.Forms.Label lbl_chptWarn;
internal System.Windows.Forms.SaveFileDialog DVD_Save;
private System.Windows.Forms.Label lbl_encode;
+ internal System.Windows.Forms.Button btn_eCancel;
}
}
\ No newline at end of file diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index e70994e7f..c66cee0b6 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -638,8 +638,19 @@ namespace Handbrake queueWindow.Show();
}
+
+
+
+
+ //---------------------------------------------------
+ // Encode / Cancel Buttons
+ // Encode Progress Text Handler
+ //---------------------------------------------------
+ Functions.CLI process = new Functions.CLI();
+
private void btn_encode_Click(object sender, EventArgs e)
{
+ btn_eCancel.Enabled = true;
String query = "";
lbl_encode.Visible = true;
@@ -655,39 +666,57 @@ namespace Handbrake ThreadPool.QueueUserWorkItem(procMonitor, query);
}
- private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)
+ private void btn_eCancel_Click(object sender, EventArgs e)
{
- if (this.InvokeRequired)
- {
- this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),
- new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });
- return;
- }
- lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);
+ process.killCLI();
+ process.setNull();
+ lbl_encode.Text = "Encoding Canceled";
}
-
+
private void procMonitor(object state)
{
- Functions.CLI process = new Functions.CLI();
+
hbProc = process.runCli(this, (string)state, true, true, false, true);
MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);
- //TODO: prevent this event from being subscribed more than once
- encode.OnEncodeProgress += encode_OnEncodeProgress;
- while (!encode.EndOfStream)
+ try
{
- encode.ReadLine();
+ Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);
+ encode.OnEncodeProgress += encode_OnEncodeProgress;
+ while (!encode.EndOfStream)
+ {
+ encode.ReadLine();
+ }
+
+ hbProc.WaitForExit();
+ process.closeCLI();
+ hbProc = null;
+ }
+ catch (Exception)
+ {
+ // Do Nothing
}
+ //TODO: prevent this event from being subscribed more than once
+
- hbProc.WaitForExit();
- hbProc.Close();
- hbProc.Dispose();
- hbProc = null;
MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
+
+
+
+
+ private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)
+ {
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),
+ new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });
+ return;
+ }
+ lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);
+ }
//---------------------------------------------------
// Items that require actions on frmMain
@@ -1394,6 +1423,8 @@ namespace Handbrake return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;
}
+
+
// This is the END of the road ------------------------------------------------------------------------------
}
}
\ No newline at end of file |