mirror of https://github.com/ppy/osu
Fix incorrect DI fetch and apply nullability to `ModelDownloader`
This commit is contained in:
parent
07874efa7f
commit
6357223341
|
@ -30,7 +30,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
|
|||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
var importer = parent.Get<BeatmapImporter>();
|
||||
var importer = parent.Get<BeatmapManager>();
|
||||
|
||||
dependencies.CacheAs<BeatmapModelDownloader>(beatmapDownloader = new TestSceneOnlinePlayBeatmapAvailabilityTracker.TestBeatmapModelDownloader(importer, API));
|
||||
return dependencies;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
|
@ -14,7 +12,7 @@ public class BeatmapModelDownloader : ModelDownloader<BeatmapSetInfo, IBeatmapSe
|
|||
protected override ArchiveDownloadRequest<IBeatmapSetInfo> CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) =>
|
||||
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
|
||||
|
||||
public override ArchiveDownloadRequest<IBeatmapSetInfo> GetExistingDownload(IBeatmapSetInfo model)
|
||||
public override ArchiveDownloadRequest<IBeatmapSetInfo>? GetExistingDownload(IBeatmapSetInfo model)
|
||||
=> CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID);
|
||||
|
||||
public BeatmapModelDownloader(IModelImporter<BeatmapSetInfo> beatmapImporter, IAPIProvider api)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -19,18 +17,18 @@ public abstract class ModelDownloader<TModel, T> : IModelDownloader<T>
|
|||
where TModel : class, IHasGuidPrimaryKey, ISoftDelete, IEquatable<TModel>, T
|
||||
where T : class
|
||||
{
|
||||
public Action<Notification> PostNotification { protected get; set; }
|
||||
public Action<Notification>? PostNotification { protected get; set; }
|
||||
|
||||
public event Action<ArchiveDownloadRequest<T>> DownloadBegan;
|
||||
public event Action<ArchiveDownloadRequest<T>>? DownloadBegan;
|
||||
|
||||
public event Action<ArchiveDownloadRequest<T>> DownloadFailed;
|
||||
public event Action<ArchiveDownloadRequest<T>>? DownloadFailed;
|
||||
|
||||
private readonly IModelImporter<TModel> importer;
|
||||
private readonly IAPIProvider api;
|
||||
private readonly IAPIProvider? api;
|
||||
|
||||
protected readonly List<ArchiveDownloadRequest<T>> CurrentDownloads = new List<ArchiveDownloadRequest<T>>();
|
||||
|
||||
protected ModelDownloader(IModelImporter<TModel> importer, IAPIProvider api)
|
||||
protected ModelDownloader(IModelImporter<TModel> importer, IAPIProvider? api)
|
||||
{
|
||||
this.importer = importer;
|
||||
this.api = api;
|
||||
|
@ -87,7 +85,7 @@ public bool Download(T model, bool minimiseDownloadSize = false)
|
|||
CurrentDownloads.Add(request);
|
||||
PostNotification?.Invoke(notification);
|
||||
|
||||
api.PerformAsync(request);
|
||||
api?.PerformAsync(request);
|
||||
|
||||
DownloadBegan?.Invoke(request);
|
||||
return true;
|
||||
|
@ -101,11 +99,11 @@ void triggerFailure(Exception error)
|
|||
notification.State = ProgressNotificationState.Cancelled;
|
||||
|
||||
if (!(error is OperationCanceledException))
|
||||
Logger.Error(error, $"{importer?.HumanisedModelName.Titleize()} download failed!");
|
||||
Logger.Error(error, $"{importer.HumanisedModelName.Titleize()} download failed!");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ArchiveDownloadRequest<T> GetExistingDownload(T model);
|
||||
public abstract ArchiveDownloadRequest<T>? GetExistingDownload(T model);
|
||||
|
||||
private bool canDownload(T model) => GetExistingDownload(model) == null && api != null;
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Online.API;
|
||||
|
|
Loading…
Reference in New Issue