You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

50 lines
1.2 KiB

using STranslate.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;
namespace STranslate.Utils
{
public class ConfigUtil
{
public static ConfigModel ReadConfig(string path)
{
using (TextReader reader = File.OpenText(path))
{
try
{
var config = new ConfigModel();
var deserializer = new Deserializer();
config = deserializer.Deserialize<ConfigModel>(reader);
return config;
}
catch (Exception ex)
{
throw ex;
}
}
}
public static void WriteConfig(string path, ConfigModel configs)
{
var serializer = new Serializer();
StringWriter strWriter = new StringWriter();
serializer.Serialize(strWriter, configs);
serializer.Serialize(Console.Out, configs);
using (TextWriter writer = File.CreateText(path))
{
writer.Write(strWriter.ToString());
}
}
}
}