Consolidate remaining methods in BeatmapModelManager

This commit is contained in:
Dean Herbert 2022-06-16 17:57:04 +09:00
parent 953ca8c2dd
commit 4c372539a1

View File

@ -29,10 +29,6 @@ namespace osu.Game.Beatmaps
/// </summary>
public IWorkingBeatmapCache? WorkingBeatmapCache { private get; set; }
public override IEnumerable<string> HandledExtensions => new[] { ".osz" };
protected override string[] HashableFileTypes => new[] { ".osu" };
public static readonly string[] VIDEO_EXTENSIONS = { ".mp4", ".mov", ".avi", ".flv" };
public BeatmapModelManager(RealmAccess realm, Storage storage, BeatmapOnlineLookupQueue? onlineLookupQueue = null)
@ -71,7 +67,7 @@ namespace osu.Game.Beatmaps
// AddFile generally handles updating/replacing files, but this is a case where the filename may have also changed so let's delete for simplicity.
var existingFileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase));
string targetFilename = getFilename(beatmapInfo);
string targetFilename = createBeatmapFilenameFromMetadata(beatmapInfo);
// ensure that two difficulties from the set don't point at the same beatmap file.
if (setInfo.Beatmaps.Any(b => b.ID != beatmapInfo.ID && string.Equals(b.Path, targetFilename, StringComparison.OrdinalIgnoreCase)))
@ -83,18 +79,19 @@ namespace osu.Game.Beatmaps
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
beatmapInfo.Hash = stream.ComputeSHA2Hash();
AddFile(setInfo, stream, getFilename(beatmapInfo));
Update(setInfo);
AddFile(setInfo, stream, createBeatmapFilenameFromMetadata(beatmapInfo));
Realm.Write(r => setInfo.CopyChangesToRealm(r.Find<BeatmapSetInfo>(setInfo.ID)));
}
WorkingBeatmapCache?.Invalidate(beatmapInfo);
}
private static string getFilename(BeatmapInfo beatmapInfo)
static string createBeatmapFilenameFromMetadata(BeatmapInfo beatmapInfo)
{
var metadata = beatmapInfo.Metadata;
return $"{metadata.Artist} - {metadata.Title} ({metadata.Author.Username}) [{beatmapInfo.DifficultyName}].osu".GetValidArchiveContentFilename();
}
}
/// <summary>
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
@ -106,15 +103,6 @@ namespace osu.Game.Beatmaps
return Realm.Run(realm => realm.All<BeatmapInfo>().FirstOrDefault(query)?.Detach());
}
public void Update(BeatmapSetInfo item)
{
Realm.Write(r =>
{
var existing = r.Find<BeatmapSetInfo>(item.ID);
item.CopyChangesToRealm(existing);
});
}
/// <summary>
/// Delete videos from a list of beatmaps.
/// This will post notifications tracking progress.