mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 22:12:53 +08:00
Rework StableInfo into a DI'd data structure
This commit is contained in:
parent
5f79feaa8b
commit
1cd96b8002
@ -5,7 +5,6 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -34,14 +33,13 @@ namespace osu.Game.Tournament.IPC
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private LadderInfo ladder { get; set; }
|
private LadderInfo ladder { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private StableInfo stableInfo { get; set; }
|
||||||
|
|
||||||
private int lastBeatmapId;
|
private int lastBeatmapId;
|
||||||
private ScheduledDelegate scheduled;
|
private ScheduledDelegate scheduled;
|
||||||
private GetBeatmapRequest beatmapLookupRequest;
|
private GetBeatmapRequest beatmapLookupRequest;
|
||||||
|
|
||||||
public StableInfo StableInfo { get; private set; }
|
|
||||||
|
|
||||||
public const string STABLE_CONFIG = "tournament/stable.json";
|
|
||||||
|
|
||||||
public Storage IPCStorage { get; private set; }
|
public Storage IPCStorage { get; private set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -165,8 +163,8 @@ namespace osu.Game.Tournament.IPC
|
|||||||
|
|
||||||
private string findStablePath()
|
private string findStablePath()
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(readStableConfig()))
|
if (!string.IsNullOrEmpty(stableInfo.StablePath))
|
||||||
return StableInfo.StablePath.Value;
|
return stableInfo.StablePath;
|
||||||
|
|
||||||
string stableInstallPath = string.Empty;
|
string stableInstallPath = string.Empty;
|
||||||
|
|
||||||
@ -204,43 +202,13 @@ namespace osu.Game.Tournament.IPC
|
|||||||
if (!ipcFileExistsInDirectory(path))
|
if (!ipcFileExistsInDirectory(path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
StableInfo.StablePath.Value = path;
|
stableInfo.StablePath = 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,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
LocateStableStorage();
|
LocateStableStorage();
|
||||||
|
stableInfo.SaveChanges();
|
||||||
|
|
||||||
return true;
|
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()
|
private string findFromEnvVar()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
// 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 System;
|
using System;
|
||||||
using osu.Framework.Bindables;
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Models
|
namespace osu.Game.Tournament.Models
|
||||||
{
|
{
|
||||||
@ -12,6 +14,43 @@ namespace osu.Game.Tournament.Models
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class StableInfo
|
public class StableInfo
|
||||||
{
|
{
|
||||||
public Bindable<string> StablePath = new Bindable<string>(string.Empty);
|
public string StablePath { get; set; }
|
||||||
|
|
||||||
|
public event Action OnStableInfoSaved;
|
||||||
|
|
||||||
|
private const string config_path = "tournament/stable.json";
|
||||||
|
|
||||||
|
private readonly Storage storage;
|
||||||
|
|
||||||
|
public StableInfo(Storage storage)
|
||||||
|
{
|
||||||
|
this.storage = storage;
|
||||||
|
|
||||||
|
if (!storage.Exists(config_path))
|
||||||
|
return;
|
||||||
|
|
||||||
|
using (Stream stream = storage.GetStream(config_path, FileAccess.Read, FileMode.Open))
|
||||||
|
using (var sr = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
JsonConvert.PopulateObject(sr.ReadToEnd(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveChanges()
|
||||||
|
{
|
||||||
|
using (var stream = storage.GetStream(config_path, FileAccess.Write, FileMode.Create))
|
||||||
|
using (var sw = new StreamWriter(stream))
|
||||||
|
{
|
||||||
|
sw.Write(JsonConvert.SerializeObject(this,
|
||||||
|
new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Formatting = Formatting.Indented,
|
||||||
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
|
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
OnStableInfoSaved?.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ namespace osu.Game.Tournament.Screens
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MatchIPCInfo ipc { get; set; }
|
private MatchIPCInfo ipc { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private StableInfo stableInfo { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
@ -57,6 +60,7 @@ namespace osu.Game.Tournament.Screens
|
|||||||
};
|
};
|
||||||
|
|
||||||
api.LocalUser.BindValueChanged(_ => Schedule(reload));
|
api.LocalUser.BindValueChanged(_ => Schedule(reload));
|
||||||
|
stableInfo.OnStableInfoSaved += () => Schedule(reload);
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,21 +70,13 @@ namespace osu.Game.Tournament.Screens
|
|||||||
private void reload()
|
private void reload()
|
||||||
{
|
{
|
||||||
var fileBasedIpc = ipc as FileBasedIPC;
|
var fileBasedIpc = ipc as FileBasedIPC;
|
||||||
StableInfo stableInfo = fileBasedIpc?.StableInfo;
|
|
||||||
fillFlow.Children = new Drawable[]
|
fillFlow.Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new ActionableInfo
|
new ActionableInfo
|
||||||
{
|
{
|
||||||
Label = "Current IPC source",
|
Label = "Current IPC source",
|
||||||
ButtonText = "Change source",
|
ButtonText = "Change source",
|
||||||
Action = () =>
|
Action = () => sceneManager?.SetScreen(new StablePathSelectScreen()),
|
||||||
{
|
|
||||||
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,
|
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."
|
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."
|
||||||
|
@ -15,34 +15,36 @@ using osu.Game.Graphics.UserInterfaceV2;
|
|||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Tournament.IPC;
|
using osu.Game.Tournament.IPC;
|
||||||
using osu.Game.Tournament.Components;
|
using osu.Game.Tournament.Components;
|
||||||
|
using osu.Game.Tournament.Models;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Screens
|
namespace osu.Game.Tournament.Screens
|
||||||
{
|
{
|
||||||
public class StablePathSelectScreen : TournamentScreen
|
public class StablePathSelectScreen : TournamentScreen
|
||||||
{
|
{
|
||||||
private DirectorySelector directorySelector;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private MatchIPCInfo ipc { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
private DialogOverlay overlay;
|
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private TournamentSceneManager sceneManager { get; set; }
|
private TournamentSceneManager sceneManager { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private GameHost host { get; set; }
|
private MatchIPCInfo ipc { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private StableInfo stableInfo { get; set; }
|
||||||
|
|
||||||
|
private DirectorySelector directorySelector;
|
||||||
|
private DialogOverlay overlay;
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(Storage storage, OsuColour colours)
|
private void load(Storage storage, OsuColour colours)
|
||||||
{
|
{
|
||||||
var fileBasedIpc = ipc as FileBasedIPC;
|
|
||||||
var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName;
|
var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(fileBasedIpc?.StableInfo.StablePath.Value))
|
if (!string.IsNullOrEmpty(stableInfo.StablePath))
|
||||||
{
|
{
|
||||||
initialPath = new DirectoryInfo(host.GetStorage(fileBasedIpc.StableInfo.StablePath.Value).GetFullPath(string.Empty)).Parent?.FullName;
|
initialPath = new DirectoryInfo(host.GetStorage(stableInfo.StablePath).GetFullPath(string.Empty)).Parent?.FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddRangeInternal(new Drawable[]
|
AddRangeInternal(new Drawable[]
|
||||||
|
@ -53,6 +53,8 @@ namespace osu.Game.Tournament
|
|||||||
|
|
||||||
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
|
ladder.CurrentMatch.Value = ladder.Matches.FirstOrDefault(p => p.Current.Value);
|
||||||
|
|
||||||
|
dependencies.CacheAs(new StableInfo(storage));
|
||||||
|
|
||||||
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
|
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
|
||||||
Add(ipc);
|
Add(ipc);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user