Exemplo n.º 1
0
        private void DownloadAllMissing(object sender, object data = null)
        {
            var downloadableBeatmaps = new Beatmaps();

            foreach (var collection in Initalizer.LoadedCollections)
            {
                foreach (var beatmap in collection.DownloadableBeatmaps)
                {
                    downloadableBeatmaps.Add(beatmap);
                }
            }

            if (downloadableBeatmaps.Count == 0)
            {
                _userDialogs.OkMessageBox("You don't have any missing maps that CM is able to download", "Info", MessageBoxType.Info);
                return;
            }

            if (OsuDownloadManager.Instance.AskUserForSaveDirectoryAndLogin(_userDialogs, _loginForm))
            {
                OsuDownloadManager.Instance.DownloadBeatmaps(downloadableBeatmaps);
                ShowDownloadManager();
            }
            else
            {
                _userDialogs.OkMessageBox("Invalid directory or osu! login/password supplied", "Error", MessageBoxType.Error);
            }
        }
Exemplo n.º 2
0
        private void DropsinkOnModelDropped(object sender, ModelDropEventArgs modelDropEventArgs)
        {
            modelDropEventArgs.Handled = true;
            var beatmaps = new Beatmaps();

            foreach (var sourceModel in modelDropEventArgs.SourceModels)
            {
                beatmaps.Add((BeatmapExtension)sourceModel);
            }
            BeatmapsDropped?.Invoke(this, beatmaps);
        }
Exemplo n.º 3
0
        private Beatmapset(string json)
        {
            JArray beatmapset = JArray.Parse(json);

            ExtractBeatmapsetInfo(beatmapset[0]);

            foreach (var beatmap in beatmapset)
            {
                Beatmaps.Add(new Beatmap(beatmap));
            }

            Beatmaps.TrimExcess();
        }
        private void ListViewCollections_ModelDropped(object sender, ModelDropEventArgs e)
        {
            e.Handled = true;
            var collection = (Collection)e.TargetModel;

            if (collection == null)
            {
                return;
            }
            var beatmaps = new Beatmaps();

            foreach (var b in e.SourceModels)
            {
                beatmaps.Add((BeatmapExtension)b);
            }

            BeatmapsDropped?.Invoke(this, beatmaps, collection.Name);
        }
Exemplo n.º 5
0
        public Beatmaps GetBeatmaps(DateTime fromDate, DateTime toDate)
        {
            var resultBeatmaps = new Beatmaps();

            DateTime currentDate = fromDate;

            while (currentDate < toDate)
            {
                bool exception;
                RangeObservableCollection <BeatmapExtensionEx> newBeatmaps = null;
                do
                {
                    exception = false;
                    try
                    {
                        newBeatmaps =
                            GetBeatmaps(string.Format(GetBeatmapsURL + "?k={0}&since={1}", ApiKey,
                                                      currentDate.ToString("yyyy-MM-dd HH:mm:ss")));
                    }
                    catch (WebException)
                    {
                        exception = true;
                    }
                } while (exception);
                if (newBeatmaps.Count < 500)
                {
                    currentDate = toDate;
                }
                foreach (var newBeatmap in newBeatmaps)
                {
                    if (newBeatmap.ApprovedDate < toDate)
                    {
                        resultBeatmaps.Add(newBeatmap);
                    }

                    if (currentDate < newBeatmap.ApprovedDate)
                    {
                        currentDate = newBeatmap.ApprovedDate;
                    }
                }
            }
            return(resultBeatmaps);
        }
Exemplo n.º 6
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();
        }
        private void DownloadAllMissing()
        {
            var downloadableBeatmaps = new Beatmaps();

            foreach (var collection in Initalizer.LoadedCollections)
            {
                foreach (var beatmap in collection.DownloadableBeatmaps)
                {
                    downloadableBeatmaps.Add(beatmap);
                }
            }

            if (downloadableBeatmaps.Count > 0)
            {
                if (OsuDownloadManager.Instance.AskUserForSaveDirectoryAndLogin(_userDialogs, _loginForm))
                {
                    OsuDownloadManager.Instance.DownloadBeatmaps(downloadableBeatmaps);
                    ShowDownloadManager();
                }
            }
        }
