2020-05-16 08:57:58 +08:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System;
|
2020-06-13 21:05:52 +08:00
|
|
|
using System.IO;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using osu.Framework.Platform;
|
2021-03-29 21:03:10 +08:00
|
|
|
using osu.Game.Tournament.IO;
|
2020-05-16 08:57:58 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Models
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-05-18 04:26:42 +08:00
|
|
|
/// Holds the path to locate the osu! stable cutting-edge installation.
|
2020-05-16 08:57:58 +08:00
|
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
|
|
public class StableInfo
|
|
|
|
{
|
2020-06-13 22:20:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Path to the IPC directory used by the stable (cutting-edge) install.
|
|
|
|
/// </summary>
|
2020-06-13 21:05:52 +08:00
|
|
|
public string StablePath { get; set; }
|
|
|
|
|
2020-06-13 22:20:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Fired whenever stable info is successfully saved to file.
|
|
|
|
/// </summary>
|
2020-06-13 21:05:52 +08:00
|
|
|
public event Action OnStableInfoSaved;
|
|
|
|
|
2021-03-29 21:03:10 +08:00
|
|
|
private const string config_path = "stable.json";
|
2020-06-13 21:05:52 +08:00
|
|
|
|
2021-04-04 20:31:08 +08:00
|
|
|
private readonly Storage configStorage;
|
2020-06-13 21:05:52 +08:00
|
|
|
|
2021-04-04 20:58:25 +08:00
|
|
|
public StableInfo(TournamentStorage storage)
|
2020-06-13 21:05:52 +08:00
|
|
|
{
|
2021-04-04 20:58:25 +08:00
|
|
|
configStorage = storage.AllTournaments;
|
2020-06-13 21:05:52 +08:00
|
|
|
|
2021-04-04 20:31:08 +08:00
|
|
|
if (!configStorage.Exists(config_path))
|
2020-06-13 21:05:52 +08:00
|
|
|
return;
|
|
|
|
|
2021-04-04 20:31:08 +08:00
|
|
|
using (Stream stream = configStorage.GetStream(config_path, FileAccess.Read, FileMode.Open))
|
2020-06-13 21:05:52 +08:00
|
|
|
using (var sr = new StreamReader(stream))
|
|
|
|
{
|
|
|
|
JsonConvert.PopulateObject(sr.ReadToEnd(), this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SaveChanges()
|
|
|
|
{
|
2021-04-04 20:31:08 +08:00
|
|
|
using (var stream = configStorage.GetStream(config_path, FileAccess.Write, FileMode.Create))
|
2020-06-13 21:05:52 +08:00
|
|
|
using (var sw = new StreamWriter(stream))
|
|
|
|
{
|
|
|
|
sw.Write(JsonConvert.SerializeObject(this,
|
|
|
|
new JsonSerializerSettings
|
|
|
|
{
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
NullValueHandling = NullValueHandling.Ignore,
|
|
|
|
DefaultValueHandling = DefaultValueHandling.Ignore,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
OnStableInfoSaved?.Invoke();
|
|
|
|
}
|
2020-05-16 08:57:58 +08:00
|
|
|
}
|
|
|
|
}
|