Skip to content

Commit

Permalink
Merge pull request #6433 from frenzibyte/online-store-proxy
Browse files Browse the repository at this point in the history
Allow rewriting URL lookups in `OnlineStore`
  • Loading branch information
peppy authored Dec 6, 2024
2 parents 2e19f17 + f13a1ce commit 83ea26d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions osu.Framework/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ private void load(FrameworkConfigManager config)
Textures = new TextureStore(Host.Renderer, Host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(Resources, @"Textures")),
filteringMode: DefaultTextureFilteringMode);

Textures.AddTextureSource(Host.CreateTextureLoaderStore(new OnlineStore()));
Textures.AddTextureSource(Host.CreateTextureLoaderStore(CreateOnlineStore()));
dependencies.Cache(Textures);

var tracks = new ResourceStore<byte[]>();
tracks.AddStore(new NamespacedResourceStore<byte[]>(Resources, @"Tracks"));
tracks.AddStore(new OnlineStore());
tracks.AddStore(CreateOnlineStore());

var samples = new ResourceStore<byte[]>();
samples.AddStore(new NamespacedResourceStore<byte[]>(Resources, @"Samples"));
samples.AddStore(new OnlineStore());
samples.AddStore(CreateOnlineStore());

Audio = new AudioManager(Host.AudioThread, tracks, samples) { EventScheduler = Scheduler };
dependencies.Cache(Audio);
Expand Down Expand Up @@ -234,6 +234,11 @@ private void load(FrameworkConfigManager config)
}, true);
}

/// <summary>
/// Creates an <see cref="OnlineStore"/> to be used for online textures/tracks/samples lookups.
/// </summary>
protected virtual OnlineStore CreateOnlineStore() => new OnlineStore();

/// <summary>
/// Add a font to be globally accessible to the game.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions osu.Framework/IO/Stores/OnlineStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<byte[]> 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();
Expand All @@ -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();
Expand All @@ -68,6 +68,12 @@ public Stream GetStream(string url)

public IEnumerable<string> GetAvailableResources() => Enumerable.Empty<string>();

/// <summary>
/// Returns the URL used to look up the requested resource.
/// </summary>
/// <param name="url">The original URL for lookup.</param>
protected virtual string GetLookupUrl(string url) => url;

private bool validateScheme(string url)
{
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
Expand Down

0 comments on commit 83ea26d

Please sign in to comment.