public void EditCollection(CollectionEditArgs e)
        {
            if (e.Action == CollectionEdit.Rename || e.Action == CollectionEdit.Add)
            {
                bool isRenameform = e.Action == CollectionEdit.Rename;

                var newCollectionName = _collectionAddRenameForm
                                        .GetCollectionName(IsCollectionNameValid, e.OrginalName, isRenameform);

                if (newCollectionName == "")
                {
                    return;
                }
                switch (e.Action)
                {
                case CollectionEdit.Rename:
                    e = CollectionEditArgs.RenameCollection(e.OrginalName, newCollectionName);
                    break;

                case CollectionEdit.Add:
                    e = CollectionEditArgs.AddCollections(new Collections()
                    {
                        new Collection(_mapCacher)
                        {
                            Name = newCollectionName
                        }
                    });
                    break;
                }
            }
            else if (e.Action == CollectionEdit.Intersect || e.Action == CollectionEdit.Difference)
            {
                if (e.Collections.Count < 2)
                {
                    return;
                }

                e.Collections.Add(new Collection(_mapCacher)
                {
                    Name = GetValidCollectionName(e.NewName)
                });
            }
            else if (e.Action == CollectionEdit.Inverse)
            {
                e.Collections.Add(new Collection(_mapCacher)
                {
                    Name = GetValidCollectionName(e.NewName)
                });
            }
            else if (e.Action == CollectionEdit.Duplicate)
            {
                var newCollection = new Collection(_mapCacher)
                {
                    Name = GetValidCollectionName(e.OrginalName)
                };
                _collectionEditor.EditCollection(
                    CollectionEditArgs.AddCollections(new Collections()
                {
                    newCollection
                })
                    );
                var beatmaps = new Beatmaps();
                beatmaps.AddRange(e.Collections[0].AllBeatmaps());

                e = CollectionEditArgs.AddBeatmaps(newCollection.Name, beatmaps);
            }

            _collectionEditor.EditCollection(e);
        }
        internal static void ProcessBeatmaps(bool newFilesOnly = false, bool quickFolderChecks = false)
        {
            SongWatcher.EnableRaisingEvents = false;
            QuickFolderChecks = quickFolderChecks;

            //Doing a full pass over the song folder is an expensive operation.
            //We should only do so if it is requested, or if we can't find the local osu!.db
            if (!newFilesOnly)
            {
                //FULL PROCESS
                Logger.LogPrint(@"_______________ Full process initiated. _______________");

                //Mark every single beatmap as "not found" to begin with, then remove any remaining at the end which were not found.
                Beatmaps.ForEach(b =>
                {
                    b.DatabaseNotFound = true;
                    b.HeadersLoaded    = false;
                });

                Root.Children.Clear();
                Root.Beatmaps.Clear();

                TotalUniqueSets = 0;
                TotalAudioOnly  = 0;

                ProcessFolder(BeatmapManager.SongsDirectory);

                int removed = Beatmaps.RemoveAll(b => b.DatabaseNotFound);

                if (removed > 0)
                {
                    InvokeOnStatusUpdate(string.Format(LocalisationManager.GetString(OsuString.BeatmapManager_RemoveMissingMaps), removed));
                }

                ReloadDictionaries();

                InvokeOnStatusUpdate(string.Format(LocalisationManager.GetString(OsuString.BeatmapManager_LoadedMaps), Beatmaps.Count));
            }
            else
            {
                //PARTIAL PROCESS

                for (int j = 0; j < ChangedPackages.Count; j++)
                {
                    string package = ChangedPackages[j];

                    if (!File.Exists(package))
                    {
                        //Package is no longer with us :(

                        Logger.Log($@"{package} could not be loaded. It no longer exists.");

                        List <Beatmap> matches = Beatmaps.FindAll(b => b.ContainingFolderAbsolute == package);
                        matches.ForEach(b => Remove(b));

                        continue;
                    }
                    else
                    {
                        BeatmapTreeLevel level = GetTreeLevel(Path.GetDirectoryName(package));
                        if (level != null)
                        {
                            ProcessPackage(package, level);
                        }
                    }
                }

                //Special processing for importing new maps
                //Changed to for loop because foreach was getting modified internally.  not sure how this could happen.
                for (int j = 0; j < ChangedFolders.Count; j++)
                {
                    string folder = ChangedFolders[j];

                    bool folderStillExists = Directory.Exists(folder);

                    if (!folder.StartsWith(BeatmapManager.SongsDirectory))
                    {
                        ProcessBeatmaps();
                        return;
                    }

                    BeatmapTreeLevel level = GetTreeLevel(folder);

                    if (level == null)
                    {
                        continue;
                    }

                    if (level.Children.Count > 0 && folderStillExists)
                    {
                        //ignore this folder change for now?
                        //sure, unless it was deleted.
                        continue;
                    }

                    ResetTreeLevel(level);
                    if (folderStillExists)
                    {
                        ProcessTree(level);
                    }
                    else
                    {
                        if (level.Parent != null)
                        {
                            level.Parent.Children.Remove(level);
                        }
                    }
                }
            }

            if (Current != null && newFilesOnly)
            {
                SetCurrentFromFilename(Current.Filename, false);
            }

            InitialLoadComplete = true;

            SongWatcher.EnableRaisingEvents = true;
        }
