csharpdeeb25a2 | 1 | using CascadeIDE.Models; |
| 2 | |
| 3 | namespace CascadeIDE.Services; |
| 4 | |
| 5 | /// <summary>Чтение/запись API-ключей в %LocalAppData%\CascadeIDE\ai-keys.toml (не коммитить).</summary> |
| 6 | public static class AiKeysStorage |
| 7 | { |
| 8 | private static string GetPath() => Path.Combine(SettingsService.GetSettingsDirectory(), "ai-keys.toml"); |
| 9 | |
| 10 | public static AiKeys Load() |
| 11 | { |
| 12 | try |
| 13 | { |
| 14 | var path = GetPath(); |
| 15 | if (!File.Exists(path)) |
| 16 | return new AiKeys(); |
| 17 | var toml = File.ReadAllText(path); |
| 18 | return CascadeTomlSerializer.Deserialize<AiKeys>(toml) ?? new AiKeys(); |
| 19 | } |
| 20 | catch |
| 21 | { |
| 22 | return new AiKeys(); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public static void Save(AiKeys keys) |
| 27 | { |
| 28 | try |
| 29 | { |
| 30 | var toml = CascadeTomlSerializer.Serialize(keys); |
| 31 | File.WriteAllText(GetPath(), toml); |
| 32 | } |
| 33 | catch |
| 34 | { |
| 35 | // Игнорируем ошибки записи |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
View only · write via MCP/CIDE