BeatSaber-version-changer/controller/Config.cs

57 lines
1.6 KiB
C#
Raw Normal View History

2022-05-14 19:00:01 +02:00
using BeatSaber_Versions.controller.helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace BeatSaber_Versions.controller
{
internal class Config
{
public Config()
{
VersionConfigDict c = new VersionConfigDict();
if (!ConfigFile.isConfigFileThere(Storage.ConfigPath))
{
c = ConfigFile.createEmptyConfig();
Storage.Config = c;
writeConfig();
}
else
{
readConfig();
}
}
public void readConfig()
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();
string yml = File.ReadAllText(Storage.ConfigPath);
try
{
VersionConfigDict tmp = deserializer.Deserialize<VersionConfigDict>(yml);
Storage.Config = tmp;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void writeConfig()
{
var serializer = new SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
var yaml = serializer.Serialize(Storage.Config);
File.WriteAllTextAsync(Storage.ConfigPath, yaml);
}
}
}