Skip to content

Commit 26f3d8c

Browse files
author
RandomEngy
committed
Encodes that fail to produce an output file but report success are now reported correctly as failed.
1 parent 9efb652 commit 26f3d8c

4 files changed

Lines changed: 45 additions & 25 deletions

File tree

VidCoder/Services/Logger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public string LogText
4747

4848
public void Log(string message)
4949
{
50-
this.RecordMessage(message);
50+
string prefix = string.IsNullOrEmpty(message) ? string.Empty : "# ";
51+
52+
this.RecordMessage(prefix + message);
5153
}
5254

5355
public void ClearLog()

VidCoder/Services/ProcessAutoPause.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void PollTimerElapsed(object sender, ElapsedEventArgs e)
110110
if (autoPauseProcess == null)
111111
{
112112
this.autoPaused = false;
113-
this.logger.Log("# Automatically resuming, processes are gone.");
113+
this.logger.Log("Automatically resuming, processes are gone.");
114114

115115
if (this.ResumeEncoding != null)
116116
{
@@ -123,7 +123,7 @@ private void PollTimerElapsed(object sender, ElapsedEventArgs e)
123123
if (autoPauseProcess != null)
124124
{
125125
this.autoPaused = true;
126-
this.logger.Log("# Automatically pausing, process detected: " + autoPauseProcess);
126+
this.logger.Log("Automatically pausing, process detected: " + autoPauseProcess);
127127
if (this.PauseEncoding != null)
128128
{
129129
this.PauseEncoding(this, new EventArgs());

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,7 +2315,7 @@ public EncodeJob EncodeJob
23152315
public void StartEncodeQueue()
23162316
{
23172317
this.EncodeProgressState = TaskbarItemProgressState.Normal;
2318-
this.logger.Log("## Starting queue");
2318+
this.logger.Log("Starting queue");
23192319

23202320
this.totalTasks = this.EncodeQueue.Count;
23212321
this.taskNumber = 0;
@@ -2373,10 +2373,10 @@ private void StartEncode()
23732373
{
23742374
EncodeJob job = this.CurrentJob.Job;
23752375

2376-
this.logger.Log("## Starting job " + this.taskNumber + "/" + this.totalTasks);
2377-
this.logger.Log("## Path: " + job.SourcePath);
2378-
this.logger.Log("## Title: " + job.Title);
2379-
this.logger.Log("## Chapters: " + job.ChapterStart + "-" + job.ChapterEnd);
2376+
this.logger.Log("Starting job " + this.taskNumber + "/" + this.totalTasks);
2377+
this.logger.Log(" Path: " + job.SourcePath);
2378+
this.logger.Log(" Title: " + job.Title);
2379+
this.logger.Log(" Chapters: " + job.ChapterStart + "-" + job.ChapterEnd);
23802380
this.CurrentJob.HandBrakeInstance.EncodeProgress += this.OnEncodeProgress;
23812381
this.CurrentJob.HandBrakeInstance.EncodeCompleted += this.OnEncodeCompleted;
23822382

@@ -2507,18 +2507,36 @@ private void OnEncodeCompleted(object sender, EncodeCompletedEventArgs e)
25072507
this.EncodeQueue.Clear();
25082508
}
25092509

2510-
this.logger.Log("## Encoding stopped");
2510+
this.logger.Log("Encoding stopped");
25112511
}
25122512
else
25132513
{
25142514
// If the encode completed successfully
25152515
this.completedQueueWork += this.EncodeQueue[0].Cost;
25162516

2517+
var outputFileInfo = new FileInfo(this.CurrentJob.Job.OutputPath);
2518+
bool succeeded = true;
2519+
if (e.Error)
2520+
{
2521+
succeeded = false;
2522+
this.logger.Log("Encode failed. HandBrake reported an error.");
2523+
}
2524+
else if (!outputFileInfo.Exists)
2525+
{
2526+
succeeded = false;
2527+
this.logger.Log("Encode failed. HandBrake reported no error but the expected output file was not found.");
2528+
}
2529+
else if (outputFileInfo.Length == 0)
2530+
{
2531+
succeeded = false;
2532+
this.logger.Log("Encode failed. HandBrake reported no error but the output file was empty.");
2533+
}
2534+
25172535
this.CompletedJobs.Add(new EncodeResultViewModel(
25182536
new EncodeResult
25192537
{
25202538
Destination = this.CurrentJob.Job.OutputPath,
2521-
Succeeded = !e.Error,
2539+
Succeeded = succeeded,
25222540
EncodeTime = this.CurrentJob.EncodeTime
25232541
}));
25242542
this.NotifyPropertyChanged("CompletedItemsCount");
@@ -2530,14 +2548,14 @@ private void OnEncodeCompleted(object sender, EncodeCompletedEventArgs e)
25302548

25312549
this.CleanupHandBrakeInstance(finishedInstance);
25322550

2533-
this.logger.Log("## Job completed");
2551+
this.logger.Log("Job completed");
25342552

25352553
if (this.EncodeQueue.Count == 0)
25362554
{
25372555
this.SelectedTabIndex = CompletedTabIndex;
25382556
this.StopEncodingAndReport();
25392557

2540-
this.logger.Log("## Queue completed");
2558+
this.logger.Log("Queue completed");
25412559
this.logger.Log("");
25422560
}
25432561
else
@@ -3005,7 +3023,7 @@ private void StartScan(string path)
30053023
this.CleanupHandBrakeInstance(oldInstance);
30063024
}
30073025

3008-
this.logger.Log("## Starting scan: " + path);
3026+
this.logger.Log("Starting scan: " + path);
30093027

30103028
this.scanInstance = new HandBrakeInstance();
30113029
this.scanInstance.Initialize(Settings.Default.LogVerbosity);
@@ -3026,12 +3044,12 @@ private void StartScan(string path)
30263044
this.ScanCancelled(this, new EventArgs());
30273045
}
30283046

3029-
this.logger.Log("## Scan cancelled");
3047+
this.logger.Log("Scan cancelled");
30303048
}
30313049
else
30323050
{
30333051
this.SourceData = new VideoSource { Titles = this.scanInstance.Titles, FeatureTitle = this.scanInstance.FeatureTitle };
3034-
this.logger.Log("## Scan completed");
3052+
this.logger.Log("Scan completed");
30353053
}
30363054

30373055
this.logger.Log("");

VidCoder/ViewModel/PreviewViewModel.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ public ICommand GeneratePreviewCommand
229229
this.generatePreviewCommand = new RelayCommand(param =>
230230
{
231231
this.job = this.mainViewModel.EncodeJob;
232-
this.logger.Log("## Generating preview clip");
233-
this.logger.Log("## Scanning title");
232+
this.logger.Log("Generating preview clip");
233+
this.logger.Log("Scanning title");
234234

235235
this.previewInstance = new HandBrakeInstance();
236236
this.previewInstance.Initialize(Settings.Default.LogVerbosity);
@@ -644,7 +644,7 @@ private void OnPreviewScanCompleted(object sender, EventArgs eventArgs)
644644
if (this.encodeCancelled)
645645
{
646646
this.GeneratingPreview = false;
647-
this.logger.Log("# Cancelled preview clip generation");
647+
this.logger.Log("Cancelled preview clip generation");
648648
return;
649649
}
650650

@@ -685,27 +685,27 @@ private void OnPreviewScanCompleted(object sender, EventArgs eventArgs)
685685

686686
if (this.encodeCancelled)
687687
{
688-
this.logger.Log("# Cancelled preview clip generation");
688+
this.logger.Log("Cancelled preview clip generation");
689689
}
690690
else
691691
{
692692
if (e.Error)
693693
{
694-
this.logger.Log("# Preview clip generation failed");
694+
this.logger.Log("Preview clip generation failed");
695695
Utilities.MessageBox.Show("Preview clip generation failed. See the Log window for details.");
696696
}
697697
else
698698
{
699-
this.logger.Log("# Finished preview clip generation");
699+
this.logger.Log("Finished preview clip generation");
700700
FileService.Instance.LaunchFile(previewFilePath);
701701
}
702702
}
703703
};
704704

705-
this.logger.Log("## Encoding clip");
706-
this.logger.Log("## Path: " + this.job.OutputPath);
707-
this.logger.Log("## Title: " + this.job.Title);
708-
this.logger.Log("## Preview #: " + this.SelectedPreview);
705+
this.logger.Log("Encoding clip");
706+
this.logger.Log(" Path: " + this.job.OutputPath);
707+
this.logger.Log(" Title: " + this.job.Title);
708+
this.logger.Log(" Preview #: " + this.SelectedPreview);
709709

710710
this.previewInstance.StartEncode(this.job, true, this.SelectedPreview, this.PreviewSeconds);
711711
}

0 commit comments

Comments
 (0)