1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:43:20 +08:00

Schedule callback instead

This commit is contained in:
smoogipoo 2021-06-23 21:26:52 +09:00
parent e7981eae9b
commit 8a2026e305

View File

@ -55,6 +55,8 @@ namespace osu.Game.Collections
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Collections.CollectionChanged += collectionsChanged;
if (storage.Exists(database_backup_name)) if (storage.Exists(database_backup_name))
{ {
// If a backup file exists, it means the previous write operation didn't run to completion. // If a backup file exists, it means the previous write operation didn't run to completion.
@ -66,10 +68,6 @@ namespace osu.Game.Collections
File.Copy(storage.GetFullPath(database_backup_name), storage.GetFullPath(database_name)); File.Copy(storage.GetFullPath(database_backup_name), storage.GetFullPath(database_name));
} }
// Only accept changes after/if the above succeeds to prevent simultaneously accessing either file.
// Todo: This really should not be delayed like this, but is unlikely to cause issues because CollectionManager loads very early in execution.
Collections.CollectionChanged += collectionsChanged;
if (storage.Exists(database_name)) if (storage.Exists(database_name))
{ {
List<BeatmapCollection> beatmapCollections; List<BeatmapCollection> beatmapCollections;
@ -82,7 +80,7 @@ namespace osu.Game.Collections
} }
} }
private void collectionsChanged(object sender, NotifyCollectionChangedEventArgs e) private void collectionsChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() =>
{ {
switch (e.Action) switch (e.Action)
{ {
@ -106,7 +104,7 @@ namespace osu.Game.Collections
} }
backgroundSave(); backgroundSave();
} });
/// <summary> /// <summary>
/// Set an endpoint for notifications to be posted to. /// Set an endpoint for notifications to be posted to.