1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Add support for undeleting beatmaps if they are imported during an undeleted state.

This commit is contained in:
Dean Herbert 2017-02-24 17:49:19 +09:00
parent 65a24dfe5d
commit c178493877
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49

View File

@ -119,10 +119,6 @@ namespace osu.Game.Database
using (var reader = ArchiveReader.GetReader(storage, path)) using (var reader = ArchiveReader.GetReader(storage, path))
metadata = reader.ReadMetadata(); metadata = reader.ReadMetadata();
if (metadata.OnlineBeatmapSetID.HasValue &&
connection.Table<BeatmapSetInfo>().Count(b => b.OnlineBeatmapSetID == metadata.OnlineBeatmapSetID) != 0)
return; // TODO: Update this beatmap instead
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
{ {
using (var md5 = MD5.Create()) using (var md5 = MD5.Create())
@ -131,10 +127,26 @@ namespace osu.Game.Database
hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant(); hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant();
input.Seek(0, SeekOrigin.Begin); input.Seek(0, SeekOrigin.Begin);
path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash);
using (var output = storage.GetStream(path, FileAccess.Write)) if (!storage.Exists(path))
input.CopyTo(output); using (var output = storage.GetStream(path, FileAccess.Write))
input.CopyTo(output);
} }
} }
var existing = connection.Table<BeatmapSetInfo>().FirstOrDefault(b => b.Hash == hash);
if (existing != null)
{
if (existing.DeletePending)
{
existing.DeletePending = false;
Update(existing, false);
BeatmapSetAdded?.Invoke(existing);
}
return;
}
var beatmapSet = new BeatmapSetInfo var beatmapSet = new BeatmapSetInfo
{ {
OnlineBeatmapSetID = metadata.OnlineBeatmapSetID, OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,