OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 27 Feb 2010 18:19:28 +0000 (18:19 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 27 Feb 2010 18:19:28 +0000 (18:19 +0000)
- Moved the Activity Log Code out of the Activity window into the Encode and Scan services. They now provide the log data. (Some duplicate code here will need to be refactored into a base class later)

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

win/C#/Controls/x264Panel.cs
win/C#/HandBrakeCS.5.0.ReSharper
win/C#/HandBrakeCS.csproj
win/C#/frmActivityWindow.cs
win/C#/frmMain.Designer.cs
win/C#/frmMain.cs

index 2780941..a338796 100644 (file)
@@ -142,8 +142,8 @@ namespace Handbrake.Controls
         /// Input: String. - Single X264 Option. Name only\r
         /// Output: String - Single X264 Option. Name only. Changed to standard format\r
         /// </summary>\r
-        /// <param name="cleanOptNameString"></param>\r
-        /// <returns></returns>\r
+        /// <param name="cleanOptNameString">a string of x264 options to clean</param>\r
+        /// <returns>A string containing standardized x264 option names</returns>\r
         private static string X264_StandardizeOptNames(string cleanOptNameString)\r
         {\r
             string input = cleanOptNameString;\r
index ede9d3f..a3d96d8 100644 (file)
@@ -88,7 +88,9 @@
       <EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>\r
       <EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>\r
       <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />\r
-      <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" />\r
+      <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces">\r
+        <ExtraRule Prefix="frm" Suffix="" Style="AaBb" />\r
+      </PredefinedRule>\r
       <PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" />\r
       <PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />\r
       <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />\r
index f4902e3..701316b 100644 (file)
     <Compile Include="Controls\x264Panel.Designer.cs">\r
       <DependentUpon>x264Panel.cs</DependentUpon>\r
     </Compile>\r
+    <Compile Include="Model\ActivityLogMode.cs" />\r
     <Compile Include="Services\Encode.cs" />\r
     <Compile Include="frmPreview.cs">\r
       <SubType>Form</SubType>\r
index 70f62d5..e346892 100644 (file)
@@ -13,6 +13,8 @@ namespace Handbrake
     using System.Threading;\r
     using System.Windows.Forms;\r
     using Functions;\r
+    using Model;\r
+    using Services;\r
     using Timer = System.Threading.Timer;\r
 \r
     /// <summary>\r
@@ -26,19 +28,24 @@ namespace Handbrake
         private int position;\r
 \r
         /// <summary>\r
-        /// The previous mode\r
+        /// A Timer for this window\r
         /// </summary>\r
-        private string lastMode;\r
+        private Timer windowTimer;\r
 \r
         /// <summary>\r
-        /// The current mode\r
+        /// The Encode Object\r
         /// </summary>\r
-        private string currentMode;\r
+        private Encode encode;\r
 \r
         /// <summary>\r
-        /// A Timer for this window\r
+        /// The Scan Object\r
         /// </summary>\r
-        private Timer windowTimer;\r
+        private Scan scan;\r
+\r
+        /// <summary>\r
+        /// The Type of log that the window is currently dealing with\r
+        /// </summary>\r
+        private ActivityLogMode mode;\r
 \r
         /// <summary>\r
         /// Initializes a new instance of the <see cref="frmActivityWindow"/> class.\r
@@ -46,15 +53,20 @@ namespace Handbrake
         /// <param name="mode">\r
         /// The mode.\r
         /// </param>\r
-        public frmActivityWindow(string mode)\r
+        /// <param name="encode">\r
+        /// The encode.\r
+        /// </param>\r
+        /// <param name="scan">\r
+        /// The scan.\r
+        /// </param>\r
+        public frmActivityWindow(ActivityLogMode mode, Encode encode, Scan scan)\r
         {\r
             InitializeComponent();\r
 \r
-            position = 0;\r
-            if (mode == "scan")\r
-                SetScanMode();\r
-            else\r
-                SetEncodeMode();\r
+            this.encode = encode;\r
+            this.scan = scan;\r
+            this.mode = mode;\r
+            this.position = 0;\r
         }\r
 \r
         /// <summary>\r
@@ -73,32 +85,16 @@ namespace Handbrake
         // Public\r
 \r
         /// <summary>\r
-        /// Gets or sets SetLogFile.\r
-        /// </summary>\r
-        public string SetLogFile\r
-        {\r
-            get { return string.IsNullOrEmpty(currentMode) ? string.Empty : currentMode; }\r
-            set { currentMode = value; }\r
-        }\r
-\r
-        /// <summary>\r
         /// Set the window to scan mode\r
         /// </summary>\r
-        public void SetScanMode()\r
-        {\r
-            Reset();\r
-            SetLogFile = "last_scan_log.txt";\r
-            this.Text = "Activity Window (Scan Log)";\r
-        }\r
-\r
-        /// <summary>\r
-        /// Set the window to encode mode\r
-        /// </summary>\r
-        public void SetEncodeMode()\r
+        /// <param name="setMode">\r
+        /// The set Mode.\r
+        /// </param>\r
+        public void SetMode(ActivityLogMode setMode)\r
         {\r
             Reset();\r
-            SetLogFile = "last_encode_log.txt";\r
-            this.Text = "Activity Window (Enocde Log)";\r
+            this.mode = setMode;\r
+            this.Text = mode == ActivityLogMode.Scan ? "Activity Window (Scan Log)" : "Activity Window (Enocde Log)";\r
         }\r
 \r
         // Logging\r
@@ -125,116 +121,79 @@ namespace Handbrake
         /// </param>\r
         private void LogMonitor(object n)\r
         {\r
-            if (SetLogFile != lastMode) Reset();\r
-\r
-            // Perform the window update\r
-            switch (SetLogFile)\r
-            {\r
-                case "last_scan_log.txt":\r
-                    AppendWindowText(ReadFile("last_scan_log.txt"));\r
-                    lastMode = "last_scan_log.txt";\r
-                    break;\r
-                case "last_encode_log.txt":\r
-                    AppendWindowText(ReadFile("last_encode_log.txt"));\r
-                    lastMode = "last_encode_log.txt";\r
-                    break;\r
-            }\r
+            AppendWindowText(GetLog());\r
         }\r
 \r
         /// <summary>\r
-        /// Read the log file\r
+        /// New Code for getting the Activity log from the Services rather than reading a file.\r
         /// </summary>\r
-        /// <param name="file">\r
-        /// The file.\r
-        /// </param>\r
         /// <returns>\r
-        /// A string builder containing the log data\r
+        /// The StringBuilder containing a log\r
         /// </returns>\r
-        private StringBuilder ReadFile(string file)\r
+        private StringBuilder GetLog()\r
         {\r
             StringBuilder appendText = new StringBuilder();\r
-            lock (this)\r
+            \r
+            if (this.mode == ActivityLogMode.Scan)\r
             {\r
-                // last_encode_log.txt is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it (Not even in read only mode),\r
-                // we'll need to make a copy of it.\r
-                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +\r
-                                "\\HandBrake\\logs";\r
-                string logFile = Path.Combine(logDir, file);\r
-                string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");\r
-\r
-                try\r
+                if (scan == null || scan.ActivityLog == string.Empty)\r
                 {\r
-                    // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.\r
-                    if (File.Exists(logFile2))\r
-                        File.Delete(logFile2);\r
-\r
-                    // Copy the log file.\r
-                    if (File.Exists(logFile))\r
-                        File.Copy(logFile, logFile2, true);\r
-                    else\r
-                    {\r
-                        appendText.AppendFormat("Waiting for the log file to be generated ...\n");\r
-                        position = 0;\r
-                        ClearWindowText();\r
-                        PrintLogHeader();\r
-                        return appendText;\r
-                    }\r
-\r
+                    appendText.AppendFormat("Waiting for the log to be generated ...\n");\r
+                    position = 0;\r
+                    ClearWindowText();\r
+                    PrintLogHeader();\r
+                    return appendText;\r
+                }\r
 \r
-                    // TODO This is just Experimental Code. Just ignore it.\r
-                    ////if (encode.ActivityLog == null)\r
-                    ////{\r
-                    ////    appendText.AppendFormat("Waiting for the log file to be generated ...\n");\r
-                    ////    position = 0;\r
-                    ////    ClearWindowText();\r
-                    ////    PrintLogHeader();\r
-                    ////    return appendText;\r
-                    ////}\r
-\r
-                    ////using (StringReader reader = new StringReader(encode.ActivityLog))\r
-                    ////{\r
-                    ////    string line;\r
-                    ////    int i = 1;\r
-                    ////    while ((line = reader.ReadLine()) != null)\r
-                    ////    {\r
-                    ////        if (i > position)\r
-                    ////        {\r
-                    ////            appendText.AppendLine(line);\r
-                    ////            position++;\r
-                    ////        }\r
-                    ////        i++;\r
-                    ////    }\r
-\r
-                    ////}\r
-\r
-                    // Start the Reader\r
-                    // Only use text which continues on from the last read line\r
-                    StreamReader sr = new StreamReader(logFile2);\r
-                    string line;\r
-                    int i = 1;\r
-                    while ((line = sr.ReadLine()) != null)\r
-                    {\r
-                        if (i > position)\r
-                        {\r
-                            appendText.AppendLine(line);\r
-                            position++;\r
-                        }\r
-                        i++;\r
-                    }\r
-                    sr.Close();\r
-                    sr.Dispose();\r
+                using (StringReader reader = new StringReader(scan.ActivityLog))\r
+                {\r
+                    LogReader(reader, appendText);\r
                 }\r
-                catch (Exception)\r
+            }\r
+            else\r
+            {\r
+                if (encode == null || encode.ActivityLog == string.Empty)\r
                 {\r
-                    Reset();\r
-                    appendText = new StringBuilder();\r
-                    appendText.AppendLine("\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");\r
+                    appendText.AppendFormat("Waiting for the log to be generated ...\n");\r
+                    position = 0;\r
+                    ClearWindowText();\r
+                    PrintLogHeader();\r
+                    return appendText;\r
+                }\r
+\r
+                using (StringReader reader = new StringReader(encode.ActivityLog))\r
+                {\r
+                    LogReader(reader, appendText);\r
                 }\r
             }\r
             return appendText;\r
         }\r
 \r
         /// <summary>\r
+        /// Reads the log data from a Scan or Encode object\r
+        /// </summary>\r
+        /// <param name="reader">\r
+        /// The reader.\r
+        /// </param>\r
+        /// <param name="appendText">\r
+        /// The append text.\r
+        /// </param>\r
+        private void LogReader(StringReader reader, StringBuilder appendText)\r
+        {\r
+            string line;\r
+            int i = 1;\r
+            while ((line = reader.ReadLine()) != null)\r
+            {\r
+                if (i > position)\r
+                {\r
+                    appendText.AppendLine(line);\r
+                    position++;\r
+                }\r
+                i++;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
         /// Append text to the RTF box\r
         /// </summary>\r
         /// <param name="text">\r
@@ -308,15 +267,15 @@ namespace Handbrake
                             // Print the log header. This function will be re-implimented later. Do not delete.\r
                             StringBuilder header = new StringBuilder();\r
 \r
-                            header.AppendLine(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));\r
-                            header.AppendLine(String.Format("### Running: {0} \n###\n", Environment.OSVersion));\r
-                            header.AppendLine(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));\r
-                            header.AppendLine(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));\r
-                            header.AppendLine(String.Format("### Screen: {0}x{1} \n", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));\r
-                            header.AppendLine(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));\r
-                            header.AppendLine(String.Format("### Install Dir: {0} \n", Application.StartupPath));\r
-                            header.AppendLine(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));\r
-                            header.AppendLine("#########################################\n\n");\r
+                            header.Append(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));\r
+                            header.Append(String.Format("### Running: {0} \n###\n", Environment.OSVersion));\r
+                            header.Append(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));\r
+                            header.Append(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));\r
+                            header.Append(String.Format("### Screen: {0}x{1} \n", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));\r
+                            header.Append(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));\r
+                            header.Append(String.Format("### Install Dir: {0} \n", Application.StartupPath));\r
+                            header.Append(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));\r
+                            header.Append("#########################################\n\n");\r
 \r
                             rtf_actLog.AppendText(header.ToString());\r
                         }\r
