mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 06:42:54 +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>
|
/// <summary>
|
||||||
/// Export te model corresponding to uuid to given stream.
|
/// Export te model corresponding to model to given stream.
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="stream">The stream to export.</param>
|
||||||
/// <returns></returns>
|
/// <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(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
RealmAccess.Run(r =>
|
RealmAccess.Run(r =>
|
||||||
{
|
{
|
||||||
TModel model = r.Find<TModel>(id);
|
TModel refetchModel = r.Find<TModel>(id);
|
||||||
createZipArchive(model, stream);
|
ExportToStream(refetchModel, stream);
|
||||||
});
|
});
|
||||||
}).ContinueWith(OnComplete);
|
}).ContinueWith(OnComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void ExportToStream(TModel model, Stream outputStream) => createZipArchive(model, outputStream);
|
||||||
|
|
||||||
private void createZipArchive(TModel model, Stream outputStream)
|
private void createZipArchive(TModel model, Stream outputStream)
|
||||||
{
|
{
|
||||||
using (var archive = ZipArchive.Create())
|
using (var archive = ZipArchive.Create())
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
@ -20,22 +19,14 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
protected override string FileExtension => ".osr";
|
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(() =>
|
var file = model.Files.SingleOrDefault();
|
||||||
{
|
if (file == null)
|
||||||
RealmAccess.Run(r =>
|
return;
|
||||||
{
|
|
||||||
ScoreInfo model = r.Find<ScoreInfo>(uuid.ID);
|
|
||||||
|
|
||||||
var file = model.Files.SingleOrDefault();
|
using (var inputStream = UserFileStorage.GetStream(file.File.GetStoragePath()))
|
||||||
if (file == null)
|
inputStream.CopyTo(stream);
|
||||||
return;
|
|
||||||
|
|
||||||
using (var inputStream = UserFileStorage.GetStream(file.File.GetStoragePath()))
|
|
||||||
inputStream.CopyTo(stream);
|
|
||||||
});
|
|
||||||
}).ContinueWith(OnComplete);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user