From 17cd9569ed2875c3fd418fc018b356eb2d092806 Mon Sep 17 00:00:00 2001 From: Shivam Date: Mon, 8 Jun 2020 00:46:40 +0200 Subject: [PATCH] Introduce new storage class and manager --- .../Components/TourneyVideo.cs | 4 +-- osu.Game.Tournament/TournamentGameBase.cs | 12 ++++--- osu.Game.Tournament/TournamentStorage.cs | 34 +++++++++++++++++-- .../TournamentStorageManager.cs | 30 ++++++++++++++++ 4 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 osu.Game.Tournament/TournamentStorageManager.cs diff --git a/osu.Game.Tournament/Components/TourneyVideo.cs b/osu.Game.Tournament/Components/TourneyVideo.cs index 317c5f6a56..259cb95035 100644 --- a/osu.Game.Tournament/Components/TourneyVideo.cs +++ b/osu.Game.Tournament/Components/TourneyVideo.cs @@ -27,9 +27,9 @@ namespace osu.Game.Tournament.Components } [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) { diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs index 85db9e61fb..427a33f871 100644 --- a/osu.Game.Tournament/TournamentGameBase.cs +++ b/osu.Game.Tournament/TournamentGameBase.cs @@ -19,6 +19,8 @@ using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Online.API.Requests; +using osu.Framework.Logging; +using osu.Game.Tournament.Configuration; using osu.Game.Tournament.IPC; using osu.Game.Tournament.Models; using osu.Game.Users; @@ -37,7 +39,7 @@ namespace osu.Game.Tournament private Storage storage; - private TournamentStorage tournamentStorage; + private NewTournamentStorage newTournamentStorage; private DependencyContainer dependencies; @@ -52,15 +54,15 @@ namespace osu.Game.Tournament } [BackgroundDependencyLoader] - private void load(Storage storage, FrameworkConfigManager frameworkConfig) + private void load(FrameworkConfigManager frameworkConfig) { 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(FrameworkSetting.WindowedSize); windowSize.BindValueChanged(size => ScheduleAfterChildren(() => diff --git a/osu.Game.Tournament/TournamentStorage.cs b/osu.Game.Tournament/TournamentStorage.cs index 139ad3857b..defeceab93 100644 --- a/osu.Game.Tournament/TournamentStorage.cs +++ b/osu.Game.Tournament/TournamentStorage.cs @@ -2,18 +2,46 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.IO.Stores; +using osu.Framework.Logging; using osu.Framework.Platform; +using osu.Game.IO; +using osu.Game.Tournament.Configuration; namespace osu.Game.Tournament { - internal class TournamentStorage : NamespacedResourceStore + internal class TournamentVideoStorage : NamespacedResourceStore { - public TournamentStorage(Storage storage) - : base(new StorageBackedResourceStore(storage), "tournament") + public TournamentVideoStorage(Storage storage) + : base(new StorageBackedResourceStore(storage), "videos") { AddExtension("m4v"); AddExtension("avi"); 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(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)); + } + } } diff --git a/osu.Game.Tournament/TournamentStorageManager.cs b/osu.Game.Tournament/TournamentStorageManager.cs new file mode 100644 index 0000000000..b1f84ecf44 --- /dev/null +++ b/osu.Game.Tournament/TournamentStorageManager.cs @@ -0,0 +1,30 @@ +// Copyright (c) ppy Pty Ltd . 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 + { + 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, + } +} \ No newline at end of file