OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 25 Jul 2007 21:58:43 +0000 (21:58 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 25 Jul 2007 21:58:43 +0000 (21:58 +0000)
- Added Cancel button to frmMain. Allows one to cancel the encode on the fly.

git-svn-id: svn://localhost/HandBrake/trunk@736 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/Functions/CLI.cs
win/C#/frmMain.Designer.cs
win/C#/frmMain.cs

index f6c774d..85d1c55 100644 (file)
@@ -13,35 +13,43 @@ namespace Handbrake.Functions
         \r
         public Process runCli(object s, string query, bool stderr, bool stdout, bool useShellExec, bool noWindow)\r
         {\r
-            hbProc.StartInfo.FileName = "hbcli.exe";\r
-            hbProc.StartInfo.Arguments = query;\r
-            hbProc.StartInfo.RedirectStandardOutput = stdout;\r
-            hbProc.StartInfo.RedirectStandardError = stderr;\r
-            hbProc.StartInfo.UseShellExecute = useShellExec;\r
-            hbProc.StartInfo.CreateNoWindow = noWindow;\r
-            hbProc.Start();     \r
+            try\r
+            {\r
+                hbProc = new Process();\r
+                hbProc.StartInfo.FileName = "hbcli.exe";\r
+                hbProc.StartInfo.Arguments = query;\r
+                hbProc.StartInfo.RedirectStandardOutput = stdout;\r
+                hbProc.StartInfo.RedirectStandardError = stderr;\r
+                hbProc.StartInfo.UseShellExecute = useShellExec;\r
+                hbProc.StartInfo.CreateNoWindow = noWindow;\r
+                hbProc.Start();\r
 \r
-            // Set the process Priority\r
-            switch (Properties.Settings.Default.processPriority)\r
+                // Set the process Priority\r
+                switch (Properties.Settings.Default.processPriority)\r
+                {\r
+                    case "Realtime":\r
+                        hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
+                        break;\r
+                    case "High":\r
+                        hbProc.PriorityClass = ProcessPriorityClass.High;\r
+                        break;\r
+                    case "Above Normal":\r
+                        hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
+                        break;\r
+                    case "Normal":\r
+                        hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
+                        break;\r
+                    case "Low":\r
+                        hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
+                        break;\r
+                    default:\r
+                        hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
+                        break;\r
+                }\r
+            }\r
+            catch\r
             {\r
-                case "Realtime":\r
-                    hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
-                    break;\r
-                case "High":\r
-                    hbProc.PriorityClass = ProcessPriorityClass.High;\r
-                    break;\r
-                case "Above Normal":\r
-                    hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
-                    break;\r
-                case "Normal":\r
-                    hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
-                    break;\r
-                case "Low":\r
-                    hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
-                    break;\r
-                default:\r
-                    hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
-                    break;\r
+                MessageBox.Show("Internal Software Error. Please Restart the Program");\r
             }\r
             return hbProc;\r
         }\r
@@ -63,5 +71,10 @@ namespace Handbrake.Functions
             hbProc.Close();\r
             hbProc.Dispose();\r
         }\r
+\r
+        public void setNull()\r
+        {\r
+            hbProc = new Process();\r
+        }   \r
     }\r
 }\r
index 418b479..30b8af7 100644 (file)
@@ -167,6 +167,7 @@ namespace Handbrake
             this.btn_encode = new System.Windows.Forms.Button();\r
             this.Version = new System.Windows.Forms.Label();\r
             this.lbl_encode = new System.Windows.Forms.Label();\r
+            this.btn_eCancel = new System.Windows.Forms.Button();\r
             Label38 = new System.Windows.Forms.Label();\r
             this.frmMainMenu.SuspendLayout();\r
             this.GroupBox1.SuspendLayout();\r
@@ -1637,7 +1638,7 @@ namespace Handbrake
             this.btn_queue.FlatStyle = System.Windows.Forms.FlatStyle.Flat;\r
             this.btn_queue.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\r
             this.btn_queue.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));\r
-            this.btn_queue.Location = new System.Drawing.Point(406, 589);\r
+            this.btn_queue.Location = new System.Drawing.Point(335, 589);\r
             this.btn_queue.Name = "btn_queue";\r
             this.btn_queue.Size = new System.Drawing.Size(124, 22);\r
             this.btn_queue.TabIndex = 416;\r
@@ -1683,11 +1684,29 @@ namespace Handbrake
             this.lbl_encode.Text = "Encoding started...";\r
             this.lbl_encode.Visible = false;\r
             // \r
