Example #1
0
        public HitsoundPreviewHelperVm()
        {
            _items = new ObservableCollection <HitsoundZone>();

            RhythmGuideCommand = new CommandImplementation(
                _ => {
                try {
                    if (_rhythmGuideWindow == null)
                    {
                        _rhythmGuideWindow         = new RhythmGuideWindow();
                        _rhythmGuideWindow.Closed += RhythmGuideWindowOnClosed;
                        _rhythmGuideWindow.Show();
                    }
                    else
                    {
                        _rhythmGuideWindow.Focus();
                    }
                } catch (Exception ex) { ex.Show(); }
            });
            AddCommand = new CommandImplementation(
                _ => {
                try {
                    var newZone = new HitsoundZone();
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                        var editor = EditorReaderStuff.GetBeatmapEditor(EditorReaderStuff.GetFullEditorReader(),
                                                                        out var selected);
                        if (selected.Count > 0)
                        {
                            newZone.XPos = selected[0].Pos.X;
                            newZone.YPos = editor.Beatmap.General["Mode"].IntValue == 3 ? -1 : selected[0].Pos.Y;
                        }
                        else
                        {
                            MessageBox.Show("Please select a hit object to fetch the coordinates.");
                        }
                    }
                    Items.Add(newZone);
                } catch (Exception ex) { ex.Show(); }
            });
            CopyCommand = new CommandImplementation(
                _ => {
                try {
                    int initialCount = Items.Count;
                    for (int i = 0; i < initialCount; i++)
                    {
                        if (Items[i].IsSelected)
                        {
                            Items.Add(Items[i].Copy());
                        }
                    }
                } catch (Exception ex) { ex.Show(); }
            });
            RemoveCommand = new CommandImplementation(
                _ => {
                try {
                    Items.RemoveAll(o => o.IsSelected);
                } catch (Exception ex) { ex.Show(); }
            });
        }
        private void PeriodicBackupTimerOnTick(object sender, EventArgs e)
        {
            try {
                // Get the newest beatmap, save a temp version, get the hash and compare it to the previous hash, backup temp file
                var path = IOHelper.GetCurrentBeatmap();

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                // Don't make period backup if the editor is not open
                if (!EditorReaderStuff.IsEditorOpen())
                {
                    return;
                }

                EditorReader reader = null;
                try {
                    reader = EditorReaderStuff.GetFullEditorReader();
                } catch (Exception ex) {
                    Console.WriteLine(ex.MessageStackTrace());
                }

                var editor = EditorReaderStuff.GetNewestVersionOrNot(path, reader);

                // Save temp version
                var tempPath = Path.Combine(MainWindow.AppDataPath, "temp.osu");

                Editor.SaveFile(tempPath, editor.Beatmap.GetLines());

                // Get MD5 from temp file
                var currentMapHash = EditorReaderStuff.GetMD5FromPath(tempPath);

                // Comparing with previously made periodic backup
                if (currentMapHash == previousPeriodicBackupHash)
                {
                    return;
                }

                // Saving backup of the map
                BackupManager.SaveMapBackup(tempPath, true, Path.GetFileName(path), "PB");  // PB stands for Periodic Backup

                previousPeriodicBackupHash = currentMapHash;
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
        private static void SmartQuickRun()
        {
            try
            {
                if (!SettingsManager.Settings.SmartQuickRunEnabled)
                {
                    QuickRunCurrentTool(); return;
                }

                var reader = EditorReaderStuff.GetFullEditorReader();

                var       so   = reader.hitObjects.Count(o => o.IsSelected);
                IQuickRun tool = null;

                if (System.Windows.Application.Current.Dispatcher == null)
                {
                    return;
                }

                System.Windows.Application.Current.Dispatcher.Invoke(() => {
                    if (so == 0)
                    {
                        if (SettingsManager.Settings.NoneQuickRunTool == "<Current Tool>")
                        {
                            QuickRunCurrentTool(); return;
                        }
                        if (!(MainWindow.AppWindow.Views.GetView(SettingsManager.Settings.NoneQuickRunTool) is IQuickRun noneTool))
                        {
                            return;
                        }

                        tool = noneTool;
                    }
                    else if (so == 1)
                    {
                        if (SettingsManager.Settings.SingleQuickRunTool == "<Current Tool>")
                        {
                            QuickRunCurrentTool(); return;
                        }
                        if (!(MainWindow.AppWindow.Views.GetView(SettingsManager.Settings.SingleQuickRunTool) is IQuickRun singleTool))
                        {
                            return;
                        }

                        tool = singleTool;
                    }
                    else if (so > 1)
                    {
                        if (SettingsManager.Settings.MultipleQuickRunTool == "<Current Tool>")
                        {
                            QuickRunCurrentTool(); return;
                        }
                        if (!(MainWindow.AppWindow.Views.GetView(SettingsManager.Settings.MultipleQuickRunTool) is IQuickRun multiTool))
                        {
                            return;
                        }

                        tool = multiTool;
                    }

                    if (tool == null)
                    {
                        return;
                    }

                    tool.RunFinished -= Reload;
                    tool.RunFinished += Reload;
                    tool.QuickRun();
                });
            }
            catch (Exception ex)
            {
                ex.Show();
            }
        }
Example #4
0
        private string ExportPattern(PatternGalleryVm args, BackgroundWorker worker, DoWorkEventArgs _)
        {
            EditorReader reader;
            double       exportTime       = 0;
            bool         usePatternOffset = false;

            switch (args.ExportTimeMode)
            {
            case ExportTimeMode.Current:
                try {
                    reader     = EditorReaderStuff.GetFullEditorReader();
                    exportTime = reader.EditorTime();
                }
                catch (Exception e) {
                    throw new Exception("Could not fetch the current editor time.", e);
                }
                break;

            case ExportTimeMode.Pattern:
                reader           = EditorReaderStuff.GetFullEditorReaderOrNot();
                usePatternOffset = true;
                break;

            case ExportTimeMode.Custom:
                reader     = EditorReaderStuff.GetFullEditorReaderOrNot();
                exportTime = args.CustomExportTime;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(ExportTimeMode), "Invalid value encountered");
            }

            var editor = EditorReaderStuff.GetNewestVersionOrNot(args.Paths[0], reader);

            var patternCount = args.Patterns.Count(o => o.IsSelected);

            if (patternCount == 0)
            {
                throw new Exception("No pattern has been selected to export.");
            }

            var patternPlacer = args.OsuPatternPlacer;

            foreach (var pattern in args.Patterns.Where(o => o.IsSelected))
            {
                var patternBeatmap = pattern.GetPatternBeatmap(args.FileHandler);

                if (usePatternOffset)
                {
                    patternPlacer.PlaceOsuPattern(patternBeatmap, editor.Beatmap, protectBeatmapPattern: false);
                }
                else
                {
                    patternPlacer.PlaceOsuPatternAtTime(patternBeatmap, editor.Beatmap, exportTime, false);
                }

                // Increase pattern use count and time
                pattern.UseCount++;
                pattern.LastUsedTime = DateTime.Now;
            }

            editor.SaveFile();

            // Complete progressbar
            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(100);
            }

            // Do stuff
            RunFinished?.Invoke(this, new RunToolCompletedEventArgs(true, reader != null, args.Quick));

            return("Successfully exported pattern!");
        }