1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-23 16:27:20 +08:00

Move implementation of DeleteVideos to BeatmapModelManager

This commit is contained in:
Noah M 2022-05-18 15:37:46 -05:00
parent 617382a56f
commit a93a2fcafb
2 changed files with 39 additions and 38 deletions

View File

@ -16,6 +16,7 @@ using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.Skinning;
using osu.Game.Stores;
using osu.Game.Overlays.Notifications;
#nullable enable
@ -114,5 +115,43 @@ namespace osu.Game.Beatmaps
item.CopyChangesToRealm(existing);
});
}
/// <summary>
/// Delete videos from a list of beatmaps.
/// This will post notifications tracking progress.
/// </summary>
public void DeleteVideos(List<BeatmapSetInfo> 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;
}
}
}

View File

@ -132,44 +132,6 @@ namespace osu.Game.Stores
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>
/// Restore multiple items that were previously deleted.
/// This will post notifications tracking progress.