Move implementation of updating a beatmap to BeatmapImporter

This commit is contained in:
Dean Herbert
2022-07-25 19:31:46 +09:00
parent 2363a3fb7b
commit 2e14d8730c
6 changed files with 89 additions and 59 deletions

View File

@ -44,7 +44,7 @@ namespace osu.Game.Database
public bool Download(T model, bool minimiseDownloadSize = false) => Download(model, minimiseDownloadSize, null);
protected bool Download(T model, bool minimiseDownloadSize, Action<Live<TModel>>? onSuccess)
protected bool Download(T model, bool minimiseDownloadSize, TModel? originalModel)
{
if (!canDownload(model)) return false;
@ -66,12 +66,10 @@ namespace osu.Game.Database
Task.Factory.StartNew(async () =>
{
// This gets scheduled back to the update thread, but we want the import to run in the background.
var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false);
var imported = await Import(notification, filename, originalModel).ConfigureAwait(false);
// for now a failed import will be marked as a failed download for simplicity.
if (imported.Any())
onSuccess?.Invoke(imported.Single());
else
if (!imported.Any())
DownloadFailed?.Invoke(request);
CurrentDownloads.Remove(request);
@ -107,6 +105,18 @@ namespace osu.Game.Database
}
}
/// <summary>
/// Run the post-download import for the model.
/// </summary>
/// <param name="notification">The notification to update.</param>
/// <param name="filename">The path of the temporary downloaded file.</param>
/// <param name="originalModel">An optional model for update scenarios, to be used as a reference.</param>
/// <returns>The imported model.</returns>
protected virtual Task<IEnumerable<Live<TModel>>> Import(ProgressNotification notification, string filename, TModel? originalModel)
{
return importer.Import(notification, new ImportTask(filename));
}
public abstract ArchiveDownloadRequest<T>? GetExistingDownload(T model);
private bool canDownload(T model) => GetExistingDownload(model) == null && api != null;