Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Button to restore recently deleted beatmaps #1671

Merged
merged 18 commits into from Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
69f28df
Merge branch 'master' of https://github.com/ppy/osu
FreezyLemon Nov 26, 2017
bf38659
Added a new "undelete" button that restores every beatmap with "Delet…
FreezyLemon Nov 30, 2017
b09ba19
Used the already-existing private method to undelete a mapset
FreezyLemon Nov 30, 2017
ee9fe64
Merge branch 'master' of https://github.com/freezylemon/osu
FreezyLemon Dec 2, 2017
d93a1fd
Merge branch 'master' of https://github.com/ppy/osu into undelete-but…
FreezyLemon Dec 8, 2017
e1c04a1
Added check for "menu music beatmap hash" before undeleting so circle…
FreezyLemon Dec 8, 2017
a01538a
Merge branch 'master' of https://github.com/freezylemon/osu
FreezyLemon Dec 8, 2017
491efe4
Merge branch 'master' of https://github.com/ppy/osu
FreezyLemon Dec 8, 2017
9c59385
Merge branch 'master' of https://github.com/ppy/osu
FreezyLemon Dec 9, 2017
1691a74
Merge branch 'undelete-button-add' of https://github.com/freezylemon/…
FreezyLemon Dec 10, 2017
8cbd6f3
Moved menu music hash property back to intro and changed check (befor…
FreezyLemon Dec 10, 2017
4c45102
Merge branch 'master' into undelete-button-add
peppy Dec 18, 2017
d2b80fd
Moved "undelete all" logic to BeatmapManager and added a progress not…
FreezyLemon Dec 18, 2017
ba61488
used Any() instead of manually checking count == 0 (CI)
FreezyLemon Dec 18, 2017
cbc1aac
Merge branch 'master' of https://github.com/ppy/osu into undelete-but…
FreezyLemon Dec 21, 2017
e4ead36
Added completion text
FreezyLemon Dec 21, 2017
a9039c7
Merge branch 'master' into undelete-button-add
peppy Dec 21, 2017
620e973
Avoid many many unnecessary enumerations
peppy Dec 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions osu.Game/Beatmaps/BeatmapManager.cs
Expand Up @@ -341,6 +341,61 @@ public void Delete(BeatmapSetInfo beatmapSet)
}
}

public void UndeleteAll()
{
var deleteMaps = QueryBeatmapSets(bs => bs.DeletePending).ToList();

if (!deleteMaps.Any()) return;

var notification = new ProgressNotification
{
CompletionText = "Restored all deleted beatmaps!",
Progress = 0,
State = ProgressNotificationState.Active,
};

PostNotification?.Invoke(notification);

int i = 0;

foreach (var bs in deleteMaps)
{
if (notification.State == ProgressNotificationState.Cancelled)
// user requested abort
return;

notification.Text = $"Restoring ({i} of {deleteMaps.Count})";
notification.Progress = (float)++i / deleteMaps.Count;
Undelete(bs);
}

notification.State = ProgressNotificationState.Completed;
}

public void Undelete(BeatmapSetInfo beatmapSet)
{
if (beatmapSet.Protected)
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>
Expand Down
10 changes: 10 additions & 0 deletions osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs
Expand Up @@ -15,6 +15,7 @@ public class GeneralSettings : SettingsSubsection
private TriangleButton importButton;
private TriangleButton deleteButton;
private TriangleButton restoreButton;
private TriangleButton undeleteButton;

protected override string Header => "General";

Expand Down Expand Up @@ -55,6 +56,15 @@ private void load(BeatmapManager beatmaps)
}).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true));
}
},
undeleteButton = new SettingsButton
{
Text = "Restore all recently deleted beatmaps",
Action = () =>
{
undeleteButton.Enabled.Value = false;
Task.Run(() => beatmaps.UndeleteAll()).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true));
}
},
};
}
}
Expand Down