initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user