diff --git a/osu.Game.Tests/Editing/Checks/CheckAudioInVideoTest.cs b/osu.Game.Tests/Editing/Checks/CheckAudioInVideoTest.cs index f3a4f10210..f9b7bfa586 100644 --- a/osu.Game.Tests/Editing/Checks/CheckAudioInVideoTest.cs +++ b/osu.Game.Tests/Editing/Checks/CheckAudioInVideoTest.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.IO; using System.Linq; using Moq; @@ -13,7 +12,6 @@ using osu.Game.Rulesets.Objects; using osu.Game.Storyboards; using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Resources; -using FileInfo = osu.Game.IO.FileInfo; namespace osu.Game.Tests.Editing.Checks { @@ -33,14 +31,10 @@ namespace osu.Game.Tests.Editing.Checks { BeatmapSet = new BeatmapSetInfo { - Files = new List(new[] + Files = { - new BeatmapSetFileInfo - { - Filename = "abc123.mp4", - FileInfo = new FileInfo { Hash = "abcdef" } - } - }) + CheckTestHelpers.CreateMockFile("mp4"), + } } } }; diff --git a/osu.Game.Tests/Editing/Checks/CheckBackgroundQualityTest.cs b/osu.Game.Tests/Editing/Checks/CheckBackgroundQualityTest.cs index 05bfae7e63..bb560054a3 100644 --- a/osu.Game.Tests/Editing/Checks/CheckBackgroundQualityTest.cs +++ b/osu.Game.Tests/Editing/Checks/CheckBackgroundQualityTest.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; +using System; using System.IO; using System.Linq; using JetBrains.Annotations; @@ -12,7 +12,6 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Checks; using osu.Game.Rulesets.Objects; -using FileInfo = osu.Game.IO.FileInfo; namespace osu.Game.Tests.Editing.Checks { @@ -25,25 +24,17 @@ namespace osu.Game.Tests.Editing.Checks [SetUp] public void Setup() { + var file = CheckTestHelpers.CreateMockFile("jpg"); + check = new CheckBackgroundQuality(); beatmap = new Beatmap { BeatmapInfo = new BeatmapInfo { - Metadata = new BeatmapMetadata { BackgroundFile = "abc123.jpg" }, + Metadata = new BeatmapMetadata { BackgroundFile = file.Filename }, BeatmapSet = new BeatmapSetInfo { - Files = new List(new[] - { - new BeatmapSetFileInfo - { - Filename = "abc123.jpg", - FileInfo = new FileInfo - { - Hash = "abcdef" - } - } - }) + Files = { file } } } }; @@ -54,7 +45,7 @@ namespace osu.Game.Tests.Editing.Checks { // While this is a problem, it is out of scope for this check and is caught by a different one. beatmap.Metadata.BackgroundFile = string.Empty; - var context = getContext(null, new MemoryStream(System.Array.Empty())); + var context = getContext(null, new MemoryStream(Array.Empty())); Assert.That(check.Run(context), Is.Empty); } diff --git a/osu.Game.Tests/Editing/Checks/CheckFilePresenceTest.cs b/osu.Game.Tests/Editing/Checks/CheckFilePresenceTest.cs index 70e4c76b19..f36454aa71 100644 --- a/osu.Game.Tests/Editing/Checks/CheckFilePresenceTest.cs +++ b/osu.Game.Tests/Editing/Checks/CheckFilePresenceTest.cs @@ -1,11 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Game.Beatmaps; -using osu.Game.IO; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Checks; using osu.Game.Rulesets.Objects; @@ -22,22 +20,17 @@ namespace osu.Game.Tests.Editing.Checks [SetUp] public void Setup() { + var file = CheckTestHelpers.CreateMockFile("jpg"); + check = new CheckBackgroundPresence(); beatmap = new Beatmap { BeatmapInfo = new BeatmapInfo { - Metadata = new BeatmapMetadata { BackgroundFile = "abc123.jpg" }, + Metadata = new BeatmapMetadata { BackgroundFile = file.Filename }, BeatmapSet = new BeatmapSetInfo { - Files = new List(new[] - { - new BeatmapSetFileInfo - { - Filename = "abc123.jpg", - FileInfo = new FileInfo { Hash = "abcdef" } - } - }) + Files = { file } } } }; diff --git a/osu.Game.Tests/Editing/Checks/CheckTestHelpers.cs b/osu.Game.Tests/Editing/Checks/CheckTestHelpers.cs new file mode 100644 index 0000000000..f702921986 --- /dev/null +++ b/osu.Game.Tests/Editing/Checks/CheckTestHelpers.cs @@ -0,0 +1,18 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Beatmaps; +using osu.Game.IO; + +namespace osu.Game.Tests.Editing.Checks +{ + public static class CheckTestHelpers + { + public static BeatmapSetFileInfo CreateMockFile(string extension) => + new BeatmapSetFileInfo + { + Filename = $"abc123.{extension}", + FileInfo = new FileInfo { Hash = "abcdef" } + }; + } +} diff --git a/osu.Game.Tests/Editing/Checks/CheckTooShortAudioFilesTest.cs b/osu.Game.Tests/Editing/Checks/CheckTooShortAudioFilesTest.cs index 9b090591bc..8adf0d3764 100644 --- a/osu.Game.Tests/Editing/Checks/CheckTooShortAudioFilesTest.cs +++ b/osu.Game.Tests/Editing/Checks/CheckTooShortAudioFilesTest.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.IO; using System.Linq; using ManagedBass; @@ -14,7 +13,6 @@ using osu.Game.Rulesets.Objects; using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Resources; using osuTK.Audio; -using FileInfo = osu.Game.IO.FileInfo; namespace osu.Game.Tests.Editing.Checks { @@ -34,14 +32,7 @@ namespace osu.Game.Tests.Editing.Checks { BeatmapSet = new BeatmapSetInfo { - Files = new List(new[] - { - new BeatmapSetFileInfo - { - Filename = "abc123.wav", - FileInfo = new FileInfo { Hash = "abcdef" } - } - }) + Files = { CheckTestHelpers.CreateMockFile("wav") } } } }; @@ -55,11 +46,7 @@ namespace osu.Game.Tests.Editing.Checks public void TestDifferentExtension() { beatmap.BeatmapInfo.BeatmapSet.Files.Clear(); - beatmap.BeatmapInfo.BeatmapSet.Files.Add(new BeatmapSetFileInfo - { - Filename = "abc123.jpg", - FileInfo = new FileInfo { Hash = "abcdef" } - }); + beatmap.BeatmapInfo.BeatmapSet.Files.Add(CheckTestHelpers.CreateMockFile("jpg")); // Should fail to load, but not produce an error due to the extension not being expected to load. Assert.IsEmpty(check.Run(getContext(null, allowMissing: true))); diff --git a/osu.Game.Tests/Editing/Checks/CheckZeroByteFilesTest.cs b/osu.Game.Tests/Editing/Checks/CheckZeroByteFilesTest.cs index c9adc030c1..79d00e6a60 100644 --- a/osu.Game.Tests/Editing/Checks/CheckZeroByteFilesTest.cs +++ b/osu.Game.Tests/Editing/Checks/CheckZeroByteFilesTest.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.IO; using System.Linq; using Moq; @@ -10,7 +9,6 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Checks; using osu.Game.Rulesets.Objects; -using FileInfo = osu.Game.IO.FileInfo; namespace osu.Game.Tests.Editing.Checks { @@ -30,14 +28,10 @@ namespace osu.Game.Tests.Editing.Checks { BeatmapSet = new BeatmapSetInfo { - Files = new List(new[] + Files = { - new BeatmapSetFileInfo - { - Filename = "abc123.jpg", - FileInfo = new FileInfo { Hash = "abcdef" } - } - }) + CheckTestHelpers.CreateMockFile("jpg"), + } } } }; diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 5bb9eefc6e..a4d60d7ea0 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -36,8 +36,7 @@ namespace osu.Game.Beatmaps public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None; - [NotNull] - public List Files { get; set; } = new List(); + public List Files { get; } = new List(); /// /// The maximum star difficulty of all beatmaps in this set. diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index a0e8105285..adbb71c8da 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -392,7 +392,8 @@ namespace osu.Game.Database { LogForModel(item, @"Beginning import..."); - item.Files = archive != null ? createFileInfos(archive, Files) : new List(); + if (archive != null) + item.Files.AddRange(createFileInfos(archive, Files)); item.Hash = ComputeHash(item); await Populate(item, archive, cancellationToken).ConfigureAwait(false); diff --git a/osu.Game/Database/IHasFiles.cs b/osu.Game/Database/IHasFiles.cs index f6aa941ec2..3f6531832f 100644 --- a/osu.Game/Database/IHasFiles.cs +++ b/osu.Game/Database/IHasFiles.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using JetBrains.Annotations; namespace osu.Game.Database { @@ -12,7 +13,8 @@ namespace osu.Game.Database public interface IHasFiles where TFile : INamedFileInfo { - List Files { get; set; } + [NotNull] + List Files { get; } string Hash { get; set; } } diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index d0ca2f0fd4..738ecaea7c 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -42,8 +42,9 @@ namespace osu.Game.Database /// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser. /// 10 2021-11-22 Use ShortName instead of RulesetID for ruleset settings. /// 11 2021-11-22 Use ShortName instead of RulesetID for ruleset key bindings. + /// 12 2021-11-24 Add Status to RealmBeatmapSet. /// - private const int schema_version = 11; + private const int schema_version = 12; /// /// Lock object which is held during sections, blocking context creation during blocking periods. diff --git a/osu.Game/Models/RealmBeatmap.cs b/osu.Game/Models/RealmBeatmap.cs index 005a7ac2a8..8e132687f7 100644 --- a/osu.Game/Models/RealmBeatmap.cs +++ b/osu.Game/Models/RealmBeatmap.cs @@ -46,7 +46,7 @@ namespace osu.Game.Models } [MapTo(nameof(Status))] - public int StatusInt { get; set; } + public int StatusInt { get; set; } = (int)BeatmapOnlineStatus.None; [Indexed] public int OnlineID { get; set; } = -1; diff --git a/osu.Game/Models/RealmBeatmapSet.cs b/osu.Game/Models/RealmBeatmapSet.cs index ff39bcf13e..fee59633f1 100644 --- a/osu.Game/Models/RealmBeatmapSet.cs +++ b/osu.Game/Models/RealmBeatmapSet.cs @@ -32,6 +32,15 @@ namespace osu.Game.Models public IList Files { get; } = null!; + public BeatmapOnlineStatus Status + { + get => (BeatmapOnlineStatus)StatusInt; + set => StatusInt = (int)value; + } + + [MapTo(nameof(Status))] + public int StatusInt { get; set; } = (int)BeatmapOnlineStatus.None; + public bool DeletePending { get; set; } public string Hash { get; set; } = string.Empty; diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 26749a23f9..f0c57cb953 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -394,7 +394,7 @@ namespace osu.Game.Online.Leaderboards if (Score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null) items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = Score.Mods)); - if (Score.Files?.Count > 0) + if (Score.Files.Count > 0) items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => scoreManager.Export(Score))); if (Score.ID != 0) diff --git a/osu.Game/Scoring/ScoreInfo.cs b/osu.Game/Scoring/ScoreInfo.cs index 736a939a59..b4e194cbed 100644 --- a/osu.Game/Scoring/ScoreInfo.cs +++ b/osu.Game/Scoring/ScoreInfo.cs @@ -160,7 +160,7 @@ namespace osu.Game.Scoring [NotMapped] public List HitEvents { get; set; } - public List Files { get; set; } + public List Files { get; } = new List(); public string Hash { get; set; } diff --git a/osu.Game/Skinning/LegacySkinResourceStore.cs b/osu.Game/Skinning/LegacySkinResourceStore.cs index 096b467867..c4418baeff 100644 --- a/osu.Game/Skinning/LegacySkinResourceStore.cs +++ b/osu.Game/Skinning/LegacySkinResourceStore.cs @@ -24,9 +24,6 @@ namespace osu.Game.Skinning protected override IEnumerable GetFilenames(string name) { - if (source.Files == null) - yield break; - foreach (string filename in base.GetFilenames(name)) { string path = getPathForFile(filename.ToStandardisedPath()); diff --git a/osu.Game/Skinning/Skin.cs b/osu.Game/Skinning/Skin.cs index fae1a599d1..10526b69af 100644 --- a/osu.Game/Skinning/Skin.cs +++ b/osu.Game/Skinning/Skin.cs @@ -59,7 +59,7 @@ namespace osu.Game.Skinning string filename = $"{skinnableTarget}.json"; // skininfo files may be null for default skin. - var fileInfo = SkinInfo.Files?.FirstOrDefault(f => f.Filename == filename); + var fileInfo = SkinInfo.Files.FirstOrDefault(f => f.Filename == filename); if (fileInfo == null) continue; diff --git a/osu.Game/Skinning/SkinInfo.cs b/osu.Game/Skinning/SkinInfo.cs index 3b34e23d57..4733e8cdd9 100644 --- a/osu.Game/Skinning/SkinInfo.cs +++ b/osu.Game/Skinning/SkinInfo.cs @@ -36,7 +36,7 @@ namespace osu.Game.Skinning return (Skin)Activator.CreateInstance(type, this, resources); } - public List Files { get; set; } = new List(); + public List Files { get; } = new List(); public bool DeletePending { get; set; } diff --git a/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs b/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs index adb447c927..9d92f5c5fc 100644 --- a/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs +++ b/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs @@ -87,23 +87,19 @@ namespace osu.Game.Tests.Beatmaps { AddStep("setup skins", () => { - userSkinInfo.Files = new List + userSkinInfo.Files.Clear(); + userSkinInfo.Files.Add(new SkinFileInfo { - new SkinFileInfo - { - Filename = userFile, - FileInfo = new IO.FileInfo { Hash = userFile } - } - }; + Filename = userFile, + FileInfo = new IO.FileInfo { Hash = userFile } + }); - beatmapInfo.BeatmapSet.Files = new List + beatmapInfo.BeatmapSet.Files.Clear(); + beatmapInfo.BeatmapSet.Files.Add(new BeatmapSetFileInfo { - new BeatmapSetFileInfo - { - Filename = beatmapFile, - FileInfo = new IO.FileInfo { Hash = beatmapFile } - } - }; + Filename = beatmapFile, + FileInfo = new IO.FileInfo { Hash = beatmapFile } + }); // Need to refresh the cached skin source to refresh the skin resource store. dependencies.SkinSource = new SkinProvidingContainer(Skin = new LegacySkin(userSkinInfo, this));