noz-cli/NozCli.Core/Config/LocalConfig.cs
kryptomrx b76896dc7a refactor(core): Native AOT - JSON source generators, AOT-safe models and API client
- Add NozJsonContext / NozJsonContextPretty source generator contexts
- Replace all reflection-based JSON with source-generated overloads
- Add NotesCacheFile record for persistent note cache
- Add date field to NoteInfo, CancellationToken to all API methods
- LocalConfig uses source-generated serialization (compact + indented)
2026-05-16 23:20:21 +02:00

37 lines
1.3 KiB
C#

using System.Text.Json;
using NozCli.Core.Serialization;
namespace NozCli.Core.Config;
public class LocalConfig
{
public string ServerUrl { get; set; } = string.Empty;
public string Token { get; set; } = string.Empty;
/// Default editor (nano, vim, vi, notepad …) — used by 'edit' and 'new'
public string? Editor { get; set; } = null;
/// Editor for the -c flag (code, zed, kate …) — used by 'edit -c' and 'new -c'
public string? CodeEditor { get; set; } = null;
private static readonly string ConfigPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".config", "noz", "config.json"
);
public static LocalConfig? Load()
{
if (!File.Exists(ConfigPath)) return null;
var json = File.ReadAllText(ConfigPath);
return JsonSerializer.Deserialize(json, NozJsonContext.Default.LocalConfig);
}
public void Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(ConfigPath)!);
var json = JsonSerializer.Serialize(this, NozJsonContextPretty.Default.LocalConfig);
File.WriteAllText(ConfigPath, json);
if (!OperatingSystem.IsWindows())
File.SetUnixFileMode(ConfigPath, UnixFileMode.UserRead | UnixFileMode.UserWrite);
}
public static bool Exists() => File.Exists(ConfigPath);
}