Skip to content

Commit 04ee844

Browse files
author
RandomEngy
committed
Updated to HandBrake 4011svn. Added logic to report failures when errors are logged during the encode or when the encode finishes prematurely. Added Copy button to log window.
1 parent bcbd9f0 commit 04ee844

10 files changed

Lines changed: 109 additions & 17 deletions

File tree

Lib/x64/hb.dll

512 Bytes
Binary file not shown.

Lib/x86/hb.dll

0 Bytes
Binary file not shown.

VidCoder/Services/Interfaces/ILogger.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public interface ILogger : IDisposable
88
{
99
void ClearLog();
1010
void Log(string message);
11+
void LogError(string message);
12+
object LogLock { get; }
1113
List<LogEntry> LogEntries { get; }
1214

1315
event EventHandler<EventArgs<LogEntry>> EntryLogged;

VidCoder/Services/Logger.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public Logger()
4444
this.AddEntry(initialEntry);
4545
}
4646

47+
public object LogLock
48+
{
49+
get
50+
{
51+
return logLock;
52+
}
53+
}
54+
4755
public List<LogEntry> LogEntries
4856
{
4957
get
@@ -66,9 +74,24 @@ public void Log(string message)
6674
this.AddEntry(entry);
6775
}
6876

77+
public void LogError(string message)
78+
{
79+
var entry = new LogEntry
80+
{
81+
LogType = LogType.Error,
82+
Source = LogSource.VidCoder,
83+
Text = "# " + message
84+
};
85+
86+
this.AddEntry(entry);
87+
}
88+
6989
public void ClearLog()
7090
{
71-
this.LogEntries.Clear();
91+
lock (this.LogLock)
92+
{
93+
this.LogEntries.Clear();
94+
}
7295

7396
if (this.Cleared != null)
7497
{
@@ -101,7 +124,7 @@ private void AddEntry(LogEntry entry)
101124
}
102125
}
103126

104-
lock (this.logLock)
127+
lock (this.LogLock)
105128
{
106129
this.LogEntries.Add(entry);
107130
}

VidCoder/View/AboutDialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<TextBlock HorizontalAlignment="Left" Name="versionLabel" Text="Version" VerticalAlignment="Top" />
1515
<TextBlock Text="{Binding Version}" Margin="5,0,0,0" Name="versionText" />
1616
</StackPanel>
17-
<TextBlock Height="23" HorizontalAlignment="Left" Margin="171,79,0,0" Name="textBlock3" Text="Based on HandBrake (3978svn)" VerticalAlignment="Top" />
17+
<TextBlock Height="23" HorizontalAlignment="Left" Margin="171,79,0,0" Name="textBlock3" Text="Based on HandBrake (4011svn)" VerticalAlignment="Top" />
1818
<TextBlock Height="23" HorizontalAlignment="Left" Margin="171,108,0,0" Name="textBlock2" Text="© 2010 VidCoder Developers" VerticalAlignment="Top" />
1919
<Label Content="License:" Height="28" HorizontalAlignment="Left" Margin="12,138,0,0" Name="label1" VerticalAlignment="Top" />
2020

VidCoder/View/LogWindow.xaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
Title="Log" Height="393" Width="459"
55
Style="{StaticResource NormalWindow}"
6-
WindowStyle="ToolWindow" ShowInTaskbar="False" Closing="Window_Closing">
6+
WindowStyle="ToolWindow" ShowInTaskbar="False" Closing="Window_Closing"
7+
MinWidth="220" MinHeight="95">
78
<Window.InputBindings>
89
<KeyBinding Key="N" Modifiers="Control" Command="{Binding MainViewModel.OpenEncodingWindowCommand}" />
910
<KeyBinding Key="P" Modifiers="Control" Command="{Binding MainViewModel.OpenPreviewWindowCommand}" />
@@ -23,6 +24,15 @@
2324
</FlowDocument.Resources>
2425
</FlowDocument>
2526
</RichTextBox>
27+
<Button
28+
Height="24" HorizontalAlignment="Right" Margin="0,0,127,7" Name="copyButton" VerticalAlignment="Bottom" Width="68"
29+
Command="{Binding CopyCommand}">
30+
<StackPanel Orientation="Horizontal">
31+
<Image Source="/Icons/copy.png" Width="16" Height="16" />
32+
<TextBlock Text="Copy" Margin="4,0,0,0" />
33+
</StackPanel>
34+
</Button>
35+
2636
<Button
2737
Content="Clear"
2838
Command="{Binding ClearLogCommand}"

