mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Merge pull request #15915 from peppy/tournament-bracket-parsing-fix
Fix `bracket.json` potentially getting saved after parsing failure
This commit is contained in:
commit
7084ef5245
@ -96,7 +96,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
||||
Directory.CreateDirectory(flagsPath);
|
||||
|
||||
// Define testing files corresponding to the specific file migrations that are needed
|
||||
string bracketFile = Path.Combine(osuRoot, "bracket.json");
|
||||
string bracketFile = Path.Combine(osuRoot, TournamentGameBase.BRACKET_FILENAME);
|
||||
|
||||
string drawingsConfig = Path.Combine(osuRoot, "drawings.ini");
|
||||
string drawingsFile = Path.Combine(osuRoot, "drawings.txt");
|
||||
@ -133,7 +133,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
||||
|
||||
Assert.That(storage.GetFullPath("."), Is.EqualTo(migratedPath));
|
||||
|
||||
Assert.True(storage.Exists("bracket.json"));
|
||||
Assert.True(storage.Exists(TournamentGameBase.BRACKET_FILENAME));
|
||||
Assert.True(storage.Exists("drawings.txt"));
|
||||
Assert.True(storage.Exists("drawings_results.txt"));
|
||||
|
||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Tournament.IO
|
||||
DeleteRecursive(source);
|
||||
}
|
||||
|
||||
moveFileIfExists("bracket.json", destination);
|
||||
moveFileIfExists(TournamentGameBase.BRACKET_FILENAME, destination);
|
||||
moveFileIfExists("drawings.txt", destination);
|
||||
moveFileIfExists("drawings_results.txt", destination);
|
||||
moveFileIfExists("drawings.ini", destination);
|
||||
|
@ -71,7 +71,7 @@ namespace osu.Game.Tournament
|
||||
loadingSpinner.Expire();
|
||||
|
||||
Logger.Error(t.Exception, "Couldn't load bracket with error");
|
||||
Add(new WarningBox("Your bracket.json file could not be parsed. Please check runtime.log for more details."));
|
||||
Add(new WarningBox($"Your {BRACKET_FILENAME} file could not be parsed. Please check runtime.log for more details."));
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -11,6 +11,7 @@ using osu.Framework.Graphics;
|
||||
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;
|
||||
@ -26,15 +27,15 @@ namespace osu.Game.Tournament
|
||||
[Cached(typeof(TournamentGameBase))]
|
||||
public class TournamentGameBase : OsuGameBase
|
||||
{
|
||||
private const string bracket_filename = "bracket.json";
|
||||
public const string BRACKET_FILENAME = @"bracket.json";
|
||||
private LadderInfo ladder;
|
||||
private TournamentStorage storage;
|
||||
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)
|
||||
{
|
||||
@ -71,9 +72,9 @@ namespace osu.Game.Tournament
|
||||
{
|
||||
try
|
||||
{
|
||||
if (storage.Exists(bracket_filename))
|
||||
if (storage.Exists(BRACKET_FILENAME))
|
||||
{
|
||||
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
|
||||
using (Stream stream = storage.GetStream(BRACKET_FILENAME, FileAccess.Read, FileMode.Open))
|
||||
using (var sr = new StreamReader(stream))
|
||||
ladder = JsonConvert.DeserializeObject<LadderInfo>(sr.ReadToEnd(), new JsonPointConverter());
|
||||
}
|
||||
@ -144,7 +145,7 @@ namespace osu.Game.Tournament
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
taskCompletionSource.SetException(e);
|
||||
bracketLoadTaskCompletionSource.SetException(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -156,7 +157,7 @@ namespace osu.Game.Tournament
|
||||
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
|
||||
Add(ipc);
|
||||
|
||||
taskCompletionSource.SetResult(true);
|
||||
bracketLoadTaskCompletionSource.SetResult(true);
|
||||
|
||||
initialisationText.Expire();
|
||||
});
|
||||
@ -292,6 +293,12 @@ namespace osu.Game.Tournament
|
||||
|
||||
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();
|
||||
|
||||
@ -309,7 +316,7 @@ namespace osu.Game.Tournament
|
||||
Converters = new JsonConverter[] { new JsonPointConverter() }
|
||||
});
|
||||
|
||||
using (var stream = storage.GetStream(bracket_filename, FileAccess.Write, FileMode.Create))
|
||||
using (var stream = storage.GetStream(BRACKET_FILENAME, FileAccess.Write, FileMode.Create))
|
||||
using (var sw = new StreamWriter(stream))
|
||||
sw.Write(serialisedLadder);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user