mirror of https://github.com/ppy/osu
LINQ-ify Import() logic and ignore case of file extensions.
This commit is contained in:
parent
f1aefcdf86
commit
6a80e1303d
|
@ -397,18 +397,13 @@ public async Task Import(params string[] paths)
|
||||||
|
|
||||||
public virtual async Task Import(params ImportTask[] tasks)
|
public virtual async Task Import(params ImportTask[] tasks)
|
||||||
{
|
{
|
||||||
var importTasks = new List<Task>();
|
var extensions = tasks.Select(t => Path.GetExtension(t.Path).ToLowerInvariant()).Distinct();
|
||||||
|
await Task.WhenAll(extensions.Select(ext =>
|
||||||
foreach (var extension in tasks.Select(t => Path.GetExtension(t.Path)).Distinct())
|
|
||||||
{
|
{
|
||||||
var importList = tasks.Where(t => t.Path.EndsWith(extension, StringComparison.OrdinalIgnoreCase));
|
var imports = tasks.Where(t => t.Path.EndsWith(ext, StringComparison.OrdinalIgnoreCase));
|
||||||
var importer = fileImporters.FirstOrDefault(i => i.HandledExtensions.Contains(extension));
|
|
||||||
|
|
||||||
if (importer != null)
|
return fileImporters.FirstOrDefault(i => i.HandledExtensions.Contains(ext))?.Import(imports.ToArray()) ?? Task.CompletedTask;
|
||||||
importTasks.Add(importer.Import(importList.ToArray()));
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
await Task.WhenAll(importTasks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions);
|
public IEnumerable<string> HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions);
|
||||||
|
|
Loading…
Reference in New Issue