From b69a19f81044d7b3f13188b1e15a4b670e1a914e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 31 Jan 2019 19:08:45 +0900 Subject: [PATCH] Attach progress immediately --- osu.Game/Online/API/APIDownloadRequest.cs | 4 ++-- .../API/Requests/DownloadBeatmapSetRequest.cs | 4 +++- .../Direct/DownloadTrackingComposite.cs | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/API/APIDownloadRequest.cs b/osu.Game/Online/API/APIDownloadRequest.cs index 97b869bccd..efc832a71e 100644 --- a/osu.Game/Online/API/APIDownloadRequest.cs +++ b/osu.Game/Online/API/APIDownloadRequest.cs @@ -17,7 +17,7 @@ namespace osu.Game.Online.API return request; } - private void request_Progress(long current, long total) => API.Schedule(() => Progress?.Invoke(current, total)); + private void request_Progress(long current, long total) => API.Schedule(() => Progressed?.Invoke(current, total)); protected APIDownloadRequest() { @@ -29,7 +29,7 @@ namespace osu.Game.Online.API Success?.Invoke(filename); } - public event APIProgressHandler Progress; + public event APIProgressHandler Progressed; public new event APISuccessHandler Success; } diff --git a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs index cd55e9b300..26e8acc2fc 100644 --- a/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs +++ b/osu.Game/Online/API/Requests/DownloadBeatmapSetRequest.cs @@ -10,6 +10,8 @@ namespace osu.Game.Online.API.Requests { public readonly BeatmapSetInfo BeatmapSet; + public float Progress; + public event Action DownloadProgressed; private readonly bool noVideo; @@ -19,7 +21,7 @@ namespace osu.Game.Online.API.Requests this.noVideo = noVideo; BeatmapSet = set; - Progress += (current, total) => DownloadProgressed?.Invoke((float) current / total); + Progressed += (current, total) => DownloadProgressed?.Invoke(Progress = (float)current / total); } protected override string Target => $@"beatmapsets/{BeatmapSet.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}"; diff --git a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs index 4b68c3824a..733bcf877e 100644 --- a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs @@ -79,10 +79,20 @@ namespace osu.Game.Overlays.Direct if (attachedRequest != null) { - State.Value = DownloadState.Downloading; - attachedRequest.Failure += onRequestFailure; - attachedRequest.DownloadProgressed += onRequestProgress; - attachedRequest.Success += onRequestSuccess; + if (attachedRequest.Progress == 1) + { + State.Value = DownloadState.Downloaded; + Progress.Value = 1; + } + else + { + State.Value = DownloadState.Downloading; + Progress.Value = attachedRequest.Progress; + + attachedRequest.Failure += onRequestFailure; + attachedRequest.DownloadProgressed += onRequestProgress; + attachedRequest.Success += onRequestSuccess; + } } else {