1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 12:37:29 +08:00
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckFilePresence.cs
Naxess c13b93e6f1 Replace IWorkingBeatmap arg with BeatmapVerifierContext in checks
This simplifies passing of contextual information by enabling addition without needing to refactor lots of classes.

See next commit for example.
2021-05-12 02:29:18 +02:00

64 lines
2.2 KiB
C#

// 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 osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public abstract class CheckFilePresence : ICheck
{
protected abstract CheckCategory Category { get; }
protected abstract string TypeOfFile { get; }
protected abstract string GetFilename(IBeatmap playableBeatmap);
public CheckMetadata Metadata => new CheckMetadata(Category, $"Missing {TypeOfFile}");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateNoneSet(this),
new IssueTemplateDoesNotExist(this)
};
public IEnumerable<Issue> Run(IBeatmap playableBeatmap, BeatmapVerifierContext context)
{
var filename = GetFilename(playableBeatmap);
if (filename == null)
{
yield return new IssueTemplateNoneSet(this).Create(TypeOfFile);
yield break;
}
// If the file is set, also make sure it still exists.
var storagePath = playableBeatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
if (storagePath != null)
yield break;
yield return new IssueTemplateDoesNotExist(this).Create(TypeOfFile, filename);
}
public class IssueTemplateNoneSet : IssueTemplate
{
public IssueTemplateNoneSet(ICheck check)
: base(check, IssueType.Problem, "No {0} has been set.")
{
}
public Issue Create(string typeOfFile) => new Issue(this, typeOfFile);
}
public class IssueTemplateDoesNotExist : IssueTemplate
{
public IssueTemplateDoesNotExist(ICheck check)
: base(check, IssueType.Problem, "The {0} file \"{1}\" does not exist.")
{
}
public Issue Create(string typeOfFile, string filename) => new Issue(this, typeOfFile, filename);
}
}
}