From: sr55 Date: Tue, 2 May 2017 17:37:52 +0000 (+0100) Subject: WinGui: Improved logging around SCANDONE and some additional defensive programming... X-Git-Tag: 1.1.0~573 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1bcb7af6947aed329924a82e58a45c143feedbf;p=handbrake WinGui: Improved logging around SCANDONE and some additional defensive programming to try track down this never ending scan. --- diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index 7114bab64..2c56a76c4 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -489,24 +489,40 @@ namespace HandBrake.ApplicationServices.Interop IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle); string statusJson = Marshal.PtrToStringAnsi(json); this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace); - JsonState state = JsonConvert.DeserializeObject(statusJson); + JsonState state = null; + if (!string.IsNullOrEmpty(statusJson)) + { + state = JsonConvert.DeserializeObject(statusJson); + } if (state != null && (state.State == NativeConstants.HB_STATE_SCANNING || state.State == NativeConstants.HB_STATE_SEARCHING)) { - if (this.ScanProgress != null) + if (this.ScanProgress != null && state.Scanning != null) { this.ScanProgress(this, new ScanProgressEventArgs(state.Scanning.Progress, state.Scanning.Preview, state.Scanning.PreviewCount, state.Scanning.Title, state.Scanning.TitleCount)); } } else if (state != null && state.State == NativeConstants.HB_STATE_SCANDONE) { + this.log.LogMessage("Scan: HB_STATE_SCANDONE", LogMessageType.API, LogLevel.Info); + this.scanPollTimer.Stop(); + var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle); string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg); - this.log.LogMessage(scanJson, LogMessageType.Progress, LogLevel.Trace); - this.titles = JsonConvert.DeserializeObject(scanJson); - this.featureTitle = this.titles.MainFeature; + this.log.LogMessage(scanJson, LogMessageType.Progress, LogLevel.Info); - this.scanPollTimer.Stop(); + if (string.IsNullOrEmpty(scanJson)) + { + this.log.LogMessage("Scan Error: No Scan Data Returned.", LogMessageType.API, LogLevel.Error); + } + else + { + this.titles = JsonConvert.DeserializeObject(scanJson); + if (this.titles != null) + { + this.featureTitle = this.titles.MainFeature; + } + } if (this.ScanCompleted != null) { diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs index ef869570a..abaf18e64 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs @@ -103,7 +103,7 @@ namespace HandBrake.ApplicationServices.Services.Logging return; } - if (level >= this.currentLogLevel) + if (level > this.currentLogLevel) { return; } diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs index eac84f263..955e769ed 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs @@ -142,7 +142,7 @@ namespace HandBrakeWPF.Services.Scan { try { - this.ServiceLogMessage("Stopping Scan ..."); + this.ServiceLogMessage("Manually Stopping Scan ..."); this.IsScanning = false; this.instance.StopScan(); }