+            // btn_eCancel\r
+            // \r
+            this.btn_eCancel.BackColor = System.Drawing.SystemColors.Control;\r
+            this.btn_eCancel.Enabled = false;\r
+            this.btn_eCancel.FlatAppearance.BorderColor = System.Drawing.Color.Black;\r
+            this.btn_eCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;\r
+            this.btn_eCancel.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\r
+            this.btn_eCancel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));\r
+            this.btn_eCancel.Location = new System.Drawing.Point(465, 589);\r
+            this.btn_eCancel.Name = "btn_eCancel";\r
+            this.btn_eCancel.Size = new System.Drawing.Size(65, 22);\r
+            this.btn_eCancel.TabIndex = 419;\r
+            this.btn_eCancel.TabStop = false;\r
+            this.btn_eCancel.Text = "Cancel";\r
+            this.btn_eCancel.UseVisualStyleBackColor = false;\r
+            this.btn_eCancel.Click += new System.EventHandler(this.btn_eCancel_Click);\r
+            // \r
             // frmMain\r
             // \r
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);\r
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\r
             this.ClientSize = new System.Drawing.Size(675, 621);\r
+            this.Controls.Add(this.btn_eCancel);\r
             this.Controls.Add(this.lbl_encode);\r
             this.Controls.Add(this.lbl_update);\r
             this.Controls.Add(this.btn_queue);\r
@@ -1863,6 +1882,7 @@ namespace Handbrake
         private System.Windows.Forms.Label lbl_chptWarn;\r
         internal System.Windows.Forms.SaveFileDialog DVD_Save;\r
         private System.Windows.Forms.Label lbl_encode;\r
+        internal System.Windows.Forms.Button btn_eCancel;\r
 \r
     }\r
 }
\ No newline at end of file
index e70994e..c66cee0 100644 (file)
@@ -638,8 +638,19 @@ namespace Handbrake
             queueWindow.Show();\r
         }\r
 \r
+\r
+\r
+\r
+\r
+        //---------------------------------------------------\r
+        // Encode / Cancel Buttons\r
+        // Encode Progress Text Handler\r
+        //---------------------------------------------------\r
+        Functions.CLI process = new Functions.CLI();\r
+\r
         private void btn_encode_Click(object sender, EventArgs e)\r
         {\r
+            btn_eCancel.Enabled = true;\r
             String query = "";\r
             lbl_encode.Visible = true;\r
  \r
@@ -655,39 +666,57 @@ namespace Handbrake
             ThreadPool.QueueUserWorkItem(procMonitor, query);\r
         }\r
 \r
-        private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
+        private void btn_eCancel_Click(object sender, EventArgs e)\r
         {\r
-            if (this.InvokeRequired)\r
-            {\r
-                this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
-                    new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
-                return;\r
-            }\r
-            lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
+            process.killCLI();\r
+            process.setNull();\r
+            lbl_encode.Text = "Encoding Canceled";\r
         }\r
-\r
+   \r
         private void procMonitor(object state)\r
         {\r
-            Functions.CLI process = new Functions.CLI();\r
+            \r
             hbProc = process.runCli(this, (string)state, true, true, false, true);\r
 \r
             MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
 \r
-            Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
-            //TODO: prevent this event from being subscribed more than once\r
-            encode.OnEncodeProgress += encode_OnEncodeProgress;\r
-            while (!encode.EndOfStream)\r
+            try\r
             {\r
-                encode.ReadLine();\r
+                Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
+                encode.OnEncodeProgress += encode_OnEncodeProgress;\r
+                while (!encode.EndOfStream)\r
+                {\r
+                    encode.ReadLine();\r
+                }\r
+\r
+                hbProc.WaitForExit();\r
+                process.closeCLI();\r
+                hbProc = null;\r
+            }\r
+            catch (Exception)\r
+            { \r
+                // Do Nothing\r
             }\r
 \r
+            //TODO: prevent this event from being subscribed more than once\r
+\r
             \r
-            hbProc.WaitForExit();\r
-            hbProc.Close();\r
-            hbProc.Dispose();\r
-            hbProc = null;\r
             MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
         }\r
+\r
+\r
+\r
+\r
+        private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
+        {\r
+            if (this.InvokeRequired)\r
+            {\r
+                this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
+                    new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
+                return;\r
+            }\r
+            lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
+        }\r
         \r
         //---------------------------------------------------\r
         //  Items that require actions on frmMain\r
@@ -1394,6 +1423,8 @@ namespace Handbrake
             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
         }\r
 \r
+        \r
+\r
         // This is the END of the road ------------------------------------------------------------------------------\r
     }\r
 }
\ No newline at end of file