mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Implement button to delete all beatmap videos
This commit is contained in:
parent
02198d0436
commit
69351d2cdf
@ -319,6 +319,18 @@ namespace osu.Game.Beatmaps
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DeleteVideos(Expression<Func<BeatmapSetInfo, bool>>? filter = null, bool silent = false)
|
||||||
|
{
|
||||||
|
realm.Write(r =>
|
||||||
|
{
|
||||||
|
var items = r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected);
|
||||||
|
|
||||||
|
if (filter != null)
|
||||||
|
items = items.Where(filter);
|
||||||
|
beatmapModelManager.DeleteVideos(items.ToList(), silent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void UndeleteAll()
|
public void UndeleteAll()
|
||||||
{
|
{
|
||||||
realm.Run(r => beatmapModelManager.Undelete(r.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList()));
|
realm.Run(r => beatmapModelManager.Undelete(r.All<BeatmapSetInfo>().Where(s => s.DeletePending).ToList()));
|
||||||
|
@ -29,6 +29,11 @@ namespace osu.Game.Localisation
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static LocalisableString DeleteAllBeatmaps => new TranslatableString(getKey(@"delete_all_beatmaps"), @"Delete ALL beatmaps");
|
public static LocalisableString DeleteAllBeatmaps => new TranslatableString(getKey(@"delete_all_beatmaps"), @"Delete ALL beatmaps");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// "Delete ALL beatmap videos"
|
||||||
|
/// </summary>
|
||||||
|
public static LocalisableString DeleteAllBeatmapVideos => new TranslatableString(getKey(@"delete_all_beatmap_videos"), @"Delete ALL beatmap videos");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// "Import scores from stable"
|
/// "Import scores from stable"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -28,6 +28,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
private SettingsButton deleteSkinsButton;
|
private SettingsButton deleteSkinsButton;
|
||||||
private SettingsButton restoreButton;
|
private SettingsButton restoreButton;
|
||||||
private SettingsButton undeleteButton;
|
private SettingsButton undeleteButton;
|
||||||
|
private SettingsButton deleteBeatmapVideosButton;
|
||||||
|
|
||||||
[BackgroundDependencyLoader(permitNulls: true)]
|
[BackgroundDependencyLoader(permitNulls: true)]
|
||||||
private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] LegacyImportManager legacyImportManager, IDialogOverlay dialogOverlay)
|
private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] LegacyImportManager legacyImportManager, IDialogOverlay dialogOverlay)
|
||||||
@ -58,6 +59,19 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Add(deleteBeatmapVideosButton = new DangerousSettingsButton
|
||||||
|
{
|
||||||
|
Text = MaintenanceSettingsStrings.DeleteAllBeatmapVideos,
|
||||||
|
Action = () =>
|
||||||
|
{
|
||||||
|
dialogOverlay?.Push(new MassVideoDeleteConfirmationDialog(() =>
|
||||||
|
{
|
||||||
|
deleteBeatmapVideosButton.Enabled.Value = false;
|
||||||
|
Task.Run(() => beatmaps.DeleteVideos()).ContinueWith(t => Schedule(() => deleteBeatmapsButton.Enabled.Value = true));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (legacyImportManager?.SupportsImportFromStable == true)
|
if (legacyImportManager?.SupportsImportFromStable == true)
|
||||||
{
|
{
|
||||||
Add(importScoresButton = new SettingsButton
|
Add(importScoresButton = new SettingsButton
|
||||||
|
@ -29,4 +29,11 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class MassVideoDeleteConfirmationDialog : MassDeleteConfirmationDialog
|
||||||
|
{
|
||||||
|
public MassVideoDeleteConfirmationDialog(Action deleteAction) : base(deleteAction)
|
||||||
|
{
|
||||||
|
BodyText = "All beatmap videos? This cannot be undone!";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,44 @@ namespace osu.Game.Stores
|
|||||||
notification.State = ProgressNotificationState.Completed;
|
notification.State = ProgressNotificationState.Completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete videos from a list of items.
|
||||||
|
/// This will post notifications tracking progress.
|
||||||
|
/// </summary>
|
||||||
|
public void DeleteVideos(List<TModel> items, bool silent = false)
|
||||||
|
{
|
||||||
|
if (items.Count == 0) return;
|
||||||
|
|
||||||
|
var notification = new ProgressNotification
|
||||||
|
{
|
||||||
|
Progress = 0,
|
||||||
|
Text = $"Preparing to delete all {HumanisedModelName} videos...",
|
||||||
|
CompletionText = $"Deleted all {HumanisedModelName} videos!",
|
||||||
|
State = ProgressNotificationState.Active,
|
||||||
|
};
|
||||||
|
if (!silent)
|
||||||
|
PostNotification?.Invoke(notification);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
foreach (var b in items)
|
||||||
|
{
|
||||||
|
if (notification.State == ProgressNotificationState.Cancelled)
|
||||||
|
// user requested abort
|
||||||
|
return;
|
||||||
|
|
||||||
|
notification.Text = $"Deleting videos from {HumanisedModelName}s ({++i} of {items.Count})";
|
||||||
|
|
||||||
|
var video = b.Files.FirstOrDefault(f => f.Filename.EndsWith(".mp4") || f.Filename.EndsWith(".avi") || f.Filename.EndsWith(".mov") || f.Filename.EndsWith(".flv"));
|
||||||
|
if (video != null)
|
||||||
|
DeleteFile(b, video);
|
||||||
|
|
||||||
|
notification.Progress = (float)i / items.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.State = ProgressNotificationState.Completed;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restore multiple items that were previously deleted.
|
/// Restore multiple items that were previously deleted.
|
||||||
/// This will post notifications tracking progress.
|
/// This will post notifications tracking progress.
|
||||||
|
Loading…
Reference in New Issue
Block a user