Move hashing functionality to ArchiveModelManager

This commit is contained in:
Dean Herbert
2018-11-28 19:16:05 +09:00
parent 0384f3549f
commit ab2b2493a1
3 changed files with 33 additions and 23 deletions

View File

@ -63,6 +63,8 @@ namespace osu.Game.Beatmaps
public override string[] HandledExtensions => new[] { ".osz" };
protected override string[] HashableFileTypes => new[] { ".osu" };
protected override string ImportFromStablePath => "Songs";
private readonly RulesetStore rulesets;
@ -129,9 +131,6 @@ namespace osu.Game.Beatmaps
beatmaps.ForEach(b => b.OnlineBeatmapID = null);
}
protected override BeatmapSetInfo CheckForExisting(BeatmapSetInfo model) =>
beatmaps.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
/// <summary>
/// Downloads a beatmap.
/// This will post notifications tracking progress.
@ -307,20 +306,6 @@ namespace osu.Game.Beatmaps
/// <returns>Results from the provided query.</returns>
public IQueryable<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query) => beatmaps.Beatmaps.AsNoTracking().Where(query);
/// <summary>
/// Create a SHA-2 hash from the provided archive based on contained beatmap (.osu) file content.
/// </summary>
private string computeBeatmapSetHash(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);
return hashable.ComputeSHA2Hash();
}
protected override BeatmapSetInfo CreateModel(ArchiveReader reader)
{
// let's make sure there are actually .osu files to import.
@ -339,7 +324,6 @@ namespace osu.Game.Beatmaps
{
OnlineBeatmapSetID = beatmap.BeatmapInfo.BeatmapSet?.OnlineBeatmapSetID,
Beatmaps = new List<BeatmapInfo>(),
Hash = computeBeatmapSetHash(reader),
Metadata = beatmap.Metadata,
};
}