Skip to content

Commit 36a6c94

Browse files
committed
Fixed an issue where scan failures on jobs added by the Watcher would stay marked as "Planned".
1 parent db5fea9 commit 36a6c94

4 files changed

Lines changed: 51 additions & 10 deletions

File tree

VidCoder/Services/HandBrakeProxy/RemoteScanProxy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public async void StartScan(string path, IAppLogger logger)
2222
await this.RunOperationAsync(worker => worker.StartScan(path));
2323
}
2424

25-
public void OnScanProgress(float fractionComplete)
26-
{
27-
this.ScanProgress?.Invoke(this, new EventArgs<float>(fractionComplete));
28-
}
25+
public void OnScanProgress(float fractionComplete)
26+
{
27+
this.ScanProgress?.Invoke(this, new EventArgs<float>(fractionComplete));
28+
}
2929

30-
public void OnScanComplete(string scanJson)
31-
{
32-
this.result = scanJson;
30+
public void OnScanComplete(string scanJson)
31+
{
32+
this.result = scanJson;
3333

3434
Task.Run(async () =>
3535
{
@@ -43,7 +43,7 @@ public void OnScanComplete(string scanJson)
4343
this.ProcessLock.Release();
4444
}
4545
});
46-
}
46+
}
4747

4848
protected override HandBrakeWorkerAction Action => HandBrakeWorkerAction.Scan;
4949

@@ -52,5 +52,5 @@ public void OnScanComplete(string scanJson)
5252
protected override void OnOperationEnd(VCEncodeResultCode result)
5353
{
5454
this.ScanCompleted?.Invoke(this, new EventArgs<string>(this.result));
55-
}
55+
}
5656
}

VidCoder/Services/QueueAdderService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class QueueAdderService : ReactiveObject
3939
private bool isCanceled = false;
4040
private bool startPending = false;
4141

42+
/// <summary>
43+
/// Fires when a scan failed because there are no titles.
44+
/// </summary>
45+
public event EventHandler<EventArgs<string>> ScanFailed;
46+
4247
public double Progress
4348
{
4449
get
@@ -136,9 +141,15 @@ private void EnsureScanProxyCreated()
136141
return;
137142
}
138143

144+
bool scanFoundTitle = true;
139145
if (args.Value != null)
140146
{
141147
JsonScanObject scanObject = JsonSerializer.Deserialize<JsonScanObject>(args.Value, JsonOptions.Plain);
148+
if (scanObject.TitleList.Count == 0)
149+
{
150+
scanFoundTitle = false;
151+
}
152+
142153
this.scanResults.Add(
143154
new ScanResult
144155
{
@@ -161,6 +172,13 @@ private void EnsureScanProxyCreated()
161172
{
162173
// Add to list of failed files, pop a dialog at the end
163174
this.failedFiles.Add(this.currentScan.SourcePath.Path);
175+
176+
scanFoundTitle = false;
177+
}
178+
179+
if (!scanFoundTitle)
180+
{
181+
this.ScanFailed.Invoke(this, new EventArgs<string>(this.currentScan.SourcePath.Path));
164182
}
165183

166184
this.scansCompletedThisSession++;

VidCoder/Services/WatchedFileStatusTracker.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ namespace VidCoder.Services;
1717
public class WatchedFileStatusTracker
1818
{
1919
private ProcessingService processingService;
20+
private QueueAdderService queueAdderService;
2021

2122
private IAppLogger logger = StaticResolver.Resolve<IAppLogger>();
2223

23-
public WatchedFileStatusTracker(ProcessingService processingService)
24+
public WatchedFileStatusTracker(ProcessingService processingService, QueueAdderService queueAdderService)
2425
{
2526
this.processingService = processingService;
27+
this.queueAdderService = queueAdderService;
2628
}
2729

2830
public void Start()
2931
{
3032
this.processingService.JobCompleted += this.OnJobCompleted;
3133
this.processingService.JobRemovedFromQueue += this.OnJobRemovedFromQueue;
3234
this.processingService.JobQueueSkipped += this.OnJobQueueSkipped;
35+
this.queueAdderService.ScanFailed += this.OnScanFailed;
3336

3437
SQLiteConnection connection = Database.Connection;
3538

@@ -86,4 +89,12 @@ private void OnJobQueueSkipped(object sender, EventArgs<string> e)
8689
e.Value,
8790
WatchedFileStatus.Skipped);
8891
}
92+
93+
private void OnScanFailed(object sender, EventArgs<string> e)
94+
{
95+
WatcherStorage.UpdateEntryStatus(
96+
Database.Connection,
97+
e.Value,
98+
WatchedFileStatus.Failed);
99+
}
89100
}

VidCoder/ViewModel/WatcherWindowViewModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class WatcherWindowViewModel : ReactiveObject, IClosableWindow
4141

4242
private PresetsService presetsService = StaticResolver.Resolve<PresetsService>();
4343
private ProcessingService processingService = StaticResolver.Resolve<ProcessingService>();
44+
private QueueAdderService queueAdderService = StaticResolver.Resolve<QueueAdderService>();
4445

4546
private readonly Dictionary<WatchedFileStatusLive, bool> statusFilters = new();
4647

@@ -338,6 +339,7 @@ public void CancelSelectedFiles()
338339

339340
private void SubscribeToJobEvents()
340341
{
342+
this.queueAdderService.ScanFailed += this.OnScanFailed;
341343
this.processingService.JobQueued += this.OnJobQueued;
342344
this.processingService.JobQueueSkipped += this.OnJobQueueSkipped;
343345
this.processingService.JobRemovedFromQueue += this.OnJobRemovedFromQueue;
@@ -349,6 +351,7 @@ private void SubscribeToJobEvents()
349351

350352
private void UnsubscribeFromJobEvents()
351353
{
354+
this.queueAdderService.ScanFailed -= this.OnScanFailed;
352355
this.processingService.JobQueued -= this.OnJobQueued;
353356
this.processingService.JobQueueSkipped -= this.OnJobQueueSkipped;
354357
this.processingService.JobRemovedFromQueue -= this.OnJobRemovedFromQueue;
@@ -358,6 +361,15 @@ private void UnsubscribeFromJobEvents()
358361
this.processingService.WatchedFilesRemoved -= this.OnWatchedFilesRemoved;
359362
}
360363

364+
private void OnScanFailed(object sender, EventArgs<string> e)
365+
{
366+
WatchedFileViewModel watchedFile = this.GetWatchedFileForSourcePath(e.Value);
367+
if (watchedFile != null)
368+
{
369+
watchedFile.Status = WatchedFileStatusLive.Failed;
370+
}
371+
}
372+
361373
private void OnJobQueued(object sender, EventArgs<EncodeJobViewModel> e)
362374
{
363375
WatchedFileViewModel watchedFile = this.GetWatchedFileForJob(e.Value);

0 commit comments

Comments
 (0)