diff --git a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs index 5e7ce3abf5..e3e2304990 100644 --- a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs +++ b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs @@ -168,19 +168,19 @@ namespace osu.Game.Tests.Online return new TestBeatmapModelManager(this, storage, contextFactory, rulesets, api, host); } - protected override BeatmapModelDownloader CreateBeatmapModelDownloader(IBeatmapModelManager manager, IAPIProvider api, GameHost host) + protected override BeatmapModelDownloader CreateBeatmapModelDownloader(IModelImporter manager, IAPIProvider api, GameHost host) { return new TestBeatmapModelDownloader(manager, api, host); } internal class TestBeatmapModelDownloader : BeatmapModelDownloader { - public TestBeatmapModelDownloader(IBeatmapModelManager modelManager, IAPIProvider apiProvider, GameHost gameHost) - : base(modelManager, apiProvider, gameHost) + public TestBeatmapModelDownloader(IModelImporter importer, IAPIProvider apiProvider, GameHost gameHost) + : base(importer, apiProvider, gameHost) { } - protected override ArchiveDownloadRequest CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) + protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) => new TestDownloadRequest(set); } @@ -202,12 +202,12 @@ namespace osu.Game.Tests.Online } } - private class TestDownloadRequest : ArchiveDownloadRequest + private class TestDownloadRequest : ArchiveDownloadRequest { public new void SetProgress(float progress) => base.SetProgress(progress); public new void TriggerSuccess(string filename) => base.TriggerSuccess(filename); - public TestDownloadRequest(BeatmapSetInfo model) + public TestDownloadRequest(IBeatmapSetInfo model) : base(model) { } diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 674d603d9a..0dc095c40a 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -29,7 +29,7 @@ namespace osu.Game.Beatmaps /// Handles general operations related to global beatmap management. /// [ExcludeFromDynamicCompile] - public class BeatmapManager : IModelDownloader, IModelManager, IModelFileManager, IWorkingBeatmapCache, IDisposable + public class BeatmapManager : IModelDownloader, IModelManager, IModelFileManager, IModelImporter, IWorkingBeatmapCache, IDisposable { private readonly BeatmapModelManager beatmapModelManager; private readonly BeatmapModelDownloader beatmapModelDownloader; @@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps } } - protected virtual BeatmapModelDownloader CreateBeatmapModelDownloader(IBeatmapModelManager modelManager, IAPIProvider api, GameHost host) + protected virtual BeatmapModelDownloader CreateBeatmapModelDownloader(IModelImporter modelManager, IAPIProvider api, GameHost host) { return new BeatmapModelDownloader(modelManager, api, host); } @@ -246,37 +246,15 @@ namespace osu.Game.Beatmaps #region Implementation of IModelDownloader - public IBindable>> DownloadBegan => beatmapModelDownloader.DownloadBegan; + public IBindable>> DownloadBegan => beatmapModelDownloader.DownloadBegan; - public IBindable>> DownloadFailed => beatmapModelDownloader.DownloadFailed; + public IBindable>> DownloadFailed => beatmapModelDownloader.DownloadFailed; - // Temporary method until this class supports IBeatmapSetInfo or otherwise. - public bool Download(IBeatmapSetInfo model, bool minimiseDownloadSize = false) - { - return beatmapModelDownloader.Download(new BeatmapSetInfo - { - OnlineBeatmapSetID = model.OnlineID, - Metadata = new BeatmapMetadata - { - Title = model.Metadata?.Title ?? string.Empty, - Artist = model.Metadata?.Artist ?? string.Empty, - TitleUnicode = model.Metadata?.TitleUnicode ?? string.Empty, - ArtistUnicode = model.Metadata?.ArtistUnicode ?? string.Empty, - AuthorString = model.Metadata?.Author.Username ?? string.Empty, - AuthorID = model.Metadata?.Author.OnlineID ?? 1, - } - }, minimiseDownloadSize); - } + public bool Download(IBeatmapSetInfo model, bool minimiseDownloadSize = false) => + beatmapModelDownloader.Download(model, minimiseDownloadSize); - public bool Download(BeatmapSetInfo model, bool minimiseDownloadSize = false) - { - return beatmapModelDownloader.Download(model, minimiseDownloadSize); - } - - public ArchiveDownloadRequest GetExistingDownload(BeatmapSetInfo model) - { - return beatmapModelDownloader.GetExistingDownload(model); - } + public ArchiveDownloadRequest GetExistingDownload(IBeatmapSetInfo model) => + beatmapModelDownloader.GetExistingDownload(model); #endregion diff --git a/osu.Game/Beatmaps/BeatmapModelDownloader.cs b/osu.Game/Beatmaps/BeatmapModelDownloader.cs index 001726e741..a170edc9f8 100644 --- a/osu.Game/Beatmaps/BeatmapModelDownloader.cs +++ b/osu.Game/Beatmaps/BeatmapModelDownloader.cs @@ -8,16 +8,16 @@ using osu.Game.Online.API.Requests; namespace osu.Game.Beatmaps { - public class BeatmapModelDownloader : ModelDownloader + public class BeatmapModelDownloader : ModelDownloader { - protected override ArchiveDownloadRequest CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) => + protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) => new DownloadBeatmapSetRequest(set, minimiseDownloadSize); - public override ArchiveDownloadRequest GetExistingDownload(BeatmapSetInfo model) + public override ArchiveDownloadRequest GetExistingDownload(IBeatmapSetInfo model) => CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID); - public BeatmapModelDownloader(IBeatmapModelManager beatmapModelManager, IAPIProvider api, GameHost host = null) - : base(beatmapModelManager, api, host) + public BeatmapModelDownloader(IModelImporter beatmapImporter, IAPIProvider api, GameHost host = null) + : base(beatmapImporter, api, host) { } } diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 4e40e52051..d2f9ee1dc1 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -30,7 +30,7 @@ namespace osu.Game.Database /// /// The model type. /// The associated file join type. - public abstract class ArchiveModelManager : IModelManager, IModelFileManager + public abstract class ArchiveModelManager : IModelImporter, IModelManager, IModelFileManager where TModel : class, IHasFiles, IHasPrimaryKey, ISoftDelete where TFileModel : class, INamedFileInfo, IHasPrimaryKey, new() { diff --git a/osu.Game/Database/IModelDownloader.cs b/osu.Game/Database/IModelDownloader.cs index a5573b2190..3c57a277ba 100644 --- a/osu.Game/Database/IModelDownloader.cs +++ b/osu.Game/Database/IModelDownloader.cs @@ -10,35 +10,35 @@ namespace osu.Game.Database /// /// Represents a that can download new models from an external source. /// - /// The model type. - public interface IModelDownloader : IPostNotifications - where TModel : class + /// The item's interface type. + public interface IModelDownloader : IPostNotifications + where T : class { /// - /// Fired when a download begins. + /// Fired when a download begins. /// This is NOT run on the update thread and should be scheduled. /// - IBindable>> DownloadBegan { get; } + IBindable>> DownloadBegan { get; } /// - /// Fired when a download is interrupted, either due to user cancellation or failure. + /// Fired when a download is interrupted, either due to user cancellation or failure. /// This is NOT run on the update thread and should be scheduled. /// - IBindable>> DownloadFailed { get; } + IBindable>> DownloadFailed { get; } /// - /// Begin a download for the requested . + /// Begin a download for the requested . /// - /// The to be downloaded. + /// The to be downloaded. /// Whether this download should be optimised for slow connections. Generally means extras are not included in the download bundle.. /// Whether the download was started. - bool Download(TModel model, bool minimiseDownloadSize); + bool Download(T item, bool minimiseDownloadSize); /// - /// Gets an existing download request if it exists. + /// Gets an existing download request if it exists. /// - /// The whose request is wanted. - /// The object if it exists, otherwise null. - ArchiveDownloadRequest GetExistingDownload(TModel model); + /// The whose request is wanted. + /// The object if it exists, otherwise null. + ArchiveDownloadRequest GetExistingDownload(T item); } } diff --git a/osu.Game/Database/IModelManager.cs b/osu.Game/Database/IModelManager.cs index f5e401cdfb..0be927322d 100644 --- a/osu.Game/Database/IModelManager.cs +++ b/osu.Game/Database/IModelManager.cs @@ -14,7 +14,7 @@ namespace osu.Game.Database /// Represents a model manager that publishes events when s are added or removed. /// /// The model type. - public interface IModelManager : IModelImporter + public interface IModelManager where TModel : class { /// diff --git a/osu.Game/Database/ModelDownloader.cs b/osu.Game/Database/ModelDownloader.cs index 12bf5e9ce7..e44ae21ed6 100644 --- a/osu.Game/Database/ModelDownloader.cs +++ b/osu.Game/Database/ModelDownloader.cs @@ -14,39 +14,40 @@ using osu.Game.Overlays.Notifications; namespace osu.Game.Database { - public abstract class ModelDownloader : IModelDownloader - where TModel : class, IHasPrimaryKey, ISoftDelete, IEquatable + public abstract class ModelDownloader : IModelDownloader + where TModel : class, IHasPrimaryKey, ISoftDelete, IEquatable, T + where T : class { public Action PostNotification { protected get; set; } - public IBindable>> DownloadBegan => downloadBegan; + public IBindable>> DownloadBegan => downloadBegan; - private readonly Bindable>> downloadBegan = new Bindable>>(); + private readonly Bindable>> downloadBegan = new Bindable>>(); - public IBindable>> DownloadFailed => downloadFailed; + public IBindable>> DownloadFailed => downloadFailed; - private readonly Bindable>> downloadFailed = new Bindable>>(); + private readonly Bindable>> downloadFailed = new Bindable>>(); - private readonly IModelManager modelManager; + private readonly IModelImporter importer; private readonly IAPIProvider api; - protected readonly List> CurrentDownloads = new List>(); + protected readonly List> CurrentDownloads = new List>(); - protected ModelDownloader(IModelManager modelManager, IAPIProvider api, IIpcHost importHost = null) + protected ModelDownloader(IModelImporter importer, IAPIProvider api, IIpcHost importHost = null) { - this.modelManager = modelManager; + this.importer = importer; this.api = api; } /// - /// Creates the download request for this . + /// Creates the download request for this . /// - /// The to be downloaded. + /// The to be downloaded. /// Whether this download should be optimised for slow connections. Generally means extras are not included in the download bundle. /// The request object. - protected abstract ArchiveDownloadRequest CreateDownloadRequest(TModel model, bool minimiseDownloadSize); + protected abstract ArchiveDownloadRequest CreateDownloadRequest(T model, bool minimiseDownloadSize); - public bool Download(TModel model, bool minimiseDownloadSize = false) + public bool Download(T model, bool minimiseDownloadSize = false) { if (!canDownload(model)) return false; @@ -68,11 +69,11 @@ namespace osu.Game.Database Task.Factory.StartNew(async () => { // This gets scheduled back to the update thread, but we want the import to run in the background. - var imported = await modelManager.Import(notification, new ImportTask(filename)).ConfigureAwait(false); + var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false); // for now a failed import will be marked as a failed download for simplicity. if (!imported.Any()) - downloadFailed.Value = new WeakReference>(request); + downloadFailed.Value = new WeakReference>(request); CurrentDownloads.Remove(request); }, TaskCreationOptions.LongRunning); @@ -91,25 +92,25 @@ namespace osu.Game.Database api.PerformAsync(request); - downloadBegan.Value = new WeakReference>(request); + downloadBegan.Value = new WeakReference>(request); return true; void triggerFailure(Exception error) { CurrentDownloads.Remove(request); - downloadFailed.Value = new WeakReference>(request); + downloadFailed.Value = new WeakReference>(request); notification.State = ProgressNotificationState.Cancelled; if (!(error is OperationCanceledException)) - Logger.Error(error, $"{modelManager.HumanisedModelName.Titleize()} download failed!"); + Logger.Error(error, $"{importer.HumanisedModelName.Titleize()} download failed!"); } } - public abstract ArchiveDownloadRequest GetExistingDownload(TModel model); + public abstract ArchiveDownloadRequest GetExistingDownload(T model); - private bool canDownload(TModel model) => GetExistingDownload(model) == null && api != null; + private bool canDownload(T model) => GetExistingDownload(model) == null && api != null; private class DownloadNotification : ProgressNotification { diff --git a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs index 2898955de7..5254dc3cf8 100644 --- a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs +++ b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs @@ -6,11 +6,11 @@ using osu.Game.Beatmaps; namespace osu.Game.Online.API.Requests { - public class DownloadBeatmapSetRequest : ArchiveDownloadRequest + public class DownloadBeatmapSetRequest : ArchiveDownloadRequest { private readonly bool noVideo; - public DownloadBeatmapSetRequest(BeatmapSetInfo set, bool noVideo) + public DownloadBeatmapSetRequest(IBeatmapSetInfo set, bool noVideo) : base(set) { this.noVideo = noVideo; @@ -25,6 +25,6 @@ namespace osu.Game.Online.API.Requests protected override string FileExtension => ".osz"; - protected override string Target => $@"beatmapsets/{Model.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}"; + protected override string Target => $@"beatmapsets/{Model.OnlineID}/download{(noVideo ? "?noVideo=1" : "")}"; } } diff --git a/osu.Game/Online/API/Requests/DownloadReplayRequest.cs b/osu.Game/Online/API/Requests/DownloadReplayRequest.cs index 6fd052653d..77174f0bb5 100644 --- a/osu.Game/Online/API/Requests/DownloadReplayRequest.cs +++ b/osu.Game/Online/API/Requests/DownloadReplayRequest.cs @@ -5,15 +5,15 @@ using osu.Game.Scoring; namespace osu.Game.Online.API.Requests { - public class DownloadReplayRequest : ArchiveDownloadRequest + public class DownloadReplayRequest : ArchiveDownloadRequest { - public DownloadReplayRequest(ScoreInfo score) + public DownloadReplayRequest(IScoreInfo score) : base(score) { } protected override string FileExtension => ".osr"; - protected override string Target => $@"scores/{Model.Ruleset.ShortName}/{Model.OnlineScoreID}/download"; + protected override string Target => $@"scores/{Model.Ruleset.ShortName}/{Model.OnlineID}/download"; } } diff --git a/osu.Game/Online/BeatmapDownloadTracker.cs b/osu.Game/Online/BeatmapDownloadTracker.cs index 4a7d0b660a..12cbcdbec7 100644 --- a/osu.Game/Online/BeatmapDownloadTracker.cs +++ b/osu.Game/Online/BeatmapDownloadTracker.cs @@ -16,7 +16,7 @@ namespace osu.Game.Online [Resolved(CanBeNull = true)] protected BeatmapManager? Manager { get; private set; } - private ArchiveDownloadRequest? attachedRequest; + private ArchiveDownloadRequest? attachedRequest; public BeatmapDownloadTracker(IBeatmapSetInfo trackedItem) : base(trackedItem) @@ -25,8 +25,8 @@ namespace osu.Game.Online private IBindable>? managerUpdated; private IBindable>? managerRemoved; - private IBindable>>? managerDownloadBegan; - private IBindable>>? managerDownloadFailed; + private IBindable>>? managerDownloadBegan; + private IBindable>>? managerDownloadFailed; [BackgroundDependencyLoader(true)] private void load() @@ -52,7 +52,7 @@ namespace osu.Game.Online managerRemoved.BindValueChanged(itemRemoved); } - private void downloadBegan(ValueChangedEvent>> weakRequest) + private void downloadBegan(ValueChangedEvent>> weakRequest) { if (weakRequest.NewValue.TryGetTarget(out var request)) { @@ -64,7 +64,7 @@ namespace osu.Game.Online } } - private void downloadFailed(ValueChangedEvent>> weakRequest) + private void downloadFailed(ValueChangedEvent>> weakRequest) { if (weakRequest.NewValue.TryGetTarget(out var request)) { @@ -76,7 +76,7 @@ namespace osu.Game.Online } } - private void attachDownload(ArchiveDownloadRequest? request) + private void attachDownload(ArchiveDownloadRequest? request) { if (attachedRequest != null) { diff --git a/osu.Game/Online/ScoreDownloadTracker.cs b/osu.Game/Online/ScoreDownloadTracker.cs index e679071ac1..9ea6d5b79a 100644 --- a/osu.Game/Online/ScoreDownloadTracker.cs +++ b/osu.Game/Online/ScoreDownloadTracker.cs @@ -16,7 +16,7 @@ namespace osu.Game.Online [Resolved(CanBeNull = true)] protected ScoreManager? Manager { get; private set; } - private ArchiveDownloadRequest? attachedRequest; + private ArchiveDownloadRequest? attachedRequest; public ScoreDownloadTracker(ScoreInfo trackedItem) : base(trackedItem) @@ -25,8 +25,8 @@ namespace osu.Game.Online private IBindable>? managerUpdated; private IBindable>? managerRemoved; - private IBindable>>? managerDownloadBegan; - private IBindable>>? managerDownloadFailed; + private IBindable>>? managerDownloadBegan; + private IBindable>>? managerDownloadFailed; [BackgroundDependencyLoader(true)] private void load() @@ -56,7 +56,7 @@ namespace osu.Game.Online managerRemoved.BindValueChanged(itemRemoved); } - private void downloadBegan(ValueChangedEvent>> weakRequest) + private void downloadBegan(ValueChangedEvent>> weakRequest) { if (weakRequest.NewValue.TryGetTarget(out var request)) { @@ -68,7 +68,7 @@ namespace osu.Game.Online } } - private void downloadFailed(ValueChangedEvent>> weakRequest) + private void downloadFailed(ValueChangedEvent>> weakRequest) { if (weakRequest.NewValue.TryGetTarget(out var request)) { @@ -80,7 +80,7 @@ namespace osu.Game.Online } } - private void attachDownload(ArchiveDownloadRequest? request) + private void attachDownload(ArchiveDownloadRequest? request) { if (attachedRequest != null) { @@ -144,7 +144,7 @@ namespace osu.Game.Online } } - private bool checkEquality(ScoreInfo x, ScoreInfo y) => x.OnlineScoreID == y.OnlineScoreID; + private bool checkEquality(IScoreInfo x, IScoreInfo y) => x.OnlineID == y.OnlineID; #region Disposal diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 253591eb56..676baf511a 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -25,7 +25,7 @@ using osu.Game.Rulesets.Scoring; namespace osu.Game.Scoring { - public class ScoreManager : IModelManager, IModelFileManager, IModelDownloader + public class ScoreManager : IModelManager, IModelImporter, IModelFileManager, IModelDownloader { private readonly Scheduler scheduler; private readonly Func difficulties; @@ -350,16 +350,14 @@ namespace osu.Game.Scoring #region Implementation of IModelDownloader - public IBindable>> DownloadBegan => scoreModelDownloader.DownloadBegan; + public IBindable>> DownloadBegan => scoreModelDownloader.DownloadBegan; - public IBindable>> DownloadFailed => scoreModelDownloader.DownloadFailed; + public IBindable>> DownloadFailed => scoreModelDownloader.DownloadFailed; - public bool Download(ScoreInfo model, bool minimiseDownloadSize) - { - return scoreModelDownloader.Download(model, minimiseDownloadSize); - } + public bool Download(IScoreInfo model, bool minimiseDownloadSize) => + scoreModelDownloader.Download(model, minimiseDownloadSize); - public ArchiveDownloadRequest GetExistingDownload(ScoreInfo model) + public ArchiveDownloadRequest GetExistingDownload(IScoreInfo model) { return scoreModelDownloader.GetExistingDownload(model); } diff --git a/osu.Game/Scoring/ScoreModelDownloader.cs b/osu.Game/Scoring/ScoreModelDownloader.cs index 52355585a9..6c63e2aa71 100644 --- a/osu.Game/Scoring/ScoreModelDownloader.cs +++ b/osu.Game/Scoring/ScoreModelDownloader.cs @@ -8,16 +8,16 @@ using osu.Game.Online.API.Requests; namespace osu.Game.Scoring { - public class ScoreModelDownloader : ModelDownloader + public class ScoreModelDownloader : ModelDownloader { - public ScoreModelDownloader(ScoreModelManager scoreManager, IAPIProvider api, IIpcHost importHost = null) + public ScoreModelDownloader(IModelImporter scoreManager, IAPIProvider api, IIpcHost importHost = null) : base(scoreManager, api, importHost) { } - protected override ArchiveDownloadRequest CreateDownloadRequest(ScoreInfo score, bool minimiseDownload) => new DownloadReplayRequest(score); + protected override ArchiveDownloadRequest CreateDownloadRequest(IScoreInfo score, bool minimiseDownload) => new DownloadReplayRequest(score); - public override ArchiveDownloadRequest GetExistingDownload(ScoreInfo model) - => CurrentDownloads.Find(r => r.Model.OnlineScoreID == model.OnlineScoreID); + public override ArchiveDownloadRequest GetExistingDownload(IScoreInfo model) + => CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID); } }