Hook up ImportParameter flow with IModelImporter caller methods

This commit is contained in:
Dean Herbert
2022-12-13 21:03:25 +09:00
parent 6bb612ce69
commit cb16d62700
15 changed files with 39 additions and 25 deletions

View File

@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using osu.Game.Beatmaps;
namespace osu.Game.Database
{
@ -31,7 +32,8 @@ namespace osu.Game.Database
/// This will post notifications tracking progress.
/// </remarks>
/// <param name="tasks">The import tasks from which the files should be imported.</param>
Task Import(params ImportTask[] tasks);
/// <param name="parameters">Parameters to further configure the import process.</param>
Task Import(ImportTask[] tasks, ImportParameters parameters = default);
/// <summary>
/// An array of accepted file extensions (in the standard format of ".abc").

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using osu.Game.Beatmaps;
using osu.Game.Overlays.Notifications;
namespace osu.Game.Database
@ -20,8 +21,9 @@ namespace osu.Game.Database
/// </summary>
/// <param name="notification">The notification to update.</param>
/// <param name="tasks">The import tasks.</param>
/// <param name="parameters">Parameters to further configure the import process.</param>
/// <returns>The imported models.</returns>
Task<IEnumerable<Live<TModel>>> Import(ProgressNotification notification, params ImportTask[] tasks);
Task<IEnumerable<Live<TModel>>> Import(ProgressNotification notification, ImportTask[] tasks, ImportParameters parameters = default);
/// <summary>
/// Process a single import as an update for an existing model.

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.IO;
namespace osu.Game.Database
@ -57,7 +58,12 @@ namespace osu.Game.Database
return Task.CompletedTask;
}
return Task.Run(async () => await Importer.Import(GetStableImportPaths(storage).ToArray()).ConfigureAwait(false));
return Task.Run(async () =>
{
var tasks = GetStableImportPaths(storage).Select(p => new ImportTask(p)).ToArray();
await Importer.Import(tasks, new ImportParameters { Batch = true, PreferHardLinks = true }).ConfigureAwait(false);
});
}
/// <summary>

View File

@ -73,7 +73,7 @@ namespace osu.Game.Database
if (originalModel != null)
importSuccessful = (await importer.ImportAsUpdate(notification, new ImportTask(filename), originalModel)) != null;
else
importSuccessful = (await importer.Import(notification, new ImportTask(filename))).Any();
importSuccessful = (await importer.Import(notification, new[] { new ImportTask(filename) })).Any();
// for now a failed import will be marked as a failed download for simplicity.
if (!importSuccessful)

View File

@ -82,16 +82,16 @@ namespace osu.Game.Database
public Task Import(params string[] paths) => Import(paths.Select(p => new ImportTask(p)).ToArray());
public Task Import(params ImportTask[] tasks)
public Task Import(ImportTask[] tasks, ImportParameters parameters = default)
{
var notification = new ProgressNotification { State = ProgressNotificationState.Active };
PostNotification?.Invoke(notification);
return Import(notification, tasks);
return Import(notification, tasks, parameters);
}
public async Task<IEnumerable<Live<TModel>>> Import(ProgressNotification notification, params ImportTask[] tasks)
public async Task<IEnumerable<Live<TModel>>> Import(ProgressNotification notification, ImportTask[] tasks, ImportParameters parameters = default)
{
if (tasks.Length == 0)
{
@ -107,7 +107,7 @@ namespace osu.Game.Database
var imported = new List<Live<TModel>>();
bool isBatchImport = tasks.Length >= minimum_items_considered_batch_import;
parameters.Batch |= tasks.Length >= minimum_items_considered_batch_import;
await Task.WhenAll(tasks.Select(async task =>
{
@ -116,7 +116,7 @@ namespace osu.Game.Database
try
{
var model = await Import(task, new ImportParameters { Batch = isBatchImport }, notification.CancellationToken).ConfigureAwait(false);
var model = await Import(task, parameters, notification.CancellationToken).ConfigureAwait(false);
lock (imported)
{