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