Only write when writes occur

Also add finaliser logic for safety. Also better threading. Also more cleanup.
This commit is contained in:
Dean Herbert
2018-02-12 19:57:21 +09:00
parent edc3638175
commit 8b37fde15b
8 changed files with 86 additions and 50 deletions

View File

@ -30,11 +30,9 @@ namespace osu.Game.IO
{
using (var usage = ContextFactory.GetForWrite())
{
var context = usage.Context;
string hash = data.ComputeSHA2Hash();
var existing = context.FileInfo.FirstOrDefault(f => f.Hash == hash);
var existing = usage.Context.FileInfo.FirstOrDefault(f => f.Hash == hash);
var info = existing ?? new FileInfo { Hash = hash };
@ -60,6 +58,8 @@ namespace osu.Game.IO
public void Reference(params FileInfo[] files)
{
if (files.Length == 0) return;
using (var usage = ContextFactory.GetForWrite())
{
var context = usage.Context;
@ -75,9 +75,12 @@ namespace osu.Game.IO
public void Dereference(params FileInfo[] files)
{
if (files.Length == 0) return;
using (var usage = ContextFactory.GetForWrite())
{
var context = usage.Context;
foreach (var f in files.GroupBy(f => f.ID))
{
var refetch = context.FileInfo.Find(f.Key);