1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Refresh import context on import error

This commit is contained in:
Dean Herbert 2017-12-31 21:22:55 +09:00
parent b269282407
commit 7154efa1c6

View File

@ -101,15 +101,26 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public Func<Storage> GetStableStorage { private get; set; } public Func<Storage> GetStableStorage { private get; set; }
public BeatmapManager(Storage storage, Func<OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null) private void refreshImportContext()
{ {
createContext = context; lock (importContextLock)
{
importContext?.Value?.Dispose();
importContext = new Lazy<OsuDbContext>(() => importContext = new Lazy<OsuDbContext>(() =>
{ {
var c = createContext(); var c = createContext();
c.Database.AutoTransactionsEnabled = false; c.Database.AutoTransactionsEnabled = false;
return c; return c;
}); });
}
}
public BeatmapManager(Storage storage, Func<OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
{
createContext = context;
refreshImportContext();
beatmaps = createBeatmapStore(context); beatmaps = createBeatmapStore(context);
files = new FileStore(context, storage); files = new FileStore(context, storage);
@ -174,13 +185,16 @@ namespace osu.Game.Beatmaps
{ {
e = e.InnerException ?? e; e = e.InnerException ?? e;
Logger.Error(e, $@"Could not import beatmap set ({Path.GetFileName(path)})"); Logger.Error(e, $@"Could not import beatmap set ({Path.GetFileName(path)})");
refreshImportContext();
} }
} }
notification.State = ProgressNotificationState.Completed; notification.State = ProgressNotificationState.Completed;
} }
private readonly Lazy<OsuDbContext> importContext; private readonly object importContextLock = new object();
private Lazy<OsuDbContext> importContext;
/// <summary> /// <summary>
/// Import a beatmap from an <see cref="ArchiveReader"/>. /// Import a beatmap from an <see cref="ArchiveReader"/>.
@ -189,7 +203,7 @@ namespace osu.Game.Beatmaps
public BeatmapSetInfo Import(ArchiveReader archiveReader) public BeatmapSetInfo Import(ArchiveReader archiveReader)
{ {
// let's only allow one concurrent import at a time for now. // let's only allow one concurrent import at a time for now.
lock (importContext) lock (importContextLock)
{ {
var context = importContext.Value; var context = importContext.Value;
@ -314,7 +328,7 @@ namespace osu.Game.Beatmaps
/// <param name="beatmapSet">The beatmap set to delete.</param> /// <param name="beatmapSet">The beatmap set to delete.</param>
public void Delete(BeatmapSetInfo beatmapSet) public void Delete(BeatmapSetInfo beatmapSet)
{ {
lock (importContext) lock (importContextLock)
{ {
var context = importContext.Value; var context = importContext.Value;
@ -377,7 +391,7 @@ namespace osu.Game.Beatmaps
if (beatmapSet.Protected) if (beatmapSet.Protected)
return; return;
lock (importContext) lock (importContextLock)
{ {
var context = importContext.Value; var context = importContext.Value;