Пример #3
0
 public CollectionsManager(Beatmaps loadedBeatmaps)
 {
     LoadedBeatmaps = loadedBeatmaps;
 }
        internal static void ProcessTree(BeatmapTreeLevel currentLevel)
        {
            if (currentLevel == null)
            {
                return;
            }

            //never process songs if we aren't the lead spectator.
            if (GameBase.Tournament && !GameBase.TournamentManager)
            {
                return;
            }

            //the number of stray .osu files found in this tree level.
            int strayBeatmapCount = 0;

            string folder = currentLevel.FullPath;

            if (currentLevel != Root)
            {
                InvokeOnStatusUpdate(folder.Replace(BeatmapManager.SongsDirectory, string.Empty).Trim('\\', '/'));
            }

#if !DEBUG
            try
            {
#endif

            bool isTopFolder = folder == BeatmapManager.SongsDirectory;

            if (!isTopFolder && InitialLoadComplete && (Current == null || Current.ContainingFolder == null || Current.ContainingFolderAbsolute != folder))
            {
                string relativeFolder = folder.Replace(SongsDirectory, string.Empty);
                bool   found          = false;

                //avoid hitting the filesystem at all wherever possible
                foreach (Beatmap fb in Beatmaps)
                {
                    if (fb.ContainingFolder != relativeFolder)
                    {
                        continue;
                    }

                    strayBeatmapCount++;
                    if (!fb.InOszContainer)
                    {
                        fb.DatabaseNotFound = false;

                        //we are matching based on filename here.
                        //the folder could have changed, and we need to update this change.
                        fb.ContainingFolderAbsolute = folder;

                        currentLevel.Beatmaps.Add(fb);

                        found = true;
                    }
                }

                if (found)
                {
                    TotalUniqueSets++;
                    return;
                }
            }

            //load osz2 packages
            foreach (string f in Directory.GetFiles(folder, "*.osz2"))
            {
                if (f == "LastUpload.osz2")
                {
                    break;
                }

                if (ProcessPackage(f, currentLevel))
                {
                    TotalUniqueSets++;
                }
            }

            //load osz directories
            foreach (string file in Directory.GetFiles(folder, "*.osu"))
            {
                strayBeatmapCount++;

                Beatmap b = new Beatmap {
                    Filename = Path.GetFileName(file)
                };

                if (InitialLoadComplete)
                {
                    int index = Beatmaps.BinarySearch(b);

                    if (index >= 0)
                    {
                        Beatmap found = Beatmaps[index];

                        //this condition is required to make sure we don't match an osz2 to a folder.
                        //this causes really weird results. this whole process could be improved to avoid this ugliness.
                        if (!found.InOszContainer)
                        {
                            found.DatabaseNotFound = false;
                            found.BeatmapPresent   = true;

                            //we are matching based on filename here.
                            //the folder could have changed, and we need to update this change.
                            found.ContainingFolderAbsolute = folder;

                            currentLevel.Beatmaps.Add(found);

                            continue;
                        }
                    }
                }

                b.ContainingFolderAbsolute = folder;
                try
                {
                    b.ProcessHeaders();
                }
                catch (UnauthorizedAccessException)
                {
                    Logger.Log($@"{b} could not be loaded. Insufficient permissions");
                    continue;
                }

                if (!b.AudioPresent && !b.BeatmapPresent)
                {
                    continue;
                }

                NewFilesList.Add(b);
                b.NewFile = true;

                Add(b);
                lastAddedMap = b;
                currentLevel.Beatmaps.Add(b);
            }

            if (strayBeatmapCount == 0 &&
                (currentLevel == Root ||
                 currentLevel.Parent == Root))
            {
                string   audioFilename = null;
                string[] files         = Directory.GetFiles(folder, @"*.mp3", SearchOption.TopDirectoryOnly);

                if (files.Length > 0)
                {
                    audioFilename = files[0];
                }

                if (audioFilename != null)
                {
                    Beatmap b = new Beatmap
                    {
                        AudioFilename            = Path.GetFileName(audioFilename),
                        Filename                 = Path.GetFileNameWithoutExtension(audioFilename) + @".osu",
                        DisplayTitle             = Path.GetFileName(audioFilename),
                        DisplayTitleNoArtist     = Path.GetFileName(audioFilename),
                        SortTitle                = Path.GetFileName(audioFilename),
                        AudioPresent             = true,
                        BeatmapPresent           = false,
                        ContainingFolderAbsolute = folder
                    };


                    int index = Add(b);

                    if (index >= 0)
                    {
                        Beatmaps[index].DatabaseNotFound = false;
                    }

                    currentLevel.Beatmaps.Add(b);

                    lastAddedMap = b;

                    TotalAudioOnly++;
                }
            }

            if (strayBeatmapCount > 0)
            {
                TotalUniqueSets++;
            }

            if (isTopFolder || strayBeatmapCount == 0)
            //Only process subfolders if they don't have any direct beatmaps contained in them.
            {
                foreach (string f in Directory.GetDirectories(folder))
                {
                    ProcessFolder(f);
                }
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            TopMostMessageBox.Show("Error while processing " + folder + "\n" + e.ToString());
        }
#endif
        }
        /// <summary>
        /// Process and load a single osz2 package.
        /// </summary>
        private static bool ProcessPackage(string filename, BeatmapTreeLevel treeLevel)
        {
            MapPackage package = Osz2Factory.TryOpen(filename);

            if (package == null)
            {
                NotificationManager.ShowMessage("Error reading " + Path.GetFileName(filename), Color.Red, 4000);
                return(false);
            }

            int mapsLoaded = 0;

            foreach (string file in package.MapFiles)
            {
                Beatmap b = new Beatmap {
                    Filename = file
                };

                if (InitialLoadComplete)
                {
                    int index = Beatmaps.BinarySearch(b);

                    if (index >= 0)
                    {
                        Beatmap found = Beatmaps[index];

                        if (found.InOszContainer)
                        {
                            found.DatabaseNotFound         = false;
                            found.BeatmapPresent           = true;
                            found.ContainingFolderAbsolute = filename;
                            found.InOszContainer           = true;

                            treeLevel.Beatmaps.Add(found);
                            mapsLoaded++;
                            continue;
                        }
                    }
                }

                b.BeatmapSetId = Convert.ToInt32(package.GetMetadata(MapMetaType.BeatmapSetID));
                b.BeatmapId    = package.GetIDByMap(file);

                b.ContainingFolderAbsolute = filename;
                b.InOszContainer           = true;
                b.AudioPresent             = true;
                b.BeatmapPresent           = true;

                b.ProcessHeaders();
                if (!b.HeadersLoaded)
                {
                    //failed?
                    continue;
                }

                b.NewFile = true;
                NewFilesList.Add(b);

                if (!b.AudioPresent && !b.BeatmapPresent)
                {
                    continue;
                }

                Add(b);
                lastAddedMap = b;
                treeLevel.Beatmaps.Add(b);
                mapsLoaded++;
            }

            Osz2Factory.CloseMapPackage(package);
            //package.Unlock();

            return(mapsLoaded > 0);
        }
 public BeatmapFilter(Beatmaps beatmaps, Scores scores, Beatmap baseBeatmap)
 {
     BeatmapExtensionIsUsed = baseBeatmap.GetType().IsAssignableFrom(typeof(BeatmapExtension));
     SetScores(scores);
     SetBeatmaps(beatmaps);
 }
 public void SetBeatmaps(Beatmaps beatmaps)
 {
     _beatmaps = beatmaps;
     UpdateSearch(_lastSearchString);
 }
Пример #8
0
        private void WriteOsdb(Collections collections, BinaryWriter _binWriter, string editor,
                               bool minimalWrite = false)
        {
            //header
            _binWriter.Write(CurrentVersion(minimalWrite));
            //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)
            {
                var beatmapsPossibleToSave = new Beatmaps();
                var 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(collection.OnlineId);
                _binWriter.Write(beatmapsPossibleToSave.Count);
                //Save beatmaps
                foreach (var beatmap in beatmapsPossibleToSave)
                {
                    _binWriter.Write(beatmap.MapId);
                    _binWriter.Write(beatmap.MapSetId);
                    if (!minimalWrite)
                    {
                        _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");
        }
 private void _model_BeatmapsChanged(object sender, System.EventArgs e)
 {
     Beatmaps = _model.GetBeatmaps();
 }
Пример #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
        }
Пример #11
0
 public Collections GetCollectionsForBeatmaps(Beatmaps beatmaps)
 => _collectionEditor.GetCollectionsForBeatmaps(beatmaps);
Пример #12
0
 public void SetBeatmaps(Beatmaps beatmaps)
 {
     _beatmaps = beatmaps;
 }
Пример #13
0
 public void SetBeatmaps(Beatmaps beatmaps)
 {
     _beatmapsDataSource = beatmaps;
     OnBeatmapsChanged();
 }
Пример #14
0
 public void EmitBeatmapsDropped(object sender, Beatmaps beatmaps)
 {
     BeatmapsDropped?.Invoke(sender, beatmaps);
 }