39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using Avalonia.Rendering.Composition;
|
|
|
|
namespace kawwa;
|
|
|
|
public static class ConfigManager
|
|
{
|
|
private static Dictionary<string,string> Config = new Dictionary<string,string>();
|
|
private static string ConfigPath = Path.Combine(App.AppDataPath, "prefs.json");
|
|
|
|
public static void InitializeConfig()
|
|
{
|
|
if (File.Exists(ConfigPath))
|
|
{
|
|
var jsonString = File.ReadAllText(ConfigPath);
|
|
var config = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonString);
|
|
if (config != null)
|
|
Config = config;
|
|
}
|
|
}
|
|
|
|
public static void SetValue(string key, string value)
|
|
{
|
|
Config[key] = value;
|
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
|
var jsonString = JsonSerializer.Serialize(Config, options);
|
|
File.WriteAllText(ConfigPath, jsonString);
|
|
}
|
|
|
|
public static string? GetValue(string key)
|
|
{
|
|
if (Config.TryGetValue(key, out string? value))
|
|
return value;
|
|
else
|
|
return null;
|
|
}
|
|
} |