refactor: modernize code, improve performance, and clean up various components.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Toak.Core;
|
||||
using Toak.Serialization;
|
||||
using Toak.Core.Interfaces;
|
||||
@@ -9,23 +7,19 @@ namespace Toak.Configuration;
|
||||
|
||||
public class ConfigManager : IConfigProvider
|
||||
{
|
||||
private readonly string ConfigDir = Constants.Paths.ConfigDir;
|
||||
private readonly string ConfigPath = Constants.Paths.ConfigFile;
|
||||
|
||||
public ConfigManager()
|
||||
{
|
||||
}
|
||||
private readonly string _configDir = Constants.Paths.ConfigDir;
|
||||
private readonly string _configPath = Constants.Paths.ConfigFile;
|
||||
|
||||
public ToakConfig LoadConfig()
|
||||
{
|
||||
if (!File.Exists(ConfigPath))
|
||||
if (!File.Exists(_configPath))
|
||||
{
|
||||
return new ToakConfig();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(ConfigPath);
|
||||
var json = File.ReadAllText(_configPath);
|
||||
return JsonSerializer.Deserialize(json, AppJsonSerializerContext.Default.ToakConfig) ?? new ToakConfig();
|
||||
}
|
||||
catch (Exception)
|
||||
@@ -36,12 +30,12 @@ public class ConfigManager : IConfigProvider
|
||||
|
||||
public void SaveConfig(ToakConfig config)
|
||||
{
|
||||
if (!Directory.Exists(ConfigDir))
|
||||
if (!Directory.Exists(_configDir))
|
||||
{
|
||||
Directory.CreateDirectory(ConfigDir);
|
||||
Directory.CreateDirectory(_configDir);
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(config, AppJsonSerializerContext.Default.ToakConfig);
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
File.WriteAllText(_configPath, json);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user