mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 21:12:55 +08: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 Newtonsoft.Json;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -17,7 +18,10 @@ namespace osu.Game.Tournament.Tests
|
|||||||
{
|
{
|
||||||
public abstract class LadderTestCase : OsuTestCase
|
public abstract class LadderTestCase : OsuTestCase
|
||||||
{
|
{
|
||||||
|
private const string bracket_filename = "bracket.json";
|
||||||
|
|
||||||
protected LadderInfo Ladder;
|
protected LadderInfo Ladder;
|
||||||
|
private Storage storage;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private APIAccess api { get; set; } = null;
|
private APIAccess api { get; set; } = null;
|
||||||
@ -26,9 +30,19 @@ namespace osu.Game.Tournament.Tests
|
|||||||
private RulesetStore rulesets { get; set; } = null;
|
private RulesetStore rulesets { get; set; } = null;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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;
|
bool addedInfo = false;
|
||||||
|
|
||||||
@ -62,7 +76,10 @@ namespace osu.Game.Tournament.Tests
|
|||||||
|
|
||||||
protected virtual void SaveChanges()
|
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
|
new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
@ -71,3 +88,4 @@ namespace osu.Game.Tournament.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user