public static async Task AddToCollectionAsync(Collection col, IList <Beatmap> entries)
        {
            var appDbOperator = new AppDbOperator();

            if (entries == null || entries.Count <= 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(col.ImagePath))
            {
                var first = entries[0];
                var dir   = first.InOwnFolder
                    ? Path.Combine(Domain.CustomSongPath, first.FolderName)
                    : Path.Combine(Domain.OsuSongPath, first.FolderName);
                var filePath = Path.Combine(dir, first.BeatmapFileName);
                var osuFile  = await OsuFile.ReadFromFileAsync(@"\\?\" + filePath, options =>
                {
                    options.IncludeSection("Events");
                    options.IgnoreSample();
                    options.IgnoreStoryboard();
                });

                if (osuFile.Events.BackgroundInfo != null)
                {
                    var imgPath = Path.Combine(dir, osuFile.Events.BackgroundInfo.Filename);
                    if (File.Exists(imgPath))
                    {
                        col.ImagePath = imgPath;
                        appDbOperator.UpdateCollection(col);
                    }
                }
            }

            appDbOperator.AddMapsToCollection(entries, col);
        }
Exemplo n.º 2
0
        public static async Task <bool> AddToCollectionAsync([NotNull] Collection col, IList <Beatmap> entries)
        {
            var controller    = Service.Get <ObservablePlayController>();
            var appDbOperator = new AppDbOperator();

            if (entries == null || entries.Count <= 0)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(col.ImagePath))
            {
                var first    = entries[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;
                        appDbOperator.UpdateCollection(col);
                    }
                }
            }

            appDbOperator.AddMapsToCollection(entries, col);
            foreach (var beatmap in entries)
            {
                if (!controller.PlayList.CurrentInfo.Beatmap.GetIdentity().Equals(beatmap.GetIdentity()) ||
                    !col.LockedBool)
                {
                    continue;
                }
                controller.PlayList.CurrentInfo.BeatmapDetail.Metadata.IsFavorite = false;
                break;
            }

            return(true);
        }
Exemplo n.º 3
0
        private static void InitLocalDb()
        {
            FluentMapper.Initialize(config =>
            {
                config.AddMap(new BeatmapMap());
                config.AddMap(new MapInfoMap());
            });

            AppDbOperator.ValidateDb();
            BeatmapDbOperator.ValidateDb();

            var appDbOperator = new AppDbOperator();
            var defCol        = appDbOperator.GetCollections();
            var locked        = defCol.Where(k => k.LockedBool);

            if (!locked.Any())
            {
                appDbOperator.AddCollection("最喜爱的", true);
            }
        }