mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 16:02:55 +08:00
Simplify hashing method
Also exit the import process before importing files to the file store to avoid incorrect reference count increments.
This commit is contained in:
parent
cbe7b08642
commit
fdc6666c71
@ -246,40 +246,39 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <returns>The imported beatmap, or an existing instance if it is already present.</returns>
|
/// <returns>The imported beatmap, or an existing instance if it is already present.</returns>
|
||||||
private BeatmapSetInfo importToStorage(ArchiveReader reader)
|
private BeatmapSetInfo importToStorage(ArchiveReader reader)
|
||||||
{
|
{
|
||||||
|
// for now, concatenate all .osu files in the set to create a unique hash.
|
||||||
|
MemoryStream hashable = new MemoryStream();
|
||||||
|
foreach (string file in reader.Filenames.Where(f => f.EndsWith(".osu")))
|
||||||
|
using (Stream s = reader.GetStream(file))
|
||||||
|
s.CopyTo(hashable);
|
||||||
|
|
||||||
|
var hash = hashable.GetMd5Hash();
|
||||||
|
|
||||||
|
// check if this beatmap has already been imported and exit early if so.
|
||||||
|
var beatmapSet = beatmaps.QueryAndPopulate<BeatmapSetInfo>().FirstOrDefault(b => b.Hash == hash);
|
||||||
|
if (beatmapSet != null)
|
||||||
|
{
|
||||||
|
Undelete(beatmapSet);
|
||||||
|
return beatmapSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FileInfo> fileInfos = new List<FileInfo>();
|
||||||
|
|
||||||
|
// import files to store
|
||||||
|
foreach (string file in reader.Filenames)
|
||||||
|
using (Stream s = reader.GetStream(file))
|
||||||
|
fileInfos.Add(files.Add(s, file));
|
||||||
|
|
||||||
BeatmapMetadata metadata;
|
BeatmapMetadata metadata;
|
||||||
|
|
||||||
using (var stream = new StreamReader(reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu")))))
|
using (var stream = new StreamReader(reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu")))))
|
||||||
metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata;
|
metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata;
|
||||||
|
|
||||||
MemoryStream hashable = new MemoryStream();
|
beatmapSet = new BeatmapSetInfo
|
||||||
|
|
||||||
List<FileInfo> fileInfos = new List<FileInfo>();
|
|
||||||
|
|
||||||
foreach (string file in reader.Filenames)
|
|
||||||
{
|
|
||||||
using (Stream s = reader.GetStream(file))
|
|
||||||
{
|
|
||||||
fileInfos.Add(files.Add(s, file));
|
|
||||||
s.CopyTo(hashable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var overallHash = hashable.GetMd5Hash();
|
|
||||||
|
|
||||||
var existing = beatmaps.Query<BeatmapSetInfo>().FirstOrDefault(b => b.Hash == overallHash);
|
|
||||||
|
|
||||||
if (existing != null)
|
|
||||||
{
|
|
||||||
beatmaps.Populate(existing);
|
|
||||||
Undelete(existing);
|
|
||||||
return existing;
|
|
||||||
}
|
|
||||||
|
|
||||||
var beatmapSet = new BeatmapSetInfo
|
|
||||||
{
|
{
|
||||||
OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
|
OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
|
||||||
Beatmaps = new List<BeatmapInfo>(),
|
Beatmaps = new List<BeatmapInfo>(),
|
||||||
Hash = overallHash,
|
Hash = hash,
|
||||||
Files = fileInfos,
|
Files = fileInfos,
|
||||||
Metadata = metadata
|
Metadata = metadata
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user