57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|