Add ImportAsUpdate method to IModelImporter to avoid otehr changes

This commit is contained in:
Dean Herbert
2022-07-26 15:46:29 +09:00
parent 7d8a78ef01
commit 8370ca9765
11 changed files with 30 additions and 38 deletions

View File

@ -44,6 +44,8 @@ namespace osu.Game.Database
public bool Download(T model, bool minimiseDownloadSize = false) => Download(model, minimiseDownloadSize, null);
public void DownloadAsUpdate(TModel originalModel) => Download(originalModel, false, originalModel);
protected bool Download(T model, bool minimiseDownloadSize, TModel? originalModel)
{
if (!canDownload(model)) return false;
@ -66,7 +68,7 @@ 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 Import(notification, filename, originalModel).ConfigureAwait(false);
var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false);
// for now a failed import will be marked as a failed download for simplicity.
if (!imported.Any())
@ -105,18 +107,6 @@ 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;