1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

override LegacyScoreExporter.Export() to not overwrite files

This commit is contained in:
Piggey 2022-11-30 10:52:41 +01:00
parent f5d85f5774
commit 5e74c4e3b7

View File

@ -8,6 +8,7 @@ using System.Linq;
using osu.Framework.Platform;
using osu.Game.Extensions;
using osu.Game.Scoring;
using osu.Game.Utils;
namespace osu.Game.Database
{
@ -29,5 +30,22 @@ 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);
}
}
}