Avoid saving bracket if parsing failed, at all costs

This commit is contained in:
Dean Herbert 2021-12-03 16:06:38 +09:00
parent ba05a0a383
commit 5158736839
1 changed files with 11 additions and 4 deletions

View File

@ -11,6 +11,7 @@
using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests;
@ -32,9 +33,9 @@ public class TournamentGameBase : OsuGameBase
private DependencyContainer dependencies;
private FileBasedIPC ipc;
protected Task BracketLoadTask => taskCompletionSource.Task;
protected Task BracketLoadTask => bracketLoadTaskCompletionSource.Task;
private readonly TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
private readonly TaskCompletionSource<bool> bracketLoadTaskCompletionSource = new TaskCompletionSource<bool>();
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
@ -144,7 +145,7 @@ private void readBracket()
}
catch (Exception e)
{
taskCompletionSource.SetException(e);
bracketLoadTaskCompletionSource.SetException(e);
return;
}
@ -156,7 +157,7 @@ private void readBracket()
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
Add(ipc);
taskCompletionSource.SetResult(true);
bracketLoadTaskCompletionSource.SetResult(true);
initialisationText.Expire();
});
@ -292,6 +293,12 @@ protected override void LoadComplete()
protected virtual void SaveChanges()
{
if (!bracketLoadTaskCompletionSource.Task.IsCompletedSuccessfully)
{
Logger.Log("Inhibiting bracket save as bracket parsing failed");
return;
}
foreach (var r in ladder.Rounds)
r.Matches = ladder.Matches.Where(p => p.Round.Value == r).Select(p => p.ID).ToList();