Пример #1
0
 private void ClearCollections(object sender, object data = null)
 {
     _collectionEditor.EditCollection(CollectionEditArgs.ClearCollections());
 }
 private void ClearCollections()
 {
     _collectionEditor.EditCollection(CollectionEditArgs.ClearCollections());
 }
Пример #3
0
        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)
            {
                if (e.Collections.Count < 2)
                {
                    return;
                }

                var newCollection = new Collection(_mapCacher)
                {
                    Name = GetValidCollectionName(e.NewName)
                };
                e.Collections.Add(newCollection);
            }
            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);
        }
Пример #4
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);
        }
 private void ViewOnBeatmapsDropped(object sender, Beatmaps args, string collectionName)
 {
     _model.EmitCollectionEditing(CollectionEditArgs.AddBeatmaps(collectionName, args));
 }
Пример #6
0
 public void EmitCollectionEditing(CollectionEditArgs args)
 {
     CollectionEditing?.Invoke(this, args);
 }
Пример #7
0
        static void Main(string[] args)
        {
            try
            {
                if (System.Threading.Thread.CurrentThread.CurrentCulture.Name.StartsWith("zh"))
                {
                    language = JsonConvert.DeserializeObject <Language>(Encoding.UTF8.GetString(Properties.Resources.zh_tw));                                                                            //假如是中文語系,就使用中文
                }
                else
                {
                    language = new Language();  //否則,英文
                }
            }
            catch (Exception) { language = new Language(); /*這邊是當跳出錯誤時,使用英文。正常來說是不會有錯誤才對,但有次比賽拿來做測試的時候出了錯誤,也抓不到點,就先認定是語系的問題了*/ }

            Console.Title = language.AppTitle;

            if (OsuPathResolver.Instance.OsuIsRunning)
            {
                FormatWrite(language.DetectionOsuIsRunning, ConsoleColor.Red);
            }

            OpenFileDialog openFileDialog = new OpenFileDialog(); //選擇收藏夾檔案的對話方塊

            openFileDialog.AddExtension    = true;
            openFileDialog.CheckFileExists = true;
            openFileDialog.CheckPathExists = true;
            openFileDialog.DefaultExt      = "json";
            openFileDialog.Filter          = language.OpenFileFilter;
            openFileDialog.Multiselect     = false;

            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                Exit(language.PleaseSelectCollection, true);
            }

            JsonData collectionData = null;

            try { collectionData = JsonConvert.DeserializeObject <JsonData>(File.ReadAllText(openFileDialog.FileName)); } //讀取收藏夾資料
            catch (Exception) { }
            if (collectionData == null || collectionData.collection_data == null)
            {
                Exit(language.ReadCollectionFail, true);
            }

            string osuPath = OsuPathResolver.Instance.GetOsuDir((path) => { //第一次會先偵測osu的路徑,然後提示使用者是否正確
                var dialogResult = MessageBox.Show(
                    string.Format(
                        language.ConfirmOsuPath, Environment.NewLine + path, Environment.NewLine),
                    "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                return(dialogResult == DialogResult.Yes);
            }, (text) => {
                FolderBrowserDialog dialog = new FolderBrowserDialog(); //假如是錯誤的,那就開個資料夾選擇對話框,讓使用者自行選擇osu的路徑

                dialog.ShowNewFolderButton = false;
                dialog.Description         = language.PleaseSelectOsuPath;
                dialog.RootFolder          = Environment.SpecialFolder.MyComputer;
                if (dialog.ShowDialog() == DialogResult.OK && Directory.Exists(dialog.SelectedPath))
                {
                    return(dialog.SelectedPath);
                }
                return("");
            });

            if (osuPath == string.Empty || !Directory.Exists(osuPath))
            {
                Exit(language.NeedValidOsuPath, true);
            }
            if (!osuPath.EndsWith("\\"))
            {
                osuPath += "\\";
            }

            FormatWrite(string.Format(language.OsuPath, osuPath), ConsoleColor.Yellow);
            OsuFileIo.OsuSettings.Load(osuPath);
            OsuFileIo.OsuDatabase.Load(osuPath + "osu!.db"); //載入osu的資料庫來抓取songs的資料夾路徑

            List <BeatmapData> needDownloadBeatmapList = new List <BeatmapData>();
            var collectionManager = new CollectionsManager(OsuFileIo.OsuDatabase.LoadedMaps.Beatmaps); Collection collection;                          //初始化目前osu所有的Beatmap

            collectionManager.EditCollection(CollectionEditArgs.AddCollections(OsuFileIo.CollectionLoader.LoadCollection(osuPath + "collection.db"))); //載入原先的收藏夾

            foreach (CollectionData item in collectionData.collection_data)
            {
                FormatWrite(string.Format(language.CollectionName, item.collection_name), ConsoleColor.Yellow);

                if (collectionManager.CollectionNameExists(item.collection_name))
                {
                    collection = collectionManager.GetCollectionByName(item.collection_name);                                                               //如果收藏夾已經存在,就讀取出來
                }
                else
                {
                    collection = new Collection(OsuFileIo.LoadedMaps)
                    {
                        Name = item.collection_name
                    }
                };                                                                                      //否則新建一個

                foreach (BeatmapData item2 in item.beatmap_data)
                {
                    if (!collection.AllBeatmaps().Any((x) => x.MapId == item2.beatmap_id)) //讀取收藏夾內的Beatmap,如果要匯入的收藏夾Beatmap ID不存在於收藏夾內,那就新增進去
                    {
                        FormatWrite(string.Format(language.AddBeatmapToCollection, item2.beatmap_name), ConsoleColor.Green);
                        collection.AddBeatmapByHash(item2.beatmap_md5);                                         //新增Beatmap,使用Hash新增法
                        if (!OsuFileIo.OsuDatabase.LoadedMaps.Beatmaps.Any((x) => x.MapId == item2.beatmap_id)) //如果osu資料庫裡面沒有該Beatmap
                        {
                            needDownloadBeatmapList.Add(item2);                                                 //就新增到下載清單內
                            FormatWrite(language.NeedDownloadBeatmap, ConsoleColor.Cyan);
                        }
                    }
                }

                collectionManager.EditCollection(CollectionEditArgs.RemoveCollections(new Collections()
                {
                    collection
                }));                                                                                                      //先把收藏夾移除
                collectionManager.EditCollection(CollectionEditArgs.AddCollections(new Collections()
                {
                    collection
                }));                                                                                                   //再把收藏夾新增,以達成重整的效果
            }

            if (needDownloadBeatmapList.Count != 0) //如果下載清單數量不為0,就進入下載程序
            {
                FormatWrite(language.DownloadBeatmapInfo, ConsoleColor.Green);
                CookieAwareWebClient cookieAwareWebClient = new CookieAwareWebClient(); //CollectionManager提供的class,可以讓WebClient使用cookie的功能
                string username, password;
                do
                {
                    Console.Write(language.OsuUsername); username = Console.ReadLine();
                    Console.Write(language.OsuPassword); password = "";
                    do
                    {
                        ConsoleKeyInfo key = Console.ReadKey(true);
                        if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
                        {
                            password += key.KeyChar;
                            Console.Write("*");
                        }
                        else
                        {
                            if (key.Key == ConsoleKey.Backspace && password.Length > 0)
                            {
                                password = password.Substring(0, (password.Length - 1));
                                Console.Write("\b \b");
                            }
                            else if (key.Key == ConsoleKey.Enter)
                            {
                                Console.WriteLine();
                                break;
                            }
                        }
                    } while (true);

                    try { if (!cookieAwareWebClient.Login(loginAddress, string.Format(loginDataStr, username, password)).Contains("I don't have an account"))
                          {
                              break;
                          }
                    }                                                                                                                                                  //登入失敗的話,回傳的網頁資料會有I don't have an account
                    catch (Exception ex) { Exit(string.Format(language.LoginErrorElseReason, ex.Message)); }

                    FormatWrite(language.LoginError, ConsoleColor.Red);
                } while (true);

                bool downloadVideo = MessageBox.Show(language.DownloadBeatmapWithVideo, "", MessageBoxButtons.YesNo) == DialogResult.Yes; //提示下載時是否包含背景影片

                needDownloadBeatmapList.ForEach((item) => {
                    string savePath = OsuFileIo.OsuSettings.CustomBeatmapDirectoryLocation + item.beatmap_setid + " " + StripInvalidCharacters(item.beatmap_name) + ".osz"; //存放路徑: osu的songs資料夾 + BeatmapSet ID + BeatmapSet Name
                    if (!File.Exists(savePath))
                    {
                        FormatWrite(string.Format(language.DownloadBeatmapName, Path.GetFileName(savePath)), ConsoleColor.Green);
                        try { File.WriteAllBytes(savePath, cookieAwareWebClient.DownloadData("https://osu.ppy.sh/d/" + item.beatmap_setid + (downloadVideo ? "n" : ""))); }
                        catch (Exception ex) { Console.WriteLine(string.Format(language.DownloadFali, ex.Message)); }
                    }
                    else
                    {
                        FormatWrite(string.Format(language.DownloadDone, Path.GetFileName(savePath)), ConsoleColor.Yellow);
                    }
                });
            }

            string backupName = "collection.db-" + DateTime.Now.ToFileTime() + ".bak"; //備份舊的收藏夾檔案

            File.Move(osuPath + "collection.db", osuPath + backupName);                //然後覆蓋新的收藏夾檔案
            Console.WriteLine(string.Format(language.BackupCollectionTo, osuPath + backupName));

            Console.WriteLine(language.WritingNewCollection);
            OsuFileIo.CollectionLoader.SaveOsuCollection(collectionManager.LoadedCollections, osuPath + "collection.db");

            if (OsuPathResolver.Instance.OsuIsRunning)
            {
                if (needDownloadBeatmapList.Count != 0)
                {
                    Exit(language.WriteDone1);
                }
                else
                {
                    Exit(language.WriteDone2);
                }
            }
            else
            {
                if (needDownloadBeatmapList.Count != 0)
                {
                    Exit(language.WriteDone3);
                }
                else
                {
                    Exit(language.WriteDone4);
                }
            }
        }
        public void Run(string[] args)
        {
            //IUserDialogs can be implemented in WinForm or WPF or Gtk or Console or...?
            UserDialogs = GuiComponentsProvider.Instance.GetClassImplementing <IUserDialogs>();

            if (Settings.Default.DontAskAboutOsuDirectory)
            {
                OsuDirectory = OsuFileIo.OsuPathResolver.GetOsuDir(_ => false, _ => Settings.Default.OsuDirectory);
            }
            else
            {
                OsuDirectory = OsuFileIo.OsuPathResolver.GetOsuDir(dir =>
                {
                    var result = UserDialogs.YesNoMessageBox($"Detected osu! in \"{dir}\"{Environment.NewLine}Is that correct?", "osu! directory", MessageBoxType.Question,
                                                             "Don't ask me again");
                    Settings.Default.DontAskAboutOsuDirectory = result.doNotAskAgain;
                    Settings.Default.Save();
                    return(result.Result);
                }, UserDialogs.SelectDirectory);
            }

            if (string.IsNullOrEmpty(OsuDirectory) && UserDialogs.YesNoMessageBox(
                    "osu! could not be found. Do you want to continue regardless?" + Environment.NewLine +
                    "This will cause all .db collections to show only as beatmap hashes.", "osu! location",
                    MessageBoxType.Question) == false)
            {
                Quit();
            }

            if (!string.IsNullOrEmpty(OsuDirectory))
            {
                Settings.Default.OsuDirectory = OsuDirectory;
                Settings.Default.Save();
                //Load osu database and setting files
                var osuDbFile     = Path.Combine(OsuDirectory, @"osu!.db");
                var osuScoresFile = Path.Combine(OsuDirectory, @"scores.db");
                OsuFileIo.OsuDatabase.Load(osuDbFile);
                OsuFileIo.OsuSettings.Load(OsuDirectory);
                OsuFileIo.ScoresLoader.ReadDb(osuScoresFile);
                BeatmapUtils.OsuSongsDirectory = OsuFileIo.OsuSettings.CustomBeatmapDirectoryLocation;
            }

            //Init "main" classes
            CollectionsManager = new CollectionsManagerWithCounts(LoadedBeatmaps);

            var collectionAddRemoveForm = GuiComponentsProvider.Instance.GetClassImplementing <ICollectionAddRenameForm>();

            CollectionEditor = new CollectionEditor(CollectionsManager, CollectionsManager, collectionAddRemoveForm, OsuFileIo.LoadedMaps);

            if (args.Length > 0)
            {
                if (File.Exists(args[0]))
                {
                    CollectionsManager.EditCollection(CollectionEditArgs.AddCollections(OsuFileIo.CollectionLoader.LoadCollection(args[0])));
                }
            }

            var updateChecker = new UpdateChecker();

            updateChecker.CheckForUpdates();
            var infoTextModel = new InfoTextModel(updateChecker);

            var mainForm      = GuiComponentsProvider.Instance.GetClassImplementing <IMainFormView>();
            var mainPresenter = new MainFormPresenter(mainForm, new MainFormModel(CollectionEditor, UserDialogs), infoTextModel, WebCollectionProvider);

            //set initial text info and update events
            SetTextData(infoTextModel);


            var loginForm         = GuiComponentsProvider.Instance.GetClassImplementing <ILoginFormView>();
            var guiActionsHandler = new GuiActionsHandler(OsuFileIo, CollectionsManager, UserDialogs, mainForm, mainPresenter, loginForm);

            if (!string.IsNullOrWhiteSpace(Settings.Default.Osustats_apiKey))
            {
                guiActionsHandler.SidePanelActionsHandler.OsustatsLogin(null, Settings.Default.Osustats_apiKey);
            }

            mainForm.ShowAndBlock();
            Quit();
        }
        private void DeleteBeatmapsFromCollection(object sender)
        {
            var model = (IBeatmapListingModel)sender;

            _collectionEditor.EditCollection(CollectionEditArgs.RemoveBeatmaps(model.CurrentCollection.Name, model.SelectedBeatmaps));
        }
 private void CollectionListing_CollectionEditing(object sender, CollectionEditArgs collectionEditArgs)
 {
     _mainFormModel.GetCollectionEditor()?.EditCollection(collectionEditArgs);
 }