@@ -407,7 +366,7 @@ namespace Handbrake
         /// </param>\r
         private void BtnScanLogClick(object sender, EventArgs e)\r
         {\r
-            SetScanMode();\r
+            SetMode(ActivityLogMode.Scan);\r
         }\r
 \r
         /// <summary>\r
@@ -421,7 +380,7 @@ namespace Handbrake
         /// </param>\r
         private void BtnEncodeLogClick(object sender, EventArgs e)\r
         {\r
-            SetEncodeMode();\r
+            SetMode(ActivityLogMode.Encode);\r
         }\r
 \r
         // Overrides\r
index 6189025..dad2201 100644 (file)
@@ -1077,6 +1077,7 @@ namespace Handbrake
             this.x264Panel.Name = "x264Panel";\r
             this.x264Panel.Size = new System.Drawing.Size(720, 306);\r
             this.x264Panel.TabIndex = 0;\r
+            this.x264Panel.X264Query = " -x ";\r
             // \r
             // tab_query\r
             // \r
index 5ec9259..e4f6c05 100644 (file)
@@ -34,12 +34,13 @@ namespace Handbrake
         private frmActivityWindow ActivityWindow;\r
         private Form splash;\r
         public string sourcePath;\r
-        private string lastAction;\r
+        private ActivityLogMode lastAction;\r
         private SourceType selectedSourceType;\r
         private string dvdDrivePath;\r
         private string dvdDriveLabel;\r
         private Preset CurrentlySelectedPreset;\r
         private DVD currentSource;\r
