32 lines
803 B
C#
32 lines
803 B
C#
using System.IO;
|
|
using System.Text.Json;
|
|
using ClashWidget.Models;
|
|
|
|
namespace ClashWidget.Services;
|
|
|
|
public static class ConfigService
|
|
{
|
|
private static readonly string ConfigPath = Path.Combine(
|
|
AppContext.BaseDirectory, "config.json");
|
|
|
|
public static AppConfig Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(ConfigPath))
|
|
{
|
|
var json = File.ReadAllText(ConfigPath);
|
|
return JsonSerializer.Deserialize<AppConfig>(json) ?? new AppConfig();
|
|
}
|
|
}
|
|
catch { }
|
|
return new AppConfig();
|
|
}
|
|
|
|
public static void Save(AppConfig config)
|
|
{
|
|
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(ConfigPath, json);
|
|
}
|
|
}
|