mirror of
https://github.com/ppy/osu
synced 2025-01-10 16:19:47 +00:00
Read and write bracket from storage instead of arbitrary location
This commit is contained in:
parent
a918e83b1e
commit
97b32a72f5
@ -5,6 +5,7 @@ using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
@ -17,7 +18,10 @@ namespace osu.Game.Tournament.Tests
|
||||
{
|
||||
public abstract class LadderTestCase : OsuTestCase
|
||||
{
|
||||
private const string bracket_filename = "bracket.json";
|
||||
|
||||
protected LadderInfo Ladder;
|
||||
private Storage storage;
|
||||
|
||||
[Resolved]
|
||||
private APIAccess api { get; set; } = null;
|
||||
@ -26,9 +30,19 @@ namespace osu.Game.Tournament.Tests
|
||||
private RulesetStore rulesets { get; set; } = null;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(Storage storage)
|
||||
{
|
||||
Ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject<LadderInfo>(File.ReadAllText(@"bracket.json")) : new LadderInfo();
|
||||
this.storage = storage;
|
||||
|
||||
string content = null;
|
||||
if (storage.Exists(bracket_filename))
|
||||
{
|
||||
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
|
||||
using (var sr = new StreamReader(stream))
|
||||
content = sr.ReadToEnd();
|
||||
}
|
||||
|
||||
Ladder = content != null ? JsonConvert.DeserializeObject<LadderInfo>(content) : new LadderInfo();
|
||||
|
||||
bool addedInfo = false;
|
||||
|
||||
@ -62,7 +76,10 @@ namespace osu.Game.Tournament.Tests
|
||||
|
||||
protected virtual void SaveChanges()
|
||||
{
|
||||
File.WriteAllText(@"bracket.json", JsonConvert.SerializeObject(Ladder,
|
||||
using (var stream = storage.GetStream(bracket_filename, FileAccess.Write, FileMode.Create))
|
||||
using (var sw = new StreamWriter(stream))
|
||||
{
|
||||
sw.Write(JsonConvert.SerializeObject(Ladder,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
@ -70,4 +87,5 @@ namespace osu.Game.Tournament.Tests
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user