2023-09-04 07:17:21 +00: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.
|
|
|
|
|
|
2023-09-04 08:53:12 +00:00
|
|
|
|
using System;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
using System.IO;
|
2023-09-04 08:37:31 +00:00
|
|
|
|
using System.Linq;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2023-09-18 12:03:55 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2023-09-18 12:03:55 +00:00
|
|
|
|
using osu.Game.Beatmaps.Drawables.Cards;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
using osu.Game.Scoring;
|
2023-09-04 08:53:12 +00:00
|
|
|
|
using Realms;
|
2023-09-18 12:09:06 +00:00
|
|
|
|
using osu.Game.Localisation;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
|
{
|
2023-09-18 12:30:06 +00:00
|
|
|
|
public partial class MissingBeatmapNotification : SimpleNotification
|
2023-09-04 07:17:21 +00:00
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapModelDownloader beatmapDownloader { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scoreManager { get; set; } = null!;
|
|
|
|
|
|
2023-09-04 08:37:31 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private RealmAccess realm { get; set; } = null!;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
2023-09-04 08:37:31 +00:00
|
|
|
|
private readonly MemoryStream scoreStream;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
private readonly APIBeatmapSet beatmapSetInfo;
|
2023-09-04 08:37:31 +00:00
|
|
|
|
private readonly string beatmapHash;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
2023-09-18 12:46:24 +00:00
|
|
|
|
private Bindable<bool> autoDownloadConfig = null!;
|
2023-09-04 08:14:04 +00:00
|
|
|
|
private Bindable<bool> noVideoSetting = null!;
|
2023-09-18 12:03:55 +00:00
|
|
|
|
private BeatmapCardNano card = null!;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
2023-09-04 08:53:12 +00:00
|
|
|
|
private IDisposable? realmSubscription;
|
|
|
|
|
|
2023-09-04 08:37:31 +00:00
|
|
|
|
public MissingBeatmapNotification(APIBeatmap beatmap, MemoryStream scoreStream, string beatmapHash)
|
2023-09-04 07:17:21 +00:00
|
|
|
|
{
|
|
|
|
|
beatmapSetInfo = beatmap.BeatmapSet!;
|
|
|
|
|
|
2023-09-04 08:37:31 +00:00
|
|
|
|
this.beatmapHash = beatmapHash;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
this.scoreStream = scoreStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-09-18 12:03:55 +00:00
|
|
|
|
private void load(OsuConfigManager config)
|
2023-09-04 07:17:21 +00:00
|
|
|
|
{
|
2023-09-04 08:53:12 +00:00
|
|
|
|
realmSubscription = realm.RegisterForNotifications(
|
|
|
|
|
realm => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending), beatmapsChanged);
|
|
|
|
|
|
2023-09-04 08:37:31 +00:00
|
|
|
|
realm.Run(r =>
|
|
|
|
|
{
|
2023-09-04 08:53:12 +00:00
|
|
|
|
if (r.All<BeatmapSetInfo>().Any(s => !s.DeletePending && s.OnlineID == beatmapSetInfo.OnlineID))
|
2023-09-04 08:37:31 +00:00
|
|
|
|
{
|
2023-09-18 12:09:06 +00:00
|
|
|
|
Text = NotificationsStrings.MismatchingBeatmapForReplay;
|
2023-09-04 08:37:31 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-18 12:46:24 +00:00
|
|
|
|
autoDownloadConfig = config.GetBindable<bool>(OsuSetting.AutomaticallyDownloadMissingBeatmaps);
|
2023-09-04 08:14:04 +00:00
|
|
|
|
noVideoSetting = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
2023-09-18 12:03:55 +00:00
|
|
|
|
Content.Add(card = new BeatmapCardNano(beatmapSetInfo));
|
2023-09-04 08:14:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
2023-09-18 12:46:24 +00:00
|
|
|
|
if (autoDownloadConfig.Value)
|
2023-09-04 08:14:04 +00:00
|
|
|
|
beatmapDownloader.Download(beatmapSetInfo, noVideoSetting.Value);
|
2023-09-18 12:54:25 +00:00
|
|
|
|
|
|
|
|
|
Text = autoDownloadConfig.Value ? NotificationsStrings.DownloadingBeatmapForReplay : NotificationsStrings.MissingBeatmapForReplay;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 12:03:55 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
card.Width = Content.DrawWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => false;
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e) { }
|
|
|
|
|
|
2023-09-04 08:53:12 +00:00
|
|
|
|
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet? changes)
|
2023-09-04 07:17:21 +00:00
|
|
|
|
{
|
2023-09-04 08:53:12 +00:00
|
|
|
|
if (changes?.InsertedIndices == null) return;
|
2023-09-04 07:17:21 +00:00
|
|
|
|
|
2023-09-04 08:53:12 +00:00
|
|
|
|
if (sender.Any(s => s.Beatmaps.Any(b => b.MD5Hash == beatmapHash)))
|
2023-09-04 08:37:31 +00:00
|
|
|
|
{
|
2023-09-04 08:53:12 +00:00
|
|
|
|
var importTask = new ImportTask(scoreStream, "score.osr");
|
2023-09-18 12:30:06 +00:00
|
|
|
|
scoreManager.Import(new[] { importTask });
|
2023-09-04 08:53:12 +00:00
|
|
|
|
realmSubscription?.Dispose();
|
|
|
|
|
}
|
2023-09-04 07:17:21 +00:00
|
|
|
|
}
|
2023-09-04 15:21:08 +00:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
realmSubscription?.Dispose();
|
|
|
|
|
}
|
2023-09-04 07:17:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|