+        private Scan SourceScan = new Scan();\r
 \r
         // Delegates **********************************************************\r
         private delegate void UpdateWindowHandler();\r
@@ -337,7 +338,7 @@ namespace Handbrake
 \r
         private void encodeStarted(object sender, EventArgs e)\r
         {\r
-            lastAction = "encode";\r
+            lastAction = ActivityLogMode.Encode;\r
             SetEncodeStarted();\r
 \r
             // Experimental HBProc Process Monitoring.\r
@@ -385,7 +386,7 @@ namespace Handbrake
 \r
         private void mnu_encodeLog_Click(object sender, EventArgs e)\r
         {\r
-            frmActivityWindow dvdInfoWindow = new frmActivityWindow(lastAction);\r
+            frmActivityWindow dvdInfoWindow = new frmActivityWindow(lastAction, encodeQueue, SourceScan);\r
             dvdInfoWindow.Show();\r
         }\r
 \r
@@ -850,10 +851,10 @@ namespace Handbrake
 \r
                         SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
                         encodeQueue.Start(); // Start The Queue Encoding Process\r
-                        lastAction = "encode"; // Set the last action to encode - Used for activity window.\r
+                        lastAction = ActivityLogMode.Encode; // Set the last action to encode - Used for activity window.\r
                     }\r
                     if (ActivityWindow != null)\r
