diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 6c3a703c19..f58b3505c5 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -68,7 +68,7 @@ namespace osu.Game.Beatmaps private readonly APIAccess api; - private readonly List currentDownloads; + private readonly List currentDownloads = new List(); // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private BeatmapIPCChannel ipc; @@ -99,8 +99,6 @@ namespace osu.Game.Beatmaps if (importHost != null) ipc = new BeatmapIPCChannel(importHost, this); - - currentDownloads = new List(); } /// @@ -194,7 +192,7 @@ namespace osu.Game.Beatmaps /// A new , or an existing one if a download is already in progress. public DownloadBeatmapSetRequest Download(BeatmapSetInfo beatmapSetInfo) { - var existing = currentDownloads.Find(d => d.BeatmapSet.OnlineBeatmapSetID == beatmapSetInfo.OnlineBeatmapSetID); + var existing = GetExistingDownload(beatmapSetInfo); if (existing != null) return existing; @@ -243,7 +241,6 @@ namespace osu.Game.Beatmaps PostNotification?.Invoke(downloadNotification); // don't run in the main api queue as this is a long-running task. - // TODO: ensure the Success/Failure callbacks are being scheduled to the main thread for thread safety. Task.Run(() => request.Perform(api)); return request; diff --git a/osu.Game/Overlays/Direct/DirectPanel.cs b/osu.Game/Overlays/Direct/DirectPanel.cs index 66b3ff8bf9..6f1f581d0b 100644 --- a/osu.Game/Overlays/Direct/DirectPanel.cs +++ b/osu.Game/Overlays/Direct/DirectPanel.cs @@ -38,38 +38,6 @@ namespace osu.Game.Overlays.Direct private BeatmapManager beatmaps; private NotificationOverlay notifications; - private DownloadBeatmapSetRequest downloadRequest; - protected DownloadBeatmapSetRequest DownloadRequest - { - get { return downloadRequest; } - set - { - if (value == null || downloadRequest == value) return; - - downloadRequest = value; - - progressBar.FadeIn(400, Easing.OutQuint); - progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); - - progressBar.Current.Value = 0; - - downloadRequest.Failure += e => - { - progressBar.Current.Value = 0; - progressBar.FadeOut(500); - Logger.Error(e, "Failed to get beatmap download information"); - }; - - downloadRequest.DownloadProgressed += progress => progressBar.Current.Value = progress; - - downloadRequest.Success += data => - { - progressBar.Current.Value = 1; - progressBar.FadeOut(500); - }; - } - } - protected override Container Content => content; protected DirectPanel(BeatmapSetInfo setInfo) @@ -128,7 +96,10 @@ namespace osu.Game.Overlays.Direct } }); - DownloadRequest = beatmaps.GetExistingDownload(SetInfo); + var downloadRequest = beatmaps.GetExistingDownload(SetInfo); + + if (downloadRequest != null) + attachDownload(downloadRequest); } protected override bool OnHover(InputState state) @@ -159,9 +130,9 @@ namespace osu.Game.Overlays.Direct return; } - // we already have an active download running. if (beatmaps.GetExistingDownload(SetInfo) != null) { + // we already have an active download running. content.MoveToX(-5, 50, Easing.OutSine).Then() .MoveToX(5, 100, Easing.InOutSine).Then() .MoveToX(-5, 100, Easing.InOutSine).Then() @@ -170,7 +141,32 @@ namespace osu.Game.Overlays.Direct return; } - DownloadRequest = beatmaps.Download(SetInfo); + var request = beatmaps.Download(SetInfo); + + attachDownload(request); + } + + private void attachDownload(DownloadBeatmapSetRequest request) + { + progressBar.FadeIn(400, Easing.OutQuint); + progressBar.ResizeHeightTo(4, 400, Easing.OutQuint); + + progressBar.Current.Value = 0; + + request.Failure += e => + { + progressBar.Current.Value = 0; + progressBar.FadeOut(500); + Logger.Error(e, "Failed to get beatmap download information"); + }; + + request.DownloadProgressed += progress => progressBar.Current.Value = progress; + + request.Success += data => + { + progressBar.Current.Value = 1; + progressBar.FadeOut(500); + }; } protected override void LoadComplete()