OpenCS2hock/OpenCS2hock/Configuration.cs
glax 41a433bf3f Version 3:
CS2GSI and CShocker libraries
More extensive options for Events
Setup on first start
2024-01-18 00:06:39 +01:00

44 lines
1.3 KiB
C#

using CShocker.Shockers.Abstract;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace OpenCS2hock;
public struct Configuration
{
public LogLevel LogLevel = LogLevel.Information;
public List<Shocker> Shockers = new();
public List<ShockerAction> ShockerActions = new ();
public Configuration()
{
}
public override string ToString()
{
return $"Loglevel: {Enum.GetName(typeof(LogLevel), LogLevel)}\n" +
$"Shockers: {string.Join("\n---", Shockers)}\n" +
$"Actions: {string.Join("\n---", ShockerActions)}";
}
internal static Configuration GetConfigurationFromFile(string? path = null, ILogger? logger = null)
{
string settingsFilePath = path ?? "config.json";
if (!File.Exists(settingsFilePath))
Setup.Run().SaveConfiguration();
Configuration c = JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(settingsFilePath), new CShocker.Shockers.ShockerJsonConverter());
foreach (Shocker cShocker in c.Shockers)
cShocker.SetLogger(logger);
return c;
}
internal void SaveConfiguration(string? path = null)
{
string settingsFilePath = path ?? "config.json";
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
}
}