Allow a single beatmap to reference the same file multiple times

This fixes incorrect reference counts causing database desync.
This commit is contained in:
Dean Herbert
2017-07-31 21:48:03 +09:00
parent bc21798e41
commit 404497fa10
6 changed files with 46 additions and 28 deletions

View File

@ -19,7 +19,6 @@ using osu.Game.IO;
using osu.Game.IPC;
using osu.Game.Rulesets;
using SQLite.Net;
using FileInfo = osu.Game.IO.FileInfo;
namespace osu.Game.Beatmaps
{
@ -135,7 +134,7 @@ namespace osu.Game.Beatmaps
if (!beatmaps.Delete(beatmapSet)) return;
if (!beatmapSet.Protected)
files.Dereference(beatmapSet.Files);
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo));
}
/// <summary>
@ -147,7 +146,8 @@ namespace osu.Game.Beatmaps
{
if (!beatmaps.Undelete(beatmapSet)) return;
files.Reference(beatmapSet.Files);
if (!beatmapSet.Protected)
files.Reference(beatmapSet.Files.Select(f => f.FileInfo));
}
/// <summary>
@ -265,12 +265,16 @@ namespace osu.Game.Beatmaps
return beatmapSet;
}
List<FileInfo> fileInfos = new List<FileInfo>();
List<BeatmapSetFileInfo> fileInfos = new List<BeatmapSetFileInfo>();
// import files to manager
foreach (string file in reader.Filenames)
using (Stream s = reader.GetStream(file))
fileInfos.Add(files.Add(s, file));
fileInfos.Add(new BeatmapSetFileInfo
{
Filename = file,
FileInfo = files.Add(s)
});
BeatmapMetadata metadata;
@ -366,7 +370,7 @@ namespace osu.Game.Beatmaps
catch { return null; }
}
private string getPathForFile(string filename) => BeatmapSetInfo.Files.First(f => f.Filename == filename).StoragePath;
private string getPathForFile(string filename) => BeatmapSetInfo.Files.First(f => f.Filename == filename).FileInfo.StoragePath;
protected override Texture GetBackground()
{

View File

@ -2,16 +2,26 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.IO;
using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes;
namespace osu.Game.Beatmaps
{
public class BeatmapSetFileInfo
{
[ForeignKey(typeof(BeatmapSetInfo))]
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
[ForeignKey(typeof(BeatmapSetInfo)), NotNull]
public int BeatmapSetInfoID { get; set; }
[ForeignKey(typeof(FileInfo))]
[ForeignKey(typeof(FileInfo)), NotNull]
public int FileInfoID { get; set; }
[OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public FileInfo FileInfo { get; set; }
[NotNull]
public string Filename { get; set; }
}
}

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using osu.Game.IO;
using SQLite.Net.Attributes;
using SQLiteNetExtensions.Attributes;
@ -37,8 +36,8 @@ namespace osu.Game.Beatmaps
public string StoryboardFile => Files.FirstOrDefault(f => f.Filename.EndsWith(".osb"))?.Filename;
[ManyToMany(typeof(BeatmapSetFileInfo), CascadeOperations = CascadeOperation.CascadeRead)]
public List<FileInfo> Files { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<BeatmapSetFileInfo> Files { get; set; }
public bool Protected { get; set; }
}