VidCoder/View/LogWindow.xaml.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public LogWindow()
2828
{
2929
InitializeComponent();
3030

31-
// Add all existing log entries
32-
foreach (LogEntry entry in this.logger.LogEntries)
31+
lock (this.logger.LogLock)
3332
{
34-
this.AddEntry(entry);
33+
// Add all existing log entries
34+
foreach (LogEntry entry in this.logger.LogEntries)
35+
{
36+
this.AddEntry(entry);
37+
}
3538
}
3639

3740
this.Loaded += (sender, e) =>
@@ -40,8 +43,8 @@ public LogWindow()
4043
};
4144

4245
// Subscribe to events
43-
this.logger.EntryLogged += OnEntryLogged;
44-
this.logger.Cleared += OnCleared;
46+
this.logger.EntryLogged += this.OnEntryLogged;
47+
this.logger.Cleared += this.OnCleared;
4548
}
4649

4750
protected override void OnSourceInitialized(EventArgs e)
@@ -52,6 +55,9 @@ protected override void OnSourceInitialized(EventArgs e)
5255

5356
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
5457
{
58+
this.logger.EntryLogged -= this.OnEntryLogged;
59+
this.logger.Cleared -= this.OnCleared;
60+
5561
Settings.Default.LogWindowPlacement = this.GetPlacement();
5662
Settings.Default.Save();
5763
}

VidCoder/View/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390
Orientation="Horizontal"
391391
Visibility="{Binding SourcePicked, Converter={StaticResource VisibilityConverter}}">
392392
<TextBlock Text="Source:" Style="{StaticResource SectionHeader}" />
393-
<Image Source="{Binding SourceIcon}" Width="16" Height="16" Margin="4,2,0,2" VerticalAlignment="Top" HorizontalAlignment="Left" />
393+
<Image Source="{Binding SourceIcon}" Width="16" Height="16" Margin="3.5,1,0,0" VerticalAlignment="Center" />
394394
<TextBlock Text="{Binding SourceText}" Style="{StaticResource SourceDescription}" Margin="4,4,4,3" />
395395
<Polygon
396396
VerticalAlignment="Center"

VidCoder/ViewModel/LogViewModel.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Windows;
56
using System.Windows.Input;
67
using Microsoft.Practices.Unity;
78
using VidCoder.Model;
@@ -15,6 +16,7 @@ public class LogViewModel : OkCancelDialogViewModel
1516
private ILogger logger = Unity.Container.Resolve<ILogger>();
1617

1718
private ICommand clearLogCommand;
19+
private ICommand copyCommand;
1820

1921
public MainViewModel MainViewModel
2022
{
@@ -40,5 +42,31 @@ public ICommand ClearLogCommand
4042
return this.clearLogCommand;
4143
}
4244
}
45+
46+
public ICommand CopyCommand
47+
{
48+
get
49+
{
50+
if (this.copyCommand == null)
51+
{
52+
this.copyCommand = new RelayCommand(param =>
53+
{
54+
lock (this.logger.LogLock)
55+
{
56+
var logTextBuilder = new StringBuilder();
57+
58+
foreach (LogEntry entry in this.logger.LogEntries)
59+
{
60+
logTextBuilder.AppendLine(entry.Text);
61+
}
62+
63+
Clipboard.SetText(logTextBuilder.ToString());
64+
}
65+
});
66+
}
67+
68+
return this.copyCommand;
69+
}
70+
}
4371
}
4472
}

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class MainViewModel : ViewModelBase
8282
private bool encoding;
8383
private bool paused;
8484
private bool encodeStopped;
85+
private bool errorLoggedDuringJob; // True if an error was logged during an encode (and no scan was going on at the time)
8586
private int totalTasks;
8687
private int taskNumber;
8788
private bool encodeSpeedDetailsAvailable;
@@ -93,6 +94,7 @@ public class MainViewModel : ViewModelBase
9394
private double completedQueueWork;
9495
private double totalQueueCost;
9596
private double overallEncodeProgressFraction;
97+
private TimeSpan currentJobEta; // Kept around to check if the job finished early
9698
private TaskbarItemProgressState encodeProgressState;
9799
private ObservableCollection<EncodeResultViewModel> completedJobs;
98100

