2021-09-30 17:21:16 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-07-25 17:52:53 +08:00
|
|
|
using osu.Framework.Logging;
|
2021-09-30 17:21:16 +08:00
|
|
|
using osu.Game.Database;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
{
|
2021-11-05 16:37:05 +08:00
|
|
|
public class BeatmapModelDownloader : ModelDownloader<BeatmapSetInfo, IBeatmapSetInfo>
|
2021-09-30 17:21:16 +08:00
|
|
|
{
|
2021-11-05 16:37:05 +08:00
|
|
|
protected override ArchiveDownloadRequest<IBeatmapSetInfo> CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) =>
|
2021-09-30 17:21:16 +08:00
|
|
|
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
|
|
|
|
|
2022-07-19 19:06:19 +08:00
|
|
|
public override ArchiveDownloadRequest<IBeatmapSetInfo>? GetExistingDownload(IBeatmapSetInfo model)
|
2021-10-27 19:02:51 +08:00
|
|
|
=> CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID);
|
|
|
|
|
2021-11-25 16:42:41 +08:00
|
|
|
public BeatmapModelDownloader(IModelImporter<BeatmapSetInfo> beatmapImporter, IAPIProvider api)
|
|
|
|
: base(beatmapImporter, api)
|
2021-09-30 17:21:16 +08:00
|
|
|
{
|
|
|
|
}
|
2022-07-25 17:52:53 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-09-30 17:21:16 +08:00
|
|
|
}
|
|
|
|
}
|