2021-04-10 11:03:16 +00: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
|
|
|
|
{
|
2021-04-18 00:07:33 +00:00
|
|
|
public abstract class CheckFilePresence : ICheck
|
2021-04-10 11:03:16 +00:00
|
|
|
{
|
2021-04-18 00:07:33 +00:00
|
|
|
protected abstract CheckCategory Category { get; }
|
|
|
|
protected abstract string TypeOfFile { get; }
|
2021-05-12 00:34:16 +00:00
|
|
|
protected abstract string GetFilename(IBeatmap beatmap);
|
2021-04-18 00:07:33 +00:00
|
|
|
|
|
|
|
public CheckMetadata Metadata => new CheckMetadata(Category, $"Missing {TypeOfFile}");
|
2021-04-10 11:03:16 +00:00
|
|
|
|
2021-04-12 15:12:37 +00:00
|
|
|
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
|
|
|
{
|
|
|
|
new IssueTemplateNoneSet(this),
|
|
|
|
new IssueTemplateDoesNotExist(this)
|
|
|
|
};
|
2021-04-12 13:47:26 +00:00
|
|
|
|
2021-05-13 09:24:22 +00:00
|
|
|
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
2021-04-10 11:03:16 +00:00
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
string filename = GetFilename(context.Beatmap);
|
2021-04-17 23:19:25 +00:00
|
|
|
|
2021-11-04 06:18:10 +00:00
|
|
|
if (string.IsNullOrEmpty(filename))
|
2021-04-10 11:03:16 +00:00
|
|
|
{
|
2021-04-18 00:07:33 +00:00
|
|
|
yield return new IssueTemplateNoneSet(this).Create(TypeOfFile);
|
2021-04-10 11:03:16 +00:00
|
|
|
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
2021-04-18 00:07:33 +00:00
|
|
|
// If the file is set, also make sure it still exists.
|
2022-10-30 08:28:49 +00:00
|
|
|
string? storagePath = context.Beatmap.BeatmapInfo.BeatmapSet?.GetPathForFile(filename);
|
2021-04-17 23:19:25 +00:00
|
|
|
if (storagePath != null)
|
2021-04-10 11:03:16 +00:00
|
|
|
yield break;
|
|
|
|
|
2021-04-18 00:07:33 +00:00
|
|
|
yield return new IssueTemplateDoesNotExist(this).Create(TypeOfFile, filename);
|
2021-04-10 11:03:16 +00:00
|
|
|
}
|
2021-04-12 14:36:10 +00:00
|
|
|
|
2021-04-13 00:29:25 +00:00
|
|
|
public class IssueTemplateNoneSet : IssueTemplate
|
2021-04-12 14:36:10 +00:00
|
|
|
{
|
2021-04-12 15:28:12 +00:00
|
|
|
public IssueTemplateNoneSet(ICheck check)
|
2021-04-18 00:07:33 +00:00
|
|
|
: base(check, IssueType.Problem, "No {0} has been set.")
|
2021-04-12 14:36:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-18 00:07:33 +00:00
|
|
|
public Issue Create(string typeOfFile) => new Issue(this, typeOfFile);
|
2021-04-12 14:36:10 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 00:29:25 +00:00
|
|
|
public class IssueTemplateDoesNotExist : IssueTemplate
|
2021-04-12 14:36:10 +00:00
|
|
|
{
|
2021-04-12 15:28:12 +00:00
|
|
|
public IssueTemplateDoesNotExist(ICheck check)
|
2021-04-18 00:07:33 +00:00
|
|
|
: base(check, IssueType.Problem, "The {0} file \"{1}\" does not exist.")
|
2021-04-12 14:36:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-18 00:07:33 +00:00
|
|
|
public Issue Create(string typeOfFile, string filename) => new Issue(this, typeOfFile, filename);
|
2021-04-12 14:36:10 +00:00
|
|
|
}
|
2021-04-10 11:03:16 +00:00
|
|
|
}
|
|
|
|
}
|