1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

oh wait this affects all of the legacy exporters

This commit is contained in:
Piggey 2022-11-30 11:06:44 +01:00
parent f0b8b53e81
commit 660ad913ec
2 changed files with 15 additions and 24 deletions

View File

@ -4,8 +4,10 @@
#nullable disable
using System.IO;
using System.Linq;
using osu.Framework.Platform;
using osu.Game.Extensions;
using osu.Game.Utils;
using SharpCompress.Archives.Zip;
namespace osu.Game.Database
@ -23,11 +25,11 @@ namespace osu.Game.Database
protected readonly Storage UserFileStorage;
protected readonly Storage ExportStorage;
private readonly Storage exportStorage;
protected LegacyExporter(Storage storage)
{
ExportStorage = storage.GetStorageForDirectory(@"exports");
exportStorage = storage.GetStorageForDirectory(@"exports");
UserFileStorage = storage.GetStorageForDirectory(@"files");
}
@ -35,14 +37,21 @@ namespace osu.Game.Database
/// Exports an item to a legacy (.zip based) package.
/// </summary>
/// <param name="item">The item to export.</param>
public virtual void Export(TModel item)
public void Export(TModel item)
{
string filename = $"{item.GetDisplayString().GetValidFilename()}{FileExtension}";
var itemFilename = item.GetDisplayString().GetValidFilename();
using (var stream = ExportStorage.CreateFileSafely(filename))
var existingExports = exportStorage.GetFiles("", $"{itemFilename}*{FileExtension}").ToArray();
// trim the file extension
for (int i = 0; i < existingExports.Length; i++)
existingExports[i] = existingExports[i].TrimEnd(FileExtension.ToCharArray());
string filename = $"{NamingUtils.GetNextBestName(existingExports, itemFilename)}{FileExtension}";
using (var stream = exportStorage.CreateFileSafely(filename))
ExportModelTo(item, stream);
ExportStorage.PresentFileExternally(filename);
exportStorage.PresentFileExternally(filename);
}
/// <summary>

View File

@ -8,7 +8,6 @@ using System.Linq;
using osu.Framework.Platform;
using osu.Game.Extensions;
using osu.Game.Scoring;
using osu.Game.Utils;
namespace osu.Game.Database
{
@ -30,22 +29,5 @@ namespace osu.Game.Database
using (var inputStream = UserFileStorage.GetStream(file.File.GetStoragePath()))
inputStream.CopyTo(outputStream);
}
public override void Export(ScoreInfo item)
{
var itemFilename = item.GetDisplayString().GetValidFilename();
var existingExports = ExportStorage.GetFiles("", $"{itemFilename}*{FileExtension}").ToArray();
// trim the file extension
for (int i = 0; i < existingExports.Length; i++)
existingExports[i] = existingExports[i].TrimEnd(FileExtension.ToCharArray());
string filename = $"{NamingUtils.GetNextBestName(existingExports, itemFilename)}{FileExtension}";
using (var stream = ExportStorage.CreateFileSafely(filename))
ExportModelTo(item, stream);
ExportStorage.PresentFileExternally(filename);
}
}
}