mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add zero byte check and tests
This commit is contained in:
41
osu.Game/Rulesets/Edit/Checks/CheckZeroByteFiles.cs
Normal file
41
osu.Game/Rulesets/Edit/Checks/CheckZeroByteFiles.cs
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
public class CheckZeroByteFiles : ICheck
|
||||
{
|
||||
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Files, "Zero-byte files");
|
||||
|
||||
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
||||
{
|
||||
new IssueTemplateZeroBytes(this)
|
||||
};
|
||||
|
||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||
{
|
||||
var beatmapSet = context.Beatmap.BeatmapInfo.BeatmapSet;
|
||||
|
||||
foreach (var file in beatmapSet.Files)
|
||||
{
|
||||
Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
|
||||
if (data?.Length == 0)
|
||||
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
|
||||
}
|
||||
}
|
||||
|
||||
public class IssueTemplateZeroBytes : IssueTemplate
|
||||
{
|
||||
public IssueTemplateZeroBytes(ICheck check)
|
||||
: base(check, IssueType.Problem, "\"{0}\" is a 0-byte file.")
|
||||
{
|
||||
}
|
||||
|
||||
public Issue Create(string filename) => new Issue(this, filename);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user