Read from (and allow reloading) IPC source

This commit is contained in:
Dean Herbert 2019-09-22 04:15:02 +09:00
parent 3b52e7c724
commit 47a89231ad
2 changed files with 117 additions and 84 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Allocation;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Platform.Windows; using osu.Framework.Platform.Windows;
using osu.Framework.Threading;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -26,34 +27,44 @@ namespace osu.Game.Tournament.IPC
[Resolved] [Resolved]
protected RulesetStore Rulesets { get; private set; } protected RulesetStore Rulesets { get; private set; }
[Resolved]
private GameHost host { get; set; }
[Resolved]
private LadderInfo ladder { get; set; }
private int lastBeatmapId; private int lastBeatmapId;
private ScheduledDelegate scheduled;
public Storage Storage { get; private set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(LadderInfo ladder, GameHost host) private void load()
{ {
StableStorage stable; LocateStableStorage();
}
public Storage LocateStableStorage()
{
scheduled?.Cancel();
Storage = null;
try try
{ {
stable = new StableStorage(host as DesktopGameHost); Storage = new StableStorage(host as DesktopGameHost);
}
catch (Exception e)
{
Logger.Error(e, "Stable installation could not be found; disabling file based IPC");
return;
}
const string file_ipc_filename = "ipc.txt"; const string file_ipc_filename = "ipc.txt";
const string file_ipc_state_filename = "ipc-state.txt"; const string file_ipc_state_filename = "ipc-state.txt";
const string file_ipc_scores_filename = "ipc-scores.txt"; const string file_ipc_scores_filename = "ipc-scores.txt";
const string file_ipc_channel_filename = "ipc-channel.txt"; const string file_ipc_channel_filename = "ipc-channel.txt";
if (stable.Exists(file_ipc_filename)) if (Storage.Exists(file_ipc_filename))
Scheduler.AddDelayed(delegate scheduled = Scheduler.AddDelayed(delegate
{ {
try try
{ {
using (var stream = stable.GetStream(file_ipc_filename)) using (var stream = Storage.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream)) using (var sr = new StreamReader(stream))
{ {
var beatmapId = int.Parse(sr.ReadLine()); var beatmapId = int.Parse(sr.ReadLine());
@ -85,7 +96,7 @@ namespace osu.Game.Tournament.IPC
try try
{ {
using (var stream = stable.GetStream(file_ipc_channel_filename)) using (var stream = Storage.GetStream(file_ipc_channel_filename))
using (var sr = new StreamReader(stream)) using (var sr = new StreamReader(stream))
{ {
ChatChannel.Value = sr.ReadLine(); ChatChannel.Value = sr.ReadLine();
@ -98,7 +109,7 @@ namespace osu.Game.Tournament.IPC
try try
{ {
using (var stream = stable.GetStream(file_ipc_state_filename)) using (var stream = Storage.GetStream(file_ipc_state_filename))
using (var sr = new StreamReader(stream)) using (var sr = new StreamReader(stream))
{ {
State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine()); State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
@ -111,7 +122,7 @@ namespace osu.Game.Tournament.IPC
try try
{ {
using (var stream = stable.GetStream(file_ipc_scores_filename)) using (var stream = Storage.GetStream(file_ipc_scores_filename))
using (var sr = new StreamReader(stream)) using (var sr = new StreamReader(stream))
{ {
Score1.Value = int.Parse(sr.ReadLine()); Score1.Value = int.Parse(sr.ReadLine());
@ -124,6 +135,13 @@ namespace osu.Game.Tournament.IPC
} }
}, 250, true); }, 250, true);
} }
catch (Exception e)
{
Logger.Error(e, "Stable installation could not be found; disabling file based IPC");
}
return Storage;
}
/// <summary> /// <summary>
/// A method of accessing an osu-stable install in a controlled fashion. /// A method of accessing an osu-stable install in a controlled fashion.

View File

@ -1,9 +1,24 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Tournament.IPC;
namespace osu.Game.Tournament.Screens namespace osu.Game.Tournament.Screens
{ {
public class SetupScreen : TournamentScreen public class SetupScreen : TournamentScreen
{ {
[Resolved]
private MatchIPCInfo ipc { get; set; }
[BackgroundDependencyLoader]
private void load()
{
AddInternal(new SpriteText
{
Text = (ipc as FileBasedIPC)?.Storage.GetFullPath(string.Empty)
});
}
} }
} }