1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 07:53:38 +08:00
osu-lazer/osu.Game/Skinning/LegacySkinResourceStore.cs
2019-12-17 13:00:15 +08:00

42 lines
1.3 KiB
C#

// 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;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.IO.Stores;
using osu.Game.Database;
namespace osu.Game.Skinning
{
public class LegacySkinResourceStore<T> : ResourceStore<byte[]>
where T : INamedFileInfo
{
private readonly IHasFiles<T> source;
public LegacySkinResourceStore(IHasFiles<T> source, IResourceStore<byte[]> underlyingStore)
: base(underlyingStore)
{
this.source = source;
}
protected override IEnumerable<string> GetFilenames(string name)
{
if (source.Files == null)
yield break;
foreach (var filename in base.GetFilenames(name))
{
var path = getPathForFile(filename);
if (path != null)
yield return path;
}
}
private string getPathForFile(string filename) =>
source.Files.Find(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
public override IEnumerable<string> GetAvailableResources() => source.Files.Select(f => f.Filename);
}
}