2021-07-13 09:45:21 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-13 09:45:21 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
2021-11-19 15:07:55 +08:00
|
|
|
using osu.Game.Extensions;
|
2021-07-13 09:45:21 +08:00
|
|
|
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;
|
|
|
|
|
2022-01-12 21:34:07 +08:00
|
|
|
if (beatmapSet != null)
|
2021-07-13 09:45:21 +08:00
|
|
|
{
|
2022-01-12 21:34:07 +08:00
|
|
|
foreach (var file in beatmapSet.Files)
|
2021-10-12 09:46:26 +08:00
|
|
|
{
|
2022-01-12 21:34:07 +08:00
|
|
|
using (Stream data = context.WorkingBeatmap.GetStream(file.File.GetStoragePath()))
|
|
|
|
{
|
|
|
|
if (data?.Length == 0)
|
|
|
|
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
|
|
|
|
}
|
2021-10-12 09:46:26 +08:00
|
|
|
}
|
2021-07-13 09:45:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|