mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Move implementation of updating a beatmap to BeatmapImporter
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user