mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Introduce new storage class and manager
This commit is contained in:
parent
73467410ab
commit
17cd9569ed
@ -27,9 +27,9 @@ namespace osu.Game.Tournament.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(TournamentStorage storage)
|
private void load(NewTournamentStorage storage)
|
||||||
{
|
{
|
||||||
var stream = storage.GetStream($@"videos/{filename}");
|
var stream = storage.VideoStorage.GetStream($@"{filename}");
|
||||||
|
|
||||||
if (stream != null)
|
if (stream != null)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,8 @@ using osu.Framework.Platform;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Game.Tournament.Configuration;
|
||||||
using osu.Game.Tournament.IPC;
|
using osu.Game.Tournament.IPC;
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
@ -37,7 +39,7 @@ namespace osu.Game.Tournament
|
|||||||
|
|
||||||
private Storage storage;
|
private Storage storage;
|
||||||
|
|
||||||
private TournamentStorage tournamentStorage;
|
private NewTournamentStorage newTournamentStorage;
|
||||||
|
|
||||||
private DependencyContainer dependencies;
|
private DependencyContainer dependencies;
|
||||||
|
|
||||||
@ -52,15 +54,15 @@ namespace osu.Game.Tournament
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(Storage storage, FrameworkConfigManager frameworkConfig)
|
private void load(FrameworkConfigManager frameworkConfig)
|
||||||
{
|
{
|
||||||
Resources.AddStore(new DllResourceStore(typeof(TournamentGameBase).Assembly));
|
Resources.AddStore(new DllResourceStore(typeof(TournamentGameBase).Assembly));
|
||||||
|
|
||||||
dependencies.CacheAs(tournamentStorage = new TournamentStorage(storage));
|
dependencies.CacheAs(newTournamentStorage = new NewTournamentStorage(Host));
|
||||||
|
|
||||||
Textures.AddStore(new TextureLoaderStore(tournamentStorage));
|
Textures.AddStore(new TextureLoaderStore(newTournamentStorage.VideoStorage));
|
||||||
|
|
||||||
this.storage = storage;
|
this.storage = newTournamentStorage;
|
||||||
|
|
||||||
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize);
|
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize);
|
||||||
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
|
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
|
||||||
|
@ -2,18 +2,46 @@
|
|||||||
// 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 osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.IO;
|
||||||
|
using osu.Game.Tournament.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Tournament
|
namespace osu.Game.Tournament
|
||||||
{
|
{
|
||||||
internal class TournamentStorage : NamespacedResourceStore<byte[]>
|
internal class TournamentVideoStorage : NamespacedResourceStore<byte[]>
|
||||||
{
|
{
|
||||||
public TournamentStorage(Storage storage)
|
public TournamentVideoStorage(Storage storage)
|
||||||
: base(new StorageBackedResourceStore(storage), "tournament")
|
: base(new StorageBackedResourceStore(storage), "videos")
|
||||||
{
|
{
|
||||||
AddExtension("m4v");
|
AddExtension("m4v");
|
||||||
AddExtension("avi");
|
AddExtension("avi");
|
||||||
AddExtension("mp4");
|
AddExtension("mp4");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class NewTournamentStorage : WrappedStorage
|
||||||
|
{
|
||||||
|
private readonly GameHost host;
|
||||||
|
private readonly TournamentStorageManager storageConfig;
|
||||||
|
public readonly TournamentVideoStorage VideoStorage;
|
||||||
|
|
||||||
|
public NewTournamentStorage(GameHost host)
|
||||||
|
: base(host.Storage, string.Empty)
|
||||||
|
{
|
||||||
|
this.host = host;
|
||||||
|
|
||||||
|
storageConfig = new TournamentStorageManager(host.Storage);
|
||||||
|
var customTournamentPath = storageConfig.Get<string>(StorageConfig.CurrentTournament);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(customTournamentPath))
|
||||||
|
{
|
||||||
|
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory("tournaments/" + customTournamentPath));
|
||||||
|
} else {
|
||||||
|
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory("tournaments/default"));
|
||||||
|
}
|
||||||
|
VideoStorage = new TournamentVideoStorage(this);
|
||||||
|
Logger.Log("Using tournament storage: " + GetFullPath(string.Empty));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
30
osu.Game.Tournament/TournamentStorageManager.cs
Normal file
30
osu.Game.Tournament/TournamentStorageManager.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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.Framework.Configuration;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Configuration
|
||||||
|
{
|
||||||
|
public class TournamentStorageManager : IniConfigManager<StorageConfig>
|
||||||
|
{
|
||||||
|
protected override string Filename => "tournament.ini";
|
||||||
|
|
||||||
|
public TournamentStorageManager(Storage storage)
|
||||||
|
: base(storage)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void InitialiseDefaults()
|
||||||
|
{
|
||||||
|
base.InitialiseDefaults();
|
||||||
|
Set(StorageConfig.CurrentTournament, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum StorageConfig
|
||||||
|
{
|
||||||
|
CurrentTournament,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user