@@ -203,8 +205,8 @@ public MainViewModel()
203205
this.encodeQueue.Add(new EncodeJobViewModel(job));
204206
}
205207

206-
this.autoPause.PauseEncoding += new EventHandler(this.AutoPauseEncoding);
207-
this.autoPause.ResumeEncoding += new EventHandler(this.AutoResumeEncoding);
208+
this.autoPause.PauseEncoding += this.AutoPauseEncoding;
209+
this.autoPause.ResumeEncoding += this.AutoResumeEncoding;
208210

209211
// Always select the modified preset if it exists.
210212
// Otherwise, choose the last selected preset.
@@ -223,6 +225,15 @@ public MainViewModel()
223225
presetIndex = 0;
224226
}
225227

228+
// Keep track of errors logged. HandBrake doesn't reliably report errors on job completion.
229+
this.logger.EntryLogged += (sender, e) =>
230+
{
231+
if (e.Value.LogType == LogType.Error && this.Encoding && !this.ScanningSource)
232+
{
233+
this.errorLoggedDuringJob = true;
234+
}
235+
};
236+
226237
this.SelectedPreset = this.allPresets[presetIndex];
227238

228239
this.completedJobs = new ObservableCollection<EncodeResultViewModel>();
@@ -2566,6 +2577,8 @@ private void StartEncode()
25662577
}
25672578
}
25682579

2580+
this.currentJobEta = TimeSpan.Zero;
2581+
this.errorLoggedDuringJob = false;
25692582
this.EncodeQueue[0].ReportEncodeStart(this.totalTasks == 1);
25702583
this.CurrentJob.HandBrakeInstance.StartEncode(this.CurrentJob.Job);
25712584
}
@@ -2641,9 +2654,9 @@ private void OnEncodeProgress(object sender, EncodeProgressEventArgs e)
26412654

26422655
double currentJobRemainingWork = this.EncodeQueue[0].Cost - currentJobCompletedWork;
26432656

2644-
TimeSpan currentJobEta =
2657+
this.currentJobEta =
26452658
TimeSpan.FromSeconds(currentJobRemainingWork / overallWorkCompletionRate);
2646-
this.EncodeQueue[0].Eta = currentJobEta;
2659+
this.EncodeQueue[0].Eta = this.currentJobEta;
26472660
}
26482661
}
26492662

@@ -2688,17 +2701,27 @@ private void OnEncodeCompleted(object sender, EncodeCompletedEventArgs e)
26882701
if (e.Error)
26892702
{
26902703
succeeded = false;
2691-
this.logger.Log("Encode failed. HandBrake reported an error.");
2704+
this.logger.LogError("Encode failed. HandBrake reported an error.");
2705+
}
2706+
else if (this.errorLoggedDuringJob)
2707+
{
2708+
succeeded = false;
2709+
this.logger.LogError("Encode failed. Error(s) were reported during the encode.");
26922710
}
26932711
else if (!outputFileInfo.Exists)
26942712
{
26952713
succeeded = false;
2696-
this.logger.Log("Encode failed. HandBrake reported no error but the expected output file was not found.");
2714+
this.logger.LogError("Encode failed. HandBrake reported no error but the expected output file was not found.");
26972715
}
26982716
else if (outputFileInfo.Length == 0)
26992717
{
27002718
succeeded = false;
2701-
this.logger.Log("Encode failed. HandBrake reported no error but the output file was empty.");
2719+
this.logger.LogError("Encode failed. HandBrake reported no error but the output file was empty.");
2720+
}
2721+
else if (this.currentJobEta > TimeSpan.FromMinutes(1))
2722+
{
2723+
succeeded = false;
2724+
this.logger.LogError("Encode failed. HandBrake reported no error but the encode finished prematurely.");
27022725
}
27032726

27042727
this.CompletedJobs.Add(new EncodeResultViewModel(

0 commit comments

Comments
 (0)