41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace AnchorCli;
|
|
|
|
internal sealed class AnchorConfig
|
|
{
|
|
public string ApiKey { get; set; } = "";
|
|
public string Model { get; set; } = "qwen/qwen3.5-27b";
|
|
|
|
// ── Persistence ──────────────────────────────────────────────────────
|
|
|
|
private static string ConfigPath =>
|
|
Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"anchor", "config.json");
|
|
|
|
public static AnchorConfig Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(ConfigPath))
|
|
{
|
|
var json = File.ReadAllText(ConfigPath);
|
|
return JsonSerializer.Deserialize(json, AppJsonContext.Default.AnchorConfig)
|
|
?? new AnchorConfig();
|
|
}
|
|
}
|
|
catch { /* fall through to defaults */ }
|
|
|
|
return new AnchorConfig();
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
Directory.CreateDirectory(Path.GetDirectoryName(ConfigPath)!);
|
|
var json = JsonSerializer.Serialize(this, AppJsonContext.Default.AnchorConfig);
|
|
File.WriteAllText(ConfigPath, json);
|
|
}
|
|
}
|