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

@ -23,6 +23,16 @@ namespace osu.Game.Database
/// <returns>The imported models.</returns>
Task<IEnumerable<Live<TModel>>> Import(ProgressNotification notification, params ImportTask[] tasks);
/// <summary>
/// Process a single import as an update for an existing model.
/// This will still run a full import, but perform any post-processing required to make it feel like an update to the user.
/// </summary>
/// <param name="notification">The notification to update.</param>
/// <param name="task">The import task.</param>
/// <param name="original">The original model which is being updated.</param>
/// <returns>The imported model.</returns>
Task<Live<TModel>?> ImportAsUpdate(ProgressNotification notification, ImportTask task, TModel original);
/// <summary>
/// A user displayable name for the model type associated with this manager.
/// </summary>

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;

View File

@ -174,6 +174,8 @@ namespace osu.Game.Database
return imported;
}
public virtual Task<Live<TModel>?> ImportAsUpdate(ProgressNotification notification, ImportTask task, TModel original) => throw new NotImplementedException();
/// <summary>
/// Import one <typeparamref name="TModel"/> from the filesystem and delete the file on success.
/// Note that this bypasses the UI flow and should only be used for special cases or testing.