1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 09:22:54 +08:00
osu-lazer/osu.Game/Online/API/APIDownloadRequest.cs
2019-01-29 18:34:10 +09:00

37 lines
1016 B
C#

// 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.
using System.IO;
using osu.Framework.IO.Network;
namespace osu.Game.Online.API
{
public abstract class APIDownloadRequest : APIRequest
{
private string filename;
protected override WebRequest CreateWebRequest()
{
var request = new FileWebRequest(filename = Path.GetTempFileName(), Uri);
request.DownloadProgress += request_Progress;
return request;
}
private void request_Progress(long current, long total) => API.Schedule(() => Progress?.Invoke(current, total));
protected APIDownloadRequest()
{
base.Success += onSuccess;
}
private void onSuccess()
{
Success?.Invoke(filename);
}
public event APIProgressHandler Progress;
public new event APISuccessHandler<string> Success;
}
}