mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 15:23:14 +08:00
Add ability to import files from a stream.
This commit is contained in:
parent
2e5a40eddf
commit
005fa3a7ee
@ -212,6 +212,14 @@ namespace osu.Game.Database
|
||||
return import;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Import one <typeparamref name="TModel"/> from a <see cref="Stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to import files from.</param>
|
||||
/// <param name="filename">The filename of the archive being imported.</param>
|
||||
public async Task Import(Stream stream, string filename)
|
||||
=> await Import(new ZipArchiveReader(stream, filename)); // we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info
|
||||
|
||||
/// <summary>
|
||||
/// Fired when the user requests to view the resulting import.
|
||||
/// </summary>
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Database
|
||||
@ -17,6 +18,14 @@ namespace osu.Game.Database
|
||||
/// <param name="paths">The files which should be imported.</param>
|
||||
Task Import(params string[] paths);
|
||||
|
||||
/// <summary>
|
||||
/// Import the specified stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to import files from.</param>
|
||||
/// <param name="filename">The filename of the archive being imported.</param>
|
||||
/// <returns></returns>
|
||||
Task Import(Stream stream, string filename);
|
||||
|
||||
/// <summary>
|
||||
/// An array of accepted file extensions (in the standard format of ".abc").
|
||||
/// </summary>
|
||||
|
@ -395,6 +395,17 @@ namespace osu.Game
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Import(Stream stream, string filename)
|
||||
{
|
||||
var extension = Path.GetExtension(filename)?.ToLowerInvariant();
|
||||
|
||||
foreach (var importer in fileImporters)
|
||||
{
|
||||
if (importer.HandledExtensions.Contains(extension))
|
||||
await importer.Import(stream, Path.GetFileNameWithoutExtension(filename));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions);
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -99,6 +99,8 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Task ICanAcceptFiles.Import(Stream stream, string filename) => Task.CompletedTask;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
Loading…
Reference in New Issue
Block a user