From 4b46601eae6efda450b70dc70aa9c86cb5f01fa5 Mon Sep 17 00:00:00 2001 From: naoey Date: Wed, 19 Jun 2019 19:43:09 +0530 Subject: [PATCH] Remove redundant variable, handle all request failures --- .../DownloadableArchiveModelManager.cs | 26 +++++++++++-------- .../API/Requests/DownloadBeatmapSetRequest.cs | 4 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/osu.Game/Database/DownloadableArchiveModelManager.cs b/osu.Game/Database/DownloadableArchiveModelManager.cs index d9ebd0c06a..90d5ec3f17 100644 --- a/osu.Game/Database/DownloadableArchiveModelManager.cs +++ b/osu.Game/Database/DownloadableArchiveModelManager.cs @@ -94,16 +94,7 @@ namespace osu.Game.Database }, TaskCreationOptions.LongRunning); }; - request.Failure += error => - { - DownloadFailed?.Invoke(request); - - if (error is OperationCanceledException) return; - - notification.State = ProgressNotificationState.Cancelled; - Logger.Error(error, $"{HumanisedModelName.Titleize()} download failed!"); - currentDownloads.Remove(request); - }; + request.Failure += error => handleRequestFailure(request, notification, error); notification.CancelRequested += () => { @@ -122,14 +113,27 @@ namespace osu.Game.Database { request.Perform(api); } - catch + catch (Exception e) { + // 404s (and maybe other failures) don't fire request.Failure so for now they handled here as well + handleRequestFailure(request, notification, e); } }, TaskCreationOptions.LongRunning); DownloadBegan?.Invoke(request); } + private void handleRequestFailure(ArchiveDownloadRequest req, ProgressNotification notification, Exception e) + { + DownloadFailed?.Invoke(req); + + if (e is OperationCanceledException) return; + + notification.State = ProgressNotificationState.Cancelled; + Logger.Error(e, $"{HumanisedModelName.Titleize()} download failed!"); + currentDownloads.Remove(req); + } + private class DownloadNotification : ProgressNotification { public override bool IsImportant => false; diff --git a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs index 999864a6eb..707c59436d 100644 --- a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs +++ b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs @@ -8,15 +8,13 @@ namespace osu.Game.Online.API.Requests public class DownloadBeatmapSetRequest : ArchiveDownloadRequest { private readonly bool noVideo; - private readonly BeatmapSetInfo set; public DownloadBeatmapSetRequest(BeatmapSetInfo set, bool noVideo) : base(set) { this.noVideo = noVideo; - this.set = set; } - protected override string Target => $@"beatmapsets/{set.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}"; + protected override string Target => $@"beatmapsets/{Model.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}"; } }