Exemplo n.º 8
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);
                }
            }
        }
        public void WriteOsdb(Collections collections, string fullFileDir, string editor, bool skipMissing = false)
        {
            OpenFile(fullFileDir, true);
            //header
            _binWriter.Write(CurrentVersion);
            //save date
            _binWriter.Write(DateTime.Now.ToOADate());
            //who saved given osdb
            _binWriter.Write(editor);
            //number of collections stored in osdb
            _binWriter.Write(collections.Count);
            //bool ignoreMissingMaps = false;
            foreach (var collection in collections)
            {
                Beatmaps         beatmapsPossibleToSave = new Beatmaps();
                HashSet <string> beatmapWithHashOnly    = new HashSet <string>();

                foreach (var beatmap in collection.KnownBeatmaps)
                {
                    beatmapsPossibleToSave.Add(beatmap);
                }
                foreach (var beatmap in collection.DownloadableBeatmaps)
                {
                    beatmapsPossibleToSave.Add(beatmap);
                }

                foreach (var partialBeatmap in collection.UnknownBeatmaps)
                {
                    if (partialBeatmap.TitleRoman != "" || partialBeatmap.MapSetId > 0)
                    {
                        beatmapsPossibleToSave.Add(partialBeatmap);
                    }
                    else
                    {
                        beatmapWithHashOnly.Add(partialBeatmap.Md5);
                    }
                }
                _binWriter.Write(collection.Name);
                _binWriter.Write(beatmapsPossibleToSave.Count);
                //Save beatmaps
                foreach (var beatmap in beatmapsPossibleToSave)
                {
                    _binWriter.Write(beatmap.MapId);
                    _binWriter.Write(beatmap.MapSetId);
                    _binWriter.Write(beatmap.ArtistRoman);
                    _binWriter.Write(beatmap.TitleRoman);
                    _binWriter.Write(beatmap.DiffName);
                    _binWriter.Write(beatmap.Md5);
                    _binWriter.Write(((BeatmapExtension)beatmap).UserComment);
                    _binWriter.Write((byte)beatmap.PlayMode);
                    _binWriter.Write(beatmap.StarsNomod);
                }
                _binWriter.Write(beatmapWithHashOnly.Count);
                foreach (var beatmapHash in beatmapWithHashOnly)
                {
                    _binWriter.Write(beatmapHash);
                }
            }

            _binWriter.Write("By Piotrekol");
            CloseFile(true);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     使用Json填充一个OnlineBeatmapSetV2对象
        /// </summary>
        /// <param name="json"></param>
        public OnlineBeatmapSetV2(JObject json)
        {
            JObject setinfo;

            if (json.GetValue("beatmaps") != null)
            {
                setinfo = json;
                var beatmaps = (JArray)json["beatmaps"];
                foreach (var js in beatmaps)
                {
                    Beatmaps.Add(new OnlineBeatmapV2((JObject)js, this));
                }
            }
            else
            {
                setinfo = (JObject)json["beatmapset"];
                Beatmaps.Add(new OnlineBeatmapV2(json, this));
            }

            Artist        = setinfo["artist"].ToString();
            ArtistUnicode = setinfo["artist_unicode"].ToString();
            Creator       = setinfo["creator"].ToString();
            FavoriteCount = setinfo["favourite_count"].ToObject <int>();
            SetId         = setinfo["id"].ToObject <int>();
            PlayCount     = setinfo["play_count"].ToObject <int>();
            PreviewUrl    = "https:" + setinfo["preview_url"];
            Source        = setinfo["source"].ToString();
            var arr = setinfo["status"].ToString().ToCharArray();

            arr[0]          = char.ToUpper(arr[0]);
            Status          = (BeatmapStatus)Enum.Parse(typeof(BeatmapStatus), new string(arr));
            Title           = setinfo["title"].ToString();
            TitleUnicode    = setinfo["title_unicode"].ToString();
            CreatorUserId   = setinfo["user_id"].ToObject <int>();
            HasVideo        = setinfo["video"].ToObject <bool>();
            Bpm             = setinfo["bpm"].ToObject <double>();
            IsScoreable     = setinfo["is_scoreable"].ToObject <bool>();
            LastUpdate      = setinfo["last_updated"].ToString().ToNullableDateTime();
            LegacyThreadUrl = setinfo["legacy_thread_url"].ToString();
            Ranked          = setinfo["ranked"].ToObject <bool>();
            RankedDate      = setinfo["ranked_date"].ToString().ToNullableDateTime();
            HasStoryBoard   = setinfo["storyboard"].ToObject <bool>();
            SubmittedDate   = setinfo["submitted_date"].ToString().ToNullableDateTime();
            Tags            = setinfo["tags"].ToString();
            Rating          = setinfo["ratings"].ToObject <List <double> >();

            #region 谱面的被推荐次数(???)

            var nomin = setinfo["nominations"];
            if (nomin?.HasValues ?? false)
            {
                Nominations.CurrentNominations  = nomin["current"]?.ToObject <int>() ?? -1;
                Nominations.RequiredNominations = nomin["required"]?.ToObject <int>() ?? -1;
            }

            #endregion

            #region 谱面能否被宣传(???)


            var hyped = setinfo["hype"];
            if (hyped?.HasValues ?? false)
            {
                HypeStatus.CanBeHyped   = setinfo["can_be_hyped"]?.ToObject <bool>() ?? false;
                HypeStatus.CurrentHyped = hyped["current"]?.ToObject <int>() ?? -1;
                HypeStatus.RequiredHype = hyped["required"]?.ToObject <int>() ?? -1;
            }

            #endregion

            #region 谱面是否可下载

            var ava = setinfo["availability"];
            if (ava?.HasValues ?? false)
            {
                BeatmapAvailability.DownloadDisabled = ava["download_disabled"]?.ToObject <bool>() ?? false;
                BeatmapAvailability.MoreInformation  = ava["more_information"]?.ToString();
            }

            #endregion

            #region 封面等图片

            var covers = (JObject)setinfo["covers"];
            if (covers?.HasValues ?? false)
            {
                Covers.Card        = covers["card"]?.ToString();
                Covers.Card2X      = covers["card@2x"]?.ToString();
                Covers.Cover       = covers["cover"]?.ToString();
                Covers.Cover2X     = covers["cover@2x"]?.ToString();
                Covers.List        = covers["list"]?.ToString();
                Covers.List2X      = covers["list@2x"]?.ToString();
                Covers.SlimCover   = covers["slimcover"]?.ToString();
                Covers.SlimCover2X = covers["slimcover@2x"]?.ToString();
            }

            #endregion
        }