41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using ModVersionChecker.data.model;
|
|
using ModVersionChecker.managers.interfaces;
|
|
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace ModVersionChecker.managers.filesystem
|
|
{
|
|
public class ConfigManager : IConfigManager
|
|
{
|
|
|
|
private static readonly string _filePath = Path.Combine(AppContext.BaseDirectory, "data", "config.json");
|
|
private GlobalConfig _config;
|
|
|
|
public ConfigManager()
|
|
{
|
|
_config = Load();
|
|
}
|
|
|
|
public GlobalConfig Load()
|
|
{
|
|
if (!File.Exists(_filePath))
|
|
return new GlobalConfig();
|
|
var json = File.ReadAllText(_filePath);
|
|
return JsonSerializer.Deserialize<GlobalConfig>(json) ?? new GlobalConfig();
|
|
}
|
|
|
|
public GlobalConfig GetConfig()
|
|
{
|
|
return _config;
|
|
}
|
|
|
|
public void Save(GlobalConfig config)
|
|
{
|
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
|
var json = JsonSerializer.Serialize(config, options);
|
|
File.WriteAllText(_filePath, json);
|
|
}
|
|
}
|
|
}
|