2021-11-29 09:05:36 +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.Collections.Generic;
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.IO.Stores;
|
|
|
|
using osu.Game.Extensions;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
public class LegacyDatabasedSkinResourceStore : ResourceStore<byte[]>
|
|
|
|
{
|
2021-11-30 17:27:41 +00:00
|
|
|
private readonly Dictionary<string, string> fileToStoragePathMapping = new Dictionary<string, string>();
|
|
|
|
|
2021-11-29 09:05:36 +00:00
|
|
|
public LegacyDatabasedSkinResourceStore(SkinInfo source, IResourceStore<byte[]> underlyingStore)
|
|
|
|
: base(underlyingStore)
|
|
|
|
{
|
2021-11-30 17:27:41 +00:00
|
|
|
initialiseFileCache(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initialiseFileCache(SkinInfo source)
|
|
|
|
{
|
|
|
|
fileToStoragePathMapping.Clear();
|
|
|
|
foreach (var f in source.Files)
|
|
|
|
fileToStoragePathMapping[f.Filename.ToLowerInvariant()] = f.File.GetStoragePath();
|
2021-11-29 09:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override IEnumerable<string> GetFilenames(string name)
|
|
|
|
{
|
|
|
|
foreach (string filename in base.GetFilenames(name))
|
|
|
|
{
|
|
|
|
string path = getPathForFile(filename.ToStandardisedPath());
|
|
|
|
if (path != null)
|
|
|
|
yield return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 17:27:41 +00:00
|
|
|
private string getPathForFile(string filename) =>
|
|
|
|
fileToStoragePathMapping.TryGetValue(filename.ToLower(), out string path) ? path : null;
|
2021-11-29 09:05:36 +00:00
|
|
|
|
2021-11-30 17:27:41 +00:00
|
|
|
public override IEnumerable<string> GetAvailableResources() => fileToStoragePathMapping.Keys;
|
2021-11-29 09:05:36 +00:00
|
|
|
}
|
|
|
|
}
|