mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Allow files missing on disk to be restored on beatmap import
Previously, in the rare case the database became out of sync with the disk store, it was impossible to feasibly repair a beatmap. Now reimporting checks each file exists on disk and adds it back if it doesn't.
This commit is contained in:
parent
4a0370a68a
commit
c41ca10715
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user