]> granicus.if.org Git - handbrake/commitdiff
WinGui: Fixes around libhb scanning. (Progress % was not shown and the scan logs...
authorsr55 <sr55.hb@outlook.com>
Sat, 24 Aug 2013 13:48:41 +0000 (13:48 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 24 Aug 2013 13:48:41 +0000 (13:48 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5744 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/Services/Interfaces/IScan.cs
win/CS/HandBrake.ApplicationServices/Services/LibScan.cs
win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index 59213e5d044a459fd477080ced978090170a1c99..78572858256473121b6ce28d4bbc9c3edc736777 100644 (file)
@@ -93,18 +93,5 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
         /// Kill the scan\r
         /// </summary>\r
         void Stop();\r
-\r
-        /// <summary>\r
-        /// Take a Scan Log file, and process it as if it were from the CLI.\r
-        /// </summary>\r
-        /// <param name="path">\r
-        /// The path to the log file.\r
-        /// </param>\r
-        void DebugScanLog(string path);\r
-\r
-        /// <summary>\r
-        /// Shutdown the service.\r
-        /// </summary>\r
-        void Shutdown();\r
     }\r
 }
\ No newline at end of file
index cc48ea3f43994b158444d224b55202b78d0a1f0d..a082bd2a4fec878be270ff9a0d69e8e93e45d283 100644 (file)
@@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Services
 {\r
     using System;\r
     using System.Collections.Generic;\r
+    using System.IO;\r
     using System.Text;\r
     using System.Threading;\r
 \r
@@ -66,6 +67,21 @@ namespace HandBrake.ApplicationServices.Services
         /// </summary>\r
         private string currentSourceScanPath;\r
 \r
+        /// <summary>\r
+        /// The log dir.\r
+        /// </summary>\r
+        private static string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+\r
+        /// <summary>\r
+        /// The dvd info path.\r
+        /// </summary>\r
+        private string dvdInfoPath = Path.Combine(logDir, string.Format("last_scan_log{0}.txt", GeneralUtilities.ProcessId));\r
+\r
+        /// <summary>\r
+        /// The scan log.\r
+        /// </summary>\r
+        private StreamWriter scanLog;\r
+\r
         #endregion\r
 \r
         /// <summary>\r
@@ -154,6 +170,9 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         public void Scan(string sourcePath, int title, int previewCount, Action<bool> postAction)\r
         {\r
+            this.logging.Clear();\r
+            scanLog = new StreamWriter(dvdInfoPath);\r
+\r
             Thread t = new Thread(unused => this.ScanSource(sourcePath, title, previewCount));\r
             t.Start();\r
         }\r
@@ -163,21 +182,20 @@ namespace HandBrake.ApplicationServices.Services
         /// </summary>\r
         public void Stop()\r
         {\r
-            instance.StopScan();\r
-        }\r
+            try\r
+            {\r
+                if (this.scanLog != null)\r
+                {\r
+                    this.scanLog.Close();\r
+                    this.scanLog.Dispose();\r
+                }\r
+            }\r
+            catch (Exception)\r
+            {\r
+                // Do Nothing.\r
+            }\r
 \r
-        /// <summary>\r
-        /// Debug a Scan Log (Only Available for CLI Mode, not LIBHB)\r
-        /// </summary>\r
-        /// <param name="path">\r
-        /// The path.\r
-        /// </param>\r
-        /// <exception cref="NotImplementedException">\r
-        /// (Only Available for CLI Mode, not LIBHB)\r
-        /// </exception>\r
-        public void DebugScanLog(string path)\r
-        {\r
-            throw new NotImplementedException("Only Available when using the CLI mode. Not LibHB");\r
+            instance.StopScan();\r
         }\r
 \r
         /// <summary>\r
@@ -246,6 +264,20 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         private void InstanceScanCompleted(object sender, EventArgs e)\r
         {\r
+            // Write the log file out before we start processing incase we crash.\r
+            try\r
+            {\r
+                if (this.scanLog != null)\r
+                {\r
+                    this.scanLog.Close();\r
+                    this.scanLog.Dispose();\r
+                }\r
+            }\r
+            catch (Exception)\r
+            {\r
+                // Do Nothing.\r
+            }\r
+\r
             // TODO -> Might be a better place to fix this.\r
             string path = currentSourceScanPath;\r
             if (currentSourceScanPath.Contains("\""))\r
@@ -253,6 +285,7 @@ namespace HandBrake.ApplicationServices.Services
                 path = currentSourceScanPath.Trim('\"');\r
             }\r
 \r
+            // Process into internal structures.\r
             this.SouceData = new Source { Titles = ConvertTitles(this.instance.Titles), ScanPath = path };\r
 \r
             IsScanning = false;\r
@@ -278,7 +311,8 @@ namespace HandBrake.ApplicationServices.Services
                     new ApplicationServices.EventArgs.ScanProgressEventArgs\r
                         {\r
                             CurrentTitle = e.CurrentTitle,\r
-                            Titles = e.Titles\r
+                            Titles = e.Titles,\r
+                            Percentage = Math.Round((decimal)e.Progress * 100, 0)\r
                         };\r
 \r
                 this.ScanStatusChanged(this, eventArgs);\r
@@ -298,6 +332,11 @@ namespace HandBrake.ApplicationServices.Services
         {\r
             lock (LogLock)\r
             {\r
+                if (this.scanLog != null)\r
+                {\r
+                    this.scanLog.WriteLine(e.Message);\r
+                }\r
+\r
                 this.logging.AppendLine(e.Message);\r
             }\r
         }\r
@@ -315,6 +354,11 @@ namespace HandBrake.ApplicationServices.Services
         {\r
             lock (LogLock)\r
             {\r
+                if (this.scanLog != null)\r
+                {\r
+                    this.scanLog.WriteLine(e.Message);\r
+                }\r
+\r
                 this.logging.AppendLine(e.Message);\r
             }\r
         }\r
@@ -335,12 +379,12 @@ namespace HandBrake.ApplicationServices.Services
             {\r
                 Title converted = new Title\r
                     {\r
-                        TitleNumber = title.TitleNumber, \r
-                        Duration = title.Duration, \r
-                        Resolution = new Size(title.Resolution.Width, title.Resolution.Height), \r
-                        AspectRatio = title.AspectRatio, \r
-                        AngleCount = title.AngleCount, \r
-                        ParVal = new Size(title.ParVal.Width, title.ParVal.Height), \r
+                        TitleNumber = title.TitleNumber,\r
+                        Duration = title.Duration,\r
+                        Resolution = new Size(title.Resolution.Width, title.Resolution.Height),\r
+                        AspectRatio = title.AspectRatio,\r
+                        AngleCount = title.AngleCount,\r
+                        ParVal = new Size(title.ParVal.Width, title.ParVal.Height),\r
                         AutoCropDimensions = title.AutoCropDimensions,\r
                         Fps = title.Framerate\r
                     };\r
index 2dbc7d9592017ed95ca03a34bcb32e20012157b3..701579d5bb9827f5aa370e37bd98e1a592950eea 100644 (file)
@@ -158,25 +158,6 @@ namespace HandBrakeWPF.Services
 \r
         #region IScan\r
 \r
-        /// <summary>\r
-        /// Take a Scan Log file, and process it as if it were from the CLI.\r
-        /// </summary>\r
-        /// <param name="path">\r
-        /// The path to the log file.\r
-        /// </param>\r
-        public void DebugScanLog(string path)\r
-        {\r
-            this.scanService.DebugScanLog(path);\r
-        }\r
-\r
-        /// <summary>\r
-        /// Shutdown the service.\r
-        /// </summary>\r
-        public void Shutdown()\r
-        {\r
-            this.scanService.Shutdown();\r
-        }\r
-\r
         /// <summary>\r
         /// Scan a Source Path.\r
         /// Title 0: scan all\r
index 8279c9adf1798a4e72ec083203fcee1623d40421..b42dd72bf8bcabeed5e5c2d69cb3db117abbd4c7 100644 (file)
@@ -978,7 +978,6 @@ namespace HandBrakeWPF.ViewModels
         public void Shutdown()\r
         {\r
             // Shutdown Service\r
-            this.scanService.Shutdown();\r
             this.encodeService.Shutdown();\r
 \r
             // Unsubscribe from Events.\r