Esempio n. 1
0
        public async Task <List <Beatmap> > FillBeatmapThumbs(List <Beatmap> dbMaps)
        {
            var allIds     = dbMaps.Select(k => k.Id).ToList();
            var withThumbs = await Beatmaps
                             .Where(k => allIds.Contains(k.Id))
                             .Include(k => k.BeatmapThumb)
                             .ToListAsync();

            return(withThumbs);
        }
Esempio n. 2
0
 public async Task <List <Beatmap> > GetBeatmapsFromFolder(string folder, bool inOwnDb)
 {
     try
     {
         return(await Beatmaps.Where(k => k.InOwnDb == inOwnDb && k.FolderNameOrPath == folder).ToListAsync());
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Error while calling GetBeatmapsFromFolder().");
         throw;
     }
 }
Esempio n. 3
0
        public OsuDbFile(string fname, bool byId = false, bool byHash = false)
        {
            if (fname.Length == 0)
            {
                return;
            }

            this.fileReader      = new BinaryReader(new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
            this.Version         = this.fileReader.ReadInt32();
            this.FolderCount     = this.fileReader.ReadInt32();
            this.AccountUnlocked = this.fileReader.ReadBoolean();
            this.DateUntilUnlock = new DateTime(this.fileReader.ReadInt64());
            this.PlayerName      = this.readNullableString();
            this.NumBeatmaps     = this.fileReader.ReadInt32();
            this.Beatmaps        = new List <Beatmap>(this.NumBeatmaps);
            if (byHash)
            {
                this.BeatmapsByHash = new Dictionary <string, Beatmap>(this.NumBeatmaps);
            }
            if (byId)
            {
                this.BeatmapsById = new Dictionary <int, Beatmap>(this.NumBeatmaps);
            }
            for (int i = 0; i < this.NumBeatmaps; i++)
            {
                Beatmap b = this.readBeatmap();
                Beatmaps.Add(b);
                if (byHash && b.Hash != null)
                {
                    BeatmapsByHash[b.Hash] = b;
                }
                if (byId)
                {
                    BeatmapsById[b.ID] = b;
                }
            }
            this.fileReader.Dispose();
            Beatmaps = Beatmaps.Where(b => b.GameMode == 0)
                       .OrderBy(b => b.ArtistName)
                       .ThenBy(b => b.SongTitle)
                       .ThenBy(b => b.Creator)
                       .ThenBy(b => b.StarRating).ToList();
        }
Esempio n. 4
0
 public async Task RemoveSyncedAll()
 {
     Beatmaps.RemoveRange(Beatmaps.Where(k => !k.InOwnDb));
     await SaveChangesAsync();
 }
Esempio n. 5
0
        private void GetMissingMapData(object sender, object data = null)
        {
            //var test = Helpers.GetClipboardText();
            //var p = new TextProcessor();
            //var output = p.ParseLines(test.Split('\n').ToList());
            //foreach (var o in output)
            //{
            //    var collection = new Collection(Initalizer.OsuFileIo.LoadedMaps) { Name = o.Key };
            //    foreach (var mapResult in o.Value)
            //    {
            //        if (mapResult.IdType == TextProcessor.MapIdType.Map)
            //            collection.AddBeatmapByMapId(mapResult.Id);
            //    }
            //    _collectionEditor.EditCollection(
            //        CollectionEditArgs.AddCollections(
            //            new Collections
            //            {
            //                collection
            //            }));
            //}
            //TODO: UI for text parser and map data getter

            if (BeatmapData == null)
            {
                BeatmapData = new BeatmapData("SNIP", Initalizer.OsuFileIo.LoadedMaps);
            }
            var mapsWithMissingData = new Beatmaps();


            foreach (var collection in Initalizer.LoadedCollections)
            {
                foreach (var beatmap in collection.UnknownBeatmaps)
                {
                    mapsWithMissingData.Add(beatmap);
                }
            }
            var            maps            = mapsWithMissingData.Where(m => !string.IsNullOrWhiteSpace(m.Md5)).Distinct();
            List <Beatmap> fetchedBeatmaps = new List <Beatmap>();

            foreach (var map in maps)
            {
                Beatmap downloadedBeatmap = null;
                if (map.MapId > 0)
                {
                    downloadedBeatmap = BeatmapData.GetBeatmapFromId(map.MapId, PlayMode.Osu);
                }
                else
                if (!map.Md5.Contains("|"))
                {
                    downloadedBeatmap = BeatmapData.GetBeatmapFromHash(map.Md5, null);
                }

                if (downloadedBeatmap != null)
                {
                    fetchedBeatmaps.Add(downloadedBeatmap);
                }
            }
            foreach (var collection in Initalizer.LoadedCollections)
            {
                foreach (var fetchedBeatmap in fetchedBeatmaps)
                {
                    //TODO: this is really inefficient
                    collection.ReplaceBeatmap(fetchedBeatmap.Md5, fetchedBeatmap);
                    collection.ReplaceBeatmap(fetchedBeatmap.MapId, fetchedBeatmap);
                }
            }
        }