-                        ActivityWindow.SetEncodeMode();\r
+                        ActivityWindow.SetMode(ActivityLogMode.Encode);\r
 \r
                     this.Focus();\r
                 }\r
@@ -924,18 +925,18 @@ namespace Handbrake
         private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
         {\r
             if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)\r
-                ActivityWindow = new frmActivityWindow(lastAction);\r
+                ActivityWindow = new frmActivityWindow(lastAction, encodeQueue, SourceScan);\r
             else\r
                 switch (lastAction)\r
                 {\r
-                    case "scan":\r
-                        ActivityWindow.SetScanMode();\r
+                    case ActivityLogMode.Scan:\r
+                        ActivityWindow.SetMode(ActivityLogMode.Scan);\r
                         break;\r
-                    case "encode":\r
-                        ActivityWindow.SetEncodeMode();\r
+                    case ActivityLogMode.Encode:\r
+                        ActivityWindow.SetMode(ActivityLogMode.Encode);\r
                         break;\r
                     default:\r
-                        ActivityWindow.SetEncodeMode();\r
+                        ActivityWindow.SetMode(ActivityLogMode.Encode);\r
                         break;\r
                 }\r
 \r
@@ -1011,7 +1012,7 @@ namespace Handbrake
         private void SelectSource(string file)\r
         {\r
             Check_ChapterMarkers.Enabled = true;\r
-            lastAction = "scan";\r
+            lastAction = ActivityLogMode.Scan;\r
             sourcePath = string.Empty;\r
 \r
             if (file == string.Empty) // Must have a file or path\r
@@ -1630,7 +1631,6 @@ namespace Handbrake
         #region Source Scan\r
 \r
         public bool isScanning { get; set; }\r
-        private Scan SourceScan;\r
 \r
         private void StartScan(string filename, int title)\r
         {\r
@@ -1650,7 +1650,7 @@ namespace Handbrake
             mnu_killCLI.Visible = true;\r
 \r
             if (ActivityWindow != null)\r
-                ActivityWindow.SetScanMode();\r
+                ActivityWindow.SetMode(ActivityLogMode.Scan);\r
 \r
             // Start the Scan\r
             try\r