From 2526f515e8221cf8a955a3ea2dd405806d3aa259 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 24 Aug 2013 13:48:41 +0000 Subject: [PATCH] WinGui: Fixes around libhb scanning. (Progress % was not shown and the scan logs was not written to disc) git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5744 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/Interfaces/IScan.cs | 13 --- .../Services/LibScan.cs | 86 ++++++++++++++----- .../Services/ScanServiceWrapper.cs | 19 ---- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 1 - 4 files changed, 65 insertions(+), 54 deletions(-) diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IScan.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IScan.cs index 59213e5d0..785728582 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IScan.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IScan.cs @@ -93,18 +93,5 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// Kill the scan /// void Stop(); - - /// - /// Take a Scan Log file, and process it as if it were from the CLI. - /// - /// - /// The path to the log file. - /// - void DebugScanLog(string path); - - /// - /// Shutdown the service. - /// - void Shutdown(); } } \ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs b/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs index cc48ea3f4..a082bd2a4 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs @@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Services { using System; using System.Collections.Generic; + using System.IO; using System.Text; using System.Threading; @@ -66,6 +67,21 @@ namespace HandBrake.ApplicationServices.Services /// private string currentSourceScanPath; + /// + /// The log dir. + /// + private static string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs"; + + /// + /// The dvd info path. + /// + private string dvdInfoPath = Path.Combine(logDir, string.Format("last_scan_log{0}.txt", GeneralUtilities.ProcessId)); + + /// + /// The scan log. + /// + private StreamWriter scanLog; + #endregion /// @@ -154,6 +170,9 @@ namespace HandBrake.ApplicationServices.Services /// public void Scan(string sourcePath, int title, int previewCount, Action postAction) { + this.logging.Clear(); + scanLog = new StreamWriter(dvdInfoPath); + Thread t = new Thread(unused => this.ScanSource(sourcePath, title, previewCount)); t.Start(); } @@ -163,21 +182,20 @@ namespace HandBrake.ApplicationServices.Services /// public void Stop() { - instance.StopScan(); - } + try + { + if (this.scanLog != null) + { + this.scanLog.Close(); + this.scanLog.Dispose(); + } + } + catch (Exception) + { + // Do Nothing. + } - /// - /// Debug a Scan Log (Only Available for CLI Mode, not LIBHB) - /// - /// - /// The path. - /// - /// - /// (Only Available for CLI Mode, not LIBHB) - /// - public void DebugScanLog(string path) - { - throw new NotImplementedException("Only Available when using the CLI mode. Not LibHB"); + instance.StopScan(); } /// @@ -246,6 +264,20 @@ namespace HandBrake.ApplicationServices.Services /// private void InstanceScanCompleted(object sender, EventArgs e) { + // Write the log file out before we start processing incase we crash. + try + { + if (this.scanLog != null) + { + this.scanLog.Close(); + this.scanLog.Dispose(); + } + } + catch (Exception) + { + // Do Nothing. + } + // TODO -> Might be a better place to fix this. string path = currentSourceScanPath; if (currentSourceScanPath.Contains("\"")) @@ -253,6 +285,7 @@ namespace HandBrake.ApplicationServices.Services path = currentSourceScanPath.Trim('\"'); } + // Process into internal structures. this.SouceData = new Source { Titles = ConvertTitles(this.instance.Titles), ScanPath = path }; IsScanning = false; @@ -278,7 +311,8 @@ namespace HandBrake.ApplicationServices.Services new ApplicationServices.EventArgs.ScanProgressEventArgs { CurrentTitle = e.CurrentTitle, - Titles = e.Titles + Titles = e.Titles, + Percentage = Math.Round((decimal)e.Progress * 100, 0) }; this.ScanStatusChanged(this, eventArgs); @@ -298,6 +332,11 @@ namespace HandBrake.ApplicationServices.Services { lock (LogLock) { + if (this.scanLog != null) + { + this.scanLog.WriteLine(e.Message); + } + this.logging.AppendLine(e.Message); } } @@ -315,6 +354,11 @@ namespace HandBrake.ApplicationServices.Services { lock (LogLock) { + if (this.scanLog != null) + { + this.scanLog.WriteLine(e.Message); + } + this.logging.AppendLine(e.Message); } } @@ -335,12 +379,12 @@ namespace HandBrake.ApplicationServices.Services { Title converted = new Title { - TitleNumber = title.TitleNumber, - Duration = title.Duration, - Resolution = new Size(title.Resolution.Width, title.Resolution.Height), - AspectRatio = title.AspectRatio, - AngleCount = title.AngleCount, - ParVal = new Size(title.ParVal.Width, title.ParVal.Height), + TitleNumber = title.TitleNumber, + Duration = title.Duration, + Resolution = new Size(title.Resolution.Width, title.Resolution.Height), + AspectRatio = title.AspectRatio, + AngleCount = title.AngleCount, + ParVal = new Size(title.ParVal.Width, title.ParVal.Height), AutoCropDimensions = title.AutoCropDimensions, Fps = title.Framerate }; diff --git a/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs b/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs index 2dbc7d959..701579d5b 100644 --- a/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs +++ b/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs @@ -158,25 +158,6 @@ namespace HandBrakeWPF.Services #region IScan - /// - /// Take a Scan Log file, and process it as if it were from the CLI. - /// - /// - /// The path to the log file. - /// - public void DebugScanLog(string path) - { - this.scanService.DebugScanLog(path); - } - - /// - /// Shutdown the service. - /// - public void Shutdown() - { - this.scanService.Shutdown(); - } - /// /// Scan a Source Path. /// Title 0: scan all diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 8279c9adf..b42dd72bf 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -978,7 +978,6 @@ namespace HandBrakeWPF.ViewModels public void Shutdown() { // Shutdown Service - this.scanService.Shutdown(); this.encodeService.Shutdown(); // Unsubscribe from Events. -- 2.40.0