diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 40f1545b77..ca1a056992 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -553,76 +553,6 @@ namespace osu.Game.Beatmaps return beatmapSet; } - public void UpdateContent(BeatmapInfo beatmapInfo, Stream newData) - { - var context = createContext(); - - using (var transaction = context.BeginTransaction()) - { - var setInfo = beatmapInfo.BeatmapSet; - var existingSetFileInfo = setInfo.Files.First(f => f.FileInfo.Hash == beatmapInfo.Hash); - var existingFileInfo = existingSetFileInfo.FileInfo; - - existingSetFileInfo.FileInfo = files.Add(newData); - files.Dereference(existingFileInfo); - - beatmapInfo.Hash = newData.ComputeSHA2Hash(); - beatmapInfo.MD5Hash = newData.ComputeMD5Hash(); - - context.Update(existingSetFileInfo); - context.Update(beatmapInfo); - - context.SaveChanges(transaction); - } - } - - public void MigrateAllToNewFormat() - { - var usableSets = GetAllUsableBeatmapSets(); - - if (usableSets.Count == 0) - return; - - var notification = new ProgressNotification - { - Progress = 0, - State = ProgressNotificationState.Active, - }; - - PostNotification?.Invoke(notification); - - int i = 1; - foreach (var set in usableSets) - { - if (notification.State == ProgressNotificationState.Cancelled) - // user requested abort - return; - - notification.Text = $"Migrating ({i} of {usableSets.Count})"; - notification.Progress = (float)i++ / usableSets.Count; - - foreach (var beatmap in set.Beatmaps) - { - if (notification.State == ProgressNotificationState.Cancelled) - // user requested abort - return; - - var working = GetWorkingBeatmap(beatmap); - using (var ms = new MemoryStream()) - using (var sw = new StreamWriter(ms)) - { - sw.Write(working.Beatmap.Serialize()); - sw.Flush(); - - ms.Position = 0; - UpdateContent(beatmap, ms); - } - } - } - - notification.State = ProgressNotificationState.Completed; - } - /// /// Returns a list of all usable s. /// diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 736cc2a0b0..8c8cf212c1 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -10,6 +10,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using osu.Game.Storyboards; +using osu.Framework.IO.File; +using System.IO; +using osu.Game.IO.Serialization; +using System.Diagnostics; namespace osu.Game.Beatmaps { @@ -38,6 +42,17 @@ namespace osu.Game.Beatmaps storyboard = new AsyncLazy(populateStoryboard); } + /// + /// Saves the . + /// + public void Save() + { + var path = FileSafety.GetTempPath(Guid.NewGuid().ToString().Replace("-", string.Empty) + ".json"); + using (var sw = new StreamWriter(path)) + sw.WriteLine(Beatmap.Serialize()); + Process.Start(path); + } + protected abstract Beatmap GetBeatmap(); protected abstract Texture GetBackground(); protected abstract Track GetTrack(); diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index 2b40ade895..a648ebd64c 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -58,18 +58,6 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance } }; - if (!osuGame.IsDeployedBuild) - { - Add(migrateButton = new SettingsButton - { - Text = "Migrate all beatmaps to the new format", - Action = () => - { - migrateButton.Enabled.Value = false; - Task.Factory.StartNew(beatmaps.MigrateAllToNewFormat).ContinueWith(t => Schedule(() => migrateButton.Enabled.Value = true), TaskContinuationOptions.LongRunning); - } - }); - } } } } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 607ff792d8..5ff48f1adf 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -67,6 +67,7 @@ namespace osu.Game.Screens.Edit { Items = new[] { + new EditorMenuItem("Export", MenuItemType.Standard, exportBeatmap), new EditorMenuItem("Exit", MenuItemType.Standard, Exit) } } @@ -136,6 +137,11 @@ namespace osu.Game.Screens.Edit bottomBackground.Colour = colours.Gray2; } + private void exportBeatmap() + { + Beatmap.Value.Save(); + } + private void onModeChanged(EditorScreenMode mode) { currentScreen?.Exit();