osu/osu.Game/Skinning/LegacySkinResourceStore.cs

43 lines
1.4 KiB
C#
Raw Normal View History

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