1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Update BeatmapModelManager.Save to work for editor scenarios

This commit is contained in:
Dean Herbert 2022-01-11 18:17:13 +09:00
parent dc9ea4adeb
commit 7509a9ff8f
3 changed files with 19 additions and 27 deletions

View File

@ -82,7 +82,7 @@ namespace osu.Game.Beatmaps
}
};
var set = new BeatmapSetInfo
var beatmapSet = new BeatmapSetInfo
{
Beatmaps =
{
@ -97,7 +97,10 @@ namespace osu.Game.Beatmaps
}
};
var imported = beatmapModelManager.Import(set).GetResultSafely();
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
b.BeatmapSet = beatmapSet;
var imported = beatmapModelManager.Import(beatmapSet).GetResultSafely();
if (imported == null)
throw new InvalidOperationException("Failed to import new beatmap");

View File

@ -70,35 +70,27 @@ namespace osu.Game.Beatmaps
stream.Seek(0, SeekOrigin.Begin);
using (var realm = ContextFactory.CreateContext())
using (var transaction = realm.BeginWrite())
{
beatmapInfo = setInfo.Beatmaps.Single(b => b.Equals(beatmapInfo));
// AddFile generally handles updating/replacing files, but this is a case where the filename may have also changed so let's delete for simplicity.
var existingFileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase));
if (existingFileInfo != null)
DeleteFile(setInfo, existingFileInfo);
// grab the original file (or create a new one if not found).
var existingFileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase));
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
beatmapInfo.Hash = stream.ComputeSHA2Hash();
if (existingFileInfo != null)
{
DeleteFile(setInfo, existingFileInfo);
}
// metadata may have changed; update the path with the standard format.
var metadata = beatmapInfo.Metadata;
string filename = $"{metadata.Artist} - {metadata.Title} ({metadata.Author}) [{beatmapInfo.DifficultyName}].osu".GetValidArchiveContentFilename();
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
stream.Seek(0, SeekOrigin.Begin);
AddFile(setInfo, stream, filename, realm);
transaction.Commit();
}
AddFile(setInfo, stream, getFilename(beatmapInfo));
Update(setInfo);
}
WorkingBeatmapCache?.Invalidate(beatmapInfo);
}
private static string getFilename(BeatmapInfo beatmapInfo)
{
var metadata = beatmapInfo.Metadata;
return $"{metadata.Artist} - {metadata.Title} ({metadata.Author}) [{beatmapInfo.DifficultyName}].osu".GetValidArchiveContentFilename();
}
/// <summary>
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
/// </summary>

View File

@ -356,9 +356,6 @@ namespace osu.Game.Screens.Edit
// no longer new after first user-triggered save.
isNewBeatmap = false;
// apply any set-level metadata changes.
beatmapManager.Update(editorBeatmap.BeatmapInfo.BeatmapSet);
// save the loaded beatmap's data stream.
beatmapManager.Save(editorBeatmap.BeatmapInfo, editorBeatmap.PlayableBeatmap, editorBeatmap.BeatmapSkin);