Only check each video file once

This commit is contained in:
Naxesss 2021-10-11 13:55:50 +02:00
parent 6aa054b5fa
commit f0cd18a721
1 changed files with 25 additions and 18 deletions

View File

@ -24,6 +24,7 @@ public class CheckAudioInVideo : ICheck
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var beatmapSet = context.Beatmap.BeatmapInfo.BeatmapSet;
var videoPaths = new List<string>();
foreach (var layer in context.WorkingBeatmap.Storyboard.Layers)
{
@ -32,26 +33,32 @@ public IEnumerable<Issue> Run(BeatmapVerifierContext context)
if (!(element is StoryboardVideo video))
continue;
string filename = video.Path;
string storagePath = beatmapSet.GetPathForFile(filename);
if (storagePath == null)
{
// There's an element in the storyboard that requires this resource, so it being missing is worth warning about.
yield return new IssueTemplateMissingFile(this).Create(filename);
continue;
}
Stream data = context.WorkingBeatmap.GetStream(storagePath);
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode, fileCallbacks.Callbacks, fileCallbacks.Handle);
if (decodeStream == 0)
continue;
yield return new IssueTemplateHasAudioTrack(this).Create(filename);
// Ensures we don't check the same video file multiple times in case of multiple elements using it.
if (!videoPaths.Contains(video.Path))
videoPaths.Add(video.Path);
}
}
foreach (var filename in videoPaths)
{
string storagePath = beatmapSet.GetPathForFile(filename);
if (storagePath == null)
{
// There's an element in the storyboard that requires this resource, so it being missing is worth warning about.
yield return new IssueTemplateMissingFile(this).Create(filename);
continue;
}
Stream data = context.WorkingBeatmap.GetStream(storagePath);
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode, fileCallbacks.Callbacks, fileCallbacks.Handle);
if (decodeStream == 0)
continue;
yield return new IssueTemplateHasAudioTrack(this).Create(filename);
}
}
public class IssueTemplateHasAudioTrack : IssueTemplate