1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 23:42:55 +08:00

Remove migration setting in favour of export option in the editor

This commit is contained in:
smoogipoo 2017-12-21 19:56:12 +09:00
parent a3fcc0b60c
commit b2c0b013aa
4 changed files with 21 additions and 82 deletions

View File

@ -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;
}
/// <summary>
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
/// </summary>

View File

@ -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<Storyboard>(populateStoryboard);
}
/// <summary>
/// Saves the <see cref="Beatmap"/>.
/// </summary>
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();

View File

@ -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);
}
});
}
}
}
}

View File

@ -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();