2019-08-30 12:04:11 +08: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;
|
2020-04-06 18:02:50 +08:00
|
|
|
using osu.Framework.Extensions;
|
2019-08-30 12:04:11 +08:00
|
|
|
using osu.Framework.IO.Stores;
|
|
|
|
using osu.Game.Database;
|
2021-11-19 15:07:55 +08:00
|
|
|
using osu.Game.Extensions;
|
2019-08-30 12:04:11 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
2021-11-23 12:24:43 +08:00
|
|
|
public class LegacySkinResourceStore : ResourceStore<byte[]>
|
2019-08-30 12:04:11 +08:00
|
|
|
{
|
2021-11-29 17:05:36 +08:00
|
|
|
private readonly IHasNamedFiles source;
|
2019-08-30 12:04:11 +08:00
|
|
|
|
2021-11-29 17:05:36 +08:00
|
|
|
public LegacySkinResourceStore(IHasNamedFiles source, IResourceStore<byte[]> underlyingStore)
|
2019-12-16 13:01:08 +08:00
|
|
|
: base(underlyingStore)
|
2019-08-30 12:04:11 +08:00
|
|
|
{
|
|
|
|
this.source = source;
|
|
|
|
}
|
|
|
|
|
2019-12-16 13:01:08 +08:00
|
|
|
protected override IEnumerable<string> GetFilenames(string name)
|
2019-08-30 12:04:11 +08:00
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
foreach (string filename in base.GetFilenames(name))
|
2019-08-30 12:04:11 +08:00
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
string path = getPathForFile(filename.ToStandardisedPath());
|
2019-12-16 13:01:08 +08:00
|
|
|
if (path != null)
|
|
|
|
yield return path;
|
2019-08-30 12:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 13:01:08 +08:00
|
|
|
private string getPathForFile(string filename) =>
|
2021-11-29 17:05:36 +08:00
|
|
|
source.Files.FirstOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.GetStoragePath();
|
2019-08-30 12:04:11 +08:00
|
|
|
|
2019-12-16 13:01:08 +08:00
|
|
|
public override IEnumerable<string> GetAvailableResources() => source.Files.Select(f => f.Filename);
|
2019-08-30 12:04:11 +08:00
|
|
|
}
|
|
|
|
}
|