1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 18:27:26 +08:00

Merge branch 'undelete-button-add' of https://github.com/freezylemon/osu into undelete-button-add

This commit is contained in:
FreezyLemon 2017-12-10 11:26:31 +01:00
commit 1691a74b14
3 changed files with 45 additions and 3 deletions

View File

@ -34,6 +34,11 @@ namespace osu.Game.Beatmaps
/// </summary>
public class BeatmapManager
{
/// <summary>
/// The hash of the supplied menu music's beatmap set.
/// </summary>
public const string MENU_MUSIC_BEATMAP_HASH = "3c8b1fcc9434dbb29e2fb613d3b9eada9d7bb6c125ceb32396c3b53437280c83";
/// <summary>
/// Fired when a new <see cref="BeatmapSetInfo"/> becomes available in the database.
/// </summary>
@ -339,6 +344,31 @@ namespace osu.Game.Beatmaps
}
}
public void Undelete(BeatmapSetInfo beatmapSet)
{
// So circles.osz doesn't get added as a map
if (beatmapSet.Hash == MENU_MUSIC_BEATMAP_HASH)
return;
lock (importContext)
{
var context = importContext.Value;
using (var transaction = context.BeginTransaction())
{
context.ChangeTracker.AutoDetectChangesEnabled = false;
var iFiles = new FileStore(() => context, storage);
var iBeatmaps = createBeatmapStore(() => context);
undelete(iBeatmaps, iFiles, beatmapSet);
context.ChangeTracker.AutoDetectChangesEnabled = true;
context.SaveChanges(transaction);
}
}
}
/// <summary>
/// Delete a beatmap difficulty.
/// </summary>

View File

@ -15,6 +15,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
private TriangleButton importButton;
private TriangleButton deleteButton;
private TriangleButton restoreButton;
private TriangleButton undeleteButton;
protected override string Header => "General";
@ -55,6 +56,19 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
}).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true));
}
},
undeleteButton = new SettingsButton
{
Text = "Restore all recently deleted beatmaps",
Action = () =>
{
undeleteButton.Enabled.Value = false;
Task.Run(() =>
{
foreach (var bs in beatmaps.QueryBeatmapSets(bs => bs.DeletePending).ToList())
beatmaps.Undelete(bs);
}).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true));
}
},
};
}
}

View File

@ -20,8 +20,6 @@ namespace osu.Game.Screens.Menu
{
public class Intro : OsuScreen
{
private const string menu_music_beatmap_hash = "3c8b1fcc9434dbb29e2fb613d3b9eada9d7bb6c125ceb32396c3b53437280c83";
/// <summary>
/// Whether we have loaded the menu previously.
/// </summary>
@ -58,7 +56,7 @@ namespace osu.Game.Screens.Menu
if (setInfo == null)
{
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == menu_music_beatmap_hash);
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapManager.MENU_MUSIC_BEATMAP_HASH);
if (setInfo == null)
{