Merge remote-tracking branch 'upstream/master' into merge-projects

This commit is contained in:
Dean Herbert 2017-09-19 20:43:20 +09:00
commit 4b0eee2bcc
2 changed files with 25 additions and 16 deletions

View File

@ -429,6 +429,15 @@ namespace osu.Game.Beatmaps
if (beatmapSet != null)
{
Undelete(beatmapSet);
// ensure all files are present and accessible
foreach (var f in beatmapSet.Files)
{
if (!storage.Exists(f.FileInfo.StoragePath))
using (Stream s = reader.GetStream(f.Filename))
files.Add(s, false);
}
return beatmapSet;
}

View File

@ -78,33 +78,33 @@ namespace osu.Game.IO
}
}
public FileInfo Add(Stream data)
public FileInfo Add(Stream data, bool reference = true)
{
string hash = data.ComputeSHA2Hash();
var existing = Connection.Table<FileInfo>().Where(f => f.Hash == hash).FirstOrDefault();
var info = existing ?? new FileInfo { Hash = hash };
if (existing != null)
string path = Path.Combine(prefix, info.StoragePath);
// we may be re-adding a file to fix missing store entries.
if (!Storage.Exists(path))
{
info = existing;
data.Seek(0, SeekOrigin.Begin);
using (var output = Storage.GetStream(path, FileAccess.Write))
data.CopyTo(output);
data.Seek(0, SeekOrigin.Begin);
}
else
{
string path = Path.Combine(prefix, info.StoragePath);
data.Seek(0, SeekOrigin.Begin);
if (!Storage.Exists(path))
using (var output = Storage.GetStream(path, FileAccess.Write))
data.CopyTo(output);
data.Seek(0, SeekOrigin.Begin);
if (existing == null)
Connection.Insert(info);
}
Reference(info);
if (reference || existing == null)
Reference(info);
return info;
}