1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Add ability to perform a download request with options

This commit is contained in:
naoey 2019-06-11 20:14:36 +05:30
parent 8ff26a8fbc
commit 802f48712d
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60
2 changed files with 28 additions and 3 deletions

View File

@ -78,7 +78,7 @@ namespace osu.Game.Beatmaps
beatmaps.BeatmapRestored += b => BeatmapRestored?.Invoke(b);
}
protected override DownloadBeatmapSetRequest CreateDownloadRequest(BeatmapSetInfo set) => new DownloadBeatmapSetRequest(set, false);
protected override DownloadBeatmapSetRequest CreateDownloadRequest(BeatmapSetInfo set, object[] options) => new DownloadBeatmapSetRequest(set, (options?.FirstOrDefault() as bool?) ?? false);
protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive)
{

View File

@ -43,7 +43,15 @@ namespace osu.Game.Database
this.api = api;
}
protected abstract TDownloadRequestModel CreateDownloadRequest(TModel model);
/// <summary>
/// Creates the download request for this <see cref="TModel"/>.
/// The <paramref name="options"/> parameters will be provided when the download was initiated with extra options meant
/// to be used in the creation of the request.
/// </summary>
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
/// <param name="options">Extra parameters for request creation, null if none were passed.</param>
/// <returns>The request object.</returns>
protected abstract TDownloadRequestModel CreateDownloadRequest(TModel model, object[] options);
/// <summary>
/// Downloads a <see cref="TModel"/>.
@ -55,7 +63,24 @@ namespace osu.Game.Database
{
if (!canDownload(model)) return false;
var request = CreateDownloadRequest(model);
var request = CreateDownloadRequest(model, null);
performDownloadWithRequest(request);
return true;
}
/// <summary>
/// Downloads a <see cref="TModel"/> with optional parameters for the download request.
/// </summary>
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
/// <param name="extra">Optional parameters to be used for creating the download request.</param>
/// <returns>Whether downloading can happen.</returns>
public bool Download(TModel model, params object[] extra)
{
if (!canDownload(model)) return false;
var request = CreateDownloadRequest(model, extra);
performDownloadWithRequest(request);