mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 18:13:09 +08:00
override a sub-method instead of the whole Export()
This commit is contained in:
parent
498d00935b
commit
d392d1a5c0
@ -33,17 +33,17 @@ namespace osu.Game.Database
|
|||||||
UserFileStorage = storage.GetStorageForDirectory(@"files");
|
UserFileStorage = storage.GetStorageForDirectory(@"files");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual string GetItemExportString(TModel item) => item.GetDisplayString().GetValidFilename();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exports an item to a legacy (.zip based) package.
|
/// Exports an item to a legacy (.zip based) package.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item to export.</param>
|
/// <param name="item">The item to export.</param>
|
||||||
public virtual void Export(TModel item)
|
public void Export(TModel item)
|
||||||
{
|
{
|
||||||
string itemFilename = item.GetDisplayString().GetValidFilename();
|
IEnumerable<string> existingExports = exportStorage.GetFiles("", $"{GetItemExportString(item)}*{FileExtension}");
|
||||||
|
|
||||||
IEnumerable<string> existingExports = exportStorage.GetFiles("", $"{itemFilename}*{FileExtension}");
|
string filename = NamingUtils.GetNextBestFilename(existingExports, $"{GetItemExportString(item)}{FileExtension}");
|
||||||
|
|
||||||
string filename = NamingUtils.GetNextBestFilename(existingExports, $"{itemFilename}{FileExtension}");
|
|
||||||
using (var stream = exportStorage.CreateFileSafely(filename))
|
using (var stream = exportStorage.CreateFileSafely(filename))
|
||||||
ExportModelTo(item, stream);
|
ExportModelTo(item, stream);
|
||||||
|
|
||||||
|
@ -3,13 +3,11 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Utils;
|
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
@ -17,27 +15,17 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
protected override string FileExtension => ".osr";
|
protected override string FileExtension => ".osr";
|
||||||
|
|
||||||
private readonly Storage exportStorage;
|
|
||||||
|
|
||||||
public LegacyScoreExporter(Storage storage)
|
public LegacyScoreExporter(Storage storage)
|
||||||
: base(storage)
|
: base(storage)
|
||||||
{
|
{
|
||||||
exportStorage = storage.GetStorageForDirectory(@"exports");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetScoreExportString(ScoreInfo score) => $"{score.GetDisplayString()} ({score.Date.LocalDateTime:yyyy-MM-dd})";
|
protected override string GetItemExportString(ScoreInfo score)
|
||||||
|
|
||||||
public override void Export(ScoreInfo score)
|
|
||||||
{
|
{
|
||||||
string scoreExportTitle = GetScoreExportString(score).GetValidFilename();
|
string scoreString = score.GetDisplayString();
|
||||||
|
string filename = $"{scoreString} ({score.Date.LocalDateTime:yyyy-MM-dd})";
|
||||||
|
|
||||||
IEnumerable<string> existingExports = exportStorage.GetFiles("", $"{scoreExportTitle}*{FileExtension}");
|
return filename.GetValidFilename();
|
||||||
|
|
||||||
string scoreExportFilename = NamingUtils.GetNextBestFilename(existingExports, $"{scoreExportTitle}{FileExtension}");
|
|
||||||
using (var stream = exportStorage.CreateFileSafely(scoreExportFilename))
|
|
||||||
ExportModelTo(score, stream);
|
|
||||||
|
|
||||||
exportStorage.PresentFileExternally(scoreExportFilename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ExportModelTo(ScoreInfo model, Stream outputStream)
|
public override void ExportModelTo(ScoreInfo model, Stream outputStream)
|
||||||
|
Loading…
Reference in New Issue
Block a user