public static async Task <bool> AddToCollectionAsync([NotNull] Collection col, IList <Beatmap> beatmaps) { var controller = Service.Get <ObservablePlayController>(); await using var dbContext = new ApplicationDbContext(); if (beatmaps == null || beatmaps.Count <= 0) { return(false); } if (string.IsNullOrEmpty(col.ImagePath)) { var first = beatmaps[0]; var dir = first.GetFolder(out var isFromDb, out var freePath); var filePath = isFromDb ? Path.Combine(dir, first.BeatmapFileName) : freePath; var osuFile = await OsuFile.ReadFromFileAsync(filePath, options => { options.IncludeSection("Events"); options.IgnoreSample(); options.IgnoreStoryboard(); }); if (!osuFile.ReadSuccess) { return(false); } if (osuFile.Events.BackgroundInfo != null) { var imgPath = Path.Combine(dir, osuFile.Events.BackgroundInfo.Filename); if (File.Exists(imgPath)) { col.ImagePath = imgPath; await dbContext.AddOrUpdateCollection(col); } } } await dbContext.AddBeatmapsToCollection(beatmaps, col); if (col.IsDefault) { foreach (var beatmap in beatmaps) { if (controller.PlayList.CurrentInfo.Beatmap.Equals(beatmap)) { controller.PlayList.CurrentInfo.BeatmapDetail.Metadata.IsFavorite = true; break; } } } return(true); }