OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 23 Jan 2009 21:08:28 +0000 (21:08 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 23 Jan 2009 21:08:28 +0000 (21:08 +0000)
- Few more bits of code refactored.
- Added a 10 second limit for the CLI to respond at GUI startup. This will prevent the app from locking if the CLI stalls.

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

win/C#/Functions/Encode.cs
win/C#/Functions/Main.cs
win/C#/frmMain.cs
win/C#/frmMain/PresetLoader.cs
win/C#/frmMain/QueryGenerator.cs
win/C#/frmMain/x264Panel.cs

index b6a4a0a..3f126d7 100644 (file)
@@ -136,6 +136,7 @@ namespace Handbrake.Functions
         /// if this feature is enabled in options.\r
         /// </summary>\r
         /// <param name="query"></param>\r
+        /// <param name="destination"></param>\r
         public void copyLog(string query, string destination)\r
         {\r
             // The user may wish to do something with the log.\r
index 05bb00f..af0ce7f 100644 (file)
@@ -173,7 +173,7 @@ namespace Handbrake.Functions
                 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);\r
                 i++;\r
             }\r
-    \r
+\r
             return data_chpt;\r
         }\r
 \r
@@ -324,7 +324,7 @@ namespace Handbrake.Functions
                     if (line == null) line = "";\r
                     Match m = Regex.Match(line, @"HandBrake ([0-9\.]*)*(svn[0-9]*[M]*)* \([0-9]*\)");\r
 \r
-                    if (m.Success != false)\r
+                    if (m.Success)\r
                     {\r
                         string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
                         string[] arr = data.Split(' ');\r
@@ -332,6 +332,9 @@ namespace Handbrake.Functions
                         cliVersionData.Add(arr[1]);\r
                         return cliVersionData;\r
                     }\r
+                    if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.\r
+                        killCLI();\r
+\r
                 }\r
             }\r
             catch (Exception e)\r
@@ -343,6 +346,22 @@ namespace Handbrake.Functions
             cliVersionData.Add("0");\r
             return cliVersionData;\r
         }\r
+        private void killCLI()\r
+        {\r
+            string AppName = "HandBrakeCLI";\r
+            AppName = AppName.ToUpper();\r
+\r
+            System.Diagnostics.Process[] prs = Process.GetProcesses();\r
+            foreach (System.Diagnostics.Process proces in prs)\r
+            {\r
+                if (proces.ProcessName.ToUpper() == AppName)\r
+                {\r
+                    proces.Refresh();\r
+                    if (!proces.HasExited)\r
+                        proces.Kill();\r
+                }\r
+            }\r
+        }\r
 \r
         /// <summary>\r
         /// Check if the queue recovery file contains records.\r
index e353740..3c9754c 100644 (file)
@@ -35,7 +35,7 @@ namespace Handbrake
         private frmQueue queueWindow;\r
         private frmGenPreview vlcpreview;\r
         private frmPreview qtpreview;\r
-        private string lastAction = null;\r
+        private string lastAction;\r
         public int maxWidth = 0;\r
         public int maxHeight = 0;\r
 \r
@@ -1557,7 +1557,6 @@ namespace Handbrake
             tb_preview.Enabled = false;\r
             mnu_killCLI.Visible = true;\r
         }\r
-\r
         private void startScan(String filename)\r
         {\r
             try\r
index ab4561c..c486247 100644 (file)
@@ -13,6 +13,7 @@ namespace Handbrake
         /// <param name="mainWindow"></param>\r
         /// <param name="presetQuery">The Parsed CLI Query</param>\r
         /// <param name="name">Name of the preset</param>\r
+        /// <param name="pictureSettings">Save picture settings in the preset</param>\r
         public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name, Boolean pictureSettings)\r
         {\r
             // ---------------------------\r
@@ -56,16 +57,16 @@ namespace Handbrake
                 else if (presetQuery.Format == "ogm")\r
                     mainWindow.drop_format.SelectedIndex = 4;\r
 \r
-                if (presetQuery.ChapterMarkers == true && presetQuery.Format == "mp4")\r
+                if (presetQuery.ChapterMarkers && presetQuery.Format == "mp4")\r
                     mainWindow.drop_format.SelectedIndex = 1;\r
             }\r
 \r
-            if (presetQuery.IpodAtom == true)\r
+            if (presetQuery.IpodAtom)\r
                 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;\r
 \r
