Moved stableInfo read to FileBasedIPC

DI is also not needed anymore to access StableInfo, this goes through FileBasedIPC.
Note: directory selector now always navigates to the osu! lazer base path.
This commit is contained in:
Shivam 2020-05-31 16:27:05 +02:00
parent dbb7651e60
commit 0027f44bd0
4 changed files with 31 additions and 40 deletions

View File

@ -37,8 +37,7 @@ namespace osu.Game.Tournament.IPC
private int lastBeatmapId;
private ScheduledDelegate scheduled;
[Resolved]
private StableInfo stableInfo { get; set; }
private StableInfo stableInfo;
public const string STABLE_CONFIG = "tournament/stable.json";
@ -161,9 +160,11 @@ namespace osu.Game.Tournament.IPC
public static bool CheckExists(string p) => File.Exists(Path.Combine(p, "ipc.txt"));
public StableInfo GetStableInfo() => stableInfo;
private string findStablePath()
{
if (!string.IsNullOrEmpty(stableInfo.StablePath.Value))
if (!string.IsNullOrEmpty(readStableConfig()))
return stableInfo.StablePath.Value;
string stableInstallPath = string.Empty;
@ -184,7 +185,7 @@ namespace osu.Game.Tournament.IPC
if (stableInstallPath != null)
{
saveStableConfig(stableInstallPath);
SaveStableConfig(stableInstallPath);
return stableInstallPath;
}
}
@ -197,7 +198,7 @@ namespace osu.Game.Tournament.IPC
}
}
private void saveStableConfig(string path)
public void SaveStableConfig(string path)
{
stableInfo.StablePath.Value = path;
@ -214,6 +215,25 @@ namespace osu.Game.Tournament.IPC
}
}
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

View File

@ -15,7 +15,6 @@ using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Tournament.IPC;
using osu.Framework.Platform;
using osu.Game.Tournament.Models;
using osuTK;
using osuTK.Graphics;
@ -43,12 +42,6 @@ namespace osu.Game.Tournament.Screens
private Bindable<Size> windowSize;
[Resolved]
private Storage storage { get; set; }
[Resolved]
private StableInfo stableInfo { get; set; }
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig)
{
@ -73,6 +66,7 @@ namespace osu.Game.Tournament.Screens
private void reload()
{
var fileBasedIpc = ipc as FileBasedIPC;
StableInfo stableInfo = fileBasedIpc?.GetStableInfo();
fillFlow.Children = new Drawable[]
{
new ActionableInfo
@ -81,13 +75,13 @@ namespace osu.Game.Tournament.Screens
ButtonText = "Change source",
Action = () =>
{
stableInfo.StablePath.BindValueChanged(_ =>
stableInfo?.StablePath.BindValueChanged(_ =>
{
Schedule(reload);
});
sceneManager?.SetScreen(new StablePathSelectScreen());
},
Value = fileBasedIpc?.IPCStorage?.GetFullPath(string.Empty) ?? "Not found",
Value = fileBasedIpc?.IPCStorage.GetFullPath(string.Empty) ?? "Not found",
Failing = fileBasedIpc?.IPCStorage == null,
Description = "The osu!stable installation which is currently being used as a data source. If a source is not found, make sure you have created an empty ipc.txt in your stable cutting-edge installation."
},

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Tournament.Models;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -24,9 +23,6 @@ namespace osu.Game.Tournament.Screens
{
private DirectorySelector directorySelector;
[Resolved]
private StableInfo stableInfo { get; set; }
[Resolved]
private MatchIPCInfo ipc { get; set; }
@ -38,7 +34,7 @@ namespace osu.Game.Tournament.Screens
[BackgroundDependencyLoader(true)]
private void load(Storage storage, OsuColour colours)
{
var initialPath = new DirectoryInfo(storage.GetFullPath(stableInfo.StablePath.Value ?? string.Empty)).Parent?.FullName;
var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName;
AddRangeInternal(new Drawable[]
{
@ -131,7 +127,7 @@ namespace osu.Game.Tournament.Screens
protected virtual void ChangePath(Storage storage)
{
var target = directorySelector.CurrentDirectory.Value.FullName;
stableInfo.StablePath.Value = target;
var fileBasedIpc = ipc as FileBasedIPC;
Logger.Log($"Changing Stable CE location to {target}");
if (!FileBasedIPC.CheckExists(target))
@ -143,7 +139,7 @@ namespace osu.Game.Tournament.Screens
return;
}
var fileBasedIpc = ipc as FileBasedIPC;
fileBasedIpc?.SaveStableConfig(target);
fileBasedIpc?.LocateStableStorage();
sceneManager?.SetScreen(typeof(SetupScreen));
}

View File

@ -43,7 +43,6 @@ namespace osu.Game.Tournament
private Bindable<Size> windowSize;
private FileBasedIPC ipc;
private StableInfo stableInfo;
private Drawable heightWarning;
@ -72,7 +71,6 @@ namespace osu.Game.Tournament
}), true);
readBracket();
readStableConfig();
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
@ -143,23 +141,6 @@ namespace osu.Game.Tournament
});
}
private void readStableConfig()
{
if (stableInfo == null)
stableInfo = new StableInfo();
if (storage.Exists(FileBasedIPC.STABLE_CONFIG))
{
using (Stream stream = storage.GetStream(FileBasedIPC.STABLE_CONFIG, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
{
stableInfo = JsonConvert.DeserializeObject<StableInfo>(sr.ReadToEnd());
}
}
dependencies.Cache(stableInfo);
}
private void readBracket()
{
if (storage.Exists(bracket_filename))