1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 10:47:24 +08:00
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckFilePresence.cs

64 lines
2.2 KiB
C#
Raw Normal View History

2021-04-10 19:03:16 +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.
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
2021-04-10 19:03:16 +08:00
{
protected abstract CheckCategory Category { get; }
protected abstract string TypeOfFile { get; }
protected abstract string GetFilename(IWorkingBeatmap workingBeatmap);
public CheckMetadata Metadata => new CheckMetadata(Category, $"Missing {TypeOfFile}");
2021-04-10 19:03:16 +08:00
2021-04-12 23:12:37 +08:00
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateNoneSet(this),
new IssueTemplateDoesNotExist(this)
};
public IEnumerable<Issue> Run(IBeatmap playableBeatmap, IWorkingBeatmap workingBeatmap)
2021-04-10 19:03:16 +08:00
{
var filename = GetFilename(workingBeatmap);
if (filename == null)
2021-04-10 19:03:16 +08:00
{
yield return new IssueTemplateNoneSet(this).Create(TypeOfFile);
2021-04-10 19:03:16 +08:00
yield break;
}
// If the file is set, also make sure it still exists.
var storagePath = playableBeatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
if (storagePath != null)
2021-04-10 19:03:16 +08:00
yield break;
yield return new IssueTemplateDoesNotExist(this).Create(TypeOfFile, filename);
2021-04-10 19:03:16 +08:00
}
2021-04-12 22:36:10 +08:00
public class IssueTemplateNoneSet : IssueTemplate
2021-04-12 22:36:10 +08:00
{
public IssueTemplateNoneSet(ICheck check)
: base(check, IssueType.Problem, "No {0} has been set.")
2021-04-12 22:36:10 +08:00
{
}
public Issue Create(string typeOfFile) => new Issue(this, typeOfFile);
2021-04-12 22:36:10 +08:00
}
public class IssueTemplateDoesNotExist : IssueTemplate
2021-04-12 22:36:10 +08:00
{
public IssueTemplateDoesNotExist(ICheck check)
: base(check, IssueType.Problem, "The {0} file \"{1}\" does not exist.")
2021-04-12 22:36:10 +08:00
{
}
public Issue Create(string typeOfFile, string filename) => new Issue(this, typeOfFile, filename);
2021-04-12 22:36:10 +08:00
}
2021-04-10 19:03:16 +08:00
}
}