Skip to content

Commit

Permalink
Fix StoryboardResourceLookupStore dying on failure to unmap path
Browse files Browse the repository at this point in the history
Before the introduction of `StoryboardResourceLookupStore`, missing
files would softly fail by use of null fallbacks. After the
aforementioned class was added, however, the fallbacks would not work
anymore if for whatever reason `GetStoragePathFromStoryboardPath()`
failed to unmap the storyboard asset name to a storage path.
  • Loading branch information
bdach committed Sep 19, 2023
1 parent aea7f81 commit ba518e1
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions osu.Game/Storyboards/Drawables/DrawableStoryboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,32 @@ public StoryboardResourceLookupStore(Storyboard storyboard, RealmAccess realm, G
public void Dispose() =>
realmFileStore.Dispose();

public byte[] Get(string name) =>
realmFileStore.Get(storyboard.GetStoragePathFromStoryboardPath(name));
public byte[] Get(string name)
{
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);

public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) =>
realmFileStore.GetAsync(storyboard.GetStoragePathFromStoryboardPath(name), cancellationToken);
return string.IsNullOrEmpty(storagePath)
? null!
: realmFileStore.Get(storagePath);
}

public Stream GetStream(string name) =>
realmFileStore.GetStream(storyboard.GetStoragePathFromStoryboardPath(name));
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = new CancellationToken())
{
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);

return string.IsNullOrEmpty(storagePath)
? Task.FromResult<byte[]>(null!)
: realmFileStore.GetAsync(storagePath, cancellationToken);
}

public Stream? GetStream(string name)
{
string? storagePath = storyboard.GetStoragePathFromStoryboardPath(name);

return string.IsNullOrEmpty(storagePath)
? null
: realmFileStore.GetStream(storagePath);
}

public IEnumerable<string> GetAvailableResources() =>
realmFileStore.GetAvailableResources();
Expand Down

0 comments on commit ba518e1

Please sign in to comment.