Add checksum validation to the panel download buttons

This commit is contained in:
smoogipoo 2020-06-02 14:04:51 +09:00
parent b41bb5a682
commit 17e91695e0
1 changed files with 25 additions and 4 deletions

View File

@ -188,7 +188,7 @@ private void refresh()
X = -18,
Children = new Drawable[]
{
new PlaylistDownloadButton(item.Beatmap.Value.BeatmapSet)
new PlaylistDownloadButton(item)
{
Size = new Vector2(50, 30)
},
@ -212,9 +212,15 @@ protected override bool OnClick(ClickEvent e)
private class PlaylistDownloadButton : BeatmapPanelDownloadButton
{
public PlaylistDownloadButton(BeatmapSetInfo beatmapSet)
: base(beatmapSet)
private readonly PlaylistItem playlistItem;
[Resolved]
private BeatmapManager beatmapManager { get; set; }
public PlaylistDownloadButton(PlaylistItem playlistItem)
: base(playlistItem.Beatmap.Value.BeatmapSet)
{
this.playlistItem = playlistItem;
Alpha = 0;
}
@ -223,11 +229,26 @@ protected override void LoadComplete()
base.LoadComplete();
State.BindValueChanged(stateChanged, true);
FinishTransforms(true);
}
private void stateChanged(ValueChangedEvent<DownloadState> state)
{
this.FadeTo(state.NewValue == DownloadState.LocallyAvailable ? 0 : 1, 500);
switch (state.NewValue)
{
case DownloadState.LocallyAvailable:
// Perform a local query of the beatmap by beatmap checksum, and reset the state if not matching.
if (beatmapManager.QueryBeatmap(b => b.MD5Hash == playlistItem.Beatmap.Value.MD5Hash) == null)
State.Value = DownloadState.NotDownloaded;
else
this.FadeTo(0, 500);
break;
default:
this.FadeTo(1, 500);
break;
}
}
}