mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Spite sync method ExportToStream
`uuid` to `model`
This commit is contained in:
parent
c509c5be40
commit
6adac853e8
@ -74,24 +74,26 @@ namespace osu.Game.Database
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export te model corresponding to uuid to given stream.
|
||||
/// Export te model corresponding to model to given stream.
|
||||
/// </summary>
|
||||
/// <param name="uuid">The medel which have <see cref="IHasGuidPrimaryKey"/>.</param>
|
||||
/// <param name="model">The medel which have <see cref="IHasGuidPrimaryKey"/>.</param>
|
||||
/// <param name="stream">The stream to export.</param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task ExportToStreamAsync(TModel uuid, Stream stream)
|
||||
public async Task ExportToStreamAsync(TModel model, Stream stream)
|
||||
{
|
||||
Guid id = uuid.ID;
|
||||
Guid id = model.ID;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
RealmAccess.Run(r =>
|
||||
{
|
||||
TModel model = r.Find<TModel>(id);
|
||||
createZipArchive(model, stream);
|
||||
TModel refetchModel = r.Find<TModel>(id);
|
||||
ExportToStream(refetchModel, stream);
|
||||
});
|
||||
}).ContinueWith(OnComplete);
|
||||
}
|
||||
|
||||
protected virtual void ExportToStream(TModel model, Stream outputStream) => createZipArchive(model, outputStream);
|
||||
|
||||
private void createZipArchive(TModel model, Stream outputStream)
|
||||
{
|
||||
using (var archive = ZipArchive.Create())
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Overlays;
|
||||
@ -20,22 +19,14 @@ namespace osu.Game.Database
|
||||
|
||||
protected override string FileExtension => ".osr";
|
||||
|
||||
public override async Task ExportToStreamAsync(ScoreInfo uuid, Stream stream)
|
||||
protected override void ExportToStream(ScoreInfo model, Stream stream)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
RealmAccess.Run(r =>
|
||||
{
|
||||
ScoreInfo model = r.Find<ScoreInfo>(uuid.ID);
|
||||
|
||||
var file = model.Files.SingleOrDefault();
|
||||
if (file == null)
|
||||
return;
|
||||
|
||||
using (var inputStream = UserFileStorage.GetStream(file.File.GetStoragePath()))
|
||||
inputStream.CopyTo(stream);
|
||||
});
|
||||
}).ContinueWith(OnComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user