mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Merge pull request #15773 from peppy/remove-model-file-list-inits
Initialise `IHasFiles<TFile>.Files` lists at construction time
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Moq;
|
using Moq;
|
||||||
@ -13,7 +12,6 @@ using osu.Game.Rulesets.Objects;
|
|||||||
using osu.Game.Storyboards;
|
using osu.Game.Storyboards;
|
||||||
using osu.Game.Tests.Beatmaps;
|
using osu.Game.Tests.Beatmaps;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
using FileInfo = osu.Game.IO.FileInfo;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Editing.Checks
|
namespace osu.Game.Tests.Editing.Checks
|
||||||
{
|
{
|
||||||
@ -33,14 +31,10 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
{
|
{
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
Files = new List<BeatmapSetFileInfo>(new[]
|
Files =
|
||||||
{
|
{
|
||||||
new BeatmapSetFileInfo
|
CheckTestHelpers.CreateMockFile("mp4"),
|
||||||
{
|
}
|
||||||
Filename = "abc123.mp4",
|
|
||||||
FileInfo = new FileInfo { Hash = "abcdef" }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@ -12,7 +12,6 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Edit.Checks;
|
using osu.Game.Rulesets.Edit.Checks;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using FileInfo = osu.Game.IO.FileInfo;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Editing.Checks
|
namespace osu.Game.Tests.Editing.Checks
|
||||||
{
|
{
|
||||||
@ -25,25 +24,17 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
var file = CheckTestHelpers.CreateMockFile("jpg");
|
||||||
|
|
||||||
check = new CheckBackgroundQuality();
|
check = new CheckBackgroundQuality();
|
||||||
beatmap = new Beatmap<HitObject>
|
beatmap = new Beatmap<HitObject>
|
||||||
{
|
{
|
||||||
BeatmapInfo = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metadata = new BeatmapMetadata { BackgroundFile = "abc123.jpg" },
|
Metadata = new BeatmapMetadata { BackgroundFile = file.Filename },
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
Files = new List<BeatmapSetFileInfo>(new[]
|
Files = { file }
|
||||||
{
|
|
||||||
new BeatmapSetFileInfo
|
|
||||||
{
|
|
||||||
Filename = "abc123.jpg",
|
|
||||||
FileInfo = new FileInfo
|
|
||||||
{
|
|
||||||
Hash = "abcdef"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -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.
|
// 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;
|
beatmap.Metadata.BackgroundFile = string.Empty;
|
||||||
var context = getContext(null, new MemoryStream(System.Array.Empty<byte>()));
|
var context = getContext(null, new MemoryStream(Array.Empty<byte>()));
|
||||||
|
|
||||||
Assert.That(check.Run(context), Is.Empty);
|
Assert.That(check.Run(context), Is.Empty);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.IO;
|
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Edit.Checks;
|
using osu.Game.Rulesets.Edit.Checks;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -22,22 +20,17 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
var file = CheckTestHelpers.CreateMockFile("jpg");
|
||||||
|
|
||||||
check = new CheckBackgroundPresence();
|
check = new CheckBackgroundPresence();
|
||||||
beatmap = new Beatmap<HitObject>
|
beatmap = new Beatmap<HitObject>
|
||||||
{
|
{
|
||||||
BeatmapInfo = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metadata = new BeatmapMetadata { BackgroundFile = "abc123.jpg" },
|
Metadata = new BeatmapMetadata { BackgroundFile = file.Filename },
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
Files = new List<BeatmapSetFileInfo>(new[]
|
Files = { file }
|
||||||
{
|
|
||||||
new BeatmapSetFileInfo
|
|
||||||
{
|
|
||||||
Filename = "abc123.jpg",
|
|
||||||
FileInfo = new FileInfo { Hash = "abcdef" }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
18
osu.Game.Tests/Editing/Checks/CheckTestHelpers.cs
Normal file
18
osu.Game.Tests/Editing/Checks/CheckTestHelpers.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// 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 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" }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ManagedBass;
|
using ManagedBass;
|
||||||
@ -14,7 +13,6 @@ using osu.Game.Rulesets.Objects;
|
|||||||
using osu.Game.Tests.Beatmaps;
|
using osu.Game.Tests.Beatmaps;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
using osuTK.Audio;
|
using osuTK.Audio;
|
||||||
using FileInfo = osu.Game.IO.FileInfo;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Editing.Checks
|
namespace osu.Game.Tests.Editing.Checks
|
||||||
{
|
{
|
||||||
@ -34,14 +32,7 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
{
|
{
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
Files = new List<BeatmapSetFileInfo>(new[]
|
Files = { CheckTestHelpers.CreateMockFile("wav") }
|
||||||
{
|
|
||||||
new BeatmapSetFileInfo
|
|
||||||
{
|
|
||||||
Filename = "abc123.wav",
|
|
||||||
FileInfo = new FileInfo { Hash = "abcdef" }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -55,11 +46,7 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
public void TestDifferentExtension()
|
public void TestDifferentExtension()
|
||||||
{
|
{
|
||||||
beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
|
beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
|
||||||
beatmap.BeatmapInfo.BeatmapSet.Files.Add(new BeatmapSetFileInfo
|
beatmap.BeatmapInfo.BeatmapSet.Files.Add(CheckTestHelpers.CreateMockFile("jpg"));
|
||||||
{
|
|
||||||
Filename = "abc123.jpg",
|
|
||||||
FileInfo = new FileInfo { Hash = "abcdef" }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should fail to load, but not produce an error due to the extension not being expected to load.
|
// 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)));
|
Assert.IsEmpty(check.Run(getContext(null, allowMissing: true)));
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Moq;
|
using Moq;
|
||||||
@ -10,7 +9,6 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Edit.Checks;
|
using osu.Game.Rulesets.Edit.Checks;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using FileInfo = osu.Game.IO.FileInfo;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Editing.Checks
|
namespace osu.Game.Tests.Editing.Checks
|
||||||
{
|
{
|
||||||
@ -30,14 +28,10 @@ namespace osu.Game.Tests.Editing.Checks
|
|||||||
{
|
{
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
Files = new List<BeatmapSetFileInfo>(new[]
|
Files =
|
||||||
{
|
{
|
||||||
new BeatmapSetFileInfo
|
CheckTestHelpers.CreateMockFile("jpg"),
|
||||||
{
|
}
|
||||||
Filename = "abc123.jpg",
|
|
||||||
FileInfo = new FileInfo { Hash = "abcdef" }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -36,8 +36,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
|
public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
|
||||||
|
|
||||||
[NotNull]
|
public List<BeatmapSetFileInfo> Files { get; } = new List<BeatmapSetFileInfo>();
|
||||||
public List<BeatmapSetFileInfo> Files { get; set; } = new List<BeatmapSetFileInfo>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum star difficulty of all beatmaps in this set.
|
/// The maximum star difficulty of all beatmaps in this set.
|
||||||
|
@ -392,7 +392,8 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
LogForModel(item, @"Beginning import...");
|
LogForModel(item, @"Beginning import...");
|
||||||
|
|
||||||
item.Files = archive != null ? createFileInfos(archive, Files) : new List<TFileModel>();
|
if (archive != null)
|
||||||
|
item.Files.AddRange(createFileInfos(archive, Files));
|
||||||
item.Hash = ComputeHash(item);
|
item.Hash = ComputeHash(item);
|
||||||
|
|
||||||
await Populate(item, archive, cancellationToken).ConfigureAwait(false);
|
await Populate(item, archive, cancellationToken).ConfigureAwait(false);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
@ -12,7 +13,8 @@ namespace osu.Game.Database
|
|||||||
public interface IHasFiles<TFile>
|
public interface IHasFiles<TFile>
|
||||||
where TFile : INamedFileInfo
|
where TFile : INamedFileInfo
|
||||||
{
|
{
|
||||||
List<TFile> Files { get; set; }
|
[NotNull]
|
||||||
|
List<TFile> Files { get; }
|
||||||
|
|
||||||
string Hash { get; set; }
|
string Hash { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
if (Score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null)
|
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));
|
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)));
|
items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => scoreManager.Export(Score)));
|
||||||
|
|
||||||
if (Score.ID != 0)
|
if (Score.ID != 0)
|
||||||
|
@ -160,7 +160,7 @@ namespace osu.Game.Scoring
|
|||||||
[NotMapped]
|
[NotMapped]
|
||||||
public List<HitEvent> HitEvents { get; set; }
|
public List<HitEvent> HitEvents { get; set; }
|
||||||
|
|
||||||
public List<ScoreFileInfo> Files { get; set; }
|
public List<ScoreFileInfo> Files { get; } = new List<ScoreFileInfo>();
|
||||||
|
|
||||||
public string Hash { get; set; }
|
public string Hash { get; set; }
|
||||||
|
|
||||||
|
@ -24,9 +24,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
protected override IEnumerable<string> GetFilenames(string name)
|
protected override IEnumerable<string> GetFilenames(string name)
|
||||||
{
|
{
|
||||||
if (source.Files == null)
|
|
||||||
yield break;
|
|
||||||
|
|
||||||
foreach (string filename in base.GetFilenames(name))
|
foreach (string filename in base.GetFilenames(name))
|
||||||
{
|
{
|
||||||
string path = getPathForFile(filename.ToStandardisedPath());
|
string path = getPathForFile(filename.ToStandardisedPath());
|
||||||
|
@ -59,7 +59,7 @@ namespace osu.Game.Skinning
|
|||||||
string filename = $"{skinnableTarget}.json";
|
string filename = $"{skinnableTarget}.json";
|
||||||
|
|
||||||
// skininfo files may be null for default skin.
|
// 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)
|
if (fileInfo == null)
|
||||||
continue;
|
continue;
|
||||||
|
@ -36,7 +36,7 @@ namespace osu.Game.Skinning
|
|||||||
return (Skin)Activator.CreateInstance(type, this, resources);
|
return (Skin)Activator.CreateInstance(type, this, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SkinFileInfo> Files { get; set; } = new List<SkinFileInfo>();
|
public List<SkinFileInfo> Files { get; } = new List<SkinFileInfo>();
|
||||||
|
|
||||||
public bool DeletePending { get; set; }
|
public bool DeletePending { get; set; }
|
||||||
|
|
||||||
|
@ -87,23 +87,19 @@ namespace osu.Game.Tests.Beatmaps
|
|||||||
{
|
{
|
||||||
AddStep("setup skins", () =>
|
AddStep("setup skins", () =>
|
||||||
{
|
{
|
||||||
userSkinInfo.Files = new List<SkinFileInfo>
|
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<BeatmapSetFileInfo>
|
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.
|
// Need to refresh the cached skin source to refresh the skin resource store.
|
||||||
dependencies.SkinSource = new SkinProvidingContainer(Skin = new LegacySkin(userSkinInfo, this));
|
dependencies.SkinSource = new SkinProvidingContainer(Skin = new LegacySkin(userSkinInfo, this));
|
||||||
|
Reference in New Issue
Block a user