Merge pull request #7145 from Flitskikker/feature/btc-fix-20230723

Add more null and count checks
This commit is contained in:
Nikolaj Olsson 2023-07-23 09:54:28 -04:00 committed by GitHub
commit b1eb3c6bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -11,7 +11,6 @@ namespace Nikse.SubtitleEdit.Core.Common
{
public static class ShotChangeHelper
{
private static string GetShotChangesFileName(string videoFileName)
{
var dir = Configuration.ShotChangesDirectory.TrimEnd(Path.DirectorySeparatorChar);
@ -89,6 +88,11 @@ namespace Nikse.SubtitleEdit.Core.Common
public static double? GetPreviousShotChange(List<double> shotChanges, TimeCode currentTime)
{
if (shotChanges == null || shotChanges.Count == 0)
{
return null;
}
try
{
return shotChanges.Last(x => SubtitleFormat.MillisecondsToFrames(x * 1000) <= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds));
@ -123,6 +127,11 @@ namespace Nikse.SubtitleEdit.Core.Common
public static double? GetNextShotChange(List<double> shotChanges, TimeCode currentTime)
{
if (shotChanges == null || shotChanges.Count == 0)
{
return null;
}
try
{
return shotChanges.First(x => SubtitleFormat.MillisecondsToFrames(x * 1000) >= SubtitleFormat.MillisecondsToFrames(currentTime.TotalMilliseconds));

View File

@ -815,6 +815,11 @@ namespace Nikse.SubtitleEdit.Core.Forms
private int? GetFirstShotChangeFrameInBetween(int leftCueFrame, int rightCueFrame)
{
if (_shotChangesFrames == null || _shotChangesFrames.Count == 0)
{
return null;
}
try
{
return _shotChangesFrames.First(x => x >= leftCueFrame && x <= rightCueFrame);
@ -827,6 +832,11 @@ namespace Nikse.SubtitleEdit.Core.Forms
private int? GetClosestShotChangeFrame(int cueFrame)
{
if (_shotChangesFrames == null || _shotChangesFrames.Count == 0)
{
return null;
}
try
{
return _shotChangesFrames.Aggregate((x, y) => Math.Abs(x - cueFrame) < Math.Abs(y - cueFrame) ? x : y);