summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--win/CS/HandBrakeWPF/Instance/RemoteInstance.cs10
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs1
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs16
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/LogInstanceManager.cs30
-rw-r--r--win/CS/HandBrakeWPF/Services/Logging/LogService.cs11
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs88
-rw-r--r--win/CS/HandBrakeWPF/Views/LogView.xaml6
7 files changed, 108 insertions, 54 deletions
diff --git a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
index 01a91c948..a6b7d7446 100644
--- a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
+++ b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
@@ -11,6 +11,7 @@
namespace HandBrakeWPF.Instance
{
using System;
+ using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
@@ -278,7 +279,14 @@ namespace HandBrakeWPF.Instance
this.encodePollTimer.Stop();
if (this.workerProcess != null && !this.workerProcess.HasExited)
{
- this.workerProcess?.Kill();
+ try
+ {
+ this.workerProcess?.Kill();
+ }
+ catch (Win32Exception e)
+ {
+ Debug.WriteLine(e);
+ }
}
this.EncodeCompleted?.Invoke(sender: this, e: new EncodeCompletedEventArgs(state.WorkDone.Error));
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
index a383a0b14..796ddac7b 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
@@ -287,6 +287,7 @@ namespace HandBrakeWPF.Services.Encode
string logFile = Path.Combine(DirectoryUtilities.GetLogDirectory(), filename);
this.encodeLogService = new LogService();
this.encodeLogService.ConfigureLogging(logFile);
+ this.encodeLogService.SetId(this.encodeCounter);
this.logInstanceManager.RegisterLoggerInstance(filename, this.encodeLogService, false);
isLoggingInitialised = true;
}
diff --git a/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs b/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs
index 57594528a..b20a04b72 100644
--- a/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs
+++ b/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs
@@ -32,6 +32,16 @@ namespace HandBrakeWPF.Services.Logging.Interfaces
event EventHandler LogReset;
/// <summary>
+ /// An ID that allows this instance to be associated with an encode service implementation.
+ /// </summary>
+ int LogId { get; }
+
+ /// <summary>
+ /// The filename this log service is outputting to.
+ /// </summary>
+ string FileName { get; }
+
+ /// <summary>
/// Enable logging for this worker process.
/// </summary>
/// <param name="filename">
@@ -58,5 +68,11 @@ namespace HandBrakeWPF.Services.Logging.Interfaces
/// Empty the log cache and reset the log handler to defaults.
/// </summary>
void Reset();
+
+ /// <summary>
+ /// Add a Marker to this log service to make it easier to associate with an encode instance.
+ /// </summary>
+ /// <param name="id">An ID number from the underlying service.</param>
+ void SetId(int id);
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/Logging/LogInstanceManager.cs b/win/CS/HandBrakeWPF/Services/Logging/LogInstanceManager.cs
index 16c9aa7dc..42f85cc53 100644
--- a/win/CS/HandBrakeWPF/Services/Logging/LogInstanceManager.cs
+++ b/win/CS/HandBrakeWPF/Services/Logging/LogInstanceManager.cs
@@ -10,13 +10,13 @@ namespace HandBrakeWPF.Services.Logging
{
using System;
using System.Collections.Generic;
+ using System.IO;
using System.Linq;
+ using System.Windows.Media.Animation;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Logging.Interfaces;
- using Microsoft.Win32.SafeHandles;
-
public class LogInstanceManager : ILogInstanceManager
{
private readonly IUserSettingService userSettingService;
@@ -104,11 +104,29 @@ namespace HandBrakeWPF.Services.Logging
private void CleanupInstance()
{
- List<string> encodeLogs = this.logInstances.Keys.Where(f => f.Contains(".encode.")).ToList();
- string removalKey = this.logInstances.Keys.OrderBy(k => k).FirstOrDefault(w => w.Contains(".encode."));
- if (encodeLogs.Count > this.maxInstances)
+ List<int> encodeLogs = new List<int>();
+ foreach (ILog logInstance in this.logInstances.Values)
+ {
+ if (logInstance.LogId != -1)
+ {
+ encodeLogs.Add(logInstance.LogId);
+ }
+ }
+
+ encodeLogs.Sort();
+
+ if (encodeLogs.Count > 0 && encodeLogs.Count > this.maxInstances)
{
- this.logInstances.Remove(removalKey);
+ int idToRemove = encodeLogs.FirstOrDefault();
+
+ KeyValuePair<string, ILog> service = this.logInstances.FirstOrDefault(i => i.Value.LogId == idToRemove);
+
+ string filename = Path.GetFileName(service.Value.FileName);
+
+ if (this.logInstances.ContainsKey(filename))
+ {
+ this.logInstances.Remove(filename);
+ }
}
}
}
diff --git a/win/CS/HandBrakeWPF/Services/Logging/LogService.cs b/win/CS/HandBrakeWPF/Services/Logging/LogService.cs
index 18a8ffaee..119a387ea 100644
--- a/win/CS/HandBrakeWPF/Services/Logging/LogService.cs
+++ b/win/CS/HandBrakeWPF/Services/Logging/LogService.cs
@@ -42,6 +42,7 @@ namespace HandBrakeWPF.Services.Logging
public LogService()
{
+ this.LogId = -1; // Unset
}
public event EventHandler<LogEventArgs> MessageLogged;
@@ -59,6 +60,10 @@ namespace HandBrakeWPF.Services.Logging
}
}
+ public int LogId { get; private set; }
+
+ public string FileName { get; private set; }
+
public void LogMessage(string content)
{
if (!this.isLoggingEnabled)
@@ -92,6 +97,7 @@ namespace HandBrakeWPF.Services.Logging
public void ConfigureLogging(string filename)
{
this.isLoggingEnabled = true;
+ this.FileName = filename;
if (!string.IsNullOrEmpty(filename) && !Directory.Exists(Path.GetDirectoryName(filename)))
{
@@ -160,6 +166,11 @@ namespace HandBrakeWPF.Services.Logging
}
}
+ public void SetId(int id)
+ {
+ this.LogId = id;
+ }
+
public void Dispose()
{
this.ShutdownFileWriter();
diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs
index acdb33816..2ce7c6c5e 100644
--- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs
@@ -14,7 +14,6 @@ namespace HandBrakeWPF.ViewModels
using System.Diagnostics;
using System.Linq;
using System.Text;
- using System.Windows.Forms;
using Caliburn.Micro;
@@ -27,9 +26,8 @@ namespace HandBrakeWPF.ViewModels
using HandBrakeWPF.ViewModels.Interfaces;
using Clipboard = System.Windows.Clipboard;
- using ILog = HandBrakeWPF.Services.Logging.Interfaces.ILog;
- using LogEventArgs = HandBrakeWPF.Services.Logging.EventArgs.LogEventArgs;
- using LogService = HandBrakeWPF.Services.Logging.LogService;
+ using ILog = Services.Logging.Interfaces.ILog;
+ using LogEventArgs = Services.Logging.EventArgs.LogEventArgs;
public class LogViewModel : ViewModelBase, ILogViewModel
{
@@ -48,7 +46,6 @@ namespace HandBrakeWPF.ViewModels
this.errorService = errorService;
this.logInstanceManager = logInstanceManager;
this.Title = Resources.LogViewModel_Title;
- this.selectedLogFile = logInstanceManager.ApplicationAndScanLog;
}
public event EventHandler<LogEventArgs> LogMessageReceived;
@@ -74,7 +71,11 @@ namespace HandBrakeWPF.ViewModels
get => this.selectedLogFile;
set
{
- if (value == this.selectedLogFile) return;
+ if (value == this.selectedLogFile)
+ {
+ return;
+ }
+
this.selectedLogFile = value;
this.NotifyOfPropertyChange(() => this.SelectedLogFile);
@@ -106,59 +107,36 @@ namespace HandBrakeWPF.ViewModels
{
this.logInstanceManager.NewLogInstanceRegistered += this.LogInstanceManager_NewLogInstanceRegistered;
- if (string.IsNullOrEmpty(this.SelectedLogFile))
- {
- base.OnActivate();
- return;
- }
-
- if (this.logService == null)
- {
- this.logService = this.logInstanceManager.GetLogInstance(this.SelectedLogFile);
- }
-
this.NotifyOfPropertyChange(() => this.LogFiles);
- this.logService.MessageLogged += this.LogService_MessageLogged;
- this.logService.LogReset += LogService_LogReset;
-
- // Refresh the Log Display
- this.log.Clear();
- foreach (LogMessage logMessage in this.logService.GetLogMessages())
+ if (string.IsNullOrEmpty(this.SelectedLogFile) || !this.LogFiles.Contains(this.SelectedLogFile))
{
- this.log.AppendLine(logMessage.Content);
- this.lastReadIndex = logMessage.MessageIndex;
-
- if (this.lastReadIndex > logMessage.MessageIndex)
- {
- throw new Exception("Log Message Index Error");
- }
- }
-
- this.OnLogMessageReceived(null);
- this.NotifyOfPropertyChange(() => this.ActivityLog);
+ this.SelectedLogFile = this.LogFiles.LastOrDefault();
+ }
base.OnActivate();
}
- protected virtual void OnLogMessageReceived(LogEventArgs e)
+ protected override void OnDeactivate(bool close)
{
- var onLogMessageReceived = this.LogMessageReceived;
- if (onLogMessageReceived != null)
+ if (this.logService != null)
{
- onLogMessageReceived.Invoke(this, e);
+ this.logService.MessageLogged -= this.LogService_MessageLogged;
+ this.logService.LogReset -= this.LogService_LogReset;
}
- }
- protected override void OnDeactivate(bool close)
- {
- this.logService.MessageLogged -= this.LogService_MessageLogged;
- this.logService.LogReset -= this.LogService_LogReset;
+ this.SelectedLogFile = null;
this.logInstanceManager.NewLogInstanceRegistered -= this.LogInstanceManager_NewLogInstanceRegistered;
base.OnDeactivate(close);
}
+ protected virtual void OnLogMessageReceived(LogEventArgs e)
+ {
+ var onLogMessageReceived = this.LogMessageReceived;
+ onLogMessageReceived?.Invoke(this, e);
+ }
+
private void ChangeLogFileView()
{
if (this.logService != null)
@@ -167,11 +145,33 @@ namespace HandBrakeWPF.ViewModels
this.logService.LogReset -= this.LogService_LogReset;
}
+ if (this.SelectedLogFile == null)
+ {
+ return;
+ }
+
this.logService = this.logInstanceManager.GetLogInstance(this.SelectedLogFile);
if (this.logService != null)
{
- OnActivate();
+ this.logService.MessageLogged += this.LogService_MessageLogged;
+ this.logService.LogReset += LogService_LogReset;
+
+ // Refresh the Log Display
+ this.log.Clear();
+ foreach (LogMessage logMessage in this.logService.GetLogMessages())
+ {
+ this.log.AppendLine(logMessage.Content);
+ this.lastReadIndex = logMessage.MessageIndex;
+
+ if (this.lastReadIndex > logMessage.MessageIndex)
+ {
+ throw new Exception("Log Message Index Error");
+ }
+ }
+
+ this.OnLogMessageReceived(null);
+ this.NotifyOfPropertyChange(() => this.ActivityLog);
}
}
diff --git a/win/CS/HandBrakeWPF/Views/LogView.xaml b/win/CS/HandBrakeWPF/Views/LogView.xaml
index 966a651f7..bc19642c5 100644
--- a/win/CS/HandBrakeWPF/Views/LogView.xaml
+++ b/win/CS/HandBrakeWPF/Views/LogView.xaml
@@ -5,9 +5,9 @@
xmlns:Properties="clr-namespace:HandBrakeWPF.Properties"
xmlns:converters="clr-namespace:HandBrakeWPF.Converters"
Title="{Binding Title}"
- Width="600"
+ Width="625"
Height="650"
- MinWidth="525"
+ MinWidth="625"
MinHeight="600"
WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display">
@@ -32,7 +32,7 @@
<StackPanel Orientation="Horizontal">
<TextBlock Text="Choose Log File: " Margin="5,0,5,0"></TextBlock>
- <ComboBox ItemsSource="{Binding LogFiles}" SelectedItem="{Binding SelectedLogFile}" Width="150" />
+ <ComboBox ItemsSource="{Binding LogFiles}" SelectedItem="{Binding SelectedLogFile}" Width="195" />
</StackPanel>
<Button cal:Message.Attach="[Event Click] = [Action CopyLog]" Margin="10,0,0,0"