Ejemplo n.º 1
0
        private void _view_RightClick(object sender, Gui.Misc.StringEventArgs e)
        {
            var selectedCollections = _model.SelectedCollections;
            CollectionEditArgs args;

            switch (e.Value)
            {
            case "Delete":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.RemoveCollections(selectedCollections);
                break;

            case "Merge":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.MergeCollections(selectedCollections, selectedCollections[0].Name);
                break;

            case "Intersect":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.IntersectCollections(selectedCollections, selectedCollections[0].Name);
                break;

            case "Create":
                args = CollectionEditArgs.AddCollections(null);
                break;

            case "Rename":
                if (_view.SelectedCollection == null)
                {
                    return;
                }
                args = CollectionEditArgs.RenameCollection(_view.SelectedCollection, null);
                break;

            case "Duplicate":
                if (_view.SelectedCollection == null)
                {
                    return;
                }

                args = CollectionEditArgs.DuplicateCollection(_view.SelectedCollection);
                break;

            default:
                return;
            }

            _model.EmitCollectionEditing(args);
        }
        private void _view_RightClick(object sender, Gui.Misc.StringEventArgs e)
        {
            var selectedCollections = _model.SelectedCollections;
            CollectionEditArgs args;

            switch (e.Value)
            {
            case "Delete":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.RemoveCollections(selectedCollections);
                break;

            case "Merge":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.MergeCollections(selectedCollections, selectedCollections[0].Name);
                break;

            case "Intersect":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.IntersectCollections(selectedCollections, selectedCollections[0].Name);
                break;

            case "Inverse":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.InverseCollections(selectedCollections, selectedCollections[0].Name);
                break;

            case "Difference":
                if (selectedCollections == null)
                {
                    return;
                }
                args = CollectionEditArgs.DifferenceCollections(selectedCollections, selectedCollections[0].Name);
                break;

            case "Create":
                args = CollectionEditArgs.AddCollections(null);
                break;

            case "Rename":
                if (_view.SelectedCollection == null)
                {
                    return;
                }
                args = CollectionEditArgs.RenameCollection(_view.SelectedCollection, null);
                break;

            case "Duplicate":
                if (_view.SelectedCollection == null)
                {
                    return;
                }

                args = CollectionEditArgs.DuplicateCollection(_view.SelectedCollection);
                break;

            case "Export":
                if (selectedCollections == null)
                {
                    return;
                }

                args = CollectionEditArgsExtension.ExportBeatmaps(selectedCollections);
                break;

            case "Copy":
                if (selectedCollections == null)
                {
                    return;
                }
                var tempFolder = Path.Combine(Path.GetTempPath(), "CMcollections");
                if (Directory.Exists(tempFolder))
                {
                    Directory.Delete(tempFolder, true);
                }

                Directory.CreateDirectory(tempFolder);
                var fileName     = Helpers.StripInvalidFileNameCharacters(selectedCollections[0].Name, "_");
                var tempLocation = Path.Combine(tempFolder, $"{fileName}.osdb");
                Initalizer.OsuFileIo.CollectionLoader.SaveOsdbCollection(selectedCollections, tempLocation);
                Clipboard.SetFileDropList(new StringCollection {
                    tempLocation
                });
                return;

            default:
                return;
            }

            _model.EmitCollectionEditing(args);
        }
Ejemplo n.º 3
0
        internal void Run()
        {
            var osuFileIo = new OsuFileIo(new BeatmapExtension());

            //Automatic Detection of osu! directory location
            string dir = osuFileIo.OsuPathResolver.GetOsuDir(ThisPathIsCorrect, SelectDirectoryDialog);



            string osuPath       = @"E:\osu!\";
            string osuDbFileName = "osu!.db";
            string ExampleCollectionFileLocation = @"E:\osuCollections\SomeCollectionThatExists.db";



            osuFileIo.OsuDatabase.Load(osuPath + osuDbFileName);

            //osu! configuration file is currently only used for getting a songs folder location
            osuFileIo.OsuSettings.Load(osuPath);

            //Data loaded using next 2 functions are going to be automatically correlated
            //with currently avalable beatmap data.
            osuFileIo.CollectionLoader.LoadOsuCollection(ExampleCollectionFileLocation);
            //osuFileIo.CollectionLoader.LoadOsdbCollection("");


            string osuSongsFolderLocation = osuFileIo.OsuSettings.CustomBeatmapDirectoryLocation;

            //Create Collection manager instance
            var collectionManager = new CollectionsManagerWithCounts(osuFileIo.OsuDatabase.LoadedMaps.Beatmaps);

            //or just this:
            //var collectionManager = new CollectionsManager(osuFileIo.OsuDatabase.LoadedMaps.Beatmaps);

            collectionManager.LoadedCollections.CollectionChanged += LoadedCollections_CollectionChanged;

            //Create some dummy collections
            Collection ourCollection = new Collection(osuFileIo.LoadedMaps)
            {
                Name = "Example collection1"
            };
            Collection ourSecondCollection = new Collection(osuFileIo.LoadedMaps)
            {
                Name = "Example collection2"
            };

            //Add these to our manager
            collectionManager.EditCollection(
                CollectionEditArgs.AddCollections(new Collections()
            {
                ourCollection, ourSecondCollection
            })
                );

            //Add some beatmaps to ourSecondCollection
            collectionManager.EditCollection(
                CollectionEditArgs.AddBeatmaps("Example collection2", new Beatmaps()
            {
                new BeatmapExtension()
                {
                    Md5 = "'known' md5"
                },
                new BeatmapExtension()
                {
                    Md5 = "another 'known' md5"
                },
                new BeatmapExtension()
                {
                    Md5 = "md5 that we have no idea about"
                }
            }));

            //Trying to issue any action on collection with unknown name will be just ignored
            collectionManager.EditCollection(
                CollectionEditArgs.AddBeatmaps("Collection that doesn't exist", new Beatmaps()
            {
                new BeatmapExtension()
                {
                    Md5 = "1234567890,yes I know these aren't valid md5s"
                }
            }));

            //Merge our collections into one.
            //Note that while I do not impose a limit on collection name length, osu! does and it will be truncated upon opening collection in osu! client.
            collectionManager.EditCollection(
                CollectionEditArgs.MergeCollections(new Collections()
            {
                ourCollection, ourSecondCollection
            }
                                                    , "Collection created from 2 Example collections")
                );

            //true
            bool isNameTaken = collectionManager.CollectionNameExists("Collection created from 2 Example collections");

            ICollection ourMergedCollection = collectionManager.GetCollectionByName("Collection created from 2 Example collections");

            //These are avaliable only when using CollectionsManagerWithCounts
            var TotalBeatmapCount    = collectionManager.BeatmapsInCollectionsCount;
            var MissingBeatmapsCount = collectionManager.MissingMapSetsCount;

            //Lets save our collections after edits
            //as .osdb
            osuFileIo.CollectionLoader.SaveOsdbCollection(collectionManager.LoadedCollections, ExampleCollectionFileLocation);
            //or .db
            osuFileIo.CollectionLoader.SaveOsuCollection(collectionManager.LoadedCollections, ExampleCollectionFileLocation);
        }