-            if (presetQuery.OptimizeMP4 == true)\r
+            if (presetQuery.OptimizeMP4)\r
                 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;\r
@@ -82,7 +83,7 @@ namespace Handbrake
             mainWindow.text_width.Text = "";\r
             mainWindow.text_height.Text = "";\r
 \r
-            if (pictureSettings == true)\r
+            if (pictureSettings)\r
             {\r
                 if (presetQuery.CropTop != null)\r
                 {\r
@@ -109,12 +110,12 @@ namespace Handbrake
             mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;\r
             mainWindow.drp_deNoise.Text = presetQuery.DeNoise;\r
 \r
-            if (presetQuery.Decomb == true)\r
+            if (presetQuery.Decomb)\r
                 mainWindow.check_decomb.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_decomb.CheckState = CheckState.Unchecked;\r
 \r
-            if (presetQuery.DeTelecine == true)\r
+            if (presetQuery.DeTelecine)\r
                 mainWindow.check_detelecine.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;\r
@@ -130,12 +131,12 @@ namespace Handbrake
                 mainWindow.lbl_deblockVal.Text = "Off";\r
             }\r
 \r
-            if (presetQuery.Anamorphic == true)\r
+            if (presetQuery.Anamorphic)\r
                 mainWindow.drp_anamorphic.SelectedIndex = 1;\r
             else\r
                 mainWindow.drp_anamorphic.SelectedIndex = 0;\r
 \r
-            if (presetQuery.LooseAnamorphic == true)\r
+            if (presetQuery.LooseAnamorphic)\r
                 mainWindow.drp_anamorphic.SelectedIndex = 2;\r
             else\r
             {\r
@@ -168,27 +169,27 @@ namespace Handbrake
             if (mainWindow.slider_videoQuality.Value != 0)\r
             {\r
                 int ql = presetQuery.VideoQuality;\r
-                mainWindow.SliderValue.Text = ql.ToString() + "%";\r
+                mainWindow.SliderValue.Text = ql + "%";\r
             }\r
 \r
-            if (presetQuery.TwoPass == true)\r
+            if (presetQuery.TwoPass)\r
                 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;\r
 \r
-            if (presetQuery.Grayscale == true)\r
+            if (presetQuery.Grayscale)\r
                 mainWindow.check_grayscale.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;\r
 \r
             mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
 \r
-            if (presetQuery.TurboFirstPass == true)\r
+            if (presetQuery.TurboFirstPass)\r
                 mainWindow.check_turbo.CheckState = CheckState.Checked;\r
             else\r
                 mainWindow.check_turbo.CheckState = CheckState.Unchecked;\r
 \r
-            if (presetQuery.LargeMP4 == true)\r
+            if (presetQuery.LargeMP4)\r
                 mainWindow.check_largeFile.CheckState = CheckState.Checked;\r
             else\r
             {\r
@@ -200,7 +201,7 @@ namespace Handbrake
             // Chapter Markers Tab\r
             #region Chapter Markers\r
 \r
-            if (presetQuery.ChapterMarkers == true)\r
+            if (presetQuery.ChapterMarkers)\r
             {\r
                 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;\r
                 mainWindow.Check_ChapterMarkers.Enabled = true;\r
@@ -264,7 +265,7 @@ namespace Handbrake
             // Subtitle Stuff\r
             mainWindow.drp_subtitle.Text = presetQuery.Subtitles;\r
 \r
-            if (presetQuery.ForcedSubtitles == true)\r
+            if (presetQuery.ForcedSubtitles)\r
             {\r
                 mainWindow.check_forced.CheckState = CheckState.Checked;\r
                 mainWindow.check_forced.Enabled = true;\r
index 346657c..8117836 100644 (file)
@@ -48,10 +48,12 @@ namespace Handbrake
         /// This basically forces a shortened version of the encdode.\r
         /// </summary>\r
         /// <param name="mainWindow"></param>\r
+        /// <param name="duration">Duration</param>\r
+        /// <param name="preview">Start at preview</param>\r
         /// <returns>Returns a CLI query String.</returns>\r
         public string GeneratePreviewQuery(frmMain mainWindow, string duration, string preview)\r
         {\r
-            int seconds = 0;\r
+            int seconds;\r
             int.TryParse(duration, out seconds);\r
 \r
             // Source tab\r
@@ -81,7 +83,6 @@ namespace Handbrake
         /// Generates part of the CLI query, for the tabbed components only.\r
         /// </summary>\r
         /// <param name="mainWindow"></param>\r
-        /// <param name="source"></param>\r
         /// <returns></returns>\r
         public string generateTabbedComponentsQuery(frmMain mainWindow)\r
         {\r
@@ -315,7 +316,7 @@ namespace Handbrake
 \r
             foreach (String item in tracks)\r
             {\r
-                if (firstLoop == true)\r
+                if (firstLoop)\r
                 {\r
                     audioItems = item; firstLoop = false;\r
                 }\r
@@ -329,7 +330,7 @@ namespace Handbrake
             // Audio Codec (-E)\r
             foreach (String item in codecs)\r
             {\r
-                if (firstLoop == true)\r
+                if (firstLoop)\r
                 {\r
                     audioItems = item; firstLoop = false;\r
                 }\r
@@ -342,7 +343,7 @@ namespace Handbrake
             // Audio Mixdown (-6)\r
             foreach (String item in mixdowns)\r
             {\r
-                if (firstLoop == true)\r
+                if (firstLoop)\r
                 {\r
                     audioItems = item; firstLoop = false;\r
                 }\r
@@ -355,7 +356,7 @@ namespace Handbrake
             // Sample Rate (-R)\r
             foreach (String item in samplerates)\r
             {\r
-                if (firstLoop == true)\r
+                if (firstLoop)\r
                 {\r
                     audioItems = item; firstLoop = false;\r
                 }\r
@@ -368,7 +369,7 @@ namespace Handbrake
             // Audio Bitrate (-B)\r
             foreach (String item in bitrates)\r
             {\r
-                if (firstLoop == true)\r
+                if (firstLoop)\r
                 {\r
                     audioItems = item; firstLoop = false;\r
                 }\r
@@ -381,7 +382,7 @@ namespace Handbrake
             // DRC (-D)\r
             foreach (String item in drcs)\r
             {\r
-                if (firstLoop == true)\r
+                if (firstLoop)\r
                 {\r
                     audioItems = item; firstLoop = false;\r
                 }\r
@@ -389,8 +390,6 @@ namespace Handbrake
                     audioItems += "," + item;\r
             }\r
             query += " -D " + audioItems;\r
-            firstLoop = true; audioItems = ""; // Reset for another pass.\r
-\r
 \r
             // Subtitles\r
             string subtitles = mainWindow.drp_subtitle.Text;\r
index e3a52fd..550c116 100644 (file)
@@ -1,6 +1,4 @@
 using System;\r
-using System.Collections.Generic;\r
-using System.Text;\r
 using System.Windows.Forms;\r
 \r
 namespace Handbrake\r
@@ -41,8 +39,8 @@ namespace Handbrake
         {\r
             /* Set widgets depending on the opt string in field */\r
             String thisOpt; // The separated option such as "bframes=3"\r
-            String optName = ""; // The option name such as "bframes"\r
-            String optValue = "";// The option value such as "3"\r
+            String optName; // The option name such as "bframes"\r
+            String optValue;// The option value such as "3"\r
             String[] currentOptsArray;\r
 \r
             //Set currentOptString to the contents of the text box.\r
@@ -146,12 +144,9 @@ namespace Handbrake
                         /*Deblocking NSPopUpButtons*/\r
                         else if (optName.Equals("deblock"))\r
                         {\r
-                            string alphaDeblock = "";\r
-                            string betaDeblock = "";\r
-\r
                             string[] splitDeblock = optValue.Split(',');\r
-                            alphaDeblock = splitDeblock[0];\r
-                            betaDeblock = splitDeblock[1];\r
+                            string alphaDeblock = splitDeblock[0];\r
+                            string betaDeblock = splitDeblock[1];\r
 \r
                             if (alphaDeblock.Equals("0") && betaDeblock.Replace("\n", "").Equals("0"))\r
                             {\r
@@ -201,8 +196,8 @@ namespace Handbrake
         {\r
             /* Set widgets depending on the opt string in field */\r
             String thisOpt; // The separated option such as "bframes=3"\r
-            String optName = ""; // The option name such as "bframes"\r
-            String optValue = "";// The option value such as "3"\r
+            String optName; // The option name such as "bframes"\r
+            String optValue;// The option value such as "3"\r
             String changedOptString = "";\r
             String[] currentOptsArray;\r
 \r
@@ -345,8 +340,7 @@ namespace Handbrake
         private void hasOptions(string currentOptString, string optNameToChange, frmMain mainWindow)\r
         {\r
             String thisOpt;             // The separated option such as "bframes=3"\r
-            String optName = "";        // The option name such as "bframes"\r
-            String optValue = "";       // The option value such as "3"\r
+            String optName;        // The option name such as "bframes"\r
             String[] currentOptsArray;\r
 \r
             /* Create new empty opt string*/\r
@@ -365,7 +359,6 @@ namespace Handbrake
                     string[] splitOptRange = thisOpt.Split('=');\r
 \r
                     optName = splitOptRange[0];     // e.g bframes\r
-                    optValue = splitOptRange[1];    // e.g 2\r
 \r
                     /* \r
                      * Run through the available widgets for x264 opts and set them, as you add widgets,\r
@@ -519,14 +512,14 @@ namespace Handbrake
                         else if (optNameToChange.Equals("merange"))\r
                         {\r
                             if (!mainWindow.drop_MotionEstimationRange.SelectedItem.ToString().Contains("Default"))\r
-                                thisOpt = "merange=" + mainWindow.drop_MotionEstimationRange.SelectedItem.ToString();\r
+                                thisOpt = "merange=" + mainWindow.drop_MotionEstimationRange.SelectedItem;\r
                             else\r
                                 thisOpt = "";\r
                         }\r
                         else if (optNameToChange.Equals("ref"))\r
                         {\r
                             if (!mainWindow.drop_refFrames.SelectedItem.ToString().Contains("Default"))\r
-                                thisOpt = "ref=" + mainWindow.drop_refFrames.SelectedItem.ToString();\r
+                                thisOpt = "ref=" + mainWindow.drop_refFrames.SelectedItem;\r
                             else\r
                                 thisOpt = "";\r
                         }\r
@@ -572,12 +565,11 @@ namespace Handbrake
         }\r
         private void hasNoOptions(string optNameToChange, frmMain mainWindow)\r
         {\r
-            string query = "";\r
             string colon = "";\r
             if (mainWindow.rtf_x264Query.Text != "")\r
                 colon = ":";\r
 \r
-            query = mainWindow.rtf_x264Query.Text;\r
+            string query = mainWindow.rtf_x264Query.Text;\r
             if (optNameToChange.Equals("me"))\r
             {\r
                 switch (mainWindow.drop_MotionEstimationMethod.SelectedIndex)\r
@@ -645,12 +637,12 @@ namespace Handbrake
             else if (optNameToChange.Equals("merange"))\r
             {\r
                 int value = mainWindow.drop_MotionEstimationRange.SelectedIndex + 3;\r
-                query = query + colon + "merange=" + value.ToString();\r
+                query = query + colon + "merange=" + value;\r
             }\r
             else if (optNameToChange.Equals("deblock"))\r
             {\r
                 String da = mainWindow.drop_deblockAlpha.SelectedItem.ToString();\r
-                String db = mainWindow.drop_deblockBeta.Text.ToString();\r
+                String db = mainWindow.drop_deblockBeta.Text;\r
 \r
                 if (((da.Contains("Default")) && (db.Contains("Default"))) || ((da.Contains("0")) && (db.Contains("0"))))\r
                 {\r
@@ -706,7 +698,7 @@ namespace Handbrake
             else if (optNameToChange.Equals("ref"))\r
             {\r
                 if (!mainWindow.drop_refFrames.SelectedItem.ToString().Contains("Default"))\r
-                    query = query + colon + "ref=" + mainWindow.drop_refFrames.SelectedItem.ToString();\r
+                    query = query + colon + "ref=" + mainWindow.drop_refFrames.SelectedItem;\r
             }\r
             else if (optNameToChange.Equals("bframes"))\r
             {\r
@@ -723,7 +715,7 @@ namespace Handbrake
             else if (optNameToChange.Equals("trellis"))\r
             {\r
                 if (!mainWindow.drop_trellis.SelectedItem.ToString().Contains("Default"))\r
-                    query = query + colon + "trellis=" + mainWindow.drop_trellis.SelectedItem.ToString();\r
+                    query = query + colon + "trellis=" + mainWindow.drop_trellis.SelectedItem;\r
             }\r
 \r
             mainWindow.rtf_x264Query.Text = query;\r