Rework StableInfo into a DI'd data structure

This commit is contained in:
Bartłomiej Dach
2020-06-13 15:05:52 +02:00
parent 5f79feaa8b
commit 1cd96b8002
5 changed files with 67 additions and 60 deletions

View File

@ -5,7 +5,6 @@ using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Microsoft.Win32;
using osu.Framework.Allocation;
using osu.Framework.Logging;
@ -34,14 +33,13 @@ namespace osu.Game.Tournament.IPC
[Resolved]
private LadderInfo ladder { get; set; }
[Resolved]
private StableInfo stableInfo { get; set; }
private int lastBeatmapId;
private ScheduledDelegate scheduled;
private GetBeatmapRequest beatmapLookupRequest;
public StableInfo StableInfo { get; private set; }
public const string STABLE_CONFIG = "tournament/stable.json";
public Storage IPCStorage { get; private set; }
[Resolved]
@ -165,8 +163,8 @@ namespace osu.Game.Tournament.IPC
private string findStablePath()
{
if (!string.IsNullOrEmpty(readStableConfig()))
return StableInfo.StablePath.Value;
if (!string.IsNullOrEmpty(stableInfo.StablePath))
return stableInfo.StablePath;
string stableInstallPath = string.Empty;
@ -204,43 +202,13 @@ namespace osu.Game.Tournament.IPC
if (!ipcFileExistsInDirectory(path))
return false;
StableInfo.StablePath.Value = path;
using (var stream = tournamentStorage.GetStream(STABLE_CONFIG, FileAccess.Write, FileMode.Create))
using (var sw = new StreamWriter(stream))
{
sw.Write(JsonConvert.SerializeObject(StableInfo,
new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
}));
}
stableInfo.StablePath = path;
LocateStableStorage();
stableInfo.SaveChanges();
return true;
}
private string readStableConfig()
{
if (StableInfo == null)
StableInfo = new StableInfo();
if (tournamentStorage.Exists(FileBasedIPC.STABLE_CONFIG))
{
using (Stream stream = tournamentStorage.GetStream(FileBasedIPC.STABLE_CONFIG, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
{
StableInfo = JsonConvert.DeserializeObject<StableInfo>(sr.ReadToEnd());
}
return StableInfo.StablePath.Value;
}
return null;
}
private string findFromEnvVar()
{
try