forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStableInfo.cs
More file actions
66 lines (56 loc) · 2.31 KB
/
Copy pathStableInfo.cs
File metadata and controls
66 lines (56 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Newtonsoft.Json;
using osu.Framework.Platform;
using osu.Game.Tournament.IO;
namespace osu.Game.Tournament.Models
{
/// <summary>
/// Holds the path to locate the osu! stable cutting-edge installation.
/// </summary>
[Serializable]
public class StableInfo
{
/// <summary>
/// Path to the IPC directory used by the stable (cutting-edge) install.
/// </summary>
public string? StablePath { get; set; }
/// <summary>
/// Fired whenever stable info is successfully saved to file.
/// </summary>
public event Action? OnStableInfoSaved;
private const string config_path = "stable.json";
private readonly Storage configStorage;
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Tournament uses Newtonsoft.Json which is not subject to IL trimming in this context.")]
public StableInfo(TournamentStorage storage)
{
configStorage = storage.AllTournaments;
if (!configStorage.Exists(config_path))
return;
using (Stream stream = configStorage.GetStream(config_path, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
{
JsonConvert.PopulateObject(sr.ReadToEnd(), this);
}
}
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Tournament uses Newtonsoft.Json which is not subject to IL trimming in this context.")]
public void SaveChanges()
{
using (var stream = configStorage.CreateFileSafely(config_path))
using (var sw = new StreamWriter(stream))
{
sw.Write(JsonConvert.SerializeObject(this,
new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
}));
}
OnStableInfoSaved?.Invoke();
}
}
}