mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Fix old version of beatmap potentially not being deleted during update flow
This can happen if the online IDs are not present in the `.osu` files. Previously this was only working due to the early logic in the import process (that relies on matching all online IDs perfectly).
This commit is contained in:
parent
6a3e8e31de
commit
b7f6413bce
@ -1,6 +1,7 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
@ -19,5 +20,24 @@ namespace osu.Game.Beatmaps
|
||||
: base(beatmapImporter, api)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Update(BeatmapSetInfo model)
|
||||
{
|
||||
return Download(model, false, onSuccess);
|
||||
|
||||
void onSuccess(Live<BeatmapSetInfo> imported)
|
||||
{
|
||||
imported.PerformWrite(updated =>
|
||||
{
|
||||
Logger.Log($"Beatmap \"{updated}\"update completed successfully", LoggingTarget.Database);
|
||||
|
||||
var original = updated.Realm.Find<BeatmapSetInfo>(model.ID);
|
||||
|
||||
// Generally the import process will do this for us if the OnlineIDs match,
|
||||
// but that isn't a guarantee (ie. if the .osu file doesn't have OnlineIDs populated).
|
||||
original.DeletePending = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,9 @@ namespace osu.Game.Database
|
||||
/// <returns>The request object.</returns>
|
||||
protected abstract ArchiveDownloadRequest<T> CreateDownloadRequest(T model, bool minimiseDownloadSize);
|
||||
|
||||
public bool Download(T model, bool minimiseDownloadSize = false)
|
||||
public bool Download(T model, bool minimiseDownloadSize = false) => Download(model, minimiseDownloadSize, null);
|
||||
|
||||
protected bool Download(T model, bool minimiseDownloadSize, Action<Live<TModel>>? onSuccess)
|
||||
{
|
||||
if (!canDownload(model)) return false;
|
||||
|
||||
@ -67,7 +69,9 @@ namespace osu.Game.Database
|
||||
var imported = await importer.Import(notification, new ImportTask(filename)).ConfigureAwait(false);
|
||||
|
||||
// for now a failed import will be marked as a failed download for simplicity.
|
||||
if (!imported.Any())
|
||||
if (imported.Any())
|
||||
onSuccess?.Invoke(imported.Single());
|
||||
else
|
||||
DownloadFailed?.Invoke(request);
|
||||
|
||||
CurrentDownloads.Remove(request);
|
||||
|
@ -90,7 +90,7 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
|
||||
Action = () =>
|
||||
{
|
||||
beatmapDownloader.Download(beatmapSetInfo);
|
||||
beatmapDownloader.Update(beatmapSetInfo);
|
||||
attachExistingDownload();
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user