mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Extract update into PreUpdate(), add test
This commit is contained in:
@ -201,10 +201,6 @@ namespace osu.Game.Beatmaps
|
||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
new LegacyBeatmapEncoder(beatmapContent).Encode(sw);
|
||||
|
||||
var attachedInfo = setInfo.Beatmaps.Single(b => b.ID == info.ID);
|
||||
var md5Hash = stream.ComputeMD5Hash();
|
||||
attachedInfo.MD5Hash = md5Hash;
|
||||
|
||||
UpdateFile(setInfo, setInfo.Files.Single(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase)), stream);
|
||||
}
|
||||
|
||||
@ -213,6 +209,19 @@ namespace osu.Game.Beatmaps
|
||||
workingCache.Remove(working);
|
||||
}
|
||||
|
||||
protected override void PreUpdate(BeatmapSetInfo item)
|
||||
{
|
||||
base.PreUpdate(item);
|
||||
|
||||
foreach (var info in item.Beatmaps)
|
||||
{
|
||||
var file = item.Files.FirstOrDefault(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
||||
|
||||
using (var stream = Files.Store.GetStream(file))
|
||||
info.MD5Hash = stream.ComputeMD5Hash();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>();
|
||||
|
||||
/// <summary>
|
||||
|
@ -430,10 +430,20 @@ namespace osu.Game.Database
|
||||
{
|
||||
item.Hash = computeHash(item);
|
||||
|
||||
PreUpdate(item);
|
||||
|
||||
ModelStore.Update(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform any final actions before the update to database executes.
|
||||
/// </summary>
|
||||
/// <param name="item">The <typeparamref name="TModel"/> that is being updated.</param>
|
||||
protected virtual void PreUpdate(TModel item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete an item from the manager.
|
||||
/// Is a no-op for already deleted items.
|
||||
|
Reference in New Issue
Block a user