Rework duplicate detection in AddBeatmap

This commit is contained in:
Drew DeVault 2016-10-18 15:41:46 -04:00
parent ad14462369
commit 105bba6178
2 changed files with 5 additions and 7 deletions

View File

@ -1,6 +1,7 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using OpenTK.Graphics;
using osu.Game.Beatmaps.Objects;

View File

@ -33,7 +33,10 @@ public BeatmapDatabase(BasicStorage storage)
public void AddBeatmap(string path)
{
string hash = null;
ArchiveReader reader;
var reader = ArchiveReader.GetReader(storage, path);
var metadata = reader.ReadMetadata();
if (connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
return; // TODO: Update this beatmap instead
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
{
using (var md5 = MD5.Create())
@ -44,14 +47,8 @@ public void AddBeatmap(string path)
var outputPath = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash);
using (var output = storage.GetStream(outputPath, FileAccess.Write))
input.CopyTo(output);
reader = ArchiveReader.GetReader(storage, path = outputPath);
}
}
else
reader = ArchiveReader.GetReader(storage, path);
var metadata = reader.ReadMetadata();
if (connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
return; // TODO: Update this beatmap instead
string[] mapNames = reader.ReadBeatmaps();
var beatmapSet = new BeatmapSetInfo
{