From f13a1cec1b98db5072c5f503e2791a703b42b701 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Sun, 24 Nov 2024 21:45:46 -0500 Subject: [PATCH] Allow proxying URL lookups in `OnlineStore` --- osu.Framework/Game.cs | 11 ++++++++--- osu.Framework/IO/Stores/OnlineStore.cs | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/osu.Framework/Game.cs b/osu.Framework/Game.cs index 01042b525c..1f7a8e827b 100644 --- a/osu.Framework/Game.cs +++ b/osu.Framework/Game.cs @@ -154,16 +154,16 @@ private void load(FrameworkConfigManager config) Textures = new TextureStore(Host.Renderer, Host.CreateTextureLoaderStore(new NamespacedResourceStore(Resources, @"Textures")), filteringMode: DefaultTextureFilteringMode); - Textures.AddTextureSource(Host.CreateTextureLoaderStore(new OnlineStore())); + Textures.AddTextureSource(Host.CreateTextureLoaderStore(CreateOnlineStore())); dependencies.Cache(Textures); var tracks = new ResourceStore(); tracks.AddStore(new NamespacedResourceStore(Resources, @"Tracks")); - tracks.AddStore(new OnlineStore()); + tracks.AddStore(CreateOnlineStore()); var samples = new ResourceStore(); samples.AddStore(new NamespacedResourceStore(Resources, @"Samples")); - samples.AddStore(new OnlineStore()); + samples.AddStore(CreateOnlineStore()); Audio = new AudioManager(Host.AudioThread, tracks, samples) { EventScheduler = Scheduler }; dependencies.Cache(Audio); @@ -234,6 +234,11 @@ private void load(FrameworkConfigManager config) }, true); } + /// + /// Creates an to be used for online textures/tracks/samples lookups. + /// + protected virtual OnlineStore CreateOnlineStore() => new OnlineStore(); + /// /// Add a font to be globally accessible to the game. /// diff --git a/osu.Framework/IO/Stores/OnlineStore.cs b/osu.Framework/IO/Stores/OnlineStore.cs index 757e14ce01..9dbc227e65 100644 --- a/osu.Framework/IO/Stores/OnlineStore.cs +++ b/osu.Framework/IO/Stores/OnlineStore.cs @@ -24,7 +24,7 @@ public async Task GetAsync(string url, CancellationToken cancellationTok try { - using (WebRequest req = new WebRequest($@"{url}")) + using (WebRequest req = new WebRequest(GetLookupUrl(url))) { await req.PerformAsync(cancellationToken).ConfigureAwait(false); return req.GetResponseData(); @@ -45,7 +45,7 @@ public virtual byte[] Get(string url) try { - using (WebRequest req = new WebRequest($@"{url}")) + using (WebRequest req = new WebRequest(GetLookupUrl(url))) { req.Perform(); return req.GetResponseData(); @@ -68,6 +68,12 @@ public Stream GetStream(string url) public IEnumerable GetAvailableResources() => Enumerable.Empty(); + /// + /// Returns the URL used to look up the requested resource. + /// + /// The original URL for lookup. + protected virtual string GetLookupUrl(string url) => url; + private bool validateScheme(string url) { if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri))